12
12
13
13
bvt boolbvt::convert_mult (const exprt &expr)
14
14
{
15
- std::size_t width=boolbv_width (expr.type ());
16
-
15
+ const std::size_t width = boolbv_width (expr.type ());
17
16
if (width==0 )
18
17
return conversion_failed (expr);
19
-
20
18
bvt bv;
21
19
bv.resize (width);
22
20
23
21
const exprt::operandst &operands=expr.operands ();
24
- if (operands.empty ())
25
- throw " mult without operands" ;
26
-
22
+ DATA_INVARIANT (!operands.empty (), " mult must have operands" );
27
23
const exprt &op0=expr.op0 ();
28
-
29
- bool no_overflow=expr.id ()==" no-overflow-mult" ;
24
+ const bool no_overflow = expr.id () == " no-overflow-mult" ;
30
25
31
26
if (expr.type ().id ()==ID_fixedbv)
32
27
{
33
- if (op0.type ()!=expr.type ())
34
- throw " multiplication with mixed types" ;
35
-
28
+ DATA_INVARIANT (op0.type () == expr.type (), " multiplication with mixed types" );
36
29
bv=convert_bv (op0);
37
30
38
- if (bv.size ()!=width)
39
- throw " convert_mult: unexpected operand width" ;
40
-
41
- std::size_t fraction_bits=
31
+ DATA_INVARIANT (bv.size () == width, " convert_mult: unexpected operand width" );
32
+ const std::size_t fraction_bits =
42
33
to_fixedbv_type (expr.type ()).get_fraction_bits ();
43
34
44
35
for (exprt::operandst::const_iterator it=operands.begin ()+1 ;
45
36
it!=operands.end (); it++)
46
37
{
47
- if (it->type ()!=expr.type ())
48
- throw " multiplication with mixed types" ;
38
+ DATA_INVARIANT (
39
+ it->type () == expr.type (),
40
+ " multiplication should have uniform operand types" );
49
41
50
42
// do a sign extension by fraction_bits bits
51
43
bv=bv_utils.sign_extension (bv, bv.size ()+fraction_bits);
52
-
53
44
bvt op=convert_bv (*it);
54
45
55
- if (op.size ()!=width)
56
- throw " convert_mult: unexpected operand width" ;
57
-
46
+ INVARIANT (op.size () == width, " convert_mult: unexpected operand width" );
58
47
op=bv_utils.sign_extension (op, bv.size ());
59
-
60
48
bv=bv_utils.signed_multiplier (bv, op);
61
-
62
49
// cut it down again
63
50
bv.erase (bv.begin (), bv.begin ()+fraction_bits);
64
51
}
@@ -68,37 +55,25 @@ bvt boolbvt::convert_mult(const exprt &expr)
68
55
else if (expr.type ().id ()==ID_unsignedbv ||
69
56
expr.type ().id ()==ID_signedbv)
70
57
{
71
- if (op0.type ()!=expr.type ())
72
- throw " multiplication with mixed types" ;
73
-
58
+ DATA_INVARIANT (
59
+ op0.type () == expr.type (), " multiplication with mixed types" );
74
60
bv_utilst::representationt rep=
75
61
expr.type ().id ()==ID_signedbv?bv_utilst::representationt::SIGNED:
76
62
bv_utilst::representationt::UNSIGNED;
77
63
78
64
bv=convert_bv (op0);
79
-
80
- if (bv.size ()!=width)
81
- throw " convert_mult: unexpected operand width" ;
82
-
65
+ INVARIANT (bv.size () == width, " convert_mult: unexpected operand width" );
83
66
for (exprt::operandst::const_iterator it=operands.begin ()+1 ;
84
67
it!=operands.end (); it++)
85
68
{
86
- if (it->type ()!=expr.type ())
87
- throw " multiplication with mixed types" ;
88
-
69
+ INVARIANT (it->type () == expr.type (), " multiplication with mixed types" );
89
70
const bvt &op=convert_bv (*it);
71
+ CHECK_RETURN (op.size () == width);
90
72
91
- if (op.size ()!=width)
92
- throw " convert_mult: unexpected operand width" ;
93
-
94
- if (no_overflow)
95
- bv=bv_utils.multiplier_no_overflow (bv, op, rep);
96
- else
97
- bv=bv_utils.multiplier (bv, op, rep);
73
+ bv = no_overflow ? bv_utils.multiplier_no_overflow (bv, op, rep)
74
+ : bv_utils.multiplier (bv, op, rep);
98
75
}
99
-
100
76
return bv;
101
77
}
102
-
103
78
return conversion_failed (expr);
104
79
}
0 commit comments