Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::PAGBuilderFromFile Class Reference

#include <PAGBuilderFromFile.h>

Public Member Functions

 PAGBuilderFromFile (std::string f)
 Constructor.
 ~PAGBuilderFromFile ()
 Destructor.
PAG * getPAG () const
 Return PAG.
std::string getFileName () const
 Return file name.
PAG * build ()
 Start building.
void addEdge (NodeID nodeSrc, NodeID nodeDst, APOffset offset, std::string edge)

Private Attributes

PAG * pag
std::string file

Detailed Description

Build PAG from a user specified file (for debugging purpose)

Definition at line 42 of file PAGBuilderFromFile.h.

Constructor & Destructor Documentation

◆ PAGBuilderFromFile()

SVF::PAGBuilderFromFile::PAGBuilderFromFile ( std::string f)
inline

Constructor.

Definition at line 50 of file PAGBuilderFromFile.h.

50 :
51 pag(PAG::getPAG(true)), file(f)
52 {
53 }
static PAG * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition PAG.h:121

◆ ~PAGBuilderFromFile()

SVF::PAGBuilderFromFile::~PAGBuilderFromFile ( )
inline

Destructor.

Definition at line 55 of file PAGBuilderFromFile.h.

56 {
57 }

Member Function Documentation

◆ addEdge()

void PAGBuilderFromFile::addEdge ( NodeID srcID,
NodeID dstID,
APOffset offsetOrCSId,
std::string edge )

Add PAG edge according to a file format

sanity check for PAG from txt

Definition at line 147 of file PAGBuilderFromFile.cpp.

149{
150
151 //check whether these two nodes available
152 PAGNode* srcNode = pag->getGNode(srcID);
153 PAGNode* dstNode = pag->getGNode(dstID);
154
156 assert(SVFUtil::isa<ValVar>(dstNode) && "dst not an value node?");
157 if(edge=="addr")
158 assert(SVFUtil::isa<ObjVar>(srcNode) && "src not an value node?");
159 else
160 assert(!SVFUtil::isa<ObjVar>(srcNode) && "src not an object node?");
161
162 if (edge == "addr")
163 {
164 pag->addAddrStmt(srcID, dstID);
165 }
166 if (edge.rfind("copy-", 0) == 0)
167 {
168 // the enum is COPYVAL, ZEXT, SEXT, BITCAST, TRUNC, FPTRUNC,
170 std::string opType = edge.substr(5); // start substring from 5th char
171
172 if (opType == "COPYVAL")
173 {
174 pag->addCopyStmt(srcID, dstID, CopyStmt::COPYVAL);
175 }
176 else if (opType == "ZEXT")
177 {
178 pag->addCopyStmt(srcID, dstID, CopyStmt::ZEXT);
179 }
180 else if (opType == "SEXT")
181 {
182 pag->addCopyStmt(srcID, dstID, CopyStmt::SEXT);
183 }
184 else if (opType == "BITCAST")
185 {
186 pag->addCopyStmt(srcID, dstID, CopyStmt::BITCAST);
187 }
188 else if (opType == "TRUNC")
189 {
190 pag->addCopyStmt(srcID, dstID, CopyStmt::TRUNC);
191 }
192 else if (opType == "FPTRUNC")
193 {
194 pag->addCopyStmt(srcID, dstID, CopyStmt::FPTRUNC);
195 }
196 else if (opType == "FPTOUI")
197 {
198 pag->addCopyStmt(srcID, dstID, CopyStmt::FPTOUI);
199 }
200 else if (opType == "FPTOSI")
201 {
202 pag->addCopyStmt(srcID, dstID, CopyStmt::FPTOSI);
203 }
204 else if (opType == "UITOFP")
205 {
206 pag->addCopyStmt(srcID, dstID, CopyStmt::UITOFP);
207 }
208 else if (opType == "SITOFP")
209 {
210 pag->addCopyStmt(srcID, dstID, CopyStmt::SITOFP);
211 }
212 else if (opType == "INTTOPTR")
213 {
214 pag->addCopyStmt(srcID, dstID, CopyStmt::INTTOPTR);
215 }
216 else if (opType == "PTRTOINT")
217 {
218 pag->addCopyStmt(srcID, dstID, CopyStmt::PTRTOINT);
219 }
220 else
221 {
222 assert(false && "format not support, can not create such edge");
223 }
224 }
225 else if (edge == "load")
226 pag->addLoadStmt(srcID, dstID);
227 else if (edge == "store")
228 pag->addStoreStmt(srcID, dstID, nullptr);
229 else if (edge == "gep")
230 pag->addNormalGepStmt(srcID, dstID, AccessPath(offsetOrCSId));
231 else if (edge == "variant-gep")
232 pag->addVariantGepStmt(srcID, dstID, AccessPath(offsetOrCSId));
233 else if (edge == "call")
234 pag->addEdge(srcNode, dstNode, new CallPE(SVFUtil::cast<ValVar>(dstNode), {SVFUtil::cast<ValVar>(srcNode)}, {nullptr}, nullptr));
235 else if (edge == "ret")
236 pag->addEdge(srcNode, dstNode, new RetPE(srcNode, dstNode, nullptr,nullptr));
237 else if (edge == "cmp")
238 pag->addCmpStmt(srcID, dstID, dstID, dstID);
239 else if (edge == "binary-op")
240 pag->addBinaryOPStmt(srcID, dstID, dstID, dstID);
241 else if (edge == "unary-op")
242 pag->addUnaryOPStmt(srcID, dstID, dstID);
243 else if (edge == "phi")
244 assert(false && "fix phi here!");
245 else if (edge == "select")
246 assert(false && "fix select here!");
247 else if (edge == "branch")
248 {
249 assert(false && "fix successors here!");
250 //pag->addBranchStmt(srcID, dstID, nullptr);
251 }
252 else
253 assert(false && "format not support, can not create such edge");
254}
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
Definition Casting.h:360
LLVM_NODISCARD bool isa(const Y &Val)
Definition Casting.h:241
SVFVar PAGNode
Definition PAGBase.h:40

