Skip to content

Commit f25f5a0

Browse files
committed
call graph helper interface to depth limited search
Gets all functions reachable within n steps, by calling depth limited search
1 parent feef3cd commit f25f5a0

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/analyses/call_graph_helpers.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,21 @@ std::set<irep_idt> get_reaching_functions(
7070
{
7171
return get_connected_functions(graph, function, false);
7272
}
73+
74+
std::set<irep_idt> get_functions_reachable_within_n_steps(
75+
const call_grapht::directed_grapht &graph,
76+
const irep_idt &start_function,
77+
std::size_t n)
78+
{
79+
std::set<irep_idt> result;
80+
81+
if(auto start_idx = graph.get_node_index(start_function))
82+
{
83+
for(const auto &index : graph.depth_limited_search(*start_idx, n))
84+
result.insert(graph[index].function);
85+
}
86+
else
87+
throw "unknown start function";
88+
89+
return result;
90+
}

src/analyses/call_graph_helpers.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,18 @@ 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+
53+
/// Get either callers or callees reachable from a given
54+
/// start function within N steps
55+
/// \param graph: call graph
56+
/// \param start_function: single start function
57+
/// \param n: number of steps to consider
58+
/// \param forwards: if true, get callees; otherwise get callers
59+
/// \return set of functions that can be reached from the start function
60+
/// including the start function
61+
std::set<irep_idt> get_functions_reachable_within_n_steps(
62+
const call_grapht::directed_grapht &graph,
63+
const irep_idt &start_function,
64+
std::size_t n);
65+
5266
#endif

0 commit comments

Comments
 (0)