Skip to content

Commit d35c2ac

Browse files
Refactoring in boolbvt::convert_byte_extract
1 parent 1b43ee9 commit d35c2ac

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

src/solvers/flattening/boolbv_byte_extract.cpp

+9-26
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,28 @@ Author: Daniel Kroening, [email protected]
2323

2424
bvt map_bv(const bv_endianness_mapt &map, const bvt &src)
2525
{
26-
assert(map.number_of_bits()==src.size());
27-
26+
PRECONDITION(map.number_of_bits() == src.size());
2827
bvt result;
29-
result.resize(src.size(), const_literal(false));
28+
result.reserve(src.size());
3029

3130
for(std::size_t i=0; i<src.size(); i++)
3231
{
33-
size_t mapped_index=map.map_bit(i);
34-
assert(mapped_index<src.size());
35-
result[i]=src[mapped_index];
32+
const size_t mapped_index = map.map_bit(i);
33+
CHECK_RETURN(mapped_index < src.size());
34+
result.push_back(src[mapped_index]);
3635
}
3736

3837
return result;
3938
}
4039

4140
bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
4241
{
43-
if(expr.operands().size()!=2)
44-
throw "byte_extract takes two operands";
45-
4642
// if we extract from an unbounded array, call the flattening code
4743
if(is_unbounded_array(expr.op().type()))
4844
{
4945
try
5046
{
51-
exprt tmp = flatten_byte_extract(expr, ns);
52-
return convert_bv(tmp);
47+
return convert_bv(flatten_byte_extract(expr, ns));
5348
}
5449
catch(const flatten_byte_extract_exceptiont &byte_extract_flatten_exception)
5550
{
@@ -58,7 +53,7 @@ bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
5853
}
5954
}
6055

61-
std::size_t width=boolbv_width(expr.type());
56+
const std::size_t width = boolbv_width(expr.type());
6257

6358
// special treatment for bit-fields and big-endian:
6459
// we need byte granularity
@@ -105,22 +100,10 @@ bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
105100

106101
const exprt &op=expr.op();
107102
const exprt &offset=expr.offset();
108-
109-
bool little_endian;
110-
111-
if(expr.id()==ID_byte_extract_little_endian)
112-
little_endian=true;
113-
else if(expr.id()==ID_byte_extract_big_endian)
114-
little_endian=false;
115-
else
116-
{
117-
little_endian=false;
118-
assert(false);
119-
}
103+
const bool little_endian = expr.id() == ID_byte_extract_little_endian;
120104

121105
// first do op0
122-
123-
bv_endianness_mapt op_map(op.type(), little_endian, ns, boolbv_width);
106+
const bv_endianness_mapt op_map(op.type(), little_endian, ns, boolbv_width);
124107
const bvt op_bv=map_bv(op_map, convert_bv(op));
125108

126109
// do result

0 commit comments

Comments
 (0)