@@ -517,11 +517,14 @@ constant_exprt smt2_convt::parse_literal(
517
517
std::size_t width=boolbv_width (type);
518
518
return constant_exprt (integer2bvrep (value, width), type);
519
519
}
520
- else if (type.id ()==ID_integer ||
521
- type.id ()==ID_range)
520
+ else if (type.id () == ID_integer)
522
521
{
523
522
return from_integer (value, type);
524
523
}
524
+ else if (type.id () == ID_range)
525
+ {
526
+ return from_integer (value + to_range_type (type).get_from (), type);
527
+ }
525
528
else
526
529
UNREACHABLE_BECAUSE (
527
530
" smt2_convt::parse_literal should not be of unsupported type " +
@@ -1317,17 +1320,26 @@ void smt2_convt::convert_expr(const exprt &expr)
1317
1320
else if (expr.id ()==ID_unary_minus)
1318
1321
{
1319
1322
const unary_minus_exprt &unary_minus_expr = to_unary_minus_expr (expr);
1323
+ const auto &type = expr.type ();
1320
1324
1321
1325
if (
1322
- unary_minus_expr.type ().id () == ID_rational ||
1323
- unary_minus_expr.type ().id () == ID_integer ||
1324
- unary_minus_expr.type ().id () == ID_real)
1326
+ type.id () == ID_rational || type.id () == ID_integer ||
1327
+ type.id () == ID_real)
1325
1328
{
1326
1329
out << " (- " ;
1327
1330
convert_expr (unary_minus_expr.op ());
1328
1331
out << " )" ;
1329
1332
}
1330
- else if (unary_minus_expr.type ().id () == ID_floatbv)
1333
+ else if (type.id () == ID_range)
1334
+ {
1335
+ auto &range_type = to_range_type (type);
1336
+ PRECONDITION (type == unary_minus_expr.op ().type ());
1337
+ // turn -x into 0-x
1338
+ auto minus_expr =
1339
+ minus_exprt{range_type.zero_expr (), unary_minus_expr.op ()};
1340
+ convert_expr (minus_expr);
1341
+ }
1342
+ else if (type.id () == ID_floatbv)
1331
1343
{
1332
1344
// this has no rounding mode
1333
1345
if (use_FPA_theory)
@@ -3764,7 +3776,7 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
3764
3776
}
3765
3777
else if (
3766
3778
expr.type ().id () == ID_unsignedbv || expr.type ().id () == ID_signedbv ||
3767
- expr.type ().id () == ID_fixedbv || expr. type (). id () == ID_range )
3779
+ expr.type ().id () == ID_fixedbv)
3768
3780
{
3769
3781
// These could be chained, i.e., need not be binary,
3770
3782
// but at least MathSat doesn't like that.
@@ -3781,6 +3793,31 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
3781
3793
convert_plus (to_plus_expr (make_binary (expr)));
3782
3794
}
3783
3795
}
3796
+ else if (expr.type ().id () == ID_range)
3797
+ {
3798
+ auto &range_type = to_range_type (expr.type ());
3799
+
3800
+ // These could be chained, i.e., need not be binary,
3801
+ // but at least MathSat doesn't like that.
3802
+ if (expr.operands ().size () == 2 )
3803
+ {
3804
+ // add: lhs + from + rhs + from - from = lhs + rhs + from
3805
+ mp_integer from = range_type.get_from ();
3806
+ const auto size = range_type.get_to () - range_type.get_from () + 1 ;
3807
+ const auto width = address_bits (size);
3808
+
3809
+ out << " (bvadd " ;
3810
+ convert_expr (expr.op0 ());
3811
+ out << " (bvadd " ;
3812
+ convert_expr (expr.op1 ());
3813
+ out << " (_ bv" << range_type.get_from () << ' ' << width
3814
+ << " )))" ; // bv, bvadd, bvadd
3815
+ }
3816
+ else
3817
+ {
3818
+ convert_plus (to_plus_expr (make_binary (expr)));
3819
+ }
3820
+ }
3784
3821
else if (expr.type ().id () == ID_floatbv)
3785
3822
{
3786
3823
// Floating-point additions should have be been converted
@@ -4018,6 +4055,22 @@ void smt2_convt::convert_minus(const minus_exprt &expr)
4018
4055
" unsupported operand types for -: " + expr.op0 ().type ().id_string () +
4019
4056
" and " + expr.op1 ().type ().id_string ());
4020
4057
}
4058
+ else if (expr.type ().id () == ID_range)
4059
+ {
4060
+ auto &range_type = to_range_type (expr.type ());
4061
+
4062
+ // sub: lhs + from - (rhs + from) - from = lhs - rhs - from
4063
+ mp_integer from = range_type.get_from ();
4064
+ const auto size = range_type.get_to () - range_type.get_from () + 1 ;
4065
+ const auto width = address_bits (size);
4066
+
4067
+ out << " (bvsub (bvsub " ;
4068
+ convert_expr (expr.op0 ());
4069
+ out << ' ' ;
4070
+ convert_expr (expr.op1 ());
4071
+ out << " ) (_ bv" << range_type.get_from () << ' ' << width
4072
+ << " ))" ; // bv, bvsub
4073
+ }
4021
4074
else
4022
4075
UNEXPECTEDCASE (" unsupported type for -: " +expr.type ().id_string ());
4023
4076
}
0 commit comments