Static Value-Flow Analysis
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. More...
 

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. More...
 
autoCStr generateJsonString ()
 
const char * numToStr (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. More...
 
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 FIObjVar *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 SVFVirtualCallInst *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::stringnumToStrMap
 

Detailed Description

Definition at line 379 of file SVFFileSystem.h.

Member Typedef Documentation

◆ autoCStr

using SVF::SVFIRWriter::autoCStr = std::unique_ptr<char, decltype(&cJSON_free)>

Definition at line 393 of file SVFFileSystem.h.

◆ autoJSON

using SVF::SVFIRWriter::autoJSON = std::unique_ptr<cJSON, decltype(&cJSON_Delete)>

Definition at line 392 of file SVFFileSystem.h.

Constructor & Destructor Documentation

◆ SVFIRWriter()

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

Constructor.

Definition at line 984 of file SVFFileSystem.cpp.

985  : svfIR(svfir), svfModuleWriter(svfir->svfModule), icfgWriter(svfir->icfg),
986  chgWriter(SVFUtil::dyn_cast<CHGraph>(svfir->chgraph)),
987  irGraphWriter(svfir)
988 {
989 }
const SVFIR * svfIR
IRGraphWriter irGraphWriter
SVFModuleWriter svfModuleWriter
CHGraphWriter chgWriter
ICFGWriter icfgWriter

Member Function Documentation

◆ contentToJson() [1/68]

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

Definition at line 680 of file SVFFileSystem.cpp.

681 {
682  return contentToJson(static_cast<const AssignStmt*>(edge));
683 }
cJSON * contentToJson(const SVFVar *var)

◆ contentToJson() [2/68]

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

Definition at line 675 of file SVFFileSystem.cpp.

676 {
677  return contentToJson(static_cast<const SVFStmt*>(edge));
678 }

◆ contentToJson() [3/68]

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

Definition at line 754 of file SVFFileSystem.cpp.

755 {
756  cJSON* root = contentToJson(static_cast<const MultiOpndStmt*>(edge));
757  JSON_WRITE_FIELD(root, edge, opcode);
758  return root;
759 }
#define JSON_WRITE_FIELD(root, objptr, field)
Definition: SVFFileSystem.h:67
Definition: cJSON.h:104

◆ contentToJson() [4/68]

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

Definition at line 768 of file SVFFileSystem.cpp.

769 {
770  cJSON* root = contentToJson(static_cast<const SVFStmt*>(edge));
771  JSON_WRITE_FIELD(root, edge, successors);
772  JSON_WRITE_FIELD(root, edge, cond);
773  JSON_WRITE_FIELD(root, edge, brInst);
774  return root;
775 }

◆ contentToJson() [5/68]

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

Definition at line 441 of file SVFFileSystem.cpp.

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

◆ contentToJson() [6/68]

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

Definition at line 412 of file SVFFileSystem.cpp.

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

◆ contentToJson() [7/68]

cJSON * SVF::SVFIRWriter::contentToJson ( const CallPE 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, entry);
715  return root;
716 }

◆ contentToJson() [8/68]

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

Definition at line 465 of file SVFFileSystem.cpp.

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

◆ contentToJson() [9/68]

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

Definition at line 455 of file SVFFileSystem.cpp.

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

◆ contentToJson() [10/68]

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

Definition at line 747 of file SVFFileSystem.cpp.

748 {
749  cJSON* root = contentToJson(static_cast<const MultiOpndStmt*>(edge));
750  JSON_WRITE_FIELD(root, edge, predicate);
751  return root;
752 }

◆ contentToJson() [11/68]

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

Definition at line 685 of file SVFFileSystem.cpp.

686 {
687  cJSON* root = contentToJson(static_cast<const AssignStmt*>(edge));
688  JSON_WRITE_FIELD(root, edge, copyKind);
689  return root;
690 }

◆ contentToJson() [12/68]

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

Definition at line 365 of file SVFFileSystem.cpp.

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

◆ contentToJson() [13/68]

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

Definition at line 360 of file SVFFileSystem.cpp.

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

◆ contentToJson() [14/68]

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

Definition at line 345 of file SVFFileSystem.cpp.

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

◆ contentToJson() [15/68]

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

Definition at line 398 of file SVFFileSystem.cpp.

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

◆ contentToJson() [16/68]

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

Definition at line 405 of file SVFFileSystem.cpp.

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

◆ contentToJson() [17/68]

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

Definition at line 337 of file SVFFileSystem.cpp.

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

