Skip to content

Commit 932a38f

Browse files
authored
Merge pull request diffblue#1827 from karkhaz/kk-symex-operator-tidy
[path explore 1/8] Tidy up symext top-level funs
2 parents 2bb98d9 + b4cadf8 commit 932a38f

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

src/cbmc/bmc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ safety_checkert::resultt bmct::execute(const goto_functionst &goto_functions)
360360
try
361361
{
362362
// perform symbolic execution
363-
symex(goto_functions);
363+
symex.symex_from_entry_point_of(goto_functions);
364364

365365
// add a partial ordering, if required
366366
if(equation.has_threads())

src/goto-instrument/accelerate/scratch_program.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool scratch_programt::check_sat(bool do_slice)
3939
symex.constant_propagation=constant_propagation;
4040
goto_symex_statet::propagationt::valuest constants;
4141

42-
symex(symex_state, functions, *this);
42+
symex.symex_with_state(symex_state, functions, *this);
4343

4444
if(do_slice)
4545
{

src/goto-symex/goto_symex.h

+20-13
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class side_effect_exprt;
3737
class symex_targett;
3838
class typecast_exprt;
3939

40-
/*! \brief The main class for the forward symbolic simulator
41-
*/
40+
/// \brief The main class for the forward symbolic simulator
4241
class goto_symext
4342
{
4443
public:
@@ -68,17 +67,23 @@ class goto_symext
6867

6968
typedef goto_symex_statet statet;
7069

71-
/** symex all at once, starting from entry point */
72-
virtual void operator()(
70+
/// \brief symex entire program starting from entry point
71+
///
72+
/// The state that goto_symext maintains has a large memory footprint.
73+
/// This method deallocates the state as soon as symbolic execution
74+
/// has completed, so use it if you don't care about having the state
75+
/// around afterwards.
76+
virtual void symex_from_entry_point_of(
7377
const goto_functionst &goto_functions);
7478

75-
/** symex starting from given goto program */
76-
virtual void operator()(
77-
const goto_functionst &goto_functions,
78-
const goto_programt &goto_program);
79-
80-
/** start symex in a given state */
81-
virtual void operator()(
79+
//// \brief symex entire program starting from entry point
80+
///
81+
/// This method uses the `state` argument as the symbolic execution
82+
/// state, which is useful for examining the state after this method
83+
/// returns. The state that goto_symext maintains has a large memory
84+
/// footprint, so if keeping the state around is not necessary,
85+
/// clients should instead call goto_symext::symex_from_entry_point_of().
86+
virtual void symex_with_state(
8287
statet &state,
8388
const goto_functionst &goto_functions,
8489
const goto_programt &goto_program);
@@ -91,20 +96,21 @@ class goto_symext
9196
/// \param goto_functions GOTO model to symex.
9297
/// \param first Entry point in form of a first instruction.
9398
/// \param limit Final instruction, which itself will not be symexed.
94-
virtual void operator()(
99+
virtual void symex_instruction_range(
95100
statet &state,
96101
const goto_functionst &goto_functions,
97102
goto_programt::const_targett first,
98103
goto_programt::const_targett limit);
99104

105+
protected:
100106
/// Initialise the symbolic execution and the given state with <code>pc</code>
101107
/// as entry point.
102108
/// \param state Symex state to initialise.
103109
/// \param goto_functions GOTO model to symex.
104110
/// \param pc first instruction to symex
105111
/// \param limit final instruction, which itself will not
106112
/// be symexed.
107-
void symex_entry_point(
113+
void initialize_entry_point(
108114
statet &state,
109115
const goto_functionst &goto_functions,
110116
goto_programt::const_targett pc,
@@ -122,6 +128,7 @@ class goto_symext
122128
const goto_functionst &goto_functions,
123129
statet &state);
124130

131+
public:
125132
// these bypass the target maps
126133
virtual void symex_step_goto(statet &state, bool taken);
127134

src/goto-symex/symex_main.cpp

+9-17
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void goto_symext::rewrite_quantifiers(exprt &expr, statet &state)
124124
}
125125
}
126126

127-
void goto_symext::symex_entry_point(
127+
void goto_symext::initialize_entry_point(
128128
statet &state,
129129
const goto_functionst &goto_functions,
130130
const goto_programt::const_targett pc,
@@ -159,14 +159,13 @@ void goto_symext::symex_threaded_step(
159159
}
160160
}
161161

162-
/// symex from given state
163-
void goto_symext::operator()(
162+
void goto_symext::symex_with_state(
164163
statet &state,
165164
const goto_functionst &goto_functions,
166165
const goto_programt &goto_program)
167166
{
168167
PRECONDITION(!goto_program.instructions.empty());
169-
symex_entry_point(
168+
initialize_entry_point(
170169
state,
171170
goto_functions,
172171
goto_program.instructions.begin(),
@@ -179,28 +178,20 @@ void goto_symext::operator()(
179178
state.dirty=nullptr;
180179
}
181180

182-
void goto_symext::operator()(
181+
void goto_symext::symex_instruction_range(
183182
statet &state,
184183
const goto_functionst &goto_functions,
185184
const goto_programt::const_targett first,
186185
const goto_programt::const_targett limit)
187186
{
188-
symex_entry_point(state, goto_functions, first, limit);
187+
initialize_entry_point(state, goto_functions, first, limit);
189188
while(state.source.pc->function!=limit->function || state.source.pc!=limit)
190189
symex_threaded_step(state, goto_functions);
191190
}
192191

193-
/// symex starting from given program
194-
void goto_symext::operator()(
195-
const goto_functionst &goto_functions,
196-
const goto_programt &goto_program)
197-
{
198-
statet state;
199-
operator() (state, goto_functions, goto_program);
200-
}
201-
202192
/// symex from entry point
203-
void goto_symext::operator()(const goto_functionst &goto_functions)
193+
void goto_symext::symex_from_entry_point_of(
194+
const goto_functionst &goto_functions)
204195
{
205196
goto_functionst::function_mapt::const_iterator it=
206197
goto_functions.function_map.find(goto_functionst::entry_point());
@@ -210,7 +201,8 @@ void goto_symext::operator()(const goto_functionst &goto_functions)
210201

211202
const goto_programt &body=it->second.body;
212203

213-
operator()(goto_functions, body);
204+
statet state;
205+
symex_with_state(state, goto_functions, body);
214206
}
215207

216208
/// do just one step

0 commit comments

Comments
 (0)