Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
SVF::PAGBuilderFromFile Class Reference

#include <PAGBuilderFromFile.h>

Public Member Functions

 PAGBuilderFromFile (std::string f)
 Constructor.
 
 ~PAGBuilderFromFile ()
 Destructor.
 
SVFIRgetPAG () const
 Return SVFIR.
 
std::string getFileName () const
 Return file name.
 
SVFIRbuild ()
 Start building.
 
void addEdge (NodeID nodeSrc, NodeID nodeDst, APOffset offset, std::string edge)
 

Private Attributes

SVFIRpag
 
std::string file
 

Detailed Description

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

Definition at line 41 of file PAGBuilderFromFile.h.

Constructor & Destructor Documentation

◆ PAGBuilderFromFile()

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

Constructor.

Definition at line 49 of file PAGBuilderFromFile.h.

49 :
50 pag(SVFIR::getPAG(true)), file(f)
51 {
52 }
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ ~PAGBuilderFromFile()

SVF::PAGBuilderFromFile::~PAGBuilderFromFile ( )
inline

Destructor.

Definition at line 54 of file PAGBuilderFromFile.h.

55 {
56 }

Member Function Documentation

◆ addEdge()

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

Add SVFIR edge according to a file format

sanity check for SVFIR from txt

Definition at line 148 of file PAGBuilderFromFile.cpp.

150{
151
152 //check whether these two nodes available
155
157 assert(SVFUtil::isa<ValVar>(dstNode) && "dst not an value node?");
158 if(edge=="addr")
159 assert(SVFUtil::isa<ObjVar>(srcNode) && "src not an value node?");
160 else
161 assert(!SVFUtil::isa<ObjVar>(srcNode) && "src not an object node?");
162
163 if (edge == "addr")
164 {
166 }
167 if (edge.rfind("copy-", 0) == 0)
168 {
169 // the enum is COPYVAL, ZEXT, SEXT, BITCAST, TRUNC, FPTRUNC,
171 std::string opType = edge.substr(5); // start substring from 5th char
172
173 if (opType == "COPYVAL")
174 {
176 }
177 else if (opType == "ZEXT")
178 {
180 }
181 else if (opType == "SEXT")
182 {
184 }
185 else if (opType == "BITCAST")
186 {
188 }
189 else if (opType == "TRUNC")
190 {
192 }
193 else if (opType == "FPTRUNC")
194 {
196 }
197 else if (opType == "FPTOUI")
198 {
200 }
201 else if (opType == "FPTOSI")
202 {
204 }
205 else if (opType == "UITOFP")
206 {
208 }
209 else if (opType == "SITOFP")
210 {
212 }
213 else if (opType == "INTTOPTR")
214 {
216 }
217 else if (opType == "PTRTOINT")
218 {
220 }
221 else
222 {
223 assert(false && "format not support, can not create such edge");
224 }
225 }
226 else if (edge == "load")
228 else if (edge == "store")
229 pag->addStoreStmt(srcID, dstID, nullptr);
230 else if (edge == "gep")
232 else if (edge == "variant-gep")
234 else if (edge == "call")
235 pag->addEdge(srcNode, dstNode, new CallPE(srcNode, dstNode, nullptr, nullptr));
236 else if (edge == "ret")
237 pag->addEdge(srcNode, dstNode, new RetPE(srcNode, dstNode, nullptr,nullptr));
238 else if (edge == "cmp")
240 else if (edge == "binary-op")
242 else if (edge == "unary-op")
244 else if (edge == "phi")
245 assert(false && "fix phi here!");
246 else if (edge == "select")
247 assert(false && "fix select here!");
248 else if (edge == "branch")
249 {
250 assert(false && "fix successors here!");
251 //pag->addBranchStmt(srcID, dstID, nullptr);
252 }
253 else
254 assert(false && "format not support, can not create such edge");
255}
NodeType * getGNode(NodeID id) const
Get a node.
bool addEdge(SVFVar *src, SVFVar *dst, SVFStmt *edge)
Add an edge into the graph.
Definition IRGraph.cpp:45
GepStmt * addVariantGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Variant(Gep) edge.
Definition SVFIR.cpp:366
CopyStmt * addCopyStmt(NodeID src, NodeID dst, CopyStmt::CopyKind type)
Add Copy edge.
Definition SVFIR.cpp:65
LoadStmt * addLoadStmt(NodeID src, NodeID dst)
Add Load edge.
Definition SVFIR.cpp:205
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
Definition SVFIR.cpp:347
CmpStmt * addCmpStmt(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
Add Copy edge.
Definition SVFIR.cpp:128
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into SVFIR.
Definition SVFIR.cpp:47
UnaryOPStmt * addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
Definition SVFIR.cpp:169
BinaryOPStmt * addBinaryOPStmt(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
Definition SVFIR.cpp:149
StoreStmt * addStoreStmt(NodeID src, NodeID dst, const ICFGNode *val)
Add Store edge.
Definition SVFIR.cpp:224

◆ build()

SVFIR * 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 {
71
73 string tmps;
75 while (ss.good())
76 {
77 ss >> tmps;
79 }
80
81 if (token_count == 0)
82 continue;
83
84 else if (token_count == 2)
85 {
87 string nodetype;
89 ss >> nodeId;
90 ss >> nodetype;
91 outs() << "reading node :" << nodeId << "\n";
92 if (nodetype == "v")
94 else if (nodetype == "o")
95 {
96 const MemObj* mem = pag->addDummyMemObj(nodeId, nullptr);
97 pag->addFIObjNode(mem);
98 }
99 else
100 assert(false && "format not support, pls specify node type");
101 }
102
103 // do consider gep edge
104 else if (token_count == 4)
105 {
109 string edge;
111 ss >> nodeSrc;
112 ss >> edge;
113 ss >> nodeDst;
114 ss >> offsetOrCSId;
115 outs() << "reading edge :" << nodeSrc << " " << edge << " "
116 << nodeDst << " offsetOrCSId=" << offsetOrCSId << " \n";
118 }
119 else
120 {
121 if (!line.empty())
122 {
123 outs() << "format not supported, token count = "
124 << token_count << "\n";
125 assert(false && "format not supported");
126 }
127 }
128 }
129 myfile.close();
130 }
131
132 else
133 outs() << "Unable to open file\n";
134
137 for(u32_t i = 0; i < lower_bound; i++)
138 pag->incNodeNum();
139
141
142 return pag;
143}
unsigned u32_t
Definition CommandLine.h:18
static u32_t gepNodeNumIndex
void incNodeNum()
Increase number of node/edge.
u32_t getTotalNodeNum() const
Get total number of node/edge.
void setNodeNumAfterPAGBuild(u32_t num)
Definition IRGraph.h:198
void addEdge(NodeID nodeSrc, NodeID nodeDst, APOffset offset, std::string edge)
NodeID addFIObjNode(const MemObj *obj)
Add a field-insensitive node, this method can only invoked by getFIGepObjNode.
Definition SVFIR.cpp:466
const MemObj * addDummyMemObj(NodeID i, const SVFType *type)
Definition SVFIR.h:730
NodeID addDummyValNode()
Definition SVFIR.h:496
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:50
u32_t NodeID
Definition GeneralType.h:55
s64_t APOffset
Definition GeneralType.h:60

◆ getFileName()

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

Return file name.

Definition at line 65 of file PAGBuilderFromFile.h.

66 {
67 return file;
68 }

◆ getPAG()

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

Return SVFIR.

Definition at line 59 of file PAGBuilderFromFile.h.

60 {
61 return pag;
62 }

Member Data Documentation

◆ file

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

Definition at line 46 of file PAGBuilderFromFile.h.

◆ pag

SVFIR* SVF::PAGBuilderFromFile::pag
private

Definition at line 45 of file PAGBuilderFromFile.h.


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