◆ contentToJson() [18/68]

cJSON * SVF::SVFIRWriter::contentToJson ( const GepStmt 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, ap);
706  JSON_WRITE_FIELD(root, edge, variantField);
707  return root;
708 }

◆ contentToJson() [19/68]

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

Definition at line 329 of file SVFFileSystem.cpp.

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

◆ contentToJson() [20/68]

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

Definition at line 381 of file SVFFileSystem.cpp.

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

◆ contentToJson() [21/68]

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

Definition at line 428 of file SVFFileSystem.cpp.

429 {
430  return genericEdgeToJson(edge);
431 }

◆ contentToJson() [22/68]

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

Definition at line 370 of file SVFFileSystem.cpp.

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

◆ contentToJson() [23/68]

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

Definition at line 393 of file SVFFileSystem.cpp.

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

◆ contentToJson() [24/68]

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

Definition at line 433 of file SVFFileSystem.cpp.

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

◆ contentToJson() [25/68]

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

Definition at line 386 of file SVFFileSystem.cpp.

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

◆ contentToJson() [26/68]

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

Definition at line 697 of file SVFFileSystem.cpp.

698 {
699  return contentToJson(static_cast<const AssignStmt*>(edge));
700 }

◆ contentToJson() [27/68]

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

Definition at line 1177 of file SVFFileSystem.cpp.

1178 {
1179  cJSON* root = jsonCreateObject();
1180  JSON_WRITE_FIELD(root, memObj, symId);
1181  JSON_WRITE_FIELD(root, memObj, typeInfo);
1182  JSON_WRITE_FIELD(root, memObj, refVal);
1183  return root;
1184 }
cJSON * jsonCreateObject()

◆ contentToJson() [28/68]

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

Definition at line 726 of file SVFFileSystem.cpp.

727 {
728  cJSON* root = contentToJson(static_cast<const SVFStmt*>(edge));
729  JSON_WRITE_FIELD(root, edge, opVars);
730  return root;
731 }

◆ contentToJson() [29/68]

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

Definition at line 322 of file SVFFileSystem.cpp.

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

◆ contentToJson() [30/68]

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

Definition at line 733 of file SVFFileSystem.cpp.

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

◆ contentToJson() [31/68]

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

Definition at line 448 of file SVFFileSystem.cpp.

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

◆ contentToJson() [32/68]

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

Definition at line 420 of file SVFFileSystem.cpp.

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

◆ contentToJson() [33/68]

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

Definition at line 718 of file SVFFileSystem.cpp.

719 {
720  cJSON* root = contentToJson(static_cast<const AssignStmt*>(edge));
721  JSON_WRITE_FIELD(root, edge, call);
722  JSON_WRITE_FIELD(root, edge, exit);
723  return root;
724 }

◆ contentToJson() [34/68]

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

Definition at line 350 of file SVFFileSystem.cpp.

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

◆ contentToJson() [35/68]

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

Definition at line 740 of file SVFFileSystem.cpp.

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

◆ contentToJson() [36/68]

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

Definition at line 1186 of file SVFFileSystem.cpp.

1187 {
1188  cJSON* root = jsonCreateObject();
1189 #define F(field) JSON_WRITE_FIELD(root, stInfo, field)
1190  F(stride);
1191  F(numOfFlattenElements);
1192  F(numOfFlattenFields);
1193  F(fldIdxVec);
1194  F(elemIdxVec);
1195  F(fldIdx2TypeMap);
1196  F(finfo);
1197  F(flattenElementTypes);
1198 #undef F
1199  return root;
1200 }
#define F(f)

◆ contentToJson() [37/68]

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

Definition at line 692 of file SVFFileSystem.cpp.

693 {
694  return contentToJson(static_cast<const AssignStmt*>(edge));
695 }

◆ contentToJson() [38/68]

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

Definition at line 602 of file SVFFileSystem.cpp.

603 {
604  cJSON* root = contentToJson(static_cast<const SVFValue*>(value));
605  JSON_WRITE_FIELD(root, value, fun);
606  JSON_WRITE_FIELD(root, value, argNo);
607  JSON_WRITE_FIELD(root, value, uncalled);
608  return root;
609 }

◆ contentToJson() [39/68]

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

Definition at line 508 of file SVFFileSystem.cpp.

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

◆ contentToJson() [40/68]

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

Definition at line 554 of file SVFFileSystem.cpp.

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

◆ contentToJson() [41/68]

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

Definition at line 636 of file SVFFileSystem.cpp.

637 {
638  return contentToJson(static_cast<const SVFConstantData*>(value));
639 }

◆ contentToJson() [42/68]

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

Definition at line 572 of file SVFFileSystem.cpp.

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

◆ contentToJson() [43/68]

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

Definition at line 590 of file SVFFileSystem.cpp.

591 {
592  return contentToJson(static_cast<const SVFValue*>(value));
593 }

◆ contentToJson() [44/68]

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

Definition at line 611 of file SVFFileSystem.cpp.

612 {
613  return contentToJson(static_cast<const SVFConstant*>(value));
614 }

◆ contentToJson() [45/68]

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

Definition at line 624 of file SVFFileSystem.cpp.

625 {
626  cJSON* root = contentToJson(static_cast<const SVFConstantData*>(value));
627  JSON_WRITE_FIELD(root, value, dval);
628  return root;
629 }

◆ contentToJson() [46/68]

cJSON * SVF::SVFIRWriter::contentToJson ( const SVFConstantInt 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, zval);
620  JSON_WRITE_FIELD(root, value, sval);
621  return root;
622 }

◆ contentToJson() [47/68]

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

Definition at line 631 of file SVFFileSystem.cpp.

632 {
633  return contentToJson(static_cast<const SVFConstantData*>(value));
634 }

◆ contentToJson() [48/68]

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

Definition at line 535 of file SVFFileSystem.cpp.

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

◆ contentToJson() [49/68]

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

Definition at line 494 of file SVFFileSystem.cpp.

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

◆ contentToJson() [50/68]

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

Definition at line 595 of file SVFFileSystem.cpp.

596 {
597  cJSON* root = contentToJson(static_cast<const SVFConstant*>(value));
598  JSON_WRITE_FIELD(root, value, realDefGlobal);
599  return root;
600 }

◆ contentToJson() [51/68]

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

Definition at line 563 of file SVFFileSystem.cpp.

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

◆ contentToJson() [52/68]

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

Definition at line 487 of file SVFFileSystem.cpp.

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

◆ contentToJson() [53/68]

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

Definition at line 661 of file SVFFileSystem.cpp.

662 {
663  cJSON* root = jsonCreateObject();
664 #define F(field) JSON_WRITE_FIELD(root, loop, field)
665  F(entryICFGEdges);
666  F(backICFGEdges);
667  F(inICFGEdges);
668  F(outICFGEdges);
669  F(icfgNodes);
670  F(loopBound);
671 #undef F
672  return root;
673 }

◆ contentToJson() [54/68]

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

Definition at line 646 of file SVFFileSystem.cpp.

647 {
648  return contentToJson(static_cast<const SVFOtherValue*>(value));
649 }

◆ contentToJson() [55/68]

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

Definition at line 516 of file SVFFileSystem.cpp.

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

◆ contentToJson() [56/68]

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

Definition at line 641 of file SVFFileSystem.cpp.

642 {
643  return contentToJson(static_cast<const SVFValue*>(value));
644 }

◆ contentToJson() [57/68]

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

Definition at line 481 of file SVFFileSystem.cpp.

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

◆ contentToJson() [58/68]

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

Definition at line 651 of file SVFFileSystem.cpp.

652 {
653  cJSON* root = genericEdgeToJson(edge);
654  JSON_WRITE_FIELD(root, edge, value);
655  JSON_WRITE_FIELD(root, edge, basicBlock);
656  JSON_WRITE_FIELD(root, edge, icfgNode);
657  JSON_WRITE_FIELD(root, edge, edgeId);
658  return root;
659 }

◆ contentToJson() [59/68]

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

Definition at line 501 of file SVFFileSystem.cpp.

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

◆ contentToJson() [60/68]

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

Definition at line 472 of file SVFFileSystem.cpp.

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

◆ contentToJson() [61/68]

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

Definition at line 523 of file SVFFileSystem.cpp.

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

◆ contentToJson() [62/68]

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

Definition at line 307 of file SVFFileSystem.cpp.

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

◆ contentToJson() [63/68]

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

Definition at line 581 of file SVFFileSystem.cpp.

582 {
583  cJSON* root = contentToJson(static_cast<const SVFCallInst*>(value));
584  JSON_WRITE_FIELD(root, value, vCallVtblPtr);
585  JSON_WRITE_FIELD(root, value, virtualFunIdx);
586  JSON_WRITE_FIELD(root, value, funNameOfVcall);
587  return root;
588 }

◆ contentToJson() [64/68]

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

Definition at line 777 of file SVFFileSystem.cpp.

