Skip to content

Commit 8984eb9

Browse files
Merge pull request #3797 from peterschrammel/refactor-path-strategy-chooser
Remove path strategy chooser from driver
2 parents af89377 + 50a9ef1 commit 8984eb9

9 files changed

+86
-107
lines changed

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Author: Daniel Kroening, [email protected]
4747
#include <goto-instrument/reachability_slicer.h>
4848
#include <goto-instrument/nondet_static.h>
4949

50+
#include <goto-symex/path_storage.h>
51+
5052
#include <linking/static_lifetime_init.h>
5153

5254
#include <pointer-analysis/add_failed_symbols.h>
@@ -67,8 +69,7 @@ Author: Daniel Kroening, [email protected]
6769
jbmc_parse_optionst::jbmc_parse_optionst(int argc, const char **argv)
6870
: parse_options_baset(JBMC_OPTIONS, argc, argv),
6971
messaget(ui_message_handler),
70-
ui_message_handler(cmdline, std::string("JBMC ") + CBMC_VERSION),
71-
path_strategy_chooser()
72+
ui_message_handler(cmdline, std::string("JBMC ") + CBMC_VERSION)
7273
{
7374
}
7475

@@ -78,8 +79,7 @@ ::jbmc_parse_optionst::jbmc_parse_optionst(
7879
const std::string &extra_options)
7980
: parse_options_baset(JBMC_OPTIONS + extra_options, argc, argv),
8081
messaget(ui_message_handler),
81-
ui_message_handler(cmdline, std::string("JBMC ") + CBMC_VERSION),
82-
path_strategy_chooser()
82+
ui_message_handler(cmdline, std::string("JBMC ") + CBMC_VERSION)
8383
{
8484
}
8585

@@ -119,11 +119,11 @@ void jbmc_parse_optionst::get_command_line_options(optionst &options)
119119

120120
if(cmdline.isset("show-symex-strategies"))
121121
{
122-
std::cout << path_strategy_chooser.show_strategies();
122+
status() << show_path_strategies() << eom;
123123
exit(CPROVER_EXIT_SUCCESS);
124124
}
125125

126-
path_strategy_chooser.set_path_strategy_options(cmdline, options, *this);
126+
parse_path_strategy_options(cmdline, options, ui_message_handler);
127127

