@@ -15,6 +15,7 @@ Author: Diffblue Ltd.
15
15
#include < util/std_code.h>
16
16
#include < util/std_expr.h>
17
17
#include < util/string2int.h>
18
+ #include < util/string_utils.h>
18
19
#include < util/ui_message.h>
19
20
20
21
#include < goto-programs/goto_convert.h>
@@ -45,9 +46,6 @@ struct function_call_harness_generatort::implt
45
46
// / Iterate over the symbol table and generate initialisation code for
46
47
// / globals into the function body.
47
48
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);
51
49
// / Return a reference to the entry function or throw if it doesn't exist.
52
50
const symbolt &lookup_function_to_call ();
53
51
// / Generate initialisation code for one lvalue inside block.
@@ -56,6 +54,11 @@ struct function_call_harness_generatort::implt
56
54
void ensure_harness_does_not_already_exist ();
57
55
// / Update the goto-model with the new harness function.
58
56
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);
59
62
};
60
63
61
64
function_call_harness_generatort::function_call_harness_generatort (
@@ -125,55 +128,26 @@ void function_call_harness_generatort::generate(
125
128
p_impl->generate (goto_model, harness_function_name);
126
129
}
127
130
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 ¶meters = 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 ¶meter : 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
-
159
131
void function_call_harness_generatort::implt::generate (
160
132
goto_modelt &goto_model,
161
133
const irep_idt &harness_function_name)
162
134
{
163
135
symbol_table = &goto_model.symbol_table ;
164
136
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);
169
137
this ->harness_function_name = harness_function_name;
138
+ const auto &function_to_call = lookup_function_to_call ();
170
139
ensure_harness_does_not_already_exist ();
171
140
172
141
// create body for the function
173
142
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);
174
148
175
149
generate_nondet_globals (function_body);
176
- setup_parameters_and_call_entry_function ( function_body);
150
+ call_function (arguments, function_body);
177
151
add_harness_function_to_goto_model (std::move (function_body));
178
152
}
179
153
@@ -266,3 +240,44 @@ void function_call_harness_generatort::implt::
266
240
function_to_call.mode );
267
241
body.add (goto_programt::make_end_function ());
268
242
}
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 ¶meters = 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 ¶meter : 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