svf-tools 1.0.730 → 1.0.732
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/svf/include/CFL/CFGNormalizer.h +1 -1
- package/svf/include/CFL/CFLAlias.h +2 -2
- package/svf/include/CFL/CFLBase.h +3 -0
- package/svf/include/CFL/CFLGramGraphChecker.h +10 -10
- package/svf/include/CFL/CFLGrammar.h +29 -29
- package/svf/include/CFL/CFLGraphBuilder.h +68 -44
- package/svf/include/CFL/CFLVF.h +3 -0
- package/svf/include/SVFIR/SVFValue.h +7 -0
- package/svf/include/Util/ExtAPI.h +209 -19
- package/svf/include/Util/ExtAPI.json +125 -22
- package/svf/include/Util/Options.h +1 -0
- package/svf/include/Util/SVFUtil.h +12 -5
- package/svf/lib/CFL/CFGNormalizer.cpp +26 -26
- package/svf/lib/CFL/CFLAlias.cpp +3 -0
- package/svf/lib/CFL/CFLBase.cpp +23 -2
- package/svf/lib/CFL/CFLGrammar.cpp +19 -19
- package/svf/lib/CFL/CFLGraphBuilder.cpp +153 -178
- package/svf/lib/CFL/CFLSolver.cpp +3 -3
- package/svf/lib/CFL/CFLVF.cpp +18 -0
- package/svf/lib/Util/ExtAPI.cpp +90 -18
- package/svf/lib/Util/Options.cpp +6 -0
- package/svf-llvm/include/SVF-LLVM/LLVMModule.h +1 -0
- package/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h +10 -5
- package/svf-llvm/lib/LLVMUtil.cpp +21 -11
- package/svf-llvm/lib/SVFIRBuilder.cpp +1 -423
- package/svf-llvm/lib/SVFIRExtAPI.cpp +681 -0
- package/svf-llvm/tools/CFL/cfl.cpp +14 -0
|
@@ -33,124 +33,162 @@
|
|
|
33
33
|
|
|
34
34
|
namespace SVF
|
|
35
35
|
{
|
|
36
|
-
///
|
|
36
|
+
/// Add attribute to kindToAttribute Map
|
|
37
37
|
void CFLGraphBuilder::addAttribute(CFLGrammar::Kind kind, CFLGrammar::Attribute attribute)
|
|
38
38
|
{
|
|
39
|
-
if(
|
|
39
|
+
if (kindToAttrsMap.find(kind) == kindToAttrsMap.end())
|
|
40
40
|
{
|
|
41
|
-
Set<CFLGrammar::Attribute> attrs
|
|
42
|
-
|
|
41
|
+
Set<CFLGrammar::Attribute> attrs{attribute};
|
|
42
|
+
kindToAttrsMap.insert(make_pair(kind, attrs));
|
|
43
43
|
}
|
|
44
44
|
else
|
|
45
45
|
{
|
|
46
|
-
if(
|
|
46
|
+
if (kindToAttrsMap[kind].find(attribute) == kindToAttrsMap[kind].end())
|
|
47
47
|
{
|
|
48
|
-
|
|
48
|
+
kindToAttrsMap[kind].insert(attribute);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
void CFLGraphBuilder::build(std::string filename, CFLGraph* cflGraph)
|
|
53
|
+
/// build label and kind connect from the grammar
|
|
54
|
+
void CFLGraphBuilder::buildlabelToKindMap(GrammarBase *grammar)
|
|
56
55
|
{
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
CFLGraph * CFLGraphBuilder::buildFromDot(std::string fileName, GrammarBase *grammar)
|
|
60
|
-
{
|
|
61
|
-
CFLGraph *cflGraph = new CFLGraph(grammar->getStartKind());
|
|
62
|
-
externMap = true;
|
|
63
56
|
for(auto pairV : grammar->getTerminals())
|
|
64
57
|
{
|
|
65
|
-
if(
|
|
58
|
+
if(labelToKindMap.find(pairV.first) == labelToKindMap.end())
|
|
66
59
|
{
|
|
67
|
-
|
|
60
|
+
labelToKindMap.insert(pairV);
|
|
68
61
|
}
|
|
69
|
-
if(
|
|
62
|
+
if(kindToLabelMap.find(pairV.second) == kindToLabelMap.end())
|
|
70
63
|
{
|
|
71
|
-
|
|
64
|
+
kindToLabelMap.insert(make_pair(pairV.second, pairV.first));
|
|
72
65
|
}
|
|
73
66
|
}
|
|
74
67
|
|
|
75
68
|
for(auto pairV : grammar->getNonterminals())
|
|
76
69
|
{
|
|
77
|
-
if(
|
|
70
|
+
if(labelToKindMap.find(pairV.first) == labelToKindMap.end())
|
|
78
71
|
{
|
|
79
|
-
|
|
72
|
+
labelToKindMap.insert(pairV);
|
|
80
73
|
}
|
|
81
|
-
if(
|
|
74
|
+
if(kindToLabelMap.find(pairV.second) == kindToLabelMap.end())
|
|
82
75
|
{
|
|
83
|
-
|
|
76
|
+
kindToLabelMap.insert(make_pair(pairV.second, pairV.first));
|
|
84
77
|
}
|
|
85
78
|
}
|
|
79
|
+
}
|
|
86
80
|
|
|
87
|
-
|
|
81
|
+
/// add src and dst node from file
|
|
82
|
+
CFLNode* CFLGraphBuilder::addGNode(u32_t NodeID)
|
|
83
|
+
{
|
|
84
|
+
CFLNode* cflNode;
|
|
85
|
+
if (cflGraph->hasGNode(NodeID)==false)
|
|
86
|
+
{
|
|
87
|
+
cflNode = new CFLNode(NodeID);
|
|
88
|
+
cflGraph->addCFLNode(NodeID, cflNode);
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
{
|
|
92
|
+
cflNode = cflGraph->getGNode(NodeID);
|
|
93
|
+
}
|
|
94
|
+
return cflNode;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
//// Build graph from text file
|
|
99
|
+
CFLGraph* CFLGraphBuilder::buildFromTextFile(std::string fileName, GrammarBase *grammar)
|
|
100
|
+
{
|
|
101
|
+
buildlabelToKindMap(grammar);
|
|
102
|
+
cflGraph = new CFLGraph(grammar->getStartKind());
|
|
103
|
+
|
|
104
|
+
std::cout << "Building CFL Graph from text file: " << fileName << "..\n";
|
|
88
105
|
std::string lineString;
|
|
89
106
|
std::ifstream inputFile(fileName);
|
|
90
107
|
|
|
91
|
-
|
|
108
|
+
if (!inputFile.is_open())
|
|
109
|
+
{
|
|
110
|
+
SVFUtil::errs() << "Error opening " << fileName << std::endl;
|
|
111
|
+
abort();
|
|
112
|
+
}
|
|
92
113
|
|
|
93
|
-
std::
|
|
114
|
+
std::string line;
|
|
115
|
+
current = labelToKindMap.size();
|
|
94
116
|
u32_t lineNum = 0 ;
|
|
95
|
-
current = label2KindMap.size();
|
|
96
117
|
|
|
97
|
-
while (getline(inputFile,
|
|
118
|
+
while (getline(inputFile, line))
|
|
98
119
|
{
|
|
120
|
+
std::vector<std::string> vec = SVFUtil::split(line, '\t');
|
|
121
|
+
if (vec.empty())
|
|
122
|
+
continue;
|
|
99
123
|
lineNum += 1;
|
|
100
|
-
std::
|
|
101
|
-
|
|
124
|
+
NodeID srcID = std::stoi(vec[0]);
|
|
125
|
+
NodeID dstID = std::stoi(vec[1]);
|
|
126
|
+
CFLNode *src = addGNode(srcID);
|
|
127
|
+
CFLNode *dst = addGNode(dstID);
|
|
128
|
+
std::string label = vec[2];
|
|
129
|
+
if (labelToKindMap.find(label) != labelToKindMap.end())
|
|
130
|
+
cflGraph->addCFLEdge(src, dst, labelToKindMap[label]);
|
|
131
|
+
else
|
|
102
132
|
{
|
|
103
|
-
|
|
104
|
-
if (cflGraph->hasGNode(std::stoul(matches.str(1), nullptr, 16))==false)
|
|
105
|
-
{
|
|
106
|
-
src = new CFLNode(std::stoul(matches.str(1), nullptr, 16));
|
|
107
|
-
cflGraph->addCFLNode(src->getId(), src);
|
|
108
|
-
}
|
|
109
|
-
else
|
|
133
|
+
if(Options::FlexSymMap() == true)
|
|
110
134
|
{
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (cflGraph->hasGNode(std::stoul(matches.str(2), nullptr, 16))==false)
|
|
114
|
-
{
|
|
115
|
-
dst = new CFLNode(std::stoul(matches.str(2), nullptr, 16));
|
|
116
|
-
cflGraph->addCFLNode(dst->getId(), dst);
|
|
135
|
+
labelToKindMap.insert({label, current++});
|
|
136
|
+
cflGraph->addCFLEdge(src, dst, labelToKindMap[label]);
|
|
117
137
|
}
|
|
118
138
|
else
|
|
119
139
|
{
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
{
|
|
126
|
-
cflGraph->addCFLEdge(src, dst, label2KindMap[matches.str(3)]);
|
|
127
|
-
}
|
|
128
|
-
else
|
|
129
|
-
{
|
|
130
|
-
label2KindMap.insert({matches.str(3), current++});
|
|
131
|
-
cflGraph->addCFLEdge(src, dst, label2KindMap[matches.str(3)]);
|
|
132
|
-
}
|
|
140
|
+
std::string msg = "In line " + std::to_string(lineNum) +
|
|
141
|
+
" sym can not find in grammar, please correct the input dot or set --flexsymmap.";
|
|
142
|
+
SVFUtil::errMsg(msg);
|
|
143
|
+
std::cout << msg;
|
|
144
|
+
abort();
|
|
133
145
|
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
inputFile.close();
|
|
150
|
+
return cflGraph;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
CFLGraph * CFLGraphBuilder::buildFromDot(std::string fileName, GrammarBase *grammar)
|
|
154
|
+
{
|
|
155
|
+
buildlabelToKindMap(grammar);
|
|
156
|
+
cflGraph = new CFLGraph(grammar->getStartKind());
|
|
157
|
+
std::string lineString;
|
|
158
|
+
std::ifstream inputFile(fileName);
|
|
159
|
+
std::cout << "Building CFL Graph from dot file: " << fileName << "..\n";
|
|
160
|
+
std::regex reg("Node(\\w+)\\s*->\\s*Node(\\w+)\\s*\\[.*label=(.*)\\]");
|
|
161
|
+
std::cout << std::boolalpha;
|
|
162
|
+
u32_t lineNum = 0 ;
|
|
163
|
+
current = labelToKindMap.size();
|
|
164
|
+
|
|
165
|
+
while (getline(inputFile, lineString))
|
|
166
|
+
{
|
|
167
|
+
lineNum += 1;
|
|
168
|
+
std::smatch matches;
|
|
169
|
+
if (std::regex_search(lineString, matches, reg))
|
|
170
|
+
{
|
|
171
|
+
u32_t srcID = std::stoul(matches.str(1), nullptr, 16);
|
|
172
|
+
u32_t dstID = std::stoul(matches.str(2), nullptr, 16);
|
|
173
|
+
std::string label = matches.str(3);
|
|
174
|
+
CFLNode *src = addGNode(srcID);
|
|
175
|
+
CFLNode *dst = addGNode(dstID);
|
|
176
|
+
if (labelToKindMap.find(label) != labelToKindMap.end())
|
|
177
|
+
cflGraph->addCFLEdge(src, dst, labelToKindMap[label]);
|
|
134
178
|
else
|
|
135
179
|
{
|
|
136
|
-
if
|
|
180
|
+
if(Options::FlexSymMap() == true)
|
|
137
181
|
{
|
|
138
|
-
|
|
182
|
+
labelToKindMap.insert({label, current++});
|
|
183
|
+
cflGraph->addCFLEdge(src, dst, labelToKindMap[label]);
|
|
139
184
|
}
|
|
140
185
|
else
|
|
141
186
|
{
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
else
|
|
148
|
-
{
|
|
149
|
-
std::string msg = "In line " + std::to_string(lineNum) + " sym can not find in grammar, please correct the input dot or set --flexsymmap.";
|
|
150
|
-
SVFUtil::errMsg(msg);
|
|
151
|
-
std::cout << msg;
|
|
152
|
-
abort();
|
|
153
|
-
}
|
|
187
|
+
std::string msg = "In line " + std::to_string(lineNum) +
|
|
188
|
+
" sym can not find in grammar, please correct the input dot or set --flexsymmap.";
|
|
189
|
+
SVFUtil::errMsg(msg);
|
|
190
|
+
std::cout << msg;
|
|
191
|
+
abort();
|
|
154
192
|
}
|
|
155
193
|
}
|
|
156
194
|
}
|
|
@@ -161,30 +199,9 @@ CFLGraph * CFLGraphBuilder::buildFromDot(std::string fileName, GrammarBase *gram
|
|
|
161
199
|
|
|
162
200
|
CFLGraph* AliasCFLGraphBuilder::buildBigraph(ConstraintGraph *graph, Kind startKind, GrammarBase *grammar)
|
|
163
201
|
{
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
{
|
|
168
|
-
if(label2KindMap.find(pairV.first) == label2KindMap.end())
|
|
169
|
-
{
|
|
170
|
-
label2KindMap.insert(pairV);
|
|
171
|
-
}
|
|
172
|
-
if(kind2LabelMap.find(pairV.second) == kind2LabelMap.end())
|
|
173
|
-
{
|
|
174
|
-
kind2LabelMap.insert(make_pair(pairV.second, pairV.first));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
for(auto pairV : grammar->getNonterminals())
|
|
178
|
-
{
|
|
179
|
-
if(label2KindMap.find(pairV.first) == label2KindMap.end())
|
|
180
|
-
{
|
|
181
|
-
label2KindMap.insert(pairV);
|
|
182
|
-
}
|
|
183
|
-
if(kind2LabelMap.find(pairV.second) == kind2LabelMap.end())
|
|
184
|
-
{
|
|
185
|
-
kind2LabelMap.insert(make_pair(pairV.second, pairV.first));
|
|
186
|
-
}
|
|
187
|
-
}
|
|
202
|
+
cflGraph = new CFLGraph(startKind);
|
|
203
|
+
|
|
204
|
+
buildlabelToKindMap(grammar);
|
|
188
205
|
for(auto it = graph->begin(); it!= graph->end(); it++)
|
|
189
206
|
{
|
|
190
207
|
CFLNode* node = new CFLNode((*it).first);
|
|
@@ -205,17 +222,17 @@ CFLGraph* AliasCFLGraphBuilder::buildBigraph(ConstraintGraph *graph, Kind startK
|
|
|
205
222
|
addAttribute(edgeLabel, attr);
|
|
206
223
|
edgeLabel = CFLGrammar::getAttributedKind(attr, edgeLabel);
|
|
207
224
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
|
|
208
|
-
std::string key =
|
|
225
|
+
std::string key = kindToLabelMap[edge->getEdgeKind()];
|
|
209
226
|
key.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
|
|
210
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr,
|
|
211
|
-
addAttribute(
|
|
227
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr, labelToKindMap[key]));
|
|
228
|
+
addAttribute(labelToKindMap[key], attr);
|
|
212
229
|
}
|
|
213
230
|
else
|
|
214
231
|
{
|
|
215
232
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
|
|
216
|
-
std::string key =
|
|
233
|
+
std::string key = kindToLabelMap[edge->getEdgeKind()];
|
|
217
234
|
key.append("bar");
|
|
218
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()),
|
|
235
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[key]);
|
|
219
236
|
}
|
|
220
237
|
}
|
|
221
238
|
}
|
|
@@ -224,30 +241,9 @@ CFLGraph* AliasCFLGraphBuilder::buildBigraph(ConstraintGraph *graph, Kind startK
|
|
|
224
241
|
|
|
225
242
|
CFLGraph* AliasCFLGraphBuilder::buildBiPEGgraph(ConstraintGraph *graph, Kind startKind, GrammarBase *grammar, SVFIR* pag)
|
|
226
243
|
{
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
{
|
|
231
|
-
if(label2KindMap.find(pairV.first) == label2KindMap.end())
|
|
232
|
-
{
|
|
233
|
-
label2KindMap.insert(pairV);
|
|
234
|
-
}
|
|
235
|
-
if(kind2LabelMap.find(pairV.second) == kind2LabelMap.end())
|
|
236
|
-
{
|
|
237
|
-
kind2LabelMap.insert(make_pair(pairV.second, pairV.first));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
for(auto pairV : grammar->getNonterminals())
|
|
241
|
-
{
|
|
242
|
-
if(label2KindMap.find(pairV.first) == label2KindMap.end())
|
|
243
|
-
{
|
|
244
|
-
label2KindMap.insert(pairV);
|
|
245
|
-
}
|
|
246
|
-
if(kind2LabelMap.find(pairV.second) == kind2LabelMap.end())
|
|
247
|
-
{
|
|
248
|
-
kind2LabelMap.insert(make_pair(pairV.second, pairV.first));
|
|
249
|
-
}
|
|
250
|
-
}
|
|
244
|
+
cflGraph = new CFLGraph(startKind);
|
|
245
|
+
|
|
246
|
+
buildlabelToKindMap(grammar);
|
|
251
247
|
for(auto it = graph->begin(); it!= graph->end(); it++)
|
|
252
248
|
{
|
|
253
249
|
CFLNode* node = new CFLNode((*it).first);
|
|
@@ -284,15 +280,15 @@ CFLGraph* AliasCFLGraphBuilder::buildBiPEGgraph(ConstraintGraph *graph, Kind sta
|
|
|
284
280
|
cflGraph->addCFLNode(refId, CFLDerefNode);
|
|
285
281
|
/// Add Addr Edge
|
|
286
282
|
cflGraph->addCFLEdge(CFLDerefNode, cflGraph->getGNode(edge->getDstID()), ConstraintEdge::Addr);
|
|
287
|
-
std::string key =
|
|
283
|
+
std::string key = kindToLabelMap[ConstraintEdge::Addr];
|
|
288
284
|
key.append("bar");
|
|
289
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), CFLDerefNode,
|
|
285
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), CFLDerefNode, labelToKindMap[key]);
|
|
290
286
|
}
|
|
291
287
|
/// Add Copy Edge
|
|
292
288
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(CFLDerefNode->getId()), ConstraintEdge::Copy);
|
|
293
|
-
std::string key =
|
|
289
|
+
std::string key = kindToLabelMap[ConstraintEdge::Copy];
|
|
294
290
|
key.append("bar");
|
|
295
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(CFLDerefNode->getId()), cflGraph->getGNode(edge->getSrcID()),
|
|
291
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(CFLDerefNode->getId()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[key]);
|
|
296
292
|
}
|
|
297
293
|
/// Process Load
|
|
298
294
|
else if ( edge->getEdgeKind() == ConstraintEdge::Load)
|
|
@@ -316,15 +312,15 @@ CFLGraph* AliasCFLGraphBuilder::buildBiPEGgraph(ConstraintGraph *graph, Kind sta
|
|
|
316
312
|
cflGraph->addCFLNode(refId, CFLDerefNode);
|
|
317
313
|
/// Add Addr Edge
|
|
318
314
|
cflGraph->addCFLEdge(CFLDerefNode, cflGraph->getGNode(edge->getSrcID()), ConstraintEdge::Addr);
|
|
319
|
-
std::string key =
|
|
315
|
+
std::string key = kindToLabelMap[ConstraintEdge::Addr];
|
|
320
316
|
key.append("bar");
|
|
321
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), CFLDerefNode,
|
|
317
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), CFLDerefNode, labelToKindMap[key]);
|
|
322
318
|
}
|
|
323
319
|
/// Add Copy Edge
|
|
324
320
|
cflGraph->addCFLEdge(cflGraph->getGNode(CFLDerefNode->getId()), cflGraph->getGNode(edge->getDstID()), ConstraintEdge::Copy);
|
|
325
|
-
std::string key =
|
|
321
|
+
std::string key = kindToLabelMap[ConstraintEdge::Copy];
|
|
326
322
|
key.append("bar");
|
|
327
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(CFLDerefNode->getId()),
|
|
323
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(CFLDerefNode->getId()), labelToKindMap[key]);
|
|
328
324
|
}
|
|
329
325
|
else if ( edge->getEdgeKind() == ConstraintEdge::VariantGep)
|
|
330
326
|
{
|
|
@@ -346,17 +342,17 @@ CFLGraph* AliasCFLGraphBuilder::buildBiPEGgraph(ConstraintGraph *graph, Kind sta
|
|
|
346
342
|
addAttribute(edgeLabel, attr);
|
|
347
343
|
edgeLabel = CFLGrammar::getAttributedKind(attr, edgeLabel);
|
|
348
344
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
|
|
349
|
-
std::string key =
|
|
345
|
+
std::string key = kindToLabelMap[edge->getEdgeKind()];
|
|
350
346
|
key.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
|
|
351
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr,
|
|
352
|
-
addAttribute(
|
|
347
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr, labelToKindMap[key]));
|
|
348
|
+
addAttribute(labelToKindMap[key], attr);
|
|
353
349
|
}
|
|
354
350
|
else
|
|
355
351
|
{
|
|
356
352
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
|
|
357
|
-
std::string key =
|
|
353
|
+
std::string key = kindToLabelMap[edge->getEdgeKind()];
|
|
358
354
|
key.append("bar");
|
|
359
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()),
|
|
355
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[key]);
|
|
360
356
|
}
|
|
361
357
|
}
|
|
362
358
|
}
|
|
@@ -386,9 +382,9 @@ void AliasCFLGraphBuilder::AliasCFLGraphBuilder::connectVGep(CFLGraph *cflGraph,
|
|
|
386
382
|
void AliasCFLGraphBuilder::addBiCFLEdge(CFLGraph *cflGraph, ConstraintNode* src, ConstraintNode* dst, CFLGrammar::Kind label)
|
|
387
383
|
{
|
|
388
384
|
cflGraph->addCFLEdge(cflGraph->getGNode(src->getId()), cflGraph->getGNode(dst->getId()), label);
|
|
389
|
-
std::string key =
|
|
385
|
+
std::string key = kindToLabelMap[label];
|
|
390
386
|
key.append("bar");
|
|
391
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(dst->getId()), cflGraph->getGNode(src->getId()),
|
|
387
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(dst->getId()), cflGraph->getGNode(src->getId()), labelToKindMap[key]);
|
|
392
388
|
return;
|
|
393
389
|
}
|
|
394
390
|
|
|
@@ -396,38 +392,17 @@ void AliasCFLGraphBuilder::addBiGepCFLEdge(CFLGraph *cflGraph, ConstraintNode*
|
|
|
396
392
|
{
|
|
397
393
|
CFLEdge::GEdgeFlag edgeLabel = CFLGrammar::getAttributedKind(attri, ConstraintEdge::NormalGep);
|
|
398
394
|
cflGraph->addCFLEdge(cflGraph->getGNode(src->getId()), cflGraph->getGNode(dst->getId()), edgeLabel);
|
|
399
|
-
std::string key =
|
|
395
|
+
std::string key = kindToLabelMap[ConstraintEdge::NormalGep];
|
|
400
396
|
key.append("bar");
|
|
401
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(dst->getId()), cflGraph->getGNode(src->getId()), CFLGrammar::getAttributedKind(attri,
|
|
397
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(dst->getId()), cflGraph->getGNode(src->getId()), CFLGrammar::getAttributedKind(attri, labelToKindMap[key]));
|
|
402
398
|
return;
|
|
403
399
|
}
|
|
404
400
|
|
|
405
401
|
CFLGraph* VFCFLGraphBuilder::buildBigraph(SVFG *graph, Kind startKind, GrammarBase *grammar)
|
|
406
402
|
{
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
{
|
|
411
|
-
if(label2KindMap.find(pairV.first) == label2KindMap.end())
|
|
412
|
-
{
|
|
413
|
-
label2KindMap.insert(pairV);
|
|
414
|
-
}
|
|
415
|
-
if(kind2LabelMap.find(pairV.second) == kind2LabelMap.end())
|
|
416
|
-
{
|
|
417
|
-
kind2LabelMap.insert(make_pair(pairV.second, pairV.first));
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
for(auto pairV : grammar->getNonterminals())
|
|
421
|
-
{
|
|
422
|
-
if(label2KindMap.find(pairV.first) == label2KindMap.end())
|
|
423
|
-
{
|
|
424
|
-
label2KindMap.insert(pairV);
|
|
425
|
-
}
|
|
426
|
-
if(kind2LabelMap.find(pairV.second) == kind2LabelMap.end())
|
|
427
|
-
{
|
|
428
|
-
kind2LabelMap.insert(make_pair(pairV.second, pairV.first));
|
|
429
|
-
}
|
|
430
|
-
}
|
|
403
|
+
cflGraph = new CFLGraph(startKind);
|
|
404
|
+
|
|
405
|
+
buildlabelToKindMap(grammar);
|
|
431
406
|
for(auto it = graph->begin(); it!= graph->end(); it++)
|
|
432
407
|
{
|
|
433
408
|
CFLNode* node = new CFLNode((*it).first);
|
|
@@ -445,9 +420,9 @@ CFLGraph* VFCFLGraphBuilder::buildBigraph(SVFG *graph, Kind startKind, GrammarBa
|
|
|
445
420
|
edgeLabel = 0;
|
|
446
421
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
|
|
447
422
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
|
|
448
|
-
std::string key =
|
|
423
|
+
std::string key = kindToLabelMap[edge->getEdgeKind()];
|
|
449
424
|
key.append("bar");
|
|
450
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()),
|
|
425
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[key]);
|
|
451
426
|
}
|
|
452
427
|
// Get 'call' edge : CallDirVF || CallIndVF
|
|
453
428
|
else if ( edge->getEdgeKind() == VFGEdge::CallDirVF )
|
|
@@ -458,10 +433,10 @@ CFLGraph* VFCFLGraphBuilder::buildBigraph(SVFG *graph, Kind startKind, GrammarBa
|
|
|
458
433
|
addAttribute(edgeLabel, attr);
|
|
459
434
|
edgeLabel = CFLGrammar::getAttributedKind(attr, edgeLabel);
|
|
460
435
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
|
|
461
|
-
std::string key =
|
|
436
|
+
std::string key = kindToLabelMap[edgeLabel];
|
|
462
437
|
key.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
|
|
463
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr,
|
|
464
|
-
addAttribute(
|
|
438
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr, labelToKindMap[key]));
|
|
439
|
+
addAttribute(labelToKindMap[key], attr);
|
|
465
440
|
}
|
|
466
441
|
// Get 'call' edge : CallIndVF
|
|
467
442
|
else if ( edge->getEdgeKind() == VFGEdge::CallIndVF )
|
|
@@ -472,10 +447,10 @@ CFLGraph* VFCFLGraphBuilder::buildBigraph(SVFG *graph, Kind startKind, GrammarBa
|
|
|
472
447
|
addAttribute(edgeLabel, attr);
|
|
473
448
|
edgeLabel = CFLGrammar::getAttributedKind(attr, edgeLabel);
|
|
474
449
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
|
|
475
|
-
std::string key =
|
|
450
|
+
std::string key = kindToLabelMap[edgeLabel];
|
|
476
451
|
key.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
|
|
477
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr,
|
|
478
|
-
addAttribute(
|
|
452
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr, labelToKindMap[key]));
|
|
453
|
+
addAttribute(labelToKindMap[key], attr);
|
|
479
454
|
}
|
|
480
455
|
// Get 'ret' edge : RetDirVF
|
|
481
456
|
else if ( edge->getEdgeKind() == VFGEdge::RetDirVF )
|
|
@@ -486,10 +461,10 @@ CFLGraph* VFCFLGraphBuilder::buildBigraph(SVFG *graph, Kind startKind, GrammarBa
|
|
|
486
461
|
addAttribute(edgeLabel, attr);
|
|
487
462
|
edgeLabel = CFLGrammar::getAttributedKind(attr, edgeLabel);
|
|
488
463
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
|
|
489
|
-
std::string key =
|
|
464
|
+
std::string key = kindToLabelMap[edgeLabel];
|
|
490
465
|
key.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
|
|
491
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr,
|
|
492
|
-
addAttribute(
|
|
466
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr, labelToKindMap[key]));
|
|
467
|
+
addAttribute(labelToKindMap[key], attr);
|
|
493
468
|
}
|
|
494
469
|
// Get 'ret' edge : RetIndVF
|
|
495
470
|
else if ( edge->getEdgeKind() == VFGEdge::RetIndVF )
|
|
@@ -500,10 +475,10 @@ CFLGraph* VFCFLGraphBuilder::buildBigraph(SVFG *graph, Kind startKind, GrammarBa
|
|
|
500
475
|
addAttribute(edgeLabel, attr);
|
|
501
476
|
edgeLabel = CFLGrammar::getAttributedKind(attr, edgeLabel);
|
|
502
477
|
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
|
|
503
|
-
std::string key =
|
|
478
|
+
std::string key = kindToLabelMap[edgeLabel];
|
|
504
479
|
key.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
|
|
505
|
-
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr,
|
|
506
|
-
addAttribute(
|
|
480
|
+
cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr, labelToKindMap[key]));
|
|
481
|
+
addAttribute(labelToKindMap[key], attr);
|
|
507
482
|
}
|
|
508
483
|
}
|
|
509
484
|
}
|
|
@@ -240,7 +240,7 @@ void POCRHybridSolver::processCFLEdge(const CFLEdge* Y_edge)
|
|
|
240
240
|
if (grammar->hasProdsFromFirstRHS(Y))
|
|
241
241
|
for(const Production& prod : grammar->getProdsFromFirstRHS(Y))
|
|
242
242
|
{
|
|
243
|
-
if ((grammar->getLHSSymbol(prod) == grammar->
|
|
243
|
+
if ((grammar->getLHSSymbol(prod) == grammar->strToSymbol("F")) && (Y == grammar->strToSymbol("F")) && (grammar->getSecondRHSSymbol(prod) == grammar->strToSymbol("F")))
|
|
244
244
|
{
|
|
245
245
|
addArc(i->getId(), j->getId());
|
|
246
246
|
}
|
|
@@ -263,7 +263,7 @@ void POCRHybridSolver::processCFLEdge(const CFLEdge* Y_edge)
|
|
|
263
263
|
if(grammar->hasProdsFromSecondRHS(Y))
|
|
264
264
|
for(const Production& prod : grammar->getProdsFromSecondRHS(Y))
|
|
265
265
|
{
|
|
266
|
-
if ((grammar->getLHSSymbol(prod) == grammar->
|
|
266
|
+
if ((grammar->getLHSSymbol(prod) == grammar->strToSymbol("F")) && (Y == grammar->strToSymbol("F")) && (grammar->getFirstRHSSymbol(prod) == grammar->strToSymbol("F")))
|
|
267
267
|
{
|
|
268
268
|
addArc(i->getId(), j->getId());
|
|
269
269
|
}
|
|
@@ -313,7 +313,7 @@ void POCRHybridSolver::initialize()
|
|
|
313
313
|
|
|
314
314
|
void POCRHybridSolver::addArc(NodeID src, NodeID dst)
|
|
315
315
|
{
|
|
316
|
-
if(hasEdge(src, dst, grammar->
|
|
316
|
+
if(hasEdge(src, dst, grammar->strToSymbol("F")))
|
|
317
317
|
return;
|
|
318
318
|
|
|
319
319
|
for (auto& iter: indMap[src])
|
package/svf/lib/CFL/CFLVF.cpp
CHANGED
|
@@ -55,6 +55,9 @@ void CFLVF::buildCFLGraph()
|
|
|
55
55
|
|
|
56
56
|
void CFLVF::initialize()
|
|
57
57
|
{
|
|
58
|
+
// Parameter Checking
|
|
59
|
+
checkParameter();
|
|
60
|
+
|
|
58
61
|
// Build CFL Grammar
|
|
59
62
|
buildCFLGrammar();
|
|
60
63
|
|
|
@@ -68,6 +71,21 @@ void CFLVF::initialize()
|
|
|
68
71
|
solver = new CFLSolver(graph, grammar);
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
void CFLVF::checkParameter()
|
|
75
|
+
{
|
|
76
|
+
// Check for valid grammar file before parsing other options
|
|
77
|
+
std::string filename = Options::GrammarFilename();
|
|
78
|
+
bool vfgfile = (filename.rfind("VFG.txt") == filename.length() - std::string("VFG.txt").length());
|
|
79
|
+
if (!Options::Customized() && !vfgfile)
|
|
80
|
+
{
|
|
81
|
+
SVFUtil::errs() << "Invalid VFG grammar file: " << Options::GrammarFilename() << "\n"
|
|
82
|
+
<< "Please use a file that ends with 'VFG.txt', "
|
|
83
|
+
<< "or use the -customized flag to allow custom grammar files.\n";
|
|
84
|
+
assert(false && "grammar loading failed!"); // exit with error
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
71
89
|
void CFLVF::finalize()
|
|
72
90
|
{
|
|
73
91
|
if(Options::PrintCFL())
|