-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabb.cpp
166 lines (155 loc) · 4.15 KB
/
abb.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// STL dependencies
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <utility>
#include <string>
#include <regex>
#include <iterator>
#include <set>
// LLVM dependencies
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/AbstractCallSite.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Analysis/DDG.h"
#include "llvm/Analysis/DDGPrinter.h"
#include "llvm/IR/Constants.h"
// JSON dependencies
#include <jsoncpp/json/json.h>
// Boost dependencies
#include <boost/algorithm/string.hpp>
using namespace llvm;
using namespace std;
namespace{
enum State
{
WHITE,
GRAY,
BLACK
};
class ProvenanceNode
{
public:
string action;
string artifact;
string id;
ProvenanceNode() {}
ProvenanceNode(string act, string art, string i)
{
action = act;
artifact = art;
id = i;
}
};
class AugmentedBasicBlock
{
private:
string blockId; // Unique Block Id
bool isRootBlock; // Defines if this is the starting block of the function.
bool isConditionalBlock; // Does it have branching at the end or just a straight jump to next block
bool hasInlineAssembly; // Is there any inline assembly instruction? Then parse separately
string trueBlock; // If branched, then next true block
string falseBlock; // If branched, then next false block
string nextBlock; // If not branched, then next block
vector<Instruction *> instructions; // All the call instructions are stored here (operation and arguments)
vector<StringRef> functions; // All the functions are stored here (Name only)
vector<string> parents; // Can keep track of the parent blocks if implementation wants
public:
AugmentedBasicBlock()
{
isConditionalBlock = false;
hasInlineAssembly = false;
isRootBlock = false;
}
string getBlockId()
{
return blockId;
}
void setBlockId(string blockID)
{
blockId = blockID;
}
void setRootBlock()
{
isRootBlock = true;
}
bool isARootBlock()
{
return isRootBlock;
}
void setInlineAssembly()
{
hasInlineAssembly = true;
}
bool getInlineAssemblyStatus()
{
return hasInlineAssembly;
}
void setConditionalBlock()
{
isConditionalBlock = true;
}
bool getConditionalBlock()
{
return isConditionalBlock;
}
string getNextBlock()
{
return nextBlock;
}
void setNextBlock(string nextB)
{
nextBlock = nextB;
}
string getTrueBlock()
{
return trueBlock;
}
void setTrueBlock(string trueB)
{
trueBlock = trueB;
}
string getFalseBlock()
{
return falseBlock;
}
void setFalseBlock(string falseB)
{
falseBlock = falseB;
}
vector<Instruction *> getInstructions()
{
return instructions;
}
void addInstruction(Instruction *instruction)
{
instructions.push_back(instruction);
}
vector<StringRef> getFunctions()
{
return functions;
}
void addFunction(StringRef functionName)
{
functions.push_back(functionName);
}
vector<string> getParents()
{
return parents;
}
void addParent(string parent)
{
parents.push_back(parent);
}
};
}