svf-lib 1.0.2189 → 1.0.2190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.2189",
3
+ "version": "1.0.2190",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,1318 +0,0 @@
1
- //===- SVFFileSystem.h -- SVF IR Reader and Writer ------------------------===//
2
- //
3
- // SVF - Static Value-Flow Analysis Framework
4
- // SVF: Static Value-Flow Analysis
5
- //
6
- // Copyright (C) <2013-2023> <Yulei Sui>
7
- //
8
-
9
- // This program is free software: you can redistribute it and/or modify
10
- // it under the terms of the GNU Affero General Public License as published by
11
- // the Free Software Foundation, either version 3 of the License, or
12
- // (at your option) any later version.
13
-
14
- // This program is distributed in the hope that it will be useful,
15
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- // GNU Affero General Public License for more details.
18
-
19
- // You should have received a copy of the GNU Affero General Public License
20
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
21
- //
22
- //===----------------------------------------------------------------------===//
23
-
24
- #ifndef INCLUDE_SVFFILESYSTEM_H_
25
- #define INCLUDE_SVFFILESYSTEM_H_
26
-
27
- #include "Graphs/GenericGraph.h"
28
- #include "Util/SVFUtil.h"
29
- #include "Util/cJSON.h"
30
- #include <type_traits>
31
-
32
- #define ABORT_MSG(reason) \
33
- do \
34
- { \
35
- SVFUtil::errs() << __FILE__ << ':' << __LINE__ << ": " << reason \
36
- << '\n'; \
37
- abort(); \
38
- } while (0)
39
- #define ABORT_IFNOT(condition, reason) \
40
- do \
41
- { \
42
- if (!(condition)) \
43
- ABORT_MSG(reason); \
44
- } while (0)
45
-
46
- #define SVFIR_DEBUG 1 /* Turn this on if you're debugging SVFWriter */
47
- #if SVFIR_DEBUG
48
- # define ENSURE_NOT_VISITED(graph) \
49
- do \
50
- { \
51
- static std::set<decltype(graph)> visited; \
52
- bool inserted = visited.insert(graph).second; \
53
- ABORT_IFNOT(inserted, #graph << " already visited!"); \
54
- } while (0)
55
- #else
56
- # define ENSURE_NOT_VISITED(graph) \
57
- do \
58
- { \
59
- } while (0)
60
- #endif
61
- #define FIELD_NAME_ITEM(field) #field, (field)
62
-
63
- #define JSON_FIELD_OR(json, field, default) ((json) ? (json)->field : default)
64
- #define JSON_KEY(json) JSON_FIELD_OR(json, string, "NULL")
65
- #define JSON_CHILD(json) JSON_FIELD_OR(json, child, nullptr)
66
-
67
- #define JSON_WRITE_FIELD(root, objptr, field) \
68
- jsonAddJsonableToObject(root, #field, (objptr)->field)
69
-
70
- #define JSON_READ_OBJ_WITH_NAME(json, obj, name) \
71
- do \
72
- { \
73
- ABORT_IFNOT(jsonKeyEquals(json, name), \
74
- "Expect name '" << name << "', got " << JSON_KEY(json)); \
75
- SVFIRReader::readJson(json, obj); \
76
- } while (0)
77
-
78
- #define JSON_READ_OBJ_WITH_NAME_FWD(json, obj, name) \
79
- do \
80
- { \
81
- JSON_READ_OBJ_WITH_NAME(json, obj, name); \
82
- json = (json)->next; \
83
- } while (0)
84
-
85
- #define JSON_READ_OBJ(json, obj) JSON_READ_OBJ_WITH_NAME(json, obj, #obj)
86
- #define JSON_READ_OBJ_FWD(json, obj) \
87
- JSON_READ_OBJ_WITH_NAME_FWD(json, obj, #obj)
88
- #define JSON_DEF_READ_FWD(json, type, obj, ...) \
89
- type obj __VA_ARGS__; \
90
- JSON_READ_OBJ_FWD(json, obj)
91
- #define JSON_READ_FIELD_FWD(json, objptr, field) \
92
- JSON_READ_OBJ_WITH_NAME_FWD(json, (objptr)->field, #field)
93
- #define CHECK_JSON_KEY_EQUALS(obj, key) \
94
- ABORT_IFNOT(jsonKeyEquals(obj, key), \
95
- "Expect json key: " << key << ", but get " << JSON_KEY(obj));
96
- #define CHECK_JSON_KEY(obj) CHECK_JSON_KEY_EQUALS(obj, #obj)
97
-
98
- namespace SVF
99
- {
100
- /// @brief Forward declarations.
101
- ///@{
102
- class NodeIDAllocator;
103
- // Classes created upon SVFMoudle construction
104
- class SVFType;
105
- class SVFPointerType;
106
- class SVFIntegerType;
107
- class SVFFunctionType;
108
- class SVFStructType;
109
- class SVFArrayType;
110
- class SVFOtherType;
111
-
112
- class StInfo; // Every SVFType is linked to a StInfo. It also references SVFType
113
-
114
- class SVFValue;
115
- class SVFFunction;
116
- class SVFBasicBlock;
117
- class SVFInstruction;
118
- class SVFCallInst;
119
- class SVFConstant;
120
- class SVFGlobalValue;
121
- class SVFArgument;
122
- class SVFConstantData;
123
- class SVFConstantInt;
124
- class SVFConstantFP;
125
- class SVFConstantNullPtr;
126
- class SVFBlackHoleValue;
127
- class SVFOtherValue;
128
- class SVFMetadataAsValue;
129
-
130
- class SVFLoopAndDomInfo; // Part of SVFFunction
131
-
132
-
133
- // Classes created upon ICFG construction
134
- class ICFGNode;
135
- class GlobalICFGNode;
136
- class IntraICFGNode;
137
- class InterICFGNode;
138
- class FunEntryICFGNode;
139
- class FunExitICFGNode;
140
- class CallICFGNode;
141
- class RetICFGNode;
142
-
143
- class ICFGEdge;
144
- class IntraCFGEdge;
145
- class CallCFGEdge;
146
- class RetCFGEdge;
147
-
148
- class SVFIR;
149
- class SVFIRWriter;
150
- class SVFLoop;
151
- class ICFG;
152
- class IRGraph;
153
- class CHGraph;
154
- class CommonCHGraph;
155
- class SymbolTableInfo;
156
-
157
- class SVFModule;
158
-
159
- class AccessPath;
160
- class ObjTypeInfo; // Need SVFType
161
-
162
- class SVFVar;
163
- class ValVar;
164
- class ObjVar;
165
- class GepValVar;
166
- class GepObjVar;
167
- class BaseObjVar;
168
- class RetPN;
169
- class VarArgPN;
170
- class DummyValVar;
171
- class DummyObjVar;
172
-
173
- class SVFStmt;
174
- class AssignStmt;
175
- class AddrStmt;
176
- class CopyStmt;
177
- class StoreStmt;
178
- class LoadStmt;
179
- class GepStmt;
180
- class CallPE;
181
- class RetPE;
182
- class MultiOpndStmt;
183
- class PhiStmt;
184
- class SelectStmt;
185
- class CmpStmt;
186
- class BinaryOPStmt;
187
- class UnaryOPStmt;
188
- class BranchStmt;
189
- class TDForkPE;
190
- class TDJoinPE;
191
-
192
- class CHNode;
193
- class CHEdge;
194
- class CHGraph;
195
- // End of forward declarations
196
- ///@}
197
-
198
- bool jsonIsBool(const cJSON* item);
199
- bool jsonIsBool(const cJSON* item, bool& flag);
200
- bool jsonIsNumber(const cJSON* item);
201
- bool jsonIsString(const cJSON* item);
202
- bool jsonIsNullId(const cJSON* item);
203
- bool jsonIsArray(const cJSON* item);
204
- bool jsonIsMap(const cJSON* item);
205
- bool jsonIsObject(const cJSON* item);
206
- bool jsonKeyEquals(const cJSON* item, const char* key);
207
- std::pair<const cJSON*, const cJSON*> jsonUnpackPair(const cJSON* item);
208
- double jsonGetNumber(const cJSON* item);
209
- cJSON* jsonCreateNullId();
210
- cJSON* jsonCreateObject();
211
- cJSON* jsonCreateArray();
212
- cJSON* jsonCreateString(const char* str);
213
- cJSON* jsonCreateIndex(size_t index);
214
- cJSON* jsonCreateBool(bool flag);
215
- cJSON* jsonCreateNumber(double num);
216
- bool jsonAddPairToMap(cJSON* obj, cJSON* key, cJSON* value);
217
- bool jsonAddItemToObject(cJSON* obj, const char* name, cJSON* item);
218
- bool jsonAddItemToArray(cJSON* array, cJSON* item);
219
- /// @brief Helper function to write a number to a JSON object.
220
- bool jsonAddNumberToObject(cJSON* obj, const char* name, double number);
221
- bool jsonAddStringToObject(cJSON* obj, const char* name, const char* str);
222
- bool jsonAddStringToObject(cJSON* obj, const char* name, const std::string& s);
223
- #define jsonForEach(field, array) \
224
- for (const cJSON* field = JSON_CHILD(array); field; field = field->next)
225
-
226
- /// @brief Bookkeeping class to keep track of the IDs of objects that doesn't
227
- /// have any ID. E.g., SVFValue, XXXEdge.
228
- /// @tparam T
229
- template <typename T> class WriterPtrPool
230
- {
231
- private:
232
- Map<const T*, size_t> ptrToId;
233
- std::vector<const T*> ptrPool;
234
-
235
- public:
236
- inline size_t getID(const T* ptr)
237
- {
238
- if (!ptr)
239
- return 0;
240
-
241
- typename decltype(ptrToId)::iterator it;
242
- bool inserted;
243
- std::tie(it, inserted) = ptrToId.emplace(ptr, 1 + ptrPool.size());
244
- if (inserted)
245
- ptrPool.push_back(ptr);
246
- return it->second;
247
- }
248
-
249
- inline void saveID(const T* ptr)
250
- {
251
- getID(ptr);
252
- }
253
-
254
- inline const T* getPtr(size_t id) const
255
- {
256
- assert(id <= ptrPool.size() && "Invalid ID");
257
- return id ? ptrPool[id - 1] : nullptr;
258
- }
259
-
260
- inline const std::vector<const T*>& getPool() const
261
- {
262
- return ptrPool;
263
- }
264
-
265
- inline size_t size() const
266
- {
267
- return ptrPool.size();
268
- }
269
-
270
- inline void reserve(size_t size)
271
- {
272
- ptrPool.reserve(size);
273
- }
274
-
275
- inline auto begin() const
276
- {
277
- return ptrPool.cbegin();
278
- }
279
-
280
- inline auto end() const
281
- {
282
- return ptrPool.cend();
283
- }
284
- };
285
-
286
- template <typename NodeTy, typename EdgeTy> class GenericGraphWriter
287
- {
288
- friend class SVFIRWriter;
289
-
290
- private:
291
- using NodeType = NodeTy;
292
- using EdgeType = EdgeTy;
293
- using GraphType = GenericGraph<NodeType, EdgeType>;
294
-
295
- // const GraphType* graph;
296
- WriterPtrPool<EdgeType> edgePool;
297
-
298
- public:
299
- GenericGraphWriter(const GraphType* graph)
300
- {
301
- assert(graph && "Graph pointer should never be null");
302
- edgePool.reserve(graph->getTotalEdgeNum());
303
-
304
- for (const auto& pair : graph->IDToNodeMap)
305
- {
306
- const NodeType* node = pair.second;
307
-
308
- for (const EdgeType* edge : node->getOutEdges())
309
- {
310
- edgePool.saveID(edge);
311
- }
312
- }
313
- }
314
-
315
- inline size_t getEdgeID(const EdgeType* edge)
316
- {
317
- return edgePool.getID(edge);
318
- }
319
- };
320
-
321
- using GenericICFGWriter = GenericGraphWriter<ICFGNode, ICFGEdge>;
322
-
323
- class ICFGWriter : public GenericICFGWriter
324
- {
325
- friend class SVFIRWriter;
326
-
327
- private:
328
- WriterPtrPool<SVFLoop> svfLoopPool;
329
-
330
- public:
331
- ICFGWriter(const ICFG* icfg);
332
-
333
- inline size_t getSvfLoopID(const SVFLoop* loop)
334
- {
335
- return svfLoopPool.getID(loop);
336
- }
337
- };
338
-
339
- using IRGraphWriter = GenericGraphWriter<SVFVar, SVFStmt>;
340
- using CHGraphWriter = GenericGraphWriter<CHNode, CHEdge>;
341
-
342
- class SVFModuleWriter
343
- {
344
- friend class SVFIRWriter;
345
-
346
- private:
347
- WriterPtrPool<SVFType> svfTypePool;
348
- WriterPtrPool<StInfo> stInfoPool;
349
- WriterPtrPool<SVFValue> svfValuePool;
350
-
351
- public:
352
- SVFModuleWriter(const SVFModule* svfModule);
353
-
354
- inline size_t getSVFValueID(const SVFValue* value)
355
- {
356
- return svfValuePool.getID(value);
357
- }
358
- inline const SVFValue* getSVFValuePtr(size_t id) const
359
- {
360
- return svfValuePool.getPtr(id);
361
- }
362
- inline size_t getSVFTypeID(const SVFType* type)
363
- {
364
- return svfTypePool.getID(type);
365
- }
366
- inline size_t getStInfoID(const StInfo* stInfo)
367
- {
368
- return stInfoPool.getID(stInfo);
369
- }
370
- inline size_t sizeSVFValuePool() const
371
- {
372
- return svfValuePool.size();
373
- }
374
- };
375
-
376
- class SVFIRWriter
377
- {
378
- private:
379
- const SVFIR* svfIR;
380
-
381
- SVFModuleWriter svfModuleWriter;
382
- ICFGWriter icfgWriter;
383
- CHGraphWriter chgWriter;
384
- IRGraphWriter irGraphWriter;
385
-
386
- OrderedMap<size_t, std::string> numToStrMap;
387
-
388
- public:
389
- using autoJSON = std::unique_ptr<cJSON, decltype(&cJSON_Delete)>;
390
- using autoCStr = std::unique_ptr<char, decltype(&cJSON_free)>;
391
-
392
- /// @brief Constructor.
393
- SVFIRWriter(const SVFIR* svfir);
394
-
395
- static void writeJsonToOstream(const SVFIR* svfir, std::ostream& os);
396
- static void writeJsonToPath(const SVFIR* svfir, const std::string& path);
397
-
398
- private:
399
- /// @brief Main logic to dump a SVFIR to a JSON object.
400
- autoJSON generateJson();
401
- autoCStr generateJsonString();
402
-
403
- const char* numToStr(size_t n);
404
-
405
- cJSON* toJson(const NodeIDAllocator* nodeIDAllocator);
406
- cJSON* toJson(const SymbolTableInfo* symTable);
407
- cJSON* toJson(const SVFModule* module);
408
- cJSON* toJson(const SVFType* type);
409
- cJSON* toJson(const SVFValue* value);
410
- cJSON* toJson(const IRGraph* graph); // IRGraph Graph
411
- cJSON* toJson(const SVFVar* var); // IRGraph Node
412
- cJSON* toJson(const SVFStmt* stmt); // IRGraph Edge
413
- cJSON* toJson(const ICFG* icfg); // ICFG Graph
414
- cJSON* toJson(const ICFGNode* node); // ICFG Node
415
- cJSON* toJson(const ICFGEdge* edge); // ICFG Edge
416
- cJSON* toJson(const CommonCHGraph* graph); // CHGraph Graph
417
- cJSON* toJson(const CHGraph* graph); // CHGraph Graph
418
- cJSON* toJson(const CHNode* node); // CHGraph Node
419
- cJSON* toJson(const CHEdge* edge); // CHGraph Edge
420
-
421
- cJSON* toJson(const AccessPath& ap);
422
- cJSON* toJson(const SVFLoop* loop);
423
- cJSON* toJson(const ObjTypeInfo* objTypeInfo); // Only owned by MemObj
424
- cJSON* toJson(const SVFLoopAndDomInfo* ldInfo); // Only owned by SVFFunction
425
- cJSON* toJson(const StInfo* stInfo);
426
-
427
- // No need for 'toJson(short)' because of promotion to int
428
- static cJSON* toJson(bool flag);
429
- static cJSON* toJson(unsigned number);
430
- static cJSON* toJson(int number);
431
- static cJSON* toJson(float number);
432
- static cJSON* toJson(const std::string& str);
433
- cJSON* toJson(unsigned long number);
434
- cJSON* toJson(long long number);
435
- cJSON* toJson(unsigned long long number);
436
-
437
- /// \brief Parameter types of these functions are all pointers.
438
- /// When they are used as arguments of toJson(), they will be
439
- /// dumped as an index. `contentToJson()` will dump the actual content.
440
- ///@{
441
- cJSON* virtToJson(const SVFType* type);
442
- cJSON* virtToJson(const SVFValue* value);
443
- cJSON* virtToJson(const SVFVar* var);
444
- cJSON* virtToJson(const SVFStmt* stmt);
445
- cJSON* virtToJson(const ICFGNode* node);
446
- cJSON* virtToJson(const ICFGEdge* edge);
447
- cJSON* virtToJson(const CHNode* node);
448
- cJSON* virtToJson(const CHEdge* edge);
449
-
450
- // Classes inherited from SVFVar
451
- cJSON* contentToJson(const SVFVar* var);
452
- cJSON* contentToJson(const ValVar* var);
453
- cJSON* contentToJson(const ObjVar* var);
454
- cJSON* contentToJson(const GepValVar* var);
455
- cJSON* contentToJson(const GepObjVar* var);
456
- cJSON* contentToJson(const BaseObjVar* var);
457
- cJSON* contentToJson(const RetPN* var);
458
- cJSON* contentToJson(const VarArgPN* var);
459
- cJSON* contentToJson(const DummyValVar* var);
460
- cJSON* contentToJson(const DummyObjVar* var);
461
-
462
- // Classes inherited from SVFStmt
463
- cJSON* contentToJson(const SVFStmt* edge);
464
- cJSON* contentToJson(const AssignStmt* edge);
465
- cJSON* contentToJson(const AddrStmt* edge);
466
- cJSON* contentToJson(const CopyStmt* edge);
467
- cJSON* contentToJson(const StoreStmt* edge);
468
- cJSON* contentToJson(const LoadStmt* edge);
469
- cJSON* contentToJson(const GepStmt* edge);
470
- cJSON* contentToJson(const CallPE* edge);
471
- cJSON* contentToJson(const RetPE* edge);
472
- cJSON* contentToJson(const MultiOpndStmt* edge);
473
- cJSON* contentToJson(const PhiStmt* edge);
474
- cJSON* contentToJson(const SelectStmt* edge);
475
- cJSON* contentToJson(const CmpStmt* edge);
476
- cJSON* contentToJson(const BinaryOPStmt* edge);
477
- cJSON* contentToJson(const UnaryOPStmt* edge);
478
- cJSON* contentToJson(const BranchStmt* edge);
479
- cJSON* contentToJson(const TDForkPE* edge);
480
- cJSON* contentToJson(const TDJoinPE* edge);
481
-
482
- // Classes inherited from ICFGNode
483
- cJSON* contentToJson(const ICFGNode* node);
484
- cJSON* contentToJson(const GlobalICFGNode* node);
485
- cJSON* contentToJson(const IntraICFGNode* node);
486
- cJSON* contentToJson(const InterICFGNode* node);
487
- cJSON* contentToJson(const FunEntryICFGNode* node);
488
- cJSON* contentToJson(const FunExitICFGNode* node);
489
- cJSON* contentToJson(const CallICFGNode* node);
490
- cJSON* contentToJson(const RetICFGNode* node);
491
-
492
- // Classes inherited from ICFGEdge
493
- cJSON* contentToJson(const ICFGEdge* edge);
494
- cJSON* contentToJson(const IntraCFGEdge* edge);
495
- cJSON* contentToJson(const CallCFGEdge* edge);
496
- cJSON* contentToJson(const RetCFGEdge* edge);
497
-
498
- // CHNode & CHEdge
499
- cJSON* contentToJson(const CHNode* node);
500
- cJSON* contentToJson(const CHEdge* edge);
501
-
502
- cJSON* contentToJson(const SVFType* type);
503
- cJSON* contentToJson(const SVFPointerType* type);
504
- cJSON* contentToJson(const SVFIntegerType* type);
505
- cJSON* contentToJson(const SVFFunctionType* type);
506
- cJSON* contentToJson(const SVFStructType* type);
507
- cJSON* contentToJson(const SVFArrayType* type);
508
- cJSON* contentToJson(const SVFOtherType* type);
509
-
510
- cJSON* contentToJson(const SVFValue* value);
511
- cJSON* contentToJson(const SVFFunction* value);
512
- cJSON* contentToJson(const SVFBasicBlock* value);
513
- cJSON* contentToJson(const SVFInstruction* value);
514
- cJSON* contentToJson(const SVFCallInst* value);
515
- cJSON* contentToJson(const SVFConstant* value);
516
- cJSON* contentToJson(const SVFGlobalValue* value);
517
- cJSON* contentToJson(const SVFArgument* value);
518
- cJSON* contentToJson(const SVFConstantData* value);
519
- cJSON* contentToJson(const SVFConstantInt* value);
520
- cJSON* contentToJson(const SVFConstantFP* value);
521
- cJSON* contentToJson(const SVFConstantNullPtr* value);
522
- cJSON* contentToJson(const SVFBlackHoleValue* value);
523
- cJSON* contentToJson(const SVFOtherValue* value);
524
- cJSON* contentToJson(const SVFMetadataAsValue* value);
525
-
526
- // Other classes
527
- cJSON* contentToJson(const SVFLoop* loop);
528
- cJSON* contentToJson(const StInfo* stInfo);
529
- ///@}
530
-
531
- template <typename NodeTy, typename EdgeTy>
532
- cJSON* genericNodeToJson(const GenericNode<NodeTy, EdgeTy>* node)
533
- {
534
- cJSON* root = jsonCreateObject();
535
- JSON_WRITE_FIELD(root, node, id);
536
- JSON_WRITE_FIELD(root, node, nodeKind);
537
- JSON_WRITE_FIELD(root, node, InEdges);
538
- JSON_WRITE_FIELD(root, node, OutEdges);
539
- return root;
540
- }
541
-
542
- template <typename NodeTy>
543
- cJSON* genericEdgeToJson(const GenericEdge<NodeTy>* edge)
544
- {
545
- cJSON* root = jsonCreateObject();
546
- JSON_WRITE_FIELD(root, edge, edgeFlag);
547
- JSON_WRITE_FIELD(root, edge, src);
548
- JSON_WRITE_FIELD(root, edge, dst);
549
- return root;
550
- }
551
-
552
- template <typename NodeTy, typename EdgeTy>
553
- cJSON* genericGraphToJson(const GenericGraph<NodeTy, EdgeTy>* graph,
554
- const std::vector<const EdgeTy*>& edgePool)
555
- {
556
- cJSON* root = jsonCreateObject();
557
-
558
- cJSON* allNode = jsonCreateArray();
559
- for (const auto& pair : graph->IDToNodeMap)
560
- {
561
- NodeTy* node = pair.second;
562
- cJSON* jsonNode = virtToJson(node);
563
- jsonAddItemToArray(allNode, jsonNode);
564
- }
565
-
566
- cJSON* allEdge = jsonCreateArray();
567
- for (const EdgeTy* edge : edgePool)
568
- {
569
- cJSON* edgeJson = virtToJson(edge);
570
- jsonAddItemToArray(allEdge, edgeJson);
571
- }
572
-
573
- JSON_WRITE_FIELD(root, graph, nodeNum);
574
- jsonAddItemToObject(root, FIELD_NAME_ITEM(allNode));
575
- JSON_WRITE_FIELD(root, graph, edgeNum);
576
- jsonAddItemToObject(root, FIELD_NAME_ITEM(allEdge));
577
-
578
- return root;
579
- }
580
-
581
- /** The following 2 functions are intended to convert SparseBitVectors
582
- * to JSON. But they're buggy. Commenting them out would enable the
583
- * toJson(T) where is_iterable_v<T> is true. But that implementation is less
584
- * space-efficient if the bitvector contains many elements.
585
- * It is observed that upon construction, SVF IR bitvectors contain at most
586
- * 1 element. In that case, we can just use the toJson(T) for iterable T
587
- * without much space overhead.
588
-
589
- template <unsigned ElementSize>
590
- cJSON* toJson(const SparseBitVectorElement<ElementSize>& element)
591
- {
592
- cJSON* array = jsonCreateArray();
593
- for (const auto v : element.Bits)
594
- {
595
- jsonAddItemToArray(array, toJson(v));
596
- }
597
- return array;
598
- }
599
-
600
- template <unsigned ElementSize>
601
- cJSON* toJson(const SparseBitVector<ElementSize>& bv)
602
- {
603
- return toJson(bv.Elements);
604
- }
605
- */
606
-
607
- template <typename T, typename U> cJSON* toJson(const std::pair<T, U>& pair)
608
- {
609
- cJSON* obj = jsonCreateArray();
610
- jsonAddItemToArray(obj, toJson(pair.first));
611
- jsonAddItemToArray(obj, toJson(pair.second));
612
- return obj;
613
- }
614
-
615
- template <typename T,
616
- typename = std::enable_if_t<SVFUtil::is_iterable_v<T>>>
617
- cJSON* toJson(const T& container)
618
- {
619
- cJSON* array = jsonCreateArray();
620
- for (const auto& item : container)
621
- {
622
- cJSON* itemObj = toJson(item);
623
- jsonAddItemToArray(array, itemObj);
624
- }
625
- return array;
626
- }
627
-
628
- template <typename T>
629
- bool jsonAddJsonableToObject(cJSON* obj, const char* name, const T& item)
630
- {
631
- cJSON* itemObj = toJson(item);
632
- return jsonAddItemToObject(obj, name, itemObj);
633
- }
634
-
635
- template <typename T>
636
- bool jsonAddContentToObject(cJSON* obj, const char* name, const T& item)
637
- {
638
- cJSON* itemObj = contentToJson(item);
639
- return jsonAddItemToObject(obj, name, itemObj);
640
- }
641
- };
642
-
643
- /*
644
- * Reader Part
645
- */
646
-
647
- /// @brief Type trait to get base type.
648
- /// Helper struct to detect inheritance from Node/Edge
649
- ///@}
650
- template <typename T, typename = void> struct KindBaseHelper
651
- {
652
- };
653
- #define KIND_BASE(B, KindGetter) \
654
- template <typename T> \
655
- struct KindBaseHelper<T, std::enable_if_t<std::is_base_of<B, T>::value>> \
656
- { \
657
- using type = B; \
658
- static inline s64_t getKind(T* p) \
659
- { \
660
- return {p->KindGetter()}; \
661
- } \
662
- }
663
- KIND_BASE(SVFType, getKind);
664
- KIND_BASE(SVFValue, getKind);
665
- KIND_BASE(SVFVar, getNodeKind);
666
- KIND_BASE(SVFStmt, getEdgeKind);
667
- KIND_BASE(ICFGNode, getNodeKind);
668
- KIND_BASE(ICFGEdge, getEdgeKind);
669
- KIND_BASE(CHNode, getNodeKind);
670
- KIND_BASE(CHEdge, getEdgeKind);
671
- #undef KIND_BASE
672
-
673
- template <typename T> using KindBaseT = typename KindBaseHelper<T>::type;
674
- ///@}
675
-
676
- /// @brief Keeps a map from IDs to T objects, such as XXNode.
677
- /// @tparam T: The type of the objects.
678
- template <typename T> class ReaderIDToObjMap
679
- {
680
- private:
681
- using IDToPairMapTy = OrderedMap<unsigned, std::pair<const cJSON*, T*>>;
682
- IDToPairMapTy idMap;
683
-
684
- public:
685
- template <typename IdObjCreator>
686
- /// idObjcreator : (const cJSON*) -> (id, T*) with id set
687
- void createObjs(const cJSON* idObjArrayJson, IdObjCreator idObjCreator)
688
- {
689
- assert(idMap.empty() &&
690
- "idToObjMap should be empty when creating objects");
691
- ABORT_IFNOT(jsonIsArray(idObjArrayJson), "expects an array");
692
-
693
- jsonForEach(objJson, idObjArrayJson)
694
- {
695
- ABORT_IFNOT(jsonIsObject(objJson), "expects an object");
696
- const cJSON* objFieldJson = objJson->child;
697
- // creator is allowed to change objFieldJson
698
- auto idObj = idObjCreator(objFieldJson);
699
- auto pair = std::pair<const cJSON*, T*>(objFieldJson, idObj.second);
700
- bool inserted = idMap.emplace(idObj.first, pair).second;
701
- ABORT_IFNOT(inserted, "ID " << idObj.first << " duplicated in "
702
- << idObjArrayJson->string);
703
- }
704
- }
705
-
706
- T* getPtr(unsigned id) const
707
- {
708
- auto it = idMap.find(id);
709
- ABORT_IFNOT(it != idMap.end(), "ID " << id << " not found");
710
- return it->second.second;
711
- }
712
-
713
- template <typename FillFunc> void fillObjs(FillFunc fillFunc)
714
- {
715
- for (auto& pair : idMap)
716
- {
717
- const cJSON* objFieldJson = pair.second.first;
718
- T* obj = pair.second.second;
719
- fillFunc(objFieldJson, obj);
720
-
721
- ABORT_IFNOT(!objFieldJson, "json should be consumed by filler, but "
722
- << objFieldJson->string << " left");
723
- }
724
- }
725
-
726
- inline size_t size() const
727
- {
728
- return idMap.size();
729
- }
730
-
731
- template <typename Map> void saveToIDToObjMap(Map& idToObjMap) const
732
- {
733
- for (auto& pair : idMap)
734
- {
735
- unsigned id = pair.first;
736
- T* obj = pair.second.second;
737
- assert(obj && "obj should not be null");
738
- idToObjMap.insert(std::make_pair(id, obj));
739
- }
740
- }
741
- };
742
-
743
- /// @brief Reverse of WriterPtrPool where T is object type without ID field.
744
- /// @tparam T
745
- template <typename T> class ReaderPtrPool
746
- {
747
- private:
748
- std::vector<const cJSON*> jsonArray;
749
- std::vector<T*> ptrPool;
750
-
751
- public:
752
- inline void reserve(size_t size)
753
- {
754
- jsonArray.reserve(size);
755
- ptrPool.reserve(size);
756
- }
757
-
758
- /// @brief
759
- /// @tparam Creator
760
- /// @param objArrayJson
761
- /// @param creator
762
- template <typename Creator>
763
- void createObjs(const cJSON* objArrayJson, Creator creator)
764
- {
765
- assert(jsonArray.empty() &&
766
- "jsonArray should be empty when creating objects");
767
- ABORT_IFNOT(jsonIsArray(objArrayJson), "expects an array");
768
-
769
- jsonForEach(objJson, objArrayJson)
770
- {
771
- ABORT_IFNOT(jsonIsObject(objJson), "expects objects in array");
772
- const cJSON* objFieldJson = objJson->child;
773
- T* obj = creator(objFieldJson);
774
- jsonArray.push_back(objFieldJson);
775
- ptrPool.push_back(obj);
776
- }
777
- }
778
-
779
- T* getPtr(size_t id) const
780
- {
781
- ABORT_IFNOT(id <= ptrPool.size(),
782
- "Invalid ID " << id << ". Max ID = " << ptrPool.size());
783
- return id ? ptrPool[id - 1] : nullptr;
784
- }
785
-
786
- template <typename FillFunc> void fillObjs(FillFunc fillFunc)
787
- {
788
- assert(jsonArray.size() == ptrPool.size() &&
789
- "jsonArray and ptrPool should have same size");
790
- for (size_t i = 0; i < jsonArray.size(); ++i)
791
- {
792
- const cJSON*& objFieldJson = jsonArray[i];
793
- fillFunc(objFieldJson, ptrPool[i]);
794
- ABORT_IFNOT(!objFieldJson, "json should be consumed by filler, but "
795
- << objFieldJson->string << " left");
796
- }
797
- jsonArray.clear();
798
- jsonArray.shrink_to_fit();
799
- }
800
-
801
- inline size_t size() const
802
- {
803
- return ptrPool.size();
804
- }
805
-
806
- template <typename Set> void saveToSet(Set& set) const
807
- {
808
- for (T* obj : ptrPool)
809
- {
810
- set.insert(obj);
811
- }
812
- }
813
- };
814
-
815
- template <typename NodeTy, typename EdgeTy> class GenericGraphReader
816
- {
817
- private:
818
- ReaderIDToObjMap<NodeTy> idToNodeMap;
819
- ReaderPtrPool<EdgeTy> edgePool;
820
-
821
- protected:
822
- const cJSON* graphFieldJson = nullptr;
823
-
824
- public:
825
- template <typename NodeCreator, typename EdgeCreator>
826
- void createObjs(const cJSON* graphJson, NodeCreator nodeCreator,
827
- EdgeCreator edgeCreator)
828
- {
829
- // Read nodeNum
830
- const cJSON* nodeNum = graphJson->child;
831
- CHECK_JSON_KEY(nodeNum);
832
- u32_t numOfNodes = jsonGetNumber(nodeNum);
833
- (void)numOfNodes;
834
-
835
- // Read allNode
836
- const cJSON* allNode = nodeNum->next;
837
- CHECK_JSON_KEY(allNode);
838
- idToNodeMap.createObjs(allNode, nodeCreator);
839
- // TODO: ABORT_IFNOT(idToNodeMap.size() == numOfNodes, "nodeNum mismatch");
840
-
841
- // Read edgeNum
842
- const cJSON* edgeNum = allNode->next;
843
- CHECK_JSON_KEY(edgeNum);
844
- u32_t numOfEdges = jsonGetNumber(edgeNum);
845
- (void)numOfEdges;
846
-
847
- // Read allEdge
848
- const cJSON* allEdge = edgeNum->next;
849
- CHECK_JSON_KEY(allEdge);
850
- edgePool.createObjs(allEdge, edgeCreator);
851
- // TODO: ABORT_IFNOT(edgePool.size() == numOfEdges, "edgeNum mismatch");
852
-
853
- // Rest fields
854
- assert(!graphFieldJson && "graphFieldJson should be empty");
855
- graphFieldJson = allEdge->next;
856
- }
857
-
858
- inline NodeTy* getNodePtr(unsigned id) const
859
- {
860
- return idToNodeMap.getPtr(id);
861
- }
862
-
863
- inline EdgeTy* getEdgePtr(unsigned id) const
864
- {
865
- return edgePool.getPtr(id);
866
- }
867
-
868
- template <typename NodeFiller, typename EdgeFiller>
869
- void fillObjs(NodeFiller nodeFiller, EdgeFiller edgeFiller)
870
- {
871
- // GenericNode<> contains field `InEdges` and `OutEdges`, which are
872
- // ordered set of edges with comparator `GenericEdge::equalGEdge()`,
873
- // which need operands `src` and `dst` to be non-null to get IDs, so we
874
- // need to fill nodes first.
875
- edgePool.fillObjs(edgeFiller);
876
- idToNodeMap.fillObjs(nodeFiller);
877
- }
878
-
879
- void saveToGenericGraph(GenericGraph<NodeTy, EdgeTy>* graph) const
880
- {
881
- graph->edgeNum = edgePool.size();
882
- graph->nodeNum = idToNodeMap.size();
883
- idToNodeMap.saveToIDToObjMap(graph->IDToNodeMap);
884
- }
885
-
886
- const cJSON* getFieldJson() const
887
- {
888
- return graphFieldJson;
889
- }
890
- };
891
-
892
- class SymbolTableInfoReader
893
- {
894
- friend class SVFIRReader;
895
-
896
- private:
897
- const cJSON* symTabFieldJson = nullptr;
898
-
899
- public:
900
-
901
- template <typename MemObjCreator>
902
- void createObjs(const cJSON* symTabJson, MemObjCreator memObjCreator)
903
- {
904
- assert(!symTabFieldJson && "symTabFieldJson should be empty");
905
- ABORT_IFNOT(jsonIsObject(symTabJson), "symTableJson is not an object?");
906
-
907
- const cJSON* const allMemObj = symTabJson->child;
908
- CHECK_JSON_KEY(allMemObj);
909
-
910
- symTabFieldJson = allMemObj->next;
911
- }
912
-
913
- inline const cJSON* getFieldJson() const
914
- {
915
- return symTabFieldJson;
916
- }
917
- };
918
-
919
- using GenericICFGReader = GenericGraphReader<ICFGNode, ICFGEdge>;
920
- using CHGraphReader = GenericGraphReader<CHNode, CHEdge>;
921
- using IRGraphReader = GenericGraphReader<SVFVar, SVFStmt>;
922
-
923
- class ICFGReader : public GenericICFGReader
924
- {
925
- // friend class SVFIRReader;
926
-
927
- private:
928
- ReaderPtrPool<SVFLoop> svfLoopPool;
929
-
930
- public:
931
- template <typename NodeCreator, typename EdgeCreator, typename SVFLoopCreator>
932
- void createObjs(const cJSON* icfgJson, NodeCreator nodeCreator,
933
- EdgeCreator edgeCreator, SVFLoopCreator svfLoopCreator)
934
- {
935
- GenericICFGReader::createObjs(icfgJson, nodeCreator, edgeCreator);
936
-
937
- const cJSON* const allSvfLoop = graphFieldJson;
938
- CHECK_JSON_KEY(allSvfLoop);
939
- svfLoopPool.createObjs(graphFieldJson, svfLoopCreator);
940
- graphFieldJson = allSvfLoop->next;
941
- }
942
-
943
- inline SVFLoop* getSVFLoopPtr(size_t id) const
944
- {
945
- return svfLoopPool.getPtr(id);
946
- }
947
-
948
- template <typename NodeFiller, typename EdgeFiller, typename LoopFiller>
949
- void fillObjs(NodeFiller nodeFiller, EdgeFiller edgeFiller,
950
- LoopFiller loopFiller)
951
- {
952
- GenericICFGReader::fillObjs(nodeFiller, edgeFiller);
953
- svfLoopPool.fillObjs(loopFiller);
954
- }
955
- };
956
-
957
- class SVFModuleReader
958
- {
959
- friend class SVFIRReader;
960
-
961
- private:
962
- const cJSON* svfModuleFieldJson = nullptr;
963
- ReaderPtrPool<SVFType> svfTypePool;
964
- ReaderPtrPool<StInfo> stInfoPool;
965
- ReaderPtrPool<SVFValue> svfValuePool;
966
-
967
- public:
968
- template <typename SVFTypeCreator, typename SVFTypeFiller,
969
- typename SVFValueCreator, typename SVFValueFiller,
970
- typename StInfoCreator>
971
- void createObjs(const cJSON* svfModuleJson, SVFTypeCreator typeCreator,
972
- SVFTypeFiller typeFiller, SVFValueCreator valueCreator,
973
- SVFValueFiller valueFiller, StInfoCreator stInfoCreator)
974
- {
975
- assert(!svfModuleFieldJson && "SVFModule Already created?");
976
- ABORT_IFNOT(jsonIsObject(svfModuleJson),
977
- "svfModuleJson not an JSON object?");
978
-
979
- const cJSON* const allSVFType = svfModuleJson->child;
980
- CHECK_JSON_KEY(allSVFType);
981
- svfTypePool.createObjs(allSVFType, typeCreator);
982
-
983
- const cJSON* const allStInfo = allSVFType->next;
984
- CHECK_JSON_KEY(allStInfo);
985
- stInfoPool.createObjs(allStInfo, stInfoCreator); // Only need SVFType*
986
-
987
- svfTypePool.fillObjs(typeFiller); // Only need SVFType* & StInfo*
988
-
989
- const cJSON* const allSVFValue = allStInfo->next;
990
- CHECK_JSON_KEY(allSVFValue);
991
- svfValuePool.createObjs(allSVFValue, valueCreator);
992
- svfValuePool.fillObjs(valueFiller); // Need SVFType* & SVFValue*
993
-
994
- svfModuleFieldJson = allSVFValue->next;
995
- }
996
-
997
- inline SVFValue* getSVFValuePtr(size_t id) const
998
- {
999
- return svfValuePool.getPtr(id);
1000
- }
1001
- inline SVFType* getSVFTypePtr(size_t id) const
1002
- {
1003
- return svfTypePool.getPtr(id);
1004
- }
1005
- inline StInfo* getStInfoPtr(size_t id) const
1006
- {
1007
- return stInfoPool.getPtr(id);
1008
- }
1009
-
1010
- const cJSON* getFieldJson() const
1011
- {
1012
- return svfModuleFieldJson;
1013
- }
1014
- };
1015
-
1016
- /* SVFIRReader
1017
- * Read SVFIR from JSON
1018
- */
1019
-
1020
- class SVFIRReader
1021
- {
1022
- private:
1023
- SVFModuleReader svfModuleReader;
1024
- SymbolTableInfoReader symTableReader;
1025
- ICFGReader icfgReader;
1026
- CHGraphReader chGraphReader;
1027
- IRGraphReader irGraphReader;
1028
-
1029
- public:
1030
- static SVFIR* read(const std::string& path);
1031
-
1032
- static void readJson(const cJSON* obj, bool& flag);
1033
- static void readJson(const cJSON* obj, unsigned& val);
1034
- static void readJson(const cJSON* obj, int& val);
1035
- static void readJson(const cJSON* obj, short& val);
1036
- static void readJson(const cJSON* obj, float& val);
1037
- static void readJson(const cJSON* obj, unsigned long& val);
1038
- static void readJson(const cJSON* obj, long long& val);
1039
- static void readJson(const cJSON* obj, unsigned long long& val);
1040
- static void readJson(const cJSON* obj, std::string& str);
1041
-
1042
- // Helper functions
1043
- static inline s64_t applyEdgeMask(u64_t edgeFlag)
1044
- {
1045
- return edgeFlag & GenericEdge<void>::EdgeKindMask;
1046
- }
1047
- template <typename T>
1048
- static inline void setEdgeFlag(GenericEdge<T>* edge,
1049
- typename GenericEdge<T>::GEdgeFlag edgeFlag)
1050
- {
1051
- edge->edgeFlag = edgeFlag;
1052
- }
1053
-
1054
- private:
1055
- using GNodeK = s32_t;
1056
- using GEdgeFlag = GenericEdge<void>::GEdgeFlag;
1057
- using GEdgeKind = GenericEdge<void>::GEdgeKind;
1058
- static ICFGNode* createICFGNode(NodeID id, GNodeK type);
1059
- static ICFGEdge* createICFGEdge(GEdgeKind kind);
1060
- static CHNode* createCHNode(NodeID id, GNodeK kind);
1061
- static CHEdge* createCHEdge(GEdgeKind kind);
1062
- static SVFVar* createPAGNode(NodeID id, GNodeK kind);
1063
- static SVFStmt* createPAGEdge(GEdgeKind kind);
1064
-
1065
- template <typename EdgeCreator>
1066
- static inline auto createEdgeWithFlag(GEdgeFlag flag, EdgeCreator creator)
1067
- {
1068
- auto kind = SVFIRReader::applyEdgeMask(flag);
1069
- auto edge = creator(kind);
1070
- setEdgeFlag(edge, flag);
1071
- return edge;
1072
- }
1073
-
1074
- SVFIR* read(const cJSON* root);
1075
- const cJSON* createObjs(const cJSON* root);
1076
-
1077
- void readJson(const cJSON* obj, NodeIDAllocator* idAllocator);
1078
- void readJson(SymbolTableInfo* symTabInfo);
1079
- void readJson(IRGraph* graph); // IRGraph Graph
1080
- void readJson(ICFG* icfg); // ICFG Graph
1081
- void readJson(CHGraph* graph); // CHGraph Graph
1082
- void readJson(SVFModule* module);
1083
-
1084
- void readJson(const cJSON* obj, SVFType*& type);
1085
- void readJson(const cJSON* obj, StInfo*& stInfo);
1086
- void readJson(const cJSON* obj, SVFValue*& value);
1087
-
1088
- void readJson(const cJSON* obj, SVFVar*& var); // IRGraph Node
1089
- void readJson(const cJSON* obj, SVFStmt*& stmt); // IRGraph Edge
1090
- void readJson(const cJSON* obj, ICFGNode*& node); // ICFG Node
1091
- void readJson(const cJSON* obj, ICFGEdge*& edge); // ICFG Edge
1092
- void readJson(const cJSON* obj, CHNode*& node); // CHGraph Node
1093
- void readJson(const cJSON* obj, CHEdge*& edge); // CHGraph Edge
1094
-
1095
- void readJson(const cJSON* obj, AccessPath& ap);
1096
- void readJson(const cJSON* obj, SVFLoop*& loop);
1097
- void readJson(const cJSON* obj,
1098
- ObjTypeInfo*& objTypeInfo); // Only owned by MemObj
1099
- void readJson(const cJSON* obj,
1100
- SVFLoopAndDomInfo*& ldInfo); // Only owned by SVFFunction
1101
-
1102
- template <unsigned ElementSize>
1103
- inline void readJson(const cJSON* obj, SparseBitVector<ElementSize>& bv)
1104
- {
1105
- ABORT_IFNOT(jsonIsArray(obj), "SparseBitVector should be an array");
1106
- jsonForEach(nObj, obj)
1107
- {
1108
- unsigned n;
1109
- readJson(nObj, n);
1110
- bv.set(n);
1111
- }
1112
- }
1113
-
1114
- /* See comment of toJson(SparseBitVectorElement) for reason of commenting
1115
- it out.
1116
- template <unsigned ElementSize>
1117
- inline void readJson(const cJSON* obj,
1118
- SparseBitVectorElement<ElementSize>& element)
1119
- {
1120
- readJson(obj, element.Bits);
1121
- }
1122
- */
1123
-
1124
- /// @brief Read a pointer of some child class of
1125
- /// SVFType/SVFValue/SVFVar/SVFStmt/ICFGNode/ICFGEdge/CHNode/CHEdge
1126
- template <typename T>
1127
- inline SVFUtil::void_t<KindBaseT<T>> readJson(const cJSON* obj, T*& ptr)
1128
- {
1129
- // TODO: Can be optimized?
1130
- KindBaseT<T>* basePtr = ptr;
1131
- readJson(obj, basePtr);
1132
- if (!basePtr)
1133
- return; // ptr is nullptr when read
1134
- ptr = SVFUtil::dyn_cast<T>(basePtr);
1135
- ABORT_IFNOT(ptr, "Cast: " << obj->string << " shouldn't have kind "
1136
- << KindBaseHelper<T>::getKind(ptr));
1137
- }
1138
-
1139
- /// Read a const pointer
1140
- template <typename T> inline void readJson(const cJSON* obj, const T*& cptr)
1141
- {
1142
- assert(!cptr && "const pointer should be NULL");
1143
- T* ptr{};
1144
- readJson(obj, ptr);
1145
- cptr = ptr;
1146
- }
1147
-
1148
- template <typename T1, typename T2>
1149
- void readJson(const cJSON* obj, std::pair<T1, T2>& pair)
1150
- {
1151
- auto jpair = jsonUnpackPair(obj);
1152
- readJson(jpair.first, pair.first);
1153
- readJson(jpair.second, pair.second);
1154
- }
1155
-
1156
- template <typename T, size_t N>
1157
- void readJson(const cJSON* obj, T (&array)[N])
1158
- {
1159
- static_assert(N > 0, "array size should be greater than 0");
1160
- ABORT_IFNOT(jsonIsArray(obj), "array expects an array");
1161
- size_t i = 0;
1162
- jsonForEach(elemJson, obj)
1163
- {
1164
- readJson(elemJson, array[i]);
1165
- if (++i >= N)
1166
- break;
1167
- }
1168
- ABORT_IFNOT(i == N, "expect array of size " << N);
1169
- }
1170
-
1171
- template <typename C>
1172
- std::enable_if_t<SVFUtil::is_sequence_container_v<C>> readJson(
1173
- const cJSON* obj, C& container)
1174
- {
1175
- using T = typename C::value_type;
1176
- assert(container.empty() && "container should be empty");
1177
- ABORT_IFNOT(jsonIsArray(obj), "vector expects an array");
1178
- jsonForEach(elemJson, obj)
1179
- {
1180
- container.push_back(T{});
1181
- readJson(elemJson, container.back());
1182
- }
1183
- }
1184
-
1185
- template <typename C>
1186
- std::enable_if_t<SVFUtil::is_map_v<C>> readJson(const cJSON* obj, C& map)
1187
- {
1188
- assert(map.empty() && "map should be empty");
1189
- ABORT_IFNOT(jsonIsMap(obj), "expects an map (represented by array)");
1190
- jsonForEach(elemJson, obj)
1191
- {
1192
- auto jpair = jsonUnpackPair(elemJson);
1193
- typename C::key_type key{};
1194
- readJson(jpair.first, key);
1195
- auto it = map.emplace(std::move(key), typename C::mapped_type{});
1196
- ABORT_IFNOT(it.second, "Duplicated map key");
1197
- readJson(jpair.second, it.first->second);
1198
- }
1199
- }
1200
-
1201
- template <typename C>
1202
- std::enable_if_t<SVFUtil::is_set_v<C>> readJson(const cJSON* obj, C& set)
1203
- {
1204
- using T = typename C::value_type;
1205
- assert(set.empty() && "set should be empty");
1206
- ABORT_IFNOT(jsonIsArray(obj), "expects an array");
1207
- jsonForEach(elemJson, obj)
1208
- {
1209
- T elem{};
1210
- readJson(elemJson, elem);
1211
- auto inserted = set.insert(std::move(elem)).second;
1212
- ABORT_IFNOT(inserted, "Duplicated set element");
1213
- }
1214
- }
1215
-
1216
- // IGRaph
1217
- void virtFill(const cJSON*& fieldJson, SVFVar* var);
1218
- void fill(const cJSON*& fieldJson, SVFVar* var);
1219
- void fill(const cJSON*& fieldJson, ValVar* var);
1220
- void fill(const cJSON*& fieldJson, ObjVar* var);
1221
- void fill(const cJSON*& fieldJson, GepValVar* var);
1222
- void fill(const cJSON*& fieldJson, GepObjVar* var);
1223
- void fill(const cJSON*& fieldJson, BaseObjVar* var);
1224
- void fill(const cJSON*& fieldJson, RetPN* var);
1225
- void fill(const cJSON*& fieldJson, VarArgPN* var);
1226
- void fill(const cJSON*& fieldJson, DummyValVar* var);
1227
- void fill(const cJSON*& fieldJson, DummyObjVar* var);
1228
-
1229
- void virtFill(const cJSON*& fieldJson, SVFStmt* stmt);
1230
- void fill(const cJSON*& fieldJson, SVFStmt* stmt);
1231
- void fill(const cJSON*& fieldJson, AssignStmt* stmt);
1232
- void fill(const cJSON*& fieldJson, AddrStmt* stmt);
1233
- void fill(const cJSON*& fieldJson, CopyStmt* stmt);
1234
- void fill(const cJSON*& fieldJson, StoreStmt* stmt);
1235
- void fill(const cJSON*& fieldJson, LoadStmt* stmt);
1236
- void fill(const cJSON*& fieldJson, GepStmt* stmt);
1237
- void fill(const cJSON*& fieldJson, CallPE* stmt);
1238
- void fill(const cJSON*& fieldJson, RetPE* stmt);
1239
- void fill(const cJSON*& fieldJson, MultiOpndStmt* stmt);
1240
- void fill(const cJSON*& fieldJson, PhiStmt* stmt);
1241
- void fill(const cJSON*& fieldJson, SelectStmt* stmt);
1242
- void fill(const cJSON*& fieldJson, CmpStmt* stmt);
1243
- void fill(const cJSON*& fieldJson, BinaryOPStmt* stmt);
1244
- void fill(const cJSON*& fieldJson, UnaryOPStmt* stmt);
1245
- void fill(const cJSON*& fieldJson, BranchStmt* stmt);
1246
- void fill(const cJSON*& fieldJson, TDForkPE* stmt);
1247
- void fill(const cJSON*& fieldJson, TDJoinPE* stmt);
1248
-
1249
- void fill(const cJSON*& fieldJson, StInfo* stInfo);
1250
- // ICFG
1251
- void virtFill(const cJSON*& fieldJson, ICFGNode* node);
1252
- void fill(const cJSON*& fieldJson, ICFGNode* node);
1253
- void fill(const cJSON*& fieldJson, GlobalICFGNode* node);
1254
- void fill(const cJSON*& fieldJson, IntraICFGNode* node);
1255
- void fill(const cJSON*& fieldJson, InterICFGNode* node);
1256
- void fill(const cJSON*& fieldJson, FunEntryICFGNode* node);
1257
- void fill(const cJSON*& fieldJson, FunExitICFGNode* node);
1258
- void fill(const cJSON*& fieldJson, CallICFGNode* node);
1259
- void fill(const cJSON*& fieldJson, RetICFGNode* node);
1260
-
1261
- void virtFill(const cJSON*& fieldJson, ICFGEdge* node);
1262
- void fill(const cJSON*& fieldJson, ICFGEdge* edge);
1263
- void fill(const cJSON*& fieldJson, IntraCFGEdge* edge);
1264
- void fill(const cJSON*& fieldJson, CallCFGEdge* edge);
1265
- void fill(const cJSON*& fieldJson, RetCFGEdge* edge);
1266
-
1267
- void fill(const cJSON*& fieldJson, SVFLoop* loop);
1268
- // CHGraph
1269
- void virtFill(const cJSON*& fieldJson, CHNode* node);
1270
- void virtFill(const cJSON*& fieldJson, CHEdge* edge);
1271
-
1272
- // SVFModule
1273
- void virtFill(const cJSON*& fieldJson, SVFValue* value);
1274
- void fill(const cJSON*& fieldJson, SVFValue* value);
1275
- void fill(const cJSON*& fieldJson, SVFFunction* value);
1276
- void fill(const cJSON*& fieldJson, SVFBasicBlock* value);
1277
- void fill(const cJSON*& fieldJson, SVFInstruction* value);
1278
- void fill(const cJSON*& fieldJson, SVFCallInst* value);
1279
- void fill(const cJSON*& fieldJson, SVFConstant* value);
1280
- void fill(const cJSON*& fieldJson, SVFGlobalValue* value);
1281
- void fill(const cJSON*& fieldJson, SVFArgument* value);
1282
- void fill(const cJSON*& fieldJson, SVFConstantData* value);
1283
- void fill(const cJSON*& fieldJson, SVFConstantInt* value);
1284
- void fill(const cJSON*& fieldJson, SVFConstantFP* value);
1285
- void fill(const cJSON*& fieldJson, SVFConstantNullPtr* value);
1286
- void fill(const cJSON*& fieldJson, SVFBlackHoleValue* value);
1287
- void fill(const cJSON*& fieldJson, SVFOtherValue* value);
1288
- void fill(const cJSON*& fieldJson, SVFMetadataAsValue* value);
1289
-
1290
- void virtFill(const cJSON*& fieldJson, SVFType* type);
1291
- void fill(const cJSON*& fieldJson, SVFType* type);
1292
- void fill(const cJSON*& fieldJson, SVFPointerType* type);
1293
- void fill(const cJSON*& fieldJson, SVFIntegerType* type);
1294
- void fill(const cJSON*& fieldJson, SVFFunctionType* type);
1295
- void fill(const cJSON*& fieldJson, SVFStructType* type);
1296
- void fill(const cJSON*& fieldJson, SVFArrayType* type);
1297
- void fill(const cJSON*& fieldJson, SVFOtherType* type);
1298
-
1299
- template <typename NodeTy, typename EdgeTy>
1300
- void fill(const cJSON*& fieldJson, GenericNode<NodeTy, EdgeTy>* node)
1301
- {
1302
- // id and nodeKind have already been read.
1303
- JSON_READ_FIELD_FWD(fieldJson, node, InEdges);
1304
- JSON_READ_FIELD_FWD(fieldJson, node, OutEdges);
1305
- }
1306
-
1307
- template <typename NodeTy>
1308
- void fill(const cJSON*& fieldJson, GenericEdge<NodeTy>* edge)
1309
- {
1310
- // edgeFlag has already been read.
1311
- JSON_READ_FIELD_FWD(fieldJson, edge, src);
1312
- JSON_READ_FIELD_FWD(fieldJson, edge, dst);
1313
- }
1314
- };
1315
-
1316
- } // namespace SVF
1317
-
1318
- #endif // !INCLUDE_SVFFILESYSTEM_H_