-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
94 lines (77 loc) · 2.42 KB
/
main.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "main.h"
cl::list<string> InputFilenames(cl::Positional, cl::OneOrMore,
cl::desc("<input bitcode files>"));
/* ./main --print-func=<function name> <bitcode files> */
cl::opt<std::string> Print("print-func",
cl::desc("Print the LLVM IR of the function"),
cl::Optional);
/* ./main --find-func=<function name> <bitcode files> */
cl::opt<std::string>
Find("find-func", cl::desc("Find the LLVM bitcode file of the function"),
cl::Optional);
/* ./main --cops <bitcode files> */
cl::opt<bool> ProjCops(
"cops",
cl::desc("Generate the cops of the whole project and write to cops.txt"),
cl::init(false));
/* ./main --cbp <bitcode files> */
cl::opt<bool> ProjCbp(
"cbp",
cl::desc(
"Generate the cbp of the whole project and write to return_values.txt"),
cl::init(false));
cl::opt<bool> ProjPathExp("path-exp", cl::desc("Path explosion experiment"),
cl::init(false));
int main(int argc, char **argv) {
cl::ParseCommandLineOptions(
argc, argv,
"AURs consistency Checker - Peiwei Hu <[email protected]>\n");
vector<string> *BcFiles = new vector<string>();
assert(BcFiles);
for (unsigned i = 0; i < InputFilenames.size(); ++i) {
BcFiles->push_back(InputFilenames[i]);
}
if (Find.size()) {
LLVMContext *Context = new LLVMContext();
assert(Context);
Function *F = NULL;
for (string B : *BcFiles) {
F = loadFuncFromFile(Context, B, Find);
if (F) {
errs() << COLOR_BLUE "Find in " << B << "\n" COLOR_CLOSE;
break;
}
}
if (!F) {
errs() << COLOR_RED "Fail to find this function\n" COLOR_CLOSE;
}
delete Context;
}
if (Print.size()) {
LLVMContext *Context = new LLVMContext();
assert(Context);
Function *F = loadFuncFromFileList(Context, Print, BcFiles);
if (F) {
errs() << COLOR_BLUE "------ LLVM IR of " << Print
<< " ------\n" COLOR_CLOSE;
for (auto Iter = inst_begin(F); Iter != inst_end(F); Iter++) {
errs() << CONS_TAB << *Iter << "\n";
}
} else {
errs() << COLOR_RED
"Fail to find the function definition......\n" COLOR_CLOSE;
}
delete Context;
}
if (ProjPathExp) {
CBP(BcFiles, true);
}
if (ProjCbp) {
CBP(BcFiles);
}
if (ProjCops) {
CollectCheck(BcFiles);
}
delete BcFiles;
return 0;
}