ROSE  0.9.10.200
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 
36  class VertexKey {
37  public:
38  rose_addr_t address;
39  VertexKey();
40  explicit VertexKey(rose_addr_t);
41  explicit VertexKey(const FunctionPtr&);
42  bool operator<(VertexKey) const;
43  };
44 
47 
48 private:
49  Graph graph_;
50 
51 public:
56  const Graph& graph() const { return graph_; }
57 
60 
62 
64  boost::iterator_range<Graph::ConstVertexValueIterator> functions() {
65  return graph_.vertexValues();
66  }
67 
74  Graph::ConstVertexIterator findFunction(const FunctionPtr &function) const;
75  Graph::ConstVertexIterator findFunction(rose_addr_t entryVa) const;
84  bool exists(const FunctionPtr &function) const;
85  bool exists(rose_addr_t entryVa) const;
92  Graph::VertexIterator insertFunction(const FunctionPtr &function);
93 
106  Graph::EdgeIterator insertCall(const FunctionPtr &source, const FunctionPtr &target,
107  EdgeType type = E_FUNCTION_CALL, size_t edgeCount = 0);
108  Graph::EdgeIterator insertCall(const Graph::VertexIterator &source, const Graph::VertexIterator &target,
109  EdgeType type = E_FUNCTION_CALL, size_t edgeCount = 0);
117  std::vector<FunctionPtr> callers(const FunctionPtr &target) const;
118  std::vector<FunctionPtr> callers(const Graph::ConstVertexIterator &target) const;
126  size_t nCallers(const FunctionPtr &target) const;
127  size_t nCallers(const Graph::ConstVertexIterator &target) const;
136  std::vector<FunctionPtr> callees(const FunctionPtr &source) const;
137  std::vector<FunctionPtr> callees(const Graph::ConstVertexIterator &source) const;
145  size_t nCallees(const FunctionPtr &source) const;
146  size_t nCallees(const Graph::ConstVertexIterator &source) const;
155  size_t nCallsIn(const FunctionPtr &target) const;
156  size_t nCallsIn(const Graph::ConstVertexIterator &target) const;
165  size_t nCallsOut(const FunctionPtr &source) const;
166  size_t nCallsOut(const Graph::ConstVertexIterator &source) const;
174  size_t nCalls(const FunctionPtr &source, const FunctionPtr &target) const;
175  size_t nCalls(const Graph::ConstVertexIterator &source, const Graph::ConstVertexIterator &target) const;
177 };
178 
179 } // namespace
180 } // namespace
181 } // namespace
182 #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:50
Graph::ConstVertexIterator findFunction(const FunctionPtr &function) const
Find function in call graph.
Main namespace for the ROSE library.
Reference-counting smart pointer.
Definition: SharedPointer.h:67
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:1489
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.