@@ -66,106 +66,51 @@ void memory_snapshot_harness_generatort::validate_options(
66
66
" --harness-type initialise-from-memory-snapshot" );
67
67
}
68
68
69
- if (entry_function_name .empty ())
69
+ if (initial_source_location_line. empty () == initial_goto_location_line .empty ())
70
70
{
71
- INVARIANT (
72
- !location_number.has_value (),
73
- " when `function` is empty then the option --initial-location was not "
74
- " given and thus `location_number` was not set" );
75
-
76
71
throw invalid_command_line_argument_exceptiont (
77
- " option --initial- location is required " ,
78
- " --harness-type initialise-from-memory-snapshot " );
72
+ " choose either source or goto location to specify the entry point " ,
73
+ " --initial-source/goto-location " );
79
74
}
80
75
81
- const auto &goto_functions = goto_model.goto_functions ;
82
- const auto &goto_function =
83
- goto_functions.function_map .find (entry_function_name);
84
- if (goto_function == goto_functions.function_map .end ())
76
+ if (!initial_source_location_line.empty ())
85
77
{
86
- throw invalid_command_line_argument_exceptiont (
87
- " unknown initial location specification" , " --initial-location" );
78
+ entry_location = initialize_entry_via_source (
79
+ parse_source_location (initial_source_location_line),
80
+ goto_model.goto_functions );
88
81
}
89
-
90
- if (!goto_function->second .body_available ())
91
- {
92
- throw invalid_command_line_argument_exceptiont (
93
- " given function `" + id2string (entry_function_name) +
94
- " ` does not have a body" ,
95
- " --initial-location" );
96
- }
97
-
98
- if (location_number.has_value ())
99
- {
100
- const auto &goto_program = goto_function->second .body ;
101
- const auto opt_it = goto_program.get_target (*location_number);
102
-
103
- if (!opt_it.has_value ())
104
- {
105
- throw invalid_command_line_argument_exceptiont (
106
- " no instruction with location number " +
107
- std::to_string (*location_number) + " in function " +
108
- id2string (entry_function_name),
109
- " --initial-location" );
110
- }
111
- }
112
-
113
- if (goto_functions.function_map .count (INITIALIZE_FUNCTION) == 0 )
82
+ else
114
83
{
115
- throw invalid_command_line_argument_exceptiont (
116
- " invalid input program: " + std::string (INITIALIZE_FUNCTION) +
117
- " not found" ,
118
- " <in>" );
84
+ entry_location = initialize_entry_via_goto (
85
+ parse_goto_location (initial_goto_location_line),
86
+ goto_model.goto_functions );
119
87
}
120
88
121
89
const symbol_tablet &symbol_table = goto_model.symbol_table ;
90
+
122
91
const symbolt *called_function_symbol =
123
- symbol_table.lookup (entry_function_name );
92
+ symbol_table.lookup (entry_location. function_name );
124
93
125
94
if (called_function_symbol == nullptr )
126
95
{
127
96
throw invalid_command_line_argument_exceptiont (
128
- " function `" + id2string (entry_function_name ) +
97
+ " function `" + id2string (entry_location. function_name ) +
129
98
" ` not found in the symbol table" ,
130
99
" --initial-location" );
131
100
}
132
101
}
133
102
134
103
void memory_snapshot_harness_generatort::add_init_section (
104
+ const symbol_exprt &func_init_done_var,
135
105
goto_modelt &goto_model) const
136
106
{
137
107
goto_functionst &goto_functions = goto_model.goto_functions ;
138
- symbol_tablet &symbol_table = goto_model.symbol_table ;
139
108
140
109
goto_functiont &goto_function =
141
- goto_functions.function_map [entry_function_name];
142
- const symbolt &function_symbol = symbol_table.lookup_ref (entry_function_name);
110
+ goto_functions.function_map [entry_location.function_name ];
143
111
144
112
goto_programt &goto_program = goto_function.body ;
145
113
146
- // introduce a symbol for a Boolean variable to indicate the point at which
147
- // the function initialisation is completed
148
- symbolt &func_init_done_symbol = get_fresh_aux_symbol (
149
- bool_typet (),
150
- id2string (entry_function_name),
151
- " func_init_done" ,
152
- function_symbol.location ,
153
- function_symbol.mode ,
154
- symbol_table);
155
- func_init_done_symbol.is_static_lifetime = true ;
156
- func_init_done_symbol.value = false_exprt ();
157
-
158
- const symbol_exprt func_init_done_var = func_init_done_symbol.symbol_expr ();
159
-
160
- // initialise func_init_done_var in __CPROVER_initialize if it is present
161
- // so that it's FALSE value is visible before the harnessed function is called
162
- goto_programt &cprover_initialize =
163
- goto_functions.function_map .find (INITIALIZE_FUNCTION)->second .body ;
164
- cprover_initialize.insert_before (
165
- std::prev (cprover_initialize.instructions .end ()),
166
- goto_programt::make_assignment (
167
- code_assignt (func_init_done_var, false_exprt ())));
168
-
169
114
const goto_programt::const_targett start_it =
170
115
goto_program.instructions .begin ();
171
116
@@ -182,9 +127,8 @@ void memory_snapshot_harness_generatort::add_init_section(
182
127
goto_program.compute_location_numbers ();
183
128
goto_program.insert_after (
184
129
ins_it2,
185
- goto_programt::make_goto (goto_program.const_cast_target (
186
- location_number.has_value () ? *goto_program.get_target (*location_number)
187
- : start_it)));
130
+ goto_programt::make_goto (
131
+ goto_program.const_cast_target (entry_location.start_instruction )));
188
132
}
189
133
190
134
code_blockt memory_snapshot_harness_generatort::add_assignments_to_globals (
@@ -310,13 +254,28 @@ void memory_snapshot_harness_generatort::generate(
310
254
goto_functionst &goto_functions = goto_model.goto_functions ;
311
255
312
256
const symbolt *called_function_symbol =
313
- symbol_table.lookup (entry_function_name);
257
+ symbol_table.lookup (entry_location.function_name );
258
+
259
+ // introduce a symbol for a Boolean variable to indicate the point at which
260
+ // the function initialisation is completed
261
+ auto &func_init_done_symbol = get_fresh_aux_symbol (
262
+ bool_typet (),
263
+ id2string (entry_location.function_name ),
264
+ " func_init_done" ,
265
+ source_locationt::nil (),
266
+ called_function_symbol->mode ,
267
+ symbol_table);
268
+ func_init_done_symbol.is_static_lifetime = true ;
269
+ func_init_done_symbol.value = false_exprt ();
270
+ symbol_exprt func_init_done_var = func_init_done_symbol.symbol_expr ();
314
271
315
- add_init_section (goto_model);
272
+ add_init_section (func_init_done_var, goto_model);
316
273
317
274
code_blockt harness_function_body =
318
275
add_assignments_to_globals (snapshot, goto_model);
319
276
277
+ harness_function_body.add (code_assignt{func_init_done_var, false_exprt{}});
278
+
320
279
add_call_with_nondet_arguments (
321
280
*called_function_symbol, harness_function_body);
322
281
0 commit comments