svf-lib 1.0.1375 → 1.0.1376

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.
Files changed (147) hide show
  1. package/SVF-osx/Release-build/svf-llvm/libSvfLLVM.a +0 -0
  2. package/SVF-osx/svf/include/include/AbstractExecution/AbstractValue.h +79 -0
  3. package/SVF-osx/svf/include/include/AbstractExecution/AddressValue.h +210 -0
  4. package/SVF-osx/svf/include/include/AbstractExecution/ExeState.h +223 -0
  5. package/SVF-osx/svf/include/include/AbstractExecution/IntervalExeState.h +425 -0
  6. package/SVF-osx/svf/include/include/AbstractExecution/IntervalValue.h +868 -0
  7. package/SVF-osx/svf/include/include/AbstractExecution/NumericLiteral.h +406 -0
  8. package/SVF-osx/svf/include/include/AbstractExecution/RelExeState.h +225 -0
  9. package/SVF-osx/svf/include/include/AbstractExecution/RelationSolver.h +68 -0
  10. package/SVF-osx/svf/include/include/AbstractExecution/SVFIR2ItvExeState.h +186 -0
  11. package/SVF-osx/svf/include/include/AbstractExecution/WTO.h +845 -0
  12. package/SVF-osx/svf/include/include/CFL/CFGNormalizer.h +84 -0
  13. package/SVF-osx/svf/include/include/CFL/CFLAlias.h +176 -0
  14. package/SVF-osx/svf/include/include/CFL/CFLBase.h +115 -0
  15. package/SVF-osx/svf/include/include/CFL/CFLData.h +316 -0
  16. package/SVF-osx/svf/include/include/CFL/CFLDataBuilder.h +91 -0
  17. package/SVF-osx/svf/include/include/CFL/CFLGramGraphChecker.h +74 -0
  18. package/SVF-osx/svf/include/include/CFL/CFLGrammar.h +468 -0
  19. package/SVF-osx/svf/include/include/CFL/CFLGrammar.txt +15 -0
  20. package/SVF-osx/svf/include/include/CFL/CFLGraphBuilder.h +193 -0
  21. package/SVF-osx/svf/include/include/CFL/CFLSolver.h +136 -0
  22. package/SVF-osx/svf/include/include/CFL/CFLStat.h +67 -0
  23. package/SVF-osx/svf/include/include/CFL/CFLVF.h +65 -0
  24. package/SVF-osx/svf/include/include/CFL/GrammarBuilder.h +100 -0
  25. package/SVF-osx/svf/include/include/CFL/PEGGrammar.txt +11 -0
  26. package/SVF-osx/svf/include/include/CFL/VFG.txt +7 -0
  27. package/SVF-osx/svf/include/include/DDA/ContextDDA.h +230 -0
  28. package/SVF-osx/svf/include/include/DDA/DDAClient.h +168 -0
  29. package/SVF-osx/svf/include/include/DDA/DDAPass.h +99 -0
  30. package/SVF-osx/svf/include/include/DDA/DDAStat.h +138 -0
  31. package/SVF-osx/svf/include/include/DDA/DDAVFSolver.h +789 -0
  32. package/SVF-osx/svf/include/include/DDA/FlowDDA.h +178 -0
  33. package/SVF-osx/svf/include/include/FastCluster/LICENSE.TXT +13 -0
  34. package/SVF-osx/svf/include/include/FastCluster/fastcluster.h +80 -0
  35. package/SVF-osx/svf/include/include/Graphs/CFLGraph.h +215 -0
  36. package/SVF-osx/svf/include/include/Graphs/CHG.h +351 -0
  37. package/SVF-osx/svf/include/include/Graphs/ConsG.h +408 -0
  38. package/SVF-osx/svf/include/include/Graphs/ConsGEdge.h +353 -0
  39. package/SVF-osx/svf/include/include/Graphs/ConsGNode.h +391 -0
  40. package/SVF-osx/svf/include/include/Graphs/DOTGraphTraits.h +188 -0
  41. package/SVF-osx/svf/include/include/Graphs/GenericGraph.h +620 -0
  42. package/SVF-osx/svf/include/include/Graphs/GraphPrinter.h +111 -0
  43. package/SVF-osx/svf/include/include/Graphs/GraphTraits.h +150 -0
  44. package/SVF-osx/svf/include/include/Graphs/GraphWriter.h +380 -0
  45. package/SVF-osx/svf/include/include/Graphs/ICFG.h +331 -0
  46. package/SVF-osx/svf/include/include/Graphs/ICFGEdge.h +264 -0
  47. package/SVF-osx/svf/include/include/Graphs/ICFGNode.h +523 -0
  48. package/SVF-osx/svf/include/include/Graphs/ICFGStat.h +164 -0
  49. package/SVF-osx/svf/include/include/Graphs/IRGraph.h +243 -0
  50. package/SVF-osx/svf/include/include/Graphs/PTACallGraph.h +471 -0
  51. package/SVF-osx/svf/include/include/Graphs/SVFG.h +490 -0
  52. package/SVF-osx/svf/include/include/Graphs/SVFGEdge.h +237 -0
  53. package/SVF-osx/svf/include/include/Graphs/SVFGNode.h +513 -0
  54. package/SVF-osx/svf/include/include/Graphs/SVFGOPT.h +362 -0
  55. package/SVF-osx/svf/include/include/Graphs/SVFGStat.h +273 -0
  56. package/SVF-osx/svf/include/include/Graphs/ThreadCallGraph.h +422 -0
  57. package/SVF-osx/svf/include/include/Graphs/VFG.h +664 -0
  58. package/SVF-osx/svf/include/include/Graphs/VFGEdge.h +295 -0
  59. package/SVF-osx/svf/include/include/Graphs/VFGNode.h +1197 -0
  60. package/SVF-osx/svf/include/include/MSSA/MSSAMuChi.h +722 -0
  61. package/SVF-osx/svf/include/include/MSSA/MemPartition.h +169 -0
  62. package/SVF-osx/svf/include/include/MSSA/MemRegion.h +491 -0
  63. package/SVF-osx/svf/include/include/MSSA/MemSSA.h +452 -0
  64. package/SVF-osx/svf/include/include/MSSA/SVFGBuilder.h +98 -0
  65. package/SVF-osx/svf/include/include/MTA/FSMPTA.h +270 -0
  66. package/SVF-osx/svf/include/include/MTA/LockAnalysis.h +517 -0
  67. package/SVF-osx/svf/include/include/MTA/MHP.h +565 -0
  68. package/SVF-osx/svf/include/include/MTA/MTA.h +101 -0
  69. package/SVF-osx/svf/include/include/MTA/MTAResultValidator.h +448 -0
  70. package/SVF-osx/svf/include/include/MTA/MTAStat.h +74 -0
  71. package/SVF-osx/svf/include/include/MTA/PCG.h +229 -0
  72. package/SVF-osx/svf/include/include/MTA/TCT.h +599 -0
  73. package/SVF-osx/svf/include/include/MemoryModel/AbstractPointsToDS.h +316 -0
  74. package/SVF-osx/svf/include/include/MemoryModel/ConditionalPT.h +878 -0
  75. package/SVF-osx/svf/include/include/MemoryModel/LocationSet.h +148 -0
  76. package/SVF-osx/svf/include/include/MemoryModel/MutablePointsToDS.h +1025 -0
  77. package/SVF-osx/svf/include/include/MemoryModel/PersistentPointsToCache.h +463 -0
  78. package/SVF-osx/svf/include/include/MemoryModel/PersistentPointsToDS.h +955 -0
  79. package/SVF-osx/svf/include/include/MemoryModel/PointerAnalysis.h +452 -0
  80. package/SVF-osx/svf/include/include/MemoryModel/PointerAnalysisImpl.h +590 -0
  81. package/SVF-osx/svf/include/include/MemoryModel/PointsTo.h +255 -0
  82. package/SVF-osx/svf/include/include/MemoryModel/SVFLoop.h +164 -0
  83. package/SVF-osx/svf/include/include/SABER/DoubleFreeChecker.h +76 -0
  84. package/SVF-osx/svf/include/include/SABER/FileChecker.h +82 -0
  85. package/SVF-osx/svf/include/include/SABER/LeakChecker.h +124 -0
  86. package/SVF-osx/svf/include/include/SABER/ProgSlice.h +313 -0
  87. package/SVF-osx/svf/include/include/SABER/SaberCheckerAPI.h +166 -0
  88. package/SVF-osx/svf/include/include/SABER/SaberCondAllocator.h +310 -0
  89. package/SVF-osx/svf/include/include/SABER/SaberSVFGBuilder.h +104 -0
  90. package/SVF-osx/svf/include/include/SABER/SrcSnkDDA.h +321 -0
  91. package/SVF-osx/svf/include/include/SABER/SrcSnkSolver.h +186 -0
  92. package/SVF-osx/svf/include/include/SVFIR/PAGBuilderFromFile.h +80 -0
  93. package/SVF-osx/svf/include/include/SVFIR/SVFIR.h +659 -0
  94. package/SVF-osx/svf/include/include/SVFIR/SVFModule.h +233 -0
  95. package/SVF-osx/svf/include/include/SVFIR/SVFStatements.h +1136 -0
  96. package/SVF-osx/svf/include/include/SVFIR/SVFType.h +527 -0
  97. package/SVF-osx/svf/include/include/SVFIR/SVFValue.h +1120 -0
  98. package/SVF-osx/svf/include/include/SVFIR/SVFVariables.h +721 -0
  99. package/SVF-osx/svf/include/include/SVFIR/SymbolTableInfo.h +597 -0
  100. package/SVF-osx/svf/include/include/Util/Annotator.h +180 -0
  101. package/SVF-osx/svf/include/include/Util/BitVector.h +55 -0
  102. package/SVF-osx/svf/include/include/Util/CallGraphBuilder.h +74 -0
  103. package/SVF-osx/svf/include/include/Util/Casting.h +426 -0
  104. package/SVF-osx/svf/include/include/Util/CommandLine.h +530 -0
  105. package/SVF-osx/svf/include/include/Util/CoreBitVector.h +214 -0
  106. package/SVF-osx/svf/include/include/Util/CppUtil.h +81 -0
  107. package/SVF-osx/svf/include/include/Util/CxtStmt.h +501 -0
  108. package/SVF-osx/svf/include/include/Util/DPItem.h +618 -0
  109. package/SVF-osx/svf/include/include/Util/ExtAPI.h +339 -0
  110. package/SVF-osx/svf/include/include/Util/ExtAPI.json +5707 -0
  111. package/SVF-osx/svf/include/include/Util/GraphReachSolver.h +186 -0
  112. package/SVF-osx/svf/include/include/Util/NodeIDAllocator.h +194 -0
  113. package/SVF-osx/svf/include/include/Util/Options.h +266 -0
  114. package/SVF-osx/svf/include/include/Util/PTAStat.h +65 -0
  115. package/SVF-osx/svf/include/include/Util/SCC.h +354 -0
  116. package/SVF-osx/svf/include/include/Util/SVFStat.h +100 -0
  117. package/SVF-osx/svf/include/include/Util/SVFUtil.h +660 -0
  118. package/SVF-osx/svf/include/include/Util/SparseBitVector.h +1202 -0
  119. package/SVF-osx/svf/include/include/Util/ThreadAPI.h +330 -0
  120. package/SVF-osx/svf/include/include/Util/WorkList.h +317 -0
  121. package/SVF-osx/svf/include/include/Util/Z3Expr.h +318 -0
  122. package/SVF-osx/svf/include/include/Util/cJSON.h +300 -0
  123. package/SVF-osx/svf/include/include/Util/iterator.h +407 -0
  124. package/SVF-osx/svf/include/include/Util/iterator_range.h +76 -0
  125. package/SVF-osx/svf/include/include/WPA/Andersen.h +416 -0
  126. package/SVF-osx/svf/include/include/WPA/AndersenPWC.h +160 -0
  127. package/SVF-osx/svf/include/include/WPA/CSC.h +95 -0
  128. package/SVF-osx/svf/include/include/WPA/FlowSensitive.h +317 -0
  129. package/SVF-osx/svf/include/include/WPA/Steensgaard.h +126 -0
  130. package/SVF-osx/svf/include/include/WPA/TypeAnalysis.h +83 -0
  131. package/SVF-osx/svf/include/include/WPA/VersionedFlowSensitive.h +287 -0
  132. package/SVF-osx/svf/include/include/WPA/WPAFSSolver.h +254 -0
  133. package/SVF-osx/svf/include/include/WPA/WPAPass.h +119 -0
  134. package/SVF-osx/svf/include/include/WPA/WPASolver.h +205 -0
  135. package/SVF-osx/svf/include/include/WPA/WPAStat.h +222 -0
  136. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/BasicTypes.h +250 -0
  137. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/BreakConstantExpr.h +94 -0
  138. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/CHGBuilder.h +73 -0
  139. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/DCHG.h +484 -0
  140. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/GEPTypeBridgeIterator.h +183 -0
  141. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/ICFGBuilder.h +106 -0
  142. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/LLVMLoopAnalysis.h +61 -0
  143. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/LLVMModule.h +360 -0
  144. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/LLVMUtil.h +466 -0
  145. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/SVFIRBuilder.h +417 -0
  146. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/SymbolTableBuilder.h +110 -0
  147. package/package.json +1 -1
