Skip to content

Factor out goto model processing and default options #2049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions src/cbmc/cbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,28 @@ ::cbmc_parse_optionst::cbmc_parse_optionst(
{
}

void cbmc_parse_optionst::set_default_options(optionst &options)
{
// Default true
options.set_option("assertions", true);
options.set_option("assumptions", true);
options.set_option("built-in-assertions", true);
options.set_option("pretty-names", true);
options.set_option("propagation", true);
options.set_option("sat-preprocessor", true);
options.set_option("simplify", true);
options.set_option("simplify-if", true);

// Default false
Copy link
Collaborator

@tautschnig tautschnig Apr 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering: should this part actually be omitted completely? It does make a difference if the (new) is_set is used, but for get_bool_option setting them to false is as good as not setting them.

Edit: many other options also default to false, but are not being set here. I'm always after consistency...

options.set_option("partial-loops", false);
options.set_option("slice-formula", false);
options.set_option("stop-on-fail", false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add unwinding-assertions, partial-loops, slice-formula in here and refactor their current command-line/options code to use if(cmdline.isset...)?

options.set_option("unwinding-assertions", false);

// Other
options.set_option("arrays-uf", "auto");
}

void cbmc_parse_optionst::eval_verbosity()
{
// this is our default verbosity
Expand All @@ -108,6 +130,8 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
exit(CPROVER_EXIT_USAGE_ERROR);
}

cbmc_parse_optionst::set_default_options(options);

if(cmdline.isset("paths"))
options.set_option("paths", true);

Expand Down Expand Up @@ -143,15 +167,11 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)

if(cmdline.isset("no-simplify"))
options.set_option("simplify", false);
else
options.set_option("simplify", true);

if(cmdline.isset("stop-on-fail") ||
cmdline.isset("dimacs") ||
cmdline.isset("outfile"))
options.set_option("stop-on-fail", true);
else
options.set_option("stop-on-fail", false);

if(cmdline.isset("trace") ||
cmdline.isset("stop-on-fail"))
Expand Down Expand Up @@ -184,43 +204,36 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
// constant propagation
if(cmdline.isset("no-propagation"))
options.set_option("propagation", false);
else
options.set_option("propagation", true);

// all checks supported by goto_check
PARSE_OPTIONS_GOTO_CHECK(cmdline, options);

// check assertions
if(cmdline.isset("no-assertions"))
options.set_option("assertions", false);
else
options.set_option("assertions", true);

// use assumptions
if(cmdline.isset("no-assumptions"))
options.set_option("assumptions", false);
else
options.set_option("assumptions", true);

// magic error label
if(cmdline.isset("error-label"))
options.set_option("error-label", cmdline.get_values("error-label"));

// generate unwinding assertions
if(cmdline.isset("cover"))
options.set_option("unwinding-assertions", false);
else
if(cmdline.isset("unwinding-assertions"))
options.set_option("unwinding-assertions", true);

if(cmdline.isset("partial-loops"))
options.set_option("partial-loops", true);

if(options.is_set("cover") && options.get_bool_option("unwinding-assertions"))
{
options.set_option(
"unwinding-assertions",
cmdline.isset("unwinding-assertions"));
error() << "--cover and --unwinding-assertions "
<< "must not be given together" << eom;
exit(CPROVER_EXIT_USAGE_ERROR);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably a good idea to communicate this to users explicitly.

}

// generate unwinding assumptions otherwise
options.set_option(
"partial-loops",
cmdline.isset("partial-loops"));

if(options.get_bool_option("partial-loops") &&
options.get_bool_option("unwinding-assertions"))
{
Expand All @@ -230,22 +243,17 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
}

// remove unused equations
options.set_option(
"slice-formula",
cmdline.isset("slice-formula"));
if(cmdline.isset("slice-formula"))
options.set_option("slice-formula", true);

// simplify if conditions and branches
if(cmdline.isset("no-simplify-if"))
options.set_option("simplify-if", false);
else
options.set_option("simplify-if", true);

if(cmdline.isset("arrays-uf-always"))
options.set_option("arrays-uf", "always");
else if(cmdline.isset("arrays-uf-never"))
options.set_option("arrays-uf", "never");
else
options.set_option("arrays-uf", "auto");

if(cmdline.isset("dimacs"))
options.set_option("dimacs", true);
Expand Down Expand Up @@ -387,12 +395,9 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)

if(cmdline.isset("no-sat-preprocessor"))
options.set_option("sat-preprocessor", false);
else
options.set_option("sat-preprocessor", true);

options.set_option(
"pretty-names",
!cmdline.isset("no-pretty-names"));
if(cmdline.isset("no-pretty-names"))
options.set_option("pretty-names", false);

if(cmdline.isset("outfile"))
options.set_option("outfile", cmdline.get_value("outfile"));
Expand Down
6 changes: 6 additions & 0 deletions src/cbmc/cbmc_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class cbmc_parse_optionst:
const char **argv,
const std::string &extra_options);

/// \brief Set the options that have default values
///
/// This function can be called from clients that wish to emulate CBMC's
/// default behaviour, for example unit tests.
static void set_default_options(optionst &);

protected:
goto_modelt goto_model;
ui_message_handlert ui_message_handler;
Expand Down
5 changes: 5 additions & 0 deletions src/util/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ unsigned int optionst::get_unsigned_int_option(const std::string &option) const
return value.empty()?0:safe_string2unsigned(value);
}

bool optionst::is_set(const std::string &option) const
{
return option_map.find(option) != option_map.end();
}

const std::string optionst::get_option(const std::string &option) const
{
option_mapt::const_iterator it=
Expand Down
3 changes: 3 additions & 0 deletions src/util/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class optionst
unsigned int get_unsigned_int_option(const std::string &option) const;
const value_listt &get_list_option(const std::string &option) const;

/// N.B. opts.is_set("foo") does not imply opts.get_bool_option("foo")
bool is_set(const std::string &option) const;

void set_option(const std::string &option, const bool value);
void set_option(const std::string &option, const int value);
void set_option(const std::string &option, const unsigned value);
Expand Down