Skip to content

Commit c2ff38f

Browse files
committed
json() is now independent of bitvector representation
1 parent bf4abab commit c2ff38f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/util/json_expr.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ json_objectt json(
217217
return result;
218218
}
219219

220+
static std::string binary(const constant_exprt &src)
221+
{
222+
const auto width = to_bitvector_type(src.type()).get_width();
223+
const auto int_val = bv2integer(id2string(src.get_value()), width, false);
224+
return integer2binary(int_val, width);
225+
}
226+
220227
/// Output a CBMC expression in json.
221228
/// The mode is used to correctly report types.
222229
/// \param expr: an expression
@@ -263,15 +270,15 @@ json_objectt json(
263270
std::size_t width=to_bitvector_type(type).get_width();
264271

265272
result["name"]=json_stringt("integer");
266-
result["binary"] = json_stringt(constant_expr.get_value());
273+
result["binary"] = json_stringt(binary(constant_expr));
267274
result["width"]=json_numbert(std::to_string(width));
268275
result["type"]=json_stringt(type_string);
269276
result["data"]=json_stringt(value_string);
270277
}
271278
else if(type.id()==ID_c_enum)
272279
{
273280
result["name"]=json_stringt("integer");
274-
result["binary"] = json_stringt(constant_expr.get_value());
281+
result["binary"] = json_stringt(binary(constant_expr));
275282
result["width"] =
276283
json_numbert(to_c_enum_type(type).subtype().get_string(ID_width));
277284
result["type"]=json_stringt("enum");
@@ -287,21 +294,21 @@ json_objectt json(
287294
else if(type.id()==ID_bv)
288295
{
289296
result["name"]=json_stringt("bitvector");
290-
result["binary"] = json_stringt(constant_expr.get_value());
297+
result["binary"] = json_stringt(binary(constant_expr));
291298
}
292299
else if(type.id()==ID_fixedbv)
293300
{
294301
result["name"]=json_stringt("fixed");
295302
result["width"]=json_numbert(type.get_string(ID_width));
296-
result["binary"] = json_stringt(constant_expr.get_value());
303+
result["binary"] = json_stringt(binary(constant_expr));
297304
result["data"]=
298305
json_stringt(fixedbvt(to_constant_expr(expr)).to_ansi_c_string());
299306
}
300307
else if(type.id()==ID_floatbv)
301308
{
302309
result["name"]=json_stringt("float");
303310
result["width"]=json_numbert(type.get_string(ID_width));
304-
result["binary"] = json_stringt(constant_expr.get_value());
311+
result["binary"] = json_stringt(binary(constant_expr));
305312
result["data"]=
306313
json_stringt(ieee_floatt(to_constant_expr(expr)).to_ansi_c_string());
307314
}

0 commit comments

Comments
 (0)