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 GraphType & G
 
DOTTraits DTraits
 

Detailed Description

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

Definition at line 62 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 71 of file GraphWriter.h.

◆ DOTTraits

template<typename GraphType >
using SVF::GraphWriter< GraphType >::DOTTraits = DOTGraphTraits<GraphType>
private

Definition at line 67 of file GraphWriter.h.

◆ GTraits

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

Definition at line 68 of file GraphWriter.h.

◆ node_iterator

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

Definition at line 70 of file GraphWriter.h.

◆ NodeRef

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

Definition at line 69 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:65
DOTGraphTraits< GraphType > DOTTraits
Definition GraphWriter.h:67
std::ofstream & O
Definition GraphWriter.h:64
DOTTraits DTraits
Definition GraphWriter.h:72
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

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

303 {
304 if (SrcNodePort > 64) return; // Emanating from truncated part?
305 if (DestNodePort > 64) DestNodePort = 64; // Targeting the truncated part?
306
307 O << "\tNode" << SrcNodeID;
308 if (SrcNodePort >= 0)
309 O << ":s" << SrcNodePort;
310 O << " -> Node" << DestNodeID;
312 O << ":d" << DestNodePort;
313
314 if (!Attrs.empty())
315 O << "[" << Attrs << "]";
316 O << ";\n";
317 }

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

277 {
278 O << "\tNode" << ID << "[ ";
279 if (!Attr.empty())
280 O << Attr << ",";
281 O << " label =\"";
282 if (NumEdgeSources) O << "{";
284 if (NumEdgeSources)
285 {
286 O << "|{";
287
288 for (unsigned i = 0; i != NumEdgeSources; ++i)
289 {
290 if (i) O << "|";
291 O << "<s" << i << ">";
293 }
294 O << "}}";
295 }
296 O << "\"];\n";
297 }
std::string EscapeStr(const std::string &Label)
GrammarBase::Symbol Label
Definition CFLSolver.h:41

◆ 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:71
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 321 of file GraphWriter.h.

322 {
323 return O;
324 }

◆ 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(const void *, const GraphType &)

◆ writeEdge()

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

Definition at line 249 of file GraphWriter.h.

250 {
251 if (NodeRef TargetNode = *EI)
252 {
253 int DestPort = -1;
255 {
257
258 // Figure out which edge this targets...
259 unsigned Offset =
260 (unsigned)std::distance(GTraits::child_begin(TargetNode), TargetIt);
261 DestPort = static_cast<int>(Offset);
262 }
263
264 if (DTraits.getEdgeSourceLabel(Node, EI).empty())
265 edgeidx = -1;
266
267 emitEdge(static_cast<const void*>(Node), edgeidx,
268 static_cast<const void*>(TargetNode), DestPort,
269 DTraits.getEdgeAttributes(Node, EI, G));
270 }
271 }
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:69
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 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" << static_cast<const void*>(Node) << " [shape=record,";
175 if (!NodeAttributes.empty()) O << NodeAttributes << ",";
176 O << "label=\"{";
177
179 {
181
182 // If we should include the address of the node in the label, do so now.
183 std::string Id = DTraits.getNodeIdentifierLabel(Node, G);
184 if (!Id.empty())
185 O << "|" << DOT::EscapeStr(Id);
186
187 std::string NodeDesc = DTraits.getNodeDescription(Node, G);
188 if (!NodeDesc.empty())
189 O << "|" << DOT::EscapeStr(NodeDesc);
190 }
191
192 std::string edgeSourceLabels;
193 std::stringstream EdgeSourceLabels(edgeSourceLabels);
195
197 {
198 if (!DTraits.renderGraphFromBottomUp()) O << "|";
199
200 O << "{" << EdgeSourceLabels.str() << "}";
201
202 if (DTraits.renderGraphFromBottomUp()) O << "|";
203 }
204
206 {
208
209 // If we should include the address of the node in the label, do so now.
210 std::string Id = DTraits.getNodeIdentifierLabel(Node, G);
211 if (!Id.empty())
212 O << "|" << DOT::EscapeStr(Id);
213
214 std::string NodeDesc = DTraits.getNodeDescription(Node, G);
215 if (!NodeDesc.empty())
216 O << "|" << DOT::EscapeStr(NodeDesc);
217 }
218
220 {
221 O << "|{";
222
223 unsigned i = 0, e = DTraits.numEdgeDestLabels(Node);
224 for (; i != e && i != 64; ++i)
225 {
226 if (i) O << "|";
227 O << "<d" << i << ">"
229 }
230
231 if (i != e)
232 O << "|<d64>truncated...";
233 O << "}";
234 }
235
236 O << "}\"];\n"; // Finish printing the "node" line
237
238 // Output all of the edges now
239 child_iterator EI = GTraits::child_begin(Node);
240 child_iterator EE = GTraits::child_end(Node);
241 for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
242 if (!DTraits.isNodeHidden(*EI, G))
243 writeEdge(Node, i, EI);
244 for (; EI != EE; ++EI)
245 if (!DTraits.isNodeHidden(*EI, G))
246 writeEdge(Node, 64, EI);
247 }
void writeEdge(NodeRef Node, unsigned edgeidx, child_iterator EI)
bool getEdgeSourceLabels(std::stringstream &O2, NodeRef Node)
Definition GraphWriter.h:81
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 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 72 of file GraphWriter.h.

◆ G

template<typename GraphType >
const GraphType& SVF::GraphWriter< GraphType >::G
private

Definition at line 65 of file GraphWriter.h.

◆ O

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

Definition at line 64 of file GraphWriter.h.


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