Skip to content

Commit cefb96a

Browse files
committed
flattening: use update_bits_exprt for 'with' on bit-vectors
This replaces the conversion of the 'with' expression on bit-vectors by using update_bits_exprt.
1 parent 1371538 commit cefb96a

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

src/solvers/flattening/boolbv_with.cpp

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,30 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
#include "boolbv.h"
10-
119
#include <util/arith_tools.h>
10+
#include <util/bitvector_expr.h>
1211
#include <util/c_types.h>
1312
#include <util/namespace.h>
1413
#include <util/std_expr.h>
1514

15+
#include "boolbv.h"
16+
1617
bvt boolbvt::convert_with(const with_exprt &expr)
1718
{
19+
auto &type = expr.type();
20+
21+
if(
22+
type.id() == ID_bv || type.id() == ID_unsignedbv ||
23+
type.id() == ID_signedbv)
24+
{
25+
PRECONDITION(expr.operands().size() == 3);
26+
return convert_bv(
27+
update_bits_exprt(expr.old(), expr.where(), expr.new_value()));
28+
}
29+
1830
bvt bv = convert_bv(expr.old());
1931

20-
std::size_t width=boolbv_width(expr.type());
32+
std::size_t width = boolbv_width(type);
2133

2234
if(width==0)
2335
{
@@ -62,7 +74,10 @@ void boolbvt::convert_with(
6274
else if(type.id()==ID_bv ||
6375
type.id()==ID_unsignedbv ||
6476
type.id()==ID_signedbv)
65-
return convert_with_bv(where, new_value, prev_bv, next_bv);
77+
{
78+
// already done
79+
PRECONDITION(false);
80+
}
6681
else if(type.id()==ID_struct)
6782
return convert_with_struct(
6883
to_struct_type(type), where, new_value, prev_bv, next_bv);
@@ -151,36 +166,6 @@ void boolbvt::convert_with_array(
151166
}
152167
}
153168

154-
void boolbvt::convert_with_bv(
155-
const exprt &index,
156-
const exprt &new_value,
157-
const bvt &prev_bv,
158-
bvt &next_bv)
159-
{
160-
literalt l = convert(new_value);
161-
162-
if(const auto index_value_opt = numeric_cast<mp_integer>(index))
163-
{
164-
next_bv=prev_bv;
165-
166-
if(*index_value_opt >= 0 && *index_value_opt < next_bv.size())
167-
next_bv[numeric_cast_v<std::size_t>(*index_value_opt)] = l;
168-
169-
return;
170-
}
171-
172-
typet counter_type = index.type();
173-
174-
for(std::size_t i=0; i<prev_bv.size(); i++)
175-
{
176-
exprt counter=from_integer(i, counter_type);
177-
178-
literalt eq_lit = convert(equal_exprt(index, counter));
179-
180-
next_bv[i]=prop.lselect(eq_lit, l, prev_bv[i]);
181-
}
182-
}
183-
184169
void boolbvt::convert_with_struct(
185170
const struct_typet &type,
186171
const exprt &where,

0 commit comments

Comments
 (0)