Skip to content

Commit

Permalink
Merge pull request #22 from Geoffrey1014/jason_test_branch
Browse files Browse the repository at this point in the history
Jason test branch
  • Loading branch information
JasonZhongZexin authored Sep 8, 2024
2 parents 6e172eb + d26bf96 commit 782f25a
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/github-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ jobs:
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install cmake gcc g++ nodejs doxygen graphviz lcov libncurses5-dev libtinfo5 libzstd-dev
# sudo mkdir -p /var/cache/swap/
# sudo dd if=/dev/zero of=/var/cache/swap/swap0 bs=64M count=96
# sudo chmod 0600 /var/cache/swap/swap0
# sudo mkswap /var/cache/swap/swap0
# sudo swapon /var/cache/swap/swap0
# sudo swapon -s
# build-svf
- name: build-svf
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Dependencies include: build-essential libncurses5 libncurses-dev cmake zlib1g-dev
set -e # exit on first error

jobs=8
jobs=''

#########
# VARs and Links
Expand Down
1 change: 1 addition & 0 deletions svf-llvm/include/SVF-LLVM/LLVMModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class LLVMModuleSet
LLVMType2SVFTypeMap LLVMType2SVFType;
Type2TypeInfoMap Type2TypeInfo;
ObjTypeInference* typeInference;
NodeID callGraphNodeNum;

/// Constructor
LLVMModuleSet();
Expand Down
8 changes: 8 additions & 0 deletions svf-llvm/lib/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ LLVMModuleSet::LLVMModuleSet()
: symInfo(SymbolTableInfo::SymbolInfo()),
svfModule(SVFModule::getSVFModule()), typeInference(new ObjTypeInference())
{
callGraphNodeNum = 0;
}

LLVMModuleSet::~LLVMModuleSet()
Expand Down Expand Up @@ -243,6 +244,13 @@ void LLVMModuleSet::createSVFFunction(const Function* func)
func->isDeclaration(), LLVMUtil::isIntrinsicFun(func),
func->hasAddressTaken(), func->isVarArg(), new SVFLoopAndDomInfo);
svfModule->addFunctionSet(svfFunc);

NodeID id = callGraphNodeNum;
CallGraphNode* callGraphNode = new CallGraphNode(id, svfFunc);
svfModule->addCallGraphNode(callGraphNode);
callGraphNodeNum++;
// std::printf("callGraphNodeNum: %d\n",callGraphNodeNum);

if (ExtFun2Annotations.find(func) != ExtFun2Annotations.end())
svfFunc->setAnnotations(ExtFun2Annotations[func]);
addFunctionMap(func, svfFunc);
Expand Down
7 changes: 5 additions & 2 deletions svf/include/Graphs/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ class CallGraphNode : public GenericCallGraphNodeTy
{

}
inline const std::string &getName() const
{
return fun->getName();
}

/// Get function of this call node
inline const SVFFunction* getFunction() const
Expand Down Expand Up @@ -250,7 +254,6 @@ class CallGraph : public GenericCallGraphTy
FunToCallGraphNodeMap funToCallGraphNodeMap; ///< Call Graph node map
CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap; ///< Map a call instruction to its corresponding call edges

NodeID callGraphNodeNum;
u32_t numOfResolvedIndCallEdge;

/// Clean up memory
Expand All @@ -261,7 +264,7 @@ class CallGraph : public GenericCallGraphTy
CallGraph(CGEK k = NormCallGraph);

/// Add callgraph Node
void addCallGraphNode(const SVFFunction* fun);
void addCallGraphNode(const CallGraphNode* fun);

