1919
2020/* ******************************************************************\
2121
22- Function: adjust_float_expressions
22+ Function: have_to_adjust_float_expressions
2323
2424 Inputs:
2525
2626 Outputs:
2727
28- Purpose: This adds the rounding mode to floating-point operations,
29- including those in vectors and complex numbers.
28+ Purpose:
3029
3130\*******************************************************************/
3231
33- void adjust_float_expressions (
34- exprt &expr,
32+ static bool have_to_adjust_float_expressions (
33+ const exprt &expr,
3534 const namespacet &ns)
3635{
3736 if (expr.id ()==ID_floatbv_plus ||
@@ -41,6 +40,68 @@ void adjust_float_expressions(
4140 expr.id ()==ID_floatbv_div ||
4241 expr.id ()==ID_floatbv_rem ||
4342 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))
44105 return ;
45106
46107 Forall_operands (it, expr)
0 commit comments