tipc
A TIP to LLVM compiler
CallGraph.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ASTVisitor.h"
4 #include "CallGraphBuilder.h"
5 #include "SymbolTable.h"
6 #include "treetypes/AST.h"
7 #include <map>
8 #include <set>
9 #include <vector>
10 
22 class CallGraph {
23 
24  std::vector<ASTFunction *> vertices;
25  std::vector<std::pair<ASTFunction *, ASTFunction *>> edges;
26  int total_edges;
27  int total_vertices;
28  std::map<ASTFunction *, std::set<ASTFunction *>> callGraph;
29  std::map<std::string, ASTFunction *> fromFunNameToASTFuns;
30  std::map<ASTFunAppExpr *, std::set<ASTFunction *>> mayCall;
31 
32 public:
33  CallGraph(std::map<ASTFunction *, std::set<ASTFunction *>> cGraph,
34  std::map<ASTFunAppExpr *, std::set<ASTFunction *>> mc,
35  std::vector<ASTFunction *> funs,
36  std::map<std::string, ASTFunction *> fmap)
37  : callGraph(cGraph), mayCall(mc), vertices(funs),
38  total_vertices(vertices.size()), fromFunNameToASTFuns(fmap) {}
39 
44  static std::shared_ptr<CallGraph> build(ASTProgram *, SymbolTable *st);
45 
48  int getTotalVertices();
49 
52  int getTotalEdges();
53 
56  std::vector<ASTFunction *> getVertices();
57 
60  std::vector<std::pair<ASTFunction *, ASTFunction *>> getEdges();
61 
65  std::set<ASTFunction *> getCalledFuns(ASTFunAppExpr *e);
66 
71  std::set<ASTFunction *> getCallees(ASTFunction *f);
72  std::set<ASTFunction *> getCallees(std::string caller);
73 
78  std::set<ASTFunction *> getCallers(ASTFunction *f);
79  std::set<std::string> getCallers(std::string callee);
80 
82  void print(std::ostream &os);
83 
88  bool existEdge(std::string caller, std::string callee);
89 
94  ASTFunction *getASTFun(std::string f_name);
95 };
Class for function call expressions.
Definition: ASTFunAppExpr.h:7
Class for defining the signature, local declarations, and a body of a function.
Definition: ASTFunction.h:11
Class for a program which is a name and a list of functions.
Definition: ASTProgram.h:11
Performs control flow analysis and records results for subsequent phases Generates call graph of a pr...
Definition: CallGraph.h:22
std::vector< ASTFunction * > getVertices()
Return the set of vertices for a given call graph.
Definition: CallGraph.cpp:23
std::vector< std::pair< ASTFunction *, ASTFunction * > > getEdges()
Return the set of edges for a given call graph.
Definition: CallGraph.cpp:25
static std::shared_ptr< CallGraph > build(ASTProgram *, SymbolTable *st)
Return the shared pointer of the call graph for a given program.
Definition: CallGraph.cpp:4
std::set< ASTFunction * > getCallees(ASTFunction *f)
Returns all the subroutines called by function f. this is an overloaded function.
Definition: CallGraph.cpp:39
void print(std::ostream &os)
Print call graph contents to output stream.
Definition: CallGraph.cpp:78
int getTotalVertices()
Return the total num of vertices for a given call graph.
Definition: CallGraph.cpp:12
std::set< ASTFunction * > getCalledFuns(ASTFunAppExpr *e)
Return the set of functions that may be called at an application expr.
Definition: CallGraph.cpp:35
CallGraph(std::map< ASTFunction *, std::set< ASTFunction * >> cGraph, std::map< ASTFunAppExpr *, std::set< ASTFunction * >> mc, std::vector< ASTFunction * > funs, std::map< std::string, ASTFunction * > fmap)
Definition: CallGraph.h:33
ASTFunction * getASTFun(std::string f_name)
Returns the ASTFunction* for a given function name .
Definition: CallGraph.cpp:104
bool existEdge(std::string caller, std::string callee)
Returns bool value indicating whether there is an edge between two subroutines.
Definition: CallGraph.cpp:95
int getTotalEdges()
Return the total num of edges for a given call graph.
Definition: CallGraph.cpp:14
std::set< ASTFunction * > getCallers(ASTFunction *f)
Returns all the subroutines that call function f.
Definition: CallGraph.cpp:68
Performs symbol analysis and records results for subsequent phases.
Definition: SymbolTable.h:17