@@ -104,9 +104,42 @@ void goto_trace_stept::output(
104
104
out << ' \n ' ;
105
105
}
106
106
107
- std::string trace_value_binary (
107
+ static std::string
108
+ numeric_representation (const exprt &expr, const trace_optionst &options)
109
+ {
110
+ std::string result;
111
+ std::string prefix;
112
+ if (options.hex_representation )
113
+ {
114
+ mp_integer value_int =
115
+ binary2integer (id2string (to_constant_expr (expr).get_value ()), false );
116
+ result = integer2string (value_int, 16 );
117
+ prefix = " 0x" ;
118
+ }
119
+ else
120
+ {
121
+ prefix = " 0b" ;
122
+ result = expr.get_string (ID_value);
123
+ }
124
+
125
+ std::ostringstream oss;
126
+ std::string::size_type i = 0 ;
127
+ for (const auto c : result)
128
+ {
129
+ oss << c;
130
+ if (++i % 8 == 0 && result.size () != i)
131
+ oss << ' ' ;
132
+ }
133
+ if (options.base_prefix )
134
+ return prefix + oss.str ();
135
+ else
136
+ return oss.str ();
137
+ }
138
+
139
+ std::string trace_value_lowlevel (
108
140
const exprt &expr,
109
- const namespacet &ns)
141
+ const namespacet &ns,
142
+ const trace_optionst &options)
110
143
{
111
144
const typet &type=ns.follow (expr.type ());
112
145
@@ -123,18 +156,8 @@ std::string trace_value_binary(
123
156
type.id ()==ID_c_enum ||
124
157
type.id ()==ID_c_enum_tag)
125
158
{
126
- const std::string & str = expr.get_string (ID_value);
127
-
128
- std::ostringstream oss;
129
- std::string::size_type i = 0 ;
130
- for (const auto c : str)
131
- {
132
- oss << c;
133
- if (++i % 8 == 0 && str.size () != i)
134
- oss << ' ' ;
135
- }
136
-
137
- return oss.str ();
159
+ const std::string &str = numeric_representation (expr, options);
160
+ return str;
138
161
}
139
162
else if (type.id ()==ID_bool)
140
163
{
@@ -157,7 +180,7 @@ std::string trace_value_binary(
157
180
result=" { " ;
158
181
else
159
182
result+=" , " ;
160
- result+=trace_value_binary (*it, ns);
183
+ result+=trace_value_lowlevel (*it, ns, options );
161
184
}
162
185
163
186
return result+" }" ;
@@ -170,15 +193,15 @@ std::string trace_value_binary(
170
193
{
171
194
if (it!=expr.operands ().begin ())
172
195
result+=" , " ;
173
- result+=trace_value_binary (*it, ns);
196
+ result+=trace_value_lowlevel (*it, ns, options );
174
197
}
175
198
176
199
return result+" }" ;
177
200
}
178
201
else if (expr.id ()==ID_union)
179
202
{
180
- assert (expr.operands ().size ()==1 );
181
- return trace_value_binary (expr.op0 (), ns);
203
+ PRECONDITION (expr.operands ().size ()==1 );
204
+ return trace_value_lowlevel (expr.op0 (), ns, options );
182
205
}
183
206
184
207
return " ?" ;
@@ -189,7 +212,8 @@ void trace_value(
189
212
const namespacet &ns,
190
213
const ssa_exprt &lhs_object,
191
214
const exprt &full_lhs,
192
- const exprt &value)
215
+ const exprt &value,
216
+ const trace_optionst &options)
193
217
{
194
218
irep_idt identifier;
195
219
@@ -205,7 +229,7 @@ void trace_value(
205
229
value_string=from_expr (ns, identifier, value);
206
230
207
231
// the binary representation
208
- value_string+= " (" + trace_value_binary (value, ns)+ " )" ;
232
+ value_string += " (" + trace_value_lowlevel (value, ns, options) + " )" ;
209
233
}
210
234
211
235
out << " "
@@ -247,7 +271,8 @@ bool is_index_member_symbol(const exprt &src)
247
271
void show_goto_trace (
248
272
std::ostream &out,
249
273
const namespacet &ns,
250
- const goto_tracet &goto_trace)
274
+ const goto_tracet &goto_trace,
275
+ const trace_optionst &options)
251
276
{
252
277
unsigned prev_step_nr=0 ;
253
278
bool first_step=true ;
@@ -315,10 +340,20 @@ void show_goto_trace(
315
340
// see if the full lhs is something clean
316
341
if (is_index_member_symbol (step.full_lhs ))
317
342
trace_value (
318
- out, ns, step.lhs_object , step.full_lhs , step.full_lhs_value );
343
+ out,
344
+ ns,
345
+ step.lhs_object ,
346
+ step.full_lhs ,
347
+ step.full_lhs_value ,
348
+ options);
319
349
else
320
350
trace_value (
321
- out, ns, step.lhs_object , step.lhs_object , step.lhs_object_value );
351
+ out,
352
+ ns,
353
+ step.lhs_object ,
354
+ step.lhs_object ,
355
+ step.lhs_object_value ,
356
+ options);
322
357
}
323
358
break ;
324
359
@@ -330,7 +365,8 @@ void show_goto_trace(
330
365
show_state_header (out, step, step.pc ->source_location , step.step_nr );
331
366
}
332
367
333
- trace_value (out, ns, step.lhs_object , step.full_lhs , step.full_lhs_value );
368
+ trace_value (
369
+ out, ns, step.lhs_object , step.full_lhs , step.full_lhs_value , options);
334
370
break ;
335
371
336
372
case goto_trace_stept::typet::OUTPUT:
@@ -356,7 +392,7 @@ void show_goto_trace(
356
392
out << " " << from_expr (ns, step.pc ->function , *l_it);
357
393
358
394
// the binary representation
359
- out << " (" << trace_value_binary (*l_it, ns) << " )" ;
395
+ out << " (" << trace_value_lowlevel (*l_it, ns, options ) << " )" ;
360
396
}
361
397
362
398
out << " \n " ;
@@ -377,7 +413,7 @@ void show_goto_trace(
377
413
out << " " << from_expr (ns, step.pc ->function , *l_it);
378
414
379
415
// the binary representation
380
- out << " (" << trace_value_binary (*l_it, ns) << " )" ;
416
+ out << " (" << trace_value_lowlevel (*l_it, ns, options ) << " )" ;
381
417
}
382
418
383
419
out << " \n " ;
@@ -401,5 +437,12 @@ void show_goto_trace(
401
437
}
402
438
}
403
439
440
+ void show_goto_trace (
441
+ std::ostream &out,
442
+ const namespacet &ns,
443
+ const goto_tracet &goto_trace)
444
+ {
445
+ show_goto_trace (out, ns, goto_trace, trace_optionst::default_options);
446
+ }
404
447
405
448
const trace_optionst trace_optionst::default_options = trace_optionst();
0 commit comments