Skip to content

Commit 1ad6ecc

Browse files
author
Remi Delmas
committed
CONTRACTS: new inlining and loop detection methods
Allows to to inlining and loop detection directly on a goto program instead of a goto function
1 parent aec6269 commit 1ad6ecc

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

src/goto-instrument/contracts/dynamic-frames/dfcc_utils.cpp

+45-6
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ void dfcc_utilst::inline_function(const irep_idt &function_id)
476476

477477
inlining_decoratort decorated(log.get_message_handler());
478478
namespacet ns{goto_model.symbol_table};
479-
goto_function_inline(
480-
goto_model.goto_functions, function_id, ns, log.get_message_handler());
479+
goto_function_inline(goto_model.goto_functions, function_id, ns, decorated);
481480

482481
decorated.throw_on_recursive_calls(log, 0);
483482
decorated.throw_on_no_body(log, 0);
@@ -503,8 +502,7 @@ void dfcc_utilst::inline_function(
503502

504503
inlining_decoratort decorated(log.get_message_handler());
505504
namespacet ns{goto_model.symbol_table};
506-
goto_function_inline(
507-
goto_model.goto_functions, function_id, ns, log.get_message_handler());
505+
goto_function_inline(goto_model.goto_functions, function_id, ns, decorated);
508506
no_body.insert(
509507
decorated.get_no_body_set().begin(), decorated.get_no_body_set().end());
510508
recursive_call.insert(
@@ -519,10 +517,51 @@ void dfcc_utilst::inline_function(
519517
goto_model.goto_functions.update();
520518
}
521519

520+
void dfcc_utilst::inline_program(goto_programt &program)
521+
{
522+
inlining_decoratort decorated(log.get_message_handler());
523+
namespacet ns{goto_model.symbol_table};
524+
goto_program_inline(goto_model.goto_functions, program, ns, decorated);
525+
526+
decorated.throw_on_recursive_calls(log, 0);
527+
decorated.throw_on_no_body(log, 0);
528+
decorated.throw_on_missing_function(log, 0);
529+
decorated.throw_on_not_enough_arguments(log, 0);
530+
}
531+
532+
void dfcc_utilst::inline_program(
533+
goto_programt &goto_program,
534+
std::set<irep_idt> &no_body,
535+
std::set<irep_idt> &recursive_call,
536+
std::set<irep_idt> &missing_function,
537+
std::set<irep_idt> &not_enough_arguments)
538+
{
539+
inlining_decoratort decorated(log.get_message_handler());
540+
namespacet ns{goto_model.symbol_table};
541+
goto_program_inline(goto_model.goto_functions, goto_program, ns, decorated);
542+
no_body.insert(
543+
decorated.get_no_body_set().begin(), decorated.get_no_body_set().end());
544+
recursive_call.insert(
545+
decorated.get_recursive_call_set().begin(),
546+
decorated.get_recursive_call_set().end());
547+
missing_function.insert(
548+
decorated.get_missing_function_set().begin(),
549+
decorated.get_missing_function_set().end());
550+
not_enough_arguments.insert(
551+
decorated.get_not_enough_arguments_set().begin(),
552+
decorated.get_not_enough_arguments_set().end());
553+
goto_model.goto_functions.update();
554+
}
555+
556+
bool dfcc_utilst::has_no_loops(const goto_programt &goto_program)
557+
{
558+
return is_loop_free(goto_program, ns, log);
559+
}
560+
522561
bool dfcc_utilst::has_no_loops(const irep_idt &function_id)
523562
{
524-
auto &goto_function = goto_model.goto_functions.function_map.at(function_id);
525-
return is_loop_free(goto_function.body, ns, log);
563+
return has_no_loops(
564+
goto_model.goto_functions.function_map.at(function_id).body);
526565
}
527566

528567
void dfcc_utilst::set_hide(const irep_idt &function_id, bool hide)

src/goto-instrument/contracts/dynamic-frames/dfcc_utils.h

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Date: August 2022
2020
#include <set>
2121

2222
class goto_modelt;
23+
class goto_programt;
2324
class message_handlert;
2425
class symbolt;
2526

@@ -213,6 +214,22 @@ class dfcc_utilst
213214
/// \returns True iff \p function_id is loop free.
214215
bool has_no_loops(const irep_idt &function_id);
215216

217+
/// \brief Inlines the given program, aborts on recursive calls during
218+
/// inlining.
219+
void inline_program(goto_programt &program);
220+
221+
/// \brief Inlines the given program, and returns function symbols that
222+
/// caused warnings.
223+
void inline_program(
224+
goto_programt &goto_program,
225+
std::set<irep_idt> &no_body,
226+
std::set<irep_idt> &recursive_call,
227+
std::set<irep_idt> &missing_function,
228+
std::set<irep_idt> &not_enough_arguments);
229+
230+
/// \returns True iff \p goto_program is loop free.
231+
bool has_no_loops(const goto_programt &goto_program);
232+
216233
/// \brief Sets the given hide flag on all instructions of the function if it
217234
/// exists.
218235
void set_hide(const irep_idt &function_id, bool hide);

0 commit comments

Comments
 (0)