Skip to content

Commit 2c76d0d

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 64fdb9b commit 2c76d0d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/analyses/call_graph_helpers.cpp

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

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 n: number of steps to consider
57+
/// \return set of functions that can be reached from the start function
58+
/// including the start function
59+
std::set<irep_idt> get_functions_reachable_within_n_steps(
60+
const call_grapht::directed_grapht &graph,
61+
const std::set<irep_idt> &start_functions,
62+
std::size_t &n);
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 n: number of steps to consider
69+
/// \return set of functions that can be reached from the start function
70+
/// including the start function
71+
std::set<irep_idt> get_functions_reachable_within_n_steps(
72+
const call_grapht::directed_grapht &graph,
73+
const irep_idt &start_function,
74+
std::size_t &n);
75+
5276
#endif

0 commit comments

Comments
 (0)