Skip to content

Commit 79515a4

Browse files
committed
goto_instrt_parse_options, util/cmdline: refactor
src/goto-instrument/goto_instrument_parse_options: add --add-cmd-line-arg option, refactor code around. src/util/cmdline: refactor, do not interpret every "--{string}" as option for CBMC.
1 parent 805e196 commit 79515a4

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414
#include <fstream>
1515
#include <iostream>
1616
#include <memory>
17+
#include <sstream>
1718

1819
#include <util/config.h>
1920
#include <util/exception_utils.h>
@@ -93,7 +94,6 @@ Author: Daniel Kroening, [email protected]
9394
#include "interrupt.h"
9495
#include "k_induction.h"
9596
#include "mmio.h"
96-
#include "model_argc_argv.h"
9797
#include "nondet_static.h"
9898
#include "nondet_volatile.h"
9999
#include "points_to.h"
@@ -1050,10 +1050,38 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10501050
{
10511051
unsigned max_argc=
10521052
safe_string2unsigned(cmdline.get_value("model-argc-argv"));
1053+
std::list<std::string> argv;
1054+
argv.resize(max_argc);
10531055

10541056
log.status() << "Adding up to " << max_argc << " command line arguments"
10551057
<< messaget::eom;
1056-
if(model_argc_argv(goto_model, max_argc, ui_message_handler))
1058+
1059+
if(model_argc_argv(
1060+
goto_model, argv, true /*model_argv*/, ui_message_handler))
1061+
throw 0;
1062+
}
1063+
1064+
if(cmdline.isset("add-cmd-line-arg"))
1065+
{
1066+
const std::list<std::string> &argv = cmdline.get_values("add-cmd-line-arg");
1067+
unsigned argc = 0;
1068+
1069+
std::stringstream ss;
1070+
ss << "[";
1071+
std::string sep = "";
1072+
for(auto const &arg : argv)
1073+
{
1074+
ss << sep << "\"" << arg << "\"";
1075+
argc++;
1076+
sep = ", ";
1077+
}
1078+
ss << "]";
1079+
1080+
log.status() << "Adding " << argc << " arguments: " << ss.str()
1081+
<< messaget::eom;
1082+
1083+
if(model_argc_argv(
1084+
goto_model, argv, false /*model_argv*/, ui_message_handler))
10571085
throw 0;
10581086
}
10591087

@@ -1827,7 +1855,8 @@ void goto_instrument_parse_optionst::help()
18271855
HELP_REMOVE_CALLS_NO_BODY
18281856
HELP_REMOVE_CONST_FUNCTION_POINTERS
18291857
" --add-library add models of C library functions\n"
1830-
" --model-argc-argv <n> model up to <n> command line arguments\n"
1858+
HELP_CONFIG_LIBRARY
1859+
HELP_ARGC_ARGV
18311860
// NOLINTNEXTLINE(whitespace/line_length)
18321861
" --remove-function-body <f> remove the implementation of function <f> (may be repeated)\n"
18331862
HELP_REPLACE_CALLS

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Author: Daniel Kroening, [email protected]
3838
#include "dump_c.h"
3939
#include "generate_function_bodies.h"
4040
#include "insert_final_assert_false.h"
41+
#include "model_argc_argv.h"
4142
#include "nondet_volatile.h"
4243
#include "replace_calls.h"
4344
#include "uninitialized.h"
@@ -93,7 +94,8 @@ Author: Daniel Kroening, [email protected]
9394
"(interpreter)(show-reaching-definitions)" \
9495
"(list-symbols)(list-undefined-functions)" \
9596
"(z3)(add-library)(show-dependence-graph)" \
96-
"(horn)(skip-loops):(model-argc-argv):" \
97+
"(horn)(skip-loops):" \
98+
OPT_ARGC_ARGV \
9799
"(" FLAG_LOOP_CONTRACTS ")" \
98100
"(" FLAG_REPLACE_CALL "):" \
99101
"(" FLAG_ENFORCE_CONTRACT "):" \

src/util/cmdline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ bool cmdlinet::parse_arguments(int argc, const char **argv)
305305
i++;
306306
if(i == argc)
307307
return true;
308-
if(argv[i][0] == '-' && argv[i][1] != 0)
308+
if(options[*optnr].optstring != "add-cmd-line-arg" && argv[i][0] == '-' && argv[i][1] != 0)
309309
return true;
310310
options[*optnr].values.push_back(argv[i]);
311311
}

0 commit comments

Comments
 (0)