Static Value-Flow Analysis
CDG.cpp
Go to the documentation of this file.
1 //===- CDG.cpp -- Control Dependence 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 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  * CDG.cpp
25  *
26  * Created on: Sep 27, 2023
27  * Author: Xiao Cheng
28  */
29 #include "Graphs/CDG.h"
30 
31 using namespace SVF;
32 
33 CDG *CDG::controlDg = nullptr;
34 
35 void CDG::addCDGEdgeFromSrcDst(const ICFGNode *src, const ICFGNode *dst, const SVFVar *pNode, s32_t branchID)
36 {
37  if (!hasCDGNode(src->getId()))
38  {
39  addGNode(src->getId(), new CDGNode(src));
40  }
41  if (!hasCDGNode(dst->getId()))
42  {
43  addGNode(dst->getId(), new CDGNode(dst));
44  }
45  if (!hasCDGEdge(getCDGNode(src->getId()), getCDGNode(dst->getId())))
46  {
47  CDGEdge *pEdge = new CDGEdge(getCDGNode(src->getId()),
48  getCDGNode(dst->getId()));
49  pEdge->insertBranchCondition(pNode, branchID);
50  addCDGEdge(pEdge);
51  incEdgeNum();
52  }
53  else
54  {
55  CDGEdge *pEdge = getCDGEdge(getCDGNode(src->getId()),
56  getCDGNode(dst->getId()));
57  pEdge->insertBranchCondition(pNode, branchID);
58  }
59 }
void insertBranchCondition(const SVFVar *pNode, s32_t branchID)
Definition: CDG.h:76
Definition: CDG.h:143
bool hasCDGEdge(CDGNode *src, CDGNode *dst)
Whether we has a CDG edge.
Definition: CDG.h:201
CDGNode * getCDGNode(NodeID id) const
Get a CDG node.
Definition: CDG.h:187
static CDG * controlDg
Definition: CDG.h:155
void addCDGEdgeFromSrcDst(const ICFGNode *src, const ICFGNode *dst, const SVFVar *pNode, s32_t branchID)
Add CDG edges from nodeid pair.
Definition: CDG.cpp:35
bool hasCDGNode(NodeID id) const
Whether has the CDGNode.
Definition: CDG.h:195
bool addCDGEdge(CDGEdge *edge)
Add CDG edge.
Definition: CDG.h:281
CDGEdge * getCDGEdge(const CDGNode *src, const CDGNode *dst)
Get a control dependence edge according to src and dst.
Definition: CDG.h:216
void addGNode(NodeID id, NodeType *node)
Add a Node.
Definition: GenericGraph.h:646
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
for isBitcode
Definition: BasicTypes.h:68
signed s32_t
Definition: GeneralType.h:47