ROSE  0.10.13.0
FunctionCallGraph.h
1 #ifndef ROSE_Partitioner2_FunctionCallGraph_H
2 #define ROSE_Partitioner2_FunctionCallGraph_H
3 
4 #include <rosePublicConfig.h>
5 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
6 
7 #include <Partitioner2/BasicTypes.h>
8 #include <Sawyer/Graph.h>
9 #include <Sawyer/Map.h>
10 
11 namespace Rose {
12 namespace BinaryAnalysis {
13 namespace Partitioner2 {
14 
23 public:
25  class Edge {
26  friend class FunctionCallGraph;
27  EdgeType type_;
28  size_t count_;
29  public:
30  explicit Edge(EdgeType type): type_(type), count_(1) {}
31 
33  EdgeType type() const { return type_; }
34 
36  size_t count() const { return count_; }
37  };
38 
39  class VertexKey {
40  public:
41  rose_addr_t address;
42  VertexKey();
43  explicit VertexKey(rose_addr_t);
44  explicit VertexKey(const FunctionPtr&);
45  bool operator<(VertexKey) const;
46  };
47 
50 
51 private:
52  Graph graph_;
53 
54 public:
59  const Graph& graph() const { return graph_; }
60 
63 
65 
67  boost::iterator_range<Graph::ConstVertexValueIterator> functions() {
68  return graph_.vertexValues();
69  }
70 
77  Graph::ConstVertexIterator findFunction(const FunctionPtr &function) const;
78  Graph::ConstVertexIterator findFunction(rose_addr_t entryVa) const;
87  bool exists(const FunctionPtr &function) const;
88  bool exists(rose_addr_t entryVa) const;
95  Graph::VertexIterator insertFunction(const FunctionPtr &function);
96 
109  Graph::EdgeIterator insertCall(const FunctionPtr &source, const FunctionPtr &target,
110  EdgeType type = E_FUNCTION_CALL, size_t edgeCount = 0);
111  Graph::EdgeIterator insertCall(const Graph::VertexIterator &source, const Graph::VertexIterator &target,
112  EdgeType type = E_FUNCTION_CALL, size_t edgeCount = 0);
120  std::vector<FunctionPtr> callers(const FunctionPtr &target) const;
121  std::vector<FunctionPtr> callers(const Graph::ConstVertexIterator &target) const;
129  size_t nCallers(const FunctionPtr &target) const;
130  size_t nCallers(const Graph::ConstVertexIterator &target) const;
139  std::vector<FunctionPtr> callees(const FunctionPtr &source) const;
140  std::vector<FunctionPtr> callees(const Graph::ConstVertexIterator &source) const;
148  size_t nCallees(const FunctionPtr &source) const;
149  size_t nCallees(const Graph::ConstVertexIterator &source) const;
158  size_t nCallsIn(const FunctionPtr &target) const;
159  size_t nCallsIn(const Graph::ConstVertexIterator &target) const;
168  size_t nCallsOut(const FunctionPtr &source) const;
169  size_t nCallsOut(const Graph::ConstVertexIterator &source) const;
177  size_t nCalls(const FunctionPtr &source, const FunctionPtr &target) const;
178  size_t nCalls(const Graph::ConstVertexIterator &source, const Graph::ConstVertexIterator &target) const;
180 };
181 
182 } // namespace
183 } // namespace
184 } // namespace
185 
186 #endif
187 #endif
size_t nCallees(const FunctionPtr &source) const
Number of functions that the specified function calls.
std::vector< FunctionPtr > callees(const FunctionPtr &source) const
List of all functions called by the specified function.
Graph::VertexIterator insertFunction(const FunctionPtr &function)
Insert a function vertex.
std::vector< FunctionPtr > callers(const FunctionPtr &target) const
List of all functions that call the specified function.
EdgeType
Partitioner control flow edge types.
Definition: BasicTypes.h:55
Graph::ConstVertexIterator findFunction(const FunctionPtr &function) const
Find function in call graph.
Main namespace for the ROSE library.
boost::iterator_range< Graph::ConstVertexValueIterator > functions()
Return all functions in the call graph.
const Graph & graph() const
Underlying function call graph.
Information about each edge in the call graph.
size_t nCallers(const FunctionPtr &target) const
Number of functions that call the specified function.
size_t nCallsOut(const FunctionPtr &source) const
Total number of calls from a function.
boost::iterator_range< VertexValueIterator > vertexValues()
Iterators for all vertices.
Definition: Graph.h:1469
size_t nCalls(const FunctionPtr &source, const FunctionPtr &target) const
Number of calls between two specific functions.
bool exists(const FunctionPtr &function) const
Determine if a function exists in the call graph.
FunctionCallGraph()
Constructs an empty function call graph.
size_t nCallsIn(const FunctionPtr &target) const
Total number of calls to a function.
size_t count() const
Number of inter-function control flow edges represented by this edge.
Sawyer::Container::Graph< FunctionPtr, Edge, VertexKey > Graph
Function call graph.
Graph::EdgeIterator insertCall(const FunctionPtr &source, const FunctionPtr &target, EdgeType type=E_FUNCTION_CALL, size_t edgeCount=0)
Insert a call edge.