@@ -16,8 +16,12 @@ Author: Diffblue Ltd.
16
16
#include < util/std_code.h>
17
17
#include < util/std_expr.h>
18
18
#include < util/string2int.h>
19
+ #include < util/string_utils.h>
19
20
#include < util/ui_message.h>
20
21
22
+ #include < algorithm>
23
+ #include < set>
24
+
21
25
#include " function_harness_generator_options.h"
22
26
#include " goto_harness_parse_options.h"
23
27
#include " recursive_initialization.h"
@@ -43,9 +47,6 @@ struct function_call_harness_generatort::implt
43
47
// / Iterate over the symbol table and generate initialisation code for
44
48
// / globals into the function body.
45
49
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);
49
50
// / Return a reference to the entry function or throw if it doesn't exist.
50
51
const symbolt &lookup_function_to_call ();
51
52
// / Generate initialisation code for one lvalue inside block.
@@ -54,6 +55,11 @@ struct function_call_harness_generatort::implt
54
55
void ensure_harness_does_not_already_exist ();
55
56
// / Update the goto-model with the new harness function.
56
57
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);
57
63
};
58
64
59
65
function_call_harness_generatort::function_call_harness_generatort (
@@ -123,55 +129,26 @@ void function_call_harness_generatort::generate(
123
129
p_impl->generate (goto_model, harness_function_name);
124
130
}
125
131
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 ¶meters = 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 ¶meter : 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
-
157
132
void function_call_harness_generatort::implt::generate (
158
133
goto_modelt &goto_model,
159
134
const irep_idt &harness_function_name)
160
135
{
161
136
symbol_table = &goto_model.symbol_table ;
162
137
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);
167
138
this ->harness_function_name = harness_function_name;
139
+ const auto &function_to_call = lookup_function_to_call ();
168
140
ensure_harness_does_not_already_exist ();
169
141
170
142
// create body for the function
171
143
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);
172
149
173
150
generate_nondet_globals (function_body);
174
- setup_parameters_and_call_entry_function ( function_body);
151
+ call_function (arguments, function_body);
175
152
add_harness_function_to_goto_model (std::move (function_body));
176
153
}
177
154
@@ -264,3 +241,44 @@ void function_call_harness_generatort::implt::
264
241
function_to_call.mode );
265
242
body.add (goto_programt::make_end_function ());
266
243
}
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 ¶meters = 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 ¶meter : 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