Skip to content

Commit 4d2a024

Browse files
authored
Merge pull request #3828 from tautschnig/function-ai
ai_baset: output now requires function identifier [blocks: #3126]
2 parents c327572 + d7db14f commit 4d2a024

File tree

6 files changed

+84
-111
lines changed

6 files changed

+84
-111
lines changed

src/analyses/ai.cpp

Lines changed: 33 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ void ai_baset::output(
3535
out << "////\n";
3636
out << "\n";
3737

38-
output(ns, f_it->second.body, f_it->first, out);
38+
output(ns, f_it->first, f_it->second.body, out);
3939
}
4040
}
4141
}
4242

4343
void ai_baset::output(
4444
const namespacet &ns,
45+
const irep_idt &function_id,
4546
const goto_programt &goto_program,
46-
const irep_idt &identifier,
4747
std::ostream &out) const
4848
{
4949
forall_goto_program_instructions(i_it, goto_program)
@@ -54,7 +54,7 @@ void ai_baset::output(
5454
abstract_state_before(i_it)->output(out, *this, ns);
5555
out << "\n";
5656
#if 1
57-
goto_program.output_instruction(ns, identifier, out, *i_it);
57+
goto_program.output_instruction(ns, function_id, out, *i_it);
5858
out << "\n";
5959
#endif
6060
}
@@ -70,8 +70,8 @@ jsont ai_baset::output_json(
7070
{
7171
if(f_it->second.body_available())
7272
{
73-
result[id2string(f_it->first)]=
74-
output_json(ns, f_it->second.body, f_it->first);
73+
result[id2string(f_it->first)] =
74+
output_json(ns, f_it->first, f_it->second.body);
7575
}
7676
else
7777
{
@@ -82,24 +82,18 @@ jsont ai_baset::output_json(
8282
return std::move(result);
8383
}
8484

85-
/// Output the domains for a single function as JSON
86-
/// \param ns: The namespace
87-
/// \param goto_program: The goto program
88-
/// \param identifier: The identifier used to find a symbol to identify the
89-
/// source language
90-
/// \return The JSON object
9185
jsont ai_baset::output_json(
9286
const namespacet &ns,
93-
const goto_programt &goto_program,
94-
const irep_idt &identifier) const
87+
const irep_idt &function_id,
88+
const goto_programt &goto_program) const
9589
{
9690
json_arrayt contents;
9791

9892
forall_goto_program_instructions(i_it, goto_program)
9993
{
10094
// Ideally we need output_instruction_json
10195
std::ostringstream out;
102-
goto_program.output_instruction(ns, identifier, out, *i_it);
96+
goto_program.output_instruction(ns, function_id, out, *i_it);
10397

10498
json_objectt location(
10599
{{"locationNumber", json_numbert(std::to_string(i_it->location_number))},
@@ -129,7 +123,7 @@ xmlt ai_baset::output_xml(
129123

130124
if(f_it->second.body_available())
131125
{
132-
function.new_element(output_xml(ns, f_it->second.body, f_it->first));
126+
function.new_element(output_xml(ns, f_it->first, f_it->second.body));
133127
}
134128

135129
program.new_element(function);
@@ -138,16 +132,10 @@ xmlt ai_baset::output_xml(
138132
return program;
139133
}
140134

141-
/// Output the domains for a single function as XML
142-
/// \param ns: The namespace
143-
/// \param goto_program: The goto program
144-
/// \param identifier: The identifier used to find a symbol to identify the
145-
/// source language
146-
/// \return The XML object
147135
xmlt ai_baset::output_xml(
148136
const namespacet &ns,
149-
const goto_programt &goto_program,
150-
const irep_idt &identifier) const
137+
const irep_idt &function_id,
138+
const goto_programt &goto_program) const
151139
{
152140
xmlt function_body;
153141

@@ -161,7 +149,7 @@ xmlt ai_baset::output_xml(
161149

162150
// Ideally we need output_instruction_xml
163151
std::ostringstream out;
164-
goto_program.output_instruction(ns, identifier, out, *i_it);
152+
goto_program.output_instruction(ns, function_id, out, *i_it);
165153
location.set_attribute("instruction", out.str());
166154

167155
function_body.new_element(location);
@@ -187,12 +175,14 @@ void ai_baset::entry_state(const goto_programt &goto_program)
187175
get_state(goto_program.instructions.begin()).make_entry();
188176
}
189177

190-
void ai_baset::initialize(const goto_functionst::goto_functiont &goto_function)
178+
void ai_baset::initialize(
179+
const irep_idt &function_id,
180+
const goto_functionst::goto_functiont &goto_function)
191181
{
192-
initialize(goto_function.body);
182+
initialize(function_id, goto_function.body);
193183
}
194184

195-
void ai_baset::initialize(const goto_programt &goto_program)
185+
void ai_baset::initialize(const irep_idt &, const goto_programt &goto_program)
196186
{
197187
// we mark everything as unreachable as starting point
198188

@@ -203,7 +193,7 @@ void ai_baset::initialize(const goto_programt &goto_program)
203193
void ai_baset::initialize(const goto_functionst &goto_functions)
204194
{
205195
forall_goto_functions(it, goto_functions)
206-
initialize(it->second);
196+
initialize(it->first, it->second);
207197
}
208198

209199
void ai_baset::finalize()
@@ -224,7 +214,7 @@ ai_baset::locationt ai_baset::get_next(
224214
}
225215

226216
bool ai_baset::fixedpoint(
227-
const irep_idt &function_identifier,
217+
const irep_idt &function_id,
228218
const goto_programt &goto_program,
229219
const goto_functionst &goto_functions,
230220
const namespacet &ns)
@@ -244,16 +234,15 @@ bool ai_baset::fixedpoint(
244234
locationt l=get_next(working_set);
245235

246236
// goto_program is really only needed for iterator manipulation
247-
if(visit(
248-
function_identifier, l, working_set, goto_program, goto_functions, ns))
237+
if(visit(function_id, l, working_set, goto_program, goto_functions, ns))
249238
new_data=true;
250239
}
251240

252241
return new_data;
253242
}
254243

255244
bool ai_baset::visit(
256-
const irep_idt &function_identifier,
245+
const irep_idt &function_id,
257246
locationt l,
258247
working_sett &working_set,
259248
const goto_programt &goto_program,
@@ -284,7 +273,7 @@ bool ai_baset::visit(
284273
to_code_function_call(l->code);
285274

286275
if(do_function_call_rec(
287-
function_identifier,
276+
function_id,
288277
l,
289278
to_l,
290279
code.function(),
@@ -298,8 +287,7 @@ bool ai_baset::visit(
298287
// initialize state, if necessary
299288
get_state(to_l);
300289

301-
new_values.transform(
302-
function_identifier, l, function_identifier, to_l, *this, ns);
290+
new_values.transform(function_id, l, function_id, to_l, *this, ns);
303291

304292
if(merge(new_values, l, to_l))
305293
have_new_values=true;
@@ -316,7 +304,7 @@ bool ai_baset::visit(
316304
}
317305

318306
bool ai_baset::do_function_call(
319-
const irep_idt &calling_function_identifier,
307+
const irep_idt &calling_function_id,
320308
locationt l_call,
321309
locationt l_return,
322310
const goto_functionst &goto_functions,
@@ -337,12 +325,7 @@ bool ai_baset::do_function_call(
337325
// If we don't have a body, we just do an edge call -> return
338326
std::unique_ptr<statet> tmp_state(make_temporary_state(get_state(l_call)));
339327
tmp_state->transform(
340-
calling_function_identifier,
341-
l_call,
342-
calling_function_identifier,
343-
l_return,
344-
*this,
345-
ns);
328+
calling_function_id, l_call, calling_function_id, l_return, *this, ns);
346329

347330
return merge(*tmp_state, l_call, l_return);
348331
}
@@ -360,7 +343,7 @@ bool ai_baset::do_function_call(
360343
// do the edge from the call site to the beginning of the function
361344
std::unique_ptr<statet> tmp_state(make_temporary_state(get_state(l_call)));
362345
tmp_state->transform(
363-
calling_function_identifier, l_call, f_it->first, l_begin, *this, ns);
346+
calling_function_id, l_call, f_it->first, l_begin, *this, ns);
364347

365348
bool new_data=false;
366349

@@ -388,15 +371,15 @@ bool ai_baset::do_function_call(
388371

389372
std::unique_ptr<statet> tmp_state(make_temporary_state(end_state));
390373
tmp_state->transform(
391-
f_it->first, l_end, calling_function_identifier, l_return, *this, ns);
374+
f_it->first, l_end, calling_function_id, l_return, *this, ns);
392375

393376
// Propagate those
394377
return merge(*tmp_state, l_end, l_return);
395378
}
396379
}
397380

398381
bool ai_baset::do_function_call_rec(
399-
const irep_idt &calling_function_identifier,
382+
const irep_idt &calling_function_id,
400383
locationt l_call,
401384
locationt l_return,
402385
const exprt &function,
@@ -424,13 +407,7 @@ bool ai_baset::do_function_call_rec(
424407
"Function " + id2string(identifier) + "not in function map");
425408

426409
new_data = do_function_call(
427-
calling_function_identifier,
428-
l_call,
429-
l_return,
430-
goto_functions,
431-
it,
432-
arguments,
433-
ns);
410+
calling_function_id, l_call, l_return, goto_functions, it, arguments, ns);
434411

435412
return new_data;
436413
}
@@ -464,16 +441,16 @@ void ai_baset::concurrent_fixedpoint(
464441
struct wl_entryt
465442
{
466443
wl_entryt(
467-
const irep_idt &_function_identifier,
444+
const irep_idt &_function_id,
468445
const goto_programt &_goto_program,
469446
locationt _location)
470-
: function_identifier(_function_identifier),
447+
: function_id(_function_id),
471448
goto_program(&_goto_program),
472449
location(_location)
473450
{
474451
}
475452

476-
irep_idt function_identifier;
453+
irep_idt function_id;
477454
const goto_programt *goto_program;
478455
locationt location;
479456
};
@@ -516,7 +493,7 @@ void ai_baset::concurrent_fixedpoint(
516493
goto_programt::const_targett l=get_next(working_set);
517494

518495
visit(
519-
wl_entry.function_identifier,
496+
wl_entry.function_id,
520497
l,
521498
working_set,
522499
*(wl_entry.goto_program),

0 commit comments

Comments
 (0)