Skip to content

Commit 8ed3ccb

Browse files
committed
Add documentation to call graph
No functional changes
1 parent 8f6f429 commit 8ed3ccb

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/analyses/call_graph.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,27 @@ Author: Daniel Kroening, [email protected]
1414
#include <util/std_expr.h>
1515
#include <util/xml.h>
1616

17+
/// Create empty call graph
18+
/// \param collect_callsites: if true, then each added graph edge will have
19+
/// the calling instruction recorded in `callsites` map.
1720
call_grapht::call_grapht(bool collect_callsites):
1821
collect_callsites(collect_callsites)
1922
{
2023
}
2124

25+
/// Create complete call graph
26+
/// \param goto_model: model to search for callsites
27+
/// \param collect_callsites: if true, then each added graph edge will have
28+
/// the calling instruction recorded in `callsites` map.
2229
call_grapht::call_grapht(const goto_modelt &goto_model, bool collect_callsites):
2330
call_grapht(goto_model.goto_functions, collect_callsites)
2431
{
2532
}
2633

34+
/// Create complete call graph
35+
/// \param goto_functions: functions to search for callsites
36+
/// \param collect_callsites: if true, then each added graph edge will have
37+
/// the calling instruction recorded in `callsites` map.
2738
call_grapht::call_grapht(
2839
const goto_functionst &goto_functions, bool collect_callsites):
2940
collect_callsites(collect_callsites)
@@ -54,7 +65,7 @@ static void forall_callsites(
5465
}
5566

5667
/// Create call graph restricted to functions reachable from `root`
57-
/// \param functions: functions to search for callsites
68+
/// \param goto_functions: functions to search for callsites
5869
/// \param root: function to start exploring the graph
5970
/// \param collect_callsites: if true, then each added graph edge will have
6071
/// the calling instruction recorded in `callsites` map.
@@ -204,6 +215,10 @@ call_grapht::directed_grapht call_grapht::get_directed_graph() const
204215
return ret;
205216
}
206217

218+
/// Prints callsites responsible for a graph edge as comma-separated
219+
/// location numbers, e.g. "{1, 2, 3}".
220+
/// \param edge: graph edge
221+
/// \return pretty representation of edge callsites
207222
std::string call_grapht::format_callsites(const edget &edge) const
208223
{
209224
PRECONDITION(collect_callsites);

src/analyses/call_graph.h

+25-1
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,50 @@ class call_grapht
4040
void output(std::ostream &out) const;
4141
void output_xml(std::ostream &out) const;
4242

43+
/// Type of the call graph. Note parallel edges (e.g. A having two callsites
44+
/// both targeting B) result in multiple graph edges.
4345
typedef std::multimap<irep_idt, irep_idt> grapht;
46+
47+
/// Type of a call graph edge in `grapht`
4448
typedef std::pair<irep_idt, irep_idt> edget;
49+
50+
/// Type of a callsite stored in member `callsites`
4551
typedef goto_programt::const_targett locationt;
52+
53+
/// Type of a set of callsites
4654
typedef std::set<locationt> locationst;
55+
56+
/// Type mapping from call-graph edges onto the set of call instructions
57+
/// that make that call.
4758
typedef std::map<edget, locationst> callsitest;
4859

60+
/// Call graph, including duplicate key-value pairs when there are parallel
61+
/// edges (see `grapht` documentation). This representation is retained for
62+
/// backward compatibility; use `get_directed_graph()` to get a generic
63+
/// directed graph representation that provides more graph algorithms
64+
/// (shortest path, SCCs and so on).
4965
grapht graph;
66+
67+
/// Map from call-graph edges to a set of callsites that make the given call.
5068
callsitest callsites;
5169

5270
void add(const irep_idt &caller, const irep_idt &callee);
5371
void add(const irep_idt &caller, const irep_idt &callee, locationt callsite);
72+
5473
call_grapht get_inverted() const;
5574

75+
/// Edge of the directed graph representation of this call graph
5676
struct edge_with_callsitest
5777
{
78+
/// Callsites responsible for this graph edge. Will be empty if
79+
/// `collect_callsites` was not set at `call_grapht` construction time.
5880
locationst callsites;
5981
};
6082

61-
struct function_nodet:public graph_nodet<edge_with_callsitest>
83+
/// Node of the directed graph representation of this call graph
84+
struct function_nodet : public graph_nodet<edge_with_callsitest>
6285
{
86+
/// Function name
6387
irep_idt function;
6488
};
6589

0 commit comments

Comments
 (0)