@@ -0,0 +1,620 @@
1
+ //===- CenericGraph.h -- Generic graph ---------------------------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-2017> <Yulei Sui>
6
+ //
7
+
8
+ // This program is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+
13
+ // This program is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * GenericGraph.h
25
+ *
26
+ * Created on: Mar 19, 2014
27
+ * Author: Yulei Sui
28
+ */
29
+
30
+ #ifndef GENERICGRAPH_H_
31
+ #define GENERICGRAPH_H_
32
+
33
+ #include "SVFIR/SVFValue.h"
34
+ #include "Util/iterator.h"
35
+ #include "Graphs/GraphTraits.h"
36
+
37
+ namespace SVF
38
+ {
39
+
40
+ /*!
41
+ * Generic edge on the graph as base class
42
+ */
43
+ template<class NodeTy>
44
+ class GenericEdge
45
+ {
46
+
47
+ public:
48
+ /// Node type
49
+ typedef NodeTy NodeType;
50
+ /// Edge Flag
51
+ /// Edge format as follows (from lowest bit):
52
+ /// (1) 0-7 bits encode an edge kind (allow maximum 16 kinds)
53
+ /// (2) 8-63 bits encode a callsite instruction
54
+ typedef u64_t GEdgeFlag;
55
+ typedef s64_t GEdgeKind;
56
+ private:
57
+ NodeTy* src; ///< source node
58
+ NodeTy* dst; ///< destination node
59
+ GEdgeFlag edgeFlag; ///< edge kind
60
+
61
+ public:
62
+ /// Constructor
63
+ GenericEdge(NodeTy* s, NodeTy* d, GEdgeFlag k) : src(s), dst(d), edgeFlag(k)
64
+ {
65
+ }
66
+
67
+ /// Destructor
68
+ virtual ~GenericEdge()
69
+ {
70
+ }
71
+
72
+ /// get methods of the components
73
+ //@{
74
+ inline NodeID getSrcID() const
75
+ {
76
+ return src->getId();
77
+ }
78
+ inline NodeID getDstID() const
79
+ {
80
+ return dst->getId();
81
+ }
82
+ inline GEdgeKind getEdgeKind() const
83
+ {
84
+ return (EdgeKindMask & edgeFlag);
85
+ }
86
+ inline GEdgeKind getEdgeKindWithoutMask() const
87
+ {
88
+ return edgeFlag;
89
+ }
90
+ NodeType* getSrcNode() const
91
+ {
92
+ return src;
93
+ }
94
+ NodeType* getDstNode() const
95
+ {
96
+ return dst;
97
+ }
98
+ //@}
99
+
100
+ /// Add the hash function for std::set (we also can overload operator< to implement this)
101
+ // and duplicated elements in the set are not inserted (binary tree comparison)
102
+ //@{
103
+ typedef struct equalGEdge
104
+ {
105
+ bool operator()(const GenericEdge<NodeType>* lhs, const GenericEdge<NodeType>* rhs) const
106
+ {
107
+ if (lhs->edgeFlag != rhs->edgeFlag)
108
+ return lhs->edgeFlag < rhs->edgeFlag;
109
+ else if (lhs->getSrcID() != rhs->getSrcID())
110
+ return lhs->getSrcID() < rhs->getSrcID();
111
+ else
112
+ return lhs->getDstID() < rhs->getDstID();
113
+ }
114
+ } equalGEdge;
115
+
116
+ virtual inline bool operator==(const GenericEdge<NodeType>* rhs) const
117
+ {
118
+ return (rhs->edgeFlag == this->edgeFlag &&
119
+ rhs->getSrcID() == this->getSrcID() &&
120
+ rhs->getDstID() == this->getDstID());
121
+ }
122
+ //@}
123
+
124
+ protected:
125
+ static constexpr unsigned char EdgeKindMaskBits = 8; ///< We use the lower 8 bits to denote edge kind
126
+ static constexpr u64_t EdgeKindMask = (~0ULL) >> (64 - EdgeKindMaskBits);
127
+ };
128
+
129
+
130
+ /*!
131
+ * Generic node on the graph as base class
132
+ */
133
+ template<class NodeTy,class EdgeTy>
134
+ class GenericNode
135
+ {
136
+
137
+ public:
138
+ typedef NodeTy NodeType;
139
+ typedef EdgeTy EdgeType;
140
+ /// Edge kind
141
+ typedef s64_t GNodeK;
142
+ typedef OrderedSet<EdgeType*, typename EdgeType::equalGEdge> GEdgeSetTy;
143
+ /// Edge iterator
144
+ ///@{
145
+ typedef typename GEdgeSetTy::iterator iterator;
146
+ typedef typename GEdgeSetTy::const_iterator const_iterator;
147
+ ///@}
148
+
149
+ private:
150
+ NodeID id; ///< Node ID
151
+ GNodeK nodeKind; ///< Node kind
152
+
153
+ GEdgeSetTy InEdges; ///< all incoming edge of this node
154
+ GEdgeSetTy OutEdges; ///< all outgoing edge of this node
155
+
156
+ public:
157
+ /// Constructor
158
+ GenericNode(NodeID i, GNodeK k): id(i),nodeKind(k)
159
+ {
160
+
161
+ }
162
+
163
+ /// Destructor
164
+ virtual ~GenericNode()
165
+ {
166
+ for (auto * edge : OutEdges)
167
+ delete edge;
168
+ }
169
+
170
+ /// Get ID
171
+ inline NodeID getId() const
172
+ {
173
+ return id;
174
+ }
175
+
176
+ /// Get node kind
177
+ inline GNodeK getNodeKind() const
178
+ {
179
+ return nodeKind;
180
+ }
181
+
182
+ /// Get incoming/outgoing edge set
183
+ ///@{
184
+ inline const GEdgeSetTy& getOutEdges() const
185
+ {
186
+ return OutEdges;
187
+ }
188
+ inline const GEdgeSetTy& getInEdges() const
189
+ {
190
+ return InEdges;
191
+ }
192
+ ///@}
193
+
194
+ /// Has incoming/outgoing edge set
195
+ //@{
196
+ inline bool hasIncomingEdge() const
197
+ {
198
+ return (InEdges.empty() == false);
199
+ }
200
+ inline bool hasOutgoingEdge() const
201
+ {
202
+ return (OutEdges.empty() == false);
203
+ }
204
+ //@}
205
+
206
+ /// iterators
207
+ //@{
208
+ inline iterator OutEdgeBegin()
209
+ {
210
+ return OutEdges.begin();
211
+ }
212
+ inline iterator OutEdgeEnd()
213
+ {
214
+ return OutEdges.end();
215
+ }
216
+ inline iterator InEdgeBegin()
217
+ {
218
+ return InEdges.begin();
219
+ }
220
+ inline iterator InEdgeEnd()
221
+ {
222
+ return InEdges.end();
223
+ }
224
+ inline const_iterator OutEdgeBegin() const
225
+ {
226
+ return OutEdges.begin();
227
+ }
228
+ inline const_iterator OutEdgeEnd() const
229
+ {
230
+ return OutEdges.end();
231
+ }
232
+ inline const_iterator InEdgeBegin() const
233
+ {
234
+ return InEdges.begin();
235
+ }
236
+ inline const_iterator InEdgeEnd() const
237
+ {
238
+ return InEdges.end();
239
+ }
240
+ //@}
241
+
242
+ /// Iterators used for SCC detection, overwrite it in child class if necessory
243
+ //@{
244
+ virtual inline iterator directOutEdgeBegin()
245
+ {
246
+ return OutEdges.begin();
247
+ }
248
+ virtual inline iterator directOutEdgeEnd()
249
+ {
250
+ return OutEdges.end();
251
+ }
252
+ virtual inline iterator directInEdgeBegin()
253
+ {
254
+ return InEdges.begin();
255
+ }
256
+ virtual inline iterator directInEdgeEnd()
257
+ {
258
+ return InEdges.end();
259
+ }
260
+
261
+ virtual inline const_iterator directOutEdgeBegin() const
262
+ {
263
+ return OutEdges.begin();
264
+ }
265
+ virtual inline const_iterator directOutEdgeEnd() const
266
+ {
267
+ return OutEdges.end();
268
+ }
269
+ virtual inline const_iterator directInEdgeBegin() const
270
+ {
271
+ return InEdges.begin();
272
+ }
273
+ virtual inline const_iterator directInEdgeEnd() const
274
+ {
275
+ return InEdges.end();
276
+ }
277
+ //@}
278
+
279
+ /// Add incoming and outgoing edges
280
+ //@{
281
+ inline bool addIncomingEdge(EdgeType* inEdge)
282
+ {
283
+ return InEdges.insert(inEdge).second;
284
+ }
285
+ inline bool addOutgoingEdge(EdgeType* outEdge)
286
+ {
287
+ return OutEdges.insert(outEdge).second;
288
+ }
289
+ //@}
290
+
291
+ /// Remove incoming and outgoing edges
292
+ ///@{
293
+ inline u32_t removeIncomingEdge(EdgeType* edge)
294
+ {
295
+ iterator it = InEdges.find(edge);
296
+ assert(it != InEdges.end() && "can not find in edge in SVFG node");
297
+ InEdges.erase(it);
298
+ return 1;
299
+ }
300
+ inline u32_t removeOutgoingEdge(EdgeType* edge)
301
+ {
302
+ iterator it = OutEdges.find(edge);
303
+ assert(it != OutEdges.end() && "can not find out edge in SVFG node");
304
+ OutEdges.erase(it);
305
+ return 1;
306
+ }
307
+ ///@}
308
+
309
+ /// Find incoming and outgoing edges
310
+ //@{
311
+ inline EdgeType* hasIncomingEdge(EdgeType* edge) const
312
+ {
313
+ const_iterator it = InEdges.find(edge);
314
+ if (it != InEdges.end())
315
+ return *it;
316
+ else
317
+ return nullptr;
318
+ }
319
+ inline EdgeType* hasOutgoingEdge(EdgeType* edge) const
320
+ {
321
+ const_iterator it = OutEdges.find(edge);
322
+ if (it != OutEdges.end())
323
+ return *it;
324
+ else
325
+ return nullptr;
326
+ }
327
+ //@}
328
+ };
329
+
330
+ /*
331
+ * Generic graph for program representation
332
+ * It is base class and needs to be instantiated
333
+ */
334
+ template<class NodeTy,class EdgeTy>
335
+ class GenericGraph
336
+ {
337
+
338
+ public:
339
+ typedef NodeTy NodeType;
340
+ typedef EdgeTy EdgeType;
341
+ /// NodeID to GenericNode map
342
+ typedef OrderedMap<NodeID, NodeType*> IDToNodeMapTy;
343
+
344
+ /// Node Iterators
345
+ //@{
346
+ typedef typename IDToNodeMapTy::iterator iterator;
347
+ typedef typename IDToNodeMapTy::const_iterator const_iterator;
348
+ //@}
349
+
350
+ /// Constructor
351
+ GenericGraph(): edgeNum(0),nodeNum(0)
352
+ {
353
+ }
354
+
355
+ /// Destructor
356
+ virtual ~GenericGraph()
357
+ {
358
+ destroy();
359
+ }
360
+
361
+ /// Release memory
362
+ void destroy()
363
+ {
364
+ for (auto &entry : IDToNodeMap)
365
+ delete entry.second;
366
+ }
367
+ /// Iterators
368
+ //@{
369
+ inline iterator begin()
370
+ {
371
+ return IDToNodeMap.begin();
372
+ }
373
+ inline iterator end()
374
+ {
375
+ return IDToNodeMap.end();
376
+ }
377
+ inline const_iterator begin() const
378
+ {
379
+ return IDToNodeMap.begin();
380
+ }
381
+ inline const_iterator end() const
382
+ {
383
+ return IDToNodeMap.end();
384
+ }
385
+ //}@
386
+
387
+ /// Add a Node
388
+ inline void addGNode(NodeID id, NodeType* node)
389
+ {
390
+ IDToNodeMap[id] = node;
391
+ nodeNum++;
392
+ }
393
+
394
+ /// Get a node
395
+ inline NodeType* getGNode(NodeID id) const
396
+ {
397
+ const_iterator it = IDToNodeMap.find(id);
398
+ assert(it != IDToNodeMap.end() && "Node not found!");
399
+ return it->second;
400
+ }
401
+
402
+ /// Has a node
403
+ inline bool hasGNode(NodeID id) const
404
+ {
405
+ const_iterator it = IDToNodeMap.find(id);
406
+ return it != IDToNodeMap.end();
407
+ }
408
+
409
+ /// Delete a node
410
+ inline void removeGNode(NodeType* node)
411
+ {
412
+ assert(node->hasIncomingEdge() == false
413
+ && node->hasOutgoingEdge() == false
414
+ && "node which have edges can't be deleted");
415
+ iterator it = IDToNodeMap.find(node->getId());
416
+ assert(it != IDToNodeMap.end() && "can not find the node");
417
+ IDToNodeMap.erase(it);
418
+ delete node;
419
+ }
420
+
421
+ /// Get total number of node/edge
422
+ inline u32_t getTotalNodeNum() const
423
+ {
424
+ return nodeNum;
425
+ }
426
+ inline u32_t getTotalEdgeNum() const
427
+ {
428
+ return edgeNum;
429
+ }
430
+ /// Increase number of node/edge
431
+ inline void incNodeNum()
432
+ {
433
+ nodeNum++;
434
+ }
435
+ inline void incEdgeNum()
436
+ {
437
+ edgeNum++;
438
+ }
439
+
440
+ protected:
441
+ IDToNodeMapTy IDToNodeMap; ///< node map
442
+
443
+ public:
444
+ u32_t edgeNum; ///< total num of node
445
+ u32_t nodeNum; ///< total num of edge
446
+ };
447
+
448
+ } // End namespace SVF
449
+
450
+ /* !
451
+ * GenericGraphTraits specializations for generic graph algorithms.
452
+ * Provide graph traits for tranversing from a node using standard graph traversals.
453
+ */
454
+ namespace SVF
455
+ {
456
+
457
+ // mapped_iter - This is a simple iterator adapter that causes a function to
458
+ // be applied whenever operator* is invoked on the iterator.
459
+
460
+ template <typename ItTy, typename FuncTy,
461
+ typename FuncReturnTy =
462
+ decltype(std::declval<FuncTy>()(*std::declval<ItTy>()))>
463
+ class mapped_iter
464
+ : public iter_adaptor_base<
465
+ mapped_iter<ItTy, FuncTy>, ItTy,
466
+ typename std::iterator_traits<ItTy>::iterator_category,
467
+ typename std::remove_reference<FuncReturnTy>::type>
468
+ {
469
+ public:
470
+ mapped_iter(ItTy U, FuncTy F)
471
+ : mapped_iter::iter_adaptor_base(std::move(U)), F(std::move(F)) {}
472
+
473
+ ItTy getCurrent()
474
+ {
475
+ return this->I;
476
+ }
477
+
478
+ FuncReturnTy operator*() const
479
+ {
480
+ return F(*this->I);
481
+ }
482
+
483
+ private:
484
+ FuncTy F;
485
+ };
486
+
487
+ // map_iter - Provide a convenient way to create mapped_iters, just like
488
+ // make_pair is useful for creating pairs...
489
+ template <class ItTy, class FuncTy>
490
+ inline mapped_iter<ItTy, FuncTy> map_iter(ItTy I, FuncTy F)
491
+ {
492
+ return mapped_iter<ItTy, FuncTy>(std::move(I), std::move(F));
493
+ }
494
+
495
+ /*!
496
+ * GenericGraphTraits for nodes
497
+ */
498
+ template<class NodeTy,class EdgeTy> struct GenericGraphTraits<SVF::GenericNode<NodeTy,EdgeTy>* >
499
+ {
500
+ typedef NodeTy NodeType;
501
+ typedef EdgeTy EdgeType;
502
+
503
+ static inline NodeType* edge_dest(const EdgeType* E)
504
+ {
505
+ return E->getDstNode();
506
+ }
507
+
508
+ // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
509
+ typedef mapped_iter<typename SVF::GenericNode<NodeTy,EdgeTy>::iterator, decltype(&edge_dest)> ChildIteratorType;
510
+
511
+ static NodeType* getEntryNode(NodeType* pagN)
512
+ {
513
+ return pagN;
514
+ }
515
+
516
+ static inline ChildIteratorType child_begin(const NodeType* N)
517
+ {
518
+ return map_iter(N->OutEdgeBegin(), &edge_dest);
519
+ }
520
+ static inline ChildIteratorType child_end(const NodeType* N)
521
+ {
522
+ return map_iter(N->OutEdgeEnd(), &edge_dest);
523
+ }
524
+ static inline ChildIteratorType direct_child_begin(const NodeType *N)
525
+ {
526
+ return map_iter(N->directOutEdgeBegin(), &edge_dest);
527
+ }
528
+ static inline ChildIteratorType direct_child_end(const NodeType *N)
529
+ {
530
+ return map_iter(N->directOutEdgeEnd(), &edge_dest);
531
+ }
532
+ };
533
+
534
+ /*!
535
+ * Inverse GenericGraphTraits for node which is used for inverse traversal.
536
+ */
537
+ template<class NodeTy,class EdgeTy>
538
+ struct GenericGraphTraits<Inverse<SVF::GenericNode<NodeTy,EdgeTy>* > >
539
+ {
540
+ typedef NodeTy NodeType;
541
+ typedef EdgeTy EdgeType;
542
+
543
+ static inline NodeType* edge_dest(const EdgeType* E)
544
+ {
545
+ return E->getSrcNode();
546
+ }
547
+
548
+ // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
549
+ typedef mapped_iter<typename SVF::GenericNode<NodeTy,EdgeTy>::iterator, decltype(&edge_dest)> ChildIteratorType;
550
+
551
+ static inline NodeType* getEntryNode(Inverse<NodeType* > G)
552
+ {
553
+ return G.Graph;
554
+ }
555
+
556
+ static inline ChildIteratorType child_begin(const NodeType* N)
557
+ {
558
+ return map_iter(N->InEdgeBegin(), &edge_dest);
559
+ }
560
+ static inline ChildIteratorType child_end(const NodeType* N)
561
+ {
562
+ return map_iter(N->InEdgeEnd(), &edge_dest);
563
+ }
564
+
565
+ static inline unsigned getNodeID(const NodeType* N)
566
+ {
567
+ return N->getId();
568
+ }
569
+ };
570
+
571
+ /*!
572
+ * GraphTraints
573
+ */
574
+ template<class NodeTy,class EdgeTy> struct GenericGraphTraits<SVF::GenericGraph<NodeTy,EdgeTy>* > : public GenericGraphTraits<SVF::GenericNode<NodeTy,EdgeTy>* >
575
+ {
576
+ typedef SVF::GenericGraph<NodeTy,EdgeTy> GenericGraphTy;
577
+ typedef NodeTy NodeType;
578
+ typedef EdgeTy EdgeType;
579
+
580
+ static NodeType* getEntryNode(GenericGraphTy* pag)
581
+ {
582
+ return nullptr; // return null here, maybe later we could create a dummy node
583
+ }
584
+
585
+ typedef std::pair<SVF::NodeID, NodeType*> PairTy;
586
+ static inline NodeType* deref_val(PairTy P)
587
+ {
588
+ return P.second;
589
+ }
590
+
591
+ // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
592
+ typedef mapped_iter<typename GenericGraphTy::iterator, decltype(&deref_val)> nodes_iterator;
593
+
594
+ static nodes_iterator nodes_begin(GenericGraphTy *G)
595
+ {
596
+ return map_iter(G->begin(), &deref_val);
597
+ }
598
+ static nodes_iterator nodes_end(GenericGraphTy *G)
599
+ {
600
+ return map_iter(G->end(), &deref_val);
601
+ }
602
+
603
+ static unsigned graphSize(GenericGraphTy* G)
604
+ {
605
+ return G->getTotalNodeNum();
606
+ }
607
+
608
+ static inline unsigned getNodeID(NodeType* N)
609
+ {
610
+ return N->getId();
611
+ }
612
+ static NodeType* getNode(GenericGraphTy *G, SVF::NodeID id)
613
+ {
614
+ return G->getGNode(id);
615
+ }
616
+ };
617
+
618
+ } // End namespace llvm
619
+
620
+ #endif /* GENERICGRAPH_H_ */