Skip to content
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

[RFC] Refactor command line options #4404

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
155 changes: 35 additions & 120 deletions src/cbmc/cbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]
#include <util/make_unique.h>
#include <util/unicode.h>
#include <util/version.h>
#include <util/xml.h>

#include <langapi/language.h>

Expand Down Expand Up @@ -83,7 +84,7 @@ Author: Daniel Kroening, [email protected]
#include "xml_interface.h"

cbmc_parse_optionst::cbmc_parse_optionst(int argc, const char **argv)
: parse_options_baset(CBMC_OPTIONS, argc, argv, ui_message_handler),
: parse_options_baset(cbmc_options.to_option_string(), argc, argv, ui_message_handler),
xml_interfacet(cmdline),
messaget(ui_message_handler),
ui_message_handler(cmdline, std::string("CBMC ") + CBMC_VERSION)
Expand All @@ -93,9 +94,9 @@ cbmc_parse_optionst::cbmc_parse_optionst(int argc, const char **argv)
::cbmc_parse_optionst::cbmc_parse_optionst(
int argc,
const char **argv,
const std::string &extra_options)
const cmdline_definitiont &extra_options)
: parse_options_baset(
CBMC_OPTIONS + extra_options,
(cbmc_options + extra_options).to_option_string(),
argc,
argv,
ui_message_handler),
Expand Down Expand Up @@ -915,121 +916,35 @@ bool cbmc_parse_optionst::process_goto_program(
/// display command line help
void cbmc_parse_optionst::help()
{
// clang-format off
std::cout << '\n' << banner_string("CBMC", CBMC_VERSION) << '\n'
<< align_center_with_border("Copyright (C) 2001-2018") << '\n'
<< align_center_with_border("Daniel Kroening, Edmund Clarke") << '\n' // NOLINT(*)
<< align_center_with_border("Carnegie Mellon University, Computer Science Department") << '\n' // NOLINT(*)
<< align_center_with_border("[email protected]") << '\n' // NOLINT(*)
<< align_center_with_border("Protected in part by U.S. patent 7,225,417") << '\n' // NOLINT(*)
<<
"\n"
"Usage: Purpose:\n"
"\n"
" cbmc [-?] [-h] [--help] show help\n"
" cbmc file.c ... source file names\n"
"\n"
"Analysis options:\n"
HELP_SHOW_PROPERTIES
" --symex-coverage-report f generate a Cobertura XML coverage report in f\n" // NOLINT(*)
" --property id only check one specific property\n"
" --stop-on-fail stop analysis once a failed property is detected\n" // NOLINT(*)
" --trace give a counterexample trace for failed properties\n" //NOLINT(*)
"\n"
"C/C++ frontend options:\n"
" -I path set include path (C/C++)\n"
" -D macro define preprocessor macro (C/C++)\n"
" --preprocess stop after preprocessing\n"
" --16, --32, --64 set width of int\n"
" --LP64, --ILP64, --LLP64,\n"
" --ILP32, --LP32 set width of int, long and pointers\n"
" --little-endian allow little-endian word-byte conversions\n"
" --big-endian allow big-endian word-byte conversions\n"
" --unsigned-char make \"char\" unsigned by default\n"
" --mm model set memory model (default: sc)\n"
" --arch set architecture (default: "
<< configt::this_architecture() << ")\n"
" --os set operating system (default: "
<< configt::this_operating_system() << ")\n"
" --c89/99/11 set C language standard (default: "
<< (configt::ansi_ct::default_c_standard()==
configt::ansi_ct::c_standardt::C89?"c89":
configt::ansi_ct::default_c_standard()==
configt::ansi_ct::c_standardt::C99?"c99":
configt::ansi_ct::default_c_standard()==
configt::ansi_ct::c_standardt::C11?"c11":"") << ")\n" // NOLINT(*)
" --cpp98/03/11 set C++ language standard (default: "
<< (configt::cppt::default_cpp_standard()==
configt::cppt::cpp_standardt::CPP98?"cpp98": // NOLINT(*)
configt::cppt::default_cpp_standard()==
configt::cppt::cpp_standardt::CPP03?"cpp03": // NOLINT(*)
configt::cppt::default_cpp_standard()==
configt::cppt::cpp_standardt::CPP11?"cpp11":"") << ")\n" // NOLINT(*)
#ifdef _WIN32
" --gcc use GCC as preprocessor\n"
#endif
" --no-arch don't set up an architecture\n"
" --no-library disable built-in abstract C library\n"
" --round-to-nearest rounding towards nearest even (default)\n"
" --round-to-plus-inf rounding towards plus infinity\n"
" --round-to-minus-inf rounding towards minus infinity\n"
" --round-to-zero rounding towards zero\n"
HELP_ANSI_C_LANGUAGE
HELP_FUNCTIONS
"\n"
"Program representations:\n"
" --show-parse-tree show parse tree\n"
" --show-symbol-table show loaded symbol table\n"
HELP_SHOW_GOTO_FUNCTIONS
"\n"
"Program instrumentation options:\n"
HELP_GOTO_CHECK
" --no-assertions ignore user assertions\n"
" --no-assumptions ignore user assumptions\n"
" --error-label label check that label is unreachable\n"
" --cover CC create test-suite with coverage criterion CC\n" // NOLINT(*)
" --mm MM memory consistency model for concurrent programs\n" // NOLINT(*)
HELP_REACHABILITY_SLICER
HELP_REACHABILITY_SLICER_FB
" --full-slice run full slicer (experimental)\n" // NOLINT(*)
" --drop-unused-functions drop functions trivially unreachable from main function\n" // NOLINT(*)
"\n"
"Semantic transformations:\n"
// NOLINTNEXTLINE(whitespace/line_length)
" --nondet-static add nondeterministic initialization of variables with static lifetime\n"
"\n"
"BMC options:\n"
HELP_BMC
"\n"
"Backend options:\n"
" --object-bits n number of bits used for object addresses\n"
" --dimacs generate CNF in DIMACS format\n"
" --beautify beautify the counterexample (greedy heuristic)\n" // NOLINT(*)
" --localize-faults localize faults (experimental)\n"
" --smt2 use default SMT2 solver (Z3)\n"
" --boolector use Boolector\n"
" --cprover-smt2 use CPROVER SMT2 solver\n"
" --cvc4 use CVC4\n"
" --mathsat use MathSAT\n"
" --yices use Yices\n"
" --z3 use Z3\n"
" --refine use refinement procedure (experimental)\n"
HELP_STRING_REFINEMENT_CBMC
" --outfile filename output formula to given file\n"
" --arrays-uf-never never turn arrays into uninterpreted functions\n" // NOLINT(*)
" --arrays-uf-always always turn arrays into uninterpreted functions\n" // NOLINT(*)
"\n"
"Other options:\n"
" --version show version and exit\n"
" --xml-ui use XML-formatted output\n"
" --xml-interface bi-directional XML interface\n"
" --json-ui use JSON-formatted output\n"
// NOLINTNEXTLINE(whitespace/line_length)
HELP_VALIDATE
HELP_GOTO_TRACE
HELP_FLUSH
" --verbosity # verbosity level\n"
HELP_TIMESTAMP
"\n";
// clang-format on
switch(ui_message_handler.get_ui())
{
case ui_message_handlert::uit::PLAIN:
// clang-format off
log.result()
<< '\n' << banner_string("CBMC", CBMC_VERSION) << '\n'
<< align_center_with_border("Copyright (C) 2001-2018") << '\n'
<< align_center_with_border("Daniel Kroening, Edmund Clarke")
<< '\n' // NOLINT(*)
<< align_center_with_border(
"Carnegie Mellon University, Computer Science Department")
<< '\n' // NOLINT(*)
<< align_center_with_border("[email protected]") << '\n' // NOLINT(*)
<< align_center_with_border("Protected in part by U.S. patent 7,225,417")
<< '\n' // NOLINT(*)
<<
"\n"
"Usage: Purpose:\n"
"\n"
" cbmc [-?] [-h] [--help] show help\n"
" cbmc file.c ... source file names\n"
<< cbmc_options.to_help_text(30, 80) << messaget::eom;
// clang-format on
break;
case ui_message_handlert::uit::JSON_UI:
ui_message_handler.get_json_stream().push_back(cbmc_options.to_json());
break;
case ui_message_handlert::uit::XML_UI:
log.result() << cbmc_options.to_xml();
break;
}
}
85 changes: 41 additions & 44 deletions src/cbmc/cbmc_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected]
#include <ansi-c/ansi_c_language.h>
#include <ansi-c/c_object_factory_parameters.h>

#include <util/cmdline_definition.h>
#include <util/parse_options.h>
#include <util/timestamper.h>
#include <util/ui_message.h>
Expand All @@ -38,49 +39,45 @@ class goto_functionst;
class optionst;

// clang-format off
#define CBMC_OPTIONS \
OPT_BMC \
"(preprocess)(slice-by-trace):" \
OPT_FUNCTIONS \
"(no-simplify)(full-slice)" \
OPT_REACHABILITY_SLICER \
"(debug-level):(no-propagation)(no-simplify-if)" \
"(document-subgoals)(outfile):(test-preprocessor)" \
"D:I:(c89)(c99)(c11)(cpp98)(cpp03)(cpp11)" \
"(object-bits):" \
OPT_GOTO_CHECK \
"(no-assertions)(no-assumptions)" \
"(xml-ui)(xml-interface)(json-ui)" \
"(smt1)(smt2)(fpa)(cvc3)(cvc4)(boolector)(yices)(z3)(mathsat)" \
"(cprover-smt2)" \
"(no-sat-preprocessor)" \
"(beautify)" \
"(dimacs)(refine)(max-node-refinement):(refine-arrays)(refine-arithmetic)"\
OPT_STRING_REFINEMENT_CBMC \
"(16)(32)(64)(LP64)(ILP64)(LLP64)(ILP32)(LP32)" \
"(little-endian)(big-endian)" \
OPT_SHOW_GOTO_FUNCTIONS \
OPT_SHOW_PROPERTIES \
"(show-symbol-table)(show-parse-tree)" \
"(drop-unused-functions)" \
"(property):(stop-on-fail)(trace)" \
"(error-label):(verbosity):(no-library)" \
"(nondet-static)" \
"(version)" \
"(cover):(symex-coverage-report):" \
"(mm):" \
OPT_TIMESTAMP \
"(i386-linux)(i386-macos)(i386-win32)(win32)(winx64)(gcc)" \
"(ppc-macos)(unsigned-char)" \
"(arrays-uf-always)(arrays-uf-never)" \
"(string-abstraction)(no-arch)(arch):" \
"(round-to-nearest)(round-to-plus-inf)(round-to-minus-inf)(round-to-zero)" \
OPT_FLUSH \
"(localize-faults)" \
OPT_GOTO_TRACE \
OPT_VALIDATE \
OPT_ANSI_C_LANGUAGE \
"(claim):(show-claims)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)
const cmdline_definitiont ui_options
Copy link
Collaborator

