tipc
A TIP to LLVM compiler
CallGraphBuilder.h
Go to the documentation of this file.
1 #include "ASTVisitor.h"
2 #include "CFAnalyzer.h"
3 #include "treetypes/AST.h"
4 #include <map>
5 #include <ostream>
6 #include <set>
7 
17 public:
23  static CallGraphBuilder build(ASTProgram *ast, CFAnalyzer cfa);
24  bool visit(ASTFunction *element) override;
25  bool visit(ASTFunAppExpr *element) override;
26 
30  std::map<ASTFunction *, std::set<ASTFunction *>> getCallGraph();
31 
36  std::map<ASTFunAppExpr *, std::set<ASTFunction *>> getMayCall();
37 
43  std::map<std::string, ASTFunction *> getFunMap();
44 
45 private:
47  ASTNode *getCanonical(ASTNode *n);
48  ASTFunction *cfun;
49  CFAnalyzer cfa;
50  std::map<ASTFunction *, std::set<ASTFunction *>> graph;
51  std::map<ASTFunAppExpr *, std::set<ASTFunction *>> mayCall;
52  std::map<std::string, ASTFunction *> fromFunNameToASTFun;
53 };
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
Abstract base class for all AST nodes.
Definition: ASTNode.h:34
Class for a program which is a name and a list of functions.
Definition: ASTProgram.h:11
Base class for AST visitors.
Definition: ASTVisitor.h:23
Performs control flow analyses with the help of AST and Symbol table of a program Provides helper fun...
Definition: CFAnalyzer.h:15
Builds call graph of a program that represents calling relationships between subroutines This class o...
Definition: CallGraphBuilder.h:16
std::map< std::string, ASTFunction * > getFunMap()
Returns the map from a function name to its ASTFunction*, ASTFunction* is then used to fetch further ...
Definition: CallGraphBuilder.cpp:43
std::map< ASTFunction *, std::set< ASTFunction * > > getCallGraph()
Returns the call graph, call graph a map from caller to callee, the callee is a set of ASTFunction* a...
Definition: CallGraphBuilder.cpp:34
std::map< ASTFunAppExpr *, std::set< ASTFunction * > > getMayCall()
Returns the may call relation, which relates each call expression to the set of possible called funct...
Definition: CallGraphBuilder.cpp:39
static CallGraphBuilder build(ASTProgram *ast, CFAnalyzer cfa)
Returns the CallGraphBuilder for a given program.
Definition: CallGraphBuilder.cpp:4
bool visit(ASTFunction *element) override
Definition: CallGraphBuilder.cpp:12