/// Destructor
virtual ~CallGraph()
Expand Down
31 changes: 30 additions & 1 deletion svf/include/SVFIR/SVFModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace SVF
{

class CallGraphNode;
class SVFModule
{
friend class SVFIRWriter;
Expand All @@ -48,6 +48,7 @@ class SVFModule
typedef std::vector<SVFGlobalValue*> AliasSetType;
typedef std::vector<SVFConstant*> ConstantType;
typedef std::vector<SVFOtherValue*> OtherValueType;
typedef std::vector<const CallGraphNode*> CallGraphNodeSetType;

/// Iterators type def
typedef FunctionSetType::iterator iterator;
Expand All @@ -60,6 +61,8 @@ class SVFModule
typedef ConstantType::const_iterator const_cdata_iterator;
typedef OtherValueType::iterator ovalue_iterator;
typedef OtherValueType::const_iterator const_ovalue_iterator;
typedef CallGraphNodeSetType::iterator callgraphnode_iterator;
typedef CallGraphNodeSetType::const_iterator const_callgraphnode_iterator;

private:
static SVFModule* svfModule;
Expand All @@ -70,6 +73,7 @@ class SVFModule
AliasSetType AliasSet; ///< The Aliases in the module
ConstantType ConstantSet; ///< The ConstantData in the module
OtherValueType OtherValueSet; ///< All other values in the module
CallGraphNodeSetType CallGraphNodeSet;

/// Constructors
SVFModule() = default;
Expand Down Expand Up @@ -107,6 +111,10 @@ class SVFModule
{
FunctionSet.push_back(svfFunc);
}
inline void addCallGraphNode(CallGraphNode* cgn)
{
CallGraphNodeSet.push_back(cgn);
}
inline void addGlobalSet(SVFGlobalValue* glob)
{
GlobalSet.push_back(glob);
Expand Down Expand Up @@ -147,6 +155,23 @@ class SVFModule
return FunctionSet.end();
}

callgraphnode_iterator callgraphnode_begin()
{
return CallGraphNodeSet.begin();
}
const_callgraphnode_iterator callgraphnode_begin() const
{
return CallGraphNodeSet.begin();
}
callgraphnode_iterator callgraphnode_end()
{
return CallGraphNodeSet.end();
}
const_callgraphnode_iterator callgraphnode_end() const
{
return CallGraphNodeSet.end();
}

global_iterator global_begin()
{
return GlobalSet.begin();
Expand Down Expand Up @@ -217,6 +242,10 @@ class SVFModule
{
return FunctionSet;
}
inline const CallGraphNodeSetType& getCallGraphNodeSet() const
{
return CallGraphNodeSet;
}
inline const ConstantType& getConstantSet() const
{
return ConstantSet;
Expand Down
11 changes: 4 additions & 7 deletions svf/lib/Graphs/CallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ bool CallGraphNode::isReachableFromProgEntry() const
/// Constructor
CallGraph::CallGraph(CGEK k): kind(k)
{
callGraphNodeNum = 0;
numOfResolvedIndCallEdge = 0;
}

Expand All @@ -121,13 +120,11 @@ void CallGraph::destroy()
/*!
* Add call graph node
*/
void CallGraph::addCallGraphNode(const SVFFunction* fun)
void CallGraph::addCallGraphNode(const CallGraphNode* callGraphNode)
{
NodeID id = callGraphNodeNum;
CallGraphNode* callGraphNode = new CallGraphNode(id, fun);
addGNode(id,callGraphNode);
funToCallGraphNodeMap[fun] = callGraphNode;
callGraphNodeNum++;
CallGraphNode* newNode = new CallGraphNode(callGraphNode->getId(), callGraphNode->getFunction());
addGNode(callGraphNode->getId(), newNode);
funToCallGraphNodeMap[callGraphNode->getFunction()] = newNode;
}

/*!
Expand Down
3 changes: 3 additions & 0 deletions svf/lib/SVFIR/SVFModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "Util/SVFUtil.h"
#include "Util/SVFStat.h"
#include "Util/Options.h"
#include "Graphs/CallGraph.h"

using namespace SVF;

Expand All @@ -40,6 +41,8 @@ SVFModule::~SVFModule()
delete c;
for (const SVFValue* o : OtherValueSet)
delete o;
for (const CallGraphNode* cgn : CallGraphNodeSet)
delete cgn;
NodeIDAllocator::unset();
ThreadAPI::destroy();
ExtAPI::destory();
Expand Down
2 changes: 1 addition & 1 deletion svf/lib/Util/CallGraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using namespace SVFUtil;
CallGraph* CallGraphBuilder::buildCallGraph(SVFModule* svfModule)
{
/// create nodes
for (SVFModule::const_iterator F = svfModule->begin(), E = svfModule->end(); F != E; ++F)
for (SVFModule::const_callgraphnode_iterator F = svfModule->callgraphnode_begin(), E = svfModule->callgraphnode_end(); F != E; ++F)
{
callgraph->addCallGraphNode(*F);
}
Expand Down

0 comments on commit 782f25a

Please sign in to comment.