Skip to content

Commit 7a98892

Browse files
authored
Merge pull request #3431 from romainbrenguier/refactor/symex-config
Group symex options into symex_config structure
2 parents 53c7a82 + bf8e58b commit 7a98892

7 files changed

+49
-37
lines changed

src/goto-symex/goto_symex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ unsigned goto_symext::dynamic_counter=0;
1717

1818
void goto_symext::do_simplify(exprt &expr)
1919
{
20-
if(simplify_opt)
20+
if(symex_config.simplify_opt)
2121
simplify(expr, ns);
2222
}
2323

src/goto-symex/goto_symex.h

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ class symex_nondet_generatort
4848
unsigned nondet_count = 0;
4949
};
5050

51+
/// Configuration of the symbolic execution
52+
struct symex_configt final
53+
{
54+
unsigned max_depth;
55+
bool doing_path_exploration;
56+
bool allow_pointer_unsoundness;
57+
bool constant_propagation;
58+
bool self_loops_to_assumptions;
59+
bool simplify_opt;
60+
bool unwinding_assertions;
61+
bool partial_loops;
62+
mp_integer debug_level;
63+
64+
explicit symex_configt(const optionst &options);
65+
};
66+
5167
/// \brief The main class for the forward symbolic simulator
5268
///
5369
/// Higher-level architectural information on symbolic execution is
@@ -65,18 +81,8 @@ class goto_symext
6581
const optionst &options,
6682
path_storaget &path_storage)
6783
: should_pause_symex(false),
68-
max_depth(options.get_unsigned_int_option("depth")),
69-
doing_path_exploration(options.is_set("paths")),
70-
allow_pointer_unsoundness(
71-
options.get_bool_option("allow-pointer-unsoundness")),
84+
symex_config(options),
7285
language_mode(),
73-
constant_propagation(options.get_bool_option("propagation")),
74-
self_loops_to_assumptions(
75-
options.get_bool_option("self-loops-to-assumptions")),
76-
simplify_opt(options.get_bool_option("simplify")),
77-
unwinding_assertions(options.get_bool_option("unwinding-assertions")),
78-
partial_loops(options.get_bool_option("partial-loops")),
79-
debug_level(options.get_option("debug-level")),
8086
outer_symbol_table(outer_symbol_table),
8187
ns(outer_symbol_table),
8288
target(_target),
@@ -150,6 +156,8 @@ class goto_symext
150156
bool should_pause_symex;
151157

152158
protected:
159+
const symex_configt symex_config;
160+
153161
/// Initialise the symbolic execution and the given state with <code>pc</code>
154162
/// as entry point.
155163
/// \param state Symex state to initialise.
@@ -176,23 +184,13 @@ class goto_symext
176184
const get_goto_functiont &,
177185
statet &);
178186

179-
const unsigned max_depth;
180-
const bool doing_path_exploration;
181-
const bool allow_pointer_unsoundness;
182-
183187
public:
184188

185189
/// language_mode: ID_java, ID_C or another language identifier
186190
/// if we know the source language in use, irep_idt() otherwise.
187191
irep_idt language_mode;
188192

189193
protected:
190-
const bool constant_propagation;
191-
const bool self_loops_to_assumptions;
192-
const bool simplify_opt;
193-
const bool unwinding_assertions;
194-
const bool partial_loops;
195-
const std::string debug_level;
196194

197195
/// The symbol table associated with the goto-program that we're
198196
/// executing. This symbol table will not additionally contain objects

src/goto-symex/symex_assign.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ void goto_symext::symex_assign_symbol(
247247
ssa_lhs,
248248
ssa_rhs,
249249
ns,
250-
simplify_opt,
251-
constant_propagation,
252-
allow_pointer_unsoundness);
250+
symex_config.simplify_opt,
251+
symex_config.constant_propagation,
252+
symex_config.allow_pointer_unsoundness);
253253

