Skip to content

Commit e639d76

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 ca12c1c commit e639d76

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
@@ -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,14 @@ 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+
/// declare local variables for each of the parameters of the entry function
58+
/// and return them
59+
code_function_callt::argumentst declare_arguments(code_blockt &function_body);
60+
/// write initialisation code for each of the arguments into function_body,
61+
/// then insert a call to the entry function with the arguments
62+
void call_function(
63+
const code_function_callt::argumentst &arguments,
64+
code_blockt &function_body);
5965
};
6066

6167
function_call_harness_generatort::function_call_harness_generatort(
@@ -125,55 +131,26 @@ void function_call_harness_generatort::generate(
125131
p_impl->generate(goto_model, harness_function_name);
126132
}
127133

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-
159134
void function_call_harness_generatort::implt::generate(
160135
goto_modelt &goto_model,
161136
const irep_idt &harness_function_name)
162137
{
163138
symbol_table = &goto_model.symbol_table;
164139
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);
169140
this->harness_function_name = harness_function_name;
141+
const auto &function_to_call = lookup_function_to_call();
170142
ensure_harness_does_not_already_exist();
171143

172144
// create body for the function
173145
code_blockt function_body{};
146+
auto const arguments = declare_arguments(function_body);
147+
148+
recursive_initialization_config.mode = function_to_call.mode;
149+
recursive_initialization = util_make_unique<recursive_initializationt>(
150+
recursive_initialization_config, goto_model);
174151

175152
generate_nondet_globals(function_body);
176-
setup_parameters_and_call_entry_function(function_body);
153+
call_function(arguments, function_body);
177154
add_harness_function_to_goto_model(std::move(function_body));
178155
}
179156

@@ -278,3 +255,44 @@ void function_call_harness_generatort::implt::
278255
function_to_call.mode);
279256
body.add(goto_programt::make_end_function());
280257
}
258+
259+
code_function_callt::argumentst
260+
function_call_harness_generatort::implt::declare_arguments(
261+
code_blockt &function_body)
262+
{
263+
const auto &function_to_call = lookup_function_to_call();
264+
const auto &function_type = to_code_type(function_to_call.type);
265+
const auto &parameters = function_type.parameters();
266+
267+
code_function_callt::operandst arguments{};
268+
269+
auto allocate_objects = allocate_objectst{function_to_call.mode,
270+
function_to_call.location,
271+
"__goto_harness",
272+
*symbol_table};
273+
for(const auto &parameter : parameters)
274+
{
275+
auto argument = allocate_objects.allocate_automatic_local_object(
276+
parameter.type(), parameter.get_base_name());
277+
arguments.push_back(argument);
278+
}
279+
280+
allocate_objects.declare_created_symbols(function_body);
281+
return arguments;
282+
}
283+
284+
void function_call_harness_generatort::implt::call_function(
285+
const code_function_callt::argumentst &arguments,
286+
code_blockt &function_body)
287+
{
288+
auto const &function_to_call = lookup_function_to_call();
289+
for(auto const &argument : arguments)
290+
{
291+
generate_initialisation_code_for(function_body, argument);
292+
}
293+
code_function_callt function_call{function_to_call.symbol_expr(),
294+
std::move(arguments)};
295+
function_call.add_source_location() = function_to_call.location;
296+
297+
function_body.add(std::move(function_call));
298+
}

0 commit comments

Comments
 (0)