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 109 of file GraphWriter.h.

109 : O(o), G(g)
110 {
112 }
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 306 of file GraphWriter.h.

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

◆ 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 280 of file GraphWriter.h.

283 {
284 O << "\tNode" << ID << "[ ";
285 if (!Attr.empty())
286 O << Attr << ",";
287 O << " label =\"";
288 if (NumEdgeSources) O << "{";
290 if (NumEdgeSources)
291 {
292 O << "|{";
293
294 for (unsigned i = 0; i != NumEdgeSources; ++i)
295 {
296 if (i) O << "|";
297 O << "<s" << i << ">";
299 }
300 O << "}}";
301 }
302 O << "\"];\n";
303 }
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 81 of file GraphWriter.h.

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

328 {
329 return O;
330 }

◆ isNodeHidden()

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

Definition at line 165 of file GraphWriter.h.

166 {
167 return DTraits.isNodeHidden(Node, G);
168 }
static bool isNodeHidden(NodeT, const GraphType &)

◆ writeEdge()

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

Definition at line 255 of file GraphWriter.h.

256 {
257 if (NodeRef TargetNode = *EI)
258 {
259 int DestPort = -1;
261 {
263
264 // Figure out which edge this targets...
265 unsigned Offset =
266 (unsigned)std::distance(GTraits::child_begin(TargetNode), TargetIt);
267 DestPort = static_cast<int>(Offset);
268 }
269
270 if (DTraits.getEdgeSourceLabel(Node, EI).empty())
271 edgeidx = -1;
272
275 DTraits.getEdgeAttributes(Node, EI, G));
276 }
277 }
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 EdgeIter getEdgeTarget(NodeT, EdgeIter I)
static const void * getNodeIdentifier(NodeT N)
static std::string getEdgeAttributes(NodeT, EdgeIter, const GraphType &)
static bool edgeTargetsEdgeSource(NodeT, EdgeIter)

◆ writeFooter()

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

Definition at line 151 of file GraphWriter.h.

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

◆ writeGraph()

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

Definition at line 114 of file GraphWriter.h.

115 {
116 // Output the header for the graph...
118
119 // Emit all of the nodes in the graph...
120 writeNodes();
121
122 // Output any customizations on the graph
124
125 // Output the end of the graph
126 writeFooter();
127 }
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 129 of file GraphWriter.h.

130 {
131 std::string GraphName(DTraits.getGraphName(G));
132
133 if (!Title.empty())
134 O << "digraph \"" << DOT::EscapeStr(Title) << "\" {\n";
135 else if (!GraphName.empty())
136 O << "digraph \"" << DOT::EscapeStr(GraphName) << "\" {\n";
137 else
138 O << "digraph unnamed {\n";
139
141 O << "\trankdir=\"BT\";\n";
142
143 if (!Title.empty())
144 O << "\tlabel=\"" << DOT::EscapeStr(Title) << "\";\n";
145 else if (!GraphName.empty())
146 O << "\tlabel=\"" << DOT::EscapeStr(GraphName) << "\";\n";
148 O << "\n";
149 }
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 170 of file GraphWriter.h.

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

◆ writeNodes()

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

Definition at line 157 of file GraphWriter.h.

158 {
159 // Loop over the graph, printing it out...
160 for (const auto Node : nodes<GraphType>(G))
161 if (!isNodeHidden(Node))
162 writeNode(Node);
163 }
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: