ROSE  0.9.10.75
FunctionCallGraph.h
1 #ifndef ROSE_Partitioner2_FunctionCallGraph_H
2 #define ROSE_Partitioner2_FunctionCallGraph_H
3 
4 #include <Partitioner2/BasicTypes.h>
5 #include <Sawyer/Graph.h>
6 #include <Sawyer/Map.h>
7 
8 namespace Rose {
9 namespace BinaryAnalysis {
10 namespace Partitioner2 {
11 
20 public:
22  class Edge {
23  friend class FunctionCallGraph;
24  EdgeType type_;
25  size_t count_;
26  public:
27  explicit Edge(EdgeType type): type_(type), count_(1) {}
28 
30  EdgeType type() const { return type_; }
31 
33  size_t count() const { return count_; }
34  };
35 
38 
41 
42 private:
43  Graph graph_;
44  Index index_;
45 
46 public:
51  const Graph& graph() const { return graph_; }
52 
57  const Index& index() const { return index_; }
58 
61 
64 
67 
69 
71  boost::iterator_range<Graph::ConstVertexValueIterator> functions() {
72  return graph_.vertexValues();
73  }
74 
81  Graph::ConstVertexIterator findFunction(const FunctionPtr &function) const;
82  Graph::ConstVertexIterator findFunction(rose_addr_t entryVa) const;
91  bool exists(const FunctionPtr &function) const;
92  bool exists(rose_addr_t entryVa) const;
99  Graph::VertexIterator insertFunction(const FunctionPtr &function);
100 
113  Graph::EdgeIterator insertCall(const FunctionPtr &source, const FunctionPtr &target,
114  EdgeType type = E_FUNCTION_CALL, size_t edgeCount = 0);
115  Graph::EdgeIterator insertCall(const Graph::VertexIterator &source, const Graph::VertexIterator &target,
116  EdgeType type = E_FUNCTION_CALL, size_t edgeCount = 0);
124  std::vector<FunctionPtr> callers(const FunctionPtr &target) const;
125  std::vector<FunctionPtr> callers(const Graph::ConstVertexIterator &target) const;
133  size_t nCallers(const FunctionPtr &target) const;
134  size_t nCallers(const Graph::ConstVertexIterator &target) const;
143  std::vector<FunctionPtr> callees(const FunctionPtr &source) const;
144  std::vector<FunctionPtr> callees(const Graph::ConstVertexIterator &source) const;
152  size_t nCallees(const FunctionPtr &source) const;
153  size_t nCallees(const Graph::ConstVertexIterator &source) const;
162  size_t nCallsIn(const FunctionPtr &target) const;
163  size_t nCallsIn(const Graph::ConstVertexIterator &target) const;
172  size_t nCallsOut(const FunctionPtr &source) const;
173  size_t nCallsOut(const Graph::ConstVertexIterator &source) const;
181  size_t nCalls(const FunctionPtr &source, const FunctionPtr &target) const;
182  size_t nCalls(const Graph::ConstVertexIterator &source, const Graph::ConstVertexIterator &target) const;
184 };
185 
186 } // namespace
187 } // namespace
188 } // namespace
189 #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:42
Sawyer::Container::Graph< FunctionPtr, Edge > Graph
Function call graph.
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:1475
Sawyer::Container::Map< rose_addr_t, Graph::VertexIterator > Index
Maps function address to function call graph vertex.
size_t nCalls(const FunctionPtr &source, const FunctionPtr &target) const
Number of calls between two specific functions.
FunctionCallGraph & operator=(const FunctionCallGraph &other)
Assignment operator.
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.
Graph::EdgeIterator insertCall(const FunctionPtr &source, const FunctionPtr &target, EdgeType type=E_FUNCTION_CALL, size_t edgeCount=0)
Insert a call edge.
const Index & index() const
Function-to-vertex index.