◆ build()

PAG * PAGBuilderFromFile::build ( )

Start building.

new gep node's id from lower bound, nodeNum may not reflect the total nodes.

Definition at line 61 of file PAGBuilderFromFile.cpp.

62{
63
64 string line;
65 ifstream myfile(file.c_str());
66 if (myfile.is_open())
67 {
68 while (myfile.good())
69 {
70 getline(myfile, line);
71
72 u32_t token_count = 0;
73 string tmps;
74 istringstream ss(line);
75 while (ss.good())
76 {
77 ss >> tmps;
78 token_count++;
79 }
80
81 if (token_count == 0)
82 continue;
83
84 else if (token_count == 2)
85 {
86 NodeID nodeId;
87 string nodetype;
88 istringstream ss(line);
89 ss >> nodeId;
90 ss >> nodetype;
91 outs() << "reading node :" << nodeId << "\n";
92 if (nodetype == "v")
93 pag->addDummyValNode(nodeId, nullptr);
94 else if (nodetype == "o")
95 {
96 pag->addFIObjNode(nodeId, pag->createObjTypeInfo(nullptr), nullptr);
97 }
98 else
99 assert(false && "format not support, pls specify node type");
100 }
101
102 // do consider gep edge
103 else if (token_count == 4)
104 {
105 NodeID nodeSrc;
106 NodeID nodeDst;
107 APOffset offsetOrCSId;
108 string edge;
109 istringstream ss(line);
110 ss >> nodeSrc;
111 ss >> edge;
112 ss >> nodeDst;
113 ss >> offsetOrCSId;
114 outs() << "reading edge :" << nodeSrc << " " << edge << " "
115 << nodeDst << " offsetOrCSId=" << offsetOrCSId << " \n";
116 addEdge(nodeSrc, nodeDst, offsetOrCSId, edge);
117 }
118 else
119 {
120 if (!line.empty())
121 {
122 outs() << "format not supported, token count = "
123 << token_count << "\n";
124 assert(false && "format not supported");
125 }
126 }
127 }
128 myfile.close();
129 }
130
131 else
132 outs() << "Unable to open file\n";
133
135 u32_t lower_bound = gepNodeNumIndex;
136 for(u32_t i = 0; i < lower_bound; i++)
137 pag->incNodeNum();
138
139 pag->setNodeNumAfterPAGBuild(pag->getTotalNodeNum());
140
141 return pag;
142}
static u32_t gepNodeNumIndex
void addEdge(NodeID nodeSrc, NodeID nodeDst, APOffset offset, std::string edge)
std::ostream & outs()
Overwrite llvm::outs().
Definition SVFUtil.h:58
u32_t NodeID
Definition GeneralType.h:76
s64_t APOffset
Definition GeneralType.h:80
unsigned u32_t
Definition GeneralType.h:67

◆ getFileName()

std::string SVF::PAGBuilderFromFile::getFileName ( ) const
inline

Return file name.

Definition at line 66 of file PAGBuilderFromFile.h.

67 {
68 return file;
69 }

◆ getPAG()

PAG * SVF::PAGBuilderFromFile::getPAG ( ) const
inline

Return PAG.

Definition at line 60 of file PAGBuilderFromFile.h.

61 {
62 return pag;
63 }

Member Data Documentation

◆ file

std::string SVF::PAGBuilderFromFile::file
private

Definition at line 47 of file PAGBuilderFromFile.h.

◆ pag

PAG* SVF::PAGBuilderFromFile::pag
private

Definition at line 46 of file PAGBuilderFromFile.h.


The documentation for this class was generated from the following files: