ROSE  0.11.59.0
FunctionCallGraph.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_FunctionCallGraph_H
2 #define ROSE_BinaryAnalysis_Partitioner2_FunctionCallGraph_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
7 #include <Sawyer/Graph.h>
8 #include <Sawyer/Map.h>
9 
10 namespace Rose {
11 namespace BinaryAnalysis {
12 namespace Partitioner2 {
13 
22 public:
24  class Edge {
25  friend class FunctionCallGraph;
26  EdgeType type_;
27  size_t count_;
28  public:
29  explicit Edge(EdgeType type): type_(type), count_(1) {}
30 
32  EdgeType type() const { return type_; }
33 
35  size_t count() const { return count_; }
36  };
37 
38  class VertexKey {
39  public:
40  rose_addr_t address;
41  VertexKey();
42  explicit VertexKey(rose_addr_t);
43  explicit VertexKey(const FunctionPtr&);
44  bool operator<(VertexKey) const;
45  };
46 
49 
50 private:
51  Graph graph_;
52 
53 public:
58  const Graph& graph() const { return graph_; }
59 
62 
64 
66  boost::iterator_range<Graph::ConstVertexValueIterator> functions() {
67  return graph_.vertexValues();
68  }
69 
76  Graph::ConstVertexIterator findFunction(const FunctionPtr &function) const;
77  Graph::ConstVertexIterator findFunction(rose_addr_t entryVa) const;
86  bool exists(const FunctionPtr &function) const;
87  bool exists(rose_addr_t entryVa) const;
94  Graph::VertexIterator insertFunction(const FunctionPtr &function);
95 
108  Graph::EdgeIterator insertCall(const FunctionPtr &source, const FunctionPtr &target,
109  EdgeType type = E_FUNCTION_CALL, size_t edgeCount = 0);
110  Graph::EdgeIterator insertCall(const Graph::VertexIterator &source, const Graph::VertexIterator &target,
111  EdgeType type = E_FUNCTION_CALL, size_t edgeCount = 0);
119  std::vector<FunctionPtr> callers(const FunctionPtr &target) const;
120  std::vector<FunctionPtr> callers(const Graph::ConstVertexIterator &target) const;
128  size_t nCallers(const FunctionPtr &target) const;
129  size_t nCallers(const Graph::ConstVertexIterator &target) const;
138  std::vector<FunctionPtr> callees(const FunctionPtr &source) const;
139  std::vector<FunctionPtr> callees(const Graph::ConstVertexIterator &source) const;
147  size_t nCallees(const FunctionPtr &source) const;
148  size_t nCallees(const Graph::ConstVertexIterator &source) const;
157  size_t nCallsIn(const FunctionPtr &target) const;
158  size_t nCallsIn(const Graph::ConstVertexIterator &target) const;
167  size_t nCallsOut(const FunctionPtr &source) const;
168  size_t nCallsOut(const Graph::ConstVertexIterator &source) const;
176  size_t nCalls(const FunctionPtr &source, const FunctionPtr &target) const;
177  size_t nCalls(const Graph::ConstVertexIterator &source, const Graph::ConstVertexIterator &target) const;
179 };
180 
181 } // namespace
182 } // namespace
183 } // namespace
184 
185 #endif
186 #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.
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.