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
|
@@ -48,21 +48,21 @@ CFLGrammar* CFGNormalizer::normalize(GrammarBase *generalGrammar)
|
|
|
48
48
|
grammar->setEBNFSigns(generalGrammar->getEBNFSigns());
|
|
49
49
|
grammar->setTotalKind(generalGrammar->getTotalKind());
|
|
50
50
|
grammar->setAttributeKinds(generalGrammar->getAttrSyms());
|
|
51
|
-
grammar->
|
|
51
|
+
grammar->setKindToAttrsMap(generalGrammar->getKindToAttrsMap());
|
|
52
52
|
grammar->setRawProductions(generalGrammar->getRawProductions());
|
|
53
53
|
barReplace(grammar);
|
|
54
54
|
ebnfSignReplace('*', grammar);
|
|
55
55
|
ebnfSignReplace('?', grammar);
|
|
56
56
|
ebnf_bin(grammar);
|
|
57
|
-
fillAttribute(grammar, grammar->
|
|
57
|
+
fillAttribute(grammar, grammar->getKindToAttrsMap());
|
|
58
58
|
return grammar;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
CFLGrammar* CFGNormalizer::fillAttribute(CFLGrammar *grammar, const Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>>&
|
|
62
|
+
CFLGrammar* CFGNormalizer::fillAttribute(CFLGrammar *grammar, const Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>>& kindToAttrsMap)
|
|
63
63
|
{
|
|
64
64
|
NodeSet nodeSet = {};
|
|
65
|
-
for (auto pair:
|
|
65
|
+
for (auto pair: kindToAttrsMap)
|
|
66
66
|
{
|
|
67
67
|
for (auto attri: pair.second)
|
|
68
68
|
{
|
|
@@ -245,7 +245,7 @@ void CFGNormalizer::getFilledProductions(GrammarBase::Production &prod, const No
|
|
|
245
245
|
normalProds.insert(currentProduction);
|
|
246
246
|
continue;
|
|
247
247
|
}
|
|
248
|
-
//*(
|
|
248
|
+
//*(kindToAttriMap.find(baseKind));
|
|
249
249
|
//for (auto attribute : nodeSet.second)
|
|
250
250
|
for (auto attribute : nodeSet)
|
|
251
251
|
{
|
|
@@ -284,7 +284,7 @@ int CFGNormalizer::ebnfBracketMatch(GrammarBase::Production &prod, int i, CFLGra
|
|
|
284
284
|
int index = i;
|
|
285
285
|
while (index >= 0)
|
|
286
286
|
{
|
|
287
|
-
if (grammar->
|
|
287
|
+
if (grammar->kindToStr(prod[index].kind) == "(")
|
|
288
288
|
{
|
|
289
289
|
return index;
|
|
290
290
|
}
|
|
@@ -305,7 +305,7 @@ void CFGNormalizer::barReplace(CFLGrammar *grammar)
|
|
|
305
305
|
size_t j = 1;
|
|
306
306
|
while (i < ebnfProduction.size())
|
|
307
307
|
{
|
|
308
|
-
if (grammar->
|
|
308
|
+
if (grammar->kindToStr(ebnfProduction[i].kind) == "|")
|
|
309
309
|
{
|
|
310
310
|
GrammarBase::Production tempPro(ebnfProduction.begin()+j, ebnfProduction.begin()+i);
|
|
311
311
|
tempPro.insert(tempPro.begin(), symbolToProductionsPair.first );
|
|
@@ -339,11 +339,11 @@ void CFGNormalizer::ebnfSignReplace(char sign, CFLGrammar *grammar)
|
|
|
339
339
|
while (i < ebnfProduction.size())
|
|
340
340
|
{
|
|
341
341
|
s32_t signGroupStart = -1;
|
|
342
|
-
if (grammar->
|
|
342
|
+
if (grammar->kindToStr(ebnfProduction[i].kind) == std::string(1, sign))
|
|
343
343
|
{
|
|
344
344
|
/// If sign assoicate wihout group e.i with single symble
|
|
345
345
|
assert(i != 1 && "sign in grammar associate with no symbol");
|
|
346
|
-
if (grammar->
|
|
346
|
+
if (grammar->kindToStr(ebnfProduction[i - 1].kind) != std::string(1, ')'))
|
|
347
347
|
{
|
|
348
348
|
signGroupStart = i - 1;
|
|
349
349
|
}
|
|
@@ -355,20 +355,20 @@ void CFGNormalizer::ebnfSignReplace(char sign, CFLGrammar *grammar)
|
|
|
355
355
|
std::string groupString = "";
|
|
356
356
|
for (size_t j = signGroupStart; j < i; j++)
|
|
357
357
|
{
|
|
358
|
-
groupString.append(grammar->
|
|
358
|
+
groupString.append(grammar->kindToStr(ebnfProduction[j].kind));
|
|
359
359
|
groupString.append(" ");
|
|
360
360
|
}
|
|
361
|
-
groupString.append(grammar->
|
|
361
|
+
groupString.append(grammar->kindToStr(ebnfProduction[i].kind));
|
|
362
362
|
if (newProductions.find(groupString) != newProductions.end())
|
|
363
363
|
{
|
|
364
364
|
productions.erase(ebnfProduction);
|
|
365
365
|
ebnfProduction.erase(ebnfProduction.begin() + signGroupStart, ebnfProduction.begin() + i + 1);
|
|
366
|
-
ebnfProduction.insert(ebnfProduction.begin() + signGroupStart, grammar->
|
|
366
|
+
ebnfProduction.insert(ebnfProduction.begin() + signGroupStart, grammar->strToSymbol(newProductions[groupString]));
|
|
367
367
|
productions.insert(ebnfProduction);
|
|
368
368
|
}
|
|
369
369
|
else if ( (signGroupStart == 1) && (i == ebnfProduction.size() -1))
|
|
370
370
|
{
|
|
371
|
-
newProductions[groupString] = grammar->
|
|
371
|
+
newProductions[groupString] = grammar->kindToStr(ebnfProduction[0].kind);
|
|
372
372
|
productions.erase(ebnfProduction);
|
|
373
373
|
ebnfProduction.erase(ebnfProduction.begin() + signGroupStart, ebnfProduction.begin() + i + 1);
|
|
374
374
|
|
|
@@ -398,10 +398,10 @@ void CFGNormalizer::ebnfSignReplace(char sign, CFLGrammar *grammar)
|
|
|
398
398
|
{
|
|
399
399
|
/// For Both * and ? need to insert epsilon rule
|
|
400
400
|
std::string new_nonterminal = rep.second;
|
|
401
|
-
GrammarBase::Production temp_list = {grammar->
|
|
402
|
-
grammar->getRawProductions()[grammar->
|
|
401
|
+
GrammarBase::Production temp_list = {grammar->strToSymbol(new_nonterminal), grammar->strToSymbol("epsilon")};
|
|
402
|
+
grammar->getRawProductions()[grammar->strToSymbol(new_nonterminal)].insert(temp_list);
|
|
403
403
|
/// insert second rule for '*' X -> X E for '+' X -> E
|
|
404
|
-
temp_list = {grammar->
|
|
404
|
+
temp_list = {grammar->strToSymbol(new_nonterminal)};
|
|
405
405
|
if (sign == '*' || sign == '?')
|
|
406
406
|
{
|
|
407
407
|
/// Insert Back the Group
|
|
@@ -412,18 +412,18 @@ void CFGNormalizer::ebnfSignReplace(char sign, CFLGrammar *grammar)
|
|
|
412
412
|
{
|
|
413
413
|
for (auto &word : normalProd)
|
|
414
414
|
{
|
|
415
|
-
if (word != grammar->
|
|
415
|
+
if (word != grammar->strToSymbol("*") && word != grammar->strToSymbol("(") && word != grammar->strToSymbol(")"))
|
|
416
416
|
{
|
|
417
417
|
withoutSign.push_back(word);
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
|
-
withoutSign.push_back(grammar->
|
|
420
|
+
withoutSign.push_back(grammar->strToSymbol(rep.second));
|
|
421
421
|
}
|
|
422
422
|
if (sign == '?')
|
|
423
423
|
{
|
|
424
424
|
for (auto &word : normalProd)
|
|
425
425
|
{
|
|
426
|
-
if (word != grammar->
|
|
426
|
+
if (word != grammar->strToSymbol("?") && word != grammar->strToSymbol("(") && word != grammar->strToSymbol(")"))
|
|
427
427
|
{
|
|
428
428
|
withoutSign.push_back(word);
|
|
429
429
|
}
|
|
@@ -431,7 +431,7 @@ void CFGNormalizer::ebnfSignReplace(char sign, CFLGrammar *grammar)
|
|
|
431
431
|
}
|
|
432
432
|
temp_list.insert(temp_list.end(), withoutSign.begin(), withoutSign.end());
|
|
433
433
|
}
|
|
434
|
-
grammar->getRawProductions()[grammar->
|
|
434
|
+
grammar->getRawProductions()[grammar->strToSymbol(new_nonterminal)].insert(temp_list);
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
437
|
|
|
@@ -449,9 +449,9 @@ void CFGNormalizer::strTrans(std::string LHS, CFLGrammar *grammar, GrammarBase::
|
|
|
449
449
|
{
|
|
450
450
|
word = LHS.substr(0, pos);
|
|
451
451
|
LHS.erase(0, pos + delimiter.length());
|
|
452
|
-
normalProd.push_back(grammar->
|
|
452
|
+
normalProd.push_back(grammar->strToSymbol(word));
|
|
453
453
|
}
|
|
454
|
-
normalProd.push_back(grammar->
|
|
454
|
+
normalProd.push_back(grammar->strToSymbol(LHS));
|
|
455
455
|
}
|
|
456
456
|
|
|
457
457
|
GrammarBase::Symbol CFGNormalizer::check_head(GrammarBase::SymbolMap<GrammarBase::Symbol, GrammarBase::Productions> &grammar, GrammarBase::Production &rule)
|
|
@@ -475,7 +475,7 @@ void CFGNormalizer::insertToCFLGrammar(CFLGrammar *grammar, GrammarBase::Product
|
|
|
475
475
|
{
|
|
476
476
|
if (prod.size() == 2)
|
|
477
477
|
{
|
|
478
|
-
if ((std::find(prod.begin(), prod.end(), grammar->
|
|
478
|
+
if ((std::find(prod.begin(), prod.end(), grammar->strToKind("epsilon")) != prod.end()))
|
|
479
479
|
{
|
|
480
480
|
if (std::find(grammar->getEpsilonProds().begin(), grammar->getEpsilonProds().end(), prod) == grammar->getEpsilonProds().end())
|
|
481
481
|
{
|
|
@@ -484,13 +484,13 @@ void CFGNormalizer::insertToCFLGrammar(CFLGrammar *grammar, GrammarBase::Product
|
|
|
484
484
|
}
|
|
485
485
|
else
|
|
486
486
|
{
|
|
487
|
-
grammar->
|
|
487
|
+
grammar->getSingleRHSToProds()[prod[1]].insert(prod);
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
if (prod.size() == 3)
|
|
491
491
|
{
|
|
492
|
-
grammar->
|
|
493
|
-
grammar->
|
|
492
|
+
grammar->getFirstRHSToProds()[prod[1]].insert(prod);
|
|
493
|
+
grammar->getSecondRHSToProds()[prod[2]].insert(prod);
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
496
|
|
package/svf/lib/CFL/CFLAlias.cpp
CHANGED
package/svf/lib/CFL/CFLBase.cpp
CHANGED
|
@@ -46,6 +46,21 @@ double CFLBase::numOfStartEdges = 0;
|
|
|
46
46
|
double CFLBase::numOfIteration = 1;
|
|
47
47
|
double CFLBase::numOfChecks = 1;
|
|
48
48
|
|
|
49
|
+
void CFLBase::checkParameter()
|
|
50
|
+
{
|
|
51
|
+
// Check for valid grammar file before parsing other options
|
|
52
|
+
std::string filename = Options::GrammarFilename();
|
|
53
|
+
bool cflfile = (filename.rfind("CFLGrammar.txt") == filename.length() - std::string("CFLGrammar.txt").length());
|
|
54
|
+
bool pegfile = (filename.rfind("PEGGrammar.txt") == filename.length() - std::string("PEGGrammar.txt").length());
|
|
55
|
+
if (!Options::Customized() && !(cflfile || pegfile))
|
|
56
|
+
{
|
|
57
|
+
SVFUtil::errs() << "Invalid alias grammar file: " << Options::GrammarFilename() << "\n"
|
|
58
|
+
<< "Please use a file that ends with either 'CFLGrammar.txt' or 'PEGGrammar.txt', "
|
|
59
|
+
<< "or use the -customized flag to allow custom grammar files.\n";
|
|
60
|
+
assert(false && "grammar loading failed!"); // exit with error
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
49
64
|
void CFLBase::buildCFLGrammar()
|
|
50
65
|
{
|
|
51
66
|
// Start building grammar
|
|
@@ -76,8 +91,14 @@ void CFLBase::buildCFLGraph()
|
|
|
76
91
|
delete consCG;
|
|
77
92
|
}
|
|
78
93
|
else
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
{
|
|
95
|
+
std::string fileName = Options::CFLGraph();
|
|
96
|
+
bool dotfile = (fileName.rfind(".dot") == fileName.length() - std::string("dot").length());
|
|
97
|
+
if (dotfile)
|
|
98
|
+
graph = cflGraphBuilder.buildFromDot(Options::CFLGraph(), grammarBase);
|
|
99
|
+
else
|
|
100
|
+
graph = cflGraphBuilder.buildFromTextFile(Options::CFLGraph(), grammarBase);
|
|
101
|
+
}
|
|
81
102
|
// Check CFL Graph and Grammar are accordance with grammar
|
|
82
103
|
CFLGramGraphChecker cflChecker = CFLGramGraphChecker();
|
|
83
104
|
cflChecker.check(grammarBase, &cflGraphBuilder, graph);
|
|
@@ -42,9 +42,9 @@ void GrammarBase::setRawProductions(SymbolMap<Symbol, Productions>& rawProductio
|
|
|
42
42
|
this->rawProductions = rawProductions;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
void GrammarBase::
|
|
45
|
+
void GrammarBase::setKindToAttrsMap(const Map<Kind, Set<Attribute>>& kindToAttrsMap)
|
|
46
46
|
{
|
|
47
|
-
this->
|
|
47
|
+
this->kindToAttrsMap = kindToAttrsMap;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
void GrammarBase::setAttributeKinds(const Set<Kind>& attributeKinds)
|
|
@@ -52,7 +52,7 @@ void GrammarBase::setAttributeKinds(const Set<Kind>& attributeKinds)
|
|
|
52
52
|
this->attributeKinds = attributeKinds;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
GrammarBase::Kind GrammarBase::
|
|
55
|
+
GrammarBase::Kind GrammarBase::strToKind(std::string str) const
|
|
56
56
|
{
|
|
57
57
|
|
|
58
58
|
auto tit = terminals.find(str);
|
|
@@ -71,12 +71,12 @@ GrammarBase::Kind GrammarBase::str2Kind(std::string str) const
|
|
|
71
71
|
abort();
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
GrammarBase::Symbol GrammarBase::
|
|
74
|
+
GrammarBase::Symbol GrammarBase::strToSymbol(const std::string str) const
|
|
75
75
|
{
|
|
76
76
|
Symbol symbol;
|
|
77
77
|
std::string attributeStr = extractAttributeStrFromSymbolStr(str);
|
|
78
78
|
std::string kindStr = extractKindStrFromSymbolStr(str);
|
|
79
|
-
symbol.kind =
|
|
79
|
+
symbol.kind = strToKind(kindStr);
|
|
80
80
|
|
|
81
81
|
if ( attributeStr == "") return symbol;
|
|
82
82
|
|
|
@@ -100,7 +100,7 @@ GrammarBase::Symbol GrammarBase::str2Symbol(const std::string str) const
|
|
|
100
100
|
return symbol;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
std::string GrammarBase::
|
|
103
|
+
std::string GrammarBase::kindToStr(Kind kind) const
|
|
104
104
|
{
|
|
105
105
|
|
|
106
106
|
std::string key = "";
|
|
@@ -136,7 +136,7 @@ std::string GrammarBase::kind2Str(Kind kind) const
|
|
|
136
136
|
return "";
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
std::string GrammarBase::
|
|
139
|
+
std::string GrammarBase::symToStrDump(Symbol sym) const
|
|
140
140
|
{
|
|
141
141
|
Kind kind = sym.kind;
|
|
142
142
|
Attribute attribute = sym.attribute;
|
|
@@ -184,7 +184,7 @@ GrammarBase::Kind GrammarBase::insertTerminalKind(std::string kindStr)
|
|
|
184
184
|
}
|
|
185
185
|
else
|
|
186
186
|
{
|
|
187
|
-
kind =
|
|
187
|
+
kind = strToKind(kindStr);
|
|
188
188
|
}
|
|
189
189
|
return kind;
|
|
190
190
|
}
|
|
@@ -199,7 +199,7 @@ inline GrammarBase::Kind GrammarBase::insertNonterminalKind(std::string const ki
|
|
|
199
199
|
}
|
|
200
200
|
else
|
|
201
201
|
{
|
|
202
|
-
kind =
|
|
202
|
+
kind = strToKind(kindStr);
|
|
203
203
|
}
|
|
204
204
|
return kind;
|
|
205
205
|
}
|
|
@@ -318,7 +318,7 @@ GrammarBase::Symbol GrammarBase::insertEBNFSigns(std::string symbolStr)
|
|
|
318
318
|
}
|
|
319
319
|
else
|
|
320
320
|
{
|
|
321
|
-
sign =
|
|
321
|
+
sign = strToKind(symbolStr);
|
|
322
322
|
}
|
|
323
323
|
return sign;
|
|
324
324
|
|
|
@@ -327,14 +327,14 @@ GrammarBase::Symbol GrammarBase::insertEBNFSigns(std::string symbolStr)
|
|
|
327
327
|
void GrammarBase::insertAttribute(Kind kind, Attribute attribute)
|
|
328
328
|
{
|
|
329
329
|
attributeKinds.insert(kind);
|
|
330
|
-
if (
|
|
330
|
+
if (kindToAttrsMap.find(kind)!= kindToAttrsMap.end())
|
|
331
331
|
{
|
|
332
|
-
|
|
332
|
+
kindToAttrsMap[kind].insert(attribute);
|
|
333
333
|
}
|
|
334
334
|
else
|
|
335
335
|
{
|
|
336
336
|
Set<CFLGrammar::Attribute> attrs {attribute};
|
|
337
|
-
|
|
337
|
+
kindToAttrsMap.insert(make_pair(kind, attrs));
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
|
|
@@ -352,7 +352,7 @@ void CFLGrammar::dump(std::string fileName) const
|
|
|
352
352
|
{
|
|
353
353
|
std::ofstream gramFile(fileName);
|
|
354
354
|
gramFile << "Start Kind:\n";
|
|
355
|
-
gramFile << '\t' <<
|
|
355
|
+
gramFile << '\t' << kindToStr(startKind) << '(' << startKind << ')' << ' ' << "\n\n";
|
|
356
356
|
|
|
357
357
|
gramFile << "Epsilon Production:\n";
|
|
358
358
|
std::vector<std::string> strV;
|
|
@@ -365,7 +365,7 @@ void CFLGrammar::dump(std::string fileName) const
|
|
|
365
365
|
{
|
|
366
366
|
ss << "-> ";
|
|
367
367
|
}
|
|
368
|
-
ss <<
|
|
368
|
+
ss << symToStrDump(sym) << '(' << sym.kind << ')' << ' ';
|
|
369
369
|
}
|
|
370
370
|
strV.insert(strV.begin(), ss.str());
|
|
371
371
|
}
|
|
@@ -380,7 +380,7 @@ void CFLGrammar::dump(std::string fileName) const
|
|
|
380
380
|
|
|
381
381
|
gramFile << "Single Production:\n";
|
|
382
382
|
strV = {};
|
|
383
|
-
for (auto symProPair:
|
|
383
|
+
for (auto symProPair: singleRHSToProds)
|
|
384
384
|
{
|
|
385
385
|
for (auto pro: symProPair.second)
|
|
386
386
|
{
|
|
@@ -393,7 +393,7 @@ void CFLGrammar::dump(std::string fileName) const
|
|
|
393
393
|
{
|
|
394
394
|
ss << "-> ";
|
|
395
395
|
}
|
|
396
|
-
ss <<
|
|
396
|
+
ss << symToStrDump(sym) << '(' << sym.kind << ')' << ' ';
|
|
397
397
|
}
|
|
398
398
|
strV.insert(strV.begin(), ss.str());
|
|
399
399
|
}
|
|
@@ -409,7 +409,7 @@ void CFLGrammar::dump(std::string fileName) const
|
|
|
409
409
|
|
|
410
410
|
gramFile << "Binary Production:\n";
|
|
411
411
|
strV = {};
|
|
412
|
-
for (auto symProPair:
|
|
412
|
+
for (auto symProPair: firstRHSToProds)
|
|
413
413
|
{
|
|
414
414
|
for (auto pro: symProPair.second)
|
|
415
415
|
{
|
|
@@ -423,7 +423,7 @@ void CFLGrammar::dump(std::string fileName) const
|
|
|
423
423
|
{
|
|
424
424
|
ss << "-> ";
|
|
425
425
|
}
|
|
426
|
-
ss <<
|
|
426
|
+
ss << symToStrDump(sym) << '(' << sym.kind << ')' << ' ';
|
|
427
427
|
}
|
|
428
428
|
strV.insert(strV.begin(), ss.str());
|
|
429
429
|
}
|