Skip to content

Commit 6c2ce78

Browse files
author
Daniel Kroening
committed
simplify_concatenation is now independent of bitvector representation
1 parent c483860 commit 6c2ce78

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/util/simplify_expr_int.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,9 @@ bool simplify_exprt::simplify_concatenation(exprt &expr)
883883
exprt &op=*it;
884884
if(op.is_true() || op.is_false())
885885
{
886-
bool value=op.is_true();
887-
op=constant_exprt(value?ID_1:ID_0, unsignedbv_typet(1));
886+
const bool value = op.is_true();
887+
op = from_integer(value, unsignedbv_typet(1));
888+
result = true;
888889
}
889890
}
890891

@@ -902,10 +903,20 @@ bool simplify_exprt::simplify_concatenation(exprt &expr)
902903
is_bitvector_type(opn.type()))
903904
{
904905
// merge!
905-
const std::string new_value=
906-
opi.get_string(ID_value)+opn.get_string(ID_value);
907-
opi.set(ID_value, new_value);
908-
opi.type().set(ID_width, new_value.size());
906+
const auto &value_i = to_constant_expr(opi).get_value();
907+
const auto &value_n = to_constant_expr(opn).get_value();
908+
const auto width_i = to_bitvector_type(opi.type()).get_width();
909+
const auto width_n = to_bitvector_type(opn.type()).get_width();
910+
const auto new_width = width_i + width_n;
911+
912+
const auto new_value =
913+
make_bvrep(new_width, [&value_i, &value_n, width_n](std::size_t x) {
914+
return x < width_n ? get_bitvector_bit(value_n, x)
915+
: get_bitvector_bit(value_i, x - width_n);
916+
});
917+
918+
to_constant_expr(opi).set_value(new_value);
919+
opi.type().set(ID_width, new_width);
909920
// erase opn
910921
expr.operands().erase(expr.operands().begin()+i+1);
911922
result=true;

0 commit comments

Comments
 (0)