Skip to content

Commit a0a1329

Browse files
committed
introduce rounding_mode_identifier()
This commit consolidates the various places in the CBMC source that contain the string CPROVER_PREFIX "rounding_mode". The usage in the C library are not included.
1 parent be17ef4 commit a0a1329

14 files changed

+42
-20
lines changed

jbmc/src/java_bytecode/java_bytecode_internal_additions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/std_types.h>
1919
#include <util/symbol_table_base.h>
2020

21+
#include <goto-programs/adjust_float_expressions.h>
22+
2123
void java_internal_additions(symbol_table_baset &dest)
2224
{
2325
// add __CPROVER_rounding_mode
2426

2527
{
2628
symbolt symbol;
27-
symbol.base_name = CPROVER_PREFIX "rounding_mode";
28-
symbol.name=CPROVER_PREFIX "rounding_mode";
29+
symbol.name = rounding_mode_identifier();
30+
symbol.base_name = symbol.name;
2931
symbol.type=signed_int_type();
3032
symbol.mode=ID_C;
3133
symbol.is_lvalue=true;

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414
#include <util/nondet.h>
1515
#include <util/suffix.h>
1616

17+
#include <goto-programs/adjust_float_expressions.h>
1718
#include <goto-programs/class_identifier.h>
1819
#include <goto-programs/goto_functions.h>
1920

@@ -120,7 +121,7 @@ void java_static_lifetime_init(
120121
code_blockt code_block;
121122

122123
const symbol_exprt rounding_mode =
123-
symbol_table.lookup_ref(CPROVER_PREFIX "rounding_mode").symbol_expr();
124+
symbol_table.lookup_ref(rounding_mode_identifier()).symbol_expr();
124125
code_block.add(
125126
code_assignt{rounding_mode, from_integer(0, rounding_mode.type())});
126127

src/analyses/constant_propagator.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Author: Peter Schrammel
1111

1212
#include "constant_propagator.h"
1313

14+
#include <goto-programs/adjust_float_expressions.h>
15+
1416
#ifdef DEBUG
1517
#include <iostream>
1618
#include <util/format_expr.h>
@@ -655,7 +657,7 @@ bool constant_propagator_domaint::partial_evaluate(
655657
// if the current rounding mode is top we can
656658
// still get a non-top result by trying all rounding
657659
// modes and checking if the results are all the same
658-
if(!known_values.is_constant(ID_cprover_rounding_mode_str))
660+
if(!known_values.is_constant(rounding_mode_identifier()))
659661
return partial_evaluate_with_all_rounding_modes(known_values, expr, ns);
660662

661663
return replace_constants_and_simplify(known_values, expr, ns);
@@ -685,7 +687,7 @@ bool constant_propagator_domaint::partial_evaluate_with_all_rounding_modes(
685687
{
686688
valuest tmp_values = known_values;
687689
tmp_values.set_to(
688-
symbol_exprt(ID_cprover_rounding_mode_str, integer_typet()),
690+
symbol_exprt(rounding_mode_identifier(), integer_typet()),
689691
from_integer(rounding_modes[i], integer_typet()));
690692
exprt result = expr;
691693
if(replace_constants_and_simplify(tmp_values, result, ns))

src/ansi-c/ansi_c_internal_additions.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <linking/static_lifetime_init.h>
1515

16+
#include <goto-programs/adjust_float_expressions.h>
17+
1618
const char gcc_builtin_headers_types[]=
1719
"# 1 \"gcc_builtin_headers_types.h\"\n"
1820
#include "gcc_builtin_headers_types.inc"
@@ -205,7 +207,8 @@ void ansi_c_internal_additions(std::string &code)
205207
CPROVER_PREFIX "constant_infinity_uint];\n"
206208

207209
// float stuff
208-
"int " CPROVER_PREFIX "thread_local " CPROVER_PREFIX "rounding_mode="+
210+
"int " CPROVER_PREFIX "thread_local " +
211+
id2string(rounding_mode_identifier()) + '='+
209212
std::to_string(config.ansi_c.rounding_mode)+";\n"
210213

211214
// pipes, write, read, close

src/cpp/cpp_internal_additions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Author: Daniel Kroening, [email protected]
1717

1818
#include <linking/static_lifetime_init.h>
1919

20+
#include <goto-programs/adjust_float_expressions.h>
21+
2022
std::string c2cpp(const std::string &s)
2123
{
2224
std::string result;
@@ -108,7 +110,7 @@ void cpp_internal_additions(std::ostream &out)
108110

109111
// float
110112
// TODO: should be thread_local
111-
out << "int " CPROVER_PREFIX "rounding_mode = "
113+
out << "int " << rounding_mode_identifier() << " = "
112114
<< std::to_string(config.ansi_c.rounding_mode) << ';' << '\n';
113115

114116
// pipes, write, read, close

src/cpp/module_dependencies.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ansi-c
22
cpp
3+
goto-programs
34
langapi # should go away
45
linking
56
util

src/goto-instrument/full_slicer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected]
1515
#include <util/find_symbols.h>
1616
#include <util/cprover_prefix.h>
1717

18+
#include <goto-programs/adjust_float_expressions.h>
1819
#include <goto-programs/remove_skip.h>
1920

2021
void full_slicert::add_dependencies(
@@ -248,7 +249,7 @@ static bool implicit(goto_programt::const_targett target)
248249

249250
const symbol_exprt &s=to_symbol_expr(a.lhs());
250251

251-
return s.get_identifier()==CPROVER_PREFIX "rounding_mode";
252+
return s.get_identifier() == rounding_mode_identifier();
252253
}
253254

254255
void full_slicert::operator()(

src/goto-programs/adjust_float_expressions.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ Author: Daniel Kroening, [email protected]
2121

2222
#include "goto_model.h"
2323

24+
irep_idt rounding_mode_identifier()
25+
{
26+
return CPROVER_PREFIX "rounding_mode";
27+
}
28+
2429
/// Iterate over an expression and check it or any of its subexpressions are
2530
/// floating point operations that haven't been adjusted with a rounding mode
2631
/// yet.
@@ -186,7 +191,7 @@ void adjust_float_expressions(exprt &expr, const namespacet &ns)
186191
return;
187192

188193
symbol_exprt rounding_mode =
189-
ns.lookup(CPROVER_PREFIX "rounding_mode").symbol_expr();
194+
ns.lookup(rounding_mode_identifier()).symbol_expr();
190195

191196
rounding_mode.add_source_location() = expr.source_location();
192197

src/goto-programs/adjust_float_expressions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ void adjust_float_expressions(
5656
/// \see adjust_float_expressions(goto_functionst &, const namespacet &)
5757
void adjust_float_expressions(goto_modelt &goto_model);
5858

59+
/// Return the identifier of the program symbol used to
60+
/// store the current rounding mode.
61+
irep_idt rounding_mode_identifier();
62+
5963
#endif // CPROVER_GOTO_PROGRAMS_ADJUST_FLOAT_EXPRESSIONS_H

src/jsil/jsil_entry_point.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Michael Tautschnig, [email protected]
1616
#include <util/message.h>
1717
#include <util/range.h>
1818

19+
#include <goto-programs/adjust_float_expressions.h>
1920
#include <goto-programs/goto_functions.h>
2021

2122
#include <linking/static_lifetime_init.h>
@@ -33,8 +34,8 @@ static void create_initialize(symbol_tablet &symbol_table)
3334

3435
namespacet ns(symbol_table);
3536

36-
symbol_exprt rounding_mode=
37-
ns.lookup(CPROVER_PREFIX "rounding_mode").symbol_expr();
37+
symbol_exprt rounding_mode =
38+
ns.lookup(rounding_mode_identifier()).symbol_expr();
3839

3940
code_assignt a(rounding_mode, from_integer(0, rounding_mode.type()));
4041
init_code.add(a);

src/jsil/jsil_internal_additions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Author: Michael Tautschnig, [email protected]
1111

1212
#include "jsil_internal_additions.h"
1313

14+
#include <goto-programs/adjust_float_expressions.h>
15+
1416
#include <util/std_types.h>
1517
#include <util/cprover_prefix.h>
1618
#include <util/symbol_table.h>
@@ -25,8 +27,8 @@ void jsil_internal_additions(symbol_tablet &dest)
2527

2628
{
2729
symbolt symbol;
28-
symbol.base_name = CPROVER_PREFIX "rounding_mode";
29-
symbol.name=CPROVER_PREFIX "rounding_mode";
30+
symbol.name = rounding_mode_identifier();
31+
symbol.base_name = symbol.name;
3032
symbol.type=signed_int_type();
3133
symbol.mode=ID_C;
3234
symbol.is_lvalue=true;

src/linking/remove_internal_symbols.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Author: Daniel Kroening
1111

1212
#include "remove_internal_symbols.h"
1313

14+
#include <goto-programs/adjust_float_expressions.h>
15+
1416
#include <util/config.h>
1517
#include <util/find_symbols.h>
1618
#include <util/message.h>
@@ -119,7 +121,7 @@ void remove_internal_symbols(
119121
special.insert(CPROVER_PREFIX "malloc_size");
120122
special.insert(CPROVER_PREFIX "deallocated");
121123
special.insert(CPROVER_PREFIX "dead_object");
122-
special.insert(CPROVER_PREFIX "rounding_mode");
124+
special.insert(rounding_mode_identifier());
123125
special.insert("__new");
124126
special.insert("__new_array");
125127
special.insert("__placement_new");

src/statement-list/statement_list_entry_point.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Matthias Weiss, [email protected]
1111

1212
#include "statement_list_entry_point.h"
1313

14+
#include <goto-programs/adjust_float_expressions.h>
1415
#include <goto-programs/goto_functions.h>
1516

1617
#include <linking/static_lifetime_init.h>
@@ -21,9 +22,6 @@ Author: Matthias Weiss, [email protected]
2122
#include <util/pointer_expr.h>
2223
#include <util/std_code.h>
2324

24-
/// Name of the CPROVER-specific variable that specifies the rounding mode.
25-
#define ROUNDING_MODE_NAME CPROVER_PREFIX "rounding_mode"
26-
2725
/// Postfix for the artificial data block that is created when calling a main
2826
/// symbol that is a function block.
2927
#define DB_ENTRY_POINT_POSTFIX "_entry_point"
@@ -146,7 +144,7 @@ static void generate_statement_list_init_function(symbol_tablet &symbol_table)
146144
static void generate_rounding_mode(symbol_tablet &symbol_table)
147145
{
148146
symbolt rounding_mode;
149-
rounding_mode.name = ROUNDING_MODE_NAME;
147+
rounding_mode.name = rounding_mode_identifier();
150148
rounding_mode.type = signed_int_type();
151149
rounding_mode.is_thread_local = true;
152150
rounding_mode.is_static_lifetime = true;

src/util/ieee_float.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ Author: Daniel Kroening, [email protected]
1919
class constant_exprt;
2020
class floatbv_typet;
2121

22-
const char ID_cprover_rounding_mode_str[] = CPROVER_PREFIX "rounding_mode";
23-
2422
class ieee_float_spect
2523
{
2624
public:

0 commit comments

Comments
 (0)