Skip to content

Commit ceb7f38

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 bbb1ce8 commit ceb7f38

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Diffblue Ltd.
1515
#include <util/std_code.h>
1616
#include <util/std_expr.h>
1717
#include <util/string2int.h>
18+
#include <util/string_utils.h>
1819
#include <util/ui_message.h>
1920

2021
#include <goto-programs/goto_convert.h>
@@ -45,9 +46,6 @@ struct function_call_harness_generatort::implt
4546
/// Iterate over the symbol table and generate initialisation code for
4647
/// globals into the function body.
4748
void generate_nondet_globals(code_blockt &function_body);
48-
/// Non-deterministically initialise the parameters of the entry function
49-
/// and insert function call to the passed code block.
50-
void setup_parameters_and_call_entry_function(code_blockt &function_body);
5149
/// Return a reference to the entry function or throw if it doesn't exist.
5250
const symbolt &lookup_function_to_call();
5351
/// Generate initialisation code for one lvalue inside block.
@@ -56,6 +54,11 @@ struct function_call_harness_generatort::implt
5654
void ensure_harness_does_not_already_exist();
5755
/// Update the goto-model with the new harness function.
5856
void add_harness_function_to_goto_model(code_blockt function_body);
57+
58+
code_function_callt::argumentst declare_arguments(code_blockt &function_body);
59+
void call_function(
60+
const code_function_callt::argumentst &arguments,
61+
code_blockt &function_body);
5962
};
6063

6164
function_call_harness_generatort::function_call_harness_generatort(
@@ -125,55 +128,26 @@ void function_call_harness_generatort::generate(
125128
p_impl->generate(goto_model, harness_function_name);
126129
}
127130

128-
void function_call_harness_generatort::implt::
129-
setup_parameters_and_call_entry_function(code_blockt &function_body)
130-
{
131-
const auto &function_to_call = lookup_function_to_call();
132-
const auto &function_type = to_code_type(function_to_call.type);
133-
const auto &parameters = function_type.parameters();
134-
135-
code_function_callt::operandst arguments{};
136-
137-
auto allocate_objects = allocate_objectst{function_to_call.mode,
138-
function_to_call.location,
139-
"__goto_harness",
140-
*symbol_table};
141-
for(const auto &parameter : parameters)
142-
{
143-
auto argument = allocate_objects.allocate_automatic_local_object(
144-
parameter.type(), parameter.get_base_name());
145-
arguments.push_back(argument);
146-
}
147-
allocate_objects.declare_created_symbols(function_body);
148-
for(auto const &argument : arguments)
149-
{
150-
generate_initialisation_code_for(function_body, argument);
151-
}
152-
code_function_callt function_call{function_to_call.symbol_expr(),
153-
std::move(arguments)};
154-
function_call.add_source_location() = function_to_call.location;
155-
156-
function_body.add(std::move(function_call));
157-
}
158-
159131
void function_call_harness_generatort::implt::generate(
160132
goto_modelt &goto_model,
161133
const irep_idt &harness_function_name)
162134
{
163135
symbol_table = &goto_model.symbol_table;
164136
goto_functions = &goto_model.goto_functions;
165-
const auto &function_to_call = lookup_function_to_call();
166-
recursive_initialization_config.mode = function_to_call.mode;
167-
recursive_initialization = util_make_unique<recursive_initializationt>(
168-
recursive_initialization_config, goto_model);
169137
this->harness_function_name = harness_function_name;
138+
const auto &function_to_call = lookup_function_to_call();
170139
ensure_harness_does_not_already_exist();
171140

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

175149
generate_nondet_globals(function_body);
176-
setup_parameters_and_call_entry_function(function_body);
150+
call_function(arguments, function_body);
177151
add_harness_function_to_goto_model(std::move(function_body));
178152
}
179153

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

0 commit comments

Comments
 (0)