Skip to content

Commit 2f0cdc8

Browse files
Split up argument declaration and function call
for the function we are calling in goto-harness. Before this we had a function called setup_parameters_and_call_entry_function, and now we have split it up into declare_arguments and call_function. This is so we can do some handling between declaring arguments and calling the function. Co-authored-by: Fotis Koutoulakis <[email protected]> Co-authored-by: Hannes Steffenhagen <[email protected]>
1 parent 55eec59 commit 2f0cdc8

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ Author: Diffblue Ltd.
1616
#include <util/std_code.h>
1717
#include <util/std_expr.h>
1818
#include <util/string2int.h>
19+
#include <util/string_utils.h>
1920
#include <util/ui_message.h>
2021

22+
#include <algorithm>
23+
#include <set>
24+
2125
#include "function_harness_generator_options.h"
2226
#include "goto_harness_parse_options.h"
2327
#include "recursive_initialization.h"
@@ -43,9 +47,6 @@ struct function_call_harness_generatort::implt
4347
/// Iterate over the symbol table and generate initialisation code for
4448
/// globals into the function body.
4549
void generate_nondet_globals(code_blockt &function_body);
46-
/// Non-deterministically initialise the parameters of the entry function
47-
/// and insert function call to the passed code block.
48-
void setup_parameters_and_call_entry_function(code_blockt &function_body);
4950
/// Return a reference to the entry function or throw if it doesn't exist.
5051
const symbolt &lookup_function_to_call();
5152
/// Generate initialisation code for one lvalue inside block.
@@ -54,6 +55,11 @@ struct function_call_harness_generatort::implt
5455
void ensure_harness_does_not_already_exist();
5556
/// Update the goto-model with the new harness function.
5657
void add_harness_function_to_goto_model(code_blockt function_body);
58+
59+
code_function_callt::argumentst declare_arguments(code_blockt &function_body);
60+
void call_function(
61+
const code_function_callt::argumentst &arguments,
62+
code_blockt &function_body);
5763
};
5864

5965
function_call_harness_generatort::function_call_harness_generatort(
@@ -123,55 +129,26 @@ void function_call_harness_generatort::generate(
123129
p_impl->generate(goto_model, harness_function_name);
124130
}
125131

126-
void function_call_harness_generatort::implt::
127-
setup_parameters_and_call_entry_function(code_blockt &function_body)
128-
{
129-
const auto &function_to_call = lookup_function_to_call();
130-
const auto &function_type = to_code_type(function_to_call.type);
131-
const auto &parameters = function_type.parameters();
132-
133-
code_function_callt::operandst arguments{};
134-
135-
auto allocate_objects = allocate_objectst{function_to_call.mode,
136-
function_to_call.location,
137-
"__goto_harness",
138-
*symbol_table};
139-
for(const auto &parameter : parameters)
140-
{
141-
auto argument = allocate_objects.allocate_automatic_local_object(
142-
parameter.type(), parameter.get_base_name());
143-
arguments.push_back(argument);
144-
}
145-
allocate_objects.declare_created_symbols(function_body);
146-
for(auto const &argument : arguments)
147-
{
148-
generate_initialisation_code_for(function_body, argument);
149-
}
150-
code_function_callt function_call{function_to_call.symbol_expr(),
151-
std::move(arguments)};
152-
function_call.add_source_location() = function_to_call.location;
153-
154-
function_body.add(std::move(function_call));
155-
}
156-
157132
void function_call_harness_generatort::implt::generate(
158133
goto_modelt &goto_model,
159134
const irep_idt &harness_function_name)
160135
{
161136
symbol_table = &goto_model.symbol_table;
162137
goto_functions = &goto_model.goto_functions;
163-
const auto &function_to_call = lookup_function_to_call();
164-
recursive_initialization_config.mode = function_to_call.mode;
165-
recursive_initialization = util_make_unique<recursive_initializationt>(
166-
recursive_initialization_config, goto_model);
167138
this->harness_function_name = harness_function_name;
139+
const auto &function_to_call = lookup_function_to_call();
168140
ensure_harness_does_not_already_exist();
169141

170142
// create body for the function
171143
code_blockt function_body{};
144+
auto const arguments = declare_arguments(function_body);
145+
146+
recursive_initialization_config.mode = function_to_call.mode;
147+
recursive_initialization = util_make_unique<recursive_initializationt>(
148+
recursive_initialization_config, goto_model);
172149

173150
generate_nondet_globals(function_body);
174-
setup_parameters_and_call_entry_function(function_body);
151+
call_function(arguments, function_body);
175152
add_harness_function_to_goto_model(std::move(function_body));
176153
}
177154

@@ -264,3 +241,44 @@ void function_call_harness_generatort::implt::
264241
function_to_call.mode);
265242
body.add(goto_programt::make_end_function());
266243
}
244+
245+
code_function_callt::argumentst
246+
function_call_harness_generatort::implt::declare_arguments(
247+
code_blockt &function_body)
248+
{
249+
const auto &function_to_call = lookup_function_to_call();
250+
const auto &function_type = to_code_type(function_to_call.type);
251+
const auto &parameters = function_type.parameters();
252+
253+
code_function_callt::operandst arguments{};
254+
255+
auto allocate_objects = allocate_objectst{function_to_call.mode,
256+
function_to_call.location,
257+
"__goto_harness",
258+
*symbol_table};
259+
for(const auto &parameter : parameters)
260+
{
261+
auto argument = allocate_objects.allocate_automatic_local_object(
262+
parameter.type(), parameter.get_base_name());
263+
arguments.push_back(argument);
264+
}
265+
266+
allocate_objects.declare_created_symbols(function_body);
267+
return arguments;
268+
}
269+
270+
void function_call_harness_generatort::implt::call_function(
271+
const code_function_callt::argumentst &arguments,
272+
code_blockt &function_body)
273+
{
274+
auto const &function_to_call = lookup_function_to_call();
275+
for(auto const &argument : arguments)
276+
{
277+
generate_initialisation_code_for(function_body, argument);
278+
}
279+
code_function_callt function_call{function_to_call.symbol_expr(),
280+
std::move(arguments)};
281+
function_call.add_source_location() = function_to_call.location;
282+
283+
function_body.add(std::move(function_call));
284+
}

0 commit comments

Comments
 (0)