12
12
13
13
bvt boolbvt::convert_extractbits (const extractbits_exprt &expr)
14
14
{
15
- std::size_t width= boolbv_width (expr.type ());
15
+ const std::size_t bv_width = boolbv_width (expr.type ());
16
16
17
- if (width== 0 )
17
+ if (bv_width == 0 )
18
18
return conversion_failed (expr);
19
19
20
20
if (expr.operands ().size ()!=3 )
@@ -24,50 +24,52 @@ bvt boolbvt::convert_extractbits(const extractbits_exprt &expr)
24
24
throw 0 ;
25
25
}
26
26
27
- mp_integer o1, o2 ;
28
- const bvt &bv0= convert_bv (expr.op0 ());
27
+ mp_integer upper_as_int, lower_as_int ;
28
+ auto const &src_bv = convert_bv (expr.src ());
29
29
30
30
// We only do constants for now.
31
31
// Should implement a shift here.
32
- if (to_integer (expr.op1 (), o1) ||
33
- to_integer (expr.op2 (), o2))
32
+ if (
33
+ to_integer (expr.op1 (), upper_as_int) ||
34
+ to_integer (expr.op2 (), lower_as_int))
34
35
return conversion_failed (expr);
35
36
36
- if (o1< 0 || o1>=bv0 .size ())
37
+ if (upper_as_int < 0 || upper_as_int >= src_bv .size ())
37
38
{
38
39
error ().source_location =expr.find_source_location ();
39
40
error () << " extractbits: second operand out of range: "
40
41
<< expr.pretty () << eom;
41
42
}
42
43
43
- if (o2< 0 || o2>=bv0 .size ())
44
+ if (lower_as_int < 0 || lower_as_int >= src_bv .size ())
44
45
{
45
46
error ().source_location =expr.find_source_location ();
46
47
error () << " extractbits: third operand out of range: "
47
48
<< expr.pretty () << eom;
48
49
throw 0 ;
49
50
}
50
51
51
- if (o2>o1 )
52
- std::swap (o1, o2 );
52
+ if (lower_as_int > upper_as_int )
53
+ std::swap (upper_as_int, lower_as_int );
53
54
54
55
// now lower_as_int <= upper_as_int
55
56
56
- if ((o1-o2+ 1 )!=width )
57
+ if ((upper_as_int - lower_as_int + 1 ) != bv_width )
57
58
{
58
59
error ().source_location =expr.find_source_location ();
59
- error () << " extractbits: wrong width (expected " << (o1-o2+1 )
60
- << " but got " << width << " ): " << expr.pretty () << eom;
60
+ error () << " extractbits: wrong width (expected "
61
+ << (upper_as_int - lower_as_int + 1 ) << " but got " << bv_width
62
+ << " ): " << expr.pretty () << eom;
61
63
throw 0 ;
62
64
}
63
65
64
- std::size_t offset= integer2unsigned (o2 );
66
+ const std::size_t offset = integer2unsigned (lower_as_int );
65
67
66
- bvt bv ;
67
- bv .resize (width );
68
+ bvt result_bv ;
69
+ result_bv .resize (bv_width );
68
70
69
- for (std::size_t i= 0 ; i<width ; i++)
70
- bv [i]=bv0 [offset+ i];
71
+ for (std::size_t i = 0 ; i < bv_width ; i++)
72
+ result_bv [i] = src_bv [offset + i];
71
73
72
- return bv ;
74
+ return result_bv ;
73
75
}
0 commit comments