Skip to content

Commit 8542137

Browse files
author
Daniel Kroening
committed
adjust_float_expressions can now take a rounding mode argument
1 parent 6ccce5b commit 8542137

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

src/goto-programs/adjust_float_expressions.cpp

+28-22
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ Author: Daniel Kroening, [email protected]
2020

2121
#include "goto_model.h"
2222

23-
static bool have_to_adjust_float_expressions(
24-
const exprt &expr,
25-
const namespacet &ns)
23+
static bool have_to_adjust_float_expressions(const exprt &expr)
2624
{
2725
if(expr.id()==ID_floatbv_plus ||
2826
expr.id()==ID_floatbv_minus ||
@@ -33,11 +31,11 @@ static bool have_to_adjust_float_expressions(
3331
expr.id()==ID_floatbv_typecast)
3432
return false;
3533

36-
const typet &type=ns.follow(expr.type());
34+
const typet &type=expr.type();
3735

3836
if(type.id()==ID_floatbv ||
3937
(type.id()==ID_complex &&
40-
ns.follow(type.subtype()).id()==ID_floatbv))
38+
type.subtype().id()==ID_floatbv))
4139
{
4240
if(expr.id()==ID_plus || expr.id()==ID_minus ||
4341
expr.id()==ID_mult || expr.id()==ID_div ||
@@ -69,7 +67,7 @@ static bool have_to_adjust_float_expressions(
6967
}
7068

7169
forall_operands(it, expr)
72-
if(have_to_adjust_float_expressions(*it, ns))
70+
if(have_to_adjust_float_expressions(*it))
7371
return true;
7472

7573
return false;
@@ -79,25 +77,21 @@ static bool have_to_adjust_float_expressions(
7977
/// vectors and complex numbers.
8078
void adjust_float_expressions(
8179
exprt &expr,
82-
const namespacet &ns)
80+
const exprt &rounding_mode)
8381
{
84-
if(!have_to_adjust_float_expressions(expr, ns))
82+
if(!have_to_adjust_float_expressions(expr))
8583
return;
8684

87-
Forall_operands(it, expr)
88-
adjust_float_expressions(*it, ns);
85+
// recursive call
86+
for(auto &op : expr.operands())
87+
adjust_float_expressions(op, rounding_mode);
8988

90-
const typet &type=ns.follow(expr.type());
89+
const typet &type=expr.type();
9190

9291
if(type.id()==ID_floatbv ||
9392
(type.id()==ID_complex &&
94-
ns.follow(type.subtype()).id()==ID_floatbv))
93+
type.subtype().id()==ID_floatbv))
9594
{
96-
symbol_exprt rounding_mode=
97-
ns.lookup(CPROVER_PREFIX "rounding_mode").symbol_expr();
98-
99-
rounding_mode.add_source_location()=expr.source_location();
100-
10195
if(expr.id()==ID_plus || expr.id()==ID_minus ||
10296
expr.id()==ID_mult || expr.id()==ID_div ||
10397
expr.id()==ID_rem)
@@ -128,11 +122,6 @@ void adjust_float_expressions(
128122
const typet &src_type=typecast_expr.op().type();
129123
const typet &dest_type=typecast_expr.type();
130124

131-
symbol_exprt rounding_mode=
132-
ns.lookup(CPROVER_PREFIX "rounding_mode").symbol_expr();
133-
134-
rounding_mode.add_source_location()=expr.source_location();
135-
136125
if(dest_type.id()==ID_floatbv &&
137126
src_type.id()==ID_floatbv)
138127
{
@@ -179,6 +168,23 @@ void adjust_float_expressions(
179168
}
180169
}
181170

171+
/// This adds the rounding mode to floating-point operations, including those in
172+
/// vectors and complex numbers.
173+
void adjust_float_expressions(
174+
exprt &expr,
175+
const namespacet &ns)
176+
{
177+
if(!have_to_adjust_float_expressions(expr))
178+
return;
179+
180+
symbol_exprt rounding_mode=
181+
ns.lookup(CPROVER_PREFIX "rounding_mode").symbol_expr();
182+
183+
rounding_mode.add_source_location()=expr.source_location();
184+
185+
adjust_float_expressions(expr, rounding_mode);
186+
}
187+
182188
void adjust_float_expressions(
183189
goto_functionst::goto_functiont &goto_function,
184190
const namespacet &ns)

src/goto-programs/adjust_float_expressions.h

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ void adjust_float_expressions(
2222
exprt &expr,
2323
const namespacet &ns);
2424

25+
void adjust_float_expressions(
26+
exprt &expr,
27+
const exprt &rounding_mode);
28+
2529
void adjust_float_expressions(
2630
goto_functionst::goto_functiont &goto_function,
2731
const namespacet &ns);

0 commit comments

Comments
 (0)