Skip to content

Commit aac181f

Browse files
Pass command line options via optionst
1 parent b6fa3e8 commit aac181f

File tree

4 files changed

+43
-30
lines changed

4 files changed

+43
-30
lines changed

src/cbmc/cbmc_parse_options.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
117117
options.set_option("show-vcc", true);
118118

119119
if(cmdline.isset("cover"))
120-
options.set_option("cover", cmdline.get_values("cover"));
120+
parse_cover_options(cmdline, options);
121121

122122
if(cmdline.isset("mm"))
123123
options.set_option("mm", cmdline.get_value("mm"));
@@ -810,10 +810,7 @@ bool cbmc_parse_optionst::process_goto_program(
810810
// instrument cover goals
811811
if(cmdline.isset("cover"))
812812
{
813-
if(instrument_cover_goals(
814-
cmdline,
815-
goto_model,
816-
get_message_handler()))
813+
if(instrument_cover_goals(options, goto_model, get_message_handler()))
817814
return true;
818815
}
819816

src/goto-instrument/cover.cpp

+33-16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Date: May 2016
1616
#include <util/config.h>
1717
#include <util/message.h>
1818
#include <util/make_unique.h>
19+
#include <util/cmdline.h>
20+
#include <util/options.h>
1921

2022
#include "cover_basic_blocks.h"
2123
#include "cover_filter.h"
@@ -141,6 +143,28 @@ parse_coverage_criterion(const std::string &criterion_string)
141143
return c;
142144
}
143145

146+
/// Parses coverage-related command line options
147+
/// \param cmdline: the command line
148+
/// \param options: the options
149+
void parse_cover_options(const cmdlinet &cmdline, optionst &options)
150+
{
151+
options.set_option("cover", cmdline.get_values("cover"));
152+
std::string cover_include_pattern =
153+
cmdline.get_value("cover-include-pattern");
154+
if(cmdline.isset("cover-function-only"))
155+
{
156+
std::regex special_characters(
157+
"\\.|\\\\|\\*|\\+|\\?|\\{|\\}|\\[|\\]|\\(|\\)|\\^|\\$|\\|");
158+
cover_include_pattern =
159+
".*" + std::regex_replace(config.main, special_characters, "\\$&") + ".*";
160+
}
161+
options.set_option("cover-include-pattern", cover_include_pattern);
162+
options.set_option("no-trivial-tests", cmdline.isset("no-trivial-tests"));
163+
options.set_option(
164+
"cover-traces-must-terminate",
165+
cmdline.isset("cover-traces-must-terminate"));
166+
}
167+
144168
/// Applies instrumenters to given goto functions
145169
/// \param goto_functions: the goto functions
146170
/// \param instrumenters: the instrumenters
@@ -162,12 +186,12 @@ void instrument_cover_goals(
162186
}
163187

164188
/// Instruments goto functions based on given command line options
165-
/// \param cmdline: the command line
189+
/// \param options: the options
166190
/// \param symbol_table: the symbol table
167191
/// \param goto_functions: the goto functions
168192
/// \param message_handler: a message handler
169193
bool instrument_cover_goals(
170-
const cmdlinet &cmdline,
194+
const optionst &options,
171195
const symbol_tablet &symbol_table,
172196
goto_functionst &goto_functions,
173197
message_handlert &message_handler)
@@ -183,7 +207,7 @@ bool instrument_cover_goals(
183207

184208
cover_instrumenterst instrumenters;
185209

186-
std::list<std::string> criteria_strings=cmdline.get_values("cover");
210+
optionst::value_listt criteria_strings = options.get_list_option("cover");
187211
bool keep_assertions=false;
188212

189213
for(const auto &criterion_string : criteria_strings)
@@ -230,22 +254,15 @@ bool instrument_cover_goals(
230254

231255
// cover entry point function only
232256
std::string cover_include_pattern =
233-
cmdline.get_value("cover-include-pattern");
234-
if(cmdline.isset("cover-function-only"))
235-
{
236-
std::regex special_characters(
237-
"\\.|\\\\|\\*|\\+|\\?|\\{|\\}|\\[|\\]|\\(|\\)|\\^|\\$|\\|");
238-
cover_include_pattern =
239-
".*" + std::regex_replace(config.main, special_characters, "\\$&") + ".*";
240-
}
257+
options.get_option("cover-include-pattern");
241258
if(!cover_include_pattern.empty())
242259
{
243260
function_filters.add(
244261
util_make_unique<include_pattern_filtert>(
245262
message_handler, cover_include_pattern));
246263
}
247264

248-
if(cmdline.isset("no-trivial-tests"))
265+
if(options.get_bool_option("no-trivial-tests"))
249266
function_filters.add(
250267
util_make_unique<trivial_functions_filtert>(message_handler));
251268

@@ -257,7 +274,7 @@ bool instrument_cover_goals(
257274
function_filters.report_anomalies();
258275
goal_filters.report_anomalies();
259276

260-
if(cmdline.isset("cover-traces-must-terminate"))
277+
if(options.get_bool_option("cover-traces-must-terminate"))
261278
{
262279
// instrument an additional goal in CPROVER_START. This will rephrase
263280
// the reachability problem by asking BMC to provide a solution that
@@ -279,16 +296,16 @@ bool instrument_cover_goals(
279296
}
280297

281298
/// Instruments a goto model based on given command line options
282-
/// \param cmdline: the command line
299+
/// \param options: the options
283300
/// \param goto_model: the goto model
284301
/// \param message_handler: a message handler
285302
bool instrument_cover_goals(
286-
const cmdlinet &cmdline,
303+
const optionst &options,
287304
goto_modelt &goto_model,
288305
message_handlert &message_handler)
289306
{
290307
return instrument_cover_goals(
291-
cmdline,
308+
options,
292309
goto_model.symbol_table,
293310
goto_model.goto_functions,
294311
message_handler);

src/goto-instrument/cover.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Date: May 2016
1616

1717
#include <goto-programs/goto_model.h>
1818

19-
#include <util/cmdline.h>
20-
2119
class message_handlert;
20+
class cmdlinet;
21+
class optionst;
2222

2323
enum class coverage_criteriont
2424
{
@@ -44,14 +44,16 @@ void instrument_cover_goals(
4444
coverage_criteriont,
4545
message_handlert &message_handler);
4646

47+
void parse_cover_options(const cmdlinet &, optionst &);
48+
4749
bool instrument_cover_goals(
48-
const cmdlinet &,
50+
const optionst &,
4951
const symbol_tablet &,
5052
goto_functionst &,
5153
message_handlert &);
5254

5355
bool instrument_cover_goals(
54-
const cmdlinet &,
56+
const optionst &,
5557
goto_modelt &,
5658
message_handlert &);
5759

src/jbmc/jbmc_parse_options.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void jbmc_parse_optionst::get_command_line_options(optionst &options)
115115
options.set_option("show-vcc", true);
116116

117117
if(cmdline.isset("cover"))
118-
options.set_option("cover", cmdline.get_values("cover"));
118+
parse_cover_options(cmdline, options);
119119

120120
if(cmdline.isset("no-simplify"))
121121
options.set_option("simplify", false);
@@ -734,10 +734,7 @@ bool jbmc_parse_optionst::process_goto_program(
734734
// instrument cover goals
735735
if(cmdline.isset("cover"))
736736
{
737-
if(instrument_cover_goals(
738-
cmdline,
739-
goto_model,
740-
get_message_handler()))
737+
if(instrument_cover_goals(options, goto_model, get_message_handler()))
741738
return true;
742739
}
743740

0 commit comments

Comments
 (0)