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=\"";
299 std::optional<std::size_t>
304 return std::optional<node_indext>();
306 return findit->second;
static void forall_callsites(const goto_programt &body, std::function< void(goto_programt::const_targett, const irep_idt &)> call_task)
Directed graph representation of this call graph.
std::optional< node_indext > get_node_index(const irep_idt &function) const
Find the graph node by function name.
std::unordered_map< irep_idt, node_indext > nodes_by_name
Maps function names onto node indices.
A call graph (https://en.wikipedia.org/wiki/Call_graph) for a GOTO model or GOTO functions collection...
void add(const irep_idt &caller, const irep_idt &callee)
Add edge.
std::pair< irep_idt, irep_idt > edget
Type of a call graph edge in edgest
edgest edges
Call graph, including duplicate key-value pairs when there are parallel edges (see grapht documentati...
call_grapht get_inverted() const
Returns an inverted copy of this call graph.
void output_dot(std::ostream &out) const
std::string format_callsites(const edget &edge) const
Prints callsites responsible for a graph edge as comma-separated location numbers,...
directed_grapht get_directed_graph() const
Returns a grapht representation of this call graph, suitable for use with generic grapht algorithms.
call_grapht(bool collect_callsites=false)
Create empty call graph.
void output(std::ostream &out) const
callsitest callsites
Map from call-graph edges to a set of callsites that make the given call.
void output_xml(std::ostream &out) const
goto_programt::const_targett locationt
Type of a callsite stored in member callsites
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
Helper class that maintains a map from function name to grapht node index and adds nodes to the graph...
std::unordered_map< irep_idt, node_indext > function_indices
call_grapht::directed_grapht::node_indext node_indext
call_grapht::directed_grapht & graph
node_indext operator[](const irep_idt &function)
function_indicest(call_grapht::directed_grapht &graph)
A collection of goto functions.
function_mapt function_map
A generic container class for the GOTO intermediate representation of one function.
instructionst::const_iterator const_targett
nodet::node_indext node_indext
bool has_edge(node_indext i, node_indext j) const
node_indext add_node(arguments &&... values)
void add_edge(node_indext a, node_indext b)
const edgest & out(node_indext n) const
const irep_idt & id() const
const irep_idt & get_identifier() const
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
#define forall_goto_program_instructions(it, program)
const std::string & id2string(const irep_idt &d)
#define PRECONDITION_WITH_DIAGNOSTICS(CONDITION,...)
#define PRECONDITION(CONDITION)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.