Skip to content

Commit 635071e

Browse files
committed
Documentation of call graph and reachable call graph
1 parent 799d034 commit 635071e

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

src/analyses/call_graph.h

+24-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ Author: Daniel Kroening, [email protected]
2323
#include <util/numbering.h>
2424

2525

26-
/// Function call graph inherits from grapht to allow forward and
26+
/// \brief Function call graph: each node represents a function
27+
/// in the GOTO model, a directed edge from A to B indicates
28+
/// that function A calls function B.
29+
/// Inherits from grapht to allow forward and
2730
/// backward traversal of the function call graph
28-
2931
struct call_graph_nodet: public graph_nodet<empty_edget>
3032
{
3133
typedef graph_nodet<empty_edget>::edget edget;
@@ -43,11 +45,28 @@ class call_grapht: public grapht<call_graph_nodet>
4345

4446
void add(const irep_idt &caller, const irep_idt &callee);
4547
void output_xml(std::ostream &out) const;
48+
49+
/// \return the inverted call graph
4650
call_grapht get_inverted() const;
51+
52+
/// \brief get the names of all functions reachable from a start function
53+
/// \param start name of initial function
54+
/// \return set of all names of the reachable functions
4755
std::unordered_set<irep_idt, irep_id_hash>
4856
reachable_functions(irep_idt start);
57+
58+
/// \brief Function returns the shortest path on the function call graph
59+
/// between a source and a destination function
60+
/// \param src name of the starting function
61+
/// \param dest name of the destination function
62+
/// \return list of function names on the shortest path between src and dest
4963
std::list<irep_idt>shortest_function_path(irep_idt src, irep_idt dest);
5064

65+
/// get the index of the node that corresponds to a function name
66+
/// \param[in] function_name function_name passed by reference
67+
/// \param[out] n variable for the node index to be written to
68+
/// \return true if a node with the given function name exists,
69+
/// false if it does not exist
5170
bool get_node_index(const irep_idt& function_name, node_indext &n) const
5271
{
5372
for(node_indext idx = 0; idx < nodes.size(); idx++)
@@ -61,6 +80,9 @@ class call_grapht: public grapht<call_graph_nodet>
6180
return false;
6281
}
6382

83+
/// \brief get a list of functions called by a function
84+
/// \param function_name the irep_idt of the function
85+
/// \return an unordered set of all functions called by function_name
6486
std::unordered_set<irep_idt, irep_id_hash> get_successors(
6587
const irep_idt& function_name) const
6688
{

src/analyses/reachable_call_graph.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ Module: Reachable Call Graphs
88

99
/// \file
1010
/// Reachable Call Graph
11-
/// Constructs a call graph only from the functions reachable from a given
12-
/// entry point, or the goto_functions.entry_point if none is given.
13-
1411
#include "reachable_call_graph.h"
1512
#include <util/message.h>
1613

17-
1814
reachable_call_grapht::reachable_call_grapht
1915
(const goto_modelt & _goto_model)
2016
{
@@ -71,7 +67,6 @@ void reachable_call_grapht::build(
7167
}
7268
}
7369

74-
7570
std::unordered_set<irep_idt, irep_id_hash>
7671
reachable_call_grapht::backward_slice(irep_idt destination_function)
7772
{

src/analyses/reachable_call_graph.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Module: Reachable Call Graphs
88

99
/// \file
1010
/// Reachable Call Graphs
11+
/// Constructs a call graph only from the functions reachable from a given
12+
/// entry point, or the goto_functions.entry_point if none is given.
1113

1214
#ifndef CPROVER_ANALYSES_REACHABLE_CALL_GRAPH_H
1315
#define CPROVER_ANALYSES_REACHABLE_CALL_GRAPH_H
@@ -19,13 +21,11 @@ class reachable_call_grapht: public call_grapht
1921
public:
2022
explicit reachable_call_grapht(const goto_modelt &);
2123

22-
/// \brief Generates list of functions reachable from initial state and
23-
/// that may reach a given destination function
24-
///
25-
/// This is done by inverting the reachable call graph and performing bfs on
26-
/// the inverted call graph.
27-
/// \param destination function
28-
/// \return unorderded set of function names as irep_idts
24+
/// \brief performs a backwards slice on a reachable call graph
25+
/// and returns an unordered set of all functions between the initial
26+
/// function and the destination function, i.e., a cone of influence
27+
/// \param destination_function name of destination function
28+
/// \return unordered set of function names
2929
std::unordered_set<irep_idt, irep_id_hash>
3030
backward_slice(irep_idt destination_function);
3131
protected:

0 commit comments

Comments
 (0)