128128
if(cmdline.isset("program-only"))
129129
options.set_option("program-only", true);
@@ -573,7 +573,6 @@ int jbmc_parse_optionst::doit()
573573
// The `configure_bmc` callback passed will enable enum-unwind-static if
574574
// applicable.
575575
return bmct::do_language_agnostic_bmc(
576-
path_strategy_chooser,
577576
options,
578577
goto_model,
579578
ui_message_handler,
@@ -618,7 +617,6 @@ int jbmc_parse_optionst::doit()
618617
// The `configure_bmc` callback passed will enable enum-unwind-static if
619618
// applicable.
620619
return bmct::do_language_agnostic_bmc(
621-
path_strategy_chooser,
622620
options,
623621
lazy_goto_model,
624622
ui_message_handler,

jbmc/src/jbmc/jbmc_parse_options.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ Author: Daniel Kroening, [email protected]
2828
#include <goto-programs/lazy_goto_model.h>
2929
#include <goto-programs/show_properties.h>
3030

31-
#include <goto-symex/path_storage.h>
32-
3331
#include <solvers/refinement/string_refinement.h>
3432

3533
#include <java_bytecode/java_bytecode_language.h>
@@ -120,7 +118,6 @@ class jbmc_parse_optionst:
120118

121119
protected:
122120
ui_message_handlert ui_message_handler;
123-
path_strategy_choosert path_strategy_chooser;
124121
java_object_factory_parameterst object_factory_params;
125122
bool stub_objects_are_not_null;
126123

src/cbmc/bmc.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ safety_checkert::resultt bmct::stop_on_fail()
255255

256256
/// Perform core BMC, using an abstract model to supply GOTO function bodies
257257
/// (perhaps created on demand).
258-
/// \param path_strategy_chooser: controls whether symex generates a single
259-
/// large equation for the whole program or an equation per path
260258
/// \param opts: command-line options affecting BMC
261259
/// \param model: provides goto function bodies and the symbol table, perhaps
262260
/// creating those function bodies on demand.
@@ -266,7 +264,6 @@ safety_checkert::resultt bmct::stop_on_fail()
266264
/// \param callback_after_symex: optional callback to be run after symex.
267265
/// See class member `bmct::driver_callback_after_symex` for details.
268266
int bmct::do_language_agnostic_bmc(
269-
const path_strategy_choosert &path_strategy_chooser,
270267
const optionst &opts,
271268
abstract_goto_modelt &model,
272269
ui_message_handlert &ui,
@@ -280,10 +277,7 @@ int bmct::do_language_agnostic_bmc(
280277
messaget message(ui);
281278
std::unique_ptr<path_storaget> worklist;
282279
std::string strategy = opts.get_option("exploration-strategy");
283-
INVARIANT(
284-
path_strategy_chooser.is_valid_strategy(strategy),
285-
"Front-end passed us invalid path strategy '" + strategy + "'");
286-
worklist = path_strategy_chooser.get(strategy);
280+
worklist = get_path_strategy(strategy);
287281
try
288282
{
289283
solver_factoryt solvers(

src/cbmc/bmc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ class bmct:public safety_checkert
118118
}
119119

120120
static int do_language_agnostic_bmc(
121-
const path_strategy_choosert &path_strategy_chooser,
122121
const optionst &opts,
123122
abstract_goto_modelt &goto_model,
124123
ui_message_handlert &ui,

src/cbmc/cbmc_parse_options.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Author: Daniel Kroening, [email protected]
5959
#include <goto-instrument/nondet_static.h>
6060
#include <goto-instrument/cover.h>
6161

62+
#include <goto-symex/path_storage.h>
63+
6264
#include <pointer-analysis/add_failed_symbols.h>
6365

6466
#include <langapi/mode.h>
@@ -69,8 +71,7 @@ cbmc_parse_optionst::cbmc_parse_optionst(int argc, const char **argv)
6971
: parse_options_baset(CBMC_OPTIONS, argc, argv),
7072
xml_interfacet(cmdline),
7173
messaget(ui_message_handler),
72-
ui_message_handler(cmdline, std::string("CBMC ") + CBMC_VERSION),
73-
path_strategy_chooser()
74+
ui_message_handler(cmdline, std::string("CBMC ") + CBMC_VERSION)
7475
{
7576
}
7677

@@ -81,8 +82,7 @@ ::cbmc_parse_optionst::cbmc_parse_optionst(
8182
: parse_options_baset(CBMC_OPTIONS + extra_options, argc, argv),
8283
xml_interfacet(cmdline),
8384
messaget(ui_message_handler),
84-
ui_message_handler(cmdline, std::string("CBMC ") + CBMC_VERSION),
85-
path_strategy_chooser()
85+
ui_message_handler(cmdline, std::string("CBMC ") + CBMC_VERSION)
8686
{
8787
}
8888

@@ -143,11 +143,11 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
143143

144144
if(cmdline.isset("show-symex-strategies"))
145145
{
146-
std::cout << path_strategy_chooser.show_strategies();
146+
status() << show_path_strategies() << eom;
147147
exit(CPROVER_EXIT_SUCCESS);
148148
}
149149

150-
path_strategy_chooser.set_path_strategy_options(cmdline, options, *this);
150+
parse_path_strategy_options(cmdline, options, ui_message_handler);
151151

152152
if(cmdline.isset("program-only"))
153153
options.set_option("program-only", true);
@@ -554,7 +554,7 @@ int cbmc_parse_optionst::doit()
554554
}
555555

556556
return bmct::do_language_agnostic_bmc(
557-
path_strategy_chooser, options, goto_model, ui_message_handler);
557+
options, goto_model, ui_message_handler);
558558
}
559559

560560
bool cbmc_parse_optionst::set_properties()

src/cbmc/cbmc_parse_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ class cbmc_parse_optionst:
116116
protected:
117117
goto_modelt goto_model;
118118
ui_message_handlert ui_message_handler;
119-
const path_strategy_choosert path_strategy_chooser;
120119

121120
void register_languages();
122121
void get_command_line_options(optionst &);

src/goto-symex/path_storage.cpp

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -82,54 +82,77 @@ void path_fifot::clear()
8282
// _____________________________________________________________________________
8383
// path_strategy_choosert
8484

85-
std::string path_strategy_choosert::show_strategies() const
85+
static const std::map<
86+
const std::string,
87+
std::pair<
88+
const std::string,
89+
const std::function<std::unique_ptr<path_storaget>()>>>
90+
path_strategies(
91+
{{"lifo",
92+
{" lifo next instruction is pushed before\n"
93+
" goto target; paths are popped in\n"
94+
" last-in, first-out order. Explores\n"
95+
" the program tree depth-first.\n",
96+
[]() { // NOLINT(whitespace/braces)
97+
return util_make_unique<path_lifot>();
98+
}}},
99+
{"fifo",
100+
{" fifo next instruction is pushed before\n"
101+
" goto target; paths are popped in\n"
102+
" first-in, first-out order. Explores\n"
103+
" the program tree breadth-first.\n",
104+
[]() { // NOLINT(whitespace/braces)
105+
return util_make_unique<path_fifot>();
106+
}}}});
107+
108+
std::string show_path_strategies()
86109
{
87110
std::stringstream ss;
88-
for(auto &pair : strategies)
111+
for(auto &pair : path_strategies)
89112
ss << pair.second.first;
90113
return ss.str();
91114
}
92115

93-
void path_strategy_choosert::set_path_strategy_options(
116+
std::string default_path_strategy()
117+
{
118+
return "lifo";
119+
}
120+
121+
bool is_valid_path_strategy(const std::string strategy)
122+
{
123+
return path_strategies.find(strategy) != path_strategies.end();
124+
}
125+
126+
std::unique_ptr<path_storaget> get_path_strategy(const std::string strategy)
127+
{
128+
auto found = path_strategies.find(strategy);
129+
INVARIANT(
130+
found != path_strategies.end(), "Unknown strategy '" + strategy + "'.");
131+
return found->second.second();
132+
}
133+
134+
void parse_path_strategy_options(
94135
const cmdlinet &cmdline,
95136
optionst &options,
96-
messaget &message) const
137+
message_handlert &message_handler)
97138
{
139+
messaget log(message_handler);
98140
if(cmdline.isset("paths"))
99141
{
100142
options.set_option("paths", true);
101143
std::string strategy = cmdline.get_value("paths");
102-
if(!is_valid_strategy(strategy))
144+
if(!is_valid_path_strategy(strategy))
103145
{
104-
message.error() << "Unknown strategy '" << strategy
105-
<< "'. Pass the --show-symex-strategies flag to list "
106-
"available strategies."
107-
<< message.eom;
146+
log.error() << "Unknown strategy '" << strategy
147+
<< "'. Pass the --show-symex-strategies flag to list "
148+
"available strategies."
149+
<< messaget::eom;
108150
exit(CPROVER_EXIT_USAGE_ERROR);
109151
}
110152
options.set_option("exploration-strategy", strategy);
111153
}
112154
else
113-
options.set_option("exploration-strategy", default_strategy());
114-
}
115-
116-
path_strategy_choosert::path_strategy_choosert()
117-
: strategies(
118-
{{"lifo",
119-
{" lifo next instruction is pushed before\n"
120-
" goto target; paths are popped in\n"
121-
" last-in, first-out order. Explores\n"
122-
" the program tree depth-first.\n",
123-
[]() { // NOLINT(whitespace/braces)
124-
return util_make_unique<path_lifot>();
125-
}}},
126-
{"fifo",
127-
{" fifo next instruction is pushed before\n"
128-
" goto target; paths are popped in\n"
129-
" first-in, first-out order. Explores\n"
130-
" the program tree breadth-first.\n",
131-
[]() { // NOLINT(whitespace/braces)
132-
return util_make_unique<path_fifot>();
133-
}}}})
134-
{
155+
{
156+
options.set_option("exploration-strategy", default_path_strategy());
157+
}
135158
}

src/goto-symex/path_storage.h

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -125,51 +125,21 @@ class path_fifot : public path_storaget
125125
void private_pop() override;
126126
};
127127

128-
/// \brief Factory and information for path_storaget
129-
class path_strategy_choosert
130-
{
131-
public:
132-
path_strategy_choosert();
133-
134-
/// \brief suitable for displaying as a front-end help message
135-
std::string show_strategies() const;
136-
137-
/// \brief is there a factory constructor for the named strategy?
138-
bool is_valid_strategy(const std::string strategy) const
139-
{
140-
return strategies.find(strategy) != strategies.end();
141-
}
142-
143-
/// \brief Factory for a path_storaget
144-
///
145-
/// Ensure that path_strategy_choosert::is_valid_strategy() returns true for a
146-
/// particular string before calling this function on that string.
147-
std::unique_ptr<path_storaget> get(const std::string strategy) const
148-
{
149-
auto found = strategies.find(strategy);
150-
INVARIANT(
151-
found != strategies.end(), "Unknown strategy '" + strategy + "'.");
152-
return found->second.second();
153-
}
154-
155-
/// \brief add `paths` and `exploration-strategy` option, suitable to be
156-
/// invoked from front-ends.
157-
void
158-
set_path_strategy_options(const cmdlinet &, optionst &, messaget &) const;
159-
160-
protected:
161-
std::string default_strategy() const
162-
{
163-
return "lifo";
164-
}
165-
166-
/// Map from the name of a strategy (to be supplied on the command line), to
167-
/// the help text for that strategy and a factory thunk returning a pointer to
168-
/// a derived class of path_storaget that implements that strategy.
169-
std::map<const std::string,
170-
std::pair<const std::string,
171-
const std::function<std::unique_ptr<path_storaget>()>>>
172-
strategies;
173-
};
128+
/// \brief suitable for displaying as a front-end help message
129+
std::string show_path_strategies();
130+
131+
/// \brief is there a factory constructor for the named strategy?
132+
bool is_valid_path_strategy(const std::string strategy);
133+
134+
/// Ensure that is_valid_strategy() returns true for a
135+
/// particular string before calling this function on that string.
136+
std::unique_ptr<path_storaget> get_path_strategy(const std::string strategy);
137+
138+
/// \brief add `paths` and `exploration-strategy` option, suitable to be
139+
/// invoked from front-ends.
140+
void parse_path_strategy_options(
141+
const cmdlinet &,
142+
optionst &,
143+
message_handlert &);
174144

175145
#endif /* CPROVER_GOTO_SYMEX_PATH_STORAGE_H */

unit/path_strategies.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,8 @@ void _check_with_strategy(
368368
mh.set_verbosity(0);
369369
messaget log(mh);
370370

371-
path_strategy_choosert chooser;
372-
REQUIRE(chooser.is_valid_strategy(strategy));
373-
std::unique_ptr<path_storaget> worklist = chooser.get(strategy);
371+
REQUIRE(is_valid_path_strategy(strategy));
372+
std::unique_ptr<path_storaget> worklist = get_path_strategy(strategy);
374373

375374
goto_modelt gm;
376375
int ret;

0 commit comments

Comments
 (0)