Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SVF::GraphWriter< GraphType > Class Template Reference

#include <GraphWriter.h>

Public Member Functions

 GraphWriter (std::ofstream &o, const GraphType &g, bool SN)
 
void writeGraph (const std::string &Title="")
 
void writeHeader (const std::string &Title)
 
void writeFooter ()
 
void writeNodes ()
 
bool isNodeHidden (NodeRef Node)
 
void writeNode (NodeRef Node)
 
void writeEdge (NodeRef Node, unsigned edgeidx, child_iterator EI)
 
void emitSimpleNode (const void *ID, const std::string &Attr, const std::string &Label, unsigned NumEdgeSources=0, const std::vector< std::string > *EdgeSourceLabels=nullptr)
 emitSimpleNode - Outputs a simple (non-record) node
 
void emitEdge (const void *SrcNodeID, int SrcNodePort, const void *DestNodeID, int DestNodePort, const std::string &Attrs)
 emitEdge - Output an edge from a simple node into the graph...
 
std::ofstream & getOStream ()
 

Private Types

using DOTTraits = DOTGraphTraits< GraphType >
 
using GTraits = GenericGraphTraits< GraphType >
 
using NodeRef = typename GTraits::NodeRef
 
using node_iterator = typename GTraits::nodes_iterator
 
using child_iterator = typename GTraits::ChildIteratorType
 

Private Member Functions

bool getEdgeSourceLabels (std::stringstream &O2, NodeRef Node)
 

Private Attributes

std::ofstream & O
 
const GraphTypeG
 
DOTTraits DTraits
 

Detailed Description

template<typename GraphType>
class SVF::GraphWriter< GraphType >

Definition at line 63 of file GraphWriter.h.

Member Typedef Documentation

◆ child_iterator

template<typename GraphType >
using SVF::GraphWriter< GraphType >::child_iterator = typename GTraits::ChildIteratorType
private

Definition at line 72 of file GraphWriter.h.

◆ DOTTraits

Definition at line 68 of file GraphWriter.h.

◆ GTraits

Definition at line 69 of file GraphWriter.h.

◆ node_iterator

template<typename GraphType >
using SVF::GraphWriter< GraphType >::node_iterator = typename GTraits::nodes_iterator
private

Definition at line 71 of file GraphWriter.h.

◆ NodeRef

Definition at line 70 of file GraphWriter.h.

Constructor & Destructor Documentation

◆ GraphWriter()

template<typename GraphType >
SVF::GraphWriter< GraphType >::GraphWriter ( std::ofstream &  o,
const GraphType g,
bool  SN 
)
inline

Definition at line 110 of file GraphWriter.h.

110 : O(o), G(g)
111 {
113 }
const GraphType & G
Definition GraphWriter.h:66
DOTGraphTraits< GraphType > DOTTraits
Definition GraphWriter.h:68
std::ofstream & O
Definition GraphWriter.h:65
DOTTraits DTraits
Definition GraphWriter.h:73
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

Member Function Documentation

◆ emitEdge()

template<typename GraphType >
void SVF::GraphWriter< GraphType >::emitEdge ( const void *  SrcNodeID,
int  SrcNodePort,
const void *  DestNodeID,
int  DestNodePort,
const std::string &  Attrs 
)
inline

emitEdge - Output an edge from a simple node into the graph...

Definition at line 307 of file GraphWriter.h.

310 {
311 if (SrcNodePort > 64) return; // Emanating from truncated part?
312 if (DestNodePort > 64) DestNodePort = 64; // Targeting the truncated part?
313
314 O << "\tNode" << SrcNodeID;
315 if (SrcNodePort >= 0)
316 O << ":s" << SrcNodePort;
317 O << " -> Node" << DestNodeID;
319 O << ":d" << DestNodePort;
320
321 if (!Attrs.empty())
322 O << "[" << Attrs << "]";
323 O << ";\n";
324 }

◆ emitSimpleNode()

template<typename GraphType >
void SVF::GraphWriter< GraphType >::emitSimpleNode ( const void *  ID,
const std::string &  Attr,
const std::string &  Label,
unsigned  NumEdgeSources = 0,
const std::vector< std::string > *  EdgeSourceLabels = nullptr 
)
inline

emitSimpleNode - Outputs a simple (non-record) node

Definition at line 281 of file GraphWriter.h.

284 {
285 O << "\tNode" << ID << "[ ";
286 if (!Attr.empty())
287 O << Attr << ",";
288 O << " label =\"";
289 if (NumEdgeSources) O << "{";
291 if (NumEdgeSources)
292 {
293 O << "|{";
294
295 for (unsigned i = 0; i != NumEdgeSources; ++i)
296 {
297 if (i) O << "|";
298 O << "<s" << i << ">";
300 }
301 O << "}}";
302 }
303 O << "\"];\n";
304 }
std::string EscapeStr(const std::string &Label)
GrammarBase::Symbol Label
Definition CFLSolver.h:42

