Skip to content

Commit 5dfcc91

Browse files
Daniel Kroeningtautschnig
Daniel Kroening
authored andcommitted
goto_unwindt now takes function identifier
We are working towards removing the "function" field from goto_programt::instructionst::instructiont, and thus need to pass the identifier of the function whenever it actually is required.
1 parent c327572 commit 5dfcc91

File tree

3 files changed

+43
-22
lines changed

3 files changed

+43
-22
lines changed

src/goto-instrument/k_induction.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,25 @@ Author: Daniel Kroening, [email protected]
2424
class k_inductiont
2525
{
2626
public:
27-
typedef goto_functionst::goto_functiont goto_functiont;
28-
2927
k_inductiont(
28+
const irep_idt &_function_id,
3029
goto_functiont &_goto_function,
31-
bool _base_case, bool _step_case,
32-
unsigned _k):
33-
goto_function(_goto_function),
34-
local_may_alias(_goto_function),
35-
natural_loops(_goto_function.body),
36-
base_case(_base_case), step_case(_step_case), k(_k)
30+
bool _base_case,
31+
bool _step_case,
32+
unsigned _k)
33+
: function_id(_function_id),
34+
goto_function(_goto_function),
35+
local_may_alias(_goto_function),
36+
natural_loops(_goto_function.body),
37+
base_case(_base_case),
38+
step_case(_step_case),
39+
k(_k)
3740
{
3841
k_induction();
3942
}
4043

4144
protected:
45+
const irep_idt &function_id;
4246
goto_functiont &goto_function;
4347
local_may_aliast local_may_alias;
4448
natural_loops_mutablet natural_loops;
@@ -70,8 +74,13 @@ void k_inductiont::process_loop(
7074
{
7175
// now unwind k times
7276
goto_unwindt goto_unwind;
73-
goto_unwind.unwind(goto_function.body, loop_head, loop_exit, k,
74-
goto_unwindt::unwind_strategyt::PARTIAL);
77+
goto_unwind.unwind(
78+
function_id,
79+
goto_function.body,
80+
loop_head,
81+
loop_exit,
82+
k,
83+
goto_unwindt::unwind_strategyt::PARTIAL);
7584

7685
// assume the loop condition has become false
7786
goto_programt::instructiont assume(ASSUME);
@@ -96,10 +105,11 @@ void k_inductiont::process_loop(
96105

97106
goto_unwindt goto_unwind;
98107
goto_unwind.unwind(
108+
function_id,
99109
goto_function.body,
100110
loop_head,
101111
loop_exit,
102-
k+1,
112+
k + 1,
103113
goto_unwindt::unwind_strategyt::PARTIAL,
104114
iteration_points);
105115

@@ -155,5 +165,5 @@ void k_induction(
155165
unsigned k)
156166
{
157167
Forall_goto_functions(it, goto_model.goto_functions)
158-
k_inductiont(it->second, base_case, step_case, k);
168+
k_inductiont(it->first, it->second, base_case, step_case, k);
159169
}

src/goto-instrument/unwind.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,26 @@ void goto_unwindt::copy_segment(
8080
}
8181

8282
void goto_unwindt::unwind(
83+
const irep_idt &function_id,
8384
goto_programt &goto_program,
8485
const goto_programt::const_targett loop_head,
8586
const goto_programt::const_targett loop_exit,
8687
const unsigned k,
8788
const unwind_strategyt unwind_strategy)
8889
{
8990
std::vector<goto_programt::targett> iteration_points;
90-
unwind(goto_program, loop_head, loop_exit, k, unwind_strategy,
91-
iteration_points);
91+
unwind(
92+
function_id,
93+
goto_program,
94+
loop_head,
95+
loop_exit,
96+
k,
97+
unwind_strategy,
98+
iteration_points);
9299
}
93100

94101
void goto_unwindt::unwind(
102+
const irep_idt &function_id,
95103
goto_programt &goto_program,
96104
const goto_programt::const_targett loop_head,
97105
const goto_programt::const_targett loop_exit,
@@ -258,6 +266,7 @@ void goto_unwindt::unwind(
258266
}
259267

260268
void goto_unwindt::unwind(
269+
const irep_idt &function_id,
261270
goto_programt &goto_program,
262271
const unwindsett &unwindset,
263272
const unwind_strategyt unwind_strategy)
@@ -278,11 +287,9 @@ void goto_unwindt::unwind(
278287
continue;
279288
}
280289

281-
const irep_idt func=i_it->function;
282-
assert(!func.empty());
283-
284-
const irep_idt loop_id=
285-
id2string(func) + "." + std::to_string(i_it->loop_number);
290+
PRECONDITION(!function_id.empty());
291+
const irep_idt loop_id =
292+
id2string(function_id) + "." + std::to_string(i_it->loop_number);
286293

287294
auto limit=unwindset.get_limit(loop_id, 0);
288295

@@ -298,7 +305,8 @@ void goto_unwindt::unwind(
298305
loop_exit++;
299306
assert(loop_exit!=goto_program.instructions.end());
300307

301-
unwind(goto_program, loop_head, loop_exit, *limit, unwind_strategy);
308+
unwind(
309+
function_id, goto_program, loop_head, loop_exit, *limit, unwind_strategy);
302310

303311
// necessary as we change the goto program in the previous line
304312
i_it=loop_exit;
@@ -323,7 +331,7 @@ void goto_unwindt::operator()(
323331

324332
goto_programt &goto_program=goto_function.body;
325333

326-
unwind(goto_program, unwindset, unwind_strategy);
334+
unwind(it->first, goto_program, unwindset, unwind_strategy);
327335
}
328336
}
329337

src/goto-instrument/unwind.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ class goto_unwindt
2828
// unwind loop
2929

3030
void unwind(
31+
const irep_idt &function_id,
3132
goto_programt &goto_program,
3233
const goto_programt::const_targett loop_head,
3334
const goto_programt::const_targett loop_exit,
3435
const unsigned k, // bound for given loop
3536
const unwind_strategyt unwind_strategy);
3637

3738
void unwind(
39+
const irep_idt &function_id,
3840
goto_programt &goto_program,
3941
const goto_programt::const_targett loop_head,
4042
const goto_programt::const_targett loop_exit,
@@ -45,9 +47,10 @@ class goto_unwindt
4547
// unwind function
4648

4749
void unwind(
50+
const irep_idt &function_id,
4851
goto_programt &goto_program,
4952
const unwindsett &unwindset,
50-
const unwind_strategyt unwind_strategy=unwind_strategyt::PARTIAL);
53+
const unwind_strategyt unwind_strategy = unwind_strategyt::PARTIAL);
5154

5255
// unwind all functions
5356
void operator()(

0 commit comments

Comments
 (0)