cprover
call_grapht Class Reference

#include <call_graph.h>

Collaboration diagram for call_grapht:
[legend]

Classes

class  directed_grapht
 Directed graph representation of this call graph. More...
 
struct  edge_with_callsitest
 Edge of the directed graph representation of this call graph. More...
 
struct  function_nodet
 Node of the directed graph representation of this call graph. More...
 

Public Types

typedef std::unordered_set< irep_idt, irep_id_hashnodest
 Type of the nodes in the call graph. More...
 
typedef std::multimap< irep_idt, irep_idtedgest
 Type of the edges in the call graph. More...
 
typedef std::pair< irep_idt, irep_idtedget
 Type of a call graph edge in edgest More...
 
typedef goto_programt::const_targett locationt
 Type of a callsite stored in member callsites More...
 
typedef std::set< locationtlocationst
 Type of a set of callsites. More...
 
typedef std::map< edget, locationstcallsitest
 Type mapping from call-graph edges onto the set of call instructions that make that call. More...
 

Public Member Functions

 call_grapht (bool collect_callsites=false)
 Create empty call graph. More...
 
 call_grapht (const goto_modelt &, bool collect_callsites=false)
 Create complete call graph. More...
 
 call_grapht (const goto_functionst &, bool collect_callsites=false)
 Create complete call graph. More...
 
void output_dot (std::ostream &out) const
 
void output (std::ostream &out) const
 
void output_xml (std::ostream &out) const
 
void add (const irep_idt &caller, const irep_idt &callee)
 Add edge. More...
 
void add (const irep_idt &caller, const irep_idt &callee, locationt callsite)
 Add edge with optional callsite information. More...
 
call_grapht get_inverted () const
 Returns an inverted copy of this call graph. More...
 
directed_grapht get_directed_graph () const
 Returns a grapht representation of this call graph, suitable for use with generic grapht algorithms. More...
 

Static Public Member Functions

static call_grapht create_from_root_function (const goto_modelt &model, const irep_idt &root, bool collect_callsites)
 
static call_grapht create_from_root_function (const goto_functionst &functions, const irep_idt &root, bool collect_callsites)
 

Public Attributes

edgest edges
 Call graph, including duplicate key-value pairs when there are parallel edges (see grapht documentation). More...
 
nodest nodes
 
callsitest callsites
 Map from call-graph edges to a set of callsites that make the given call. More...
 

Protected Member Functions

void add (const irep_idt &function, const goto_programt &body)
 

Private Member Functions

 call_grapht (const goto_modelt &model, const irep_idt &root, bool collect_callsites)
 Create call graph restricted to functions reachable from root More...
 
 call_grapht (const goto_functionst &functions, const irep_idt &root, bool collect_callsites)
 Create call graph restricted to functions reachable from root More...
 
std::string format_callsites (const edget &edge) const
 Prints callsites responsible for a graph edge as comma-separated location numbers, e.g. More...
 

Private Attributes

bool collect_callsites
 

Detailed Description

Definition at line 21 of file call_graph.h.

Member Typedef Documentation

◆ callsitest

Type mapping from call-graph edges onto the set of call instructions that make that call.

Definition at line 83 of file call_graph.h.

◆ edgest

typedef std::multimap<irep_idt, irep_idt> call_grapht::edgest

Type of the edges in the call graph.

Note parallel edges (e.g. A having two callsites both targeting B) result in multiple graph edges.

Definition at line 70 of file call_graph.h.

◆ edget

typedef std::pair<irep_idt, irep_idt> call_grapht::edget

Type of a call graph edge in edgest

Definition at line 73 of file call_graph.h.

◆ locationst

Type of a set of callsites.

Definition at line 79 of file call_graph.h.

◆ locationt

Type of a callsite stored in member callsites

Definition at line 76 of file call_graph.h.

◆ nodest

typedef std::unordered_set<irep_idt, irep_id_hash> call_grapht::nodest

Type of the nodes in the call graph.

Definition at line 66 of file call_graph.h.

Constructor & Destructor Documentation

◆ call_grapht() [1/5]

call_grapht::call_grapht ( bool  collect_callsites = false)
explicit

Create empty call graph.

Parameters
collect_callsitesif true, then each added graph edge will have the calling instruction recorded in callsites map.

Definition at line 20 of file call_graph.cpp.

Referenced by create_from_root_function().

◆ call_grapht() [2/5]

call_grapht::call_grapht ( const goto_modelt goto_model,
bool  collect_callsites = false 
)
explicit

Create complete call graph.

Parameters
goto_modelmodel to search for callsites
collect_callsitesif true, then each added graph edge will have the calling instruction recorded in callsites map.

Definition at line 29 of file call_graph.cpp.

◆ call_grapht() [3/5]

call_grapht::call_grapht ( const goto_functionst goto_functions,
bool  collect_callsites = false 
)
explicit

Create complete call graph.

Parameters
goto_functionsfunctions to search for callsites
collect_callsitesif true, then each added graph edge will have the calling instruction recorded in callsites map.

Definition at line 38 of file call_graph.cpp.

References add(), forall_goto_functions, and nodes.

◆ call_grapht() [4/5]

call_grapht::call_grapht ( const goto_modelt goto_model,
const irep_idt root,
bool  collect_callsites 
)
private

Create call graph restricted to functions reachable from root

