cprover
call_graph.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Function Call Graphs
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "call_graph.h"
13 
14 #include <util/std_expr.h>
15 #include <util/xml.h>
16 
18 {
19 }
20 
22 {
23  forall_goto_functions(f_it, goto_functions)
24  {
25  const goto_programt &body=f_it->second.body;
26  add(f_it->first, body);
27  }
28 }
29 
31  const irep_idt &function,
32  const goto_programt &body)
33 {
35  {
36  if(i_it->is_function_call())
37  {
38  const exprt &function_expr=to_code_function_call(i_it->code).function();
39  if(function_expr.id()==ID_symbol)
40  add(function, to_symbol_expr(function_expr).get_identifier());
41  }
42  }
43 }
44 
46  const irep_idt &caller,
47  const irep_idt &callee)
48 {
49  graph.insert(std::pair<irep_idt, irep_idt>(caller, callee));
50 }
51 
52 void call_grapht::output_dot(std::ostream &out) const
53 {
54  out << "digraph call_graph {\n";
55 
56  for(const auto &edge : graph)
57  {
58  out << " \"" << edge.first << "\" -> "
59  << "\"" << edge.second << "\" "
60  << " [arrowhead=\"vee\"];"
61  << "\n";
62  }
63 
64  out << "}\n";
65 }
66 
67 void call_grapht::output(std::ostream &out) const
68 {
69  for(const auto &edge : graph)
70  {
71  out << edge.first << " -> " << edge.second << "\n";
72  }
73 }
74 
75 void call_grapht::output_xml(std::ostream &out) const
76 {
77  for(const auto &edge : graph)
78  {
79  out << "<call_graph_edge caller=\"";
80  xmlt::escape_attribute(id2string(edge.first), out);
81  out << "\" callee=\"";
82  xmlt::escape_attribute(id2string(edge.second), out);
83  out << "\">\n";
84  }
85 }
void add(const irep_idt &caller, const irep_idt &callee)
Definition: call_graph.cpp:45
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
const irep_idt & get_identifier() const
Definition: std_expr.h:120
Function Call Graphs.
const irep_idt & id() const
Definition: irep.h:189
void output_xml(std::ostream &out) const
Definition: call_graph.cpp:75
API to expression classes.
void output_dot(std::ostream &out) const
Definition: call_graph.cpp:52
void output(std::ostream &out) const
Definition: call_graph.cpp:67
A specialization of goto_program_templatet over goto programs in which instructions have codet type...
Definition: goto_program.h:24
exprt & function()
Definition: std_code.h:677
Base class for all expressions.
Definition: expr.h:46
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast a generic exprt to a symbol_exprt.
Definition: std_expr.h:202
#define forall_goto_functions(it, functions)
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 ...
Definition: xml.cpp:115
#define forall_goto_program_instructions(it, program)
Definition: goto_program.h:68
grapht graph
Definition: call_graph.h:31
const code_function_callt & to_code_function_call(const codet &code)
Definition: std_code.h:700