Skip to content

Commit

Permalink
flattening: use update_bits_exprt for 'with' on bit-vectors
Browse files Browse the repository at this point in the history
This replaces the conversion of the 'with' expression on bit-vectors by
using update_bits_exprt.
  • Loading branch information
kroening committed Feb 4, 2024
1 parent 3eb2a3d commit 0e2502e
Showing 1 changed file with 19 additions and 34 deletions.
53 changes: 19 additions & 34 deletions src/solvers/flattening/boolbv_with.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@ Author: Daniel Kroening, kroening@kroening.com
\*******************************************************************/

#include "boolbv.h"

#include <util/arith_tools.h>
#include <util/bitvector_expr.h>
#include <util/c_types.h>
#include <util/namespace.h>
#include <util/std_expr.h>

#include "boolbv.h"

bvt boolbvt::convert_with(const with_exprt &expr)
{
auto &type = expr.type();

if(
type.id() == ID_bv || type.id() == ID_unsignedbv ||
type.id() == ID_signedbv)
{
PRECONDITION(expr.operands().size() == 3);
return convert_bv(
update_bits_exprt(expr.old(), expr.where(), expr.new_value()));

Check warning on line 27 in src/solvers/flattening/boolbv_with.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_with.cpp#L25-L27

Added lines #L25 - L27 were not covered by tests
}

bvt bv = convert_bv(expr.old());

std::size_t width=boolbv_width(expr.type());
std::size_t width = boolbv_width(type);

if(width==0)
{
Expand Down Expand Up @@ -62,7 +74,10 @@ void boolbvt::convert_with(
else if(type.id()==ID_bv ||
type.id()==ID_unsignedbv ||
type.id()==ID_signedbv)
return convert_with_bv(where, new_value, prev_bv, next_bv);
{
// already done
PRECONDITION(false);

Check warning on line 79 in src/solvers/flattening/boolbv_with.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_with.cpp#L79

Added line #L79 was not covered by tests
}
else if(type.id()==ID_struct)
return convert_with_struct(
to_struct_type(type), where, new_value, prev_bv, next_bv);
Expand Down Expand Up @@ -151,36 +166,6 @@ void boolbvt::convert_with_array(
}
}

void boolbvt::convert_with_bv(
const exprt &index,
const exprt &new_value,
const bvt &prev_bv,
bvt &next_bv)
{
literalt l = convert(new_value);

if(const auto index_value_opt = numeric_cast<mp_integer>(index))
{
next_bv=prev_bv;

if(*index_value_opt >= 0 && *index_value_opt < next_bv.size())
next_bv[numeric_cast_v<std::size_t>(*index_value_opt)] = l;

return;
}

typet counter_type = index.type();

for(std::size_t i=0; i<prev_bv.size(); i++)
{
exprt counter=from_integer(i, counter_type);

literalt eq_lit = convert(equal_exprt(index, counter));

next_bv[i]=prop.lselect(eq_lit, l, prev_bv[i]);
}
}

void boolbvt::convert_with_struct(
const struct_typet &type,
const exprt &where,
Expand Down

0 comments on commit 0e2502e

Please sign in to comment.