Skip to content

Commit 9ec8484

Browse files
author
Remi Delmas
committed
Add new function to inline calls in a goto_program
1 parent ce1ce13 commit 9ec8484

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

src/goto-programs/goto_inline.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,36 @@ jsont goto_function_inline_and_log(
354354

355355
return goto_inline.output_inline_log_json();
356356
}
357+
358+
/// Transitively inline all function calls found in a particular program.
359+
/// Caller is responsible for calling update(), compute_loop_numbers(), etc.
360+
/// \param goto_functions: The function map to use to find function bodies.
361+
/// \param goto_program: The program whose calls to inline.
362+
/// \param ns: Namespace used by goto_inlinet.
363+
/// \param message_handler: Message handler used by goto_inlinet.
364+
/// \param adjust_function: Replace location in inlined function with call site.
365+
/// \param caching: Tell goto_inlinet to cache.
366+
void goto_program_inline(
367+
goto_functionst &goto_functions,
368+
goto_programt &goto_program,
369+
const namespacet &ns,
370+
message_handlert &message_handler,
371+
bool adjust_function,
372+
bool caching)
373+
{
374+
goto_inlinet goto_inline(
375+
goto_functions, ns, message_handler, adjust_function, caching);
376+
377+
// gather all calls found in the program
378+
goto_inlinet::call_listt call_list;
379+
380+
Forall_goto_program_instructions(i_it, goto_program)
381+
{
382+
if(!i_it->is_function_call())
383+
continue;
384+
385+
call_list.push_back(goto_inlinet::callt(i_it, true));
386+
}
387+
388+
goto_inline.goto_inline(call_list, goto_program, true);
389+
}

src/goto-programs/goto_inline.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
1818

1919
class goto_functionst;
2020
class goto_modelt;
21+
class goto_programt;
2122
class message_handlert;
2223
class namespacet;
2324

@@ -74,4 +75,12 @@ jsont goto_function_inline_and_log(
7475
bool adjust_function=false,
7576
bool caching=true);
7677

78+
void goto_program_inline(
79+
goto_functionst &goto_functions,
80+
goto_programt &goto_program,
81+
const namespacet &ns,
82+
message_handlert &message_handler,
83+
bool adjust_function = false,
84+
bool caching = true);
85+
7786
#endif // CPROVER_GOTO_PROGRAMS_GOTO_INLINE_H

src/goto-programs/goto_inline_class.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,26 @@ void goto_inlinet::goto_inline(
488488
force_full);
489489
}
490490

491+
/// Inline specified calls in a given program.
492+
/// \param call_list : calls to inline in the program.
493+
/// \param goto_function : to program to inline in.
494+
/// \param force_full : true to break recursion with a SKIP,
495+
/// false means detecting recursion is an error.
496+
void goto_inlinet::goto_inline(
497+
const goto_inlinet::call_listt &call_list,
498+
goto_programt &goto_program,
499+
const bool force_full)
500+
{
501+
recursion_set.clear();
502+
for(const auto &call : call_list)
503+
{
504+
// each top level call in the program gets its own fresh inline map
505+
const inline_mapt inline_map;
506+
expand_function_call(
507+
goto_program, inline_map, call.second, force_full, call.first);
508+
}
509+
}
510+
491511
void goto_inlinet::goto_inline_nontransitive(
492512
const irep_idt identifier,
493513
goto_functiont &goto_function,

src/goto-programs/goto_inline_class.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ class goto_inlinet
6969
const inline_mapt &inline_map,
7070
const bool force_full=false);
7171

72+
/// Inline specified calls in a goto_program.
73+
/// force_full:
74+
/// - true: put skip on recursion and issue warning
75+
/// - false: leave call on recursion
76+
void goto_inline(
77+
const goto_inlinet::call_listt &call_list,
78+
goto_programt &goto_program,
79+
const bool force_full = false);
80+
7281
// handle all functions
7382
void goto_inline(
7483
const inline_mapt &inline_map,

0 commit comments

Comments
 (0)