Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFFileSystem.cpp
Go to the documentation of this file.
2#include "Graphs/CHG.h"
3#include "SVFIR/SVFIR.h"
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>
10
12 "human-readable", "Whether to output human-readable JSON", true);
13
14namespace SVF
15{
16
17SVFType* 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");
26 ABORT_IFNOT(isSingleValTy, "Pointer type must be single-valued");
27 return new SVFPointerType();
29 ABORT_IFNOT(isSingleValTy, "Integer type must be single-valued");
30 return new SVFIntegerType();
32 ABORT_IFNOT(!isSingleValTy, "Function type must be multi-valued");
33 return new SVFFunctionType(nullptr);
35 ABORT_IFNOT(!isSingleValTy, "Struct type must be multi-valued");
36 return new SVFStructType();
38 ABORT_IFNOT(!isSingleValTy, "Array type must be multi-valued");
39 return new SVFArrayType();
41 return new SVFOtherType(isSingleValTy);
42 }
43}
44
46 std::string&& name)
47{
48 auto creator = [=]() -> SVFValue*
49 {
50 switch (kind)
51 {
52 default:
53 ABORT_MSG(kind << " is an impossible SVFValueKind in create()");
55 ABORT_MSG("Creation of RAW SVFValue isn't allowed");
57 return new SVFFunction(type, {}, {}, {}, {}, {}, {});
58 case SVFValue::SVFBB:
59 return new SVFBasicBlock(type, {});
61 return new SVFInstruction(type, {}, {}, {});
63 return new SVFCallInst(type, {}, {}, {});
65 return new SVFGlobalValue(type);
67 return new SVFArgument(type, {}, {}, {});
69 return new SVFConstant(type);
71 return new SVFConstantData(type);
73 return new SVFConstantInt(type, {}, {});
75 return new SVFConstantFP(type, {});
77 return new SVFConstantNullPtr(type);
79 return new SVFBlackHoleValue(type);
81 return new SVFMetadataAsValue(type);
83 return new SVFOtherValue(type);
84 }
85 };
86 auto val = creator();
87 val->setName(std::move(name));
88 return val;
89}
90
91template <typename SmallNumberType>
92static inline void readSmallNumber(const cJSON* obj, SmallNumberType& val)
93{
94 val = static_cast<SmallNumberType>(jsonGetNumber(obj));
95}
96
97template <typename BigNumberType, typename CStrToVal>
98static inline void readBigNumber(const cJSON* obj, BigNumberType& val, CStrToVal conv)
99{
101 "Expect (number) string JSON for " << JSON_KEY(obj));
102 val = conv(obj->valuestring);
103}
104
106{
107 return jsonCreateBool(flag);
108}
109
111{
112 // OK, double precision enough
113 return jsonCreateNumber(number);
114}
115
117{
118 // OK, double precision enough
119 return jsonCreateNumber(number);
120}
121
122cJSON* SVFIRWriter::toJson(const std::string& str)
123{
124 return jsonCreateString(str.c_str());
125}
126
131
133{
134 // unsigned long is subset of unsigned long long
135 return toJson(static_cast<unsigned long long>(number));
136}
137
139{
140 return toJson(static_cast<unsigned long long>(number));
141}
142
143cJSON* SVFIRWriter::toJson(unsigned long long number)
144{
146}
147
149{
150 auto kind = type->getKind();
151
152 switch (kind)
153 {
154 default:
155 assert(false && "Impossible SVFType kind");
156
157#define CASE(Kind) \
158 case SVFType::Kind: \
159 return contentToJson(static_cast<const Kind##pe*>(type))
160
161 CASE(SVFTy);
162 CASE(SVFPointerTy);
163 CASE(SVFIntegerTy);
164 CASE(SVFFunctionTy);
165 CASE(SVFStructTy);
166 CASE(SVFArrayTy);
167 CASE(SVFOtherTy);
168#undef CASE
169 }
170}
171
173{
174 auto kind = value->getKind();
175
176 switch (kind)
177 {
178 default:
179 assert(false && "Impossible SVFValue kind");
180
181#define CASE(ValueKind, type) \
182 case SVFValue::ValueKind: \
183 return contentToJson(static_cast<const type*>(value))
184
185 CASE(SVFVal, SVFValue);
186 CASE(SVFFunc, SVFFunction);
187 CASE(SVFBB, SVFBasicBlock);
188 CASE(SVFInst, SVFInstruction);
189 CASE(SVFCall, SVFCallInst);
190 CASE(SVFGlob, SVFGlobalValue);
191 CASE(SVFArg, SVFArgument);
192 CASE(SVFConst, SVFConstant);
193 CASE(SVFConstData, SVFConstantData);
194 CASE(SVFConstInt, SVFConstantInt);
195 CASE(SVFConstFP, SVFConstantFP);
196 CASE(SVFNullPtr, SVFConstantNullPtr);
197 CASE(SVFBlackHole, SVFBlackHoleValue);
198 CASE(SVFMetaAsValue, SVFMetadataAsValue);
199 CASE(SVFOther, SVFOtherValue);
200#undef CASE
201 }
202}
203
205{
206 switch (var->getNodeKind())
207 {
208 default:
209 assert(false && "Unknown SVFVar kind");
210
211#define CASE(VarKind, VarType) \
212 case SVFVar::VarKind: \
213 return contentToJson(static_cast<const VarType*>(var))
214
215 CASE(ValNode, ValVar);
216 CASE(ObjNode, ObjVar);
217 CASE(RetNode, RetPN);
218 CASE(VarargNode, VarArgPN);
219 CASE(GepValNode, GepValVar);
220 CASE(GepObjNode, GepObjVar);
221 CASE(BaseObjNode, BaseObjVar);
222 CASE(DummyValNode, DummyValVar);
223 CASE(DummyObjNode, DummyObjVar);
224 CASE(FunObjNode, FunObjVar);
225 CASE(FunValNode, FunValVar);
226 CASE(HeapObjNode, HeapObjVar);
227 CASE(StackObjNode, StackObjVar);
228 CASE(ConstantDataValNode, ConstantDataValVar);
229 CASE(GlobalValNode, GlobalValVar);
230 CASE(BlackHoleNode, BlackHoleVar);
231 CASE(ConstantFPValNode, ConstantFPValVar);
232 CASE(ConstantIntValNode, ConstantIntValVar);
233 CASE(ConstantNullptrValNode, ConstantNullPtrValVar);
234 CASE(ConstantDataObjNode, ConstantDataObjVar);
235 CASE(GlobalObjNode, GlobalObjVar);
236 CASE(ConstantFPObjNode, ConstantFPObjVar);
237 CASE(ConstantIntObjNode, ConstantIntObjVar);
238 CASE(ConstantNullptrObjNode, ConstantNullPtrObjVar);
239#undef CASE
240 }
241}
242
244{
245 switch (stmt->getEdgeKind())
246 {
247 default:
248 assert(false && "Unknown SVFStmt kind");
249
250#define CASE(EdgeKind, EdgeType) \
251 case SVFStmt::EdgeKind: \
252 return contentToJson(static_cast<const EdgeType*>(stmt))
253
254 CASE(Addr, AddrStmt);
255 CASE(Copy, CopyStmt);
256 CASE(Store, StoreStmt);
257 CASE(Load, LoadStmt);
258 CASE(Call, CallPE);
259 CASE(Ret, RetPE);
260 CASE(Gep, GepStmt);
261 CASE(Phi, PhiStmt);
262 CASE(Select, SelectStmt);
263 CASE(Cmp, CmpStmt);
264 CASE(BinaryOp, BinaryOPStmt);
265 CASE(UnaryOp, UnaryOPStmt);
266 CASE(Branch, BranchStmt);
267 CASE(ThreadFork, TDForkPE);
268 CASE(ThreadJoin, TDJoinPE);
269#undef CASE
270 }
271}
272
274{
275 switch (node->getNodeKind())
276 {
277 default:
278 assert(false && "Unknown ICFGNode kind");
279
280#define CASE(NodeKind, NodeType) \
281 case ICFGNode::NodeKind: \
282 return contentToJson(static_cast<const NodeType*>(node))
283
284 CASE(IntraBlock, IntraICFGNode);
285 CASE(FunEntryBlock, FunEntryICFGNode);
286 CASE(FunExitBlock, FunExitICFGNode);
287 CASE(FunCallBlock, CallICFGNode);
288 CASE(FunRetBlock, RetICFGNode);
289 CASE(GlobalBlock, GlobalICFGNode);
290#undef CASE
291 }
292}
293
295{
296 switch (edge->getEdgeKind())
297 {
298 default:
299 assert(false && "Unknown ICFGEdge kind");
301 return contentToJson(static_cast<const IntraCFGEdge*>(edge));
302 case ICFGEdge::CallCF:
303 return contentToJson(static_cast<const CallCFGEdge*>(edge));
304 case ICFGEdge::RetCF:
305 return contentToJson(static_cast<const RetCFGEdge*>(edge));
306 }
307}
308
310{
311 return contentToJson(node);
312}
313
318
320{
321 cJSON* root = genericNodeToJson(var);
322 JSON_WRITE_FIELD(root, var, value);
323 JSON_WRITE_FIELD(root, var, InEdgeKindToSetMap);
324 JSON_WRITE_FIELD(root, var, OutEdgeKindToSetMap);
325 JSON_WRITE_FIELD(root, var, isPtr);
326 return root;
327}
328
330{
331 return contentToJson(static_cast<const SVFVar*>(var));
332}
333
335{
336 cJSON* root = contentToJson(static_cast<const SVFVar*>(var));
337 JSON_WRITE_FIELD(root, var, mem);
338 return root;
339}
340
342{
343 cJSON* root = contentToJson(static_cast<const ValVar*>(var));
344 JSON_WRITE_FIELD(root, var, ap);
345 JSON_WRITE_FIELD(root, var, gepValType);
346 return root;
347}
348
350{
351 cJSON* root = contentToJson(static_cast<const ObjVar*>(var));
352 JSON_WRITE_FIELD(root, var, apOffset);
353 JSON_WRITE_FIELD(root, var, base);
354 return root;
355}
356
358{
359 return contentToJson(static_cast<const ObjVar*>(var));
360}
361
363{
364 return contentToJson(static_cast<const ValVar*>(var));
365}
366
368{
369 return contentToJson(static_cast<const ValVar*>(var));
370}
371
373{
374 return contentToJson(static_cast<const ValVar*>(var));
375}
376
378{
379 return contentToJson(static_cast<const ObjVar*>(var));
380}
381
383{
384 cJSON* root = genericNodeToJson(node);
385 JSON_WRITE_FIELD(root, node, fun);
386 JSON_WRITE_FIELD(root, node, bb);
387 // TODO: Ensure this?
388 assert(node->VFGNodes.empty() && "VFGNodes list not empty?");
389 JSON_WRITE_FIELD(root, node, pagEdges);
390 return root;
391}
392
394{
395 return contentToJson(static_cast<const ICFGNode*>(node));
396}
397
399{
400 cJSON* root = contentToJson(static_cast<const ICFGNode*>(node));
401 JSON_WRITE_FIELD(root, node, isRet);
402 return root;
403}
404
406{
407 return contentToJson(static_cast<const ICFGNode*>(node));
408}
409
411{
412 cJSON* root = contentToJson(static_cast<const ICFGNode*>(node));
413 JSON_WRITE_FIELD(root, node, FPNodes);
414 return root;
415}
416
418{
419 cJSON* root = contentToJson(static_cast<const ICFGNode*>(node));
420 JSON_WRITE_FIELD(root, node, formalRet);
421 return root;
422}
423
425{
426 cJSON* root = contentToJson(static_cast<const ICFGNode*>(node));
427 JSON_WRITE_FIELD(root, node, ret);
428 JSON_WRITE_FIELD(root, node, APNodes);
429 return root;
430}
431
433{
434 cJSON* root = contentToJson(static_cast<const ICFGNode*>(node));
435 JSON_WRITE_FIELD(root, node, actualRet);
436 JSON_WRITE_FIELD(root, node, callBlockNode);
437 return root;
438}
439
444
446{
447 cJSON* root = contentToJson(static_cast<const ICFGEdge*>(edge));
448 JSON_WRITE_FIELD(root, edge, conditionVar);
449 JSON_WRITE_FIELD(root, edge, branchCondVal);
450 return root;
451}
452
454{
455 cJSON* root = contentToJson(static_cast<const ICFGEdge*>(edge));
456 JSON_WRITE_FIELD(root, edge, callPEs);
457 return root;
458}
459
461{
462 cJSON* root = contentToJson(static_cast<const ICFGEdge*>(edge));
463 JSON_WRITE_FIELD(root, edge, retPE);
464 return root;
465}
466
468{
469 cJSON* root = genericNodeToJson(node);
470 JSON_WRITE_FIELD(root, node, vtable);
471 JSON_WRITE_FIELD(root, node, className);
472 JSON_WRITE_FIELD(root, node, flags);
473 JSON_WRITE_FIELD(root, node, virtualFunctionVectors);
474 return root;
475}
476
478{
480 JSON_WRITE_FIELD(root, edge, edgeType);
481 return root;
482}
483
485{
486 cJSON* root = jsonCreateObject();
487 JSON_WRITE_FIELD(root, type, kind);
488 JSON_WRITE_FIELD(root, type, isSingleValTy);
489 JSON_WRITE_FIELD(root, type, typeinfo);
490 return root;
491}
492
494{
495 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
496 return root;
497}
498
500{
501 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
502 JSON_WRITE_FIELD(root, type, signAndWidth);
503 return root;
504}
505
507{
508 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
509 JSON_WRITE_FIELD(root, type, retTy);
510 return root;
511}
512
514{
515 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
516 JSON_WRITE_FIELD(root, type, name);
517 return root;
518}
519
521{
522 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
523 JSON_WRITE_FIELD(root, type, numOfElement);
524 JSON_WRITE_FIELD(root, type, typeOfElement);
525 return root;
526}
527
529{
530 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
531 JSON_WRITE_FIELD(root, type, repr);
532 return root;
533}
534
536{
537 cJSON* root = jsonCreateObject();
538 JSON_WRITE_FIELD(root, value, kind);
539 JSON_WRITE_FIELD(root, value, type);
540 JSON_WRITE_FIELD(root, value, name);
541 JSON_WRITE_FIELD(root, value, ptrInUncalledFun);
542 JSON_WRITE_FIELD(root, value, constDataOrAggData);
543 JSON_WRITE_FIELD(root, value, sourceLoc);
544 return root;
545}
546
548{
549 cJSON* root = contentToJson(static_cast<const SVFValue*>(value));
550#define F(f) JSON_WRITE_FIELD(root, value, f);
551 F(isDecl);
552 F(intrinsic);
553 F(addrTaken);
554 F(isUncalled);
555 F(isNotRet);
556 F(varArg);
557 F(funcType);
558 F(loopAndDom);
559 F(realDefFun);
560 F(allBBs);
561 F(allArgs);
562#undef F
563 return root;
564}
565
567{
568 cJSON* root = contentToJson(static_cast<const SVFValue*>(value));
569 JSON_WRITE_FIELD(root, value, succBBs);
570 JSON_WRITE_FIELD(root, value, predBBs);
571 JSON_WRITE_FIELD(root, value, fun);
572 return root;
573}
574
576{
577 cJSON* root = contentToJson(static_cast<const SVFValue*>(value));
578 JSON_WRITE_FIELD(root, value, bb);
579 JSON_WRITE_FIELD(root, value, terminator);
580 JSON_WRITE_FIELD(root, value, ret);
581 return root;
582}
583
585{
586 cJSON* root = contentToJson(static_cast<const SVFInstruction*>(value));
587 JSON_WRITE_FIELD(root, value, args);
588 JSON_WRITE_FIELD(root, value, varArg);
589 JSON_WRITE_FIELD(root, value, calledVal);
590 return root;
591}
592
594{
595 return contentToJson(static_cast<const SVFValue*>(value));
596}
597
599{
600 cJSON* root = contentToJson(static_cast<const SVFConstant*>(value));
601 JSON_WRITE_FIELD(root, value, realDefGlobal);
602 return root;
603}
604
606{
607 cJSON* root = contentToJson(static_cast<const SVFValue*>(value));
608 JSON_WRITE_FIELD(root, value, fun);
609 JSON_WRITE_FIELD(root, value, argNo);
610 JSON_WRITE_FIELD(root, value, uncalled);
611 return root;
612}
613
615{
616 return contentToJson(static_cast<const SVFConstant*>(value));
617}
618
620{
621 cJSON* root = contentToJson(static_cast<const SVFConstantData*>(value));
622 JSON_WRITE_FIELD(root, value, zval);
623 JSON_WRITE_FIELD(root, value, sval);
624 return root;
625}
626
628{
629 cJSON* root = contentToJson(static_cast<const SVFConstantData*>(value));
630 JSON_WRITE_FIELD(root, value, dval);
631 return root;
632}
633
635{
636 return contentToJson(static_cast<const SVFConstantData*>(value));
637}
638
640{
641 return contentToJson(static_cast<const SVFConstantData*>(value));
642}
643
645{
646 return contentToJson(static_cast<const SVFValue*>(value));
647}
648
650{
651 return contentToJson(static_cast<const SVFOtherValue*>(value));
652}
653
655{
657 JSON_WRITE_FIELD(root, edge, value);
658 JSON_WRITE_FIELD(root, edge, basicBlock);
659 JSON_WRITE_FIELD(root, edge, icfgNode);
660 JSON_WRITE_FIELD(root, edge, edgeId);
661 return root;
662}
663
665{
666 cJSON* root = jsonCreateObject();
667#define F(field) JSON_WRITE_FIELD(root, loop, field)
668 F(entryICFGEdges);
669 F(backICFGEdges);
670 F(inICFGEdges);
671 F(outICFGEdges);
672 F(icfgNodes);
673 F(loopBound);
674#undef F
675 return root;
676}
677
679{
680 return contentToJson(static_cast<const SVFStmt*>(edge));
681}
682
684{
685 return contentToJson(static_cast<const AssignStmt*>(edge));
686}
687
689{
690 cJSON* root = contentToJson(static_cast<const AssignStmt*>(edge));
691 JSON_WRITE_FIELD(root, edge, copyKind);
692 return root;
693}
694
696{
697 return contentToJson(static_cast<const AssignStmt*>(edge));
698}
699
701{
702 return contentToJson(static_cast<const AssignStmt*>(edge));
703}
704
706{
707 cJSON* root = contentToJson(static_cast<const AssignStmt*>(edge));
708 JSON_WRITE_FIELD(root, edge, ap);
709 JSON_WRITE_FIELD(root, edge, variantField);
710 return root;
711}
712
714{
715 cJSON* root = contentToJson(static_cast<const AssignStmt*>(edge));
716 JSON_WRITE_FIELD(root, edge, call);
717 JSON_WRITE_FIELD(root, edge, entry);
718 return root;
719}
720
722{
723 cJSON* root = contentToJson(static_cast<const AssignStmt*>(edge));
724 JSON_WRITE_FIELD(root, edge, call);
725 JSON_WRITE_FIELD(root, edge, exit);
726 return root;
727}
728
730{
731 cJSON* root = contentToJson(static_cast<const SVFStmt*>(edge));
732 JSON_WRITE_FIELD(root, edge, opVars);
733 return root;
734}
735
737{
738 cJSON* root = contentToJson(static_cast<const MultiOpndStmt*>(edge));
739 JSON_WRITE_FIELD(root, edge, opICFGNodes);
740 return root;
741}
742
744{
745 cJSON* root = contentToJson(static_cast<const MultiOpndStmt*>(edge));
746 JSON_WRITE_FIELD(root, edge, condition);
747 return root;
748}
749
751{
752 cJSON* root = contentToJson(static_cast<const MultiOpndStmt*>(edge));
753 JSON_WRITE_FIELD(root, edge, predicate);
754 return root;
755}
756
758{
759 cJSON* root = contentToJson(static_cast<const MultiOpndStmt*>(edge));
760 JSON_WRITE_FIELD(root, edge, opcode);
761 return root;
762}
763
765{
766 cJSON* root = contentToJson(static_cast<const SVFStmt*>(edge));
767 JSON_WRITE_FIELD(root, edge, opcode);
768 return root;
769}
770
772{
773 cJSON* root = contentToJson(static_cast<const SVFStmt*>(edge));
774 JSON_WRITE_FIELD(root, edge, successors);
775 JSON_WRITE_FIELD(root, edge, cond);
776 JSON_WRITE_FIELD(root, edge, brInst);
777 return root;
778}
779
781{
782 return contentToJson(static_cast<const CallPE*>(edge));
783}
784
786{
787 return contentToJson(static_cast<const RetPE*>(edge));
788}
789
790bool jsonAddNumberToObject(cJSON* obj, const char* name, double number)
791{
793 return jsonAddItemToObject(obj, name, node);
794}
795
796bool jsonAddStringToObject(cJSON* obj, const char* name, const char* str)
797{
799 return jsonAddItemToObject(obj, name, node);
800}
801
802bool jsonAddStringToObject(cJSON* obj, const char* name, const std::string& s)
803{
804 return jsonAddStringToObject(obj, name, s.c_str());
805}
806
808{
809 return humanReadableOption()
811 : cJSON_IsNumber(item) &&
812 (item->valuedouble == 0 || item->valuedouble == 1);
813}
814
815bool jsonIsBool(const cJSON* item, bool& flag)
816{
818 {
819 if (!cJSON_IsBool(item))
820 return false;
822 return true;
823 }
824 else
825 {
826 if (!cJSON_IsNumber(item))
827 return false;
828 flag = item->valuedouble == 1;
829 return true;
830 }
831}
832
834{
835 return cJSON_IsNumber(item);
836}
837
839{
840 return cJSON_IsString(item);
841}
842
844{
845 // TODO: optimize
846 return cJSON_IsNull(item);
847}
848
850{
851 return cJSON_IsArray(item);
852}
853
854bool jsonIsMap(const cJSON* item)
855{
856 return cJSON_IsArray(item);
857}
858
863
864bool jsonKeyEquals(const cJSON* item, const char* key)
865{
866 return item && !(humanReadableOption() && std::strcmp(item->string, key));
867}
868
869std::pair<const cJSON*,const cJSON*> jsonUnpackPair(const cJSON* item)
870{
871 ABORT_IFNOT(jsonIsArray(item), "Expected array as pair");
873 ABORT_IFNOT(child1, "Missing first child of pair");
875 ABORT_IFNOT(child2, "Missing first child of pair");
876 ABORT_IFNOT(!child2->next, "Pair has more than two children");
877 return {child1, child2};
878}
879
881{
882 ABORT_IFNOT(jsonIsNumber(item), "Expected number for " << JSON_KEY(item));
883 return item->valuedouble;
884}
885
887{
888 // TODO: optimize
889 return cJSON_CreateNull();
890}
891
896
898{
899 return cJSON_CreateArray();
900}
901
903{
904 // Don't use cJSON_CreateObject() here, because it only allows string keys.
905 return cJSON_CreateArray();
906}
907
909{
911}
912
914{
915 constexpr size_t maxPreciseIntInDouble = (1ull << 53);
916 (void)maxPreciseIntInDouble; // silence unused warning
919}
920
926
928{
929 return cJSON_CreateNumber(num);
930}
931
940
946
951
953{
954 for (const auto& pair : icfg->getIcfgNodeToSVFLoopVec())
955 {
956 for (const SVFLoop* loop : pair.second)
957 {
958 svfLoopPool.saveID(loop);
959 }
960 }
961}
962
964{
965 // TODO: SVFType & StInfo are managed by SymbolTableInfo. Refactor it?
967
968 const auto& svfTypes = symTab->getSVFTypes();
969 svfTypePool.reserve(svfTypes.size());
970 for (const SVFType* type : svfTypes)
971 {
972 svfTypePool.saveID(type);
973 }
974
975 const auto& stInfos = symTab->getStInfos();
976 stInfoPool.reserve(stInfos.size());
977 for (const StInfo* stInfo : stInfos)
978 {
979 stInfoPool.saveID(stInfo);
980 }
981
982 svfValuePool.reserve(svfModule->getFunctionSet().size() +
983 svfModule->getConstantSet().size() +
984 svfModule->getOtherValueSet().size());
985}
986
988 : svfIR(svfir), svfModuleWriter(svfir->svfModule), icfgWriter(svfir->icfg),
989 chgWriter(SVFUtil::dyn_cast<CHGraph>(svfir->chgraph)),
990 irGraphWriter(svfir)
991{
992}
993
994void SVFIRWriter::writeJsonToOstream(const SVFIR* svfir, std::ostream& os)
995{
996 SVFIRWriter writer(svfir);
997 os << writer.generateJsonString().get() << '\n';
998}
999
1000void SVFIRWriter::writeJsonToPath(const SVFIR* svfir, const std::string& path)
1001{
1002 std::ofstream jsonFile(path);
1003 if (jsonFile.is_open())
1004 {
1006 jsonFile.close();
1007 }
1008 else
1009 {
1010 SVFUtil::errs() << "Failed to open file '" << path
1011 << "' to write SVFIR's JSON\n";
1012 }
1013}
1014
1015const char* SVFIRWriter::numToStr(size_t n)
1016{
1017 auto it = numToStrMap.find(n);
1018 if (it != numToStrMap.end() && !(numToStrMap.key_comp()(n, it->first)))
1019 {
1020 return it->second.c_str();
1021 }
1022 return numToStrMap.emplace_hint(it, n, std::to_string(n))->second.c_str();
1023}
1024
1026{
1027 autoJSON object = generateJson();
1028 char* str = humanReadableOption() ? cJSON_Print(object.get())
1029 : cJSON_PrintUnformatted(object.get());
1030 return {str, cJSON_free};
1031}
1032
1034{
1035 const IRGraph* const irGraph = svfIR;
1037 assert(nodeIDAllocator && "NodeIDAllocator is not initialized?");
1038
1039 cJSON* root = jsonCreateObject();
1040#define F(field) JSON_WRITE_FIELD(root, svfIR, field)
1041 F(svfModule);
1042 F(symInfo);
1043 F(icfg);
1044 F(chgraph);
1046 F(icfgNode2SVFStmtsMap);
1047 F(icfgNode2PTASVFStmtsMap);
1048 F(GepValObjMap);
1049 F(typeLocSetsMap);
1050 F(GepObjVarMap);
1051 F(memToFieldsMap);
1052 F(globSVFStmtSet);
1053 F(phiNodeMap);
1054 F(funArgsListMap);
1055 F(callSiteArgsListMap);
1056 F(callSiteRetMap);
1057 F(funRetMap);
1058 F(indCallSiteToFunPtrMap);
1059 F(funPtrToCallSitesMap);
1060 F(candidatePointers);
1061 F(callSiteSet);
1063#undef F
1064
1065 return {root, cJSON_Delete};
1066}
1067
1072
1074{
1076}
1077
1079{
1080 ENSURE_NOT_VISITED(graph);
1081
1083#define F(field) JSON_WRITE_FIELD(root, graph, field)
1084 F(KindToSVFStmtSetMap);
1085 F(KindToPTASVFStmtSetMap);
1086 F(fromFile);
1087 F(nodeNumAfterPAGBuild);
1088 F(totalPTAPAGEdge);
1089 F(valueToEdgeMap);
1090#undef F
1091 return root;
1092}
1093
1095{
1096 return var ? jsonCreateIndex(var->getId()) : jsonCreateNullId();
1097}
1098
1103
1105{
1106 cJSON* allSvfLoop = jsonCreateArray(); // all indices seen in constructor
1107 for (const SVFLoop* svfLoop : icfgWriter.svfLoopPool)
1108 {
1111 }
1112
1113#define F(field) JSON_WRITE_FIELD(root, icfg, field)
1115 jsonAddItemToObject(root, FIELD_NAME_ITEM(allSvfLoop)); // Meta field
1116 F(totalICFGNode);
1117 F(FunToFunEntryNodeMap);
1118 F(FunToFunExitNodeMap);
1119 F(globalBlockNode);
1120 F(icfgNodeToSVFLoopVec);
1121#undef F
1122 return root;
1123}
1124
1126{
1127 assert(node && "ICFGNode is null!");
1128 return jsonCreateIndex(node->getId());
1129}
1130
1132{
1133 assert(edge && "ICFGNode is null!");
1135}
1136
1138{
1139 auto chg = SVFUtil::dyn_cast<CHGraph>(graph);
1140 assert(chg && "Unsupported CHGraph type!");
1141 return toJson(chg);
1142}
1143
1145{
1147#define F(field) JSON_WRITE_FIELD(root, graph, field)
1148 // TODO: Ensure svfMod is the same as the SVFIR's?
1149 F(classNum);
1150 F(vfID);
1151 // F(buildingCHGTime); No need
1152 F(classNameToNodeMap);
1153 F(classNameToDescendantsMap);
1154 F(classNameToAncestorsMap);
1155 F(classNameToInstAndDescsMap);
1156 F(templateNameToInstancesMap);
1157 F(callNodeToClassesMap);
1158 F(virtualFunctionToIDMap);
1159 F(callNodeToCHAVtblsMap);
1160 F(callNodeToCHAVFnsMap);
1161#undef F
1162 return root;
1163}
1164
1166{
1167 return jsonCreateIndex(node->getId());
1168}
1169
1174
1179
1181{
1182 cJSON* root = jsonCreateObject();
1183 JSON_WRITE_FIELD(root, memObj, symId);
1184 JSON_WRITE_FIELD(root, memObj, typeInfo);
1185 JSON_WRITE_FIELD(root, memObj, refVal);
1186 return root;
1187}
1188
1190{
1191 cJSON* root = jsonCreateObject();
1192#define F(field) JSON_WRITE_FIELD(root, stInfo, field)
1193 F(stride);
1194 F(numOfFlattenElements);
1195 F(numOfFlattenFields);
1196 F(fldIdxVec);
1197 F(elemIdxVec);
1198 F(fldIdx2TypeMap);
1199 F(finfo);
1200 F(flattenElementTypes);
1201#undef F
1202 return root;
1203}
1204
1206{
1208
1209 cJSON* root = jsonCreateObject();
1211 JSON_WRITE_FIELD(root, objTypeInfo, flags);
1212 JSON_WRITE_FIELD(root, objTypeInfo, maxOffsetLimit);
1213 JSON_WRITE_FIELD(root, objTypeInfo, elemNum);
1214 return root;
1215}
1216
1218{
1219 return jsonCreateIndex(memObj->getId());
1220}
1221
1223{
1225
1226 cJSON* root = jsonCreateObject();
1227 JSON_WRITE_FIELD(root, ldInfo, reachableBBs);
1228 JSON_WRITE_FIELD(root, ldInfo, dtBBsMap);
1229 JSON_WRITE_FIELD(root, ldInfo, pdtBBsMap);
1230 JSON_WRITE_FIELD(root, ldInfo, dfBBsMap);
1231 JSON_WRITE_FIELD(root, ldInfo, bb2LoopMap);
1232 JSON_WRITE_FIELD(root, ldInfo, bb2PdomLevel);
1233 JSON_WRITE_FIELD(root, ldInfo, bb2PIdom);
1234 return root;
1235}
1236
1241
1243{
1244 cJSON* root = jsonCreateObject();
1245 JSON_WRITE_FIELD(root, &ap, fldIdx);
1246 JSON_WRITE_FIELD(root, &ap, idxOperandPairs);
1247 return root;
1248}
1249
1251{
1253
1254 cJSON* root = jsonCreateObject();
1255 JSON_WRITE_FIELD(root, nodeIDAllocator, strategy);
1256 JSON_WRITE_FIELD(root, nodeIDAllocator, numObjects);
1257 JSON_WRITE_FIELD(root, nodeIDAllocator, numValues);
1258 JSON_WRITE_FIELD(root, nodeIDAllocator, numSymbols);
1259 JSON_WRITE_FIELD(root, nodeIDAllocator, numNodes);
1260 return root;
1261}
1262
1264{
1266
1267 cJSON* root = jsonCreateObject();
1269 for (const auto& pair : symTable->objMap)
1270 {
1271 const MemObj* memObj = pair.second;
1274 }
1275
1276#define F(field) JSON_WRITE_FIELD(root, symTable, field)
1277 jsonAddItemToObject(root, FIELD_NAME_ITEM(allMemObj)); // Actual field
1278
1279 F(valSymMap);
1280 F(objSymMap);
1281 F(returnSymMap);
1282 F(varargSymMap);
1283 // Field objMap can be represented by allMemObj
1284 // Field mod can be represented by svfIR->svfModule. Delete it?
1285 assert(symTable->mod == svfIR->svfModule && "SVFModule mismatch!");
1286 F(modelConstants);
1287 F(totalSymNum);
1288 F(maxStruct);
1289 F(maxStSize);
1290 // Field svfTypes can be represented by svfModuleWriter.svfTypePool
1291 // Field stInfos can be represented by svfModuleWriter.stInfoPool
1292#undef F
1293
1294 return root;
1295}
1296
1298{
1299 cJSON* root = jsonCreateObject();
1303
1305 {
1308 }
1309
1311 {
1314 }
1315
1316#define F(field) JSON_WRITE_FIELD(root, module, field)
1317 jsonAddItemToObject(root, FIELD_NAME_ITEM(allSVFType)); // Meta field
1318 jsonAddItemToObject(root, FIELD_NAME_ITEM(allStInfo)); // Meta field
1319 jsonAddItemToObject(root, FIELD_NAME_ITEM(allSVFValue)); // Meta field
1320 F(pagReadFromTxt);
1321 F(moduleIdentifier);
1322
1323 F(FunctionSet);
1324 F(GlobalSet);
1325 F(AliasSet);
1326 F(ConstantSet);
1327 F(OtherValueSet);
1328#undef F
1329
1330 for (size_t i = 1; i <= svfModuleWriter.sizeSVFValuePool(); ++i)
1331 {
1334 }
1335
1336 return root;
1337}
1338
1340{
1341 const cJSON* svfirField = createObjs(root);
1342
1343 SVFIR* svfIR = SVFIR::getPAG(); // SVFIR constructor sets symInfo
1344 IRGraph* irGraph = svfIR;
1345
1346 auto svfModule = SVFModule::getSVFModule();
1347 auto icfg = new ICFG();
1348 auto chgraph = new CHGraph(svfModule);
1349 auto symInfo = SymbolTableInfo::SymbolInfo();
1350 symInfo->mod = svfModule;
1351
1352 svfIR->svfModule = svfModule;
1353 svfIR->icfg = icfg;
1354 svfIR->chgraph = chgraph;
1355
1356#define F(field) JSON_READ_FIELD_FWD(svfirField, svfIR, field)
1357 readJson(symInfo);
1359 readJson(icfg);
1360 readJson(chgraph);
1361 readJson(svfModule);
1362
1363 F(icfgNode2SVFStmtsMap);
1364 F(icfgNode2PTASVFStmtsMap);
1365 F(GepValObjMap);
1366 F(typeLocSetsMap);
1367 F(GepObjVarMap);
1368 F(memToFieldsMap);
1369 F(globSVFStmtSet);
1370 F(phiNodeMap);
1371 F(funArgsListMap);
1372 F(callSiteArgsListMap);
1373 F(callSiteRetMap);
1374 F(funRetMap);
1375 F(indCallSiteToFunPtrMap);
1376 F(funPtrToCallSitesMap);
1377 F(candidatePointers);
1378 F(callSiteSet);
1379#undef F
1380 assert(!NodeIDAllocator::allocator && "NodeIDAllocator should be NULL");
1383
1384 return svfIR;
1385}
1386
1388{
1389#define READ_CREATE_NODE_FWD(GType) \
1390 [](const cJSON*& nodeJson) { \
1391 JSON_DEF_READ_FWD(nodeJson, NodeID, id); \
1392 JSON_DEF_READ_FWD(nodeJson, GNodeK, nodeKind); \
1393 return std::make_pair(id, create##GType##Node(id, nodeKind)); \
1394 }
1395#define READ_CREATE_EDGE_FWD(GType) \
1396 [](const cJSON*& edgeJson) { \
1397 JSON_DEF_READ_FWD(edgeJson, GEdgeFlag, edgeFlag); \
1398 auto kind = applyEdgeMask(edgeFlag); \
1399 auto edge = create##GType##Edge(kind); \
1400 setEdgeFlag(edge, edgeFlag); \
1401 return edge; \
1402 }
1403
1404 ABORT_IFNOT(jsonIsObject(root), "Root should be an object");
1405
1406 const cJSON* const svfModule = root->child;
1407 CHECK_JSON_KEY(svfModule);
1409 svfModule,
1410 // SVFType Creator
1411 [](const cJSON*& svfTypeFldJson)
1412 {
1414 JSON_DEF_READ_FWD(svfTypeFldJson, bool, isSingleValTy);
1415 return createSVFType(kind, isSingleValTy);
1416 },
1417 // SVFType Filler
1418 [this](const cJSON*& svfVarFldJson, SVFType* type)
1419 {
1421 },
1422 // SVFValue Creator
1423 [this](const cJSON*& svfValueFldJson)
1424 {
1427 JSON_DEF_READ_FWD(svfValueFldJson, std::string, name);
1428 return createSVFValue(kind, type, std::move(name));
1429 },
1430 // SVFValue Filler
1431 [this](const cJSON*& svfVarFldJson, SVFValue* value)
1432 {
1433 virtFill(svfVarFldJson, value);
1434 },
1435 // StInfo Creator (no filler needed)
1436 [this](const cJSON*& stInfoFldJson)
1437 {
1439 auto si = new StInfo(stride);
1441 ABORT_IFNOT(!stInfoFldJson, "StInfo has extra field");
1442 return si;
1443 });
1444
1445 const cJSON* const symInfo = svfModule->next;
1446 CHECK_JSON_KEY(symInfo);
1448 symInfo,
1449 // MemObj Creator (no filler needed)
1450 [this](const cJSON*& memObjFldJson)
1451 {
1454 JSON_DEF_READ_FWD(memObjFldJson, const SVFValue*, refVal, {});
1455 return std::make_pair(symId, new MemObj(symId, typeInfo, refVal));
1456 });
1457
1458 const cJSON* const icfg = symInfo->next;
1459 CHECK_JSON_KEY(icfg);
1462 [](auto)
1463 {
1464 return new SVFLoop({}, 0);
1465 });
1466
1467 const cJSON* const chgraph = icfg->next;
1468 CHECK_JSON_KEY(chgraph);
1471
1472 const cJSON* const irGraph = chgraph->next;
1476
1478 [this](const cJSON*& j, ICFGNode* node)
1479 {
1480 virtFill(j, node);
1481 },
1482 [this](const cJSON*& j, ICFGEdge* edge)
1483 {
1484 virtFill(j, edge);
1485 },
1486 [this](const cJSON*& j, SVFLoop* loop)
1487 {
1488 fill(j, loop);
1489 });
1491 [this](const cJSON*& j, CHNode* node)
1492 {
1493 virtFill(j, node);
1494 },
1495 [this](const cJSON*& j, CHEdge* edge)
1496 {
1497 virtFill(j, edge);
1498 });
1500 [this](const cJSON*& j, SVFVar* var)
1501 {
1502 virtFill(j, var);
1503 },
1504 [this](const cJSON*& j, SVFStmt* stmt)
1505 {
1506 virtFill(j, stmt);
1507 });
1508
1509 return irGraph->next;
1510
1511#undef READ_CREATE_EDGE_FWD
1512#undef READ_CREATE_NODE_FWD
1513}
1514
1516{
1517 ABORT_IFNOT(jsonIsBool(obj, flag), "Expect bool for " << obj->string);
1518}
1519
1520void SVFIRReader::readJson(const cJSON* obj, unsigned& val)
1521{
1523}
1524
1526{
1528}
1529
1531{
1533}
1534
1536{
1538}
1539
1540void SVFIRReader::readJson(const cJSON* obj, unsigned long& val)
1541{
1543 [](const char* s)
1544 {
1545 return std::strtoul(s, nullptr, 10);
1546 });
1547}
1548
1549void SVFIRReader::readJson(const cJSON* obj, long long& val)
1550{
1552 [](const char* s)
1553 {
1554 return std::strtoll(s, nullptr, 10);
1555 });
1556}
1557
1558void SVFIRReader::readJson(const cJSON* obj, unsigned long long& val)
1559{
1561 [](const char* s)
1562 {
1563 return std::strtoull(s, nullptr, 10);
1564 });
1565}
1566
1567void SVFIRReader::readJson(const cJSON* obj, std::string& str)
1568{
1569 ABORT_IFNOT(jsonIsString(obj), "Expect string for " << obj->string);
1570 str = obj->valuestring;
1571}
1572
1574{
1575 switch (kind)
1576 {
1577 default:
1578 ABORT_MSG(kind << " is an impossible ICFGNodeKind in create()");
1579#define CASE(kind, constructor) \
1580 case ICFGNode::kind: \
1581 return new constructor(id);
1582 CASE(IntraBlock, IntraICFGNode);
1583 CASE(FunEntryBlock, FunEntryICFGNode);
1584 CASE(FunExitBlock, FunExitICFGNode);
1585 CASE(FunCallBlock, CallICFGNode);
1586 CASE(FunRetBlock, RetICFGNode);
1587 CASE(GlobalBlock, GlobalICFGNode);
1588#undef CASE
1589 }
1590}
1591
1593{
1594 constexpr ICFGNode* src = nullptr;
1595 constexpr ICFGNode* dst = nullptr;
1596
1597 switch (kind)
1598 {
1599 default:
1600 ABORT_MSG(kind << " is an impossible ICFGEdgeKind in create()");
1601 case ICFGEdge::IntraCF:
1602 return new IntraCFGEdge(src, dst);
1603 case ICFGEdge::CallCF:
1604 return new CallCFGEdge(src, dst);
1605 case ICFGEdge::RetCF:
1606 return new RetCFGEdge(src, dst);
1607 }
1608}
1609
1611{
1612 ABORT_IFNOT(kind == 0, "Impossible CHNode kind " << kind);
1613 return new CHNode("", id);
1614}
1615
1617{
1618 ABORT_IFNOT(kind == 0, "Unsupported CHEdge kind " << kind);
1619 return new CHEdge(nullptr, nullptr, {});
1620}
1621
1623{
1624 switch (kind)
1625 {
1626 default:
1627 ABORT_MSG(kind << " is an impossible SVFVarKind in create()");
1628#define CASE(kind, constructor) \
1629 case SVFVar::kind: \
1630 return new constructor(id);
1631 CASE(ValNode, ValVar);
1632 CASE(RetNode, RetPN);
1633 CASE(ObjNode, ObjVar);
1634 CASE(VarargNode, VarArgPN);
1635 CASE(GepValNode, GepValVar);
1636 CASE(GepObjNode, GepObjVar);
1637 CASE(BaseObjNode, BaseObjVar);
1638 CASE(DummyValNode, DummyValVar);
1639 CASE(DummyObjNode, DummyObjVar);
1640#undef CASE
1641 }
1642}
1643
1645{
1646 switch (kind)
1647 {
1648 default:
1649 ABORT_MSG(kind << " is an impossible SVFStmtKind in create()");
1650#define CASE(kind, constructor) \
1651 case SVFStmt::kind: \
1652 return new constructor;
1653 CASE(Addr, AddrStmt);
1654 CASE(Copy, CopyStmt);
1655 CASE(Store, StoreStmt);
1656 CASE(Load, LoadStmt);
1657 CASE(Call, CallPE);
1658 CASE(Ret, RetPE);
1659 CASE(Gep, GepStmt);
1660 CASE(Phi, PhiStmt);
1661 CASE(Select, SelectStmt);
1662 CASE(Cmp, CmpStmt);
1663 CASE(BinaryOp, BinaryOPStmt);
1664 CASE(UnaryOp, UnaryOPStmt);
1665 CASE(Branch, BranchStmt);
1666 CASE(ThreadFork, TDForkPE);
1667 CASE(ThreadJoin, TDJoinPE);
1668#undef CASE
1669 }
1670}
1671
1673{
1674 assert(idAllocator && "idAllocator should be nonempty");
1675
1676 ABORT_IFNOT(jsonIsObject(obj), "Expect object for " << JSON_KEY(obj));
1677 obj = obj->child;
1678
1679 JSON_DEF_READ_FWD(obj, int, strategy);
1680 static_assert(sizeof(idAllocator->strategy) == sizeof(strategy),
1681 "idAllocator->strategy should be represented by int");
1682 idAllocator->strategy = static_cast<NodeIDAllocator::Strategy>(strategy);
1683 JSON_READ_FIELD_FWD(obj, idAllocator, numObjects);
1684 JSON_READ_FIELD_FWD(obj, idAllocator, numValues);
1685 JSON_READ_FIELD_FWD(obj, idAllocator, numSymbols);
1687
1688 ABORT_IFNOT(!obj, "Extra field " << JSON_KEY(obj) << " in NodeIDAllocator");
1689}
1690
1692{
1694#define F(field) JSON_READ_FIELD_FWD(obj, symTabInfo, field)
1695 // `allMemObj` was consumed during create & fill phase.
1696 F(valSymMap);
1697 F(objSymMap);
1698 F(returnSymMap);
1699 F(varargSymMap);
1700 symTableReader.memObjMap.saveToIDToObjMap(symTabInfo->objMap); // objMap
1701 F(modelConstants);
1702 F(totalSymNum);
1703 F(maxStruct);
1704 F(maxStSize);
1705#undef F
1706 ABORT_IFNOT(!obj, "Extra field " << JSON_KEY(obj) << " in SymbolTableInfo");
1707}
1708
1710{
1711 assert(SymbolTableInfo::symInfo && "SymbolTableInfo should be nonempty");
1712 assert(graph->symInfo == SymbolTableInfo::SymbolInfo() && "symInfo differ");
1713
1714 auto& valToEdgeMap = graph->valueToEdgeMap;
1715 valToEdgeMap.clear();
1716
1719#define F(field) JSON_READ_FIELD_FWD(obj, graph, field)
1720 // base and symInfo have already been read
1721 F(KindToSVFStmtSetMap);
1722 F(KindToPTASVFStmtSetMap);
1723 F(fromFile);
1724 F(nodeNumAfterPAGBuild);
1725 F(totalPTAPAGEdge);
1726 F(valueToEdgeMap);
1727#undef F
1728
1729 auto nullit = valToEdgeMap.find(nullptr);
1730 ABORT_IFNOT(nullit != valToEdgeMap.end(), "valueToEdgeMap should has key NULL");
1731 ABORT_IFNOT(nullit->second.empty(), "valueToEdgeMap[NULL] should be empty");
1732}
1733
1735{
1737 const cJSON* obj = icfgReader.getFieldJson();
1738#define F(field) JSON_READ_FIELD_FWD(obj, icfg, field)
1739 F(totalICFGNode);
1740 F(FunToFunEntryNodeMap);
1741 F(FunToFunExitNodeMap);
1742 F(globalBlockNode);
1743 F(icfgNodeToSVFLoopVec);
1744#undef F
1745}
1746
1748{
1751#define F(field) JSON_READ_FIELD_FWD(obj, graph, field)
1752 F(classNum);
1753 F(vfID);
1754 F(classNameToNodeMap);
1755 F(classNameToDescendantsMap);
1756 F(classNameToAncestorsMap);
1757 F(classNameToInstAndDescsMap);
1758 F(templateNameToInstancesMap);
1759 F(callNodeToClassesMap);
1760 F(virtualFunctionToIDMap);
1761 F(callNodeToCHAVtblsMap);
1762 F(callNodeToCHAVFnsMap);
1763#undef F
1764}
1765
1767{
1769 auto symInfo = SymbolTableInfo::symInfo;
1770 assert(symInfo && "SymbolTableInfo should be non-NULL");
1771 svfModuleReader.svfTypePool.saveToSet(symInfo->svfTypes);
1772 svfModuleReader.stInfoPool.saveToSet(symInfo->stInfos);
1773
1774#define F(field) JSON_READ_FIELD_FWD(obj, module, field)
1775 F(pagReadFromTxt);
1776 F(moduleIdentifier);
1777 F(FunctionSet);
1778 F(GlobalSet);
1779 F(AliasSet);
1780 F(ConstantSet);
1781 F(OtherValueSet);
1782#undef F
1783}
1784
1786{
1787 assert(!type && "SVFType already read?");
1789}
1790
1792{
1793 assert(!stInfo && "StInfo already read?");
1795}
1796
1798{
1799 assert(!value && "SVFValue already read?");
1801}
1802
1804{
1805 assert(!var && "SVFVar already read?");
1806 if (jsonIsNullId(obj))
1807 var = nullptr;
1808 else
1810}
1811
1813{
1814 assert(!stmt && "SVFStmt already read?");
1816}
1817
1819{
1820 assert(!node && "ICFGNode already read?");
1821 NodeID id = jsonGetNumber(obj);
1822 node = icfgReader.getNodePtr(id);
1823}
1824
1826{
1827 assert(!edge && "ICFGEdge already read?");
1829}
1830
1832{
1833 assert(!node && "CHNode already read?");
1835}
1836
1838{
1839 assert(!edge && "CHEdge already read?");
1841}
1842
1844{
1845 ABORT_IFNOT(jsonIsObject(obj), "Expected obj for AccessPath");
1846 obj = obj->child;
1847 JSON_READ_FIELD_FWD(obj, &ap, fldIdx);
1848 JSON_READ_FIELD_FWD(obj, &ap, idxOperandPairs);
1849 ABORT_IFNOT(!obj, "Extra field " << JSON_KEY(obj) << " in AccessPath");
1850}
1851
1853{
1854 assert(!loop && "SVFLoop already read?");
1855 unsigned id = jsonGetNumber(obj);
1857}
1858
1860{
1861 assert(!memObj && "MemObj already read?");
1863}
1864
1866{
1867 assert(!objTypeInfo && "ObjTypeInfo already read?");
1868 ABORT_IFNOT(jsonIsObject(obj), "Expected object for objTypeInfo");
1869 cJSON* field = obj->child;
1870
1872 JSON_DEF_READ_FWD(field, u32_t, flags);
1873 JSON_DEF_READ_FWD(field, u32_t, maxOffsetLimit);
1874 JSON_DEF_READ_FWD(field, u32_t, elemNum);
1875
1876 ABORT_IFNOT(!field, "Extra field in objTypeInfo: " << JSON_KEY(field));
1877 objTypeInfo = new ObjTypeInfo(type, maxOffsetLimit);
1878 objTypeInfo->flags = flags;
1879 objTypeInfo->elemNum = elemNum;
1880}
1881
1883{
1884 assert(!ldInfo && "SVFLoopAndDomInfo already read?");
1885 ABORT_IFNOT(jsonIsObject(obj), "Expected object for SVFLoopAndDomInfo");
1886 cJSON* field = obj->child;
1887
1888 ldInfo = new SVFLoopAndDomInfo();
1889
1890 JSON_READ_FIELD_FWD(field, ldInfo, reachableBBs);
1891 JSON_READ_FIELD_FWD(field, ldInfo, dtBBsMap);
1892 JSON_READ_FIELD_FWD(field, ldInfo, pdtBBsMap);
1893 JSON_READ_FIELD_FWD(field, ldInfo, dfBBsMap);
1894 JSON_READ_FIELD_FWD(field, ldInfo, bb2LoopMap);
1895 JSON_READ_FIELD_FWD(field, ldInfo, bb2PdomLevel);
1896 JSON_READ_FIELD_FWD(field, ldInfo, bb2PIdom);
1897
1899 "Extra field in SVFLoopAndDomInfo: " << JSON_KEY(field));
1900}
1901
1903{
1904 switch (var->getNodeKind())
1905 {
1906 default:
1907 assert(false && "Unknown SVFVar kind");
1908
1909#define CASE(VarKind, VarType) \
1910 case SVFVar::VarKind: \
1911 return fill(fieldJson, static_cast<VarType*>(var))
1912
1913 CASE(ValNode, ValVar);
1914 CASE(ObjNode, ObjVar);
1915 CASE(RetNode, RetPN);
1916 CASE(VarargNode, VarArgPN);
1917 CASE(GepValNode, GepValVar);
1918 CASE(GepObjNode, GepObjVar);
1919 CASE(BaseObjNode, BaseObjVar);
1920 CASE(DummyValNode, DummyValVar);
1921 CASE(DummyObjNode, DummyObjVar);
1922#undef CASE
1923 }
1924}
1925
1927{
1928 fill(fieldJson, static_cast<GenericPAGNodeTy*>(var));
1930 JSON_READ_FIELD_FWD(fieldJson, var, InEdgeKindToSetMap);
1931 JSON_READ_FIELD_FWD(fieldJson, var, OutEdgeKindToSetMap);
1933}
1934
1936{
1937 fill(fieldJson, static_cast<SVFVar*>(var));
1938}
1939
1941{
1942 fill(fieldJson, static_cast<SVFVar*>(var));
1944}
1945
1947{
1948 fill(fieldJson, static_cast<ValVar*>(var));
1950 JSON_READ_FIELD_FWD(fieldJson, var, gepValType);
1951}
1952
1954{
1955 fill(fieldJson, static_cast<ObjVar*>(var));
1956 JSON_READ_FIELD_FWD(fieldJson, var, apOffset);
1958}
1959
1961{
1962 fill(fieldJson, static_cast<ObjVar*>(var));
1963}
1964
1966{
1967 fill(fieldJson, static_cast<ValVar*>(var));
1968}
1969
1971{
1972 fill(fieldJson, static_cast<ValVar*>(var));
1973}
1974
1976{
1977 fill(fieldJson, static_cast<ValVar*>(var));
1978}
1979
1981{
1982 fill(fieldJson, static_cast<ObjVar*>(var));
1983}
1984
1986{
1987 auto kind = stmt->getEdgeKind();
1988
1989 switch (kind)
1990 {
1991 default:
1992 ABORT_MSG("Unknown SVFStmt kind " << kind);
1993
1994#define CASE(EdgeKind, EdgeType) \
1995 case SVFStmt::EdgeKind: \
1996 return fill(fieldJson, static_cast<EdgeType*>(stmt))
1997
1998 CASE(Addr, AddrStmt);
1999 CASE(Copy, CopyStmt);
2000 CASE(Store, StoreStmt);
2001 CASE(Load, LoadStmt);
2002 CASE(Call, CallPE);
2003 CASE(Ret, RetPE);
2004 CASE(Gep, GepStmt);
2005 CASE(Phi, PhiStmt);
2006 CASE(Select, SelectStmt);
2007 CASE(Cmp, CmpStmt);
2008 CASE(BinaryOp, BinaryOPStmt);
2009 CASE(UnaryOp, UnaryOPStmt);
2010 CASE(Branch, BranchStmt);
2011 CASE(ThreadFork, TDForkPE);
2012 CASE(ThreadJoin, TDJoinPE);
2013#undef CASE
2014 }
2015}
2016
2018{
2019 fill(fieldJson, static_cast<GenericPAGEdgeTy*>(stmt));
2021 JSON_READ_FIELD_FWD(fieldJson, stmt, basicBlock);
2024}
2025
2027{
2028 fill(fieldJson, static_cast<SVFStmt*>(stmt));
2029}
2030
2032{
2033 fill(fieldJson, static_cast<AssignStmt*>(stmt));
2034}
2035
2037{
2038 fill(fieldJson, static_cast<AssignStmt*>(stmt));
2040}
2041
2043{
2044 fill(fieldJson, static_cast<AssignStmt*>(stmt));
2045}
2046
2048{
2049 fill(fieldJson, static_cast<AssignStmt*>(stmt));
2050}
2051
2053{
2054 fill(fieldJson, static_cast<AssignStmt*>(stmt));
2056 JSON_READ_FIELD_FWD(fieldJson, stmt, variantField);
2057}
2058
2060{
2061 fill(fieldJson, static_cast<AssignStmt*>(stmt));
2064}
2065
2067{
2068 fill(fieldJson, static_cast<AssignStmt*>(stmt));
2071}
2072
2074{
2075 fill(fieldJson, static_cast<SVFStmt*>(stmt));
2077}
2078
2080{
2081 fill(fieldJson, static_cast<MultiOpndStmt*>(stmt));
2082 JSON_READ_FIELD_FWD(fieldJson, stmt, opICFGNodes);
2083}
2084
2086{
2087 fill(fieldJson, static_cast<MultiOpndStmt*>(stmt));
2088 JSON_READ_FIELD_FWD(fieldJson, stmt, condition);
2089}
2090
2092{
2093 fill(fieldJson, static_cast<MultiOpndStmt*>(stmt));
2094 JSON_READ_FIELD_FWD(fieldJson, stmt, predicate);
2095}
2096
2098{
2099 fill(fieldJson, static_cast<MultiOpndStmt*>(stmt));
2101}
2102
2104{
2105 fill(fieldJson, static_cast<SVFStmt*>(stmt));
2107}
2108
2110{
2111 fill(fieldJson, static_cast<SVFStmt*>(stmt));
2112 JSON_READ_FIELD_FWD(fieldJson, stmt, successors);
2115}
2116
2118{
2119 fill(fieldJson, static_cast<CallPE*>(stmt));
2120}
2121
2123{
2124 fill(fieldJson, static_cast<RetPE*>(stmt));
2125}
2126
2128{
2129 // symId has already been read
2132}
2133
2135{
2136#define F(field) JSON_READ_FIELD_FWD(fieldJson, stInfo, field)
2137 // stride has already been read upon construction
2138 F(numOfFlattenElements);
2139 F(numOfFlattenFields);
2140 F(fldIdxVec);
2141 F(elemIdxVec);
2142 F(fldIdx2TypeMap);
2143 F(finfo);
2144 F(flattenElementTypes);
2145#undef F
2146}
2147
2149{
2150 switch (node->getNodeKind())
2151 {
2152 default:
2153 ABORT_MSG("Unknown ICFGNode kind " << node->getNodeKind());
2154
2155#define CASE(NodeKind, NodeType) \
2156 case ICFGNode::NodeKind: \
2157 return fill(fieldJson, static_cast<NodeType*>(node))
2158
2159 CASE(IntraBlock, IntraICFGNode);
2160 CASE(FunEntryBlock, FunEntryICFGNode);
2161 CASE(FunExitBlock, FunExitICFGNode);
2162 CASE(FunCallBlock, CallICFGNode);
2163 CASE(FunRetBlock, RetICFGNode);
2164 CASE(GlobalBlock, GlobalICFGNode);
2165#undef CASE
2166 }
2167}
2168
2170{
2171 fill(fieldJson, static_cast<GenericICFGNodeTy*>(node));
2172 JSON_READ_FIELD_FWD(fieldJson, node, fun);
2173 JSON_READ_FIELD_FWD(fieldJson, node, bb);
2174 // Skip VFGNodes as it is empty
2175 JSON_READ_FIELD_FWD(fieldJson, node, pagEdges);
2176}
2177
2179{
2180 fill(fieldJson, static_cast<ICFGNode*>(node));
2181}
2182
2184{
2185 fill(fieldJson, static_cast<ICFGNode*>(node));
2186 JSON_READ_FIELD_FWD(fieldJson, node, isRet);
2187}
2188
2190{
2191 fill(fieldJson, static_cast<ICFGNode*>(node));
2192}
2193
2195{
2196 fill(fieldJson, static_cast<ICFGNode*>(node));
2197 JSON_READ_FIELD_FWD(fieldJson, node, FPNodes);
2198}
2199
2201{
2202 fill(fieldJson, static_cast<ICFGNode*>(node));
2203 JSON_READ_FIELD_FWD(fieldJson, node, formalRet);
2204}
2205
2207{
2208 fill(fieldJson, static_cast<ICFGNode*>(node));
2209 JSON_READ_FIELD_FWD(fieldJson, node, ret);
2210 JSON_READ_FIELD_FWD(fieldJson, node, APNodes);
2211}
2212
2214{
2215 fill(fieldJson, static_cast<ICFGNode*>(node));
2216 JSON_READ_FIELD_FWD(fieldJson, node, actualRet);
2217 JSON_READ_FIELD_FWD(fieldJson, node, callBlockNode);
2218}
2219
2221{
2222 auto kind = edge->getEdgeKind();
2223 switch (kind)
2224 {
2225 default:
2226 ABORT_MSG("Unknown ICFGEdge kind " << kind);
2227 case ICFGEdge::IntraCF:
2228 return fill(fieldJson, static_cast<IntraCFGEdge*>(edge));
2229 case ICFGEdge::CallCF:
2230 return fill(fieldJson, static_cast<CallCFGEdge*>(edge));
2231 case ICFGEdge::RetCF:
2232 return fill(fieldJson, static_cast<RetCFGEdge*>(edge));
2233 }
2234}
2235
2237{
2238 fill(fieldJson, static_cast<GenericICFGEdgeTy*>(edge));
2239}
2240
2242{
2243 fill(fieldJson, static_cast<ICFGEdge*>(edge));
2244 JSON_READ_FIELD_FWD(fieldJson, edge, conditionVar);
2245 JSON_READ_FIELD_FWD(fieldJson, edge, branchCondVal);
2246}
2247
2249{
2250 fill(fieldJson, static_cast<ICFGEdge*>(edge));
2252}
2253
2255{
2256 fill(fieldJson, static_cast<ICFGEdge*>(edge));
2258}
2259
2261{
2262#define F(field) JSON_READ_FIELD_FWD(fieldJson, loop, field)
2263 F(entryICFGEdges);
2264 F(backICFGEdges);
2265 F(inICFGEdges);
2266 F(outICFGEdges);
2267 F(icfgNodes);
2268 F(loopBound);
2269#undef F
2270}
2271
2273{
2274 assert(node->getNodeKind() == 0 && "Unknown CHNode kind");
2275 fill(fieldJson, static_cast<GenericCHNodeTy*>(node));
2276 JSON_READ_FIELD_FWD(fieldJson, node, vtable);
2277 JSON_READ_FIELD_FWD(fieldJson, node, className);
2278 JSON_READ_FIELD_FWD(fieldJson, node, flags);
2279 JSON_READ_FIELD_FWD(fieldJson, node, virtualFunctionVectors);
2280}
2281
2283{
2284 assert(edge->getEdgeKind() == 0 && "Unknown CHEdge kind");
2285 fill(fieldJson, static_cast<GenericCHEdgeTy*>(edge));
2286 // edgeType is a enum
2287 JSON_DEF_READ_FWD(fieldJson, unsigned, edgeType);
2288 if (edgeType == CHEdge::INHERITANCE)
2289 edge->edgeType = CHEdge::INHERITANCE;
2290 else if (edgeType == CHEdge::INSTANTCE)
2291 edge->edgeType = CHEdge::INSTANTCE;
2292 else
2293 ABORT_MSG("Unknown CHEdge type " << edgeType);
2294}
2295
2297{
2298 auto kind = value->getKind();
2299
2300 switch (kind)
2301 {
2302 default:
2303 ABORT_MSG("Impossible SVFValue kind " << kind);
2304
2305#define CASE(ValueKind, Type) \
2306 case SVFValue::ValueKind: \
2307 return fill(fieldJson, static_cast<Type*>(value))
2308
2309 CASE(SVFVal, SVFValue);
2310 CASE(SVFFunc, SVFFunction);
2311 CASE(SVFBB, SVFBasicBlock);
2312 CASE(SVFInst, SVFInstruction);
2313 CASE(SVFCall, SVFCallInst);
2314 CASE(SVFGlob, SVFGlobalValue);
2315 CASE(SVFArg, SVFArgument);
2316 CASE(SVFConst, SVFConstant);
2317 CASE(SVFConstData, SVFConstantData);
2318 CASE(SVFConstInt, SVFConstantInt);
2319 CASE(SVFConstFP, SVFConstantFP);
2320 CASE(SVFNullPtr, SVFConstantNullPtr);
2321 CASE(SVFBlackHole, SVFBlackHoleValue);
2322 CASE(SVFMetaAsValue, SVFMetadataAsValue);
2323 CASE(SVFOther, SVFOtherValue);
2324#undef CASE
2325 }
2326}
2327
2329{
2330 // kind, type, name have already been read.
2331 JSON_READ_FIELD_FWD(fieldJson, value, ptrInUncalledFun);
2332 JSON_READ_FIELD_FWD(fieldJson, value, constDataOrAggData);
2333 JSON_READ_FIELD_FWD(fieldJson, value, sourceLoc);
2334}
2335
2337{
2338 fill(fieldJson, static_cast<SVFValue*>(value));
2339#define F(f) JSON_READ_FIELD_FWD(fieldJson, value, f)
2340 F(isDecl);
2341 F(intrinsic);
2342 F(addrTaken);
2343 F(isUncalled);
2344 F(isNotRet);
2345 F(varArg);
2346 F(funcType);
2347 F(loopAndDom);
2348 F(realDefFun);
2349 F(allBBs);
2350 F(allArgs);
2351#undef F
2352}
2353
2355{
2356 fill(fieldJson, static_cast<SVFValue*>(value));
2357 JSON_READ_FIELD_FWD(fieldJson, value, succBBs);
2358 JSON_READ_FIELD_FWD(fieldJson, value, predBBs);
2359 JSON_READ_FIELD_FWD(fieldJson, value, fun);
2360}
2361
2363{
2364 fill(fieldJson, static_cast<SVFValue*>(value));
2365 JSON_READ_FIELD_FWD(fieldJson, value, bb);
2366 JSON_READ_FIELD_FWD(fieldJson, value, terminator);
2367 JSON_READ_FIELD_FWD(fieldJson, value, ret);
2368}
2369
2371{
2372 fill(fieldJson, static_cast<SVFInstruction*>(value));
2373 JSON_READ_FIELD_FWD(fieldJson, value, args);
2374 JSON_READ_FIELD_FWD(fieldJson, value, varArg);
2375 JSON_READ_FIELD_FWD(fieldJson, value, calledVal);
2376}
2377
2379{
2380 fill(fieldJson, static_cast<SVFValue*>(value));
2381}
2382
2384{
2385 fill(fieldJson, static_cast<SVFConstant*>(value));
2386 JSON_READ_FIELD_FWD(fieldJson, value, realDefGlobal);
2387}
2388
2390{
2391 fill(fieldJson, static_cast<SVFValue*>(value));
2392 JSON_READ_FIELD_FWD(fieldJson, value, fun);
2393 JSON_READ_FIELD_FWD(fieldJson, value, argNo);
2394 JSON_READ_FIELD_FWD(fieldJson, value, uncalled);
2395}
2396
2398{
2399 fill(fieldJson, static_cast<SVFConstant*>(value));
2400}
2401
2403{
2404 fill(fieldJson, static_cast<SVFConstantData*>(value));
2405 JSON_READ_FIELD_FWD(fieldJson, value, zval);
2406 JSON_READ_FIELD_FWD(fieldJson, value, sval);
2407}
2408
2410{
2411 fill(fieldJson, static_cast<SVFConstantData*>(value));
2412 JSON_READ_FIELD_FWD(fieldJson, value, dval);
2413}
2414
2416{
2417 fill(fieldJson, static_cast<SVFConstantData*>(value));
2418}
2419
2421{
2422 fill(fieldJson, static_cast<SVFConstantData*>(value));
2423}
2424
2426{
2427 fill(fieldJson, static_cast<SVFValue*>(value));
2428}
2429
2431{
2432 fill(fieldJson, static_cast<SVFOtherValue*>(value));
2433}
2434
2436{
2437 auto kind = type->getKind();
2438
2439 switch (kind)
2440 {
2441 default:
2442 assert(false && "Impossible SVFType kind");
2443
2444#define CASE(Kind) \
2445 case SVFType::Kind: \
2446 return fill(fieldJson, SVFUtil::dyn_cast<Kind##pe>(type))
2447
2448 CASE(SVFTy);
2449 CASE(SVFPointerTy);
2450 CASE(SVFIntegerTy);
2451 CASE(SVFFunctionTy);
2452 CASE(SVFStructTy);
2453 CASE(SVFArrayTy);
2454 CASE(SVFOtherTy);
2455#undef CASE
2456 }
2457}
2458
2460{
2461 // kind has already been read
2463}
2464
2466{
2467 fill(fieldJson, static_cast<SVFType*>(type));
2468}
2469
2471{
2472 fill(fieldJson, static_cast<SVFType*>(type));
2473 JSON_READ_FIELD_FWD(fieldJson, type, signAndWidth);
2474}
2475
2477{
2478 fill(fieldJson, static_cast<SVFType*>(type));
2480}
2481
2487
2489{
2490 fill(fieldJson, static_cast<SVFType*>(type));
2491 JSON_READ_FIELD_FWD(fieldJson, type, numOfElement);
2492 JSON_READ_FIELD_FWD(fieldJson, type, typeOfElement);
2493}
2494
2496{
2497 fill(fieldJson, static_cast<SVFType*>(type));
2499}
2500
2501SVFIR* SVFIRReader::read(const std::string& path)
2502{
2503 struct stat buf;
2504 int fd = open(path.c_str(), O_RDONLY);
2505 if (fd == -1)
2506 {
2507 std::string info = "open(\"" + path + "\")";
2508 perror(info.c_str());
2509 abort();
2510 }
2511 if (fstat(fd, &buf) == -1)
2512 {
2513 std::string info = "fstate(\"" + path + "\")";
2514 perror(info.c_str());
2515 abort();
2516 }
2517 auto addr =
2518 (char*)mmap(nullptr, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
2519 if (addr == MAP_FAILED)
2520 {
2521 std::string info = "mmap(content of \"" + path + "\")";
2522 perror(info.c_str());
2523 abort();
2524 }
2525
2526 auto root = cJSON_ParseWithLength(addr, buf.st_size);
2527
2528 if (munmap(addr, buf.st_size) == -1)
2529 perror("munmap()");
2530
2531 if (close(fd) < 0)
2532 perror("close()");
2533
2535 SVFIR* ir = reader.read(root);
2536
2537 cJSON_Delete(root);
2538 return ir;
2539}
2540
2541} // namespace SVF
#define ABORT_MSG(msg)
#define ABORT_IFNOT(condition, msg)
#define READ_CREATE_EDGE_FWD(GType)
#define CASE(Kind)
#define F(f)
static const Option< bool > humanReadableOption("human-readable", "Whether to output human-readable JSON", true)
#define READ_CREATE_NODE_FWD(GType)
#define JSON_READ_OBJ_FWD(json, obj)
#define FIELD_NAME_ITEM(field)
#define JSON_DEF_READ_FWD(json, type, obj,...)
#define JSON_READ_FIELD_FWD(json, objptr, field)
#define ENSURE_NOT_VISITED(graph)
#define CHECK_JSON_KEY(obj)
#define JSON_WRITE_FIELD(root, objptr, field)
#define JSON_KEY(json)
newitem type
Definition cJSON.cpp:2739
cJSON * n
Definition cJSON.cpp:2558
cJSON_Delete(null)
const char *const name
Definition cJSON.h:264
const char *const const double number
Definition cJSON.h:268
int index
Definition cJSON.h:170
cJSON * item
Definition cJSON.h:222
@ INHERITANCE
Definition CHG.h:86
@ INSTANTCE
Definition CHG.h:87
Common base for class hierarchy graph. Only implements what PointerAnalysis needs.
Definition CHG.h:51
EdgeTy * getEdgePtr(unsigned id) const
void createObjs(const cJSON *graphJson, NodeCreator nodeCreator, EdgeCreator edgeCreator)
void saveToGenericGraph(GenericGraph< NodeTy, EdgeTy > *graph) const
NodeTy * getNodePtr(unsigned id) const
const cJSON * getFieldJson() const
void fillObjs(NodeFiller nodeFiller, EdgeFiller edgeFiller)
size_t getEdgeID(const EdgeType *edge)
WriterPtrPool< EdgeType > edgePool
Class representing a heap object variable in the SVFIR.
VFGNodeList VFGNodes
Definition ICFGNode.h:150
SVFLoop * getSVFLoopPtr(size_t id) const
void fillObjs(NodeFiller nodeFiller, EdgeFiller edgeFiller, LoopFiller loopFiller)
void createObjs(const cJSON *icfgJson, NodeCreator nodeCreator, EdgeCreator edgeCreator, SVFLoopCreator svfLoopCreator)
WriterPtrPool< SVFLoop > svfLoopPool
size_t getSvfLoopID(const SVFLoop *loop)
ICFGWriter(const ICFG *icfg)
const ICFGNodeToSVFLoopVec & getIcfgNodeToSVFLoopVec() const
Definition ICFG.h:137
ValueToEdgeMap valueToEdgeMap
Map SVFValues (e.g., ICFGNodes) to all corresponding PAGEdges.
Definition IRGraph.h:64
SymbolTableInfo * symInfo
Definition IRGraph.h:65
static NodeIDAllocator * get(void)
Return (singleton) allocator.
static NodeIDAllocator * allocator
Single allocator.
Strategy
Allocation strategy to use.
GNodeK getNodeKind() const
Get node kind.
NodeID getId() const
Get ID.
IRGraphReader irGraphReader
SVFModuleReader svfModuleReader
static CHNode * createCHNode(NodeID id, GNodeK kind)
static ICFGEdge * createICFGEdge(GEdgeKind kind)
void fill(const cJSON *&fieldJson, SVFVar *var)
GenericEdge< void >::GEdgeKind GEdgeKind
static void readJson(const cJSON *obj, bool &flag)
static ICFGNode * createICFGNode(NodeID id, GNodeK type)
static CHEdge * createCHEdge(GEdgeKind kind)
static SVFStmt * createPAGEdge(GEdgeKind kind)
CHGraphReader chGraphReader
ICFGReader icfgReader
static SVFIR * read(const std::string &path)
const cJSON * createObjs(const cJSON *root)
static SVFVar * createPAGNode(NodeID id, GNodeK kind)
void virtFill(const cJSON *&fieldJson, SVFVar *var)
SymbolTableInfoReader symTableReader
const char * numToStr(size_t n)
static void writeJsonToOstream(const SVFIR *svfir, std::ostream &os)
std::unique_ptr< char, decltype(&cJSON_free)> autoCStr
static void writeJsonToPath(const SVFIR *svfir, const std::string &path)
const SVFIR * svfIR
std::unique_ptr< cJSON, decltype(&cJSON_Delete)> autoJSON
cJSON * genericGraphToJson(const GenericGraph< NodeTy, EdgeTy > *graph, const std::vector< const EdgeTy * > &edgePool)
OrderedMap< size_t, std::string > numToStrMap
cJSON * genericNodeToJson(const GenericNode< NodeTy, EdgeTy > *node)
autoJSON generateJson()
Main logic to dump a SVFIR to a JSON object.
cJSON * toJson(const NodeIDAllocator *nodeIDAllocator)
IRGraphWriter irGraphWriter
SVFIRWriter(const SVFIR *svfir)
Constructor.
SVFModuleWriter svfModuleWriter
cJSON * contentToJson(const SVFVar *var)
CHGraphWriter chgWriter
autoCStr generateJsonString()
ICFGWriter icfgWriter
cJSON * contentToJson(const SVFFunctionType *type)
bool jsonAddJsonableToObject(cJSON *obj, const char *name, const T &item)
cJSON * virtToJson(const SVFType *type)
Parameter types of these functions are all pointers. When they are used as arguments of toJson(),...
cJSON * genericEdgeToJson(const GenericEdge< NodeTy > *edge)
CommonCHGraph * chgraph
Definition SVFIR.h:100
SVFModule * svfModule
Definition SVFIR.h:98
ICFG * icfg
SVF Module.
Definition SVFIR.h:99
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
SVFType * getSVFTypePtr(size_t id) const
const cJSON * getFieldJson() const
StInfo * getStInfoPtr(size_t id) const
SVFValue * getSVFValuePtr(size_t id) const
ReaderPtrPool< StInfo > stInfoPool
void createObjs(const cJSON *svfModuleJson, SVFTypeCreator typeCreator, SVFTypeFiller typeFiller, SVFValueCreator valueCreator, SVFValueFiller valueFiller, StInfoCreator stInfoCreator)
ReaderPtrPool< SVFType > svfTypePool
size_t getSVFValueID(const SVFValue *value)
size_t sizeSVFValuePool() const
SVFModuleWriter(const SVFModule *svfModule)
WriterPtrPool< SVFValue > svfValuePool
size_t getStInfoID(const StInfo *stInfo)
size_t getSVFTypeID(const SVFType *type)
WriterPtrPool< StInfo > stInfoPool
WriterPtrPool< SVFType > svfTypePool
const SVFValue * getSVFValuePtr(size_t id) const
const OtherValueType & getOtherValueSet() const
Definition SVFModule.h:215
const FunctionSetType & getFunctionSet() const
Definition SVFModule.h:199
static SVFModule * getSVFModule()
Definition SVFModule.cpp:60
const ConstantType & getConstantSet() const
Definition SVFModule.h:203
s64_t GNodeK
Definition SVFType.h:163
GNodeK getKind() const
Get the type of this SVFValue.
Definition SVFValue.h:238
Represents a stack-allocated object variable in the SVFIR (SVF Intermediate Representation) @inherits...
ReaderIDToObjMap< MemObj > memObjMap
const cJSON * getFieldJson() const
void createObjs(const cJSON *symTabJson, MemObjCreator memObjCreator)
MemObj * getMemObjPtr(unsigned id) const
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis.
static SymbolTableInfo * symInfo
const std::vector< const T * > & getPool() const
std::ostream & errs()
Overwrite llvm::errs()
Definition SVFUtil.h:56
for isBitcode
Definition BasicTypes.h:68
bool jsonAddNumberToObject(cJSON *obj, const char *name, double number)
Helper function to write a number to a JSON object.
cJSON * jsonCreateNullId()
double jsonGetNumber(const cJSON *item)
static void readSmallNumber(const cJSON *obj, SmallNumberType &val)
cJSON * jsonCreateNumber(double num)
bool jsonKeyEquals(const cJSON *item, const char *key)
bool jsonIsNumber(const cJSON *item)
bool jsonIsNullId(const cJSON *item)
u32_t NodeID
Definition GeneralType.h:55
cJSON * jsonCreateMap()
bool jsonAddPairToMap(cJSON *obj, cJSON *key, cJSON *value)
bool jsonIsMap(const cJSON *item)
cJSON * jsonCreateBool(bool flag)
bool jsonIsArray(const cJSON *item)
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
bool jsonAddItemToArray(cJSON *array, cJSON *item)
static SVFValue * createSVFValue(SVFValue::GNodeK kind, const SVFType *type, std::string &&name)
bool jsonAddStringToObject(cJSON *obj, const char *name, const char *str)
std::pair< const cJSON *, const cJSON * > jsonUnpackPair(const cJSON *item)
bool jsonIsObject(const cJSON *item)
static void readBigNumber(const cJSON *obj, BigNumberType &val, CStrToVal conv)
cJSON * jsonCreateObject()
bool jsonAddItemToObject(cJSON *obj, const char *name, cJSON *item)
unsigned SymID
Definition GeneralType.h:57
unsigned u32_t
Definition GeneralType.h:46
bool jsonIsBool(const cJSON *item)
cJSON * jsonCreateString(const char *str)
bool jsonIsString(const cJSON *item)
cJSON * jsonCreateIndex(size_t index)
cJSON * jsonCreateArray()
SVFType * createSVFType(SVFType::GNodeK kind, bool isSingleValTy)
Definition cJSON.h:104
struct cJSON * child
Definition cJSON.h:109
double valuedouble
Definition cJSON.h:119
char * string
Definition cJSON.h:122
struct cJSON * next
Definition cJSON.h:106