18
18
#include " expr_util.h"
19
19
#include " fixedbv.h"
20
20
#include " ieee_float.h"
21
+ #include " invariant.h"
21
22
#include " namespace.h"
22
23
#include " rational.h"
23
24
#include " rational_tools.h"
@@ -1101,34 +1102,32 @@ bool simplify_exprt::simplify_power(exprt &expr)
1101
1102
}
1102
1103
1103
1104
// / Simplifies extracting of bits from a constant.
1104
- bool simplify_exprt::simplify_extractbits (exprt &expr)
1105
+ bool simplify_exprt::simplify_extractbits (extractbits_exprt &expr)
1105
1106
{
1106
- assert (expr.operands ().size ()==3 );
1107
-
1108
- const typet &op0_type=expr.op0 ().type ();
1107
+ const typet &op0_type = expr.src ().type ();
1109
1108
1110
1109
if (!is_bitvector_type (op0_type) &&
1111
1110
!is_bitvector_type (expr.type ()))
1112
1111
return true ;
1113
1112
1114
- if (expr.op0 ().is_constant ())
1115
- {
1116
- std::size_t width=to_bitvector_type (op0_type).get_width ();
1117
- mp_integer start, end;
1113
+ mp_integer start, end;
1118
1114
1119
- if (to_integer (expr.op1 (), start))
1120
- return true ;
1115
+ if (to_integer (expr.upper (), start))
1116
+ return true ;
1121
1117
1122
- if (to_integer (expr.op2 (), end))
1123
- return true ;
1118
+ if (to_integer (expr.lower (), end))
1119
+ return true ;
1124
1120
1125
- if (start<0 || start>=width ||
1126
- end<0 || end>=width)
1127
- return true ;
1121
+ const std::size_t width = to_bitvector_type (op0_type).get_width ();
1128
1122
1129
- assert (start>=end); // is this always the case??
1123
+ if (start < 0 || start >= width || end < 0 || end >= width)
1124
+ return true ;
1130
1125
1131
- const irep_idt &value=expr.op0 ().get (ID_value);
1126
+ PRECONDITION (start >= end);
1127
+
1128
+ if (expr.src ().is_constant ())
1129
+ {
1130
+ const irep_idt &value = to_constant_expr (expr.src ()).get_value ();
1132
1131
1133
1132
if (value.size ()!=width)
1134
1133
return true ;
@@ -1139,7 +1138,8 @@ bool simplify_exprt::simplify_extractbits(exprt &expr)
1139
1138
svalue.substr (width-integer2size_t (start)-1 ,
1140
1139
integer2size_t (start-end+1 ));
1141
1140
1142
- expr = constant_exprt (extracted_value, expr.type ());
1141
+ constant_exprt result (extracted_value, expr.type ());
1142
+ expr.swap (result);
1143
1143
1144
1144
return false ;
1145
1145
}
0 commit comments