@@ -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,14 @@ 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
+ // / 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);
59
65
};
60
66
61
67
function_call_harness_generatort::function_call_harness_generatort (
@@ -125,55 +131,26 @@ void function_call_harness_generatort::generate(
125
131
p_impl->generate (goto_model, harness_function_name);
126
132
}
127
133
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
134
void function_call_harness_generatort::implt::generate (
160
135
goto_modelt &goto_model,
161
136
const irep_idt &harness_function_name)
162
137
{
163
138
symbol_table = &goto_model.symbol_table ;
164
139
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
140
this ->harness_function_name = harness_function_name;
141
+ const auto &function_to_call = lookup_function_to_call ();
170
142
ensure_harness_does_not_already_exist ();
171
143
172
144
// create body for the function
173
145
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);
174
151
175
152
generate_nondet_globals (function_body);
176
- setup_parameters_and_call_entry_function ( function_body);
153
+ call_function (arguments, function_body);
177
154
add_harness_function_to_goto_model (std::move (function_body));
178
155
}
179
156
@@ -278,3 +255,44 @@ void function_call_harness_generatort::implt::
278
255
function_to_call.mode );
279
256
body.add (goto_programt::make_end_function ());
280
257
}
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 ¶meters = 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 ¶meter : 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