◆ getEdgeSourceLabels()

template<typename GraphType >
bool SVF::GraphWriter< GraphType >::getEdgeSourceLabels ( std::stringstream &  O2,
NodeRef  Node 
)
inlineprivate

Definition at line 82 of file GraphWriter.h.

83 {
84 child_iterator EI = GTraits::child_begin(Node);
85 child_iterator EE = GTraits::child_end(Node);
86 bool hasEdgeSourceLabels = false;
87
88 for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
89 {
90 std::string label = DTraits.getEdgeSourceLabel(Node, EI);
91
92 if (label.empty())
93 continue;
94
96
97 if (i)
98 O2 << "|";
99
100 O2 << "<s" << i << ">" << DOT::EscapeStr(label);
101 }
102
103 if (EI != EE && hasEdgeSourceLabels)
104 O2 << "|<s64>truncated...";
105
106 return hasEdgeSourceLabels;
107 }
typename GTraits::ChildIteratorType child_iterator
Definition GraphWriter.h:72
static std::string getEdgeSourceLabel(const void *, EdgeIter)

◆ getOStream()

template<typename GraphType >
std::ofstream & SVF::GraphWriter< GraphType >::getOStream ( )
inline

getOStream - Get the raw output stream into the graph file. Useful to write fancy things using addCustomGraphFeatures().

Definition at line 328 of file GraphWriter.h.

329 {
330 return O;
331 }

◆ isNodeHidden()

template<typename GraphType >
bool SVF::GraphWriter< GraphType >::isNodeHidden ( NodeRef  Node)
inline

Definition at line 166 of file GraphWriter.h.

167 {
168 return DTraits.isNodeHidden(Node, G);
169 }
static bool isNodeHidden(const void *, const GraphType &)

◆ writeEdge()

template<typename GraphType >
void SVF::GraphWriter< GraphType >::writeEdge ( NodeRef  Node,
unsigned  edgeidx,
child_iterator  EI 
)
inline

Definition at line 256 of file GraphWriter.h.

257 {
258 if (NodeRef TargetNode = *EI)
259 {
260 int DestPort = -1;
262 {
264
265 // Figure out which edge this targets...
266 unsigned Offset =
267 (unsigned)std::distance(GTraits::child_begin(TargetNode), TargetIt);
268 DestPort = static_cast<int>(Offset);
269 }
270
271 if (DTraits.getEdgeSourceLabel(Node, EI).empty())
272 edgeidx = -1;
273
274 emitEdge(static_cast<const void*>(Node), edgeidx,
275 static_cast<const void*>(TargetNode), DestPort,
276 DTraits.getEdgeAttributes(Node, EI, G));
277 }
278 }
void emitEdge(const void *SrcNodeID, int SrcNodePort, const void *DestNodeID, int DestNodePort, const std::string &Attrs)
emitEdge - Output an edge from a simple node into the graph...
typename GTraits::NodeRef NodeRef
Definition GraphWriter.h:70
static bool edgeTargetsEdgeSource(const void *, EdgeIter)
static EdgeIter getEdgeTarget(const void *, EdgeIter I)
static std::string getEdgeAttributes(const void *, EdgeIter, const GraphType &)

◆ writeFooter()

template<typename GraphType >
void SVF::GraphWriter< GraphType >::writeFooter ( )
inline

Definition at line 152 of file GraphWriter.h.

153 {
154 // Finish off the graph
155 O << "}\n";
156 }

◆ writeGraph()

template<typename GraphType >
void SVF::GraphWriter< GraphType >::writeGraph ( const std::string &  Title = "")
inline

Definition at line 115 of file GraphWriter.h.

116 {
117 // Output the header for the graph...
119
120 // Emit all of the nodes in the graph...
121 writeNodes();
122
123 // Output any customizations on the graph
125
126 // Output the end of the graph
127 writeFooter();
128 }
void writeHeader(const std::string &Title)
static void addCustomGraphFeatures(const GraphType &, GraphWriter &)

◆ writeHeader()

template<typename GraphType >
void SVF::GraphWriter< GraphType >::writeHeader ( const std::string &  Title)
inline

Definition at line 130 of file GraphWriter.h.

131 {
132 std::string GraphName(DTraits.getGraphName(G));
133
134 if (!Title.empty())
135 O << "digraph \"" << DOT::EscapeStr(Title) << "\" {\n";
136 else if (!GraphName.empty())
137 O << "digraph \"" << DOT::EscapeStr(GraphName) << "\" {\n";
138 else
139 O << "digraph unnamed {\n";
140
142 O << "\trankdir=\"BT\";\n";
143
144 if (!Title.empty())
145 O << "\tlabel=\"" << DOT::EscapeStr(Title) << "\";\n";
146 else if (!GraphName.empty())
147 O << "\tlabel=\"" << DOT::EscapeStr(GraphName) << "\";\n";
149 O << "\n";
150 }
static std::string getGraphName(const GraphType &)
static bool renderGraphFromBottomUp()
static std::string getGraphProperties(const GraphType &)

