@@ -275,11 +275,15 @@ constant_exprt smt2_convt::parse_literal(
275
275
parse_literal (src.get_sub ()[2 ], unsignedbv_typet (floatbv_type.get_e ()));
276
276
constant_exprt s3 =
277
277
parse_literal (src.get_sub ()[3 ], unsignedbv_typet (floatbv_type.get_f ()));
278
+
279
+ const auto s1_int = numeric_cast_v<mp_integer>(s1);
280
+ const auto s2_int = numeric_cast_v<mp_integer>(s2);
281
+ const auto s3_int = numeric_cast_v<mp_integer>(s3);
282
+
278
283
// stitch the bits together
279
- std::string bits=id2string (s1.get_value ())+
280
- id2string (s2.get_value ())+
281
- id2string (s3.get_value ());
282
- value=binary2integer (bits, false );
284
+ value = bitwise_or (
285
+ s1_int << (floatbv_type.get_e () + floatbv_type.get_f ()),
286
+ bitwise_or ((s2_int << floatbv_type.get_f ()), s3_int));
283
287
}
284
288
else
285
289
value=0 ;
@@ -318,10 +322,12 @@ constant_exprt smt2_convt::parse_literal(
318
322
}
319
323
else if (type.id ()==ID_c_enum_tag)
320
324
{
321
- return
322
- from_integer (
323
- value,
324
- ns.follow_tag (to_c_enum_tag_type (type)));
325
+ constant_exprt result =
326
+ from_integer (value, ns.follow_tag (to_c_enum_tag_type (type)));
327
+
328
+ // restore the c_enum_tag type
329
+ result.type () = type;
330
+ return result;
325
331
}
326
332
else if (type.id ()==ID_fixedbv ||
327
333
type.id ()==ID_floatbv)
@@ -331,7 +337,9 @@ constant_exprt smt2_convt::parse_literal(
331
337
}
332
338
else if (type.id ()==ID_integer ||
333
339
type.id ()==ID_range)
340
+ {
334
341
return from_integer (value, type);
342
+ }
335
343
else
336
344
INVARIANT (
337
345
false ,
@@ -384,25 +392,24 @@ exprt smt2_convt::parse_union(
384
392
return union_exprt (first.get_name (), converted, type);
385
393
}
386
394
387
- exprt smt2_convt::parse_struct (
388
- const irept &src,
389
- const struct_typet &type)
395
+ struct_exprt
396
+ smt2_convt::parse_struct (const irept &src, const struct_typet &type)
390
397
{
391
398
const struct_typet::componentst &components =
392
399
type.components ();
393
400
394
401
struct_exprt result (exprt::operandst (components.size (), nil_exprt ()), type);
395
402
396
403
if (components.empty ())
397
- return std::move ( result) ;
404
+ return result;
398
405
399
406
if (use_datatypes)
400
407
{
401
408
// Structs look like:
402
409
// (mk-struct.1 <component0> <component1> ... <componentN>)
403
410
404
411
if (src.get_sub ().size ()!=components.size ()+1 )
405
- return std::move ( result) ; // give up
412
+ return result; // give up
406
413
407
414
for (std::size_t i=0 ; i<components.size (); i++)
408
415
{
@@ -414,13 +421,12 @@ exprt smt2_convt::parse_struct(
414
421
{
415
422
// These are just flattened, i.e., we expect to see a monster bit vector.
416
423
std::size_t total_width=boolbv_width (type);
417
- exprt l = parse_literal (src, unsignedbv_typet (total_width));
418
- if (!l.is_constant ())
419
- return nil_exprt ();
424
+ const auto l = parse_literal (src, unsignedbv_typet (total_width));
420
425
421
- irep_idt binary=to_constant_expr (l).get_value ();
422
- if (binary.size ()!=total_width)
423
- return nil_exprt ();
426
+ const irep_idt binary =
427
+ integer2binary (numeric_cast_v<mp_integer>(l), total_width);
428
+
429
+ CHECK_RETURN (binary.size () == total_width);
424
430
425
431
std::size_t offset=0 ;
426
432
@@ -443,20 +449,17 @@ exprt smt2_convt::parse_struct(
443
449
}
444
450
}
445
451
446
- return std::move ( result) ;
452
+ return result;
447
453
}
448
454
449
- exprt smt2_convt::parse_rec (const irept &src, const typet &_type )
455
+ exprt smt2_convt::parse_rec (const irept &src, const typet &type )
450
456
{
451
- const typet &type=ns.follow (_type);
452
-
453
- if (type.id ()==ID_signedbv ||
454
- type.id ()==ID_unsignedbv ||
455
- type.id ()==ID_integer ||
456
- type.id ()==ID_rational ||
457
- type.id ()==ID_real ||
458
- type.id ()==ID_fixedbv ||
459
- type.id ()==ID_floatbv)
457
+ if (
458
+ type.id () == ID_signedbv || type.id () == ID_unsignedbv ||
459
+ type.id () == ID_integer || type.id () == ID_rational ||
460
+ type.id () == ID_real || type.id () == ID_c_enum ||
461
+ type.id () == ID_c_enum_tag || type.id () == ID_fixedbv ||
462
+ type.id () == ID_floatbv)
460
463
{
461
464
return parse_literal (src, type);
462
465
}
@@ -486,10 +489,25 @@ exprt smt2_convt::parse_rec(const irept &src, const typet &_type)
486
489
{
487
490
return parse_struct (src, to_struct_type (type));
488
491
}
492
+ else if (type.id () == ID_struct_tag)
493
+ {
494
+ auto struct_expr =
495
+ parse_struct (src, ns.follow_tag (to_struct_tag_type (type)));
496
+ // restore the tag type
497
+ struct_expr.type () = type;
498
+ return std::move (struct_expr);
499
+ }
489
500
else if (type.id ()==ID_union)
490
501
{
491
502
return parse_union (src, to_union_type (type));
492
503
}
504
+ else if (type.id () == ID_union_tag)
505
+ {
506
+ auto union_expr = parse_union (src, ns.follow_tag (to_union_tag_type (type)));
507
+ // restore the tag type
508
+ union_expr.type () = type;
509
+ return union_expr;
510
+ }
493
511
else if (type.id ()==ID_array)
494
512
{
495
513
return parse_array (src, to_array_type (type));
@@ -2371,15 +2389,15 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
2371
2389
significand = 1 ;
2372
2390
exponent = 0 ;
2373
2391
a.build (significand , exponent);
2374
- val.set (ID_value, integer2binary (a.pack (), a.spec .width ()));
2392
+ val.set_value ( integer2bvrep (a.pack (), a.spec .width ()));
2375
2393
2376
2394
convert_constant (val);
2377
2395
out << " " ;
2378
2396
2379
2397
significand = 0 ;
2380
2398
exponent = 0 ;
2381
2399
a.build (significand , exponent);
2382
- val.set (ID_value, integer2binary (a.pack (), a.spec .width ()));
2400
+ val.set_value ( integer2bvrep (a.pack (), a.spec .width ()));
2383
2401
2384
2402
convert_constant (val);
2385
2403
out << " )" ;
@@ -2780,7 +2798,7 @@ void smt2_convt::convert_constant(const constant_exprt &expr)
2780
2798
}
2781
2799
else if (expr_type.id ()==ID_pointer)
2782
2800
{
2783
- const irep_idt &value= expr.get (ID_value );
2801
+ const irep_idt &value = expr.get_value ( );
2784
2802
2785
2803
if (value==ID_NULL)
2786
2804
{
@@ -3110,7 +3128,7 @@ void smt2_convt::convert_rounding_mode_FPA(const exprt &expr)
3110
3128
{
3111
3129
const constant_exprt &cexpr=to_constant_expr (expr);
3112
3130
3113
- mp_integer value= binary2integer ( id2string ( cexpr. get_value ()), false );
3131
+ mp_integer value = numeric_cast_v<mp_integer>( cexpr);
3114
3132
3115
3133
if (value==0 )
3116
3134
out << " roundNearestTiesToEven" ;
0 commit comments