@@ -136,6 +136,7 @@ xmlt xml(const exprt &expr, const namespacet &ns)
136
136
if (expr.id () == ID_constant)
137
137
{
138
138
const auto &constant_expr = to_constant_expr (expr);
139
+ const auto &value = constant_expr.get_value ();
139
140
140
141
const typet &type = expr.type ();
141
142
@@ -175,10 +176,14 @@ xmlt xml(const exprt &expr, const namespacet &ns)
175
176
}
176
177
else if (type.id () == ID_c_enum)
177
178
{
179
+ const auto width =
180
+ to_bitvector_type (to_c_enum_type (type).subtype ()).get_width ();
181
+
178
182
result.name = " integer" ;
179
- result.set_attribute (" binary" , constant_expr.get_string (ID_value));
180
183
result.set_attribute (
181
- " width" , to_bitvector_type (to_c_enum_type (type).subtype ()).get_width ());
184
+ " binary" ,
185
+ integer2binary (numeric_cast_v<mp_integer>(constant_expr), width));
186
+ result.set_attribute (" width" , width);
182
187
result.set_attribute (" c_type" , " enum" );
183
188
184
189
mp_integer i;
@@ -198,22 +203,28 @@ xmlt xml(const exprt &expr, const namespacet &ns)
198
203
}
199
204
else if (type.id () == ID_fixedbv)
200
205
{
206
+ const auto width = to_fixedbv_type (type).get_width ();
201
207
result.name = " fixed" ;
202
- result.set_attribute (" width" , to_bitvector_type (type).get_width ());
203
- result.set_attribute (" binary" , constant_expr.get_string (ID_value));
208
+ result.set_attribute (" width" , width);
209
+ result.set_attribute (
210
+ " binary" , integer2binary (bvrep2integer (value, width, false ), width));
204
211
result.data = fixedbvt (constant_expr).to_ansi_c_string ();
205
212
}
206
213
else if (type.id () == ID_floatbv)
207
214
{
215
+ const auto width = to_floatbv_type (type).get_width ();
208
216
result.name = " float" ;
209
- result.set_attribute (" width" , to_bitvector_type (type).get_width ());
210
- result.set_attribute (" binary" , constant_expr.get_string (ID_value));
217
+ result.set_attribute (" width" , width);
218
+ result.set_attribute (
219
+ " binary" , integer2binary (bvrep2integer (value, width, false ), width));
211
220
result.data = ieee_floatt (constant_expr).to_ansi_c_string ();
212
221
}
213
222
else if (type.id () == ID_pointer)
214
223
{
224
+ const auto width = to_pointer_type (type).get_width ();
215
225
result.name = " pointer" ;
216
- result.set_attribute (" binary" , constant_expr.get_string (ID_value));
226
+ result.set_attribute (
227
+ " binary" , integer2binary (bvrep2integer (value, width, false ), width));
217
228
if (constant_expr.get (ID_value) == ID_NULL)
218
229
result.data = " NULL" ;
219
230
}
0 commit comments