◆ writeNode()

template<typename GraphType >
void SVF::GraphWriter< GraphType >::writeNode ( NodeRef  Node)
inline

Definition at line 171 of file GraphWriter.h.

172 {
173 std::string NodeAttributes = DTraits.getNodeAttributes(Node, G);
174
175 O << "\tNode" << static_cast<const void*>(Node) << " [";
176 if (!NodeAttributes.empty()) O << NodeAttributes << ",";
177 O << "label=\"{";
178
180 {
181 std::string label = DTraits.getNodeLabel(Node, G);
182 if (label.length() > Options::MaxNodeLabelLength())
183 {
184 label = label.substr(0, Options::MaxNodeLabelLength()) + "...";
185 }
186
188
189 // If we should include the address of the node in the label, do so now.
190 std::string Id = DTraits.getNodeIdentifierLabel(Node, G);
191 if (!Id.empty())
192 O << "|" << DOT::EscapeStr(Id);
193
194 std::string NodeDesc = DTraits.getNodeDescription(Node, G);
195 if (!NodeDesc.empty())
196 O << "|" << DOT::EscapeStr(NodeDesc);
197 }
198
199 std::string edgeSourceLabels;
200 std::stringstream EdgeSourceLabels(edgeSourceLabels);
202
204 {
205 if (!DTraits.renderGraphFromBottomUp()) O << "|";
206
207 O << "{" << EdgeSourceLabels.str() << "}";
208
209 if (DTraits.renderGraphFromBottomUp()) O << "|";
210 }
211
213 {
215
216 // If we should include the address of the node in the label, do so now.
217 std::string Id = DTraits.getNodeIdentifierLabel(Node, G);
218 if (!Id.empty())
219 O << "|" << DOT::EscapeStr(Id);
220
221 std::string NodeDesc = DTraits.getNodeDescription(Node, G);
222 if (!NodeDesc.empty())
223 O << "|" << DOT::EscapeStr(NodeDesc);
224 }
225
227 {
228 O << "|{";
229
230 unsigned i = 0, e = DTraits.numEdgeDestLabels(Node);
231 for (; i != e && i != 64; ++i)
232 {
233 if (i) O << "|";
234 O << "<d" << i << ">"
236 }
237
238 if (i != e)
239 O << "|<d64>truncated...";
240 O << "}";
241 }
242
243 O << "}\"];\n"; // Finish printing the "node" line
244
245 // Output all of the edges now
246 child_iterator EI = GTraits::child_begin(Node);
247 child_iterator EE = GTraits::child_end(Node);
248 for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
249 if (!DTraits.isNodeHidden(*EI, G))
250 writeEdge(Node, i, EI);
251 for (; EI != EE; ++EI)
252 if (!DTraits.isNodeHidden(*EI, G))
253 writeEdge(Node, 64, EI);
254 }
void writeEdge(NodeRef Node, unsigned edgeidx, child_iterator EI)
bool getEdgeSourceLabels(std::stringstream &O2, NodeRef Node)
Definition GraphWriter.h:82
static const Option< u32_t > MaxNodeLabelLength
Definition Options.h:270
std::string getNodeLabel(const void *, const GraphType &)
static std::string getNodeIdentifierLabel(const void *, const GraphType &)
static std::string getNodeAttributes(const void *, const GraphType &)
static std::string getEdgeDestLabel(const void *, unsigned)
static unsigned numEdgeDestLabels(const void *)
static std::string getNodeDescription(const void *, const GraphType &)

◆ writeNodes()

template<typename GraphType >
void SVF::GraphWriter< GraphType >::writeNodes ( )
inline

Definition at line 158 of file GraphWriter.h.

159 {
160 // Loop over the graph, printing it out...
161 for (const auto Node : nodes<GraphType>(G))
162 if (!isNodeHidden(Node))
163 writeNode(Node);
164 }
if(prebuffer< 0)
Definition cJSON.cpp:1269
void writeNode(NodeRef Node)
bool isNodeHidden(NodeRef Node)
iter_range< typename GenericGraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)

Member Data Documentation

◆ DTraits

template<typename GraphType >
DOTTraits SVF::GraphWriter< GraphType >::DTraits
private

Definition at line 73 of file GraphWriter.h.

◆ G

Definition at line 66 of file GraphWriter.h.

◆ O

template<typename GraphType >
std::ofstream& SVF::GraphWriter< GraphType >::O
private

Definition at line 65 of file GraphWriter.h.


The documentation for this class was generated from the following file: