1313
1414/* ******************************************************************\
1515
16- Function: call_grapht::call_grapht
16+ Function: call_grapht::operator()
1717
1818 Inputs:
1919
@@ -23,23 +23,7 @@ Function: call_grapht::call_grapht
2323
2424\*******************************************************************/
2525
26- call_grapht::call_grapht ()
27- {
28- }
29-
30- /* ******************************************************************\
31-
32- Function: call_grapht::call_grapht
33-
34- Inputs:
35-
36- Outputs:
37-
38- Purpose:
39-
40- \*******************************************************************/
41-
42- call_grapht::call_grapht (const goto_functionst &goto_functions)
26+ void call_grapht::operator ()()
4327{
4428 forall_goto_functions (f_it, goto_functions)
4529 {
@@ -96,6 +80,53 @@ void call_grapht::add(
9680
9781/* ******************************************************************\
9882
83+ Function: call_grapht::compute_reachable
84+
85+ Inputs:
86+
87+ Outputs:
88+
89+ Purpose:
90+
91+ \*******************************************************************/
92+
93+ void call_grapht::compute_reachable (
94+ const irep_idt entry_point,
95+ std::unordered_set<irep_idt, irep_id_hash> &reachable_functions)
96+ {
97+ assert (reachable_functions.empty ());
98+
99+ std::list<irep_idt> worklist;
100+
101+ const goto_functionst::function_mapt::const_iterator e_it=
102+ goto_functions.function_map .find (entry_point);
103+
104+ assert (e_it!=goto_functions.function_map .end ());
105+
106+ worklist.push_back (entry_point);
107+
108+ do
109+ {
110+ const irep_idt id=worklist.front ();
111+ worklist.pop_front ();
112+
113+ reachable_functions.insert (id);
114+
115+ const auto &p=graph.equal_range (id);
116+
117+ for (auto it=p.first ; it!=p.second ; it++)
118+ {
119+ const irep_idt callee=it->second ;
120+
121+ if (reachable_functions.find (callee)==reachable_functions.end ())
122+ worklist.push_back (callee);
123+ }
124+ }
125+ while (!worklist.empty ());
126+ }
127+
128+ /* ******************************************************************\
129+
99130Function: call_grapht::output_dot
100131
101132 Inputs:
0 commit comments