19
19
20
20
bvt map_bv (const endianness_mapt &map, const bvt &src)
21
21
{
22
- assert (map.number_of_bits ()==src.size ());
23
-
22
+ PRECONDITION (map.number_of_bits () == src.size ());
24
23
bvt result;
25
24
result.resize (src.size (), const_literal (false ));
26
-
27
25
for (std::size_t i=0 ; i<src.size (); i++)
28
26
{
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 ());
31
29
result[i]=src[mapped_index];
32
30
}
33
-
34
31
return result;
35
32
}
36
33
37
34
bvt boolbvt::convert_byte_extract (const byte_extract_exprt &expr)
38
35
{
39
- if (expr.operands ().size ()!=2 )
40
- throw " byte_extract takes two operands" ;
36
+ PRECONDITION (expr.operands ().size () == 2 );
41
37
42
38
// if we extract from an unbounded array, call the flattening code
43
39
if (is_unbounded_array (expr.op ().type ()))
44
40
{
45
- exprt tmp= flatten_byte_extract (expr, ns);
41
+ const exprt tmp = flatten_byte_extract (expr, ns);
46
42
return convert_bv (tmp);
47
43
}
48
44
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 ());
50
50
51
51
// special treatment for bit-fields and big-endian:
52
52
// we need byte granularity
@@ -69,22 +69,10 @@ bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
69
69
70
70
const exprt &op=expr.op ();
71
71
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;
84
73
85
74
// 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);
88
76
const bvt op_bv=map_bv (op_map, convert_bv (op));
89
77
90
78
// do result
0 commit comments