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

#include <PAGBuilderFromFile.h>

Public Member Functions

 PAGBuilderFromFile (std::string f)
 Constructor. More...
 
 ~PAGBuilderFromFile ()
 Destructor. More...
 
SVFIRgetPAG () const
 Return SVFIR. More...
 
std::string getFileName () const
 Return file name. More...
 
SVFIRbuild ()
 Start building. More...
 
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:115

◆ ~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
153  PAGNode* srcNode = pag->getGNode(srcID);
154  PAGNode* dstNode = pag->getGNode(dstID);
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  {
165  pag->addAddrStmt(srcID, dstID);
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  {
175  pag->addCopyStmt(srcID, dstID, CopyStmt::COPYVAL);
176  }
177  else if (opType == "ZEXT")
178  {
179  pag->addCopyStmt(srcID, dstID, CopyStmt::ZEXT);
180  }
181  else if (opType == "SEXT")
182  {
183  pag->addCopyStmt(srcID, dstID, CopyStmt::SEXT);
184  }
185  else if (opType == "BITCAST")
186  {
187  pag->addCopyStmt(srcID, dstID, CopyStmt::BITCAST);
188  }
189  else if (opType == "TRUNC")
190  {
191  pag->addCopyStmt(srcID, dstID, CopyStmt::TRUNC);
192  }
193  else if (opType == "FPTRUNC")
194  {
195  pag->addCopyStmt(srcID, dstID, CopyStmt::FPTRUNC);
196  }
197  else if (opType == "FPTOUI")
198  {
199  pag->addCopyStmt(srcID, dstID, CopyStmt::FPTOUI);
200  }
201  else if (opType == "FPTOSI")
202  {
203  pag->addCopyStmt(srcID, dstID, CopyStmt::FPTOSI);
204  }
205  else if (opType == "UITOFP")
206  {
207  pag->addCopyStmt(srcID, dstID, CopyStmt::UITOFP);
208  }
209  else if (opType == "SITOFP")
210  {
211  pag->addCopyStmt(srcID, dstID, CopyStmt::SITOFP);
212  }
213  else if (opType == "INTTOPTR")
214  {
215  pag->addCopyStmt(srcID, dstID, CopyStmt::INTTOPTR);
216  }
217  else if (opType == "PTRTOINT")
218  {
219  pag->addCopyStmt(srcID, dstID, CopyStmt::PTRTOINT);
220  }
221  else
222  {
223  assert(false && "format not support, can not create such edge");
224  }
225  }
226  else if (edge == "load")
227  pag->addLoadStmt(srcID, dstID);
228  else if (edge == "store")
229  pag->addStoreStmt(srcID, dstID, nullptr);
230  else if (edge == "gep")
231  pag->addNormalGepStmt(srcID, dstID, AccessPath(offsetOrCSId));
232  else if (edge == "variant-gep")
233  pag->addVariantGepStmt(srcID, dstID, AccessPath(offsetOrCSId));
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")
239  pag->addCmpStmt(srcID, dstID, dstID, dstID);
240  else if (edge == "binary-op")
241  pag->addBinaryOPStmt(srcID, dstID, dstID, dstID);
242  else if (edge == "unary-op")
243  pag->addUnaryOPStmt(srcID, dstID, dstID);
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 }
const char *const string
Definition: cJSON.h:172
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
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:365
CopyStmt * addCopyStmt(NodeID src, NodeID dst, CopyStmt::CopyKind type)
Add Copy edge.
Definition: SVFIR.cpp:64
LoadStmt * addLoadStmt(NodeID src, NodeID dst)
Add Load edge.
Definition: SVFIR.cpp:204
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
Definition: SVFIR.cpp:346
CmpStmt * addCmpStmt(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
Add Copy edge.
Definition: SVFIR.cpp:127
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into SVFIR.
Definition: SVFIR.cpp:46
UnaryOPStmt * addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
Definition: SVFIR.cpp:168
BinaryOPStmt * addBinaryOPStmt(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
Definition: SVFIR.cpp:148
StoreStmt * addStoreStmt(NodeID src, NodeID dst, const ICFGNode *val)
Add Store edge.
Definition: SVFIR.cpp:223

◆ 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  {
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);
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  {
106  NodeID nodeSrc;
107  NodeID nodeDst;
108  APOffset offsetOrCSId;
109  string edge;
110  istringstream ss(line);
111  ss >> nodeSrc;
112  ss >> edge;
113  ss >> nodeDst;
114  ss >> offsetOrCSId;
115  outs() << "reading edge :" << nodeSrc << " " << edge << " "
116  << nodeDst << " offsetOrCSId=" << offsetOrCSId << " \n";
117  addEdge(nodeSrc, nodeDst, offsetOrCSId, edge);
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 
136  u32_t lower_bound = gepNodeNumIndex;
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.
Definition: GenericGraph.h:689
u32_t getTotalNodeNum() const
Get total number of node/edge.
Definition: GenericGraph.h:680
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:465
const MemObj * addDummyMemObj(NodeID i, const SVFType *type)
Definition: SVFIR.h:591
NodeID addDummyValNode()
Definition: SVFIR.h:474
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: