Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
SVF::SVFIRWriter Class Reference

#include <SVFFileSystem.h>

Public Types

using autoJSON = std::unique_ptr< cJSON, decltype(&cJSON_Delete)>
 
using autoCStr = std::unique_ptr< char, decltype(&cJSON_free)>
 

Public Member Functions

 SVFIRWriter (const SVFIR *svfir)
 Constructor.
 

Static Public Member Functions

static void writeJsonToOstream (const SVFIR *svfir, std::ostream &os)
 
static void writeJsonToPath (const SVFIR *svfir, const std::string &path)
 

Private Member Functions

autoJSON generateJson ()
 Main logic to dump a SVFIR to a JSON object.
 
autoCStr generateJsonString ()
 
const charnumToStr (size_t n)
 
cJSONtoJson (const NodeIDAllocator *nodeIDAllocator)
 
cJSONtoJson (const SymbolTableInfo *symTable)
 
cJSONtoJson (const SVFModule *module)
 
cJSONtoJson (const SVFType *type)
 
cJSONtoJson (const SVFValue *value)
 
cJSONtoJson (const IRGraph *graph)
 
cJSONtoJson (const SVFVar *var)
 
cJSONtoJson (const SVFStmt *stmt)
 
cJSONtoJson (const ICFG *icfg)
 
cJSONtoJson (const ICFGNode *node)
 
cJSONtoJson (const ICFGEdge *edge)
 
cJSONtoJson (const CommonCHGraph *graph)
 
cJSONtoJson (const CHGraph *graph)
 
cJSONtoJson (const CHNode *node)
 
cJSONtoJson (const CHEdge *edge)
 
cJSONtoJson (const AccessPath &ap)
 
cJSONtoJson (const SVFLoop *loop)
 
cJSONtoJson (const MemObj *memObj)
 
cJSONtoJson (const ObjTypeInfo *objTypeInfo)
 
cJSONtoJson (const SVFLoopAndDomInfo *ldInfo)
 
cJSONtoJson (const StInfo *stInfo)
 
cJSONtoJson (unsigned long number)
 
cJSONtoJson (long long number)
 
cJSONtoJson (unsigned long long number)
 
template<typename NodeTy , typename EdgeTy >
cJSONgenericNodeToJson (const GenericNode< NodeTy, EdgeTy > *node)
 
template<typename NodeTy >
cJSONgenericEdgeToJson (const GenericEdge< NodeTy > *edge)
 
template<typename NodeTy , typename EdgeTy >
cJSONgenericGraphToJson (const GenericGraph< NodeTy, EdgeTy > *graph, const std::vector< const EdgeTy * > &edgePool)
 
template<typename T , typename U >
cJSONtoJson (const std::pair< T, U > &pair)
 
template<typename T , typename = std::enable_if_t<SVFUtil::is_iterable_v<T>>>
cJSONtoJson (const T &container)
 
template<typename T >
bool jsonAddJsonableToObject (cJSON *obj, const char *name, const T &item)
 
template<typename T >
bool jsonAddContentToObject (cJSON *obj, const char *name, const T &item)
 
cJSONvirtToJson (const SVFType *type)
 Parameter types of these functions are all pointers. When they are used as arguments of toJson(), they will be dumped as an index. contentToJson() will dump the actual content.
 
cJSONvirtToJson (const SVFValue *value)
 
cJSONvirtToJson (const SVFVar *var)
 
cJSONvirtToJson (const SVFStmt *stmt)
 
cJSONvirtToJson (const ICFGNode *node)
 
cJSONvirtToJson (const ICFGEdge *edge)
 
cJSONvirtToJson (const CHNode *node)
 
cJSONvirtToJson (const CHEdge *edge)
 
cJSONcontentToJson (const SVFVar *var)
 
cJSONcontentToJson (const ValVar *var)
 
cJSONcontentToJson (const ObjVar *var)
 
cJSONcontentToJson (const GepValVar *var)
 
cJSONcontentToJson (const GepObjVar *var)
 
cJSONcontentToJson (const BaseObjVar *var)
 
cJSONcontentToJson (const RetPN *var)
 
cJSONcontentToJson (const VarArgPN *var)
 
cJSONcontentToJson (const DummyValVar *var)
 
cJSONcontentToJson (const DummyObjVar *var)
 
cJSONcontentToJson (const SVFStmt *edge)
 
cJSONcontentToJson (const AssignStmt *edge)
 
cJSONcontentToJson (const AddrStmt *edge)
 
cJSONcontentToJson (const CopyStmt *edge)
 
cJSONcontentToJson (const StoreStmt *edge)
 
cJSONcontentToJson (const LoadStmt *edge)
 
cJSONcontentToJson (const GepStmt *edge)
 
cJSONcontentToJson (const CallPE *edge)
 
cJSONcontentToJson (const RetPE *edge)
 
cJSONcontentToJson (const MultiOpndStmt *edge)
 
cJSONcontentToJson (const PhiStmt *edge)
 
cJSONcontentToJson (const SelectStmt *edge)
 
cJSONcontentToJson (const CmpStmt *edge)
 
cJSONcontentToJson (const BinaryOPStmt *edge)
 
cJSONcontentToJson (const UnaryOPStmt *edge)
 
cJSONcontentToJson (const BranchStmt *edge)
 
cJSONcontentToJson (const TDForkPE *edge)
 
cJSONcontentToJson (const TDJoinPE *edge)
 
cJSONcontentToJson (const ICFGNode *node)
 
cJSONcontentToJson (const GlobalICFGNode *node)
 
cJSONcontentToJson (const IntraICFGNode *node)
 
cJSONcontentToJson (const InterICFGNode *node)
 
cJSONcontentToJson (const FunEntryICFGNode *node)
 
cJSONcontentToJson (const FunExitICFGNode *node)
 
cJSONcontentToJson (const CallICFGNode *node)
 
cJSONcontentToJson (const RetICFGNode *node)
 
cJSONcontentToJson (const ICFGEdge *edge)
 
cJSONcontentToJson (const IntraCFGEdge *edge)
 
cJSONcontentToJson (const CallCFGEdge *edge)
 
cJSONcontentToJson (const RetCFGEdge *edge)
 
cJSONcontentToJson (const CHNode *node)
 
cJSONcontentToJson (const CHEdge *edge)
 
cJSONcontentToJson (const SVFType *type)
 
cJSONcontentToJson (const SVFPointerType *type)
 
cJSONcontentToJson (const SVFIntegerType *type)
 
cJSONcontentToJson (const SVFFunctionType *type)
 
cJSONcontentToJson (const SVFStructType *type)
 
cJSONcontentToJson (const SVFArrayType *type)
 
cJSONcontentToJson (const SVFOtherType *type)
 
cJSONcontentToJson (const SVFValue *value)
 
cJSONcontentToJson (const SVFFunction *value)
 
cJSONcontentToJson (const SVFBasicBlock *value)
 
cJSONcontentToJson (const SVFInstruction *value)
 
cJSONcontentToJson (const SVFCallInst *value)
 
cJSONcontentToJson (const SVFConstant *value)
 
cJSONcontentToJson (const SVFGlobalValue *value)
 
cJSONcontentToJson (const SVFArgument *value)
 
cJSONcontentToJson (const SVFConstantData *value)
 
cJSONcontentToJson (const SVFConstantInt *value)
 
cJSONcontentToJson (const SVFConstantFP *value)
 
cJSONcontentToJson (const SVFConstantNullPtr *value)
 
cJSONcontentToJson (const SVFBlackHoleValue *value)
 
cJSONcontentToJson (const SVFOtherValue *value)
 
cJSONcontentToJson (const SVFMetadataAsValue *value)
 
cJSONcontentToJson (const SVFLoop *loop)
 
cJSONcontentToJson (const MemObj *memObj)
 
cJSONcontentToJson (const StInfo *stInfo)
 

Static Private Member Functions

static cJSONtoJson (bool flag)
 
static cJSONtoJson (unsigned number)
 
static cJSONtoJson (int number)
 
static cJSONtoJson (float number)
 
static cJSONtoJson (const std::string &str)
 

Private Attributes

const SVFIRsvfIR
 
SVFModuleWriter svfModuleWriter
 
ICFGWriter icfgWriter
 
CHGraphWriter chgWriter
 
IRGraphWriter irGraphWriter
 
OrderedMap< size_t, std::string > numToStrMap
 

Detailed Description

Definition at line 378 of file SVFFileSystem.h.

Member Typedef Documentation

◆ autoCStr

Definition at line 392 of file SVFFileSystem.h.

◆ autoJSON

Definition at line 391 of file SVFFileSystem.h.

Constructor & Destructor Documentation

◆ SVFIRWriter()

SVF::SVFIRWriter::SVFIRWriter ( const SVFIR svfir)

Constructor.

Definition at line 976 of file SVFFileSystem.cpp.

977 : svfIR(svfir), svfModuleWriter(svfir->svfModule), icfgWriter(svfir->icfg),
978 chgWriter(SVFUtil::dyn_cast<CHGraph>(svfir->chgraph)),
979 irGraphWriter(svfir)
980{
981}
const SVFIR * svfIR
IRGraphWriter irGraphWriter
SVFModuleWriter svfModuleWriter
CHGraphWriter chgWriter
ICFGWriter icfgWriter

Member Function Documentation

◆ contentToJson() [1/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const AddrStmt edge)
private

Definition at line 672 of file SVFFileSystem.cpp.

673{
674 return contentToJson(static_cast<const AssignStmt*>(edge));
675}
cJSON * contentToJson(const SVFVar *var)
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ contentToJson() [2/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const AssignStmt edge)
private

Definition at line 667 of file SVFFileSystem.cpp.

668{
669 return contentToJson(static_cast<const SVFStmt*>(edge));
670}

◆ contentToJson() [3/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const BaseObjVar var)
private

Definition at line 346 of file SVFFileSystem.cpp.

347{
348 return contentToJson(static_cast<const ObjVar*>(var));
349}

◆ contentToJson() [4/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const BinaryOPStmt edge)
private

Definition at line 746 of file SVFFileSystem.cpp.

747{
748 cJSON* root = contentToJson(static_cast<const MultiOpndStmt*>(edge));
749 JSON_WRITE_FIELD(root, edge, opcode);
750 return root;
751}
#define JSON_WRITE_FIELD(root, objptr, field)
Definition cJSON.h:104

◆ contentToJson() [5/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const BranchStmt edge)
private

Definition at line 760 of file SVFFileSystem.cpp.

761{
762 cJSON* root = contentToJson(static_cast<const SVFStmt*>(edge));
763 JSON_WRITE_FIELD(root, edge, successors);
764 JSON_WRITE_FIELD(root, edge, cond);
765 JSON_WRITE_FIELD(root, edge, brInst);
766 return root;
767}

◆ contentToJson() [6/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const CallCFGEdge edge)
private

Definition at line 442 of file SVFFileSystem.cpp.

443{
444 cJSON* root = contentToJson(static_cast<const ICFGEdge*>(edge));
445 JSON_WRITE_FIELD(root, edge, callPEs);
446 return root;
447}

◆ contentToJson() [7/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const CallICFGNode node)
private

Definition at line 413 of file SVFFileSystem.cpp.

414{
415 cJSON* root = contentToJson(static_cast<const ICFGNode*>(node));
416 JSON_WRITE_FIELD(root, node, ret);
417 JSON_WRITE_FIELD(root, node, APNodes);
418 return root;
419}

◆ contentToJson() [8/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const CallPE edge)
private

Definition at line 702 of file SVFFileSystem.cpp.

703{
704 cJSON* root = contentToJson(static_cast<const AssignStmt*>(edge));
705 JSON_WRITE_FIELD(root, edge, call);
706 JSON_WRITE_FIELD(root, edge, entry);
707 return root;
708}

◆ contentToJson() [9/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const CHEdge edge)
private

Definition at line 466 of file SVFFileSystem.cpp.

467{
469 JSON_WRITE_FIELD(root, edge, edgeType);
470 return root;
471}
cJSON * genericEdgeToJson(const GenericEdge< NodeTy > *edge)

◆ contentToJson() [10/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const CHNode node)
private

Definition at line 456 of file SVFFileSystem.cpp.

457{
458 cJSON* root = genericNodeToJson(node);
459 JSON_WRITE_FIELD(root, node, vtable);
460 JSON_WRITE_FIELD(root, node, className);
461 JSON_WRITE_FIELD(root, node, flags);
462 JSON_WRITE_FIELD(root, node, virtualFunctionVectors);
463 return root;
464}
cJSON * genericNodeToJson(const GenericNode< NodeTy, EdgeTy > *node)

◆ contentToJson() [11/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const CmpStmt edge)
private

Definition at line 739 of file SVFFileSystem.cpp.

740{
741 cJSON* root = contentToJson(static_cast<const MultiOpndStmt*>(edge));
742 JSON_WRITE_FIELD(root, edge, predicate);
743 return root;
744}

◆ contentToJson() [12/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const CopyStmt edge)
private

Definition at line 677 of file SVFFileSystem.cpp.

678{
679 cJSON* root = contentToJson(static_cast<const AssignStmt*>(edge));
680 JSON_WRITE_FIELD(root, edge, copyKind);
681 return root;
682}

◆ contentToJson() [13/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const DummyObjVar var)
private

Definition at line 366 of file SVFFileSystem.cpp.

367{
368 return contentToJson(static_cast<const ObjVar*>(var));
369}

◆ contentToJson() [14/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const DummyValVar var)
private

Definition at line 361 of file SVFFileSystem.cpp.

362{
363 return contentToJson(static_cast<const ValVar*>(var));
364}

◆ contentToJson() [15/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const FunEntryICFGNode node)
private

Definition at line 399 of file SVFFileSystem.cpp.

400{
401 cJSON* root = contentToJson(static_cast<const ICFGNode*>(node));
402 JSON_WRITE_FIELD(root, node, FPNodes);
403 return root;
404}

◆ contentToJson() [16/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const FunExitICFGNode node)
private

Definition at line 406 of file SVFFileSystem.cpp.

407{
408 cJSON* root = contentToJson(static_cast<const ICFGNode*>(node));
409 JSON_WRITE_FIELD(root, node, formalRet);
410 return root;
411}

◆ contentToJson() [17/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const GepObjVar var)
private

Definition at line 338 of file SVFFileSystem.cpp.

339{
340 cJSON* root = contentToJson(static_cast<const ObjVar*>(var));
341 JSON_WRITE_FIELD(root, var, apOffset);
342 JSON_WRITE_FIELD(root, var, base);
343 return root;
344}

◆ contentToJson() [18/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const GepStmt edge)
private

Definition at line 694 of file SVFFileSystem.cpp.

695{
696 cJSON* root = contentToJson(static_cast<const AssignStmt*>(edge));
697 JSON_WRITE_FIELD(root, edge, ap);
698 JSON_WRITE_FIELD(root, edge, variantField);
699 return root;
700}

◆ contentToJson() [19/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const GepValVar var)
private

Definition at line 330 of file SVFFileSystem.cpp.

331{
332 cJSON* root = contentToJson(static_cast<const ValVar*>(var));
333 JSON_WRITE_FIELD(root, var, ap);
334 JSON_WRITE_FIELD(root, var, gepValType);
335 return root;
336}

◆ contentToJson() [20/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const GlobalICFGNode node)
private

Definition at line 382 of file SVFFileSystem.cpp.

383{
384 return contentToJson(static_cast<const ICFGNode*>(node));
385}

◆ contentToJson() [21/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const ICFGEdge edge)
private

Definition at line 429 of file SVFFileSystem.cpp.

430{
431 return genericEdgeToJson(edge);
432}

◆ contentToJson() [22/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const ICFGNode node)
private

Definition at line 371 of file SVFFileSystem.cpp.

372{
373 cJSON* root = genericNodeToJson(node);
374 JSON_WRITE_FIELD(root, node, fun);
375 JSON_WRITE_FIELD(root, node, bb);
376 // TODO: Ensure this?
377 assert(node->VFGNodes.empty() && "VFGNodes list not empty?");
378 JSON_WRITE_FIELD(root, node, pagEdges);
379 return root;
380}

◆ contentToJson() [23/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const InterICFGNode node)
private

Definition at line 394 of file SVFFileSystem.cpp.

395{
396 return contentToJson(static_cast<const ICFGNode*>(node));
397}

◆ contentToJson() [24/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const IntraCFGEdge edge)
private

Definition at line 434 of file SVFFileSystem.cpp.

435{
436 cJSON* root = contentToJson(static_cast<const ICFGEdge*>(edge));
437 JSON_WRITE_FIELD(root, edge, conditionVar);
438 JSON_WRITE_FIELD(root, edge, branchCondVal);
439 return root;
440}

◆ contentToJson() [25/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const IntraICFGNode node)
private

Definition at line 387 of file SVFFileSystem.cpp.

388{
389 cJSON* root = contentToJson(static_cast<const ICFGNode*>(node));
390 JSON_WRITE_FIELD(root, node, isRet);
391 return root;
392}

◆ contentToJson() [26/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const LoadStmt edge)
private

Definition at line 689 of file SVFFileSystem.cpp.

690{
691 return contentToJson(static_cast<const AssignStmt*>(edge));
692}

◆ contentToJson() [27/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const MemObj memObj)
private

Definition at line 1169 of file SVFFileSystem.cpp.

1170{
1171 cJSON* root = jsonCreateObject();
1172 JSON_WRITE_FIELD(root, memObj, symId);
1173 JSON_WRITE_FIELD(root, memObj, typeInfo);
1174 JSON_WRITE_FIELD(root, memObj, refVal);
1175 return root;
1176}
cJSON * jsonCreateObject()

◆ contentToJson() [28/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const MultiOpndStmt edge)
private

Definition at line 718 of file SVFFileSystem.cpp.

719{
720 cJSON* root = contentToJson(static_cast<const SVFStmt*>(edge));
721 JSON_WRITE_FIELD(root, edge, opVars);
722 return root;
723}

◆ contentToJson() [29/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const ObjVar var)
private

Definition at line 323 of file SVFFileSystem.cpp.

324{
325 cJSON* root = contentToJson(static_cast<const SVFVar*>(var));
326 JSON_WRITE_FIELD(root, var, mem);
327 return root;
328}

◆ contentToJson() [30/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const PhiStmt edge)
private

Definition at line 725 of file SVFFileSystem.cpp.

726{
727 cJSON* root = contentToJson(static_cast<const MultiOpndStmt*>(edge));
728 JSON_WRITE_FIELD(root, edge, opICFGNodes);
729 return root;
730}

◆ contentToJson() [31/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const RetCFGEdge edge)
private

Definition at line 449 of file SVFFileSystem.cpp.

450{
451 cJSON* root = contentToJson(static_cast<const ICFGEdge*>(edge));
452 JSON_WRITE_FIELD(root, edge, retPE);
453 return root;
454}

◆ contentToJson() [32/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const RetICFGNode node)
private

Definition at line 421 of file SVFFileSystem.cpp.

422{
423 cJSON* root = contentToJson(static_cast<const ICFGNode*>(node));
424 JSON_WRITE_FIELD(root, node, actualRet);
425 JSON_WRITE_FIELD(root, node, callBlockNode);
426 return root;
427}

◆ contentToJson() [33/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const RetPE edge)
private

Definition at line 710 of file SVFFileSystem.cpp.

711{
712 cJSON* root = contentToJson(static_cast<const AssignStmt*>(edge));
713 JSON_WRITE_FIELD(root, edge, call);
714 JSON_WRITE_FIELD(root, edge, exit);
715 return root;
716}

◆ contentToJson() [34/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const RetPN var)
private

Definition at line 351 of file SVFFileSystem.cpp.

352{
353 return contentToJson(static_cast<const ValVar*>(var));
354}

◆ contentToJson() [35/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SelectStmt edge)
private

Definition at line 732 of file SVFFileSystem.cpp.

733{
734 cJSON* root = contentToJson(static_cast<const MultiOpndStmt*>(edge));
735 JSON_WRITE_FIELD(root, edge, condition);
736 return root;
737}

◆ contentToJson() [36/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const StInfo stInfo)
private

Definition at line 1178 of file SVFFileSystem.cpp.

1179{
1180 cJSON* root = jsonCreateObject();
1181#define F(field) JSON_WRITE_FIELD(root, stInfo, field)
1182 F(stride);
1183 F(numOfFlattenElements);
1184 F(numOfFlattenFields);
1185 F(fldIdxVec);
1186 F(elemIdxVec);
1187 F(fldIdx2TypeMap);
1188 F(finfo);
1189 F(flattenElementTypes);
1190#undef F
1191 return root;
1192}
#define F(f)

◆ contentToJson() [37/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const StoreStmt edge)
private

Definition at line 684 of file SVFFileSystem.cpp.

685{
686 return contentToJson(static_cast<const AssignStmt*>(edge));
687}

◆ contentToJson() [38/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFArgument value)
private

Definition at line 594 of file SVFFileSystem.cpp.

595{
596 cJSON* root = contentToJson(static_cast<const SVFValue*>(value));
597 JSON_WRITE_FIELD(root, value, fun);
598 JSON_WRITE_FIELD(root, value, argNo);
599 JSON_WRITE_FIELD(root, value, uncalled);
600 return root;
601}

◆ contentToJson() [39/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFArrayType type)
private

Definition at line 509 of file SVFFileSystem.cpp.

510{
511 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
512 JSON_WRITE_FIELD(root, type, numOfElement);
513 JSON_WRITE_FIELD(root, type, typeOfElement);
514 return root;
515}
newitem type
Definition cJSON.cpp:2739

◆ contentToJson() [40/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFBasicBlock value)
private

Definition at line 555 of file SVFFileSystem.cpp.

556{
557 cJSON* root = contentToJson(static_cast<const SVFValue*>(value));
558 JSON_WRITE_FIELD(root, value, succBBs);
559 JSON_WRITE_FIELD(root, value, predBBs);
560 JSON_WRITE_FIELD(root, value, fun);
561 return root;
562}

◆ contentToJson() [41/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFBlackHoleValue value)
private

Definition at line 628 of file SVFFileSystem.cpp.

629{
630 return contentToJson(static_cast<const SVFConstantData*>(value));
631}

◆ contentToJson() [42/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFCallInst value)
private

Definition at line 573 of file SVFFileSystem.cpp.

574{
575 cJSON* root = contentToJson(static_cast<const SVFInstruction*>(value));
576 JSON_WRITE_FIELD(root, value, args);
577 JSON_WRITE_FIELD(root, value, varArg);
578 JSON_WRITE_FIELD(root, value, calledVal);
579 return root;
580}

◆ contentToJson() [43/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFConstant value)
private

Definition at line 582 of file SVFFileSystem.cpp.

583{
584 return contentToJson(static_cast<const SVFValue*>(value));
585}

◆ contentToJson() [44/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFConstantData value)
private

Definition at line 603 of file SVFFileSystem.cpp.

604{
605 return contentToJson(static_cast<const SVFConstant*>(value));
606}

◆ contentToJson() [45/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFConstantFP value)
private

Definition at line 616 of file SVFFileSystem.cpp.

617{
618 cJSON* root = contentToJson(static_cast<const SVFConstantData*>(value));
619 JSON_WRITE_FIELD(root, value, dval);
620 return root;
621}

◆ contentToJson() [46/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFConstantInt value)
private

Definition at line 608 of file SVFFileSystem.cpp.

609{
610 cJSON* root = contentToJson(static_cast<const SVFConstantData*>(value));
611 JSON_WRITE_FIELD(root, value, zval);
612 JSON_WRITE_FIELD(root, value, sval);
613 return root;
614}

◆ contentToJson() [47/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFConstantNullPtr value)
private

Definition at line 623 of file SVFFileSystem.cpp.

624{
625 return contentToJson(static_cast<const SVFConstantData*>(value));
626}

◆ contentToJson() [48/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFFunction value)
private

Definition at line 536 of file SVFFileSystem.cpp.

537{
538 cJSON* root = contentToJson(static_cast<const SVFValue*>(value));
539#define F(f) JSON_WRITE_FIELD(root, value, f);
540 F(isDecl);
541 F(intrinsic);
542 F(addrTaken);
543 F(isUncalled);
544 F(isNotRet);
545 F(varArg);
546 F(funcType);
547 F(loopAndDom);
548 F(realDefFun);
549 F(allBBs);
550 F(allArgs);
551#undef F
552 return root;
553}

◆ contentToJson() [49/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFFunctionType type)
private

Definition at line 495 of file SVFFileSystem.cpp.

496{
497 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
498 JSON_WRITE_FIELD(root, type, retTy);
499 return root;
500}

◆ contentToJson() [50/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFGlobalValue value)
private

Definition at line 587 of file SVFFileSystem.cpp.

588{
589 cJSON* root = contentToJson(static_cast<const SVFConstant*>(value));
590 JSON_WRITE_FIELD(root, value, realDefGlobal);
591 return root;
592}

◆ contentToJson() [51/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFInstruction value)
private

Definition at line 564 of file SVFFileSystem.cpp.

565{
566 cJSON* root = contentToJson(static_cast<const SVFValue*>(value));
567 JSON_WRITE_FIELD(root, value, bb);
568 JSON_WRITE_FIELD(root, value, terminator);
569 JSON_WRITE_FIELD(root, value, ret);
570 return root;
571}

◆ contentToJson() [52/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFIntegerType type)
private

Definition at line 488 of file SVFFileSystem.cpp.

489{
490 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
491 JSON_WRITE_FIELD(root, type, signAndWidth);
492 return root;
493}

◆ contentToJson() [53/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFLoop loop)
private

Definition at line 653 of file SVFFileSystem.cpp.

654{
655 cJSON* root = jsonCreateObject();
656#define F(field) JSON_WRITE_FIELD(root, loop, field)
657 F(entryICFGEdges);
658 F(backICFGEdges);
659 F(inICFGEdges);
660 F(outICFGEdges);
661 F(icfgNodes);
662 F(loopBound);
663#undef F
664 return root;
665}

◆ contentToJson() [54/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFMetadataAsValue value)
private

Definition at line 638 of file SVFFileSystem.cpp.

639{
640 return contentToJson(static_cast<const SVFOtherValue*>(value));
641}

◆ contentToJson() [55/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFOtherType type)
private

Definition at line 517 of file SVFFileSystem.cpp.

518{
519 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
520 JSON_WRITE_FIELD(root, type, repr);
521 return root;
522}

◆ contentToJson() [56/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFOtherValue value)
private

Definition at line 633 of file SVFFileSystem.cpp.

634{
635 return contentToJson(static_cast<const SVFValue*>(value));
636}

◆ contentToJson() [57/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFPointerType type)
private

Definition at line 482 of file SVFFileSystem.cpp.

483{
484 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
485 return root;
486}

◆ contentToJson() [58/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFStmt edge)
private

Definition at line 643 of file SVFFileSystem.cpp.

644{
646 JSON_WRITE_FIELD(root, edge, value);
647 JSON_WRITE_FIELD(root, edge, basicBlock);
648 JSON_WRITE_FIELD(root, edge, icfgNode);
649 JSON_WRITE_FIELD(root, edge, edgeId);
650 return root;
651}

◆ contentToJson() [59/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFStructType type)
private

Definition at line 502 of file SVFFileSystem.cpp.

503{
504 cJSON* root = contentToJson(static_cast<const SVFType*>(type));
505 JSON_WRITE_FIELD(root, type, name);
506 return root;
507}
const char *const name
Definition cJSON.h:264

◆ contentToJson() [60/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFType type)
private

Definition at line 473 of file SVFFileSystem.cpp.

474{
475 cJSON* root = jsonCreateObject();
476 JSON_WRITE_FIELD(root, type, kind);
477 JSON_WRITE_FIELD(root, type, isSingleValTy);
478 JSON_WRITE_FIELD(root, type, typeinfo);
479 return root;
480}

◆ contentToJson() [61/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFValue value)
private

Definition at line 524 of file SVFFileSystem.cpp.

525{
526 cJSON* root = jsonCreateObject();
527 JSON_WRITE_FIELD(root, value, kind);
528 JSON_WRITE_FIELD(root, value, type);
529 JSON_WRITE_FIELD(root, value, name);
530 JSON_WRITE_FIELD(root, value, ptrInUncalledFun);
531 JSON_WRITE_FIELD(root, value, constDataOrAggData);
532 JSON_WRITE_FIELD(root, value, sourceLoc);
533 return root;
534}

◆ contentToJson() [62/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFVar var)
private

Definition at line 308 of file SVFFileSystem.cpp.

309{
310 cJSON* root = genericNodeToJson(var);
311 JSON_WRITE_FIELD(root, var, value);
312 JSON_WRITE_FIELD(root, var, InEdgeKindToSetMap);
313 JSON_WRITE_FIELD(root, var, OutEdgeKindToSetMap);
314 JSON_WRITE_FIELD(root, var, isPtr);
315 return root;
316}

◆ contentToJson() [63/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const TDForkPE edge)
private

Definition at line 769 of file SVFFileSystem.cpp.

770{
771 return contentToJson(static_cast<const CallPE*>(edge));
772}

◆ contentToJson() [64/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const TDJoinPE edge)
private

Definition at line 774 of file SVFFileSystem.cpp.

775{
776 return contentToJson(static_cast<const RetPE*>(edge));
777}

◆ contentToJson() [65/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const UnaryOPStmt edge)
private

Definition at line 753 of file SVFFileSystem.cpp.

754{
755 cJSON* root = contentToJson(static_cast<const SVFStmt*>(edge));
756 JSON_WRITE_FIELD(root, edge, opcode);
757 return root;
758}

◆ contentToJson() [66/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const ValVar var)
private

Definition at line 318 of file SVFFileSystem.cpp.

319{
320 return contentToJson(static_cast<const SVFVar*>(var));
321}

◆ contentToJson() [67/67]

cJSON * SVF::SVFIRWriter::contentToJson ( const VarArgPN var)
private

Definition at line 356 of file SVFFileSystem.cpp.

357{
358 return contentToJson(static_cast<const ValVar*>(var));
359}

◆ generateJson()

SVFIRWriter::autoJSON SVF::SVFIRWriter::generateJson ( )
private

Main logic to dump a SVFIR to a JSON object.

Definition at line 1022 of file SVFFileSystem.cpp.

1023{
1024 const IRGraph* const irGraph = svfIR;
1026 assert(nodeIDAllocator && "NodeIDAllocator is not initialized?");
1027
1028 cJSON* root = jsonCreateObject();
1029#define F(field) JSON_WRITE_FIELD(root, svfIR, field)
1030 F(svfModule);
1031 F(symInfo);
1032 F(icfg);
1033 F(chgraph);
1035 F(icfgNode2SVFStmtsMap);
1036 F(icfgNode2PTASVFStmtsMap);
1037 F(GepValObjMap);
1038 F(typeLocSetsMap);
1039 F(GepObjVarMap);
1040 F(memToFieldsMap);
1041 F(globSVFStmtSet);
1042 F(phiNodeMap);
1043 F(funArgsListMap);
1044 F(callSiteArgsListMap);
1045 F(callSiteRetMap);
1046 F(funRetMap);
1047 F(indCallSiteToFunPtrMap);
1048 F(funPtrToCallSitesMap);
1049 F(candidatePointers);
1050 F(callSiteSet);
1052#undef F
1053
1054 return {root, cJSON_Delete};
1055}
#define FIELD_NAME_ITEM(field)
cJSON_Delete(null)
static NodeIDAllocator * allocator
Single allocator.
bool jsonAddJsonableToObject(cJSON *obj, const char *name, const T &item)

◆ generateJsonString()

SVFIRWriter::autoCStr SVF::SVFIRWriter::generateJsonString ( )
private

Definition at line 1014 of file SVFFileSystem.cpp.

1015{
1016 autoJSON object = generateJson();
1017 char* str = humanReadableOption() ? cJSON_Print(object.get())
1018 : cJSON_PrintUnformatted(object.get());
1019 return {str, cJSON_free};
1020}
static const Option< bool > humanReadableOption("human-readable", "Whether to output human-readable JSON", true)
std::unique_ptr< cJSON, decltype(&cJSON_Delete)> autoJSON
autoJSON generateJson()
Main logic to dump a SVFIR to a JSON object.

◆ genericEdgeToJson()

template<typename NodeTy >
cJSON * SVF::SVFIRWriter::genericEdgeToJson ( const GenericEdge< NodeTy > *  edge)
inlineprivate

Definition at line 547 of file SVFFileSystem.h.

548 {
549 cJSON* root = jsonCreateObject();
550 JSON_WRITE_FIELD(root, edge, edgeFlag);
551 JSON_WRITE_FIELD(root, edge, src);
552 JSON_WRITE_FIELD(root, edge, dst);
553 return root;
554 }

◆ genericGraphToJson()

cJSON * SVF::SVFIRWriter::genericGraphToJson ( const GenericGraph< NodeTy, EdgeTy > *  graph,
const std::vector< const EdgeTy * > &  edgePool 
)
inlineprivate

Definition at line 557 of file SVFFileSystem.h.

559 {
560 cJSON* root = jsonCreateObject();
561
563 for (const auto& pair : graph->IDToNodeMap)
564 {
565 NodeTy* node = pair.second;
566 cJSON* jsonNode = virtToJson(node);
568 }
569
571 for (const EdgeTy* edge : edgePool)
572 {
575 }
576
577 JSON_WRITE_FIELD(root, graph, nodeNum);
579 JSON_WRITE_FIELD(root, graph, edgeNum);
581
582 return root;
583 }
cJSON * virtToJson(const SVFType *type)
Parameter types of these functions are all pointers. When they are used as arguments of toJson(),...
bool jsonAddItemToArray(cJSON *array, cJSON *item)
bool jsonAddItemToObject(cJSON *obj, const char *name, cJSON *item)
cJSON * jsonCreateArray()

◆ genericNodeToJson()

cJSON * SVF::SVFIRWriter::genericNodeToJson ( const GenericNode< NodeTy, EdgeTy > *  node)
inlineprivate

Definition at line 536 of file SVFFileSystem.h.

537 {
538 cJSON* root = jsonCreateObject();
539 JSON_WRITE_FIELD(root, node, id);
540 JSON_WRITE_FIELD(root, node, nodeKind);
541 JSON_WRITE_FIELD(root, node, InEdges);
542 JSON_WRITE_FIELD(root, node, OutEdges);
543 return root;
544 }

◆ jsonAddContentToObject()

template<typename T >
bool SVF::SVFIRWriter::jsonAddContentToObject ( cJSON obj,
const char name,
const T item 
)
inlineprivate

Definition at line 640 of file SVFFileSystem.h.

641 {
644 }
cJSON * item
Definition cJSON.h:222

◆ jsonAddJsonableToObject()

template<typename T >
bool SVF::SVFIRWriter::jsonAddJsonableToObject ( cJSON obj,
const char name,
const T item 
)
inlineprivate

Definition at line 633 of file SVFFileSystem.h.

634 {
637 }
cJSON * toJson(const NodeIDAllocator *nodeIDAllocator)

◆ numToStr()

const char * SVF::SVFIRWriter::numToStr ( size_t  n)
private

Definition at line 1004 of file SVFFileSystem.cpp.

1005{
1006 auto it = numToStrMap.find(n);
1007 if (it != numToStrMap.end() && !(numToStrMap.key_comp()(n, it->first)))
1008 {
1009 return it->second.c_str();
1010 }
1011 return numToStrMap.emplace_hint(it, n, std::to_string(n))->second.c_str();
1012}
cJSON * n
Definition cJSON.cpp:2558
OrderedMap< size_t, std::string > numToStrMap

◆ toJson() [1/31]

cJSON * SVF::SVFIRWriter::toJson ( bool  flag)
staticprivate

Definition at line 105 of file SVFFileSystem.cpp.

106{
107 return jsonCreateBool(flag);
108}
cJSON * jsonCreateBool(bool flag)

◆ toJson() [2/31]

cJSON * SVF::SVFIRWriter::toJson ( const AccessPath ap)
private

Definition at line 1231 of file SVFFileSystem.cpp.

1232{
1233 cJSON* root = jsonCreateObject();
1234 JSON_WRITE_FIELD(root, &ap, fldIdx);
1235 JSON_WRITE_FIELD(root, &ap, idxOperandPairs);
1236 return root;
1237}

◆ toJson() [3/31]

cJSON * SVF::SVFIRWriter::toJson ( const CHEdge edge)
private

Definition at line 1159 of file SVFFileSystem.cpp.

1160{
1162}
size_t getEdgeID(const EdgeType *edge)
cJSON * jsonCreateIndex(size_t index)

◆ toJson() [4/31]

cJSON * SVF::SVFIRWriter::toJson ( const CHGraph graph)
private

Definition at line 1133 of file SVFFileSystem.cpp.

1134{
1136#define F(field) JSON_WRITE_FIELD(root, graph, field)
1137 // TODO: Ensure svfMod is the same as the SVFIR's?
1138 F(classNum);
1139 F(vfID);
1140 // F(buildingCHGTime); No need
1141 F(classNameToNodeMap);
1142 F(classNameToDescendantsMap);
1143 F(classNameToAncestorsMap);
1144 F(classNameToInstAndDescsMap);
1145 F(templateNameToInstancesMap);
1146 F(callNodeToClassesMap);
1147 F(virtualFunctionToIDMap);
1148 F(callNodeToCHAVtblsMap);
1149 F(callNodeToCHAVFnsMap);
1150#undef F
1151 return root;
1152}
WriterPtrPool< EdgeType > edgePool
cJSON * genericGraphToJson(const GenericGraph< NodeTy, EdgeTy > *graph, const std::vector< const EdgeTy * > &edgePool)
const std::vector< const T * > & getPool() const

◆ toJson() [5/31]

cJSON * SVF::SVFIRWriter::toJson ( const CHNode node)
private

Definition at line 1154 of file SVFFileSystem.cpp.

1155{
1156 return jsonCreateIndex(node->getId());
1157}

◆ toJson() [6/31]

cJSON * SVF::SVFIRWriter::toJson ( const CommonCHGraph graph)
private

Definition at line 1126 of file SVFFileSystem.cpp.

1127{
1128 auto chg = SVFUtil::dyn_cast<CHGraph>(graph);
1129 assert(chg && "Unsupported CHGraph type!");
1130 return toJson(chg);
1131}

◆ toJson() [7/31]

cJSON * SVF::SVFIRWriter::toJson ( const ICFG icfg)
private

Definition at line 1093 of file SVFFileSystem.cpp.

1094{
1095 cJSON* allSvfLoop = jsonCreateArray(); // all indices seen in constructor
1096 for (const SVFLoop* svfLoop : icfgWriter.svfLoopPool)
1097 {
1100 }
1101
1102#define F(field) JSON_WRITE_FIELD(root, icfg, field)
1104 jsonAddItemToObject(root, FIELD_NAME_ITEM(allSvfLoop)); // Meta field
1105 F(totalICFGNode);
1106 F(FunToFunEntryNodeMap);
1107 F(FunToFunExitNodeMap);
1108 F(globalBlockNode);
1109 F(icfgNodeToSVFLoopVec);
1110#undef F
1111 return root;
1112}

◆ toJson() [8/31]

cJSON * SVF::SVFIRWriter::toJson ( const ICFGEdge edge)
private

Definition at line 1120 of file SVFFileSystem.cpp.

1121{
1122 assert(edge && "ICFGNode is null!");
1124}

◆ toJson() [9/31]

cJSON * SVF::SVFIRWriter::toJson ( const ICFGNode node)
private

Definition at line 1114 of file SVFFileSystem.cpp.

1115{
1116 assert(node && "ICFGNode is null!");
1117 return jsonCreateIndex(node->getId());
1118}

◆ toJson() [10/31]

cJSON * SVF::SVFIRWriter::toJson ( const IRGraph graph)
private

Definition at line 1067 of file SVFFileSystem.cpp.

1068{
1069 ENSURE_NOT_VISITED(graph);
1070
1072#define F(field) JSON_WRITE_FIELD(root, graph, field)
1073 F(KindToSVFStmtSetMap);
1074 F(KindToPTASVFStmtSetMap);
1075 F(fromFile);
1076 F(nodeNumAfterPAGBuild);
1077 F(totalPTAPAGEdge);
1078 F(valueToEdgeMap);
1079#undef F
1080 return root;
1081}
#define ENSURE_NOT_VISITED(graph)

◆ toJson() [11/31]

cJSON * SVF::SVFIRWriter::toJson ( const MemObj memObj)
private

Definition at line 1206 of file SVFFileSystem.cpp.

1207{
1208 return jsonCreateIndex(memObj->getId());
1209}

◆ toJson() [12/31]

cJSON * SVF::SVFIRWriter::toJson ( const NodeIDAllocator nodeIDAllocator)
private

Definition at line 1239 of file SVFFileSystem.cpp.

1240{
1242
1243 cJSON* root = jsonCreateObject();
1244 JSON_WRITE_FIELD(root, nodeIDAllocator, strategy);
1245 JSON_WRITE_FIELD(root, nodeIDAllocator, numObjects);
1246 JSON_WRITE_FIELD(root, nodeIDAllocator, numValues);
1247 JSON_WRITE_FIELD(root, nodeIDAllocator, numSymbols);
1248 JSON_WRITE_FIELD(root, nodeIDAllocator, numNodes);
1249 return root;
1250}

◆ toJson() [13/31]

cJSON * SVF::SVFIRWriter::toJson ( const ObjTypeInfo objTypeInfo)
private

Definition at line 1194 of file SVFFileSystem.cpp.

1195{
1197
1198 cJSON* root = jsonCreateObject();
1200 JSON_WRITE_FIELD(root, objTypeInfo, flags);
1201 JSON_WRITE_FIELD(root, objTypeInfo, maxOffsetLimit);
1202 JSON_WRITE_FIELD(root, objTypeInfo, elemNum);
1203 return root;
1204}

◆ toJson() [14/31]

template<typename T , typename U >
cJSON * SVF::SVFIRWriter::toJson ( const std::pair< T, U > &  pair)
inlineprivate

The following 2 functions are intended to convert SparseBitVectors to JSON. But they're buggy. Commenting them out would enable the toJson(T) where is_iterable_v<T> is true. But that implementation is less space-efficient if the bitvector contains many elements. It is observed that upon construction, SVF IR bitvectors contain at most 1 element. In that case, we can just use the toJson(T) for iterable T without much space overhead.

template <unsigned ElementSize> cJSON* toJson(const SparseBitVectorElement<ElementSize>& element) { cJSON* array = jsonCreateArray(); for (const auto v : element.Bits) { jsonAddItemToArray(array, toJson(v)); } return array; }

template <unsigned ElementSize> cJSON* toJson(const SparseBitVector<ElementSize>& bv) { return toJson(bv.Elements); }

Definition at line 611 of file SVFFileSystem.h.

612 {
616 return obj;
617 }

◆ toJson() [15/31]

cJSON * SVF::SVFIRWriter::toJson ( const std::string &  str)
staticprivate

Definition at line 122 of file SVFFileSystem.cpp.

123{
124 return jsonCreateString(str.c_str());
125}
cJSON * jsonCreateString(const char *str)

◆ toJson() [16/31]

cJSON * SVF::SVFIRWriter::toJson ( const StInfo stInfo)
private

Definition at line 1226 of file SVFFileSystem.cpp.

1227{
1229}
size_t getStInfoID(const StInfo *stInfo)

◆ toJson() [17/31]

cJSON * SVF::SVFIRWriter::toJson ( const SVFLoop loop)
private

Definition at line 1164 of file SVFFileSystem.cpp.

1165{
1167}
size_t getSvfLoopID(const SVFLoop *loop)

◆ toJson() [18/31]

cJSON * SVF::SVFIRWriter::toJson ( const SVFLoopAndDomInfo ldInfo)
private

Definition at line 1211 of file SVFFileSystem.cpp.

1212{
1214
1215 cJSON* root = jsonCreateObject();
1216 JSON_WRITE_FIELD(root, ldInfo, reachableBBs);
1217 JSON_WRITE_FIELD(root, ldInfo, dtBBsMap);
1218 JSON_WRITE_FIELD(root, ldInfo, pdtBBsMap);
1219 JSON_WRITE_FIELD(root, ldInfo, dfBBsMap);
1220 JSON_WRITE_FIELD(root, ldInfo, bb2LoopMap);
1221 JSON_WRITE_FIELD(root, ldInfo, bb2PdomLevel);
1222 JSON_WRITE_FIELD(root, ldInfo, bb2PIdom);
1223 return root;
1224}

◆ toJson() [19/31]

cJSON * SVF::SVFIRWriter::toJson ( const SVFModule module)
private

Definition at line 1286 of file SVFFileSystem.cpp.

1287{
1288 cJSON* root = jsonCreateObject();
1292
1293 for (const SVFType* svfType : svfModuleWriter.svfTypePool)
1294 {
1297 }
1298
1299 for (const StInfo* stInfo : svfModuleWriter.stInfoPool)
1300 {
1303 }
1304
1305#define F(field) JSON_WRITE_FIELD(root, module, field)
1306 jsonAddItemToObject(root, FIELD_NAME_ITEM(allSVFType)); // Meta field
1307 jsonAddItemToObject(root, FIELD_NAME_ITEM(allStInfo)); // Meta field
1308 jsonAddItemToObject(root, FIELD_NAME_ITEM(allSVFValue)); // Meta field
1309 F(pagReadFromTxt);
1310 F(moduleIdentifier);
1311
1312 F(FunctionSet);
1313 F(GlobalSet);
1314 F(AliasSet);
1315 F(ConstantSet);
1316 F(OtherValueSet);
1317#undef F
1318
1319 for (size_t i = 1; i <= svfModuleWriter.sizeSVFValuePool(); ++i)
1320 {
1323 }
1324
1325 return root;
1326}
size_t sizeSVFValuePool() const
const SVFValue * getSVFValuePtr(size_t id) const

◆ toJson() [20/31]

cJSON * SVF::SVFIRWriter::toJson ( const SVFStmt stmt)
private

Definition at line 1088 of file SVFFileSystem.cpp.

1089{
1091}

◆ toJson() [21/31]

cJSON * SVF::SVFIRWriter::toJson ( const SVFType type)
private

Definition at line 1057 of file SVFFileSystem.cpp.

1058{
1060}
size_t getSVFTypeID(const SVFType *type)

◆ toJson() [22/31]

cJSON * SVF::SVFIRWriter::toJson ( const SVFValue value)
private

Definition at line 1062 of file SVFFileSystem.cpp.

1063{
1065}
size_t getSVFValueID(const SVFValue *value)

◆ toJson() [23/31]

cJSON * SVF::SVFIRWriter::toJson ( const SVFVar var)
private

Definition at line 1083 of file SVFFileSystem.cpp.

1084{
1085 return var ? jsonCreateIndex(var->getId()) : jsonCreateNullId();
1086}
cJSON * jsonCreateNullId()

◆ toJson() [24/31]

cJSON * SVF::SVFIRWriter::toJson ( const SymbolTableInfo symTable)
private

Definition at line 1252 of file SVFFileSystem.cpp.

1253{
1255
1256 cJSON* root = jsonCreateObject();
1258 for (const auto& pair : symTable->objMap)
1259 {
1260 const MemObj* memObj = pair.second;
1263 }
1264
1265#define F(field) JSON_WRITE_FIELD(root, symTable, field)
1266 jsonAddItemToObject(root, FIELD_NAME_ITEM(allMemObj)); // Actual field
1267
1268 F(valSymMap);
1269 F(objSymMap);
1270 F(returnSymMap);
1271 F(varargSymMap);
1272 // Field objMap can be represented by allMemObj
1273 // Field mod can be represented by svfIR->svfModule. Delete it?
1274 assert(symTable->mod == svfIR->svfModule && "SVFModule mismatch!");
1275 F(modelConstants);
1276 F(totalSymNum);
1277 F(maxStruct);
1278 F(maxStSize);
1279 // Field svfTypes can be represented by svfModuleWriter.svfTypePool
1280 // Field stInfos can be represented by svfModuleWriter.stInfoPool
1281#undef F
1282
1283 return root;
1284}
SVFModule * svfModule
Definition SVFIR.h:98

◆ toJson() [25/31]

template<typename T , typename = std::enable_if_t<SVFUtil::is_iterable_v<T>>>
cJSON * SVF::SVFIRWriter::toJson ( const T container)
inlineprivate

Definition at line 621 of file SVFFileSystem.h.

622 {
624 for (const auto& item : container)
625 {
628 }
629 return array;
630 }

◆ toJson() [26/31]

cJSON * SVF::SVFIRWriter::toJson ( float  number)
staticprivate

Definition at line 127 of file SVFFileSystem.cpp.

128{
129 return jsonCreateNumber(number);
130}
const char *const const double number
Definition cJSON.h:268
cJSON * jsonCreateNumber(double num)

◆ toJson() [27/31]

cJSON * SVF::SVFIRWriter::toJson ( int  number)
staticprivate

Definition at line 116 of file SVFFileSystem.cpp.

117{
118 // OK, double precision enough
119 return jsonCreateNumber(number);
120}

◆ toJson() [28/31]

cJSON * SVF::SVFIRWriter::toJson ( long long  number)
private

Definition at line 138 of file SVFFileSystem.cpp.

139{
140 return toJson(static_cast<unsigned long long>(number));
141}

◆ toJson() [29/31]

cJSON * SVF::SVFIRWriter::toJson ( unsigned long long  number)
private

Definition at line 143 of file SVFFileSystem.cpp.

144{
146}
const char * numToStr(size_t n)

◆ toJson() [30/31]

cJSON * SVF::SVFIRWriter::toJson ( unsigned long  number)
private

Definition at line 132 of file SVFFileSystem.cpp.

133{
134 // unsigned long is subset of unsigned long long
135 return toJson(static_cast<unsigned long long>(number));
136}

◆ toJson() [31/31]

cJSON * SVF::SVFIRWriter::toJson ( unsigned  number)
staticprivate

Definition at line 110 of file SVFFileSystem.cpp.

111{
112 // OK, double precision enough
113 return jsonCreateNumber(number);
114}

◆ virtToJson() [1/8]

cJSON * SVF::SVFIRWriter::virtToJson ( const CHEdge edge)
private

Definition at line 303 of file SVFFileSystem.cpp.

304{
305 return contentToJson(edge);
306}

◆ virtToJson() [2/8]

cJSON * SVF::SVFIRWriter::virtToJson ( const CHNode node)
private

Definition at line 298 of file SVFFileSystem.cpp.

299{
300 return contentToJson(node);
301}

◆ virtToJson() [3/8]

cJSON * SVF::SVFIRWriter::virtToJson ( const ICFGEdge edge)
private

Definition at line 283 of file SVFFileSystem.cpp.

284{
285 switch (edge->getEdgeKind())
286 {
287 default:
288 assert(false && "Unknown ICFGEdge kind");
290 return contentToJson(static_cast<const IntraCFGEdge*>(edge));
291 case ICFGEdge::CallCF:
292 return contentToJson(static_cast<const CallCFGEdge*>(edge));
293 case ICFGEdge::RetCF:
294 return contentToJson(static_cast<const RetCFGEdge*>(edge));
295 }
296}

◆ virtToJson() [4/8]

cJSON * SVF::SVFIRWriter::virtToJson ( const ICFGNode node)
private

Definition at line 262 of file SVFFileSystem.cpp.

263{
264 switch (node->getNodeKind())
265 {
266 default:
267 assert(false && "Unknown ICFGNode kind");
268
269#define CASE(NodeKind, NodeType) \
270 case ICFGNode::NodeKind: \
271 return contentToJson(static_cast<const NodeType*>(node))
272
273 CASE(IntraBlock, IntraICFGNode);
274 CASE(FunEntryBlock, FunEntryICFGNode);
275 CASE(FunExitBlock, FunExitICFGNode);
276 CASE(FunCallBlock, CallICFGNode);
277 CASE(FunRetBlock, RetICFGNode);
278 CASE(GlobalBlock, GlobalICFGNode);
279#undef CASE
280 }
281}
#define CASE(Kind)

◆ virtToJson() [5/8]

cJSON * SVF::SVFIRWriter::virtToJson ( const SVFStmt stmt)
private

Definition at line 232 of file SVFFileSystem.cpp.

233{
234 switch (stmt->getEdgeKind())
235 {
236 default:
237 assert(false && "Unknown SVFStmt kind");
238
239#define CASE(EdgeKind, EdgeType) \
240 case SVFStmt::EdgeKind: \
241 return contentToJson(static_cast<const EdgeType*>(stmt))
242
243 CASE(Addr, AddrStmt);
244 CASE(Copy, CopyStmt);
245 CASE(Store, StoreStmt);
246 CASE(Load, LoadStmt);
247 CASE(Call, CallPE);
248 CASE(Ret, RetPE);
249 CASE(Gep, GepStmt);
250 CASE(Phi, PhiStmt);
251 CASE(Select, SelectStmt);
252 CASE(Cmp, CmpStmt);
253 CASE(BinaryOp, BinaryOPStmt);
254 CASE(UnaryOp, UnaryOPStmt);
255 CASE(Branch, BranchStmt);
256 CASE(ThreadFork, TDForkPE);
257 CASE(ThreadJoin, TDJoinPE);
258#undef CASE
259 }
260}

◆ virtToJson() [6/8]

cJSON * SVF::SVFIRWriter::virtToJson ( const SVFType type)
private

Parameter types of these functions are all pointers. When they are used as arguments of toJson(), they will be dumped as an index. contentToJson() will dump the actual content.

Definition at line 148 of file SVFFileSystem.cpp.

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}

◆ virtToJson() [7/8]

cJSON * SVF::SVFIRWriter::virtToJson ( const SVFValue value)
private

Definition at line 172 of file SVFFileSystem.cpp.

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}

◆ virtToJson() [8/8]

cJSON * SVF::SVFIRWriter::virtToJson ( const SVFVar var)
private

Definition at line 204 of file SVFFileSystem.cpp.

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#undef CASE
229 }
230}

◆ writeJsonToOstream()

void SVF::SVFIRWriter::writeJsonToOstream ( const SVFIR svfir,
std::ostream &  os 
)
static

Definition at line 983 of file SVFFileSystem.cpp.

984{
985 SVFIRWriter writer(svfir);
986 os << writer.generateJsonString().get() << '\n';
987}
SVFIRWriter(const SVFIR *svfir)
Constructor.

◆ writeJsonToPath()

void SVF::SVFIRWriter::writeJsonToPath ( const SVFIR svfir,
const std::string &  path 
)
static

Definition at line 989 of file SVFFileSystem.cpp.

990{
991 std::ofstream jsonFile(path);
992 if (jsonFile.is_open())
993 {
995 jsonFile.close();
996 }
997 else
998 {
999 SVFUtil::errs() << "Failed to open file '" << path
1000 << "' to write SVFIR's JSON\n";
1001 }
1002}
static void writeJsonToOstream(const SVFIR *svfir, std::ostream &os)
std::ostream & errs()
Overwrite llvm::errs()
Definition SVFUtil.h:56

Member Data Documentation

◆ chgWriter

CHGraphWriter SVF::SVFIRWriter::chgWriter
private

Definition at line 385 of file SVFFileSystem.h.

◆ icfgWriter

ICFGWriter SVF::SVFIRWriter::icfgWriter
private

Definition at line 384 of file SVFFileSystem.h.

◆ irGraphWriter

IRGraphWriter SVF::SVFIRWriter::irGraphWriter
private

Definition at line 386 of file SVFFileSystem.h.

◆ numToStrMap

OrderedMap<size_t, std::string> SVF::SVFIRWriter::numToStrMap
private

Definition at line 388 of file SVFFileSystem.h.

◆ svfIR

const SVFIR* SVF::SVFIRWriter::svfIR
private

Definition at line 381 of file SVFFileSystem.h.

◆ svfModuleWriter

SVFModuleWriter SVF::SVFIRWriter::svfModuleWriter
private

Definition at line 383 of file SVFFileSystem.h.


The documentation for this class was generated from the following files: