39 using namespace SVFUtil;
49 outs() <<
"Writing SVFG analysis to '" << filename <<
"'...";
51 std::fstream f(filename.c_str(), std::ios_base::out);
54 outs() <<
" error opening file for writing!\n";
59 for(
iterator it = begin(), eit = end(); it!=eit; ++it)
63 if(
const FormalINSVFGNode* formalIn = SVFUtil::dyn_cast<FormalINSVFGNode>(node))
66 f <<
"SVFGNodeID: " << nodeId <<
" >= " <<
"FormalINSVFGNode";
68 f << *formalIn->getMRVer() <<
"} >= ICFGNodeID: " << formalIn->getFunEntryNode()->
getId() <<
"\n";
70 else if(
const FormalOUTSVFGNode* formalOut = SVFUtil::dyn_cast<FormalOUTSVFGNode>(node))
73 f <<
"SVFGNodeID: " << nodeId <<
" >= " <<
"FormalOUTSVFGNode";
75 f << *formalOut->getMRVer() <<
"} >= ICFGNodeID: " << formalOut->getFunExitNode()->getId() <<
"\n";
77 else if(
const ActualINSVFGNode* actualIn = SVFUtil::dyn_cast<ActualINSVFGNode>(node))
80 f <<
"SVFGNodeID: " << nodeId <<
" >= " <<
"ActualINSVFGNode";
82 f << *actualIn->getMRVer() <<
"} >= ICFGNodeID: " << actualIn->getCallSite()->getId() <<
"\n";
84 else if(
const ActualOUTSVFGNode* actualOut = SVFUtil::dyn_cast<ActualOUTSVFGNode>(node))
87 f <<
"SVFGNodeID: " << nodeId <<
" >= " <<
"ActualOUTSVFGNode" <<
" >= MVER: {";
88 f << *actualOut->getMRVer() <<
"} >= ICFGNodeID: " << actualOut->getCallSite()->getId() <<
"\n";
90 else if(
const MSSAPHISVFGNode* phiNode = SVFUtil::dyn_cast<MSSAPHISVFGNode>(node))
93 f <<
"SVFGNodeID: " << nodeId <<
" >= " <<
"PHISVFGNode";
94 unordered_map<u32_t,const MRVer*> opvers;
95 for (MemSSA::PHI::OPVers::const_iterator it = phiNode->opVerBegin(), eit = phiNode->opVerEnd();
98 opvers.insert(make_pair(it->first, it->second));
102 f << *phiNode->getResVer();
104 f <<
"} >= ICFGNodeID: " << inst->
getId();
105 f <<
" >= OPVers: {";
108 const MRVer* op = x.second;
109 f <<
"{" << *op <<
"}" <<
",";
115 f <<
"\n\n__Edges__\n";
117 for(
iterator it = begin(), eit = end(); it!=eit; ++it)
119 NodeID nodeId = it->first;
121 if(
const LoadSVFGNode* loadNode = SVFUtil::dyn_cast<LoadSVFGNode>(node))
123 MUSet& muSet = mssa->getMUSet(SVFUtil::cast<LoadStmt>(loadNode->getPAGEdge()));
124 for(MUSet::iterator it = muSet.begin(), eit = muSet.end(); it!=eit; ++it)
126 if(
LOADMU* mu = SVFUtil::dyn_cast<LOADMU>(*it))
128 NodeID def = getDef(mu->getMRVer());
129 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << def <<
" >= LoadNode | MVER: {" << *mu->getMRVer() <<
"}" <<
"\n";
133 else if(
const StoreSVFGNode* storeNode = SVFUtil::dyn_cast<StoreSVFGNode>(node))
135 CHISet& chiSet = mssa->getCHISet(SVFUtil::cast<StoreStmt>(storeNode->getPAGEdge()));
136 for(CHISet::iterator it = chiSet.begin(), eit = chiSet.end(); it!=eit; ++it)
138 if(
STORECHI* chi = SVFUtil::dyn_cast<STORECHI>(*it))
140 NodeID def = getDef(chi->getOpVer());
141 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << def <<
" >= StoreNode | MVER: {" << *chi->getOpVer() <<
"}" <<
"\n";
145 else if(
const FormalINSVFGNode* formalIn = SVFUtil::dyn_cast<FormalINSVFGNode>(node))
148 mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun(),callInstSet);
149 for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it)
157 const ActualINSVFGNode* actualIn = SVFUtil::cast<ActualINSVFGNode>(getSVFGNode(*ait));
158 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << actualIn->
getId() <<
" >= FormalINSVFGNode" <<
"\n";
162 else if(
const FormalOUTSVFGNode* formalOut = SVFUtil::dyn_cast<FormalOUTSVFGNode>(node))
165 mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun(),callInstSet);
166 for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it)
169 if(!mssa->hasCHI(cs))
174 const ActualOUTSVFGNode* actualOut = SVFUtil::cast<ActualOUTSVFGNode>(getSVFGNode(*ait));
175 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << actualOut->
getId() <<
" >= FormalOUTSVFGNode" <<
"\n";
178 NodeID def = getDef(formalOut->getMRVer());
179 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << def <<
" >= FormalOUTSVFGNode | intra" <<
"\n";
181 else if(
const ActualINSVFGNode* actualIn = SVFUtil::dyn_cast<ActualINSVFGNode>(node))
183 NodeID def = getDef(actualIn->getMRVer());
184 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << def <<
" >= ActualINSVFGNode" <<
"\n";
187 else if(
const MSSAPHISVFGNode* phiNode = SVFUtil::dyn_cast<MSSAPHISVFGNode>(node))
189 for (MemSSA::PHI::OPVers::const_iterator it = phiNode->opVerBegin(), eit = phiNode->opVerEnd();
192 const MRVer* op = it->second;
194 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << def <<
" >= PHISVFGNode | MVER: {" << *op <<
"}" <<
"\n";
209 outs() <<
"Loading SVFG analysis results from '" << filename <<
"'...";
210 ifstream
F(filename.c_str());
213 outs() <<
" error opening file for reading!\n";
218 for (PAGEdge::PAGEdgeSetTy::iterator iter = stores.begin(), eiter =
219 stores.end(); iter != eiter; ++iter)
221 StoreStmt* store = SVFUtil::cast<StoreStmt>(*iter);
223 for(CHISet::iterator pi = mssa->getCHISet(store).begin(), epi = mssa->getCHISet(store).end(); pi!=epi; ++pi)
224 setDef((*pi)->getResVer(),sNode);
229 stat->ATVFNodeStart();
235 if (line.find(
"__Edges__") != std::string::npos)
245 size_t outer_last = 0;
253 while ((
next = s.find(delimiter, last)) != string::npos)
255 temp = s.substr(last,
next-last);
257 outer_last =
next + 4;
260 nextTemp = temp.find(
"SVFGNodeID: ") + 12;
261 id = atoi(temp.substr(nextTemp).c_str());
283 tempMRVer = getMRVERFromString(MR);
287 tempMRVer = getMRVERFromString(
"");
290 if(
type ==
"FormalINSVFGNode")
292 outer_last = s.find(
"ICFGNodeID: ") + 12;
293 NodeID FunID = atoi(s.substr(outer_last).c_str());
294 addFormalINSVFGNode(SVFUtil::dyn_cast<FunEntryICFGNode>(pag->getICFG()->getICFGNode(FunID)), tempMRVer,
id);
296 else if(
type ==
"FormalOUTSVFGNode")
298 outer_last = s.find(
"ICFGNodeID: ") + 12;
299 NodeID FunID = atoi(s.substr(outer_last).c_str());
300 addFormalOUTSVFGNode(SVFUtil::dyn_cast<FunExitICFGNode>(pag->getICFG()->getICFGNode(FunID)), tempMRVer,
id);
302 else if(
type ==
"ActualINSVFGNode")
304 outer_last = s.find(
"ICFGNodeID: ") + 12;
306 addActualINSVFGNode(SVFUtil::dyn_cast<CallICFGNode>(pag->getICFG()->getICFGNode(
CallSiteID)), tempMRVer,
id);
308 else if(
type ==
"ActualOUTSVFGNode")
310 outer_last = s.find(
"ICFGNodeID: ") + 12;
312 addActualOUTSVFGNode(SVFUtil::dyn_cast<CallICFGNode>(pag->getICFG()->getICFGNode(
CallSiteID)), tempMRVer,
id);
314 else if (
type ==
"PHISVFGNode")
316 opVer = s.substr(outer_last);
317 next = opVer.find(
"{") + 1;
318 last = opVer.find(
",}");
319 temp = opVer.substr(
next, last);
322 while ((
next = temp.find(
"{") + 1) != string::npos)
326 last = temp.find(
"},");
328 temp1 = temp.substr(
next, last-
next);
329 MRVer* tempOPVer = getMRVERFromString(temp1);
330 OPVers.insert(make_pair(
index, tempOPVer));
331 temp = temp.substr(last + 1);
334 next = basicBlock.find(
"ICFGNodeID: ") + 12;
335 temp = basicBlock.substr(
next);
336 addIntraMSSAPHISVFGNode(pag->getICFG()->getICFGNode(atoi(temp.c_str())), OPVers.begin(), OPVers.end(), tempMRVer,
id);
342 if (totalVFGNode <
id)
343 totalVFGNode =
id + 1;
347 stat->indVFEdgeStart();
364 next = s.find(delimiter);
366 edge = s.substr(0,
next);
367 attributes = s.substr(
next + 4);
372 next = edge.find(
"srcSVFGNodeID: ") + 15;
373 last = edge.find(
" => ");
374 src = atoi(edge.substr(
next, last-
next).c_str());
375 next = edge.find(
"dstSVFGNodeID: ") + 15;
376 dst = atoi(edge.substr(
next).c_str());
380 if (attributes.find(
" | ") == string::npos)
384 next = attributes.find(
" | ");
386 attribute = attributes.substr(
next + 3);
389 if(
type ==
"FormalINSVFGNode")
391 const FormalINSVFGNode* formalIn = SVFUtil::cast<FormalINSVFGNode>(getSVFGNode(src));
392 const ActualINSVFGNode* actualIn = SVFUtil::cast<ActualINSVFGNode>(getSVFGNode(dst));
393 addInterIndirectVFCallEdge(actualIn,formalIn, getCallSiteID(actualIn->
getCallSite(), formalIn->
getFun()));
395 else if(
type ==
"FormalOUTSVFGNode")
397 const FormalOUTSVFGNode* formalOut = SVFUtil::cast<FormalOUTSVFGNode>(getSVFGNode(src));
398 if (attribute.find(
"intra") != string::npos)
404 const ActualOUTSVFGNode* actualOut = SVFUtil::cast<ActualOUTSVFGNode>(getSVFGNode(dst));
405 addInterIndirectVFRetEdge(formalOut,actualOut,getCallSiteID(actualOut->
getCallSite(), formalOut->
getFun()));
408 else if(
type ==
"ActualINSVFGNode")
410 const ActualINSVFGNode* actualIn = SVFUtil::cast<ActualINSVFGNode>(getSVFGNode(src));
413 else if(
type ==
"ActualOUTSVFGNode")
417 else if (
type ==
"StoreNode" ||
type ==
"LoadNode" ||
type ==
"PHISVFGNode")
420 tempMRVer = getMRVERFromString(attribute);
427 stat->indVFEdgeEnd();
428 connectFromGlobalToProgEntry();
444 next = s.find(
"MemRegion: pts{") + 15;
445 last = s.find(
"} MRVERSION: ");
450 stringstream ss(temp);
451 while (getline(ss, point,
' '))
453 istringstream sss(point);
460 next = s.find(
"MSSADef: ") + 9;
461 last = s.find(
"} >=");
464 istringstream ss1(temp.substr(0, temp.find(
", ")));
468 tempDef =
new MSSADEF(defType, tempMemRegion);
470 next = s.find(
"MRVERSION: ") + 11;
471 last = s.find(
" MSSADef:");
474 istringstream ss2(temp);
478 tempMRVer =
new MRVer(tempMemRegion, obj2, tempDef);
const MRVer * getMRVer() const
Ver.
const CallICFGNode * getCallSite() const
Callsite.
const CallICFGNode * getCallSite() const
Callsite.
IDToNodeMapTy::iterator iterator
Node Iterators.
virtual const SVFBasicBlock * getBB() const
Return the basic block of this ICFGNode.
const MemRegion * getMR() const
Return the memory region.
const NodeBS & getPointsTo() const
Return points-to.
Set< const CallICFGNode * > CallInstSet
NodeID getId() const
Get ID.
const ICFGNode * front() const
virtual void writeToFile(const std::string &filename)
virtual MRVer * getMRVERFromString(const std::string &input)
virtual void readFile(const std::string &filename)
SVFStmtSetTy PAGEdgeSetTy
virtual const SVFFunction * getFun() const
Get the function of this SVFGNode.
std::ostream & outs()
Overwrite llvm::outs()
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map