Skip to content

Commit c461030

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 9082564 commit c461030

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/analyses/call_graph_helpers.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,34 @@ 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 std::set<irep_idt> &start_functions,
77+
std::size_t &n,
78+
bool forwards)
79+
{
80+
std::vector<std::size_t> start_indices;
81+
std::set<irep_idt> result;
82+
83+
for(const auto &func : start_functions)
84+
start_indices.push_back(*(graph.get_node_index(func)));
85+
86+
for(const auto &index :
87+
graph.depth_limited_search(start_indices, n, forwards))
88+
result.insert(graph[index].function);
89+
90+
return result;
91+
}
92+
93+
std::set<irep_idt> get_functions_reachable_within_n_steps(
94+
const call_grapht::directed_grapht &graph,
95+
const irep_idt &start_function,
96+
std::size_t &n,
97+
bool forwards)
98+
{
99+
std::set<irep_idt> start_functions;
100+
start_functions.insert(start_function);
101+
return get_functions_reachable_within_n_steps(
102+
graph, start_functions, n, forwards);
103+
}

src/analyses/call_graph_helpers.h

+24
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,28 @@ 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 either callers or callees reachable from a given
53+
/// list of functions within N steps
54+
/// \param graph: call graph
55+
/// \param start_functions: set of start functions
56+
/// \param forwards: if true, get callees; otherwise get callers
57+
/// \param n: number of steps to consider
58+
std::set<irep_idt> get_functions_reachable_within_n_steps(
59+
const call_grapht::directed_grapht &graph,
60+
const std::set<irep_idt> &start_functions,
61+
std::size_t &n,
62+
bool forwards);
63+
64+
/// Get either callers or callees reachable from a given
65+
/// list of functions within N steps
66+
/// \param graph: call graph
67+
/// \param start_function: single start function
68+
/// \param forwards: if true, get callees; otherwise get callers
69+
/// \param n: number of steps to consider
70+
std::set<irep_idt> get_functions_reachable_within_n_steps(
71+
const call_grapht::directed_grapht &graph,
72+
const irep_idt &start_function,
73+
std::size_t &n,
74+
bool forwards);
75+
5276
#endif

0 commit comments

Comments
 (0)