svf-lib 1.0.1889 → 1.0.1891

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
@@ -52,6 +52,10 @@ public:
52
52
 
53
53
  explicit ICFGWTO(ICFG* graph, const ICFGNode* node) : Base(graph, node) {}
54
54
 
55
+ virtual ~ICFGWTO()
56
+ {
57
+ }
58
+
55
59
  inline void forEachSuccessor(
56
60
  const ICFGNode* node,
57
61
  std::function<void(const ICFGNode*)> func) const override
@@ -433,6 +433,8 @@ public:
433
433
  return *this;
434
434
  }
435
435
 
436
+ virtual void printExprValues(std::ostream &oss) const override;
437
+
436
438
  /// move constructor
437
439
  IntervalExeState(IntervalExeState &&rhs) : IntervalESBase(std::move(rhs))
438
440
  {
@@ -32,7 +32,7 @@
32
32
  #include "AE/Svfexe/SVFIR2ItvExeState.h"
33
33
  #include "Util/WorkList.h"
34
34
  #include "MSSA/SVFGBuilder.h"
35
- #include "AE/Core/CFBasicBlockGWTO.h"
35
+ #include "AE/Core/ICFGWTO.h"
36
36
  #include "WPA/Andersen.h"
37
37
  #include "Util/SVFBugReport.h"
38
38
 
@@ -46,7 +46,7 @@ class AEAPI;
46
46
  enum class AEKind
47
47
  {
48
48
  AbstractExecution,
49
- BufOverflowChecker
49
+ BufOverflowChecker,
50
50
  };
51
51
 
52
52
  /// AEStat: Statistic for AE
@@ -120,7 +120,6 @@ public:
120
120
 
121
121
  virtual void runOnModule(SVFIR* svfModule);
122
122
 
123
-
124
123
  /// Destructor
125
124
  virtual ~AbstractExecution();
126
125
 
@@ -145,37 +144,37 @@ protected:
145
144
  void markRecursiveFuns();
146
145
 
147
146
  /**
148
- * Check if execution state exist by merging states of predecessor blocks
147
+ * Check if execution state exist by merging states of predecessor nodes
149
148
  *
150
- * @param block The basic block to analyse
151
- * @return if this block has preceding execution state
149
+ * @param node The ICFGNode to analyse
150
+ * @return if this node has preceding execution state
152
151
  */
153
- bool hasInEdgesES(const CFBasicBlockNode *block);
152
+ bool hasInEdgesES(const ICFGNode *node);
154
153
 
155
154
  /**
156
155
  * Check if execution state exist at the branch edge
157
156
  *
158
- * @param intraEdge the edge from CmpStmt to the next Block
157
+ * @param intraEdge the edge from CmpStmt to the next node
159
158
  * @return if this edge is feasible
160
159
  */
161
160
  bool hasBranchES(const IntraCFGEdge* intraEdge, IntervalExeState& es);
162
161
 
163
162
  /**
164
- * handle instructions in svf basic blocks
163
+ * handle instructions in ICFGNode
165
164
  *
166
165
  * @param block basic block that has a series of instructions
167
166
  */
168
- void handleBlock(const CFBasicBlockNode *block);
167
+ void handleWTONode(const ICFGNode* node);
169
168
 
170
169
  /**
171
- * handle one instruction in svf basic blocks
170
+ * handle one instruction in ICFGNode
172
171
  *
173
172
  * @param node ICFGNode which has a single instruction
174
173
  */
175
174
  virtual void handleICFGNode(const ICFGNode *node);
176
175
 
177
176
  /**
178
- * handle call node in svf basic blocks
177
+ * handle call node in ICFGNode
179
178
  *
180
179
  * @param node ICFGNode which has a single CallICFGNode
181
180
  */
@@ -186,7 +185,7 @@ protected:
186
185
  *
187
186
  * @param cycle WTOCycle which has weak topo order of basic blocks and nested cycles
188
187
  */
189
- virtual void handleCycle(const CFBasicBlockGWTOCycle *cycle);
188
+ virtual void handleCycle(const ICFGWTOCycle *cycle);
190
189
 
191
190
  /**
192
191
  * handle user defined function, ext function is not included.
@@ -221,7 +220,7 @@ protected:
221
220
  *
222
221
  * @param cmpStmt CmpStmt is a conditional branch statement
223
222
  * @param succ the value of cmpStmt (True or False)
224
- * @return if this block has preceding execution state
223
+ * @return if this ICFGNode has preceding execution state
225
224
  */
226
225
  bool hasCmpBranchES(const CmpStmt* cmpStmt, s64_t succ, IntervalExeState& es);
227
226
 
@@ -230,7 +229,7 @@ protected:
230
229
  *
231
230
  * @param var var in switch inst
232
231
  * @param succ the case value of switch inst
233
- * @return if this block has preceding execution state
232
+ * @return if this ICFGNode has preceding execution state
234
233
  */
235
234
  bool hasSwitchBranchES(const SVFVar* var, s64_t succ, IntervalExeState& es);
236
235
 
@@ -249,33 +248,32 @@ protected:
249
248
  SVFBugReport _recoder;
250
249
  std::vector<const CallICFGNode*> _callSiteStack;
251
250
  Map<const ICFGNode *, std::string> _nodeToBugInfo;
251
+ AndersenWaveDiff *_ander;
252
+ Map<const SVFFunction*, ICFGWTO *> _funcToWTO;
253
+ Set<const SVFFunction*> _recursiveFuns;
252
254
 
253
255
  private:
254
256
  // helper functions in handleCallSite
255
- bool isExtCall(const CallICFGNode* callNode);
256
- void extCallPass(const CallICFGNode* callNode);
257
- bool isRecursiveCall(const CallICFGNode* callNode);
258
- void recursiveCallPass(const CallICFGNode* callNode);
259
- bool isDirectCall(const CallICFGNode* callNode);
260
- void directCallFunPass(const CallICFGNode* callNode);
261
- bool isIndirectCall(const CallICFGNode* callNode);
262
- void indirectCallFunPass(const CallICFGNode* callNode);
257
+ virtual bool isExtCall(const CallICFGNode* callNode);
258
+ virtual void extCallPass(const CallICFGNode* callNode);
259
+ virtual bool isRecursiveCall(const CallICFGNode* callNode);
260
+ virtual void recursiveCallPass(const CallICFGNode* callNode);
261
+ virtual bool isDirectCall(const CallICFGNode* callNode);
262
+ virtual void directCallFunPass(const CallICFGNode* callNode);
263
+ virtual bool isIndirectCall(const CallICFGNode* callNode);
264
+ virtual void indirectCallFunPass(const CallICFGNode* callNode);
263
265
 
264
266
  // helper functions in hasInEdgesES
265
- bool isFunEntry(const CFBasicBlockNode* block);
266
- bool isGlobalEntry(const CFBasicBlockNode* block);
267
+ bool isFunEntry(const ICFGNode* node);
268
+ bool isGlobalEntry(const ICFGNode* node);
267
269
 
268
270
  // helper functions in handleCycle
269
- bool widenFixpointPass(const CFBasicBlockNode* cycle_head, IntervalExeState& pre_es);
270
- bool narrowFixpointPass(const CFBasicBlockNode* cycle_head, IntervalExeState& pre_es);
271
+ bool widenFixpointPass(const ICFGNode* cycle_head, IntervalExeState& pre_es);
272
+ bool narrowFixpointPass(const ICFGNode* cycle_head, IntervalExeState& pre_es);
271
273
 
272
274
  // private data
273
- CFBasicBlockGraph* _CFBlockG;
274
- AndersenWaveDiff *_ander;
275
- Map<const CFBasicBlockNode*, IntervalExeState> _preES;
276
- Map<const CFBasicBlockNode*, IntervalExeState> _postES;
277
- Map<const SVFFunction*, CFBasicBlockGWTO *> _funcToWTO;
278
- Set<const SVFFunction*> _recursiveFuns;
275
+ Map<const ICFGNode*, IntervalExeState> _preES;
276
+ Map<const ICFGNode*, IntervalExeState> _postES;
279
277
  std::string _moduleName;
280
278
 
281
279
  };
