Skip to content

Commit 45a4363

Browse files
Merge pull request #3433 from romainbrenguier/refactor/symex-nondet-count
Refactoring in symex, replace nondet_count by a functor
2 parents f5eedc4 + 8fb2902 commit 45a4363

File tree

4 files changed

+46
-37
lines changed

4 files changed

+46
-37
lines changed

src/goto-symex/goto_symex.cpp

+1-16
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <util/simplify_expr.h>
1515

16-
unsigned goto_symext::nondet_count=0;
1716
unsigned goto_symext::dynamic_counter=0;
1817

1918
void goto_symext::do_simplify(exprt &expr)
@@ -22,23 +21,9 @@ void goto_symext::do_simplify(exprt &expr)
2221
simplify(expr, ns);
2322
}
2423

25-
nondet_symbol_exprt goto_symext::build_symex_nondet(typet &type)
24+
nondet_symbol_exprt symex_nondet_generatort::operator()(typet &type)
2625
{
2726
irep_idt identifier = "symex::nondet" + std::to_string(nondet_count++);
2827
nondet_symbol_exprt new_expr(identifier, type);
2928
return new_expr;
3029
}
31-
32-
void goto_symext::replace_nondet(exprt &expr)
33-
{
34-
if(expr.id()==ID_side_effect &&
35-
expr.get(ID_statement)==ID_nondet)
36-
{
37-
nondet_symbol_exprt new_expr = build_symex_nondet(expr.type());
38-
new_expr.add_source_location()=expr.source_location();
39-
expr.swap(new_expr);
40-
}
41-
else
42-
Forall_operands(it, expr)
43-
replace_nondet(*it);
44-
}

src/goto-symex/goto_symex.h

+18-17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ class namespacet;
3838
class side_effect_exprt;
3939
class typecast_exprt;
4040

41+
/// Functor generating fresh nondet symbols
42+
class symex_nondet_generatort
43+
{
44+
public:
45+
nondet_symbol_exprt operator()(typet &type);
46+
47+
private:
48+
unsigned nondet_count = 0;
49+
};
50+
4151
/// \brief The main class for the forward symbolic simulator
4252
///
4353
/// Higher-level architectural information on symbolic execution is
@@ -238,19 +248,6 @@ class goto_symext
238248

239249
const irep_idt guard_identifier;
240250

241-
// symex
242-
virtual void symex_transition(
243-
statet &,
244-
goto_programt::const_targett to,
245-
bool is_backwards_goto);
246-
247-
virtual void symex_transition(statet &state)
248-
{
249-
goto_programt::const_targett next=state.source.pc;
250-
++next;
251-
symex_transition(state, next, false);
252-
}
253-
254251
virtual void symex_goto(statet &);
255252
virtual void symex_start_thread(statet &);
256253
virtual void symex_atomic_begin(statet &);
@@ -333,8 +330,6 @@ class goto_symext
333330
statet &,
334331
const goto_functionst::goto_functiont &);
335332

336-
nondet_symbol_exprt build_symex_nondet(typet &type);
337-
338333
// exceptions
339334
void symex_throw(statet &);
340335
void symex_catch(statet &);
@@ -414,10 +409,9 @@ class goto_symext
414409
virtual void symex_input(statet &, const codet &);
415410
virtual void symex_output(statet &, const codet &);
416411

417-
static unsigned nondet_count;
412+
symex_nondet_generatort build_symex_nondet;
418413
static unsigned dynamic_counter;
419414

420-
void replace_nondet(exprt &);
421415
void rewrite_quantifiers(exprt &, statet &);
422416

423417
path_storaget &path_storage;
@@ -465,4 +459,11 @@ class goto_symext
465459
}
466460
};
467461

462+
void symex_transition(goto_symext::statet &state);
463+
464+
void symex_transition(
465+
goto_symext::statet &,
466+
goto_programt::const_targett to,
467+
bool is_backwards_goto);
468+
468469
#endif // CPROVER_GOTO_SYMEX_GOTO_SYMEX_H

src/goto-symex/symex_clean_expr.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,28 @@ static void adjust_byte_extract_rec(exprt &expr, const namespacet &ns)
135135
}
136136
}
137137

138+
static void
139+
replace_nondet(exprt &expr, symex_nondet_generatort &build_symex_nondet)
140+
{
141+
if(expr.id() == ID_side_effect && expr.get(ID_statement) == ID_nondet)
142+
{
143+
nondet_symbol_exprt new_expr = build_symex_nondet(expr.type());
144+
new_expr.add_source_location() = expr.source_location();
145+
expr.swap(new_expr);
146+
}
147+
else
148+
{
149+
Forall_operands(it, expr)
150+
replace_nondet(*it, build_symex_nondet);
151+
}
152+
}
153+
138154
void goto_symext::clean_expr(
139155
exprt &expr,
140156
statet &state,
141157
const bool write)
142158
{
143-
replace_nondet(expr);
159+
replace_nondet(expr, build_symex_nondet);
144160
dereference(expr, state, write);
145161

146162
// make sure all remaining byte extract operations use the root

src/goto-symex/symex_main.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Author: Daniel Kroening, [email protected]
2222

2323
#include <analyses/dirty.h>
2424

25-
void goto_symext::symex_transition(
26-
statet &state,
25+
void symex_transition(
26+
goto_symext::statet &state,
2727
goto_programt::const_targett to,
2828
bool is_backwards_goto)
2929
{
@@ -34,7 +34,7 @@ void goto_symext::symex_transition(
3434
// 1. the transition from state.source.pc to "to" is not a backwards goto
3535
// or
3636
// 2. we are arriving from an outer loop
37-
statet::framet &frame=state.top();
37+
goto_symext::statet::framet &frame = state.top();
3838
const goto_programt::instructiont &instruction=*to;
3939
for(const auto &i_e : instruction.incoming_edges)
4040
if(i_e->is_goto() && i_e->is_backwards_goto() &&
@@ -46,6 +46,13 @@ void goto_symext::symex_transition(
4646
state.source.pc=to;
4747
}
4848

49+
void symex_transition(goto_symext::statet &state)
50+
{
51+
goto_programt::const_targett next = state.source.pc;
52+
++next;
53+
symex_transition(state, next, false);
54+
}
55+
4956
void goto_symext::vcc(
5057
const exprt &vcc_expr,
5158
const std::string &msg,

0 commit comments

Comments
 (0)