Go to the documentation of this file.
22 collect_callsites(collect_callsites)
31 call_grapht(goto_model.goto_functions, collect_callsites)
41 collect_callsites(collect_callsites)
45 const irep_idt &function_name = gf_entry.first;
47 nodes.insert(function_name);
48 add(function_name, body);
58 if(i_it->is_function_call())
60 const exprt &function_expr = i_it->call_function();
62 function_expr.
id() == ID_symbol,
63 "call graph computation requires function pointer removal");
65 call_task(i_it, callee);
78 bool collect_callsites):
79 collect_callsites(collect_callsites)
81 std::stack<irep_idt, std::vector<irep_idt>> pending_stack;
82 pending_stack.push(root);
84 while(!pending_stack.empty())
86 irep_idt function=pending_stack.top();
89 nodes.insert(
function);
92 const auto &it = goto_functions.
function_map.find(
function);
102 add(
function, callee, i_it);
104 pending_stack.push(callee);
118 bool collect_callsites):
119 call_grapht(goto_model.goto_functions, root, collect_callsites)
131 add(
function, callee, i_it);
143 edges.insert({caller, callee});
144 nodes.insert(caller);
145 nodes.insert(callee);
160 callsites[{caller, callee}].insert(callsite);
169 for(
const auto &caller_callee :
edges)
170 result.
add(caller_callee.second, caller_callee.first);
195 findit.first->second=new_index;
196 graph[new_index].function=
function;
198 return findit.first->second;
217 function_indices[function_name];
219 for(
const auto &edge :
edges)
221 auto a_index=function_indices[edge.first];
222 auto b_index=function_indices[edge.second];
257 out <<
"digraph call_graph {\n";
259 for(
const auto &edge :
edges)
261 out <<
" \"" << edge.first <<
"\" -> "
262 <<
"\"" << edge.second <<
"\" "
263 <<
" [arrowhead=\"vee\"";
274 for(
const auto &edge :
edges)
276 out << edge.first <<
" -> " << edge.second <<
"\n";
287 out <<
"<!-- XML call-graph representation does not document callsites yet."
288 " If you need this, edit call_grapht::output_xml -->\n";
289 for(
const auto &edge :
edges)
291 out <<
"<call_graph_edge caller=\"";
293 out <<
"\" callee=\"";
306 return findit->second;
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
static void forall_callsites(const goto_programt &body, std::function< void(goto_programt::const_targett, const irep_idt &)> call_task)
call_grapht get_inverted() const
Returns an inverted copy of this call graph.
Helper class that maintains a map from function name to grapht node index and adds nodes to the graph...
optionalt< node_indext > get_node_index(const irep_idt &function) const
Find the graph node by function name.
bool has_edge(node_indext i, node_indext j) const
call_grapht(bool collect_callsites=false)
Create empty call graph.
call_grapht::directed_grapht & graph
node_indext add_node(arguments &&... values)
std::unordered_map< irep_idt, node_indext > function_indices
Base class for all expressions.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
function_mapt function_map
void output_xml(std::ostream &out) const
void output_dot(std::ostream &out) const
nodet::node_indext node_indext
const std::string & id2string(const irep_idt &d)
#define PRECONDITION(CONDITION)
const irep_idt & get_identifier() const
Directed graph representation of this call graph.
function_indicest(call_grapht::directed_grapht &graph)
static void escape_attribute(const std::string &s, std::ostream &out)
escaping for XML attributes, assuming that double quotes " are used consistently, not single quotes
std::unordered_map< irep_idt, node_indext > nodes_by_name
Maps function names onto node indices.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
directed_grapht get_directed_graph() const
Returns a grapht representation of this call graph, suitable for use with generic grapht algorithms.
void add_edge(node_indext a, node_indext b)
nonstd::optional< T > optionalt
std::string format_callsites(const edget &edge) const
Prints callsites responsible for a graph edge as comma-separated location numbers,...
const edgest & out(node_indext n) const
A collection of goto functions.
A call graph (https://en.wikipedia.org/wiki/Call_graph) for a GOTO model or GOTO functions collection...
std::pair< irep_idt, irep_idt > edget
Type of a call graph edge in edgest
callsitest callsites
Map from call-graph edges to a set of callsites that make the given call.
node_indext operator[](const irep_idt &function)
#define PRECONDITION_WITH_DIAGNOSTICS(CONDITION,...)
void output(std::ostream &out) const
A generic container class for the GOTO intermediate representation of one function.
call_grapht::directed_grapht::node_indext node_indext
instructionst::const_iterator const_targett
void add(const irep_idt &caller, const irep_idt &callee)
Add edge.
goto_programt::const_targett locationt
Type of a callsite stored in member callsites
edgest edges
Call graph, including duplicate key-value pairs when there are parallel edges (see grapht documentati...
#define forall_goto_program_instructions(it, program)