Parameters
goto_modelmodel to search for callsites
rootfunction to start exploring the graph
collect_callsitesif true, then each added graph edge will have the calling instruction recorded in callsites map.

Definition at line 109 of file call_graph.cpp.

◆ call_grapht() [5/5]

call_grapht::call_grapht ( const goto_functionst goto_functions,
const irep_idt root,
bool  collect_callsites 
)
private

Create call graph restricted to functions reachable from root

Parameters
goto_functionsfunctions to search for callsites
rootfunction to start exploring the graph
collect_callsitesif true, then each added graph edge will have the calling instruction recorded in callsites map.

Definition at line 74 of file call_graph.cpp.

References add(), edges, forall_callsites(), goto_functionst::function_map, goto_program, and nodes.

Member Function Documentation

◆ add() [1/3]

void call_grapht::add ( const irep_idt caller,
const irep_idt callee 
)

Add edge.

Parameters
callercaller function
calleecallee function

Definition at line 133 of file call_graph.cpp.

References edges, and nodes.

Referenced by add(), call_grapht(), and get_inverted().

◆ add() [2/3]

void call_grapht::add ( const irep_idt caller,
const irep_idt callee,
locationt  callsite 
)

Add edge with optional callsite information.

Parameters
callercaller function
calleecallee function
callsitecall instruction responsible for this edge. Note this is only stored if collect_callsites was specified during construction.

Definition at line 147 of file call_graph.cpp.

References add(), callsites, and collect_callsites.

◆ add() [3/3]

void call_grapht::add ( const irep_idt function,
const goto_programt body 
)
protected

Definition at line 117 of file call_graph.cpp.

References add(), and forall_callsites().

◆ create_from_root_function() [1/2]

static call_grapht call_grapht::create_from_root_function ( const goto_modelt model,
const irep_idt root,
bool  collect_callsites 
)
inlinestatic

Definition at line 31 of file call_graph.h.

References call_grapht(), and collect_callsites.

Referenced by goto_instrument_parse_optionst::doit(), and slice_global_inits().

◆ create_from_root_function() [2/2]

static call_grapht call_grapht::create_from_root_function ( const goto_functionst functions,
const irep_idt root,
bool  collect_callsites 
)
inlinestatic

Definition at line 39 of file call_graph.h.

References call_grapht(), and collect_callsites.

◆ format_callsites()

std::string call_grapht::format_callsites ( const edget edge) const
private

Prints callsites responsible for a graph edge as comma-separated location numbers, e.g.

"{1, 2, 3}".

Parameters
edgegraph edge
Returns
pretty representation of edge callsites

Definition at line 235 of file call_graph.cpp.

References callsites, collect_callsites, loc, PRECONDITION, and to_string().

Referenced by output(), and output_dot().

◆ get_directed_graph()

call_grapht::directed_grapht call_grapht::get_directed_graph ( ) const

Returns a grapht representation of this call graph, suitable for use with generic grapht algorithms.

Note that parallel edges in call_grapht (e.g. A { B(); B(); } appearing as two A->B edges) will be condensed in the grapht output, so only one edge will appear. If collect_callsites was set when this call-graph was constructed the edge will be annotated with the call-site set.

Returns
grapht representation of this call_grapht

Definition at line 203 of file call_graph.cpp.

References grapht< N >::add_edge(), callsites, collect_callsites, edges, function_indicest::function_indices, grapht< N >::has_edge(), nodes, call_grapht::directed_grapht::nodes_by_name, and grapht< N >::out().

Referenced by slice_global_inits().

◆ get_inverted()

call_grapht call_grapht::get_inverted ( ) const

Returns an inverted copy of this call graph.

Returns
Inverted (callee -> caller) call graph

Definition at line 159 of file call_graph.cpp.

References add(), edges, and nodes.

◆ output()

void call_grapht::output ( std::ostream &  out) const

Definition at line 266 of file call_graph.cpp.

References collect_callsites, edges, and format_callsites().

Referenced by goto_instrument_parse_optionst::doit().

◆ output_dot()

void call_grapht::output_dot ( std::ostream &  out) const

Definition at line 249 of file call_graph.cpp.

References collect_callsites, edges, and format_callsites().

Referenced by goto_instrument_parse_optionst::doit().

◆ output_xml()

void call_grapht::output_xml ( std::ostream &  out) const

Member Data Documentation

◆ callsites

callsitest call_grapht::callsites

Map from call-graph edges to a set of callsites that make the given call.

Definition at line 94 of file call_graph.h.

Referenced by add(), format_callsites(), and get_directed_graph().

◆ collect_callsites

bool call_grapht::collect_callsites
private

◆ edges

edgest call_grapht::edges

Call graph, including duplicate key-value pairs when there are parallel edges (see grapht documentation).

This representation is retained for backward compatibility; use get_directed_graph() to get a generic directed graph representation that provides more graph algorithms (shortest path, SCCs and so on).

Definition at line 90 of file call_graph.h.

Referenced by add(), call_grapht(), get_directed_graph(), get_inverted(), output(), output_dot(), and output_xml().

◆ nodes

nodest call_grapht::nodes

Definition at line 91 of file call_graph.h.

Referenced by add(), call_grapht(), get_directed_graph(), and get_inverted().


The documentation for this class was generated from the following files: