19
19
20
20
/* ******************************************************************\
21
21
22
- Function: adjust_float_expressions
22
+ Function: have_to_adjust_float_expressions
23
23
24
24
Inputs:
25
25
26
26
Outputs:
27
27
28
- Purpose: This adds the rounding mode to floating-point operations,
29
- including those in vectors and complex numbers.
28
+ Purpose:
30
29
31
30
\*******************************************************************/
32
31
33
- void adjust_float_expressions (
34
- exprt &expr,
32
+ static bool have_to_adjust_float_expressions (
33
+ const exprt &expr,
35
34
const namespacet &ns)
36
35
{
37
36
if (expr.id ()==ID_floatbv_plus ||
@@ -41,6 +40,68 @@ void adjust_float_expressions(
41
40
expr.id ()==ID_floatbv_div ||
42
41
expr.id ()==ID_floatbv_rem ||
43
42
expr.id ()==ID_floatbv_typecast)
43
+ return false ;
44
+
45
+ const typet &type=ns.follow (expr.type ());
46
+
47
+ if (type.id ()==ID_floatbv ||
48
+ (type.id ()==ID_complex &&
49
+ ns.follow (type.subtype ()).id ()==ID_floatbv))
50
+ {
51
+ if (expr.id ()==ID_plus || expr.id ()==ID_minus ||
52
+ expr.id ()==ID_mult || expr.id ()==ID_div ||
53
+ expr.id ()==ID_rem)
54
+ return true ;
55
+ }
56
+
57
+ if (expr.id ()==ID_typecast)
58
+ {
59
+ const typecast_exprt &typecast_expr=to_typecast_expr (expr);
60
+
61
+ const typet &src_type=typecast_expr.op ().type ();
62
+ const typet &dest_type=typecast_expr.type ();
63
+
64
+ if (dest_type.id ()==ID_floatbv &&
65
+ src_type.id ()==ID_floatbv)
66
+ return true ;
67
+ else if (dest_type.id ()==ID_floatbv &&
68
+ (src_type.id ()==ID_c_bool ||
69
+ src_type.id ()==ID_signedbv ||
70
+ src_type.id ()==ID_unsignedbv ||
71
+ src_type.id ()==ID_c_enum_tag))
72
+ return true ;
73
+ else if ((dest_type.id ()==ID_signedbv ||
74
+ dest_type.id ()==ID_unsignedbv ||
75
+ dest_type.id ()==ID_c_enum_tag) &&
76
+ src_type.id ()==ID_floatbv)
77
+ return true ;
78
+ }
79
+
80
+ forall_operands (it, expr)
81
+ if (have_to_adjust_float_expressions (*it, ns))
82
+ return true ;
83
+
84
+ return false ;
85
+ }
86
+
87
+ /* ******************************************************************\
88
+
89
+ Function: adjust_float_expressions
90
+
91
+ Inputs:
92
+
93
+ Outputs:
94
+
95
+ Purpose: This adds the rounding mode to floating-point operations,
96
+ including those in vectors and complex numbers.
97
+
98
+ \*******************************************************************/
99
+
100
+ void adjust_float_expressions (
101
+ exprt &expr,
102
+ const namespacet &ns)
103
+ {
104
+ if (!have_to_adjust_float_expressions (expr, ns))
44
105
return ;
45
106
46
107
Forall_operands (it, expr)
0 commit comments