Skip to content

Commit 799d034

Browse files
committed
return shortest path from function call graph
Returns the list of functions on the shortest path from a src function to a destination function on the function call graph.
1 parent 04e56c3 commit 799d034

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/analyses/call_graph.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ call_grapht call_grapht::get_inverted() const
107107
return result;
108108
}
109109

110+
std::list<irep_idt>call_grapht::shortest_function_path
111+
(irep_idt src, irep_idt dest)
112+
{
113+
std::list<irep_idt> result;
114+
node_indext src_idx, dest_idx;
115+
if(!get_node_index(src, src_idx))
116+
throw "unable to find src function in call graph";
117+
if(!get_node_index(dest, dest_idx))
118+
throw "unable to find destination function in call graph";
119+
120+
patht path;
121+
shortest_path(src_idx, dest_idx, path);
122+
for(const auto &n : path)
123+
{
124+
result.push_back(nodes[n].function_name);
125+
}
126+
return result;
127+
}
128+
129+
110130
std::unordered_set<irep_idt, irep_id_hash>
111131
call_grapht::reachable_functions(irep_idt start_function)
112132
{

src/analyses/call_graph.h

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class call_grapht: public grapht<call_graph_nodet>
4646
call_grapht get_inverted() const;
4747
std::unordered_set<irep_idt, irep_id_hash>
4848
reachable_functions(irep_idt start);
49+
std::list<irep_idt>shortest_function_path(irep_idt src, irep_idt dest);
4950

5051
bool get_node_index(const irep_idt& function_name, node_indext &n) const
5152
{

0 commit comments

Comments
 (0)