svf-tools 1.0.694 → 1.0.696
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/CMakeLists.txt +3 -0
- package/package.json +1 -1
- package/svf/include/Graphs/CHG.h +4 -1
- package/svf/include/Graphs/GenericGraph.h +5 -0
- package/svf/include/Graphs/ICFG.h +1 -0
- package/svf/include/Graphs/ICFGEdge.h +4 -0
- package/svf/include/Graphs/ICFGNode.h +28 -2
- package/svf/include/Graphs/IRGraph.h +1 -0
- package/svf/include/MemoryModel/LocationSet.h +1 -0
- package/svf/include/MemoryModel/SVFLoop.h +1 -0
- package/svf/include/SVFIR/SVFIR.h +1 -0
- package/svf/include/SVFIR/SVFIRRW.h +864 -186
- package/svf/include/SVFIR/SVFModule.h +1 -0
- package/svf/include/SVFIR/SVFModuleRW.h +2 -2
- package/svf/include/SVFIR/SVFStatements.h +65 -15
- package/svf/include/SVFIR/SVFType.h +4 -0
- package/svf/include/SVFIR/SVFValue.h +22 -0
- package/svf/include/SVFIR/SVFVariables.h +42 -0
- package/svf/include/SVFIR/SymbolTableInfo.h +17 -1
- package/svf/include/Util/Options.h +1 -0
- package/svf/include/Util/SVFUtil.h +49 -0
- package/svf/include/Util/SparseBitVector.h +2 -0
- package/svf/lib/SVFIR/SVFIRRW.cpp +1509 -127
- package/svf/lib/SVFIR/SVFModuleRW.cpp +6 -6
- package/svf/lib/SVFIR/SymbolTableInfo.cpp +1 -1
- package/svf/lib/Util/Options.cpp +7 -1
- package/svf-llvm/lib/LLVMModule.cpp +1 -1
- package/svf-llvm/lib/SVFIRBuilder.cpp +1 -1
- package/svf-llvm/tools/CMakeLists.txt +1 -0
- package/svf-llvm/tools/LLVM2SVF/CMakeLists.txt +10 -0
- package/svf-llvm/tools/LLVM2SVF/llvm2svf.cpp +72 -0
- package/svf-llvm/tools/WPA/wpa.cpp +17 -14
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
#include "Graphs/CHG.h"
|
|
3
3
|
#include "SVFIR/SVFIR.h"
|
|
4
4
|
#include "Util/CommandLine.h"
|
|
5
|
+
#include <sys/fcntl.h>
|
|
6
|
+
#include <sys/mman.h>
|
|
7
|
+
#include <sys/stat.h>
|
|
8
|
+
#include <sys/types.h>
|
|
9
|
+
#include <unistd.h>
|
|
5
10
|
|
|
6
11
|
static const Option<bool> humanReadableOption(
|
|
7
12
|
"human-readable", "Whether to output human-readable JSON", true);
|
|
@@ -9,6 +14,95 @@ static const Option<bool> humanReadableOption(
|
|
|
9
14
|
namespace SVF
|
|
10
15
|
{
|
|
11
16
|
|
|
17
|
+
SVFType* createSVFType(SVFType::GNodeK kind, bool isSingleValTy)
|
|
18
|
+
{
|
|
19
|
+
switch (kind)
|
|
20
|
+
{
|
|
21
|
+
default:
|
|
22
|
+
ABORT_MSG(kind << " is an impossible SVFTyKind in create()");
|
|
23
|
+
case SVFType::SVFTy:
|
|
24
|
+
ABORT_MSG("Creation of RAW SVFType isn't allowed");
|
|
25
|
+
case SVFType::SVFPointerTy:
|
|
26
|
+
ABORT_IFNOT(isSingleValTy, "Pointer type must be single-valued");
|
|
27
|
+
return new SVFPointerType(nullptr);
|
|
28
|
+
case SVFType::SVFIntegerTy:
|
|
29
|
+
ABORT_IFNOT(isSingleValTy, "Integer type must be single-valued");
|
|
30
|
+
return new SVFIntegerType();
|
|
31
|
+
case SVFType::SVFFunctionTy:
|
|
32
|
+
ABORT_IFNOT(!isSingleValTy, "Function type must be multi-valued");
|
|
33
|
+
return new SVFFunctionType(nullptr);
|
|
34
|
+
case SVFType::SVFStructTy:
|
|
35
|
+
ABORT_IFNOT(!isSingleValTy, "Struct type must be multi-valued");
|
|
36
|
+
return new SVFStructType();
|
|
37
|
+
case SVFType::SVFArrayTy:
|
|
38
|
+
ABORT_IFNOT(!isSingleValTy, "Array type must be multi-valued");
|
|
39
|
+
return new SVFArrayType();
|
|
40
|
+
case SVFType::SVFOtherTy:
|
|
41
|
+
return new SVFOtherType(isSingleValTy);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static SVFValue* createSVFValue(SVFValue::GNodeK kind, const SVFType* type,
|
|
46
|
+
const std::string& name)
|
|
47
|
+
{
|
|
48
|
+
switch (kind)
|
|
49
|
+
{
|
|
50
|
+
default:
|
|
51
|
+
ABORT_MSG(kind << " is an impossible SVFValueKind in create()");
|
|
52
|
+
case SVFValue::SVFVal:
|
|
53
|
+
ABORT_MSG("Creation of RAW SVFValue isn't allowed");
|
|
54
|
+
case SVFValue::SVFFunc:
|
|
55
|
+
return new SVFFunction(name, type, {}, {}, {}, {}, {}, {});
|
|
56
|
+
case SVFValue::SVFBB:
|
|
57
|
+
return new SVFBasicBlock(name, type, {});
|
|
58
|
+
case SVFValue::SVFInst:
|
|
59
|
+
return new SVFInstruction(name, type, {}, {}, {});
|
|
60
|
+
case SVFValue::SVFCall:
|
|
61
|
+
return new SVFCallInst(name, type, {}, {}, {});
|
|
62
|
+
case SVFValue::SVFVCall:
|
|
63
|
+
return new SVFVirtualCallInst(name, type, {}, {}, {});
|
|
64
|
+
case SVFValue::SVFGlob:
|
|
65
|
+
return new SVFGlobalValue(name, type);
|
|
66
|
+
case SVFValue::SVFArg:
|
|
67
|
+
return new SVFArgument(name, type, {}, {}, {});
|
|
68
|
+
case SVFValue::SVFConst:
|
|
69
|
+
return new SVFConstant(name, type);
|
|
70
|
+
case SVFValue::SVFConstData:
|
|
71
|
+
return new SVFConstantData(name, type);
|
|
72
|
+
case SVFValue::SVFConstInt:
|
|
73
|
+
return new SVFConstantInt(name, type, {}, {});
|
|
74
|
+
case SVFValue::SVFConstFP:
|
|
75
|
+
return new SVFConstantFP(name, type, {});
|
|
76
|
+
case SVFValue::SVFNullPtr:
|
|
77
|
+
return new SVFConstantNullPtr(name, type);
|
|
78
|
+
case SVFValue::SVFBlackHole:
|
|
79
|
+
return new SVFBlackHoleValue(name, type);
|
|
80
|
+
case SVFValue::SVFMetaAsValue:
|
|
81
|
+
return new SVFMetadataAsValue(name, type);
|
|
82
|
+
case SVFValue::SVFOther:
|
|
83
|
+
return new SVFOtherValue(name, type);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
template <typename SmallNumberType>
|
|
88
|
+
static inline void readSmallNumber(const cJSON* obj, SmallNumberType& val)
|
|
89
|
+
{
|
|
90
|
+
val = static_cast<SmallNumberType>(jsonGetNumber(obj));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
template <typename BigNumberType, typename CStrToVal>
|
|
94
|
+
static inline void readBigNumber(const cJSON* obj, BigNumberType& val, CStrToVal conv)
|
|
95
|
+
{
|
|
96
|
+
ABORT_IFNOT(jsonIsString(obj),
|
|
97
|
+
"Expect (number) string JSON for " << JSON_KEY(obj));
|
|
98
|
+
val = conv(obj->valuestring);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
cJSON* SVFIRWriter::toJson(bool flag)
|
|
102
|
+
{
|
|
103
|
+
return jsonCreateBool(flag);
|
|
104
|
+
}
|
|
105
|
+
|
|
12
106
|
cJSON* SVFIRWriter::toJson(unsigned number)
|
|
13
107
|
{
|
|
14
108
|
// OK, double precision enough
|
|
@@ -21,6 +115,11 @@ cJSON* SVFIRWriter::toJson(int number)
|
|
|
21
115
|
return jsonCreateNumber(number);
|
|
22
116
|
}
|
|
23
117
|
|
|
118
|
+
cJSON* SVFIRWriter::toJson(const std::string& str)
|
|
119
|
+
{
|
|
120
|
+
return jsonCreateString(str.c_str());
|
|
121
|
+
}
|
|
122
|
+
|
|
24
123
|
cJSON* SVFIRWriter::toJson(float number)
|
|
25
124
|
{
|
|
26
125
|
return jsonCreateNumber(number);
|
|
@@ -53,7 +152,7 @@ cJSON* SVFIRWriter::virtToJson(const SVFType* type)
|
|
|
53
152
|
|
|
54
153
|
#define CASE(Kind) \
|
|
55
154
|
case SVFType::Kind: \
|
|
56
|
-
return contentToJson(
|
|
155
|
+
return contentToJson(static_cast<const Kind##pe*>(type))
|
|
57
156
|
|
|
58
157
|
CASE(SVFTy);
|
|
59
158
|
CASE(SVFPointerTy);
|
|
@@ -372,9 +471,9 @@ cJSON* SVFIRWriter::contentToJson(const SVFType* type)
|
|
|
372
471
|
{
|
|
373
472
|
cJSON* root = jsonCreateObject();
|
|
374
473
|
JSON_WRITE_FIELD(root, type, kind);
|
|
474
|
+
JSON_WRITE_FIELD(root, type, isSingleValTy);
|
|
375
475
|
JSON_WRITE_FIELD(root, type, getPointerToTy);
|
|
376
476
|
JSON_WRITE_FIELD(root, type, typeinfo);
|
|
377
|
-
JSON_WRITE_FIELD(root, type, isSingleValTy);
|
|
378
477
|
return root;
|
|
379
478
|
}
|
|
380
479
|
|
|
@@ -416,29 +515,30 @@ cJSON* SVFIRWriter::contentToJson(const SVFValue* value)
|
|
|
416
515
|
{
|
|
417
516
|
cJSON* root = jsonCreateObject();
|
|
418
517
|
JSON_WRITE_FIELD(root, value, kind);
|
|
419
|
-
JSON_WRITE_FIELD(root, value, ptrInUncalledFun);
|
|
420
|
-
JSON_WRITE_FIELD(root, value, constDataOrAggData);
|
|
421
518
|
JSON_WRITE_FIELD(root, value, type);
|
|
422
519
|
JSON_WRITE_FIELD(root, value, name);
|
|
520
|
+
JSON_WRITE_FIELD(root, value, ptrInUncalledFun);
|
|
521
|
+
JSON_WRITE_FIELD(root, value, constDataOrAggData);
|
|
423
522
|
JSON_WRITE_FIELD(root, value, sourceLoc);
|
|
424
|
-
|
|
425
523
|
return root;
|
|
426
524
|
}
|
|
427
525
|
|
|
428
526
|
cJSON* SVFIRWriter::contentToJson(const SVFFunction* value)
|
|
429
527
|
{
|
|
430
528
|
cJSON* root = contentToJson(static_cast<const SVFValue*>(value));
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
529
|
+
#define F(f) JSON_WRITE_FIELD(root, value, f);
|
|
530
|
+
F(isDecl);
|
|
531
|
+
F(intrinsic);
|
|
532
|
+
F(addrTaken);
|
|
533
|
+
F(isUncalled);
|
|
534
|
+
F(isNotRet);
|
|
535
|
+
F(varArg);
|
|
536
|
+
F(funcType);
|
|
537
|
+
F(loopAndDom);
|
|
538
|
+
F(realDefFun);
|
|
539
|
+
F(allBBs);
|
|
540
|
+
F(allArgs);
|
|
541
|
+
#undef F
|
|
442
542
|
return root;
|
|
443
543
|
}
|
|
444
544
|
|
|
@@ -566,35 +666,6 @@ cJSON* SVFIRWriter::contentToJson(const SVFLoop* loop)
|
|
|
566
666
|
return root;
|
|
567
667
|
}
|
|
568
668
|
|
|
569
|
-
cJSON* SVFIRWriter::contentToJson(const SymbolTableInfo* symTable)
|
|
570
|
-
{
|
|
571
|
-
// Owns values of objMap & svfTypes (?)
|
|
572
|
-
cJSON* root = jsonCreateObject();
|
|
573
|
-
JSON_WRITE_FIELD(root, symTable, valSymMap);
|
|
574
|
-
JSON_WRITE_FIELD(root, symTable, objSymMap);
|
|
575
|
-
JSON_WRITE_FIELD(root, symTable, returnSymMap);
|
|
576
|
-
JSON_WRITE_FIELD(root, symTable, varargSymMap);
|
|
577
|
-
|
|
578
|
-
// objMap
|
|
579
|
-
cJSON* objMap = jsonCreateMap();
|
|
580
|
-
for (const auto &pair : symTable->objMap)
|
|
581
|
-
{
|
|
582
|
-
SymID id = pair.first;
|
|
583
|
-
const MemObj* memObj = pair.second;
|
|
584
|
-
|
|
585
|
-
cJSON* keyJson = toJson(id);
|
|
586
|
-
cJSON* valueJson = contentToJson(memObj);
|
|
587
|
-
jsonAddPairToMap(objMap, keyJson, valueJson);
|
|
588
|
-
}
|
|
589
|
-
jsonAddItemToObject(root, "objMap", objMap);
|
|
590
|
-
|
|
591
|
-
// TODO: Check symTable->module == module
|
|
592
|
-
JSON_WRITE_FIELD(root, symTable, modelConstants);
|
|
593
|
-
JSON_WRITE_FIELD(root, symTable, totalSymNum);
|
|
594
|
-
JSON_WRITE_FIELD(root, symTable, svfTypes);
|
|
595
|
-
return root;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
669
|
cJSON* SVFIRWriter::contentToJson(const AssignStmt* edge)
|
|
599
670
|
{
|
|
600
671
|
return contentToJson(static_cast<const SVFStmt*>(edge));
|
|
@@ -717,15 +788,45 @@ bool jsonAddStringToObject(cJSON* obj, const char* name, const char* str)
|
|
|
717
788
|
return jsonAddItemToObject(obj, name, node);
|
|
718
789
|
}
|
|
719
790
|
|
|
720
|
-
bool jsonAddStringToObject(cJSON* obj, const char* name, const std::string&
|
|
791
|
+
bool jsonAddStringToObject(cJSON* obj, const char* name, const std::string& s)
|
|
721
792
|
{
|
|
722
|
-
return jsonAddStringToObject(obj, name,
|
|
793
|
+
return jsonAddStringToObject(obj, name, s.c_str());
|
|
723
794
|
}
|
|
724
795
|
|
|
725
|
-
cJSON*
|
|
796
|
+
bool jsonIsBool(const cJSON* item)
|
|
726
797
|
{
|
|
727
|
-
|
|
728
|
-
|
|
798
|
+
return humanReadableOption()
|
|
799
|
+
? cJSON_IsBool(item)
|
|
800
|
+
: cJSON_IsNumber(item) &&
|
|
801
|
+
(item->valuedouble == 0 || item->valuedouble == 1);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
bool jsonIsBool(const cJSON* item, bool& flag)
|
|
805
|
+
{
|
|
806
|
+
if (humanReadableOption())
|
|
807
|
+
{
|
|
808
|
+
if (!cJSON_IsBool(item))
|
|
809
|
+
return false;
|
|
810
|
+
flag = cJSON_IsTrue(item);
|
|
811
|
+
return true;
|
|
812
|
+
}
|
|
813
|
+
else
|
|
814
|
+
{
|
|
815
|
+
if (!cJSON_IsNumber(item))
|
|
816
|
+
return false;
|
|
817
|
+
flag = item->valuedouble == 1;
|
|
818
|
+
return true;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
bool jsonIsNumber(const cJSON* item)
|
|
823
|
+
{
|
|
824
|
+
return cJSON_IsNumber(item);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
bool jsonIsString(const cJSON* item)
|
|
828
|
+
{
|
|
829
|
+
return cJSON_IsString(item);
|
|
729
830
|
}
|
|
730
831
|
|
|
731
832
|
bool jsonIsNullId(const cJSON* item)
|
|
@@ -734,6 +835,49 @@ bool jsonIsNullId(const cJSON* item)
|
|
|
734
835
|
return cJSON_IsNull(item);
|
|
735
836
|
}
|
|
736
837
|
|
|
838
|
+
bool jsonIsArray(const cJSON* item)
|
|
839
|
+
{
|
|
840
|
+
return cJSON_IsArray(item);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
bool jsonIsMap(const cJSON* item)
|
|
844
|
+
{
|
|
845
|
+
return cJSON_IsArray(item);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
bool jsonIsObject(const cJSON* item)
|
|
849
|
+
{
|
|
850
|
+
return humanReadableOption() ? cJSON_IsObject(item) : cJSON_IsArray(item);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
bool jsonKeyEquals(const cJSON* item, const char* key)
|
|
854
|
+
{
|
|
855
|
+
return item && !(humanReadableOption() && std::strcmp(item->string, key));
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
std::pair<const cJSON*,const cJSON*> jsonUnpackPair(const cJSON* item)
|
|
859
|
+
{
|
|
860
|
+
ABORT_IFNOT(jsonIsArray(item), "Expected array as pair");
|
|
861
|
+
cJSON* child1 = item->child;
|
|
862
|
+
ABORT_IFNOT(child1, "Missing first child of pair");
|
|
863
|
+
cJSON* child2 = child1->next;
|
|
864
|
+
ABORT_IFNOT(child2, "Missing first child of pair");
|
|
865
|
+
ABORT_IFNOT(!child2->next, "Pair has more than two children");
|
|
866
|
+
return {child1, child2};
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
double jsonGetNumber(const cJSON* item)
|
|
870
|
+
{
|
|
871
|
+
ABORT_IFNOT(jsonIsNumber(item), "Expected number for " << JSON_KEY(item));
|
|
872
|
+
return item->valuedouble;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
cJSON* jsonCreateNullId()
|
|
876
|
+
{
|
|
877
|
+
// TODO: optimize
|
|
878
|
+
return cJSON_CreateNull();
|
|
879
|
+
}
|
|
880
|
+
|
|
737
881
|
cJSON* jsonCreateObject()
|
|
738
882
|
{
|
|
739
883
|
return humanReadableOption() ? cJSON_CreateObject() : cJSON_CreateArray();
|
|
@@ -763,6 +907,12 @@ cJSON* jsonCreateIndex(size_t index)
|
|
|
763
907
|
return cJSON_CreateNumber(index);
|
|
764
908
|
}
|
|
765
909
|
|
|
910
|
+
cJSON* jsonCreateBool(bool flag)
|
|
911
|
+
{
|
|
912
|
+
bool hr = humanReadableOption();
|
|
913
|
+
return hr ? cJSON_CreateBool(flag) : cJSON_CreateNumber(flag);
|
|
914
|
+
}
|
|
915
|
+
|
|
766
916
|
cJSON* jsonCreateNumber(double num)
|
|
767
917
|
{
|
|
768
918
|
return cJSON_CreateNumber(num);
|
|
@@ -799,40 +949,34 @@ ICFGWriter::ICFGWriter(const ICFG* icfg) : GenericICFGWriter(icfg)
|
|
|
799
949
|
}
|
|
800
950
|
}
|
|
801
951
|
|
|
802
|
-
|
|
803
|
-
{
|
|
804
|
-
auto it = memObjToID.find(memObj);
|
|
805
|
-
assert(it != memObjToID.end() && "MemObj not found!");
|
|
806
|
-
return it->second;
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
SymbolTableInfoWriter::SymbolTableInfoWriter(const SymbolTableInfo* symTab)
|
|
810
|
-
: symbolTableInfo(symTab)
|
|
952
|
+
SVFModuleWriter::SVFModuleWriter(const SVFModule* svfModule)
|
|
811
953
|
{
|
|
812
|
-
|
|
954
|
+
// TODO: SVFType & StInfo are managed by SymbolTableInfo. Refactor it?
|
|
955
|
+
auto symTab = SymbolTableInfo::SymbolInfo();
|
|
813
956
|
|
|
814
|
-
|
|
957
|
+
const auto& svfTypes = symTab->getSVFTypes();
|
|
958
|
+
svfTypePool.reserve(svfTypes.size());
|
|
959
|
+
for (const SVFType* type : svfTypes)
|
|
815
960
|
{
|
|
816
|
-
|
|
817
|
-
const MemObj* obj = pair.second;
|
|
818
|
-
memObjToID.emplace(obj, id);
|
|
961
|
+
svfTypePool.saveID(type);
|
|
819
962
|
}
|
|
820
|
-
}
|
|
821
963
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
964
|
+
const auto& stInfos = symTab->getStInfos();
|
|
965
|
+
stInfoPool.reserve(stInfos.size());
|
|
966
|
+
for (const StInfo* stInfo : stInfos)
|
|
967
|
+
{
|
|
968
|
+
stInfoPool.saveID(stInfo);
|
|
969
|
+
}
|
|
826
970
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
971
|
+
svfValuePool.reserve(svfModule->getFunctionSet().size() +
|
|
972
|
+
svfModule->getConstantSet().size() +
|
|
973
|
+
svfModule->getOtherValueSet().size());
|
|
830
974
|
}
|
|
831
975
|
|
|
832
976
|
SVFIRWriter::SVFIRWriter(const SVFIR* svfir)
|
|
833
|
-
: svfIR(svfir),
|
|
977
|
+
: svfIR(svfir), svfModuleWriter(svfir->svfModule), icfgWriter(svfir->icfg),
|
|
834
978
|
chgWriter(SVFUtil::dyn_cast<CHGraph>(svfir->chgraph)),
|
|
835
|
-
|
|
979
|
+
irGraphWriter(svfir)
|
|
836
980
|
{
|
|
837
981
|
}
|
|
838
982
|
|
|
@@ -877,9 +1021,15 @@ SVFIRWriter::autoCStr SVFIRWriter::generateJsonString()
|
|
|
877
1021
|
|
|
878
1022
|
SVFIRWriter::autoJSON SVFIRWriter::generateJson()
|
|
879
1023
|
{
|
|
880
|
-
|
|
1024
|
+
const IRGraph* const irGraph = svfIR;
|
|
881
1025
|
|
|
1026
|
+
cJSON* root = jsonCreateObject();
|
|
882
1027
|
#define F(field) JSON_WRITE_FIELD(root, svfIR, field)
|
|
1028
|
+
F(svfModule);
|
|
1029
|
+
F(symInfo);
|
|
1030
|
+
F(icfg);
|
|
1031
|
+
F(chgraph);
|
|
1032
|
+
jsonAddJsonableToObject(root, FIELD_NAME_ITEM(irGraph));
|
|
883
1033
|
F(icfgNode2SVFStmtsMap);
|
|
884
1034
|
F(icfgNode2PTASVFStmtsMap);
|
|
885
1035
|
F(GepValObjMap);
|
|
@@ -894,11 +1044,7 @@ SVFIRWriter::autoJSON SVFIRWriter::generateJson()
|
|
|
894
1044
|
F(indCallSiteToFunPtrMap);
|
|
895
1045
|
F(funPtrToCallSitesMap);
|
|
896
1046
|
F(candidatePointers);
|
|
897
|
-
F(icfg);
|
|
898
|
-
F(chgraph);
|
|
899
1047
|
F(callSiteSet);
|
|
900
|
-
|
|
901
|
-
F(svfModule); // Keep this last one
|
|
902
1048
|
#undef F
|
|
903
1049
|
|
|
904
1050
|
return {root, cJSON_Delete};
|
|
@@ -906,12 +1052,12 @@ SVFIRWriter::autoJSON SVFIRWriter::generateJson()
|
|
|
906
1052
|
|
|
907
1053
|
cJSON* SVFIRWriter::toJson(const SVFType* type)
|
|
908
1054
|
{
|
|
909
|
-
return jsonCreateIndex(svfModuleWriter.
|
|
1055
|
+
return jsonCreateIndex(svfModuleWriter.getSVFTypeID(type));
|
|
910
1056
|
}
|
|
911
1057
|
|
|
912
1058
|
cJSON* SVFIRWriter::toJson(const SVFValue* value)
|
|
913
1059
|
{
|
|
914
|
-
return jsonCreateIndex(svfModuleWriter.
|
|
1060
|
+
return jsonCreateIndex(svfModuleWriter.getSVFValueID(value));
|
|
915
1061
|
}
|
|
916
1062
|
|
|
917
1063
|
cJSON* SVFIRWriter::toJson(const IRGraph* graph)
|
|
@@ -926,15 +1072,13 @@ cJSON* SVFIRWriter::toJson(const IRGraph* graph)
|
|
|
926
1072
|
F(nodeNumAfterPAGBuild);
|
|
927
1073
|
F(totalPTAPAGEdge);
|
|
928
1074
|
F(valueToEdgeMap);
|
|
929
|
-
jsonAddContentToObject(root, "symInfo", graph->symInfo);
|
|
930
1075
|
#undef F
|
|
931
1076
|
return root;
|
|
932
1077
|
}
|
|
933
1078
|
|
|
934
1079
|
cJSON* SVFIRWriter::toJson(const SVFVar* var)
|
|
935
1080
|
{
|
|
936
|
-
return var ? jsonCreateIndex(
|
|
937
|
-
: jsonCreateNullId();
|
|
1081
|
+
return var ? jsonCreateIndex(var->getId()) : jsonCreateNullId();
|
|
938
1082
|
}
|
|
939
1083
|
|
|
940
1084
|
cJSON* SVFIRWriter::toJson(const SVFStmt* stmt)
|
|
@@ -944,9 +1088,17 @@ cJSON* SVFIRWriter::toJson(const SVFStmt* stmt)
|
|
|
944
1088
|
|
|
945
1089
|
cJSON* SVFIRWriter::toJson(const ICFG* icfg)
|
|
946
1090
|
{
|
|
947
|
-
cJSON*
|
|
1091
|
+
cJSON* allSvfLoop = jsonCreateArray(); // all indices seen in constructor
|
|
1092
|
+
for (const SVFLoop* svfLoop : icfgWriter.svfLoopPool)
|
|
1093
|
+
{
|
|
1094
|
+
cJSON* svfLoopObj = contentToJson(svfLoop);
|
|
1095
|
+
jsonAddItemToArray(allSvfLoop, svfLoopObj);
|
|
1096
|
+
}
|
|
948
1097
|
|
|
949
1098
|
#define F(field) JSON_WRITE_FIELD(root, icfg, field)
|
|
1099
|
+
cJSON* root = genericGraphToJson(icfg, icfgWriter.edgePool.getPool());
|
|
1100
|
+
jsonAddItemToObject(root, FIELD_NAME_ITEM(allSvfLoop)); // Meta field
|
|
1101
|
+
F(totalICFGNode);
|
|
950
1102
|
F(FunToFunEntryNodeMap);
|
|
951
1103
|
F(FunToFunExitNodeMap);
|
|
952
1104
|
F(CSToCallNodeMap);
|
|
@@ -960,11 +1112,13 @@ cJSON* SVFIRWriter::toJson(const ICFG* icfg)
|
|
|
960
1112
|
|
|
961
1113
|
cJSON* SVFIRWriter::toJson(const ICFGNode* node)
|
|
962
1114
|
{
|
|
963
|
-
|
|
1115
|
+
assert(node && "ICFGNode is null!");
|
|
1116
|
+
return jsonCreateIndex(node->getId());
|
|
964
1117
|
}
|
|
965
1118
|
|
|
966
1119
|
cJSON* SVFIRWriter::toJson(const ICFGEdge* edge)
|
|
967
1120
|
{
|
|
1121
|
+
assert(edge && "ICFGNode is null!");
|
|
968
1122
|
return jsonCreateIndex(icfgWriter.getEdgeID(edge));
|
|
969
1123
|
}
|
|
970
1124
|
|
|
@@ -998,7 +1152,7 @@ cJSON* SVFIRWriter::toJson(const CHGraph* graph)
|
|
|
998
1152
|
|
|
999
1153
|
cJSON* SVFIRWriter::toJson(const CHNode* node)
|
|
1000
1154
|
{
|
|
1001
|
-
return jsonCreateIndex(
|
|
1155
|
+
return jsonCreateIndex(node->getId());
|
|
1002
1156
|
}
|
|
1003
1157
|
|
|
1004
1158
|
cJSON* SVFIRWriter::toJson(const CHEdge* edge)
|
|
@@ -1019,9 +1173,24 @@ cJSON* SVFIRWriter::toJson(const SVFLoop* loop)
|
|
|
1019
1173
|
cJSON* SVFIRWriter::contentToJson(const MemObj* memObj)
|
|
1020
1174
|
{
|
|
1021
1175
|
cJSON* root = jsonCreateObject();
|
|
1022
|
-
JSON_WRITE_FIELD(root, memObj, typeInfo); // Owns this pointer
|
|
1023
|
-
JSON_WRITE_FIELD(root, memObj, refVal);
|
|
1024
1176
|
JSON_WRITE_FIELD(root, memObj, symId);
|
|
1177
|
+
JSON_WRITE_FIELD(root, memObj, typeInfo);
|
|
1178
|
+
JSON_WRITE_FIELD(root, memObj, refVal);
|
|
1179
|
+
return root;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
cJSON* SVFIRWriter::contentToJson(const StInfo* stInfo)
|
|
1183
|
+
{
|
|
1184
|
+
cJSON* root = jsonCreateObject();
|
|
1185
|
+
#define F(field) JSON_WRITE_FIELD(root, stInfo, field)
|
|
1186
|
+
F(stride);
|
|
1187
|
+
F(fldIdxVec);
|
|
1188
|
+
F(elemIdxVec);
|
|
1189
|
+
F(fldIdx2TypeMap);
|
|
1190
|
+
F(finfo);
|
|
1191
|
+
F(numOfFlattenElements);
|
|
1192
|
+
F(flattenElementTypes);
|
|
1193
|
+
#undef F
|
|
1025
1194
|
return root;
|
|
1026
1195
|
}
|
|
1027
1196
|
|
|
@@ -1034,16 +1203,12 @@ cJSON* SVFIRWriter::toJson(const ObjTypeInfo* objTypeInfo)
|
|
|
1034
1203
|
JSON_WRITE_FIELD(root, objTypeInfo, flags);
|
|
1035
1204
|
JSON_WRITE_FIELD(root, objTypeInfo, maxOffsetLimit);
|
|
1036
1205
|
JSON_WRITE_FIELD(root, objTypeInfo, elemNum);
|
|
1037
|
-
JSON_WRITE_FIELD(root, objTypeInfo, type);
|
|
1038
|
-
JSON_WRITE_FIELD(root, objTypeInfo, flags);
|
|
1039
|
-
JSON_WRITE_FIELD(root, objTypeInfo, maxOffsetLimit);
|
|
1040
|
-
JSON_WRITE_FIELD(root, objTypeInfo, elemNum);
|
|
1041
1206
|
return root;
|
|
1042
1207
|
}
|
|
1043
1208
|
|
|
1044
1209
|
cJSON* SVFIRWriter::toJson(const MemObj* memObj)
|
|
1045
1210
|
{
|
|
1046
|
-
return jsonCreateIndex(
|
|
1211
|
+
return jsonCreateIndex(memObj->getId());
|
|
1047
1212
|
}
|
|
1048
1213
|
|
|
1049
1214
|
cJSON* SVFIRWriter::toJson(const SVFLoopAndDomInfo* ldInfo)
|
|
@@ -1059,21 +1224,9 @@ cJSON* SVFIRWriter::toJson(const SVFLoopAndDomInfo* ldInfo)
|
|
|
1059
1224
|
return root;
|
|
1060
1225
|
}
|
|
1061
1226
|
|
|
1062
|
-
cJSON* SVFIRWriter::toJson(const StInfo*
|
|
1227
|
+
cJSON* SVFIRWriter::toJson(const StInfo* stInfo)
|
|
1063
1228
|
{
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
cJSON* root = jsonCreateObject();
|
|
1067
|
-
#define F(field) JSON_WRITE_FIELD(root, type, field)
|
|
1068
|
-
F(fldIdxVec);
|
|
1069
|
-
F(elemIdxVec);
|
|
1070
|
-
F(fldIdx2TypeMap);
|
|
1071
|
-
F(finfo);
|
|
1072
|
-
F(stride);
|
|
1073
|
-
F(numOfFlattenElements);
|
|
1074
|
-
F(flattenElementTypes);
|
|
1075
|
-
#undef F
|
|
1076
|
-
return root;
|
|
1229
|
+
return jsonCreateIndex(svfModuleWriter.getStInfoID(stInfo));
|
|
1077
1230
|
}
|
|
1078
1231
|
|
|
1079
1232
|
cJSON* SVFIRWriter::toJson(const LocationSet& ls)
|
|
@@ -1084,36 +1237,1265 @@ cJSON* SVFIRWriter::toJson(const LocationSet& ls)
|
|
|
1084
1237
|
return root;
|
|
1085
1238
|
}
|
|
1086
1239
|
|
|
1087
|
-
cJSON* SVFIRWriter::toJson(const
|
|
1240
|
+
cJSON* SVFIRWriter::toJson(const SymbolTableInfo* symTable)
|
|
1088
1241
|
{
|
|
1242
|
+
ENSURE_NOT_VISITED(symTable);
|
|
1243
|
+
|
|
1089
1244
|
cJSON* root = jsonCreateObject();
|
|
1245
|
+
cJSON* allMemObj = jsonCreateArray();
|
|
1246
|
+
for (const auto& pair : symTable->objMap)
|
|
1247
|
+
{
|
|
1248
|
+
const MemObj* memObj = pair.second;
|
|
1249
|
+
cJSON* memObjJson = contentToJson(memObj);
|
|
1250
|
+
jsonAddItemToArray(allMemObj, memObjJson);
|
|
1251
|
+
}
|
|
1090
1252
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1253
|
+
#define F(field) JSON_WRITE_FIELD(root, symTable, field)
|
|
1254
|
+
jsonAddItemToObject(root, FIELD_NAME_ITEM(allMemObj)); // Actual field
|
|
1255
|
+
|
|
1256
|
+
F(valSymMap);
|
|
1257
|
+
F(objSymMap);
|
|
1258
|
+
F(returnSymMap);
|
|
1259
|
+
F(varargSymMap);
|
|
1260
|
+
// Field objMap can be represented by allMemObj
|
|
1261
|
+
// Field mod can be represented by svfIR->svfModule. Delete it?
|
|
1262
|
+
assert(symTable->mod == svfIR->svfModule && "SVFModule mismatch!");
|
|
1263
|
+
F(modelConstants);
|
|
1264
|
+
F(totalSymNum);
|
|
1265
|
+
F(maxStruct);
|
|
1266
|
+
F(maxStSize);
|
|
1267
|
+
// Field svfTypes can be represented by svfModuleWriter.svfTypePool
|
|
1268
|
+
// Field stInfos can be represented by svfModuleWriter.stInfoPool
|
|
1269
|
+
#undef F
|
|
1270
|
+
|
|
1271
|
+
return root;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
cJSON* SVFIRWriter::toJson(const SVFModule* module)
|
|
1275
|
+
{
|
|
1276
|
+
cJSON* root = jsonCreateObject();
|
|
1277
|
+
cJSON* allSVFType = jsonCreateArray();
|
|
1278
|
+
cJSON* allStInfo = jsonCreateArray();
|
|
1279
|
+
cJSON* allSVFValue = jsonCreateArray();
|
|
1093
1280
|
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1281
|
+
for (const SVFType* svfType : svfModuleWriter.svfTypePool)
|
|
1282
|
+
{
|
|
1283
|
+
cJSON* svfTypeObj = virtToJson(svfType);
|
|
1284
|
+
jsonAddItemToArray(allSVFType, svfTypeObj);
|
|
1285
|
+
}
|
|
1099
1286
|
|
|
1100
|
-
|
|
1101
|
-
for (size_t i = 1; i <= svfModuleWriter.svfValuePool.size(); ++i)
|
|
1287
|
+
for (const StInfo* stInfo : svfModuleWriter.stInfoPool)
|
|
1102
1288
|
{
|
|
1103
|
-
cJSON*
|
|
1104
|
-
jsonAddItemToArray(
|
|
1289
|
+
cJSON* stInfoObj = contentToJson(stInfo);
|
|
1290
|
+
jsonAddItemToArray(allStInfo, stInfoObj);
|
|
1105
1291
|
}
|
|
1106
|
-
jsonAddItemToObject(root, "values", values);
|
|
1107
1292
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1293
|
+
#define F(field) JSON_WRITE_FIELD(root, module, field)
|
|
1294
|
+
jsonAddItemToObject(root, FIELD_NAME_ITEM(allSVFType)); // Meta field
|
|
1295
|
+
jsonAddItemToObject(root, FIELD_NAME_ITEM(allStInfo)); // Meta field
|
|
1296
|
+
jsonAddItemToObject(root, FIELD_NAME_ITEM(allSVFValue)); // Meta field
|
|
1297
|
+
F(pagReadFromTxt);
|
|
1298
|
+
F(moduleIdentifier);
|
|
1299
|
+
|
|
1300
|
+
F(FunctionSet);
|
|
1301
|
+
F(GlobalSet);
|
|
1302
|
+
F(AliasSet);
|
|
1303
|
+
F(ConstantSet);
|
|
1304
|
+
F(OtherValueSet);
|
|
1305
|
+
#undef F
|
|
1306
|
+
|
|
1307
|
+
for (size_t i = 1; i <= svfModuleWriter.sizeSVFValuePool(); ++i)
|
|
1110
1308
|
{
|
|
1111
|
-
cJSON*
|
|
1112
|
-
jsonAddItemToArray(
|
|
1309
|
+
cJSON* value = virtToJson(svfModuleWriter.getSVFValuePtr(i));
|
|
1310
|
+
jsonAddItemToArray(allSVFValue, value);
|
|
1113
1311
|
}
|
|
1114
|
-
jsonAddItemToObject(root, "types", types);
|
|
1115
1312
|
|
|
1116
1313
|
return root;
|
|
1117
1314
|
}
|
|
1118
1315
|
|
|
1119
|
-
|
|
1316
|
+
SVFIR* SVFIRReader::read(const cJSON* root)
|
|
1317
|
+
{
|
|
1318
|
+
const cJSON* svfirField = createObjs(root);
|
|
1319
|
+
|
|
1320
|
+
SVFIR* svfIR = SVFIR::getPAG(); // SVFIR constructor sets symInfo
|
|
1321
|
+
IRGraph* irGraph = svfIR;
|
|
1322
|
+
|
|
1323
|
+
auto svfModule = new SVFModule();
|
|
1324
|
+
auto icfg = new ICFG();
|
|
1325
|
+
auto chgraph = new CHGraph(svfModule);
|
|
1326
|
+
auto symboTableInfo = SymbolTableInfo::SymbolInfo();
|
|
1327
|
+
|
|
1328
|
+
svfIR->svfModule = svfModule;
|
|
1329
|
+
svfIR->icfg = icfg;
|
|
1330
|
+
svfIR->chgraph = chgraph;
|
|
1331
|
+
|
|
1332
|
+
#define F(field) JSON_READ_FIELD_FWD(svfirField, svfIR, field)
|
|
1333
|
+
readJson(symboTableInfo);
|
|
1334
|
+
readJson(irGraph);
|
|
1335
|
+
readJson(icfg);
|
|
1336
|
+
readJson(chgraph);
|
|
1337
|
+
readJson(svfModule);
|
|
1338
|
+
|
|
1339
|
+
F(icfgNode2SVFStmtsMap);
|
|
1340
|
+
F(icfgNode2PTASVFStmtsMap);
|
|
1341
|
+
F(GepValObjMap);
|
|
1342
|
+
F(GepObjVarMap);
|
|
1343
|
+
F(memToFieldsMap);
|
|
1344
|
+
F(globSVFStmtSet);
|
|
1345
|
+
F(phiNodeMap);
|
|
1346
|
+
F(funArgsListMap);
|
|
1347
|
+
F(callSiteArgsListMap);
|
|
1348
|
+
F(callSiteRetMap);
|
|
1349
|
+
F(funRetMap);
|
|
1350
|
+
F(indCallSiteToFunPtrMap);
|
|
1351
|
+
F(funPtrToCallSitesMap);
|
|
1352
|
+
F(candidatePointers);
|
|
1353
|
+
F(callSiteSet);
|
|
1354
|
+
#undef F
|
|
1355
|
+
|
|
1356
|
+
return svfIR;
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
const cJSON* SVFIRReader::createObjs(const cJSON* root)
|
|
1360
|
+
{
|
|
1361
|
+
#define READ_CREATE_NODE_FWD(GType) \
|
|
1362
|
+
[](const cJSON*& nodeJson) { \
|
|
1363
|
+
JSON_DEF_READ_FWD(nodeJson, NodeID, id); \
|
|
1364
|
+
JSON_DEF_READ_FWD(nodeJson, GNodeK, nodeKind); \
|
|
1365
|
+
return std::make_pair(id, create##GType##Node(id, nodeKind)); \
|
|
1366
|
+
}
|
|
1367
|
+
#define READ_CREATE_EDGE_FWD(GType) \
|
|
1368
|
+
[](const cJSON*& edgeJson) { \
|
|
1369
|
+
JSON_DEF_READ_FWD(edgeJson, GEdgeFlag, edgeFlag); \
|
|
1370
|
+
auto kind = applyEdgeMask(edgeFlag); \
|
|
1371
|
+
auto edge = create##GType##Edge(kind); \
|
|
1372
|
+
setEdgeFlag(edge, edgeFlag); \
|
|
1373
|
+
return edge; \
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
ABORT_IFNOT(jsonIsObject(root), "Root should be an object");
|
|
1377
|
+
|
|
1378
|
+
const cJSON* const svfModule = root->child;
|
|
1379
|
+
CHECK_JSON_KEY(svfModule);
|
|
1380
|
+
svfModuleReader.createObjs(
|
|
1381
|
+
svfModule,
|
|
1382
|
+
// SVFType Creator
|
|
1383
|
+
[](const cJSON*& svfTypeFldJson)
|
|
1384
|
+
{
|
|
1385
|
+
JSON_DEF_READ_FWD(svfTypeFldJson, SVFType::GNodeK, kind);
|
|
1386
|
+
JSON_DEF_READ_FWD(svfTypeFldJson, bool, isSingleValTy);
|
|
1387
|
+
return createSVFType(kind, isSingleValTy);
|
|
1388
|
+
},
|
|
1389
|
+
// SVFType Filler
|
|
1390
|
+
[this](const cJSON*& svfVarFldJson, SVFType* type)
|
|
1391
|
+
{
|
|
1392
|
+
virtFill(svfVarFldJson, type);
|
|
1393
|
+
},
|
|
1394
|
+
// SVFValue Creator
|
|
1395
|
+
[this](const cJSON*& svfValueFldJson)
|
|
1396
|
+
{
|
|
1397
|
+
JSON_DEF_READ_FWD(svfValueFldJson, SVFValue::GNodeK, kind);
|
|
1398
|
+
JSON_DEF_READ_FWD(svfValueFldJson, const SVFType*, type, {});
|
|
1399
|
+
JSON_DEF_READ_FWD(svfValueFldJson, std::string, name);
|
|
1400
|
+
return createSVFValue(kind, type, name);
|
|
1401
|
+
},
|
|
1402
|
+
// SVFValue Filler
|
|
1403
|
+
[this](const cJSON*& svfVarFldJson, SVFValue* value)
|
|
1404
|
+
{
|
|
1405
|
+
virtFill(svfVarFldJson, value);
|
|
1406
|
+
},
|
|
1407
|
+
// StInfo Creator (no filler needed)
|
|
1408
|
+
[this](const cJSON*& stInfoFldJson)
|
|
1409
|
+
{
|
|
1410
|
+
JSON_DEF_READ_FWD(stInfoFldJson, u32_t, stride);
|
|
1411
|
+
auto si = new StInfo(stride);
|
|
1412
|
+
fill(stInfoFldJson, si);
|
|
1413
|
+
ABORT_IFNOT(!stInfoFldJson, "StInfo has extra field");
|
|
1414
|
+
return si;
|
|
1415
|
+
});
|
|
1416
|
+
|
|
1417
|
+
const cJSON* const symInfo = svfModule->next;
|
|
1418
|
+
CHECK_JSON_KEY(symInfo);
|
|
1419
|
+
symTableReader.createObjs(
|
|
1420
|
+
symInfo,
|
|
1421
|
+
// MemObj Creator (no filler needed)
|
|
1422
|
+
[this](const cJSON*& memObjFldJson)
|
|
1423
|
+
{
|
|
1424
|
+
JSON_DEF_READ_FWD(memObjFldJson, SymID, symId);
|
|
1425
|
+
JSON_DEF_READ_FWD(memObjFldJson, ObjTypeInfo*, typeInfo, {});
|
|
1426
|
+
JSON_DEF_READ_FWD(memObjFldJson, const SVFValue*, refVal, {});
|
|
1427
|
+
return std::make_pair(symId, new MemObj(symId, typeInfo, refVal));
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1430
|
+
const cJSON* const icfg = symInfo->next;
|
|
1431
|
+
CHECK_JSON_KEY(icfg);
|
|
1432
|
+
icfgReader.createObjs(icfg, READ_CREATE_NODE_FWD(ICFG),
|
|
1433
|
+
READ_CREATE_EDGE_FWD(ICFG),
|
|
1434
|
+
[](auto)
|
|
1435
|
+
{
|
|
1436
|
+
return new SVFLoop({}, 0);
|
|
1437
|
+
});
|
|
1438
|
+
|
|
1439
|
+
const cJSON* const chgraph = icfg->next;
|
|
1440
|
+
CHECK_JSON_KEY(chgraph);
|
|
1441
|
+
chGraphReader.createObjs(chgraph, READ_CREATE_NODE_FWD(CH),
|
|
1442
|
+
READ_CREATE_EDGE_FWD(CH));
|
|
1443
|
+
|
|
1444
|
+
const cJSON* const irGraph = chgraph->next;
|
|
1445
|
+
CHECK_JSON_KEY(irGraph);
|
|
1446
|
+
irGraphReader.createObjs(irGraph, READ_CREATE_NODE_FWD(PAG),
|
|
1447
|
+
READ_CREATE_EDGE_FWD(PAG));
|
|
1448
|
+
|
|
1449
|
+
icfgReader.fillObjs(
|
|
1450
|
+
[this](const cJSON*& j, ICFGNode* node)
|
|
1451
|
+
{
|
|
1452
|
+
virtFill(j, node);
|
|
1453
|
+
},
|
|
1454
|
+
[this](const cJSON*& j, ICFGEdge* edge)
|
|
1455
|
+
{
|
|
1456
|
+
virtFill(j, edge);
|
|
1457
|
+
},
|
|
1458
|
+
[this](const cJSON*& j, SVFLoop* loop)
|
|
1459
|
+
{
|
|
1460
|
+
fill(j, loop);
|
|
1461
|
+
});
|
|
1462
|
+
chGraphReader.fillObjs(
|
|
1463
|
+
[this](const cJSON*& j, CHNode* node)
|
|
1464
|
+
{
|
|
1465
|
+
virtFill(j, node);
|
|
1466
|
+
},
|
|
1467
|
+
[this](const cJSON*& j, CHEdge* edge)
|
|
1468
|
+
{
|
|
1469
|
+
virtFill(j, edge);
|
|
1470
|
+
});
|
|
1471
|
+
irGraphReader.fillObjs(
|
|
1472
|
+
[this](const cJSON*& j, SVFVar* var)
|
|
1473
|
+
{
|
|
1474
|
+
virtFill(j, var);
|
|
1475
|
+
},
|
|
1476
|
+
[this](const cJSON*& j, SVFStmt* stmt)
|
|
1477
|
+
{
|
|
1478
|
+
virtFill(j, stmt);
|
|
1479
|
+
});
|
|
1480
|
+
|
|
1481
|
+
return irGraph->next;
|
|
1482
|
+
|
|
1483
|
+
#undef READ_CREATE_EDGE_FWD
|
|
1484
|
+
#undef READ_CREATE_NODE_FWD
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
void SVFIRReader::readJson(const cJSON* obj, bool& flag)
|
|
1488
|
+
{
|
|
1489
|
+
ABORT_IFNOT(jsonIsBool(obj, flag), "Expect bool for " << obj->string);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
void SVFIRReader::readJson(const cJSON* obj, unsigned& val)
|
|
1493
|
+
{
|
|
1494
|
+
readSmallNumber(obj, val);
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
void SVFIRReader::readJson(const cJSON* obj, int& val)
|
|
1498
|
+
{
|
|
1499
|
+
readSmallNumber(obj, val);
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
void SVFIRReader::readJson(const cJSON* obj, float& val)
|
|
1503
|
+
{
|
|
1504
|
+
readSmallNumber(obj, val);
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
void SVFIRReader::readJson(const cJSON* obj, unsigned long& val)
|
|
1508
|
+
{
|
|
1509
|
+
readBigNumber(obj, val,
|
|
1510
|
+
[](const char* s)
|
|
1511
|
+
{
|
|
1512
|
+
return std::strtoul(s, nullptr, 10);
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
void SVFIRReader::readJson(const cJSON* obj, long long& val)
|
|
1517
|
+
{
|
|
1518
|
+
readBigNumber(obj, val,
|
|
1519
|
+
[](const char* s)
|
|
1520
|
+
{
|
|
1521
|
+
return std::strtoll(s, nullptr, 10);
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
void SVFIRReader::readJson(const cJSON* obj, unsigned long long& val)
|
|
1526
|
+
{
|
|
1527
|
+
readBigNumber(obj, val,
|
|
1528
|
+
[](const char* s)
|
|
1529
|
+
{
|
|
1530
|
+
return std::strtoull(s, nullptr, 10);
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
void SVFIRReader::readJson(const cJSON* obj, std::string& str)
|
|
1535
|
+
{
|
|
1536
|
+
ABORT_IFNOT(jsonIsString(obj), "Expect string for " << obj->string);
|
|
1537
|
+
str = obj->valuestring;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
ICFGNode* SVFIRReader::createICFGNode(NodeID id, GNodeK kind)
|
|
1541
|
+
{
|
|
1542
|
+
switch (kind)
|
|
1543
|
+
{
|
|
1544
|
+
default:
|
|
1545
|
+
ABORT_MSG(kind << " is an impossible ICFGNodeKind in create()");
|
|
1546
|
+
#define CASE(kind, constructor) \
|
|
1547
|
+
case ICFGNode::kind: \
|
|
1548
|
+
return new constructor(id);
|
|
1549
|
+
CASE(IntraBlock, IntraICFGNode);
|
|
1550
|
+
CASE(FunEntryBlock, FunEntryICFGNode);
|
|
1551
|
+
CASE(FunExitBlock, FunExitICFGNode);
|
|
1552
|
+
CASE(FunCallBlock, CallICFGNode);
|
|
1553
|
+
CASE(FunRetBlock, RetICFGNode);
|
|
1554
|
+
CASE(GlobalBlock, GlobalICFGNode);
|
|
1555
|
+
#undef CASE
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
ICFGEdge* SVFIRReader::createICFGEdge(GEdgeKind kind)
|
|
1560
|
+
{
|
|
1561
|
+
constexpr ICFGNode* src = nullptr;
|
|
1562
|
+
constexpr ICFGNode* dst = nullptr;
|
|
1563
|
+
|
|
1564
|
+
switch (kind)
|
|
1565
|
+
{
|
|
1566
|
+
default:
|
|
1567
|
+
ABORT_MSG(kind << " is an impossible ICFGEdgeKind in create()");
|
|
1568
|
+
case ICFGEdge::IntraCF:
|
|
1569
|
+
return new IntraCFGEdge(src, dst);
|
|
1570
|
+
case ICFGEdge::CallCF:
|
|
1571
|
+
return new CallCFGEdge(src, dst, nullptr);
|
|
1572
|
+
case ICFGEdge::RetCF:
|
|
1573
|
+
return new RetCFGEdge(src, dst, nullptr);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
CHNode* SVFIRReader::createCHNode(NodeID id, GNodeK kind)
|
|
1578
|
+
{
|
|
1579
|
+
ABORT_IFNOT(kind == 0, "Impossible CHNode kind " << kind);
|
|
1580
|
+
return new CHNode("", id);
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
CHEdge* SVFIRReader::createCHEdge(GEdgeKind kind)
|
|
1584
|
+
{
|
|
1585
|
+
ABORT_IFNOT(kind == 0, "Unsupported CHEdge kind " << kind);
|
|
1586
|
+
return new CHEdge(nullptr, nullptr, {});
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
SVFVar* SVFIRReader::createPAGNode(NodeID id, GNodeK kind)
|
|
1590
|
+
{
|
|
1591
|
+
switch (kind)
|
|
1592
|
+
{
|
|
1593
|
+
default:
|
|
1594
|
+
ABORT_MSG(kind << " is an impossible SVFVarKind in create()");
|
|
1595
|
+
#define CASE(kind, constructor) \
|
|
1596
|
+
case SVFVar::kind: \
|
|
1597
|
+
return new constructor(id);
|
|
1598
|
+
CASE(ValNode, ValVar);
|
|
1599
|
+
CASE(RetNode, RetPN);
|
|
1600
|
+
CASE(ObjNode, ObjVar);
|
|
1601
|
+
CASE(VarargNode, VarArgPN);
|
|
1602
|
+
CASE(GepValNode, GepValVar);
|
|
1603
|
+
CASE(GepObjNode, GepObjVar);
|
|
1604
|
+
CASE(FIObjNode, FIObjVar);
|
|
1605
|
+
CASE(DummyValNode, DummyValVar);
|
|
1606
|
+
CASE(DummyObjNode, DummyObjVar);
|
|
1607
|
+
#undef CASE
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
SVFStmt* SVFIRReader::createPAGEdge(GEdgeKind kind)
|
|
1612
|
+
{
|
|
1613
|
+
switch (kind)
|
|
1614
|
+
{
|
|
1615
|
+
default:
|
|
1616
|
+
ABORT_MSG(kind << " is an impossible SVFStmtKind in create()");
|
|
1617
|
+
#define CASE(kind, constructor) \
|
|
1618
|
+
case SVFStmt::kind: \
|
|
1619
|
+
return new constructor;
|
|
1620
|
+
CASE(Addr, AddrStmt);
|
|
1621
|
+
CASE(Copy, CopyStmt);
|
|
1622
|
+
CASE(Store, StoreStmt);
|
|
1623
|
+
CASE(Load, LoadStmt);
|
|
1624
|
+
CASE(Call, CallPE);
|
|
1625
|
+
CASE(Ret, RetPE);
|
|
1626
|
+
CASE(Gep, GepStmt);
|
|
1627
|
+
CASE(Phi, PhiStmt);
|
|
1628
|
+
CASE(Select, SelectStmt);
|
|
1629
|
+
CASE(Cmp, CmpStmt);
|
|
1630
|
+
CASE(BinaryOp, BinaryOPStmt);
|
|
1631
|
+
CASE(UnaryOp, UnaryOPStmt);
|
|
1632
|
+
CASE(Branch, BranchStmt);
|
|
1633
|
+
CASE(ThreadFork, TDForkPE);
|
|
1634
|
+
CASE(ThreadJoin, TDJoinPE);
|
|
1635
|
+
#undef CASE
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
void SVFIRReader::readJson(SymbolTableInfo*& symTabInfo)
|
|
1640
|
+
{
|
|
1641
|
+
const cJSON* obj = symTableReader.getFieldJson();
|
|
1642
|
+
#define F(field) JSON_READ_FIELD_FWD(obj, symTabInfo, field)
|
|
1643
|
+
// `allMemObj` was consumed during create & fill phase.
|
|
1644
|
+
F(valSymMap);
|
|
1645
|
+
F(objSymMap);
|
|
1646
|
+
F(returnSymMap);
|
|
1647
|
+
F(varargSymMap);
|
|
1648
|
+
symTableReader.memObjMap.saveToIDToObjMap(symTabInfo->objMap); // objMap
|
|
1649
|
+
F(modelConstants);
|
|
1650
|
+
F(totalSymNum);
|
|
1651
|
+
F(maxStruct);
|
|
1652
|
+
F(maxStSize);
|
|
1653
|
+
#undef F
|
|
1654
|
+
ABORT_IFNOT(!obj, "Extra field " << JSON_KEY(obj) << " in SymbolTableInfo");
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
void SVFIRReader::readJson(IRGraph*& graph)
|
|
1658
|
+
{
|
|
1659
|
+
assert(SymbolTableInfo::symInfo && "SymbolTableInfo should be nonempty");
|
|
1660
|
+
assert(graph->symInfo == SymbolTableInfo::SymbolInfo() && "symInfo differ");
|
|
1661
|
+
|
|
1662
|
+
auto& valToEdgeMap = graph->valueToEdgeMap;
|
|
1663
|
+
valToEdgeMap.clear();
|
|
1664
|
+
|
|
1665
|
+
irGraphReader.saveToGenericGraph(graph);
|
|
1666
|
+
const cJSON* obj = irGraphReader.getFieldJson();
|
|
1667
|
+
#define F(field) JSON_READ_FIELD_FWD(obj, graph, field)
|
|
1668
|
+
// base and symInfo have already been read
|
|
1669
|
+
F(KindToSVFStmtSetMap);
|
|
1670
|
+
F(KindToPTASVFStmtSetMap);
|
|
1671
|
+
F(fromFile);
|
|
1672
|
+
F(nodeNumAfterPAGBuild);
|
|
1673
|
+
F(totalPTAPAGEdge);
|
|
1674
|
+
F(valueToEdgeMap);
|
|
1675
|
+
#undef F
|
|
1676
|
+
|
|
1677
|
+
auto nullit = valToEdgeMap.find(nullptr);
|
|
1678
|
+
ABORT_IFNOT(nullit != valToEdgeMap.end(), "valueToEdgeMap should has key NULL");
|
|
1679
|
+
ABORT_IFNOT(nullit->second.empty(), "valueToEdgeMap[NULL] should be empty");
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
void SVFIRReader::readJson(ICFG*& icfg)
|
|
1683
|
+
{
|
|
1684
|
+
icfgReader.saveToGenericGraph(icfg);
|
|
1685
|
+
const cJSON* obj = icfgReader.getFieldJson();
|
|
1686
|
+
#define F(field) JSON_READ_FIELD_FWD(obj, icfg, field)
|
|
1687
|
+
F(totalICFGNode);
|
|
1688
|
+
F(FunToFunEntryNodeMap);
|
|
1689
|
+
F(FunToFunExitNodeMap);
|
|
1690
|
+
F(CSToCallNodeMap);
|
|
1691
|
+
F(CSToRetNodeMap);
|
|
1692
|
+
F(InstToBlockNodeMap);
|
|
1693
|
+
F(globalBlockNode);
|
|
1694
|
+
F(icfgNodeToSVFLoopVec);
|
|
1695
|
+
#undef F
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
void SVFIRReader::readJson(CHGraph*& graph)
|
|
1699
|
+
{
|
|
1700
|
+
chGraphReader.saveToGenericGraph(graph);
|
|
1701
|
+
const cJSON* obj = chGraphReader.getFieldJson();
|
|
1702
|
+
#define F(field) JSON_READ_FIELD_FWD(obj, graph, field)
|
|
1703
|
+
F(classNum);
|
|
1704
|
+
F(vfID);
|
|
1705
|
+
F(classNameToNodeMap);
|
|
1706
|
+
F(classNameToDescendantsMap);
|
|
1707
|
+
F(classNameToAncestorsMap);
|
|
1708
|
+
F(classNameToInstAndDescsMap);
|
|
1709
|
+
F(templateNameToInstancesMap);
|
|
1710
|
+
F(csToClassesMap);
|
|
1711
|
+
F(virtualFunctionToIDMap);
|
|
1712
|
+
F(csToCHAVtblsMap);
|
|
1713
|
+
F(csToCHAVFnsMap);
|
|
1714
|
+
#undef F
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
void SVFIRReader::readJson(SVFModule*& module)
|
|
1718
|
+
{
|
|
1719
|
+
const cJSON* obj = svfModuleReader.getFieldJson();
|
|
1720
|
+
#define F(field) JSON_READ_FIELD_FWD(obj, module, field)
|
|
1721
|
+
F(pagReadFromTxt);
|
|
1722
|
+
F(moduleIdentifier);
|
|
1723
|
+
F(FunctionSet);
|
|
1724
|
+
F(GlobalSet);
|
|
1725
|
+
F(AliasSet);
|
|
1726
|
+
F(ConstantSet);
|
|
1727
|
+
F(OtherValueSet);
|
|
1728
|
+
#undef F
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
void SVFIRReader::readJson(const cJSON* obj, SVFType*& type)
|
|
1732
|
+
{
|
|
1733
|
+
assert(!type && "SVFType already read?");
|
|
1734
|
+
type = svfModuleReader.getSVFTypePtr(jsonGetNumber(obj));
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
void SVFIRReader::readJson(const cJSON* obj, StInfo*& stInfo)
|
|
1738
|
+
{
|
|
1739
|
+
assert(!stInfo && "StInfo already read?");
|
|
1740
|
+
stInfo = svfModuleReader.getStInfoPtr(jsonGetNumber(obj));
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
void SVFIRReader::readJson(const cJSON* obj, SVFValue*& value)
|
|
1744
|
+
{
|
|
1745
|
+
assert(!value && "SVFValue already read?");
|
|
1746
|
+
value = svfModuleReader.getSVFValuePtr(jsonGetNumber(obj));
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
void SVFIRReader::readJson(const cJSON* obj, SVFVar*& var)
|
|
1750
|
+
{
|
|
1751
|
+
assert(!var && "SVFVar already read?");
|
|
1752
|
+
if (jsonIsNullId(obj))
|
|
1753
|
+
var = nullptr;
|
|
1754
|
+
else
|
|
1755
|
+
var = irGraphReader.getNodePtr(jsonGetNumber(obj));
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
void SVFIRReader::readJson(const cJSON* obj, SVFStmt*& stmt)
|
|
1759
|
+
{
|
|
1760
|
+
assert(!stmt && "SVFStmt already read?");
|
|
1761
|
+
stmt = irGraphReader.getEdgePtr(jsonGetNumber(obj));
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
void SVFIRReader::readJson(const cJSON* obj, ICFGNode*& node)
|
|
1765
|
+
{
|
|
1766
|
+
assert(!node && "ICFGNode already read?");
|
|
1767
|
+
NodeID id = jsonGetNumber(obj);
|
|
1768
|
+
node = icfgReader.getNodePtr(id);
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
void SVFIRReader::readJson(const cJSON* obj, ICFGEdge*& edge)
|
|
1772
|
+
{
|
|
1773
|
+
assert(!edge && "ICFGEdge already read?");
|
|
1774
|
+
edge = icfgReader.getEdgePtr(jsonGetNumber(obj));
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
void SVFIRReader::readJson(const cJSON* obj, CHNode*& node)
|
|
1778
|
+
{
|
|
1779
|
+
assert(!node && "CHNode already read?");
|
|
1780
|
+
node = chGraphReader.getNodePtr(jsonGetNumber(obj));
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
void SVFIRReader::readJson(const cJSON* obj, CHEdge*& edge)
|
|
1784
|
+
{
|
|
1785
|
+
assert(!edge && "CHEdge already read?");
|
|
1786
|
+
edge = chGraphReader.getEdgePtr(jsonGetNumber(obj));
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
void SVFIRReader::readJson(const cJSON* obj, CallSite& cs)
|
|
1790
|
+
{
|
|
1791
|
+
readJson(obj, cs.CB);
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
void SVFIRReader::readJson(const cJSON* obj, LocationSet& ls)
|
|
1795
|
+
{
|
|
1796
|
+
ABORT_IFNOT(jsonIsObject(obj), "Expected obj for LocationSet");
|
|
1797
|
+
obj = obj->child;
|
|
1798
|
+
JSON_READ_FIELD_FWD(obj, &ls, fldIdx);
|
|
1799
|
+
JSON_READ_FIELD_FWD(obj, &ls, offsetVarAndGepTypePairs);
|
|
1800
|
+
ABORT_IFNOT(!obj, "Extra field " << JSON_KEY(obj) << " in LocationSet");
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
void SVFIRReader::readJson(const cJSON* obj, SVFLoop*& loop)
|
|
1804
|
+
{
|
|
1805
|
+
assert(!loop && "SVFLoop already read?");
|
|
1806
|
+
unsigned id = jsonGetNumber(obj);
|
|
1807
|
+
loop = icfgReader.getSVFLoopPtr(id);
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
void SVFIRReader::readJson(const cJSON* obj, MemObj*& memObj)
|
|
1811
|
+
{
|
|
1812
|
+
assert(!memObj && "MemObj already read?");
|
|
1813
|
+
memObj = symTableReader.getMemObjPtr(jsonGetNumber(obj));
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
void SVFIRReader::readJson(const cJSON* obj, ObjTypeInfo*& objTypeInfo)
|
|
1817
|
+
{
|
|
1818
|
+
assert(!objTypeInfo && "ObjTypeInfo already read?");
|
|
1819
|
+
ABORT_IFNOT(jsonIsObject(obj), "Expected object for objTypeInfo");
|
|
1820
|
+
cJSON* field = obj->child;
|
|
1821
|
+
|
|
1822
|
+
JSON_DEF_READ_FWD(field, SVFType*, type, {});
|
|
1823
|
+
JSON_DEF_READ_FWD(field, u32_t, flags);
|
|
1824
|
+
JSON_DEF_READ_FWD(field, u32_t, maxOffsetLimit);
|
|
1825
|
+
JSON_DEF_READ_FWD(field, u32_t, elemNum);
|
|
1826
|
+
|
|
1827
|
+
ABORT_IFNOT(!field, "Extra field in objTypeInfo: " << JSON_KEY(field));
|
|
1828
|
+
objTypeInfo = new ObjTypeInfo(type, maxOffsetLimit);
|
|
1829
|
+
objTypeInfo->flags = flags;
|
|
1830
|
+
objTypeInfo->elemNum = elemNum;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
void SVFIRReader::readJson(const cJSON* obj, SVFLoopAndDomInfo*& ldInfo)
|
|
1834
|
+
{
|
|
1835
|
+
assert(!ldInfo && "SVFLoopAndDomInfo already read?");
|
|
1836
|
+
ABORT_IFNOT(jsonIsObject(obj), "Expected object for SVFLoopAndDomInfo");
|
|
1837
|
+
cJSON* field = obj->child;
|
|
1838
|
+
|
|
1839
|
+
ldInfo = new SVFLoopAndDomInfo();
|
|
1840
|
+
|
|
1841
|
+
JSON_READ_FIELD_FWD(field, ldInfo, reachableBBs);
|
|
1842
|
+
JSON_READ_FIELD_FWD(field, ldInfo, dtBBsMap);
|
|
1843
|
+
JSON_READ_FIELD_FWD(field, ldInfo, pdtBBsMap);
|
|
1844
|
+
JSON_READ_FIELD_FWD(field, ldInfo, dfBBsMap);
|
|
1845
|
+
JSON_READ_FIELD_FWD(field, ldInfo, bb2LoopMap);
|
|
1846
|
+
|
|
1847
|
+
ABORT_IFNOT(!field,
|
|
1848
|
+
"Extra field in SVFLoopAndDomInfo: " << JSON_KEY(field));
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
void SVFIRReader::virtFill(const cJSON*& fieldJson, SVFVar* var)
|
|
1852
|
+
{
|
|
1853
|
+
switch (var->getNodeKind())
|
|
1854
|
+
{
|
|
1855
|
+
default:
|
|
1856
|
+
assert(false && "Unknown SVFVar kind");
|
|
1857
|
+
|
|
1858
|
+
#define CASE(VarKind, VarType) \
|
|
1859
|
+
case SVFVar::VarKind: \
|
|
1860
|
+
return fill(fieldJson, static_cast<VarType*>(var))
|
|
1861
|
+
|
|
1862
|
+
CASE(ValNode, ValVar);
|
|
1863
|
+
CASE(ObjNode, ObjVar);
|
|
1864
|
+
CASE(RetNode, RetPN);
|
|
1865
|
+
CASE(VarargNode, VarArgPN);
|
|
1866
|
+
CASE(GepValNode, GepValVar);
|
|
1867
|
+
CASE(GepObjNode, GepObjVar);
|
|
1868
|
+
CASE(FIObjNode, FIObjVar);
|
|
1869
|
+
CASE(DummyValNode, DummyValVar);
|
|
1870
|
+
CASE(DummyObjNode, DummyObjVar);
|
|
1871
|
+
#undef CASE
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFVar* var)
|
|
1876
|
+
{
|
|
1877
|
+
fill(fieldJson, static_cast<GenericPAGNodeTy*>(var));
|
|
1878
|
+
JSON_READ_FIELD_FWD(fieldJson, var, value);
|
|
1879
|
+
JSON_READ_FIELD_FWD(fieldJson, var, InEdgeKindToSetMap);
|
|
1880
|
+
JSON_READ_FIELD_FWD(fieldJson, var, OutEdgeKindToSetMap);
|
|
1881
|
+
JSON_READ_FIELD_FWD(fieldJson, var, isPtr);
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, ValVar* var)
|
|
1885
|
+
{
|
|
1886
|
+
fill(fieldJson, static_cast<SVFVar*>(var));
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, ObjVar* var)
|
|
1890
|
+
{
|
|
1891
|
+
fill(fieldJson, static_cast<SVFVar*>(var));
|
|
1892
|
+
JSON_READ_FIELD_FWD(fieldJson, var, mem);
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, GepValVar* var)
|
|
1896
|
+
{
|
|
1897
|
+
fill(fieldJson, static_cast<ValVar*>(var));
|
|
1898
|
+
JSON_READ_FIELD_FWD(fieldJson, var, ls);
|
|
1899
|
+
JSON_READ_FIELD_FWD(fieldJson, var, gepValType);
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, GepObjVar* var)
|
|
1903
|
+
{
|
|
1904
|
+
fill(fieldJson, static_cast<ObjVar*>(var));
|
|
1905
|
+
JSON_READ_FIELD_FWD(fieldJson, var, ls);
|
|
1906
|
+
JSON_READ_FIELD_FWD(fieldJson, var, base);
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, FIObjVar* var)
|
|
1910
|
+
{
|
|
1911
|
+
fill(fieldJson, static_cast<ObjVar*>(var));
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, RetPN* var)
|
|
1915
|
+
{
|
|
1916
|
+
fill(fieldJson, static_cast<ValVar*>(var));
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, VarArgPN* var)
|
|
1920
|
+
{
|
|
1921
|
+
fill(fieldJson, static_cast<ValVar*>(var));
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, DummyValVar* var)
|
|
1925
|
+
{
|
|
1926
|
+
fill(fieldJson, static_cast<ValVar*>(var));
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, DummyObjVar* var)
|
|
1930
|
+
{
|
|
1931
|
+
fill(fieldJson, static_cast<ObjVar*>(var));
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
void SVFIRReader::virtFill(const cJSON*& fieldJson, SVFStmt* stmt)
|
|
1935
|
+
{
|
|
1936
|
+
auto kind = stmt->getEdgeKind();
|
|
1937
|
+
|
|
1938
|
+
switch (kind)
|
|
1939
|
+
{
|
|
1940
|
+
default:
|
|
1941
|
+
ABORT_MSG("Unknown SVFStmt kind " << kind);
|
|
1942
|
+
|
|
1943
|
+
#define CASE(EdgeKind, EdgeType) \
|
|
1944
|
+
case SVFStmt::EdgeKind: \
|
|
1945
|
+
return fill(fieldJson, static_cast<EdgeType*>(stmt))
|
|
1946
|
+
|
|
1947
|
+
CASE(Addr, AddrStmt);
|
|
1948
|
+
CASE(Copy, CopyStmt);
|
|
1949
|
+
CASE(Store, StoreStmt);
|
|
1950
|
+
CASE(Load, LoadStmt);
|
|
1951
|
+
CASE(Call, CallPE);
|
|
1952
|
+
CASE(Ret, RetPE);
|
|
1953
|
+
CASE(Gep, GepStmt);
|
|
1954
|
+
CASE(Phi, PhiStmt);
|
|
1955
|
+
CASE(Select, SelectStmt);
|
|
1956
|
+
CASE(Cmp, CmpStmt);
|
|
1957
|
+
CASE(BinaryOp, BinaryOPStmt);
|
|
1958
|
+
CASE(UnaryOp, UnaryOPStmt);
|
|
1959
|
+
CASE(Branch, BranchStmt);
|
|
1960
|
+
CASE(ThreadFork, TDForkPE);
|
|
1961
|
+
CASE(ThreadJoin, TDJoinPE);
|
|
1962
|
+
#undef CASE
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFStmt* stmt)
|
|
1967
|
+
{
|
|
1968
|
+
fill(fieldJson, static_cast<GenericPAGEdgeTy*>(stmt));
|
|
1969
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, value);
|
|
1970
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, basicBlock);
|
|
1971
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, icfgNode);
|
|
1972
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, edgeId);
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, AssignStmt* stmt)
|
|
1976
|
+
{
|
|
1977
|
+
fill(fieldJson, static_cast<SVFStmt*>(stmt));
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, AddrStmt* stmt)
|
|
1981
|
+
{
|
|
1982
|
+
fill(fieldJson, static_cast<AssignStmt*>(stmt));
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, CopyStmt* stmt)
|
|
1986
|
+
{
|
|
1987
|
+
fill(fieldJson, static_cast<AssignStmt*>(stmt));
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, StoreStmt* stmt)
|
|
1991
|
+
{
|
|
1992
|
+
fill(fieldJson, static_cast<AssignStmt*>(stmt));
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, LoadStmt* stmt)
|
|
1996
|
+
{
|
|
1997
|
+
fill(fieldJson, static_cast<AssignStmt*>(stmt));
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, GepStmt* stmt)
|
|
2001
|
+
{
|
|
2002
|
+
fill(fieldJson, static_cast<AssignStmt*>(stmt));
|
|
2003
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, ls);
|
|
2004
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, variantField);
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, CallPE* stmt)
|
|
2008
|
+
{
|
|
2009
|
+
fill(fieldJson, static_cast<AssignStmt*>(stmt));
|
|
2010
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, call);
|
|
2011
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, entry);
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, RetPE* stmt)
|
|
2015
|
+
{
|
|
2016
|
+
fill(fieldJson, static_cast<AssignStmt*>(stmt));
|
|
2017
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, call);
|
|
2018
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, exit);
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, MultiOpndStmt* stmt)
|
|
2022
|
+
{
|
|
2023
|
+
fill(fieldJson, static_cast<SVFStmt*>(stmt));
|
|
2024
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, opVars);
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, PhiStmt* stmt)
|
|
2028
|
+
{
|
|
2029
|
+
fill(fieldJson, static_cast<MultiOpndStmt*>(stmt));
|
|
2030
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, opICFGNodes);
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SelectStmt* stmt)
|
|
2034
|
+
{
|
|
2035
|
+
fill(fieldJson, static_cast<MultiOpndStmt*>(stmt));
|
|
2036
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, condition);
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, CmpStmt* stmt)
|
|
2040
|
+
{
|
|
2041
|
+
fill(fieldJson, static_cast<MultiOpndStmt*>(stmt));
|
|
2042
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, predicate);
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, BinaryOPStmt* stmt)
|
|
2046
|
+
{
|
|
2047
|
+
fill(fieldJson, static_cast<MultiOpndStmt*>(stmt));
|
|
2048
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, opcode);
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, UnaryOPStmt* stmt)
|
|
2052
|
+
{
|
|
2053
|
+
fill(fieldJson, static_cast<SVFStmt*>(stmt));
|
|
2054
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, opcode);
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, BranchStmt* stmt)
|
|
2058
|
+
{
|
|
2059
|
+
fill(fieldJson, static_cast<SVFStmt*>(stmt));
|
|
2060
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, successors);
|
|
2061
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, cond);
|
|
2062
|
+
JSON_READ_FIELD_FWD(fieldJson, stmt, brInst);
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, TDForkPE* stmt)
|
|
2066
|
+
{
|
|
2067
|
+
fill(fieldJson, static_cast<CallPE*>(stmt));
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, TDJoinPE* stmt)
|
|
2071
|
+
{
|
|
2072
|
+
fill(fieldJson, static_cast<RetPE*>(stmt));
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, MemObj* memObj)
|
|
2076
|
+
{
|
|
2077
|
+
// symId has already been read
|
|
2078
|
+
JSON_READ_FIELD_FWD(fieldJson, memObj, typeInfo);
|
|
2079
|
+
JSON_READ_FIELD_FWD(fieldJson, memObj, refVal);
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, StInfo* stInfo)
|
|
2083
|
+
{
|
|
2084
|
+
#define F(field) JSON_READ_FIELD_FWD(fieldJson, stInfo, field)
|
|
2085
|
+
// stride has already been read
|
|
2086
|
+
F(fldIdxVec);
|
|
2087
|
+
F(elemIdxVec);
|
|
2088
|
+
F(fldIdx2TypeMap);
|
|
2089
|
+
F(finfo);
|
|
2090
|
+
F(numOfFlattenElements);
|
|
2091
|
+
F(flattenElementTypes);
|
|
2092
|
+
#undef F
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
void SVFIRReader::virtFill(const cJSON*& fieldJson, ICFGNode* node)
|
|
2096
|
+
{
|
|
2097
|
+
switch (node->getNodeKind())
|
|
2098
|
+
{
|
|
2099
|
+
default:
|
|
2100
|
+
ABORT_MSG("Unknown ICFGNode kind " << node->getNodeKind());
|
|
2101
|
+
|
|
2102
|
+
#define CASE(NodeKind, NodeType) \
|
|
2103
|
+
case ICFGNode::NodeKind: \
|
|
2104
|
+
return fill(fieldJson, static_cast<NodeType*>(node))
|
|
2105
|
+
|
|
2106
|
+
CASE(IntraBlock, IntraICFGNode);
|
|
2107
|
+
CASE(FunEntryBlock, FunEntryICFGNode);
|
|
2108
|
+
CASE(FunExitBlock, FunExitICFGNode);
|
|
2109
|
+
CASE(FunCallBlock, CallICFGNode);
|
|
2110
|
+
CASE(FunRetBlock, RetICFGNode);
|
|
2111
|
+
CASE(GlobalBlock, GlobalICFGNode);
|
|
2112
|
+
#undef CASE
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, ICFGNode* node)
|
|
2117
|
+
{
|
|
2118
|
+
fill(fieldJson, static_cast<GenericICFGNodeTy*>(node));
|
|
2119
|
+
JSON_READ_FIELD_FWD(fieldJson, node, fun);
|
|
2120
|
+
JSON_READ_FIELD_FWD(fieldJson, node, bb);
|
|
2121
|
+
// Skip VFGNodes as it is empty
|
|
2122
|
+
JSON_READ_FIELD_FWD(fieldJson, node, pagEdges);
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, GlobalICFGNode* node)
|
|
2126
|
+
{
|
|
2127
|
+
fill(fieldJson, static_cast<ICFGNode*>(node));
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, IntraICFGNode* node)
|
|
2131
|
+
{
|
|
2132
|
+
fill(fieldJson, static_cast<ICFGNode*>(node));
|
|
2133
|
+
JSON_READ_FIELD_FWD(fieldJson, node, inst);
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, InterICFGNode* node)
|
|
2137
|
+
{
|
|
2138
|
+
fill(fieldJson, static_cast<ICFGNode*>(node));
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, FunEntryICFGNode* node)
|
|
2142
|
+
{
|
|
2143
|
+
fill(fieldJson, static_cast<ICFGNode*>(node));
|
|
2144
|
+
JSON_READ_FIELD_FWD(fieldJson, node, FPNodes);
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, FunExitICFGNode* node)
|
|
2148
|
+
{
|
|
2149
|
+
fill(fieldJson, static_cast<ICFGNode*>(node));
|
|
2150
|
+
JSON_READ_FIELD_FWD(fieldJson, node, formalRet);
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, CallICFGNode* node)
|
|
2154
|
+
{
|
|
2155
|
+
fill(fieldJson, static_cast<ICFGNode*>(node));
|
|
2156
|
+
JSON_READ_FIELD_FWD(fieldJson, node, cs);
|
|
2157
|
+
JSON_READ_FIELD_FWD(fieldJson, node, ret);
|
|
2158
|
+
JSON_READ_FIELD_FWD(fieldJson, node, APNodes);
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, RetICFGNode* node)
|
|
2162
|
+
{
|
|
2163
|
+
fill(fieldJson, static_cast<ICFGNode*>(node));
|
|
2164
|
+
JSON_READ_FIELD_FWD(fieldJson, node, cs);
|
|
2165
|
+
JSON_READ_FIELD_FWD(fieldJson, node, actualRet);
|
|
2166
|
+
JSON_READ_FIELD_FWD(fieldJson, node, callBlockNode);
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
void SVFIRReader::virtFill(const cJSON*& fieldJson, ICFGEdge* edge)
|
|
2170
|
+
{
|
|
2171
|
+
auto kind = edge->getEdgeKind();
|
|
2172
|
+
switch (kind)
|
|
2173
|
+
{
|
|
2174
|
+
default:
|
|
2175
|
+
ABORT_MSG("Unknown ICFGEdge kind " << kind);
|
|
2176
|
+
case ICFGEdge::IntraCF:
|
|
2177
|
+
return fill(fieldJson, static_cast<IntraCFGEdge*>(edge));
|
|
2178
|
+
case ICFGEdge::CallCF:
|
|
2179
|
+
return fill(fieldJson, static_cast<CallCFGEdge*>(edge));
|
|
2180
|
+
case ICFGEdge::RetCF:
|
|
2181
|
+
return fill(fieldJson, static_cast<RetCFGEdge*>(edge));
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, ICFGEdge* edge)
|
|
2186
|
+
{
|
|
2187
|
+
fill(fieldJson, static_cast<GenericICFGEdgeTy*>(edge));
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, IntraCFGEdge* edge)
|
|
2191
|
+
{
|
|
2192
|
+
fill(fieldJson, static_cast<ICFGEdge*>(edge));
|
|
2193
|
+
JSON_READ_FIELD_FWD(fieldJson, edge, conditionVar);
|
|
2194
|
+
JSON_READ_FIELD_FWD(fieldJson, edge, branchCondVal);
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, CallCFGEdge* edge)
|
|
2198
|
+
{
|
|
2199
|
+
fill(fieldJson, static_cast<ICFGEdge*>(edge));
|
|
2200
|
+
JSON_READ_FIELD_FWD(fieldJson, edge, cs);
|
|
2201
|
+
JSON_READ_FIELD_FWD(fieldJson, edge, callPEs);
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, RetCFGEdge* edge)
|
|
2205
|
+
{
|
|
2206
|
+
fill(fieldJson, static_cast<ICFGEdge*>(edge));
|
|
2207
|
+
JSON_READ_FIELD_FWD(fieldJson, edge, cs);
|
|
2208
|
+
JSON_READ_FIELD_FWD(fieldJson, edge, retPE);
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFLoop* loop)
|
|
2212
|
+
{
|
|
2213
|
+
#define F(field) JSON_READ_FIELD_FWD(fieldJson, loop, field)
|
|
2214
|
+
F(entryICFGEdges);
|
|
2215
|
+
F(backICFGEdges);
|
|
2216
|
+
F(inICFGEdges);
|
|
2217
|
+
F(outICFGEdges);
|
|
2218
|
+
F(icfgNodes);
|
|
2219
|
+
F(loopBound);
|
|
2220
|
+
#undef F
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
void SVFIRReader::virtFill(const cJSON*& fieldJson, CHNode* node)
|
|
2224
|
+
{
|
|
2225
|
+
assert(node->getNodeKind() == 0 && "Unknown CHNode kind");
|
|
2226
|
+
fill(fieldJson, static_cast<GenericCHNodeTy*>(node));
|
|
2227
|
+
JSON_READ_FIELD_FWD(fieldJson, node, vtable);
|
|
2228
|
+
JSON_READ_FIELD_FWD(fieldJson, node, className);
|
|
2229
|
+
JSON_READ_FIELD_FWD(fieldJson, node, flags);
|
|
2230
|
+
JSON_READ_FIELD_FWD(fieldJson, node, virtualFunctionVectors);
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
void SVFIRReader::virtFill(const cJSON*& fieldJson, CHEdge* edge)
|
|
2234
|
+
{
|
|
2235
|
+
assert(edge->getEdgeKind() == 0 && "Unknown CHEdge kind");
|
|
2236
|
+
fill(fieldJson, static_cast<GenericCHEdgeTy*>(edge));
|
|
2237
|
+
// edgeType is a enum
|
|
2238
|
+
JSON_DEF_READ_FWD(fieldJson, unsigned, edgeType);
|
|
2239
|
+
if (edgeType == CHEdge::INHERITANCE)
|
|
2240
|
+
edge->edgeType = CHEdge::INHERITANCE;
|
|
2241
|
+
else if (edgeType == CHEdge::INSTANTCE)
|
|
2242
|
+
edge->edgeType = CHEdge::INSTANTCE;
|
|
2243
|
+
else
|
|
2244
|
+
ABORT_MSG("Unknown CHEdge type " << edgeType);
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
void SVFIRReader::virtFill(const cJSON*& fieldJson, SVFValue* value)
|
|
2248
|
+
{
|
|
2249
|
+
auto kind = value->getKind();
|
|
2250
|
+
|
|
2251
|
+
switch (kind)
|
|
2252
|
+
{
|
|
2253
|
+
default:
|
|
2254
|
+
ABORT_MSG("Impossible SVFValue kind " << kind);
|
|
2255
|
+
|
|
2256
|
+
#define CASE(ValueKind, Type) \
|
|
2257
|
+
case SVFValue::ValueKind: \
|
|
2258
|
+
return fill(fieldJson, static_cast<Type*>(value))
|
|
2259
|
+
|
|
2260
|
+
CASE(SVFVal, SVFValue);
|
|
2261
|
+
CASE(SVFFunc, SVFFunction);
|
|
2262
|
+
CASE(SVFBB, SVFBasicBlock);
|
|
2263
|
+
CASE(SVFInst, SVFInstruction);
|
|
2264
|
+
CASE(SVFCall, SVFCallInst);
|
|
2265
|
+
CASE(SVFVCall, SVFVirtualCallInst);
|
|
2266
|
+
CASE(SVFGlob, SVFGlobalValue);
|
|
2267
|
+
CASE(SVFArg, SVFArgument);
|
|
2268
|
+
CASE(SVFConst, SVFConstant);
|
|
2269
|
+
CASE(SVFConstData, SVFConstantData);
|
|
2270
|
+
CASE(SVFConstInt, SVFConstantInt);
|
|
2271
|
+
CASE(SVFConstFP, SVFConstantFP);
|
|
2272
|
+
CASE(SVFNullPtr, SVFConstantNullPtr);
|
|
2273
|
+
CASE(SVFBlackHole, SVFBlackHoleValue);
|
|
2274
|
+
CASE(SVFMetaAsValue, SVFMetadataAsValue);
|
|
2275
|
+
CASE(SVFOther, SVFOtherValue);
|
|
2276
|
+
#undef CASE
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFValue* value)
|
|
2281
|
+
{
|
|
2282
|
+
// kind, type, name have already been read.
|
|
2283
|
+
JSON_READ_FIELD_FWD(fieldJson, value, ptrInUncalledFun);
|
|
2284
|
+
JSON_READ_FIELD_FWD(fieldJson, value, constDataOrAggData);
|
|
2285
|
+
JSON_READ_FIELD_FWD(fieldJson, value, sourceLoc);
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFFunction* value)
|
|
2289
|
+
{
|
|
2290
|
+
fill(fieldJson, static_cast<SVFValue*>(value));
|
|
2291
|
+
#define F(f) JSON_READ_FIELD_FWD(fieldJson, value, f)
|
|
2292
|
+
F(isDecl);
|
|
2293
|
+
F(intrinsic);
|
|
2294
|
+
F(addrTaken);
|
|
2295
|
+
F(isUncalled);
|
|
2296
|
+
F(isNotRet);
|
|
2297
|
+
F(varArg);
|
|
2298
|
+
F(funcType);
|
|
2299
|
+
F(loopAndDom);
|
|
2300
|
+
F(realDefFun);
|
|
2301
|
+
F(allBBs);
|
|
2302
|
+
F(allArgs);
|
|
2303
|
+
#undef F
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFBasicBlock* value)
|
|
2307
|
+
{
|
|
2308
|
+
fill(fieldJson, static_cast<SVFValue*>(value));
|
|
2309
|
+
JSON_READ_FIELD_FWD(fieldJson, value, allInsts);
|
|
2310
|
+
JSON_READ_FIELD_FWD(fieldJson, value, succBBs);
|
|
2311
|
+
JSON_READ_FIELD_FWD(fieldJson, value, predBBs);
|
|
2312
|
+
JSON_READ_FIELD_FWD(fieldJson, value, fun);
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFInstruction* value)
|
|
2316
|
+
{
|
|
2317
|
+
fill(fieldJson, static_cast<SVFValue*>(value));
|
|
2318
|
+
JSON_READ_FIELD_FWD(fieldJson, value, bb);
|
|
2319
|
+
JSON_READ_FIELD_FWD(fieldJson, value, terminator);
|
|
2320
|
+
JSON_READ_FIELD_FWD(fieldJson, value, ret);
|
|
2321
|
+
JSON_READ_FIELD_FWD(fieldJson, value, succInsts);
|
|
2322
|
+
JSON_READ_FIELD_FWD(fieldJson, value, predInsts);
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFCallInst* value)
|
|
2326
|
+
{
|
|
2327
|
+
fill(fieldJson, static_cast<SVFInstruction*>(value));
|
|
2328
|
+
JSON_READ_FIELD_FWD(fieldJson, value, args);
|
|
2329
|
+
JSON_READ_FIELD_FWD(fieldJson, value, varArg);
|
|
2330
|
+
JSON_READ_FIELD_FWD(fieldJson, value, calledVal);
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFVirtualCallInst* value)
|
|
2334
|
+
{
|
|
2335
|
+
fill(fieldJson, static_cast<SVFCallInst*>(value));
|
|
2336
|
+
JSON_READ_FIELD_FWD(fieldJson, value, vCallVtblPtr);
|
|
2337
|
+
JSON_READ_FIELD_FWD(fieldJson, value, virtualFunIdx);
|
|
2338
|
+
JSON_READ_FIELD_FWD(fieldJson, value, funNameOfVcall);
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFConstant* value)
|
|
2342
|
+
{
|
|
2343
|
+
fill(fieldJson, static_cast<SVFValue*>(value));
|
|
2344
|
+
}
|
|
2345
|
+
|
|
2346
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFGlobalValue* value)
|
|
2347
|
+
{
|
|
2348
|
+
fill(fieldJson, static_cast<SVFConstant*>(value));
|
|
2349
|
+
JSON_READ_FIELD_FWD(fieldJson, value, realDefGlobal);
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFArgument* value)
|
|
2353
|
+
{
|
|
2354
|
+
fill(fieldJson, static_cast<SVFValue*>(value));
|
|
2355
|
+
JSON_READ_FIELD_FWD(fieldJson, value, fun);
|
|
2356
|
+
JSON_READ_FIELD_FWD(fieldJson, value, argNo);
|
|
2357
|
+
JSON_READ_FIELD_FWD(fieldJson, value, uncalled);
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFConstantData* value)
|
|
2361
|
+
{
|
|
2362
|
+
fill(fieldJson, static_cast<SVFConstant*>(value));
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFConstantInt* value)
|
|
2366
|
+
{
|
|
2367
|
+
fill(fieldJson, static_cast<SVFConstantData*>(value));
|
|
2368
|
+
JSON_READ_FIELD_FWD(fieldJson, value, zval);
|
|
2369
|
+
JSON_READ_FIELD_FWD(fieldJson, value, sval);
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFConstantFP* value)
|
|
2373
|
+
{
|
|
2374
|
+
fill(fieldJson, static_cast<SVFConstantData*>(value));
|
|
2375
|
+
JSON_READ_FIELD_FWD(fieldJson, value, dval);
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFConstantNullPtr* value)
|
|
2379
|
+
{
|
|
2380
|
+
fill(fieldJson, static_cast<SVFConstantData*>(value));
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFBlackHoleValue* value)
|
|
2384
|
+
{
|
|
2385
|
+
fill(fieldJson, static_cast<SVFConstantData*>(value));
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFOtherValue* value)
|
|
2389
|
+
{
|
|
2390
|
+
fill(fieldJson, static_cast<SVFValue*>(value));
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2393
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFMetadataAsValue* value)
|
|
2394
|
+
{
|
|
2395
|
+
fill(fieldJson, static_cast<SVFOtherValue*>(value));
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
void SVFIRReader::virtFill(const cJSON*& fieldJson, SVFType* type)
|
|
2399
|
+
{
|
|
2400
|
+
auto kind = type->getKind();
|
|
2401
|
+
|
|
2402
|
+
switch (kind)
|
|
2403
|
+
{
|
|
2404
|
+
default:
|
|
2405
|
+
assert(false && "Impossible SVFType kind");
|
|
2406
|
+
|
|
2407
|
+
#define CASE(Kind) \
|
|
2408
|
+
case SVFType::Kind: \
|
|
2409
|
+
return fill(fieldJson, SVFUtil::dyn_cast<Kind##pe>(type))
|
|
2410
|
+
|
|
2411
|
+
CASE(SVFTy);
|
|
2412
|
+
CASE(SVFPointerTy);
|
|
2413
|
+
CASE(SVFIntegerTy);
|
|
2414
|
+
CASE(SVFFunctionTy);
|
|
2415
|
+
CASE(SVFStructTy);
|
|
2416
|
+
CASE(SVFArrayTy);
|
|
2417
|
+
CASE(SVFOtherTy);
|
|
2418
|
+
#undef CASE
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFType* type)
|
|
2423
|
+
{
|
|
2424
|
+
// kind has already been read
|
|
2425
|
+
JSON_READ_FIELD_FWD(fieldJson, type, getPointerToTy);
|
|
2426
|
+
JSON_READ_FIELD_FWD(fieldJson, type, typeinfo);
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFPointerType* type)
|
|
2430
|
+
{
|
|
2431
|
+
fill(fieldJson, static_cast<SVFType*>(type));
|
|
2432
|
+
JSON_READ_FIELD_FWD(fieldJson, type, ptrElementType);
|
|
2433
|
+
}
|
|
2434
|
+
|
|
2435
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFIntegerType* type)
|
|
2436
|
+
{
|
|
2437
|
+
fill(fieldJson, static_cast<SVFType*>(type));
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFFunctionType* type)
|
|
2441
|
+
{
|
|
2442
|
+
fill(fieldJson, static_cast<SVFType*>(type));
|
|
2443
|
+
JSON_READ_FIELD_FWD(fieldJson, type, retTy);
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFStructType* type)
|
|
2447
|
+
{
|
|
2448
|
+
fill(fieldJson, static_cast<SVFType*>(type));
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFArrayType* type)
|
|
2452
|
+
{
|
|
2453
|
+
fill(fieldJson, static_cast<SVFType*>(type));
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
void SVFIRReader::fill(const cJSON*& fieldJson, SVFOtherType* type)
|
|
2457
|
+
{
|
|
2458
|
+
fill(fieldJson, static_cast<SVFType*>(type));
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
SVFIR* SVFIRReader::read(const std::string& path)
|
|
2462
|
+
{
|
|
2463
|
+
struct stat buf;
|
|
2464
|
+
int fd = open(path.c_str(), O_RDONLY);
|
|
2465
|
+
if (fd == -1)
|
|
2466
|
+
{
|
|
2467
|
+
std::string info = "open(\"" + path + "\")";
|
|
2468
|
+
perror(info.c_str());
|
|
2469
|
+
abort();
|
|
2470
|
+
}
|
|
2471
|
+
if (fstat(fd, &buf) == -1)
|
|
2472
|
+
{
|
|
2473
|
+
std::string info = "fstate(\"" + path + "\")";
|
|
2474
|
+
perror(info.c_str());
|
|
2475
|
+
abort();
|
|
2476
|
+
}
|
|
2477
|
+
auto addr =
|
|
2478
|
+
(char*)mmap(nullptr, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
2479
|
+
if (addr == MAP_FAILED)
|
|
2480
|
+
{
|
|
2481
|
+
std::string info = "mmap(content of \"" + path + "\")";
|
|
2482
|
+
perror(info.c_str());
|
|
2483
|
+
abort();
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
auto root = cJSON_ParseWithLength(addr, buf.st_size);
|
|
2487
|
+
|
|
2488
|
+
if (munmap(addr, buf.st_size) == -1)
|
|
2489
|
+
perror("munmap()");
|
|
2490
|
+
|
|
2491
|
+
if (close(fd) < 0)
|
|
2492
|
+
perror("close()");
|
|
2493
|
+
|
|
2494
|
+
SVFIRReader reader;
|
|
2495
|
+
SVFIR* ir = reader.read(root);
|
|
2496
|
+
|
|
2497
|
+
cJSON_Delete(root);
|
|
2498
|
+
return ir;
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
} // namespace SVF
|