Skip to content

Commit cee6d7d

Browse files
committed
call graph helper interface to "get shortest path" function of grapht
gets list of functions on shortest path between function src and function dest.
1 parent d94fe93 commit cee6d7d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/analyses/call_graph_helpers.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,25 @@ std::set<irep_idt> get_functions_reachable_within_n_steps(
101101
return get_functions_reachable_within_n_steps(
102102
graph, start_functions, n, forwards);
103103
}
104+
105+
std::set<irep_idt> get_shortest_function_path(
106+
const call_grapht::directed_grapht &graph,
107+
const irep_idt &src,
108+
const irep_idt &dest)
109+
{
110+
std::set<irep_idt> result;
111+
std::size_t start_node = *graph.get_node_index(src);
112+
std::size_t dest_node = *graph.get_node_index(dest);
113+
114+
PRECONDITION(
115+
start_node != optionalt<std::size_t>() &&
116+
dest_node != optionalt<std::size_t>());
117+
118+
std::list<std::size_t> path;
119+
graph.shortest_path(start_node, dest_node, path);
120+
121+
for(const auto &n : path)
122+
result.insert(graph[n].function);
123+
124+
return result;
125+
}

src/analyses/call_graph_helpers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ std::set<irep_idt> get_reachable_functions(
4949
std::set<irep_idt> get_reaching_functions(
5050
const call_grapht::directed_grapht &graph, const irep_idt &function);
5151

52+
/// Get list of functions on the shortest path between two functions
53+
/// \param graph: call graph
54+
/// \param src: function to start from
55+
/// \param dest: function to reach
56+
std::set<irep_idt> get_shortest_function_path(
57+
const call_grapht::directed_grapht &graph,
58+
const irep_idt &src,
59+
const irep_idt &dest);
60+
5261
/// Get either callers or callees reachable from a given
5362
/// list of functions within N steps
5463
/// \param graph: call graph

0 commit comments

Comments
 (0)