Skip to content

Commit 77db049

Browse files
Petr BauchPetr Bauch
authored andcommitted
Reflect the changes on individual generators
1: Config options are handled by the config's internal `handle_option`. 2: Options names are unified. 3: Memory-snapshot options are in a separate file.
1 parent ba9c9b6 commit 77db049

File tree

3 files changed

+24
-92
lines changed

3 files changed

+24
-92
lines changed

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -90,57 +90,19 @@ void function_call_harness_generatort::handle_option(
9090
const std::string &option,
9191
const std::list<std::string> &values)
9292
{
93-
if(option == FUNCTION_HARNESS_GENERATOR_FUNCTION_OPT)
94-
{
95-
p_impl->function = require_exactly_one_value(option, values);
96-
}
97-
else if(option == FUNCTION_HARNESS_GENERATOR_NONDET_GLOBALS_OPT)
98-
{
99-
p_impl->nondet_globals = true;
100-
}
101-
else if(option == FUNCTION_HARNESS_GENERATOR_MIN_NULL_TREE_DEPTH_OPT)
102-
{
103-
auto const value = require_exactly_one_value(option, values);
104-
auto const min_null_tree_depth = string2optional<std::size_t>(value, 10);
105-
if(min_null_tree_depth.has_value())
106-
{
107-
p_impl->recursive_initialization_config.min_null_tree_depth =
108-
min_null_tree_depth.value();
109-
}
110-
else
111-
{
112-
throw invalid_command_line_argument_exceptiont{
113-
"failed to convert `" + value + "' to integer",
114-
"--" FUNCTION_HARNESS_GENERATOR_MIN_NULL_TREE_DEPTH_OPT};
115-
}
116-
}
117-
else if(option == FUNCTION_HARNESS_GENERATOR_MAX_NONDET_TREE_DEPTH_OPT)
93+
auto &require_exactly_one_value =
94+
harness_options_parsert::require_exactly_one_value;
95+
96+
if(p_impl->recursive_initialization_config.handle_option(option, values))
11897
{
119-
auto const value = require_exactly_one_value(option, values);
120-
auto const max_nondet_tree_depth = string2optional<std::size_t>(value, 10);
121-
if(max_nondet_tree_depth.has_value())
122-
{
123-
p_impl->recursive_initialization_config.max_nondet_tree_depth =
124-
max_nondet_tree_depth.value();
125-
}
126-
else
127-
{
128-
throw invalid_command_line_argument_exceptiont{
129-
"failed to convert `" + value + "' to integer",
130-
"--" FUNCTION_HARNESS_GENERATOR_MAX_NONDET_TREE_DEPTH_OPT};
131-
}
13298
}
133-
else if(option == FUNCTION_HARNESS_GENERATOR_MAX_ARRAY_SIZE_OPT)
99+
else if(option == FUNCTION_HARNESS_GENERATOR_FUNCTION_OPT)
134100
{
135-
p_impl->recursive_initialization_config.max_dynamic_array_size =
136-
require_one_size_value(
137-
FUNCTION_HARNESS_GENERATOR_MAX_ARRAY_SIZE_OPT, values);
101+
p_impl->function = require_exactly_one_value(option, values);
138102
}
139-
else if(option == FUNCTION_HARNESS_GENERATOR_MIN_ARRAY_SIZE_OPT)
103+
else if(option == COMMON_HARNESS_GENERATOR_NONDET_GLOBALS_OPT)
140104
{
141-
p_impl->recursive_initialization_config.min_dynamic_array_size =
142-
require_one_size_value(
143-
FUNCTION_HARNESS_GENERATOR_MIN_ARRAY_SIZE_OPT, values);
105+
p_impl->nondet_globals = true;
144106
}
145107
else if(option == FUNCTION_HARNESS_GENERATOR_TREAT_POINTER_AS_ARRAY_OPT)
146108
{
@@ -285,25 +247,8 @@ void function_call_harness_generatort::validate_options(
285247
{
286248
throw invalid_command_line_argument_exceptiont{
287249
"min dynamic array size cannot be greater than max dynamic array size",
288-
"--" FUNCTION_HARNESS_GENERATOR_MIN_ARRAY_SIZE_OPT
289-
" --" FUNCTION_HARNESS_GENERATOR_MAX_ARRAY_SIZE_OPT};
290-
}
291-
}
292-
293-
std::size_t function_call_harness_generatort::require_one_size_value(
294-
const std::string &option,
295-
const std::list<std::string> &values)
296-
{
297-
auto const string_value = require_exactly_one_value(option, values);
298-
auto value = string2optional<std::size_t>(string_value, 10);
299-
if(value.has_value())
300-
{
301-
return value.value();
302-
}
303-
else
304-
{
305-
throw invalid_command_line_argument_exceptiont{
306-
"failed to parse `" + string_value + "' as integer", "--" + option};
250+
"--" COMMON_HARNESS_GENERATOR_MIN_ARRAY_SIZE_OPT
251+
" --" COMMON_HARNESS_GENERATOR_MAX_ARRAY_SIZE_OPT};
307252
}
308253
}
309254

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Author: Daniel Poetzl
77
\******************************************************************/
88

99
#include "memory_snapshot_harness_generator.h"
10+
#include "goto_harness_generator_factory.h"
11+
#include "memory_snapshot_harness_generator_options.h"
1012

1113
#include <goto-programs/goto_convert.h>
1214

@@ -23,18 +25,20 @@ Author: Daniel Poetzl
2325

2426
#include <linking/static_lifetime_init.h>
2527

26-
#include "goto_harness_generator_factory.h"
27-
#include "recursive_initialization.h"
28-
2928
void memory_snapshot_harness_generatort::handle_option(
3029
const std::string &option,
3130
const std::list<std::string> &values)
3231
{
33-
if(option == "memory-snapshot")
32+
auto &require_exactly_one_value =
33+
harness_options_parsert::require_exactly_one_value;
34+
if(recursive_initialization_config.handle_option(option, values))
35+
{
36+
}
37+
else if(option == MEMORY_SNAPSHOT_HARNESS_SNAPSHOT_OPT)
3438
{
3539
memory_snapshot_file = require_exactly_one_value(option, values);
3640
}
37-
else if(option == "initial-location")
41+
else if(option == MEMORY_SNAPSHOT_HARNESS_INITIAL_LOCATION_OPT)
3842
{
3943
const std::string initial_location =
4044
require_exactly_one_value(option, values);
@@ -57,7 +61,7 @@ void memory_snapshot_harness_generatort::handle_option(
5761
location_number = optionalt<unsigned>(safe_string2unsigned(start.back()));
5862
}
5963
}
60-
else if(option == "havoc-variables")
64+
else if(option == MEMORY_SNAPSHOT_HARNESS_HAVOC_VARIABLES_OPT)
6165
{
6266
variables_to_havoc.insert(values.begin(), values.end());
6367
}
@@ -222,7 +226,7 @@ code_blockt memory_snapshot_harness_generatort::add_assignments_to_globals(
222226
goto_modelt &goto_model) const
223227
{
224228
recursive_initializationt recursive_initialization{
225-
recursive_initialization_configt{}, goto_model};
229+
recursive_initialization_config, goto_model};
226230

227231
code_blockt code;
228232
for(const auto &pair : snapshot)

src/goto-harness/memory_snapshot_harness_generator.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,13 @@ Author: Daniel Poetzl
1313
#include <string>
1414

1515
#include "goto_harness_generator.h"
16+
#include "recursive_initialization.h"
1617

1718
#include <goto-programs/goto_model.h>
1819

1920
#include <util/message.h>
2021
#include <util/optional.h>
2122

22-
// clang-format off
23-
#define MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS \
24-
"(memory-snapshot):" \
25-
"(initial-location):" \
26-
"(havoc-variables):" // MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS
27-
// clang-format on
28-
29-
// clang-format off
30-
#define MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP \
31-
"memory snapshot harness generator (--harness-type\n" \
32-
" initialise-from-memory-snapshot)\n\n" \
33-
"--memory-snapshot <file> initialise memory from JSON memory snapshot\n"\
34-
"--initial-location <func[:<n>]>\n" \
35-
" use given function and location number as " \
36-
"entry\n point\n" \
37-
"--havoc-variables vars initialise variables from vars to\n" \
38-
" non-deterministic values" \
39-
// MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP
40-
// clang-format on
41-
4223
/// Generates a harness which first assigns global variables with values from
4324
/// a given memory snapshot and then calls a specified function. The called
4425
/// function is also modified such that it appears to start executing at the
@@ -164,6 +145,8 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
164145
std::unordered_set<irep_idt> variables_to_havoc;
165146

166147
message_handlert &message_handler;
148+
149+
recursive_initialization_configt recursive_initialization_config;
167150
};
168151

169152
#endif // CPROVER_GOTO_HARNESS_MEMORY_SNAPSHOT_HARNESS_GENERATOR_H

0 commit comments

Comments
 (0)