@@ -36,7 +36,6 @@
36
36
  #include "Util/NodeIDAllocator.h"
37
37
  #include "Util/SVFUtil.h"
38
38
  #include "Graphs/ICFG.h"
39
- #include "Graphs/CFBasicBlockG.h"
40
39
 
41
40
  namespace SVF
42
41
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1889",
3
+ "version": "1.0.1891",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,85 +0,0 @@
1
- //===- CFBasicBlockGWTO.h -- WTO for CFBasicBlockGraph----------------------//
2
- //
3
- // SVF: Static Value-Flow Analysis
4
- //
5
- // Copyright (C) <2013-> <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
- * CFBasicBlockGWTO.h
25
- *
26
- * The implementation is based on F. Bourdoncle's paper:
27
- * "Efficient chaotic iteration strategies with widenings", Formal
28
- * Methods in Programming and Their Applications, 1993, pages 128-141.
29
- *
30
- * Created on: Jan 22, 2024
31
- * Author: Xiao Cheng
32
- *
33
- */
34
- #ifndef SVF_CFBASICBLOCKGWTO_H
35
- #define SVF_CFBASICBLOCKGWTO_H
36
- #include "Graphs/CFBasicBlockG.h"
37
- #include "Graphs/WTO.h"
38
-
39
- namespace SVF
40
- {
41
- typedef WTOComponent<CFBasicBlockGraph> CFBasicBlockGWTOComp;
42
- typedef WTONode<CFBasicBlockGraph> CFBasicBlockGWTONode;
43
- typedef WTOCycle<CFBasicBlockGraph> CFBasicBlockGWTOCycle;
44
-
45
- class CFBasicBlockGWTO : public WTO<CFBasicBlockGraph>
46
- {
47
- public:
48
- typedef WTO<CFBasicBlockGraph> Base;
49
- typedef WTOComponentVisitor<CFBasicBlockGraph>::WTONodeT
50
- CFBasicBlockGWTONode;
51
-
52
- explicit CFBasicBlockGWTO(CFBasicBlockGraph* graph,
53
- const CFBasicBlockNode* node)
54
- : Base(graph, node)
55
- {
56
- }
57
-
58
- virtual ~CFBasicBlockGWTO() = default;
59
-
60
- inline void forEachSuccessor(
61
- const CFBasicBlockNode* node,
62
- std::function<void(const CFBasicBlockNode*)> func) const override
63
- {
64
- if (const auto* callNode =
65
- SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
66
- {
67
- const CFBasicBlockNode* succ = _graph->getCFBasicBlockNode(
68
- callNode->getRetICFGNode()->getId());
69
- func(succ);
70
- }
71
- else
72
- {
73
- for (const auto& e : node->getOutEdges())
74
- {
75
- if (e->getICFGEdge() &&
76
- (!e->getICFGEdge()->isIntraCFGEdge() ||
77
- node->getFunction() != e->getDstNode()->getFunction()))
78
- continue;
79
- func(e->getDstNode());
80
- }
81
- }
82
- }
83
- };
84
- } // namespace SVF
85
- #endif // SVF_CFBASICBLOCKGWTO_H
@@ -1,581 +0,0 @@
1
- //===- CFBasicBlockG.h ----------------------------------------------------------------//
2
- //
3
- // SVF: Static Value-Flow Analysis
4
- //
5
- // Copyright (C) <2013-> <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 Affero 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 Affero General Public License for more details.
17
-
18
- // You should have received a copy of the GNU Affero General Public License
19
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
- //
21
- //===----------------------------------------------------------------------===//
22
-
23
- /*
24
- * CFBasicBlockG.h
25
- *
26
- * Created on: 24 Dec. 2022
27
- * Author: Xiao, Jiawei
28
- */
29
-
30
- #ifndef SVF_CFBASICBLOCKG_H
31
- #define SVF_CFBASICBLOCKG_H
32
- #include "Util/SVFUtil.h"
33
- #include "Graphs/ICFG.h"
34
- #include "Graphs/GenericGraph.h"
35
-
36
- namespace SVF
37
- {
38
- class CFBasicBlockNode;
39
- class SVFIR;
40
-
41
- typedef GenericEdge<CFBasicBlockNode> GenericCFBasicBlockEdgeTy;
42
-
43
- class CFBasicBlockEdge : public GenericCFBasicBlockEdgeTy
44
- {
45
- public:
46
- typedef struct equalCFBBEdge
47
- {
48
- bool
49
- operator()(const CFBasicBlockEdge *lhs, const CFBasicBlockEdge *rhs) const
50
- {
51
- if (lhs->getSrcID() != rhs->getSrcID())
52
- return lhs->getSrcID() < rhs->getSrcID();
53
- else if (lhs->getDstID() != rhs->getDstID())
54
- return lhs->getDstID() < rhs->getDstID();
55
- else
56
- return lhs->getICFGEdge() < rhs->getICFGEdge();
57
- }
58
- } equalICFGEdgeWrapper;
59
-
60
- typedef OrderedSet<CFBasicBlockEdge *, equalICFGEdgeWrapper> CFBBEdgeSetTy;
61
- typedef CFBBEdgeSetTy::iterator iterator;
62
- typedef CFBBEdgeSetTy::const_iterator const_iterator;
63
-
64
- private:
65
- const ICFGEdge *_icfgEdge;
66
-
67
- public:
68
- CFBasicBlockEdge(CFBasicBlockNode* src, CFBasicBlockNode* dst,
69
- const ICFGEdge* edge)
70
- : GenericCFBasicBlockEdgeTy(src, dst, 0), _icfgEdge(edge)
71
- {
72
- }
73
-
74
- CFBasicBlockEdge(CFBasicBlockNode* src, CFBasicBlockNode* dst)
75
- : GenericCFBasicBlockEdgeTy(src, dst, 0), _icfgEdge(nullptr)
76
- {
77
- }
78
-
79
- friend std::ostream &operator<<(std::ostream &o, const CFBasicBlockEdge &edge)
80
- {
81
- o << edge.toString();
82
- return o;
83
- }
84
-
85
- virtual const std::string toString() const
86
- {
87
- std::string str;
88
- std::stringstream rawstr(str);
89
- rawstr << "CFBBGEdge: [CFBBGNode" << getDstID() << " <-- CFBBGNode" << getSrcID() << "]\t";
90
- return rawstr.str();
91
- }
92
-
93
- inline const ICFGEdge *getICFGEdge() const
94
- {
95
- return _icfgEdge;
96
- }
97
-
98
- using SVF::GenericEdge<NodeType>::operator==;
99
- /// Add the hash function for std::set (we also can overload operator< to implement this)
100
- // and duplicated elements in the set are not inserted (binary tree comparison)
101
- //@{
102
-
103
- virtual inline bool operator==(const CFBasicBlockEdge *rhs) const
104
- {
105
- return (rhs->getSrcID() == this->getSrcID() && rhs->getDstID() == this->getDstID() &&
106
- rhs->getICFGEdge() == this->getICFGEdge());
107
- }
108
- //@}
109
-
110
- };
111
-
112
- typedef GenericNode<CFBasicBlockNode, CFBasicBlockEdge> GenericCFBasicBlockNodeTy;
113
-
114
- class CFBasicBlockNode : public GenericCFBasicBlockNodeTy
115
- {
116
- public:
117
- typedef CFBasicBlockEdge::CFBBEdgeSetTy CFBBEdgeSetTy;
118
- typedef CFBasicBlockEdge::CFBBEdgeSetTy ::iterator iterator;
119
- typedef CFBasicBlockEdge::CFBBEdgeSetTy::const_iterator const_iterator;
120
-
121
- private:
122
- std::vector<const ICFGNode *> _icfgNodes; /// Every CBFGNode holds a vector of ICFGNodes
123
- CFBBEdgeSetTy InEdges; ///< all incoming edge of this node
124
- CFBBEdgeSetTy OutEdges; ///< all outgoing edge of this node
125
-
126
- public:
127
- CFBasicBlockNode(std::vector<const ICFGNode*> icfgNodes)
128
- : GenericCFBasicBlockNodeTy((*icfgNodes.begin())->getId(), 0),
129
- _icfgNodes(SVFUtil::move(icfgNodes))
130
- {
131
- }
132
-
133
- virtual ~CFBasicBlockNode()
134
- {
135
- for (auto edge : OutEdges)
136
- delete edge;
137
- }
138
-
139
- friend std::ostream &operator<<(std::ostream &o, const CFBasicBlockNode &node)
140
- {
141
- o << node.toString();
142
- return o;
143
- }
144
-
145
- virtual const std::string toString() const;
146
-
147
- inline std::string getName() const
148
- {
149
- assert(!_icfgNodes.empty() && "no ICFG nodes in CFBB");
150
- return (*_icfgNodes.begin())->getBB()->getName();
151
- }
152
-
153
- inline const std::vector<const ICFGNode*>& getICFGNodes() const
154
- {
155
- return _icfgNodes;
156
- }
157
-
158
- inline const SVFFunction *getFunction() const
159
- {
160
- assert(!_icfgNodes.empty() && "no ICFG nodes in CFBB");
161
- return (*_icfgNodes.begin())->getFun();
162
- }
163
-
164
- inline std::vector<const ICFGNode *>::const_iterator begin() const
165
- {
166
- return _icfgNodes.cbegin();
167
- }
168
-
169
- inline std::vector<const ICFGNode *>::const_iterator end() const
170
- {
171
- return _icfgNodes.cend();
172
- }
173
-
174
- inline void removeNode(const ICFGNode* node)
175
- {
176
- const auto it = std::find(_icfgNodes.begin(), _icfgNodes.end(), node);
177
- assert(it != _icfgNodes.end() && "icfg node not in BB?");
178
- _icfgNodes.erase(it);
179
- }
180
-
181
- inline void addNode(const ICFGNode* node)
182
- {
183
- _icfgNodes.push_back(node);
184
- }
185
-
186
- inline u32_t getICFGNodeNum() const
187
- {
188
- return _icfgNodes.size();
189
- }
190
-
191
- public:
192
- /// Get incoming/outgoing edge set
193
- ///@{
194
- inline const CFBBEdgeSetTy &getOutEdges() const
195
- {
196
- return OutEdges;
197
- }
198
-
199
- inline const CFBBEdgeSetTy &getInEdges() const
200
- {
201
- return InEdges;
202
- }
203
- ///@}
204
-
205
- /// Has incoming/outgoing edge set
206
- //@{
207
- inline bool hasIncomingEdge() const
208
- {
209
- return (InEdges.empty() == false);
210
- }
211
-
212
- inline bool hasOutgoingEdge() const
213
- {
214
- return (OutEdges.empty() == false);
215
- }
216
- //@}
217
-
218
- /// iterators
219
- //@{
220
- inline iterator OutEdgeBegin()
221
- {
222
- return OutEdges.begin();
223
- }
224
-
225
- inline iterator OutEdgeEnd()
226
- {
227
- return OutEdges.end();
228
- }
229
-
230
- inline iterator InEdgeBegin()
231
- {
232
- return InEdges.begin();
233
- }
234
-
235
- inline iterator InEdgeEnd()
236
- {
237
- return InEdges.end();
238
- }
239
-
240
- inline const_iterator OutEdgeBegin() const
241
- {
242
- return OutEdges.begin();
243
- }
244
-
245
- inline const_iterator OutEdgeEnd() const
246
- {
247
- return OutEdges.end();
248
- }
249
-
250
- inline const_iterator InEdgeBegin() const
251
- {
252
- return InEdges.begin();
253
- }
254
-
255
- inline const_iterator InEdgeEnd() const
256
- {
257
- return InEdges.end();
258
- }
259
- //@}
260
-
261
- /// Add incoming and outgoing edges
262
- //@{
263
- inline bool addIncomingEdge(CFBasicBlockEdge *inEdge)
264
- {
265
- return InEdges.insert(inEdge).second;
266
- }
267
-
268
- inline bool addOutgoingEdge(CFBasicBlockEdge *outEdge)
269
- {
270
- return OutEdges.insert(outEdge).second;
271
- }
272
- //@}
273
-
274
- /// Remove incoming and outgoing edges
275
- ///@{
276
- inline u32_t removeIncomingEdge(CFBasicBlockEdge *edge)
277
- {
278
- assert(InEdges.find(edge) != InEdges.end() && "can not find in edge in SVFG node");
279
- return InEdges.erase(edge);
280
- }
281
-
282
- inline u32_t removeOutgoingEdge(CFBasicBlockEdge *edge)
283
- {
284
- assert(OutEdges.find(edge) != OutEdges.end() && "can not find out edge in SVFG node");
285
- return OutEdges.erase(edge);
286
- }
287
- ///@}
288
-
289
- /// Find incoming and outgoing edges
290
- //@{
291
- inline CFBasicBlockEdge *hasIncomingEdge(CFBasicBlockEdge *edge) const
292
- {
293
- const_iterator it = InEdges.find(edge);
294
- if (it != InEdges.end())
295
- return *it;
296
- else
297
- return nullptr;
298
- }
299
-
300
- inline CFBasicBlockEdge *hasOutgoingEdge(CFBasicBlockEdge *edge) const
301
- {
302
- const_iterator it = OutEdges.find(edge);
303
- if (it != OutEdges.end())
304
- return *it;
305
- else
306
- return nullptr;
307
- }
308
- //@}
309
- };
310
-
311
- typedef GenericGraph<CFBasicBlockNode, CFBasicBlockEdge> GenericCFBasicBlockGTy;
312
-
313
- class CFBasicBlockGraph : public GenericCFBasicBlockGTy
314
- {
315
- friend class CFBasicBlockGBuilder;
316
- private:
317
- u32_t _totalCFBasicBlockNode{0};
318
- u32_t _totalCFBasicBlockEdge{0};
319
- public:
320
-
321
- CFBasicBlockGraph() = default;
322
-
323
- ~CFBasicBlockGraph() override = default;
324
-
325
- /// Dump graph into dot file
326
- void dump(const std::string &filename)
327
- {
328
- GraphPrinter::WriteGraphToFile(SVFUtil::outs(), filename, this);
329
- }
330
-
331
- inline CFBasicBlockNode *getCFBasicBlockNode(u32_t id) const
332
- {
333
- if (!hasGNode(id)) return nullptr;
334
- return getGNode(id);
335
- }
336
-
337
- inline bool hasCFBasicBlockNode(NodeID id) const
338
- {
339
- return hasGNode(id);
340
- }
341
-
342
-
343
- bool hasCFBasicBlockEdge(CFBasicBlockNode *src, CFBasicBlockNode *dst, ICFGEdge *icfgEdge)
344
- {
345
- CFBasicBlockEdge edge(src, dst, icfgEdge);
346
- CFBasicBlockEdge *outEdge = src->hasOutgoingEdge(&edge);
347
- CFBasicBlockEdge *inEdge = dst->hasIncomingEdge(&edge);
348
- if (outEdge && inEdge)
349
- {
350
- assert(outEdge == inEdge && "edges not match");
351
- return true;
352
- }
353
- else
354
- return false;
355
- }
356
-
357
- inline bool hasCFBasicBlockEdge(CFBasicBlockNode *src, CFBasicBlockNode *dst) const
358
- {
359
- for (const auto &e: src->getOutEdges())
360
- {
361
- if (e->getDstNode() == dst)
362
- return true;
363
- }
364
- return false;
365
- }
366
-
367
- CFBasicBlockEdge* getCFBasicBlockEdge(const CFBasicBlockNode *src, const CFBasicBlockNode *dst, const ICFGEdge *icfgEdge);
368
-
369
- std::vector<CFBasicBlockEdge*> getCFBasicBlockEdge(const CFBasicBlockNode *src, const CFBasicBlockNode *dst);
370
-
371
- /// Remove a ICFGEdgeWrapper
372
- inline void removeCFBBEdge(CFBasicBlockEdge *edge)
373
- {
374
- if (edge->getDstNode()->hasIncomingEdge(edge))
375
- {
376
- edge->getDstNode()->removeIncomingEdge(edge);
377
- }
378
- if (edge->getSrcNode()->hasOutgoingEdge(edge))
379
- {
380
- edge->getSrcNode()->removeOutgoingEdge(edge);
381
- }
382
- delete edge;
383
- _totalCFBasicBlockEdge--;
384
- }
385
-
386
- /// Remove a ICFGNodeWrapper
387
- inline void removeCFBBNode(CFBasicBlockNode *node)
388
- {
389
- std::set<CFBasicBlockEdge *> temp;
390
- for (CFBasicBlockEdge *e: node->getInEdges())
391
- temp.insert(e);
392
- for (CFBasicBlockEdge *e: node->getOutEdges())
393
- temp.insert(e);
394
- for (CFBasicBlockEdge *e: temp)
395
- {
396
- removeCFBBEdge(e);
397
- }
398
- removeGNode(node);
399
- _totalCFBasicBlockNode--;
400
- }
401
-
402
-
403
- /// Remove node from nodeID
404
- inline bool removeCFBBNode(NodeID id)
405
- {
406
- if (hasGNode(id))
407
- {
408
- removeCFBBNode(getGNode(id));
409
- return true;
410
- }
411
- return false;
412
- }
413
-
414
- /// Add ICFGEdgeWrapper
415
- inline bool addCFBBEdge(CFBasicBlockEdge *edge)
416
- {
417
- bool added1 = edge->getDstNode()->addIncomingEdge(edge);
418
- bool added2 = edge->getSrcNode()->addOutgoingEdge(edge);
419
- assert(added1 && added2 && "edge not added??");
420
- _totalCFBasicBlockEdge++;
421
- return added1 && added2;
422
- }
423
-
424
- /// Add a ICFGNodeWrapper
425
- virtual inline void addCFBBNode(CFBasicBlockNode *node)
426
- {
427
- addGNode(node->getId(), node);
428
- _totalCFBasicBlockNode++;
429
- }
430
- };
431
-
432
- }
433
-
434
-
435
- namespace SVF
436
- {
437
- /* !
438
- * GenericGraphTraits specializations for generic graph algorithms.
439
- * Provide graph traits for traversing from a constraint node using standard graph ICFGTraversals.
440
- */
441
- template<>
442
- struct GenericGraphTraits<SVF::CFBasicBlockNode *>
443
- : public GenericGraphTraits<SVF::GenericNode<SVF::CFBasicBlockNode, SVF::CFBasicBlockEdge> *>
444
- {
445
- };
446
-
447
- /// Inverse GenericGraphTraits specializations for call graph node, it is used for inverse ICFGTraversal.
448
- template<>
449
- struct GenericGraphTraits<Inverse< SVF::CFBasicBlockNode *> > : public GenericGraphTraits<
450
- Inverse<SVF::GenericNode<SVF::CFBasicBlockNode, SVF::CFBasicBlockEdge> *> >
451
- {
452
- };
453
-
454
- template<>
455
- struct GenericGraphTraits<SVF::CFBasicBlockGraph *>
456
- : public GenericGraphTraits<SVF::GenericGraph<SVF::CFBasicBlockNode, SVF::CFBasicBlockEdge> *>
457
- {
458
- typedef SVF::CFBasicBlockNode *NodeRef;
459
- };
460
-
461
- } // End namespace SVF
462
-
463
- namespace SVF
464
- {
465
- template<>
466
- struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVFIR *>
467
- {
468
-
469
- typedef SVF::CFBasicBlockNode NodeType;
470
-
471
- DOTGraphTraits(bool isSimple = false) :
472
- DOTGraphTraits<SVF::SVFIR *>(isSimple)
473
- {
474
- }
475
-
476
- /// Return name of the graph
477
- static std::string getGraphName(SVF::CFBasicBlockGraph *)
478
- {
479
- return "CFBasicBlockGraph";
480
- }
481
-
482
- std::string getNodeLabel(NodeType *node, SVF::CFBasicBlockGraph *graph)
483
- {
484
- return getSimpleNodeLabel(node, graph);
485
- }
486
-
487
- /// Return the label of an ICFG node
488
- static std::string getSimpleNodeLabel(NodeType *node, SVF::CFBasicBlockGraph *)
489
- {
490
- std::string str;
491
- std::stringstream rawstr(str);
492
- rawstr << "NodeID: " << node->getId() << "\n";
493
- rawstr << node->toString();
494
-
495
- return rawstr.str();
496
- }
497
-
498
- static std::string getNodeAttributes(NodeType *node, SVF::CFBasicBlockGraph *)
499
- {
500
- std::string str;
501
- std::stringstream rawstr(str);
502
- if(node->getICFGNodes().size() == 1)
503
- {
504
- const ICFGNode* n = node->getICFGNodes()[0];
505
- if(SVFUtil::isa<IntraICFGNode>(n))
506
- {
507
- rawstr << "color=black";
508
- }
509
- else if(SVFUtil::isa<FunEntryICFGNode>(n))
510
- {
511
- rawstr << "color=yellow";
512
- }
513
- else if(SVFUtil::isa<FunExitICFGNode>(n))
514
- {
515
- rawstr << "color=green";
516
- }
517
- else if(SVFUtil::isa<CallICFGNode>(n))
518
- {
519
- rawstr << "color=red";
520
- }
521
- else if(SVFUtil::isa<RetICFGNode>(n))
522
- {
523
- rawstr << "color=blue";
524
- }
525
- else if(SVFUtil::isa<GlobalICFGNode>(n))
526
- {
527
- rawstr << "color=purple";
528
- }
529
- else
530
- assert(false && "no such kind of node!!");
531
- }
532
- else
533
- {
534
- rawstr << "color=black";
535
- }
536
- rawstr << "";
537
- return rawstr.str();
538
- }
539
-
540
- template<class EdgeIter>
541
- static std::string getEdgeAttributes(NodeType *, EdgeIter EI, SVF::CFBasicBlockGraph *)
542
- {
543
- CFBasicBlockEdge* edge = *(EI.getCurrent());
544
- assert(edge && "No edge found!!");
545
- if (edge->getICFGEdge())
546
- {
547
- if (SVFUtil::isa<CallCFGEdge>(edge->getICFGEdge()))
548
- {
549
- return "style=solid,color=red";
550
- }
551
- else if (SVFUtil::isa<RetCFGEdge>(edge->getICFGEdge()))
552
- return "style=solid,color=blue";
553
- else
554
- return "style=solid";
555
- }
556
- else
557
- {
558
- return "style=solid";
559
- }
560
- }
561
-
562
- template<class EdgeIter>
563
- static std::string getEdgeSourceLabel(NodeType *, EdgeIter EI)
564
- {
565
- CFBasicBlockEdge* edge = *(EI.getCurrent());
566
- assert(edge && "No edge found!!");
567
-
568
- std::string str;
569
- std::stringstream rawstr(str);
570
- if (edge->getICFGEdge())
571
- {
572
- if (const CallCFGEdge* dirCall = SVFUtil::dyn_cast<CallCFGEdge>(edge->getICFGEdge()))
573
- rawstr << dirCall->getCallSite();
574
- else if (const RetCFGEdge* dirRet = SVFUtil::dyn_cast<RetCFGEdge>(edge->getICFGEdge()))
575
- rawstr << dirRet->getCallSite();
576
- }
577
- return rawstr.str();
578
- }
579
- };
580
- }
581
- #endif //SVF_CFBASICBLOCKG_H
@@ -1,64 +0,0 @@
1
- //===- CFBasicBlockGBuilder.h ----------------------------------------------------------------//
2
- //
3
- // SVF: Static Value-Flow Analysis
4
- //
5
- // Copyright (C) <2013-> <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 Affero 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 Affero General Public License for more details.
17
-
18
- // You should have received a copy of the GNU Affero General Public License
19
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
- //
21
- //===----------------------------------------------------------------------===//
22
-
23
- /*
24
- * CFBasicBlockGBuilder.h
25
- *
26
- * Created on: 17 Oct. 2023
27
- * Author: Xiao, Jiawei
28
- */
29
-
30
- #include "Graphs/CFBasicBlockG.h"
31
-
32
- namespace SVF
33
- {
34
-
35
- class CFBasicBlockGBuilder
36
- {
37
-
38
- private:
39
- CFBasicBlockGraph* _CFBasicBlockG;
40
-
41
- public:
42
- CFBasicBlockGBuilder() : _CFBasicBlockG() {}
43
-
44
- ~CFBasicBlockGBuilder()
45
- {
46
- delete _CFBasicBlockG;
47
- }
48
-
49
- virtual void build(ICFG* icfg);
50
-
51
- inline CFBasicBlockGraph* getCFBasicBlockGraph()
52
- {
53
- return _CFBasicBlockG;
54
- }
55
- private:
56
- void initCFBasicBlockGNodes(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
57
-
58
- void addInterBBEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
59
-
60
- void addIntraBBEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
61
-
62
- void addInterProceduralEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
63
- };
64
- }