Skip to content

Commit 9d386d3

Browse files
Refactoring in boolbvt::convert_byte_extract
1 parent fb03a45 commit 9d386d3

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

src/solvers/flattening/boolbv_byte_extract.cpp

+12-24
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@ Author: Daniel Kroening, [email protected]
1919

2020
bvt map_bv(const endianness_mapt &map, const bvt &src)
2121
{
22-
assert(map.number_of_bits()==src.size());
23-
22+
PRECONDITION(map.number_of_bits() == src.size());
2423
bvt result;
2524
result.resize(src.size(), const_literal(false));
26-
2725
for(std::size_t i=0; i<src.size(); i++)
2826
{
29-
size_t mapped_index=map.map_bit(i);
30-
assert(mapped_index<src.size());
27+
const size_t mapped_index = map.map_bit(i);
28+
CHECK_RETURN(mapped_index < src.size());
3129
result[i]=src[mapped_index];
3230
}
33-
3431
return result;
3532
}
3633

3734
bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
3835
{
39-
if(expr.operands().size()!=2)
40-
throw "byte_extract takes two operands";
36+
PRECONDITION(expr.operands().size() == 2);
4137

4238
// if we extract from an unbounded array, call the flattening code
4339
if(is_unbounded_array(expr.op().type()))
4440
{
45-
exprt tmp=flatten_byte_extract(expr, ns);
41+
const exprt tmp = flatten_byte_extract(expr, ns);
4642
return convert_bv(tmp);
4743
}
4844

49-
std::size_t width=boolbv_width(expr.type());
45+
PRECONDITION(
46+
expr.id() == ID_byte_extract_little_endian ||
47+
expr.id() == ID_byte_extract_big_endian);
48+
49+
const std::size_t width = boolbv_width(expr.type());
5050

5151
// special treatment for bit-fields and big-endian:
5252
// we need byte granularity
@@ -69,22 +69,10 @@ bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
6969

7070
const exprt &op=expr.op();
7171
const exprt &offset=expr.offset();
72-
73-
bool little_endian;
74-
75-
if(expr.id()==ID_byte_extract_little_endian)
76-
little_endian=true;
77-
else if(expr.id()==ID_byte_extract_big_endian)
78-
little_endian=false;
79-
else
80-
{
81-
little_endian=false;
82-
assert(false);
83-
}
72+
const bool little_endian = expr.id() == ID_byte_extract_little_endian;
8473

8574
// first do op0
86-
87-
endianness_mapt op_map(op.type(), little_endian, ns);
75+
const endianness_mapt op_map(op.type(), little_endian, ns);
8876
const bvt op_bv=map_bv(op_map, convert_bv(op));
8977

9078
// do result

0 commit comments

Comments
 (0)