48 outs() <<
"Writing SVFG analysis to '" << filename <<
"'...";
50 std::fstream f(filename.c_str(), std::ios_base::out);
53 outs() <<
" error opening file for writing!\n";
65 f <<
"SVFGNodeID: " << nodeId <<
" >= " <<
"FormalINSVFGNode";
67 f << *formalIn->getMRVer() <<
"} >= ICFGNodeID: " << formalIn->getFunEntryNode()->getId() <<
"\n";
72 f <<
"SVFGNodeID: " << nodeId <<
" >= " <<
"FormalOUTSVFGNode";
74 f << *formalOut->getMRVer() <<
"} >= ICFGNodeID: " << formalOut->getFunExitNode()->getId() <<
"\n";
79 f <<
"SVFGNodeID: " << nodeId <<
" >= " <<
"ActualINSVFGNode";
81 f << *actualIn->getMRVer() <<
"} >= ICFGNodeID: " << actualIn->getCallSite()->getId() <<
"\n";
86 f <<
"SVFGNodeID: " << nodeId <<
" >= " <<
"ActualOUTSVFGNode" <<
" >= MVER: {";
87 f << *actualOut->getMRVer() <<
"} >= ICFGNodeID: " << actualOut->getCallSite()->getId() <<
"\n";
92 f <<
"SVFGNodeID: " << nodeId <<
" >= " <<
"PHISVFGNode";
93 unordered_map<u32_t,const MRVer*> opvers;
94 for (MemSSA::PHI::OPVers::const_iterator it = phiNode->opVerBegin(), eit = phiNode->opVerEnd();
97 opvers.insert(make_pair(it->first, it->second));
101 f << *phiNode->getResVer();
103 f <<
"} >= ICFGNodeID: " << inst->
getId();
104 f <<
" >= OPVers: {";
107 const MRVer* op = x.second;
108 f <<
"{" << *op <<
"}" <<
",";
114 f <<
"\n\n__Edges__\n";
118 NodeID nodeId = it->first;
123 for(MUSet::iterator it = muSet.begin(), eit = muSet.end(); it!=eit; ++it)
128 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << def <<
" >= LoadNode | MVER: {" << *mu->getMRVer() <<
"}" <<
"\n";
135 for(CHISet::iterator it = chiSet.begin(), eit = chiSet.end(); it!=eit; ++it)
140 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << def <<
" >= StoreNode | MVER: {" << *chi->getOpVer() <<
"}" <<
"\n";
147 mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun(),callInstSet);
148 for(CallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it)
157 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << actualIn->
getId() <<
" >= FormalINSVFGNode" <<
"\n";
164 mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun(),callInstSet);
165 for(CallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it)
168 if(!
mssa->hasCHI(cs))
174 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << actualOut->
getId() <<
" >= FormalOUTSVFGNode" <<
"\n";
178 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << def <<
" >= FormalOUTSVFGNode | intra" <<
"\n";
183 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << def <<
" >= ActualINSVFGNode" <<
"\n";
188 for (MemSSA::PHI::OPVers::const_iterator it = phiNode->opVerBegin(), eit = phiNode->opVerEnd();
191 const MRVer* op = it->second;
193 f <<
"srcSVFGNodeID: " << nodeId <<
" => " <<
"dstSVFGNodeID: " << def <<
" >= PHISVFGNode | MVER: {" << *op <<
"}" <<
"\n";
208 outs() <<
"Loading SVFG analysis results from '" << filename <<
"'...";
209 ifstream F(filename.c_str());
212 outs() <<
" error opening file for reading!\n";
217 for (SVFStmt::SVFStmtSetTy::iterator iter = stores.begin(), eiter =
218 stores.end(); iter != eiter; ++iter)
222 for(CHISet::iterator pi =
mssa->getCHISet(store).begin(), epi =
mssa->getCHISet(store).end(); pi!=epi; ++pi)
223 setDef((*pi)->getResVer(),sNode);
228 stat->ATVFNodeStart();
234 if (line.find(
"__Edges__") != std::string::npos)
237 std::string s = line;
238 std::string delimiter =
" >= ";
244 size_t outer_last = 0;
252 while ((
next = s.find(delimiter, last)) != string::npos)
254 temp = s.substr(last,
next-last);
256 outer_last =
next + 4;
259 nextTemp = temp.find(
"SVFGNodeID: ") + 12;
260 id = atoi(temp.substr(nextTemp).c_str());
289 if(
type ==
"FormalINSVFGNode")
291 outer_last = s.find(
"ICFGNodeID: ") + 12;
292 NodeID FunID = atoi(s.substr(outer_last).c_str());
295 else if(
type ==
"FormalOUTSVFGNode")
297 outer_last = s.find(
"ICFGNodeID: ") + 12;
298 NodeID FunID = atoi(s.substr(outer_last).c_str());
301 else if(
type ==
"ActualINSVFGNode")
303 outer_last = s.find(
"ICFGNodeID: ") + 12;
307 else if(
type ==
"ActualOUTSVFGNode")
309 outer_last = s.find(
"ICFGNodeID: ") + 12;
313 else if (
type ==
"PHISVFGNode")
315 opVer = s.substr(outer_last);
316 next = opVer.find(
"{") + 1;
317 last = opVer.find(
",}");
318 temp = opVer.substr(
next, last);
321 while ((
next = temp.find(
"{") + 1) != string::npos)
325 last = temp.find(
"},");
327 temp1 = temp.substr(
next, last-
next);
329 OPVers.insert(make_pair(
index, tempOPVer));
330 temp = temp.substr(last + 1);
333 next = basicBlock.find(
"ICFGNodeID: ") + 12;
334 temp = basicBlock.substr(
next);
346 stat->indVFEdgeStart();
354 std::string s = line;
355 std::string delimiter =
" >= ";
363 next = s.find(delimiter);
365 edge = s.substr(0,
next);
366 attributes = s.substr(
next + 4);
371 next = edge.find(
"srcSVFGNodeID: ") + 15;
372 last = edge.find(
" => ");
373 src = atoi(edge.substr(
next, last-
next).c_str());
374 next = edge.find(
"dstSVFGNodeID: ") + 15;
375 dst = atoi(edge.substr(
next).c_str());
379 if (attributes.find(
" | ") == string::npos)
383 next = attributes.find(
" | ");
385 attribute = attributes.substr(
next + 3);
388 if(
type ==
"FormalINSVFGNode")
394 else if(
type ==
"FormalOUTSVFGNode")
397 if (attribute.find(
"intra") != string::npos)
407 else if(
type ==
"ActualINSVFGNode")
412 else if(
type ==
"ActualOUTSVFGNode")
416 else if (
type ==
"StoreNode" ||
type ==
"LoadNode" ||
type ==
"PHISVFGNode")
426 stat->indVFEdgeEnd();
443 next = s.find(
"MemRegion: pts{") + 15;
444 last = s.find(
"} MRVERSION: ");
449 stringstream ss(temp);
450 while (getline(ss, point,
' '))
452 istringstream sss(point);
459 next = s.find(
"MSSADef: ") + 9;
460 last = s.find(
"} >=");
463 istringstream ss1(temp.substr(0, temp.find(
", ")));
467 tempDef =
new MSSADEF(defType, tempMemRegion);
469 next = s.find(
"MRVERSION: ") + 11;
470 last = s.find(
" MSSADef:");
473 istringstream ss2(temp);
477 tempMRVer =
new MRVer(tempMemRegion, obj2, tempDef);
const MRVer * getMRVer() const
Ver.
const CallICFGNode * getCallSite() const
Callsite.
const CallICFGNode * getCallSite() const
Callsite.
Set< const CallICFGNode * > CallInstSet
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.
const ICFGNode * front() const
ActualOUTSVFGNodeSet & getActualOUTSVFGNodes(const CallICFGNode *cs)
NodeBS ActualOUTSVFGNodeSet
SVFGEdge * addInterIndirectVFCallEdge(const ActualINSVFGNode *src, const FormalINSVFGNode *dst, CallSiteID csId)
Add inter VF edge from callsite mu to function entry chi.
void connectFromGlobalToProgEntry()
Connect indirect SVFG edges from global initializers (store) to main function entry.
SVFGNode * getSVFGNode(NodeID id) const
Get a SVFG node.
void addIntraMSSAPHISVFGNode(ICFGNode *BlockICFGNode, const Map< u32_t, const MRVer * >::const_iterator opVerBegin, const Map< u32_t, const MRVer * >::const_iterator opVerEnd, const MRVer *resVer, const NodeID nodeId)
Add memory SSA PHI SVFG node.
ActualINSVFGNodeSet & getActualINSVFGNodes(const CallICFGNode *cs)
Get SVFGNode set.
void addActualOUTSVFGNode(const CallICFGNode *callsite, const MRVer *resVer, const NodeID nodeId)
Add memory callsite chi SVFG node.
virtual void writeToFile(const std::string &filename)
void addFormalOUTSVFGNode(const FunExitICFGNode *funExit, const MRVer *ver, const NodeID nodeId)
Add memory Function return mu SVFG node.
void setDef(const ValVar *valVar, const SVFGNode *node)
Given a ValVar, set/get its def SVFG node (definition of top level pointers).
virtual MRVer * getMRVERFromString(const std::string &input)
void addActualINSVFGNode(const CallICFGNode *callsite, const MRVer *ver, const NodeID nodeId)
Add memory callsite mu SVFG node.
NodeID getDef(const ValVar *valVar) const
virtual void readFile(const std::string &filename)
std::unique_ptr< MemSSA > mssa
NodeBS ActualINSVFGNodeSet
void addFormalINSVFGNode(const FunEntryICFGNode *funEntry, const MRVer *resVer, const NodeID nodeId)
Add memory Function entry chi SVFG node.
SVFGEdge * addInterIndirectVFRetEdge(const FormalOUTSVFGNode *src, const ActualOUTSVFGNode *dst, CallSiteID csId)
Add inter VF edge from function exit mu to callsite chi.
SVFGEdge * addIntraIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS &cpts)
Add indirect def-use edges of a memory region between two statements,.
MemSSA::STORECHI STORECHI
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
NodeID getId() const
Get ID.
SparseBitVectorIterator iterator
virtual const FunObjVar * getFun() const
Get the function of this SVFGNode.
VFGNodeIDToNodeMapTy::iterator iterator
CallSiteID getCallSiteID(const CallICFGNode *cs, const FunObjVar *func) const
Get callsite given a callsiteID.
StmtVFGNode * getStmtVFGNode(const SVFStmt *svfStmt) const
Get an VFGNode.
virtual SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get SVFStmt set.
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
std::ostream & outs()
Overwrite llvm::outs().
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
StoreVFGNode StoreSVFGNode
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map