778 {
779  return contentToJson(static_cast<const CallPE*>(edge));
780 }

◆ contentToJson() [65/68]

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

Definition at line 782 of file SVFFileSystem.cpp.

783 {
784  return contentToJson(static_cast<const RetPE*>(edge));
785 }

◆ contentToJson() [66/68]

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

Definition at line 761 of file SVFFileSystem.cpp.

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

◆ contentToJson() [67/68]

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

Definition at line 317 of file SVFFileSystem.cpp.

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

◆ contentToJson() [68/68]

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

Definition at line 355 of file SVFFileSystem.cpp.

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

◆ generateJson()

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

Main logic to dump a SVFIR to a JSON object.

Definition at line 1030 of file SVFFileSystem.cpp.

1031 {
1032  const IRGraph* const irGraph = svfIR;
1033  NodeIDAllocator* nodeIDAllocator = NodeIDAllocator::allocator;
1034  assert(nodeIDAllocator && "NodeIDAllocator is not initialized?");
1035 
1036  cJSON* root = jsonCreateObject();
1037 #define F(field) JSON_WRITE_FIELD(root, svfIR, field)
1038  F(svfModule);
1039  F(symInfo);
1040  F(icfg);
1041  F(chgraph);
1042  jsonAddJsonableToObject(root, FIELD_NAME_ITEM(irGraph));
1043  F(icfgNode2SVFStmtsMap);
1044  F(icfgNode2PTASVFStmtsMap);
1045  F(GepValObjMap);
1046  F(typeLocSetsMap);
1047  F(GepObjVarMap);
1048  F(memToFieldsMap);
1049  F(globSVFStmtSet);
1050  F(phiNodeMap);
1051  F(funArgsListMap);
1052  F(callSiteArgsListMap);
1053  F(callSiteRetMap);
1054  F(funRetMap);
1055  F(indCallSiteToFunPtrMap);
1056  F(funPtrToCallSitesMap);
1057  F(candidatePointers);
1058  F(callSiteSet);
1059  jsonAddJsonableToObject(root, FIELD_NAME_ITEM(nodeIDAllocator));
1060 #undef F
1061 
1062  return {root, cJSON_Delete};
1063 }
#define FIELD_NAME_ITEM(field)
Definition: SVFFileSystem.h:61
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 1022 of file SVFFileSystem.cpp.

1023 {
1024  autoJSON object = generateJson();
1025  char* str = humanReadableOption() ? cJSON_Print(object.get())
1026  : cJSON_PrintUnformatted(object.get());
1027  return {str, cJSON_free};
1028 }
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 549 of file SVFFileSystem.h.

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

◆ genericGraphToJson()

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

Definition at line 559 of file SVFFileSystem.h.

561  {
562  cJSON* root = jsonCreateObject();
563 
564  cJSON* allNode = jsonCreateArray();
565  for (const auto& pair : graph->IDToNodeMap)
566  {
567  NodeTy* node = pair.second;
568  cJSON* jsonNode = virtToJson(node);
569  jsonAddItemToArray(allNode, jsonNode);
570  }
571 
572  cJSON* allEdge = jsonCreateArray();
573  for (const EdgeTy* edge : edgePool)
574  {
575  cJSON* edgeJson = virtToJson(edge);
576  jsonAddItemToArray(allEdge, edgeJson);
577  }
578 
579  JSON_WRITE_FIELD(root, graph, nodeNum);
580  jsonAddItemToObject(root, FIELD_NAME_ITEM(allNode));
581  JSON_WRITE_FIELD(root, graph, edgeNum);
582  jsonAddItemToObject(root, FIELD_NAME_ITEM(allEdge));
583 
584  return root;
585  }
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()

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

Definition at line 538 of file SVFFileSystem.h.

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

◆ jsonAddContentToObject()

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

Definition at line 642 of file SVFFileSystem.h.

643  {
644  cJSON* itemObj = contentToJson(item);
645  return jsonAddItemToObject(obj, name, itemObj);
646  }
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 635 of file SVFFileSystem.h.

636  {
637  cJSON* itemObj = toJson(item);
638  return jsonAddItemToObject(obj, name, itemObj);
639  }
cJSON * toJson(const NodeIDAllocator *nodeIDAllocator)

◆ numToStr()

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

Definition at line 1012 of file SVFFileSystem.cpp.

1013 {
1014  auto it = numToStrMap.find(n);
1015  if (it != numToStrMap.end() && !(numToStrMap.key_comp()(n, it->first)))
1016  {
1017  return it->second.c_str();
1018  }
1019  return numToStrMap.emplace_hint(it, n, std::to_string(n))->second.c_str();
1020 }
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 107 of file SVFFileSystem.cpp.

108 {
109  return jsonCreateBool(flag);
110 }
cJSON * jsonCreateBool(bool flag)

◆ toJson() [2/31]

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

Definition at line 1239 of file SVFFileSystem.cpp.

1240 {
1241  cJSON* root = jsonCreateObject();
1242  JSON_WRITE_FIELD(root, &ap, fldIdx);
1243  JSON_WRITE_FIELD(root, &ap, idxOperandPairs);
1244  return root;
1245 }

◆ toJson() [3/31]

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

Definition at line 1167 of file SVFFileSystem.cpp.

1168 {
1169  return jsonCreateIndex(chgWriter.getEdgeID(edge));
1170 }
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 1141 of file SVFFileSystem.cpp.

1142 {
1144 #define F(field) JSON_WRITE_FIELD(root, graph, field)
1145  // TODO: Ensure svfMod is the same as the SVFIR's?
1146  F(classNum);
1147  F(vfID);
1148  // F(buildingCHGTime); No need
1149  F(classNameToNodeMap);
1150  F(classNameToDescendantsMap);
1151  F(classNameToAncestorsMap);
1152  F(classNameToInstAndDescsMap);
1153  F(templateNameToInstancesMap);
1154  F(callNodeToClassesMap);
1155  F(virtualFunctionToIDMap);
1156  F(callNodeToCHAVtblsMap);
1157  F(callNodeToCHAVFnsMap);
1158 #undef F
1159  return root;
1160 }
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 1162 of file SVFFileSystem.cpp.

1163 {
1164  return jsonCreateIndex(node->getId());
1165 }

◆ toJson() [6/31]

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

Definition at line 1134 of file SVFFileSystem.cpp.

1135 {
1136  auto chg = SVFUtil::dyn_cast<CHGraph>(graph);
1137  assert(chg && "Unsupported CHGraph type!");
1138  return toJson(chg);
1139 }

◆ toJson() [7/31]

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

Definition at line 1101 of file SVFFileSystem.cpp.

1102 {
1103  cJSON* allSvfLoop = jsonCreateArray(); // all indices seen in constructor
1104  for (const SVFLoop* svfLoop : icfgWriter.svfLoopPool)
1105  {
1106  cJSON* svfLoopObj = contentToJson(svfLoop);
1107  jsonAddItemToArray(allSvfLoop, svfLoopObj);
1108  }
1109 
1110 #define F(field) JSON_WRITE_FIELD(root, icfg, field)
1112  jsonAddItemToObject(root, FIELD_NAME_ITEM(allSvfLoop)); // Meta field
1113  F(totalICFGNode);
1114  F(FunToFunEntryNodeMap);
1115  F(FunToFunExitNodeMap);
1116  F(globalBlockNode);
1117  F(icfgNodeToSVFLoopVec);
1118 #undef F
1119  return root;
1120 }
WriterPtrPool< SVFLoop > svfLoopPool

◆ toJson() [8/31]

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

Definition at line 1128 of file SVFFileSystem.cpp.

1129 {
1130  assert(edge && "ICFGNode is null!");
1131  return jsonCreateIndex(icfgWriter.getEdgeID(edge));
1132 }

◆ toJson() [9/31]

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

Definition at line 1122 of file SVFFileSystem.cpp.

1123 {
1124  assert(node && "ICFGNode is null!");
1125  return jsonCreateIndex(node->getId());
1126 }

◆ toJson() [10/31]

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

Definition at line 1075 of file SVFFileSystem.cpp.

1076 {
1077  ENSURE_NOT_VISITED(graph);
1078 
1080 #define F(field) JSON_WRITE_FIELD(root, graph, field)
1081  F(KindToSVFStmtSetMap);
1082  F(KindToPTASVFStmtSetMap);
1083  F(fromFile);
1084  F(nodeNumAfterPAGBuild);
1085  F(totalPTAPAGEdge);
1086  F(valueToEdgeMap);
1087 #undef F
1088  return root;
1089 }
#define ENSURE_NOT_VISITED(graph)
Definition: SVFFileSystem.h:48

◆ toJson() [11/31]

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

Definition at line 1214 of file SVFFileSystem.cpp.

1215 {
1216  return jsonCreateIndex(memObj->getId());
1217 }

◆ toJson() [12/31]

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