Choose a reason for hiding this comment

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

A rather unrelated comment: does anyone know why this ever needed to go in the header file? I.e., not just the changes in this PR, but also the current CBMC_OPTIONS?

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea :D

{
{
"json-ui",
{},
"use JSON-formatted output",
"Other options",
{}
},
{
"xml-ui",
{},
"use XML-formatted output",
"Other options",
{}
}
};

const cmdline_definitiont cbmc_options(
ui_options
+ cmdline_definitiont{
{
"preprocess",
{},
"stop after preprocessing. "
"This is a veeeeeeeeeeeeeeeeery long help text. "
"This is a veeeeeeeeeeeeeeeeery long help text.",
"C/C++ frontend options",
{}
},
{
"slice-by-trace",
cmdline_optiont::argumentt{"f", "string"},
"",
"",
cmdline_optiont::deprecatedt("-slice-by-trace has been removed")
}
}
+ ui_options);
// clang-format on

class cbmc_parse_optionst:
Expand All @@ -96,7 +93,7 @@ class cbmc_parse_optionst:
cbmc_parse_optionst(
int argc,
const char **argv,
const std::string &extra_options);
const cmdline_definitiont &extra_options);

/// \brief Set the options that have default values
///
Expand Down
1 change: 1 addition & 0 deletions src/util/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SRC = allocate_objects.cpp \
byte_operators.cpp \
c_types.cpp \
cmdline.cpp \
cmdline_definition.cpp \
config.cpp \
cout_message.cpp \
decision_procedure.cpp \
Expand Down
Loading