23 #ifndef LLVM_SUPPORT_GRAPHWRITER_H
24 #define LLVM_SUPPORT_GRAPHWRITER_H
43 namespace GraphProgram {
56 template<
typename GraphType>
61 typedef DOTGraphTraits<GraphType> DOTTraits;
62 typedef GraphTraits<GraphType> GTraits;
64 typedef typename GTraits::nodes_iterator node_iterator;
65 typedef typename GTraits::ChildIteratorType child_iterator;
70 bool getEdgeSourceLabels(raw_ostream &O, NodeType *Node) {
71 child_iterator EI = GTraits::child_begin(Node);
72 child_iterator EE = GTraits::child_end(Node);
73 bool hasEdgeSourceLabels =
false;
75 for (
unsigned i = 0; EI != EE && i != 64; ++EI, ++i) {
81 hasEdgeSourceLabels =
true;
89 if (EI != EE && hasEdgeSourceLabels)
90 O <<
"|<s64>truncated...";
92 return hasEdgeSourceLabels;
119 else if (!GraphName.empty())
122 O <<
"digraph unnamed {\n";
125 O <<
"\trankdir=\"BT\";\n";
129 else if (!GraphName.empty())
142 for (node_iterator
I = GTraits::nodes_begin(G), E = GTraits::nodes_end(G);
171 O <<
"\tNode" <<
static_cast<const void*
>(Node) <<
" [shape=record,";
172 if (!NodeAttributes.empty()) O << NodeAttributes <<
",";
180 O <<
"|" << static_cast<const void*>(Node);
183 if (!NodeDesc.empty())
187 std::string edgeSourceLabels;
189 bool hasEdgeSourceLabels = getEdgeSourceLabels(EdgeSourceLabels, Node);
191 if (hasEdgeSourceLabels) {
194 O <<
"{" << EdgeSourceLabels.
str() <<
"}";
204 O <<
"|" << static_cast<const void*>(Node);
207 if (!NodeDesc.empty())
215 for (; i != e && i != 64; ++i) {
217 O <<
"<d" << i <<
">"
222 O <<
"|<d64>truncated...";
229 child_iterator EI = GTraits::child_begin(Node);
230 child_iterator EE = GTraits::child_end(Node);
231 for (
unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
234 for (; EI != EE; ++EI)
239 void writeEdge(NodeType *Node,
unsigned edgeidx, child_iterator EI) {
240 if (NodeType *TargetNode = *EI) {
247 (
unsigned)std::distance(GTraits::child_begin(TargetNode), TargetIt);
248 DestPort =
static_cast<int>(Offset);
254 emitEdge(static_cast<const void*>(Node), edgeidx,
255 static_cast<const void*>(TargetNode), DestPort,
262 const std::string &Label,
unsigned NumEdgeSources = 0,
263 const std::vector<std::string> *EdgeSourceLabels = 0) {
264 O <<
"\tNode" << ID <<
"[ ";
268 if (NumEdgeSources) O <<
"{";
270 if (NumEdgeSources) {
273 for (
unsigned i = 0; i != NumEdgeSources; ++i) {
275 O <<
"<s" << i <<
">";
284 void emitEdge(
const void *SrcNodeID,
int SrcNodePort,
285 const void *DestNodeID,
int DestNodePort,
286 const std::string &Attrs) {
287 if (SrcNodePort > 64)
return;
288 if (DestNodePort > 64) DestNodePort = 64;
290 O <<
"\tNode" << SrcNodeID;
291 if (SrcNodePort >= 0)
292 O <<
":s" << SrcNodePort;
293 O <<
" -> Node" << DestNodeID;
295 O <<
":d" << DestNodePort;
298 O <<
"[" << Attrs <<
"]";
309 template<
typename GraphType>
311 bool ShortNames =
false,
312 const Twine &Title =
"") {
317 W.writeGraph(Title.str());
324 template <
typename GraphType>
326 bool ShortNames =
false,
const Twine &Title =
"") {
332 errs() <<
"error opening file '" << Filename <<
"' for writing!\n";
337 errs() <<
" done. \n";
345 template<
typename GraphType>
347 bool ShortNames =
false,
const Twine &Title =
"",
351 if (Filename.empty())
static std::string getNodeDescription(const void *, const GraphType &)
static EdgeIter getEdgeTarget(const void *, EdgeIter I)
void emitSimpleNode(const void *ID, const std::string &Attr, const std::string &Label, unsigned NumEdgeSources=0, const std::vector< std::string > *EdgeSourceLabels=0)
emitSimpleNode - Outputs a simple (non-record) node
bool isNodeHidden(NodeType *const *Node)
static void addCustomGraphFeatures(const GraphType &, GraphWriter &)
void writeNode(NodeType &Node)
void writeNode(NodeType *Node)
raw_ostream & WriteGraph(raw_ostream &O, const EdgeBundles &G, bool ShortNames=false, const Twine &Title="")
Specialize WriteGraph, the standard implementation won't work.
static std::string getEdgeAttributes(const void *, EdgeIter, const GraphType &)
raw_ostream & getOStream()
static std::string getEdgeSourceLabel(const void *, EdgeIter)
static bool hasEdgeDestLabels()
static unsigned numEdgeDestLabels(const void *)
static bool edgeTargetsEdgeSource(const void *, EdgeIter)
bool isNodeHidden(NodeType &Node)
GraphWriter(raw_ostream &o, const GraphType &g, bool SN)
ID
LLVM Calling Convention Representation.
std::string getNodeLabel(const void *, const GraphType &)
void writeNode(NodeType *const *Node)
std::string EscapeString(const std::string &Label)
void DisplayGraph(StringRef Filename, bool wait=true, GraphProgram::Name program=GraphProgram::DOT)
void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
GraphType::UnknownGraphTypeError NodeType
std::string createGraphFilename(const Twine &Name, int &FD)
static std::string getEdgeDestLabel(const void *, unsigned)
static std::string getGraphProperties(const GraphType &)
void writeHeader(const std::string &Title)
StringRef getColorString(unsigned NodeNumber)
Get a color string for this node number. Simply round-robin selects from a reasonable number of color...
static std::string getNodeAttributes(const void *, const GraphType &)
static bool isNodeHidden(const void *)
static bool hasNodeAddressLabel(const void *, const GraphType &)
void writeGraph(const std::string &Title="")
void writeEdge(NodeType *Node, unsigned edgeidx, child_iterator EI)
static bool renderGraphFromBottomUp()
static std::string getGraphName(const GraphType &)
bool isNodeHidden(NodeType *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...