diff --git a/svf-llvm/tools/Example/svf-ex.cpp b/svf-llvm/tools/Example/svf-ex.cpp
index 8d2473e2b..42c780958 100644
--- a/svf-llvm/tools/Example/svf-ex.cpp
+++ b/svf-llvm/tools/Example/svf-ex.cpp
@@ -6,16 +6,16 @@
//
// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published by
+// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
+// GNU General Public License for more details.
-// You should have received a copy of the GNU Affero General Public License
+// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
//===-----------------------------------------------------------------------===//
@@ -34,30 +34,35 @@
#include "Util/Options.h"
#include "WPA/Andersen.h"
+using namespace llvm;
using namespace std;
using namespace SVF;
/*!
* An example to query alias results of two LLVM values
*/
-SVF::AliasResult aliasQuery(PointerAnalysis* pta, SVFValue* v1, SVFValue* v2)
+SVF::AliasResult aliasQuery(PointerAnalysis* pta, Value* v1, Value* v2)
{
- return pta->alias(v1,v2);
+ SVFValue* val1 = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(v1);
+ SVFValue* val2 = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(v2);
+
+ return pta->alias(val1,val2);
}
/*!
* An example to print points-to set of an LLVM value
*/
-std::string printPts(PointerAnalysis* pta, SVFValue* val)
+std::string printPts(PointerAnalysis* pta, Value* val)
{
std::string str;
- std::stringstream rawstr(str);
+ raw_string_ostream rawstr(str);
+ SVFValue* svfval = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(val);
- NodeID pNodeId = pta->getPAG()->getValueNode(val);
+ NodeID pNodeId = pta->getPAG()->getValueNode(svfval);
const PointsTo& pts = pta->getPts(pNodeId);
for (PointsTo::iterator ii = pts.begin(), ie = pts.end();
- ii != ie; ii++)
+ ii != ie; ii++)
{
rawstr << " " << *ii << " ";
PAGNode* targetObj = pta->getPAG()->getGNode(*ii);
@@ -162,14 +167,18 @@ void traverseOnICFG(ICFG* icfg, const ICFGNode* iNode)
}
}
+void skipWarning(const VFGNode* node) {
+
+}
/*!
* An example to query/collect all the uses of a definition of a value along value-flow graph (VFG)
*/
-void traverseOnVFG(const SVFG* vfg, SVFValue* val)
+void traverseOnVFG(const SVFG* vfg, const SVFValue* svfval)
{
SVFIR* pag = SVFIR::getPAG();
-
- PAGNode* pNode = pag->getGNode(pag->getValueNode(val));
+ PAGNode* pNode = pag->getGNode(pag->getValueNode(svfval));
+ if (!vfg->hasDefSVFGNode(pNode))
+ return;
const VFGNode* vNode = vfg->getDefSVFGNode(pNode);
FIFOWorkList worklist;
Set visited;
@@ -195,10 +204,11 @@ void traverseOnVFG(const SVFG* vfg, SVFValue* val)
/// Collect all LLVM Values
for(Set::const_iterator it = visited.begin(), eit = visited.end(); it!=eit; ++it)
{
- // const VFGNode* node = *it;
+ const VFGNode* node = *it;
+ skipWarning(node);
/// can only query VFGNode involving top-level pointers (starting with % or @ in LLVM IR)
/// PAGNode* pNode = vfg->getLHSTopLevPtr(node);
- /// SVFValue* val = pNode->getValue();
+ /// Value* val = pNode->getValue();
}
}
@@ -207,8 +217,8 @@ int main(int argc, char ** argv)
std::vector moduleNameVec;
moduleNameVec = OptionBase::parseOptions(
- argc, argv, "Whole Program Points-to Analysis", "[options] "
- );
+ argc, argv, "Whole Program Points-to Analysis", "[options] "
+ );
if (Options::WriteAnder() == "ir_annotator")
{
@@ -221,7 +231,6 @@ int main(int argc, char ** argv)
SVFIRBuilder builder(svfModule);
SVFIR* pag = builder.build();
-
/// Create Andersen's pointer analysis
Andersen* ander = AndersenWaveDiff::createAndersenWaveDiff(pag);
@@ -236,19 +245,21 @@ int main(int argc, char ** argv)
/// ICFG
ICFG* icfg = pag->getICFG();
- icfg->dump("icfg");
/// Value-Flow Graph (VFG)
VFG* vfg = new VFG(callgraph);
/// Sparse value-flow graph (SVFG)
- SVFGBuilder svfBuilder(true);
- //SVFG* svfg =
- svfBuilder.buildFullSVFG(ander);
+ SVFGBuilder svfBuilder;
+ SVFG* svfg = svfBuilder.buildFullSVFG(ander);
/// Collect uses of an LLVM Value
- /// traverseOnVFG(svfg, value);
-
+ for (const auto &it : *svfg)
+ {
+ const SVFGNode* node = it.second;
+ if (node->getValue())
+ traverseOnVFG(svfg, node->getValue());
+ }
/// Collect all successor nodes on ICFG
for (const auto &it : *icfg)