Static Value-Flow Analysis
Loading...
Searching...
No Matches
CFLGraph.cpp
Go to the documentation of this file.
1//===----- CFLGraph.cpp -- Graph for context-free language reachability analysis --//
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/*
25 * CFLGraph.cpp
26 *
27 * Created on: March 5, 2022
28 * Author: Yulei Sui
29 */
30
31#include "Util/Options.h"
32#include "Graphs/CFLGraph.h"
33#include "Util/SVFUtil.h"
34
35using namespace SVF;
36
38{
39 return this->startKind;
40}
41
43{
44 addGNode(id, node);
45}
46
48{
49 CFLEdge* edge = new CFLEdge(src,dst,label);
50 if(cflEdgeSet.insert(edge).second)
51 {
53 dst->addIngoingEdge(edge);
54 return edge;
55 }
56 else
57 {
58 delete edge;
59 return nullptr;
60 }
61}
62
64{
65 CFLEdge edge(src,dst,label);
66 auto it = cflEdgeSet.find(&edge);
67 if(it !=cflEdgeSet.end())
68 return *it;
69 else
70 return nullptr;
71}
72
73void CFLGraph::dump(const std::string& filename)
74{
76}
77
79{
80 SVF::ViewGraph(this, "CFL Graph");
81}
82
83namespace SVF
84{
88template<>
90{
91
93
94 DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple)
95 {
96 }
97
99 static std::string getGraphName(CFLGraph*)
100 {
101 return "CFL Reachability Graph";
102 }
104 static std::string getNodeLabel(CFLNode *node, CFLGraph*)
105 {
106 std::string str;
107 std::stringstream rawstr(str);
108 rawstr << "Node ID: " << node->getId() << " ";
109 return rawstr.str();
110 }
111
112 static std::string getNodeAttributes(CFLNode *node, CFLGraph*)
113 {
114 return "shape=box";
115 }
116
117 template<class EdgeIter>
118 static std::string getEdgeAttributes(CFLNode*, EdgeIter EI, CFLGraph* graph)
119 {
120 CFLEdge* edge = *(EI.getCurrent());
121 assert(edge && "No edge found!!");
122 std::string str;
123 std::stringstream rawstr(str);
124 if (edge->getEdgeKind() == ConstraintEdge::Addr)
125 {
126 rawstr << "color=green";
127 }
128 else if (edge->getEdgeKind() == ConstraintEdge::Copy)
129 {
130 rawstr << "color=black";
131 }
132 else if (edge->getEdgeKindWithMask() == ConstraintEdge::NormalGep)
133 {
134 rawstr << "color=purple,label=" << '"' << "Gep_" << edge->getEdgeAttri() << '"';
135 }
136 else if (edge->getEdgeKindWithMask() == ConstraintEdge::VariantGep)
137 {
138 rawstr << "color=purple,label=" << '"' << "VGep" << '"';
139 }
140 else if (edge->getEdgeKind() == ConstraintEdge::Store)
141 {
142 rawstr << "color=blue";
143 }
144 else if (edge->getEdgeKind() == ConstraintEdge::Load)
145 {
146 rawstr << "color=red";
147 }
148 else if (edge->getEdgeKind() == graph->getStartKind())
149 {
150 rawstr << "color=Turquoise";
151 }
152 else
153 {
154 rawstr << "style=invis";
155 }
156 return rawstr.str();
157 }
158
159 template<class EdgeIter>
161 {
162 CFLEdge* edge = *(EI.getCurrent());
163 assert(edge && "No edge found!!");
164 std::string str;
165 std::stringstream rawstr(str);
166 rawstr << "Edge label: " << edge->getEdgeKind() << " ";
167 return rawstr.str();
168 }
169};
170
171}
virtual void addCFLNode(NodeID id, CFLNode *node)
Definition CFLGraph.cpp:42
CFGrammar::Kind Kind
Definition CFLGraph.h:176
Kind getStartKind() const
Definition CFLGraph.cpp:37
virtual const CFLEdge * addCFLEdge(CFLNode *src, CFLNode *dst, CFLEdge::GEdgeFlag label)
Definition CFLGraph.cpp:47
void dump(const std::string &filename)
Definition CFLGraph.cpp:73
virtual const CFLEdge * hasEdge(CFLNode *src, CFLNode *dst, CFLEdge::GEdgeFlag label)
Definition CFLGraph.cpp:63
CFLEdgeSet cflEdgeSet
Definition CFLGraph.h:204
bool addIngoingEdge(CFLEdge *inEdge)
Definition CFLGraph.h:112
bool addOutgoingEdge(CFLEdge *OutEdge)
Definition CFLGraph.h:126
void addGNode(NodeID id, NodeType *node)
Add a Node.
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)
NodeID getId() const
Get ID.
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:50
for isBitcode
Definition BasicTypes.h:68
u32_t NodeID
Definition GeneralType.h:55
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
static std::string getEdgeSourceLabel(NodeType *, EdgeIter EI)
Definition CFLGraph.cpp:160
static std::string getNodeAttributes(CFLNode *node, CFLGraph *)
Definition CFLGraph.cpp:112
static std::string getNodeLabel(CFLNode *node, CFLGraph *)
Return function name;.
Definition CFLGraph.cpp:104
DOTGraphTraits(bool isSimple=false)
Definition CFLGraph.cpp:94
static std::string getGraphName(CFLGraph *)
Return name of the graph.
Definition CFLGraph.cpp:99
static std::string getEdgeAttributes(CFLNode *, EdgeIter EI, CFLGraph *graph)
Definition CFLGraph.cpp:118