8
8
#include < iostream>
9
9
#include < fstream>
10
10
11
- cutpoint_graph ::~cutpoint_graph () {
11
+ cutpoint_grapht ::~cutpoint_grapht () {
12
12
m_edges.clear ();
13
13
m_cps.clear ();
14
14
m_insts.clear ();
15
15
}
16
16
17
- void cutpoint_graph ::run (const goto_functiont & goto_function)
17
+ void cutpoint_grapht ::run (const goto_functiont & goto_function)
18
18
{
19
- computeCutpoints (goto_function);
20
- computeFwdReach (goto_function);
21
- computeBwdReach (goto_function);
22
- computeEdges (goto_function);
19
+ compute_cutpoints (goto_function);
20
+ compute_fwd_reach (goto_function);
21
+ compute_bwd_reach (goto_function);
22
+ compute_edges (goto_function);
23
23
24
- toDot (goto_function, " cp.dot" );
24
+ to_dot (goto_function, " cp.dot" );
25
25
}
26
26
27
- void cutpoint_graph::toDot (const goto_functiont & f, std::string filename)
27
+ void cutpoint_grapht::to_dot (const goto_functiont & f, std::string filename)
28
28
{
29
29
std::ofstream out;
30
30
out.open (filename);
@@ -35,7 +35,7 @@ void cutpoint_graph::toDot(const goto_functiont & f, std::string filename)
35
35
36
36
for (auto cp : m_cps)
37
37
{
38
- cp->toDot (out, ns);
38
+ cp->to_dot (out, ns);
39
39
}
40
40
41
41
for (auto edge : m_edges)
@@ -62,7 +62,7 @@ void cutpoint_graph::toDot(const goto_functiont & f, std::string filename)
62
62
out.close ();
63
63
}
64
64
65
- cutpoint_edge_ptr cutpoint_graph::getEdge (const cutpoint &s, const cutpoint &d)
65
+ cutpoint_edge_ptr cutpoint_grapht::get_edge (const cutpointt &s, const cutpointt &d)
66
66
{
67
67
for (auto it = s.succ_begin (), end = s.succ_end (); it != end; ++it)
68
68
{
@@ -73,7 +73,8 @@ cutpoint_edge_ptr cutpoint_graph::getEdge(const cutpoint &s, const cutpoint &d)
73
73
return nullptr ;
74
74
}
75
75
76
- const cutpoint_edge_ptr cutpoint_graph::getEdge (const cutpoint &s, const cutpoint &d) const
76
+ const cutpoint_edge_ptr
77
+ cutpoint_grapht::getEdge (const cutpointt &s, const cutpointt &d) const
77
78
{
78
79
for (auto it = s.succ_begin (), end = s.succ_end (); it != end; ++it)
79
80
{
@@ -84,20 +85,20 @@ const cutpoint_edge_ptr cutpoint_graph::getEdge(const cutpoint &s, const cutpoin
84
85
return nullptr ;
85
86
}
86
87
87
- void cutpoint_graph::computeEdges (const goto_functiont &goto_function)
88
+ void cutpoint_grapht::compute_edges (const goto_functiont &goto_function)
88
89
{
89
90
forall_goto_program_instructions (it, goto_function.body )
90
91
{
91
- if (isCutpoint (*it))
92
+ if (is_cutpoint (*it))
92
93
{
93
94
std::vector<bool > & reach = m_fwd[&(*it)];
94
- cutpoint & cp = getCutpoint (*it);
95
+ cutpointt & cp = get_cutpoint (*it);
95
96
96
- for (unsigned r = 0 ; r < reach.size (); r++)
97
+ for (std:: size_t r = 0 ; r < reach.size (); r++)
97
98
{
98
99
if (reach[r] == true )
99
100
{
100
- cutpoint_edge_ptr edg = newEdge (cp, *m_cps[r]);
101
+ cutpoint_edge_ptr edg = create_edge (cp, *m_cps[r]);
101
102
edg->push_back (&(*it));
102
103
}
103
104
}
@@ -112,19 +113,19 @@ void cutpoint_graph::computeEdges (const goto_functiont &goto_function)
112
113
if (breach[i] == false ) continue ;
113
114
for (int j = 0 ; j < freach.size (); j++) {
114
115
if (freach[j] == false ) continue ;
115
- cutpoint_edge_ptr edge = getEdge (*m_cps[i], *m_cps[j]);
116
+ cutpoint_edge_ptr edge = get_edge (*m_cps[i], *m_cps[j]);
116
117
edge->push_back (&(*it));
117
118
}
118
119
}
119
120
}
120
121
}
121
122
}
122
123
123
- void cutpoint_graph::computeCutpoints (const goto_functiont &goto_function)
124
+ void cutpoint_grapht::compute_cutpoints (const goto_functiont &goto_function)
124
125
{
125
126
m_cps.clear ();
126
127
127
- std::map<const goto_programt::instructiont*, unsigned > cp_map;
128
+ std::map<const goto_programt::instructiont*, std:: size_t > cp_map;
128
129
129
130
forall_goto_program_instructions (it, goto_function.body )
130
131
{
@@ -163,14 +164,14 @@ void cutpoint_graph::computeCutpoints(const goto_functiont &goto_function)
163
164
auto i = cp_map.find (&*it);
164
165
if (i == cp_map.end ()) continue ;
165
166
auto inst = i->first ;
166
- if (isCutpoint (*inst)) continue ;
167
+ if (is_cutpoint (*inst)) continue ;
167
168
168
- m_cps.push_back (std::make_shared<cutpoint >(*this , m_cps.size (), *inst));
169
+ m_cps.push_back (std::make_shared<cutpointt >(*this , m_cps.size (), *inst));
169
170
m_insts.insert (std::make_pair (inst, m_cps.back ()));
170
171
}
171
172
}
172
173
173
- void cutpoint_graph::computeFwdReach (const goto_functiont &goto_function)
174
+ void cutpoint_grapht::compute_fwd_reach (const goto_functiont &goto_function)
174
175
{
175
176
176
177
for (auto it = goto_function.body .instructions .rbegin (); it != goto_function.body .instructions .rend ();)
@@ -179,34 +180,32 @@ void cutpoint_graph::computeFwdReach (const goto_functiont &goto_function)
179
180
auto succs = goto_function.body .get_successors (itf);
180
181
// if (succs.empty()) continue;
181
182
auto inst = &*itf;
182
- m_fwd.insert (std::make_pair (inst, reachability ()));
183
- reachability &r = m_fwd [inst];
184
- std::cout << inst->to_string () << " \n " ;
185
- if (succs.size () > 1 ) std::cout << " YAY\n " ;
183
+ m_fwd.insert (std::make_pair (inst, reachabilityt ()));
184
+ reachabilityt &r = m_fwd [inst];
186
185
for (auto succ : succs)
187
186
{
188
- if (isCutpoint (*succ))
189
- r.set (getCutpoint (*succ).id ());
187
+ if (is_cutpoint (*succ))
188
+ r.set (get_cutpoint (*succ).id ());
190
189
else
191
190
r |= m_fwd[&*succ];
192
191
193
192
}
194
193
}
195
194
}
196
195
197
- void cutpoint_graph::computeBwdReach (const goto_functiont &goto_function)
196
+ void cutpoint_grapht::compute_bwd_reach (const goto_functiont &goto_function)
198
197
{
199
198
forall_goto_program_instructions (it, goto_function.body )
200
199
{
201
200
auto inst = &*it;
202
- m_bwd.insert (std::make_pair (inst, reachability ()));
203
- reachability &r = m_bwd[inst];
201
+ m_bwd.insert (std::make_pair (inst, reachabilityt ()));
202
+ reachabilityt &r = m_bwd[inst];
204
203
for (auto pred : it->incoming_edges )
205
204
{
206
205
if (pred->is_backwards_goto ())
207
206
continue ;
208
- if (isCutpoint (*pred))
209
- r.set (getCutpoint (*pred).id ());
207
+ if (is_cutpoint (*pred))
208
+ r.set (get_cutpoint (*pred).id ());
210
209
else
211
210
r |= m_bwd[&*pred];
212
211
@@ -216,36 +215,16 @@ void cutpoint_graph::computeBwdReach (const goto_functiont &goto_function)
216
215
for (auto & cp : m_cps)
217
216
{
218
217
auto & inst = cp->inst ();
219
- reachability &r = m_bwd [&inst];
218
+ reachabilityt &r = m_bwd [&inst];
220
219
221
220
for (auto pred : inst.incoming_edges )
222
221
{
223
222
if (! pred->is_backwards_goto ()) continue ;
224
- if (isCutpoint (*pred))
225
- r.set (getCutpoint (*pred).id ());
223
+ if (is_cutpoint (*pred))
224
+ r.set (get_cutpoint (*pred).id ());
226
225
else
227
226
r |= m_bwd[&*pred];
228
227
}
229
228
}
230
229
}
231
230
232
- bool cutpoint_graph::isFwdReach (const cutpoint &cp, const goto_programt::instructiont &inst) const
233
- {
234
- if (&(cp.inst ()) == &inst) return true ;
235
-
236
- // The instruction is already a cut-point, but not the one testes.
237
- // It is impossible to reach another cut-point without getting to it
238
- if (isCutpoint (inst)) return false ;
239
-
240
- // In case the instruction is not a cut-point, retrieve the backward
241
- // reachability info (cut-point backward reachability) and check if the
242
- // cut-point is backward reachable. If it is, then the instruction
243
- // is forward reachable from the given cp.
244
- auto it = m_bwd.find (&inst);
245
- INVARIANT (it != m_bwd.end (), " No back-reachability information" );
246
-
247
- unsigned sz = it->second .size ();
248
- unsigned id = cp.id ();
249
- if (sz == 0 || id >= sz) return false ;
250
- return (it->second )[id];
251
- }
0 commit comments