-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCGFrontendAction.h
80 lines (65 loc) · 2.36 KB
/
CGFrontendAction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/****************************************************************/
/* All rights reserved (it will be changed) */
/* masud.abunaser@mdh.se */
/****************************************************************/
#ifndef LLVM_CLANG_CGFRONTENDACTION_H
#define LLVM_CLANG_CGFRONTENDACTION_H
#include "clang/Driver/Options.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/CompilerInstance.h"
#include "libExt/CompilerInstanceCtu.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Tooling/Tooling.h"
#include "libExt/CallGraphCtu.h"
#include "steengaardPAVisitor.h"
#include "symTabBuilder.h"
using namespace std;
using namespace clang;
using namespace clang::driver;
using namespace clang::tooling;
using namespace llvm;
class CGConsumer : public ASTConsumer {
private:
CallGraph &CG;
SteengaardPAVisitor *visitorPA;
SymTabBuilderVisitor *visitorSymTab;
public:
explicit CGConsumer(CompilerInstance *CI,CallGraph &g,std::string file) : CG(g), visitorPA(new SteengaardPAVisitor(CI,0,file)),visitorSymTab(new SymTabBuilderVisitor(CI,0))
{}
virtual void HandleTranslationUnit(ASTContext &Context) {
//Perform pointer analysis first on this translation unit
visitorSymTab->TraverseDecl(Context.getTranslationUnitDecl());
//visitorSymTab->dumpSymTab();
visitorPA->initPA(visitorSymTab->getSymTab());
visitorPA->TraverseDecl(Context.getTranslationUnitDecl());
visitorPA->showStatistics();
TranslationUnitDecl *tu=Context.getTranslationUnitDecl();
CG.setPA(visitorPA);
CG.addToCallGraph(tu);
//Context.getSourceManager().getFileManager().PrintStats();
}
};
class CGFrontendAction : public ASTFrontendAction {
CallGraph &_cg;
public:
CGFrontendAction(CallGraph &cg)
: _cg (cg) {}
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) {
//llvm::errs()<<"Building Call Graph of "<<file.str()<<"\n";
return llvm::make_unique<CGConsumer>(&CI,_cg,file.str());
}
~CGFrontendAction(){
}
void EndSourceFileAction() {}
void EndSourceFileCtu() { }
void EndActionOnSourceFile() {}
void EndFrontendAction()
{
EndActionOnSourceFile();
setCompilerInstance(nullptr);
//setCurrentInput(FrontendInputFile());
}
};
#endif