8 using namespace SVFUtil;
10 ICFGPrinter::ICFGPrinter() {}
11 void ICFGPrinter::printICFGToJson(
const std::string& filename)
13 outs() <<
"write symbols to '" << filename <<
"'...";
18 outs() <<
" error opening file for writing!\n";
23 llvm::json::Array root_array;
28 llvm::json::Object ICFGNode_Obj;
29 ICFGNode_Obj[
"ICFG_ID"] = id;
30 ICFGNode_Obj[
"Node Type"] = getICFGKind(node->
getNodeKind());
31 if(
IntraBlockNode* bNode = SVFUtil::dyn_cast<IntraBlockNode>(node))
33 ICFGNode_Obj[
"Source Location"] =
getSourceLoc(bNode->getInst());
35 llvm::json::Array PAGEdge_array;
38 for (PAG::PAGEdgeList::iterator it = edges.begin(),
39 eit = edges.end(); it != eit; ++it)
42 llvm::json::Object edge_obj;
43 edge_obj[
"Source Node"] = edge->
getSrcID();
44 edge_obj[
"Destination Node"] = edge->
getDstID();
45 edge_obj[
"Source Type"] = getPAGNodeKindValue(edge->
getSrcNode()->getNodeKind());
46 edge_obj[
"Destination Type"] = getPAGNodeKindValue(edge->
getDstNode()->getNodeKind());
47 edge_obj[
"Edge Type"] = getPAGEdgeKindValue(edge->
getEdgeKind());
48 edge_obj[
"srcValueName"] = edge->
getSrcNode()->getValueName();
49 edge_obj[
"dstValueName"] = edge->
getDstNode()->getValueName();
52 const NormalGepPE* gepEdge = SVFUtil::cast<NormalGepPE>(edge);
53 edge_obj[
"offset"] = gepEdge->
getOffset();
56 PAGEdge_array.push_back(edge_value);
59 ICFGNode_Obj[
"PAG Edges"] = PagEdge_value;
64 ICFGNode_Obj[
"isExtCall"] =
true;
67 ICFGNode_Obj[
"isExtCall"] =
false;
70 ICFGNode_Obj[
"Function Name"] =
entry->getFun()->getName();
75 ICFGNode_Obj[
"isExtCall"] =
true;
78 ICFGNode_Obj[
"isExtCall"] =
false;
79 ICFGNode_Obj[
"Source Location"] =
getSourceLoc(&(
exit->getFun()->getLLVMFun()->back()));
81 ICFGNode_Obj[
"Function Name"] =
exit->getFun()->getName();
83 else if (
CallBlockNode* call = SVFUtil::dyn_cast<CallBlockNode>(node))
85 ICFGNode_Obj[
"Source Location"] =
getSourceLoc(call->getCallSite());
87 else if (
RetBlockNode* ret = SVFUtil::dyn_cast<RetBlockNode>(node))
89 ICFGNode_Obj[
"Source Location"] =
getSourceLoc(ret->getCallSite());
92 assert(
false &&
"what else kinds of nodes do we have??");
94 llvm::json::Array ICFGEdges_array;
98 llvm::json::Object ICFGEdge_obj;
99 if (SVFUtil::isa<CallCFGEdge>(edge))
102 ICFGEdge_obj[
"ICFG Edge Type"] =
"CallCFGEdge";
103 ICFGEdge_obj[
"ICFGEdgeSrcID"] = call->
getSrcID();
104 ICFGEdge_obj[
"ICFGEdgeDstID"] = call->
getDstID();
106 else if (SVFUtil::isa<RetCFGEdge>(edge))
109 ICFGEdge_obj[
"ICFG Edge Type"] =
"RetCFGEdge";
110 ICFGEdge_obj[
"ICFGEdgeSrcID"] = call->
getSrcID();
111 ICFGEdge_obj[
"ICFGEdgeDstID"] = call->
getDstID();
113 else if(SVFUtil::isa<IntraCFGEdge>(edge))
116 ICFGEdge_obj[
"ICFG Edge Type"] =
"IntraCFGEdge";
117 ICFGEdge_obj[
"ICFGEdgeSrcID"] = intraCFGEdge->
getSrcID();
118 ICFGEdge_obj[
"ICFGEdgeDstID"] = intraCFGEdge->
getDstID();
121 ICFGEdges_array.push_back(ICFGEdge_Val);
124 ICFGNode_Obj[
"ICFGEdges"] = ICFGEdges_val;
126 root_array.push_back(ICFGNode_val);
132 if (!F.os().has_error())
140 std::string ICFGPrinter::getICFGKind(
const int kind)
144 case ICFGNode::IntraBlock:
147 case ICFGNode::FunEntryBlock:
148 return "FunEntryBlock";
150 case ICFGNode::FunExitBlock:
151 return "FunExitBlock";
153 case ICFGNode::FunCallBlock:
154 return "FunCallBlock";
156 case ICFGNode::FunRetBlock:
157 return "FunRetBlock";
165 std::string ICFGPrinter::getPAGNodeKindValue(
int kind)
169 case (PAGNode::ValNode):
172 case PAGNode::ObjNode:
175 case PAGNode::RetNode:
178 case PAGNode::VarargNode:
181 case PAGNode::GepValNode:
184 case PAGNode::GepObjNode:
187 case PAGNode::FIObjNode:
190 case PAGNode::DummyValNode:
191 return "DummyValNode";
193 case PAGNode::DummyObjNode:
194 return "DummyObjNode";
200 std::string ICFGPrinter::getPAGEdgeKindValue(
int kind)
204 case (PAGEdge::Addr):
207 case (PAGEdge::Copy):
210 case (PAGEdge::Store):
213 case (PAGEdge::Load):
216 case (PAGEdge::Call):
222 case (PAGEdge::NormalGep):
225 case (PAGEdge::VariantGep):
228 case (PAGEdge::ThreadFork):
231 case (PAGEdge::ThreadJoin):
237 case (PAGEdge::BinaryOp):
240 case (PAGEdge::UnaryOp):
GEdgeKind getEdgeKind() const
iterator OutEdgeBegin()
iterators
NodeID getSrcID() const
get methods of the components
std::string getSourceLoc(const Value *val)
Return source code including line number and file name from debug information.
GNodeK getNodeKind() const
Get node kind.
NodeType * getDstNode() const
std::vector< const PAGEdge * > PAGEdgeList
llvm::ToolOutputFile ToolOutputFile
NodeType * getSrcNode() const
ICFGNodeIDToNodeMapTy::iterator iterator
raw_ostream & outs()
Overwrite llvm::outs()
ICFGEdge::ICFGEdgeSetTy::iterator iterator
raw_ostream & operator<<(raw_ostream &o, const std::pair< F, S > &var)
NodeID getId() const
Get ID.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
u32_t getOffset() const
offset of the gep edge
bool isExtCall(const SVFFunction *fun)