Definition at line 1247 of file SVFFileSystem.cpp.

1248 {
1249  ENSURE_NOT_VISITED(nodeIDAllocator);
1250 
1251  cJSON* root = jsonCreateObject();
1252  JSON_WRITE_FIELD(root, nodeIDAllocator, strategy);
1253  JSON_WRITE_FIELD(root, nodeIDAllocator, numObjects);
1254  JSON_WRITE_FIELD(root, nodeIDAllocator, numValues);
1255  JSON_WRITE_FIELD(root, nodeIDAllocator, numSymbols);
1256  JSON_WRITE_FIELD(root, nodeIDAllocator, numNodes);
1257  return root;
1258 }

◆ toJson() [13/31]

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

Definition at line 1202 of file SVFFileSystem.cpp.

1203 {
1204  ENSURE_NOT_VISITED(objTypeInfo);
1205 
1206  cJSON* root = jsonCreateObject();
1207  JSON_WRITE_FIELD(root, objTypeInfo, type);
1208  JSON_WRITE_FIELD(root, objTypeInfo, flags);
1209  JSON_WRITE_FIELD(root, objTypeInfo, maxOffsetLimit);
1210  JSON_WRITE_FIELD(root, objTypeInfo, elemNum);
1211  return root;
1212 }

◆ 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 613 of file SVFFileSystem.h.

614  {
615  cJSON* obj = jsonCreateArray();
616  jsonAddItemToArray(obj, toJson(pair.first));
617  jsonAddItemToArray(obj, toJson(pair.second));
618  return obj;
619  }

◆ toJson() [15/31]

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

Definition at line 124 of file SVFFileSystem.cpp.

125 {
126  return jsonCreateString(str.c_str());
127 }
cJSON * jsonCreateString(const char *str)

◆ toJson() [16/31]

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

Definition at line 1234 of file SVFFileSystem.cpp.

1235 {
1237 }
size_t getStInfoID(const StInfo *stInfo)

◆ toJson() [17/31]

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

Definition at line 1172 of file SVFFileSystem.cpp.

1173 {
1174  return jsonCreateIndex(icfgWriter.getSvfLoopID(loop));
1175 }
size_t getSvfLoopID(const SVFLoop *loop)

◆ toJson() [18/31]

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

Definition at line 1219 of file SVFFileSystem.cpp.

1220 {
1221  ENSURE_NOT_VISITED(ldInfo);
1222 
1223  cJSON* root = jsonCreateObject();
1224  JSON_WRITE_FIELD(root, ldInfo, reachableBBs);
1225  JSON_WRITE_FIELD(root, ldInfo, dtBBsMap);
1226  JSON_WRITE_FIELD(root, ldInfo, pdtBBsMap);
1227  JSON_WRITE_FIELD(root, ldInfo, dfBBsMap);
1228  JSON_WRITE_FIELD(root, ldInfo, bb2LoopMap);
1229  JSON_WRITE_FIELD(root, ldInfo, bb2PdomLevel);
1230  JSON_WRITE_FIELD(root, ldInfo, bb2PIdom);
1231  return root;
1232 }

◆ toJson() [19/31]

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

Definition at line 1294 of file SVFFileSystem.cpp.

1295 {
1296  cJSON* root = jsonCreateObject();
1297  cJSON* allSVFType = jsonCreateArray();
1298  cJSON* allStInfo = jsonCreateArray();
1299  cJSON* allSVFValue = jsonCreateArray();
1300 
1301  for (const SVFType* svfType : svfModuleWriter.svfTypePool)
1302  {
1303  cJSON* svfTypeObj = virtToJson(svfType);
1304  jsonAddItemToArray(allSVFType, svfTypeObj);
1305  }
1306 
1307  for (const StInfo* stInfo : svfModuleWriter.stInfoPool)
1308  {
1309  cJSON* stInfoObj = contentToJson(stInfo);
1310  jsonAddItemToArray(allStInfo, stInfoObj);
1311  }
1312 
1313 #define F(field) JSON_WRITE_FIELD(root, module, field)
1314  jsonAddItemToObject(root, FIELD_NAME_ITEM(allSVFType)); // Meta field
1315  jsonAddItemToObject(root, FIELD_NAME_ITEM(allStInfo)); // Meta field
1316  jsonAddItemToObject(root, FIELD_NAME_ITEM(allSVFValue)); // Meta field
1317  F(pagReadFromTxt);
1318  F(moduleIdentifier);
1319 
1320  F(FunctionSet);
1321  F(GlobalSet);
1322  F(AliasSet);
1323  F(ConstantSet);
1324  F(OtherValueSet);
1325 #undef F
1326 
1327  for (size_t i = 1; i <= svfModuleWriter.sizeSVFValuePool(); ++i)
1328  {
1330  jsonAddItemToArray(allSVFValue, value);
1331  }
1332 
1333  return root;
1334 }
size_t sizeSVFValuePool() const
const SVFValue * getSVFValuePtr(size_t id) const
WriterPtrPool< StInfo > stInfoPool
WriterPtrPool< SVFType > svfTypePool

◆ toJson() [20/31]

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

Definition at line 1096 of file SVFFileSystem.cpp.

1097 {
1098  return jsonCreateIndex(irGraphWriter.getEdgeID(stmt));
1099 }

◆ toJson() [21/31]

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

Definition at line 1065 of file SVFFileSystem.cpp.

1066 {
1068 }
size_t getSVFTypeID(const SVFType *type)

◆ toJson() [22/31]

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

Definition at line 1070 of file SVFFileSystem.cpp.

1071 {
1073 }
size_t getSVFValueID(const SVFValue *value)

◆ toJson() [23/31]

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

Definition at line 1091 of file SVFFileSystem.cpp.

1092 {
1093  return var ? jsonCreateIndex(var->getId()) : jsonCreateNullId();
1094 }
cJSON * jsonCreateNullId()

◆ toJson() [24/31]

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

Definition at line 1260 of file SVFFileSystem.cpp.

1261 {
1262  ENSURE_NOT_VISITED(symTable);
1263 
1264  cJSON* root = jsonCreateObject();
1265  cJSON* allMemObj = jsonCreateArray();
1266  for (const auto& pair : symTable->objMap)
1267  {
1268  const MemObj* memObj = pair.second;
1269  cJSON* memObjJson = contentToJson(memObj);
1270  jsonAddItemToArray(allMemObj, memObjJson);
1271  }
1272 
1273 #define F(field) JSON_WRITE_FIELD(root, symTable, field)
1274  jsonAddItemToObject(root, FIELD_NAME_ITEM(allMemObj)); // Actual field
1275 
1276  F(valSymMap);
1277  F(objSymMap);
1278  F(returnSymMap);
1279  F(varargSymMap);
1280  // Field objMap can be represented by allMemObj
1281  // Field mod can be represented by svfIR->svfModule. Delete it?
1282  assert(symTable->mod == svfIR->svfModule && "SVFModule mismatch!");
1283  F(modelConstants);
1284  F(totalSymNum);
1285  F(maxStruct);
1286  F(maxStSize);
1287  // Field svfTypes can be represented by svfModuleWriter.svfTypePool
1288  // Field stInfos can be represented by svfModuleWriter.stInfoPool
1289 #undef F
1290 
1291  return root;
1292 }
SVFModule * svfModule
Definition: SVFIR.h:97

◆ 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 623 of file SVFFileSystem.h.

624  {
625  cJSON* array = jsonCreateArray();
626  for (const auto& item : container)
627  {
628  cJSON* itemObj = toJson(item);
629  jsonAddItemToArray(array, itemObj);
630  }
631  return array;
632  }

◆ toJson() [26/31]

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

Definition at line 129 of file SVFFileSystem.cpp.

130 {
131  return jsonCreateNumber(number);
132 }
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 118 of file SVFFileSystem.cpp.

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

◆ toJson() [28/31]

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

Definition at line 140 of file SVFFileSystem.cpp.

141 {
142  return toJson(static_cast<unsigned long long>(number));
143 }

◆ toJson() [29/31]

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

Definition at line 145 of file SVFFileSystem.cpp.

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

◆ toJson() [30/31]

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

Definition at line 134 of file SVFFileSystem.cpp.

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

◆ toJson() [31/31]

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

Definition at line 112 of file SVFFileSystem.cpp.

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

◆ virtToJson() [1/8]

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

Definition at line 302 of file SVFFileSystem.cpp.

303 {
304  return contentToJson(edge);
305 }

◆ virtToJson() [2/8]

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

Definition at line 297 of file SVFFileSystem.cpp.

298 {
299  return contentToJson(node);
300 }

◆ virtToJson() [3/8]

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

Definition at line 282 of file SVFFileSystem.cpp.

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

◆ virtToJson() [4/8]

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

Definition at line 261 of file SVFFileSystem.cpp.

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

◆ virtToJson() [5/8]

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

Definition at line 231 of file SVFFileSystem.cpp.

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

◆ 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 150 of file SVFFileSystem.cpp.

151 {
152  auto kind = type->getKind();
153 
154  switch (kind)
155  {
156  default:
157  assert(false && "Impossible SVFType kind");
158 
159 #define CASE(Kind) \
160  case SVFType::Kind: \
161  return contentToJson(static_cast<const Kind##pe*>(type))
162 
163  CASE(SVFTy);
164  CASE(SVFPointerTy);
165  CASE(SVFIntegerTy);
166  CASE(SVFFunctionTy);
167  CASE(SVFStructTy);
168  CASE(SVFArrayTy);
169  CASE(SVFOtherTy);
170 #undef CASE
171  }
172 }

◆ virtToJson() [7/8]

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

Definition at line 174 of file SVFFileSystem.cpp.

175 {
176  auto kind = value->getKind();
177 
178  switch (kind)
179  {
180  default:
181  assert(false && "Impossible SVFValue kind");
182 
183 #define CASE(ValueKind, type) \
184  case SVFValue::ValueKind: \
185  return contentToJson(static_cast<const type*>(value))
186 
187  CASE(SVFVal, SVFValue);
188  CASE(SVFFunc, SVFFunction);
189  CASE(SVFBB, SVFBasicBlock);
190  CASE(SVFInst, SVFInstruction);
191  CASE(SVFCall, SVFCallInst);
192  CASE(SVFVCall, SVFVirtualCallInst);
193  CASE(SVFGlob, SVFGlobalValue);
194  CASE(SVFArg, SVFArgument);
195  CASE(SVFConst, SVFConstant);
196  CASE(SVFConstData, SVFConstantData);
197  CASE(SVFConstInt, SVFConstantInt);
198  CASE(SVFConstFP, SVFConstantFP);
199  CASE(SVFNullPtr, SVFConstantNullPtr);
200  CASE(SVFBlackHole, SVFBlackHoleValue);
201  CASE(SVFMetaAsValue, SVFMetadataAsValue);
202  CASE(SVFOther, SVFOtherValue);
203 #undef CASE
204  }
205 }

◆ virtToJson() [8/8]

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

Definition at line 207 of file SVFFileSystem.cpp.

208 {
209  switch (var->getNodeKind())
210  {
211  default:
212  assert(false && "Unknown SVFVar kind");
213 
214 #define CASE(VarKind, VarType) \
215  case SVFVar::VarKind: \
216  return contentToJson(static_cast<const VarType*>(var))
217 
218  CASE(ValNode, ValVar);
219  CASE(ObjNode, ObjVar);
220  CASE(RetNode, RetPN);
221  CASE(VarargNode, VarArgPN);
222  CASE(GepValNode, GepValVar);
223  CASE(GepObjNode, GepObjVar);
224  CASE(FIObjNode, FIObjVar);
225  CASE(DummyValNode, DummyValVar);
226  CASE(DummyObjNode, DummyObjVar);
227 #undef CASE
228  }
229 }

◆ writeJsonToOstream()

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

Definition at line 991 of file SVFFileSystem.cpp.

992 {
993  SVFIRWriter writer(svfir);
994  os << writer.generateJsonString().get() << '\n';
995 }
SVFIRWriter(const SVFIR *svfir)
Constructor.

◆ writeJsonToPath()

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

Definition at line 997 of file SVFFileSystem.cpp.

998 {
999  std::ofstream jsonFile(path);
1000  if (jsonFile.is_open())
1001  {
1002  writeJsonToOstream(svfir, jsonFile);
1003  jsonFile.close();
1004  }
1005  else
1006  {
1007  SVFUtil::errs() << "Failed to open file '" << path
1008  << "' to write SVFIR's JSON\n";
1009  }
1010 }
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 386 of file SVFFileSystem.h.

◆ icfgWriter

ICFGWriter SVF::SVFIRWriter::icfgWriter
private

Definition at line 385 of file SVFFileSystem.h.

◆ irGraphWriter

IRGraphWriter SVF::SVFIRWriter::irGraphWriter
private

Definition at line 387 of file SVFFileSystem.h.

◆ numToStrMap

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

Definition at line 389 of file SVFFileSystem.h.

◆ svfIR

const SVFIR* SVF::SVFIRWriter::svfIR
private

Definition at line 382 of file SVFFileSystem.h.

◆ svfModuleWriter

SVFModuleWriter SVF::SVFIRWriter::svfModuleWriter
private

Definition at line 384 of file SVFFileSystem.h.


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