ROSE  0.9.9.139
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 
7 namespace Rose {
8 namespace BinaryAnalysis {
9 namespace Partitioner2 {
10 
19 public:
21  class Edge {
22  friend class FunctionCallGraph;
23  EdgeType type_;
24  size_t count_;
25  public:
26  explicit Edge(EdgeType type): type_(type), count_(1) {}
27 
29  EdgeType type() const { return type_; }
30 
32  size_t count() const { return count_; }
33  };
34 
37 
40 
41 private:
42  Graph graph_;
43  Index index_;
44 
45 public:
50  const Graph& graph() const { return graph_; }
51 
56  const Index& index() const { return index_; }
57 
60 
63 
66 
68 
70  boost::iterator_range<Graph::ConstVertexValueIterator> functions() {
71  return graph_.vertexValues();
72  }
73 
80  Graph::ConstVertexIterator findFunction(const FunctionPtr &function) const;
81  Graph::ConstVertexIterator findFunction(rose_addr_t entryVa) const;
90  bool exists(const FunctionPtr &function) const;
91  bool exists(rose_addr_t entryVa) const;
98  Graph::VertexIterator insertFunction(const FunctionPtr &function);
99 
112  Graph::EdgeIterator insertCall(const FunctionPtr &source, const FunctionPtr &target,
113  EdgeType type = E_FUNCTION_CALL, size_t edgeCount = 0);
114  Graph::EdgeIterator insertCall(const Graph::VertexIterator &source, const Graph::VertexIterator &target,
115  EdgeType type = E_FUNCTION_CALL, size_t edgeCount = 0);
123  std::vector<FunctionPtr> callers(const FunctionPtr &target) const;
124  std::vector<FunctionPtr> callers(const Graph::ConstVertexIterator &target) const;
132  size_t nCallers(const FunctionPtr &target) const;
133  size_t nCallers(const Graph::ConstVertexIterator &target) const;
142  std::vector<FunctionPtr> callees(const FunctionPtr &source) const;
143  std::vector<FunctionPtr> callees(const Graph::ConstVertexIterator &source) const;
151  size_t nCallees(const FunctionPtr &source) const;
152  size_t nCallees(const Graph::ConstVertexIterator &source) const;
161  size_t nCallsIn(const FunctionPtr &target) const;
162  size_t nCallsIn(const Graph::ConstVertexIterator &target) const;
171  size_t nCallsOut(const FunctionPtr &source) const;
172  size_t nCallsOut(const Graph::ConstVertexIterator &source) const;
180  size_t nCalls(const FunctionPtr &source, const FunctionPtr &target) const;
181  size_t nCalls(const Graph::ConstVertexIterator &source, const Graph::ConstVertexIterator &target) const;
183 };
184 
185 } // namespace
186 } // namespace
187 } // namespace
188 #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:30
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:1481
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.