254254
exprt ssa_full_lhs=full_lhs;
255255
ssa_full_lhs=add_to_lhs(ssa_full_lhs, ssa_lhs);

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,6 @@ void goto_symext::symex_trace(
458458
{
459459
PRECONDITION(code.arguments().size() >= 2);
460460

461-
int debug_thresh = unsafe_string2int(debug_level);
462-
463461
mp_integer debug_lvl;
464462
optionalt<mp_integer> maybe_debug =
465463
numeric_cast<mp_integer>(code.arguments()[0]);
@@ -473,7 +471,7 @@ void goto_symext::symex_trace(
473471
code.arguments()[1].op0().id() == ID_string_constant,
474472
"CBMC_trace expects string constant as second argument");
475473

476-
if(mp_integer(debug_thresh)>=debug_lvl)
474+
if(symex_config.debug_level >= debug_lvl)
477475
{
478476
std::list<exprt> vars;
479477

src/goto-symex/symex_function_call.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ void goto_symext::symex_function_call_code(
236236
// see if it's too much
237237
if(stop_recursing)
238238
{
239-
if(partial_loops)
239+
if(symex_config.partial_loops)
240240
{
241241
// it's ok, ignore
242242
}
243243
else
244244
{
245-
if(unwinding_assertions)
245+
if(symex_config.unwinding_assertions)
246246
vcc(false_exprt(), "recursion unwinding assertion", state);
247247

248248
// add to state guard to prevent further assignments

src/goto-symex/symex_goto.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void goto_symext::symex_goto(statet &state)
6666
{
6767
// is it label: goto label; or while(cond); - popular in SV-COMP
6868
if(
69-
self_loops_to_assumptions &&
69+
symex_config.self_loops_to_assumptions &&
7070
(goto_target == state.source.pc ||
7171
(instruction.incoming_edges.size() == 1 &&
7272
*instruction.incoming_edges.begin() == goto_target)))
@@ -114,7 +114,7 @@ void goto_symext::symex_goto(statet &state)
114114
(simpl_state_guard.is_true() ||
115115
// or there is another block, but we're doing path exploration so
116116
// we're going to skip over it for now and return to it later.
117-
doing_path_exploration))
117+
symex_config.doing_path_exploration))
118118
{
119119
DATA_INVARIANT(
120120
instruction.targets.size() > 0,
@@ -181,7 +181,7 @@ void goto_symext::symex_goto(statet &state)
181181
log.debug() << "Resuming from next instruction '"
182182
<< state_pc->source_location << "'" << log.eom;
183183
}
184-
else if(doing_path_exploration)
184+
else if(symex_config.doing_path_exploration)
185185
{
186186
// We should save both the instruction after this goto, and the target of
187187
// the goto.
@@ -495,9 +495,9 @@ void goto_symext::loop_bound_exceeded(
495495
else
496496
negated_cond=not_exprt(guard);
497497

498-
if(!partial_loops)
498+
if(!symex_config.partial_loops)
499499
{
500-
if(unwinding_assertions)
500+
if(symex_config.unwinding_assertions)
501501
{
502502
// Generate VCC for unwinding assertion.
503503
vcc(negated_cond,

src/goto-symex/symex_main.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,26 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/make_unique.h>
1919
#include <util/replace_symbol.h>
2020
#include <util/std_expr.h>
21+
#include <util/string2int.h>
2122
#include <util/symbol_table.h>
2223

2324
#include <analyses/dirty.h>
2425

26+
symex_configt::symex_configt(const optionst &options)
27+
: max_depth(options.get_unsigned_int_option("depth")),
28+
doing_path_exploration(options.is_set("paths")),
29+
allow_pointer_unsoundness(
30+
options.get_bool_option("allow-pointer-unsoundness")),
31+
constant_propagation(options.get_bool_option("propagation")),
32+
self_loops_to_assumptions(
33+
options.get_bool_option("self-loops-to-assumptions")),
34+
simplify_opt(options.get_bool_option("simplify")),
35+
unwinding_assertions(options.get_bool_option("unwinding-assertions")),
36+
partial_loops(options.get_bool_option("partial-loops")),
37+
debug_level(unsafe_string2int(options.get_option("debug-level")))
38+
{
39+
}
40+
2541
void symex_transition(
2642
goto_symext::statet &state,
2743
goto_programt::const_targett to,
@@ -317,11 +333,11 @@ void goto_symext::symex_step(
317333

318334
const goto_programt::instructiont &instruction=*state.source.pc;
319335

320-
if(!doing_path_exploration)
336+
if(!symex_config.doing_path_exploration)
321337
merge_gotos(state);
322338

323339
// depth exceeded?
324-
if(max_depth != 0 && state.depth > max_depth)
340+
if(symex_config.max_depth != 0 && state.depth > symex_config.max_depth)
325341
state.guard.add(false_exprt());
326342
state.depth++;
327343

0 commit comments

Comments
 (0)