2004-09-01 22:55:40 +00:00
|
|
|
//===-- llvm/Support/GraphWriter.h - Write graph to a .dot file -*- C++ -*-===//
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2003-10-20 19:46:57 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2003-10-20 19:46:57 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-07 18:37:10 +00:00
|
|
|
//
|
|
|
|
// This file defines a simple interface that can be used to print out generic
|
|
|
|
// LLVM graphs to ".dot" files. "dot" is a tool that is part of the AT&T
|
|
|
|
// graphviz package (http://www.research.att.com/sw/tools/graphviz/) which can
|
|
|
|
// be used to turn the files output by this interface into a variety of
|
|
|
|
// different graphics formats.
|
|
|
|
//
|
|
|
|
// Graphs do not need to implement any interface past what is already required
|
|
|
|
// by the GraphTraits template, but they can choose to implement specializations
|
|
|
|
// of the DOTGraphTraits template if they want to customize the graphs output in
|
|
|
|
// any way.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#ifndef LLVM_SUPPORT_GRAPHWRITER_H
|
|
|
|
#define LLVM_SUPPORT_GRAPHWRITER_H
|
2002-10-07 18:37:10 +00:00
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/GraphTraits.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/Support/DOTGraphTraits.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/Path.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-07-08 21:53:41 +00:00
|
|
|
#include <cassert>
|
2012-12-03 17:02:12 +00:00
|
|
|
#include <vector>
|
2002-10-07 18:37:10 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2002-10-07 18:37:10 +00:00
|
|
|
namespace DOT { // Private functions...
|
2009-08-23 07:19:13 +00:00
|
|
|
std::string EscapeString(const std::string &Label);
|
2013-01-25 07:45:25 +00:00
|
|
|
|
|
|
|
/// \brief Get a color string for this node number. Simply round-robin selects
|
|
|
|
/// from a reasonable number of colors.
|
|
|
|
StringRef getColorString(unsigned NodeNumber);
|
2002-10-07 18:37:10 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 17:06:18 +00:00
|
|
|
namespace GraphProgram {
|
|
|
|
enum Name {
|
|
|
|
DOT,
|
|
|
|
FDP,
|
|
|
|
NEATO,
|
|
|
|
TWOPI,
|
|
|
|
CIRCO
|
|
|
|
};
|
|
|
|
}
|
2009-09-20 04:03:25 +00:00
|
|
|
|
2014-06-02 01:40:04 +00:00
|
|
|
bool DisplayGraph(StringRef Filename, bool wait = true,
|
2013-06-13 17:20:48 +00:00
|
|
|
GraphProgram::Name program = GraphProgram::DOT);
|
2013-06-13 16:56:13 +00:00
|
|
|
|
2002-10-07 18:37:10 +00:00
|
|
|
template<typename GraphType>
|
2002-10-16 01:34:18 +00:00
|
|
|
class GraphWriter {
|
2009-08-23 07:19:13 +00:00
|
|
|
raw_ostream &O;
|
2002-10-16 01:34:18 +00:00
|
|
|
const GraphType &G;
|
2002-10-07 18:37:10 +00:00
|
|
|
|
2002-10-16 01:34:18 +00:00
|
|
|
typedef DOTGraphTraits<GraphType> DOTTraits;
|
|
|
|
typedef GraphTraits<GraphType> GTraits;
|
|
|
|
typedef typename GTraits::NodeType NodeType;
|
|
|
|
typedef typename GTraits::nodes_iterator node_iterator;
|
|
|
|
typedef typename GTraits::ChildIteratorType child_iterator;
|
2009-11-30 12:38:13 +00:00
|
|
|
DOTTraits DTraits;
|
2009-11-30 12:24:40 +00:00
|
|
|
|
|
|
|
// Writes the edge labels of the node to O and returns true if there are any
|
|
|
|
// edge labels not equal to the empty string "".
|
|
|
|
bool getEdgeSourceLabels(raw_ostream &O, NodeType *Node) {
|
|
|
|
child_iterator EI = GTraits::child_begin(Node);
|
|
|
|
child_iterator EE = GTraits::child_end(Node);
|
|
|
|
bool hasEdgeSourceLabels = false;
|
|
|
|
|
|
|
|
for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i) {
|
2009-11-30 12:38:13 +00:00
|
|
|
std::string label = DTraits.getEdgeSourceLabel(Node, EI);
|
2009-11-30 12:24:40 +00:00
|
|
|
|
2011-03-01 22:07:55 +00:00
|
|
|
if (label.empty())
|
2009-11-30 12:24:40 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
hasEdgeSourceLabels = true;
|
|
|
|
|
|
|
|
if (i)
|
|
|
|
O << "|";
|
|
|
|
|
2011-03-01 22:12:24 +00:00
|
|
|
O << "<s" << i << ">" << DOT::EscapeString(label);
|
2009-11-30 12:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EI != EE && hasEdgeSourceLabels)
|
|
|
|
O << "|<s64>truncated...";
|
|
|
|
|
|
|
|
return hasEdgeSourceLabels;
|
|
|
|
}
|
|
|
|
|
2002-10-16 01:34:18 +00:00
|
|
|
public:
|
2009-11-30 12:38:47 +00:00
|
|
|
GraphWriter(raw_ostream &o, const GraphType &g, bool SN) : O(o), G(g) {
|
2010-09-27 14:44:14 +00:00
|
|
|
DTraits = DOTTraits(SN);
|
|
|
|
}
|
2002-10-17 00:59:59 +00:00
|
|
|
|
2010-09-27 16:59:51 +00:00
|
|
|
void writeGraph(const std::string &Title = "") {
|
2010-09-27 16:44:11 +00:00
|
|
|
// Output the header for the graph...
|
2010-09-27 16:54:13 +00:00
|
|
|
writeHeader(Title);
|
2010-09-27 16:44:11 +00:00
|
|
|
|
|
|
|
// Emit all of the nodes in the graph...
|
2010-09-27 16:54:13 +00:00
|
|
|
writeNodes();
|
2010-09-27 16:44:11 +00:00
|
|
|
|
|
|
|
// Output any customizations on the graph
|
2010-09-27 16:54:13 +00:00
|
|
|
DOTGraphTraits<GraphType>::addCustomGraphFeatures(G, *this);
|
2010-09-27 16:44:11 +00:00
|
|
|
|
|
|
|
// Output the end of the graph
|
2010-09-27 16:54:13 +00:00
|
|
|
writeFooter();
|
2010-09-27 16:44:11 +00:00
|
|
|
}
|
|
|
|
|
2010-09-27 15:34:19 +00:00
|
|
|
void writeHeader(const std::string &Title) {
|
2009-11-30 12:38:13 +00:00
|
|
|
std::string GraphName = DTraits.getGraphName(G);
|
2008-07-08 23:33:46 +00:00
|
|
|
|
2010-09-27 15:34:19 +00:00
|
|
|
if (!Title.empty())
|
|
|
|
O << "digraph \"" << DOT::EscapeString(Title) << "\" {\n";
|
2008-07-08 23:33:46 +00:00
|
|
|
else if (!GraphName.empty())
|
2008-07-10 19:55:54 +00:00
|
|
|
O << "digraph \"" << DOT::EscapeString(GraphName) << "\" {\n";
|
2008-07-08 23:33:46 +00:00
|
|
|
else
|
|
|
|
O << "digraph unnamed {\n";
|
2002-10-07 18:37:10 +00:00
|
|
|
|
2009-11-30 12:38:13 +00:00
|
|
|
if (DTraits.renderGraphFromBottomUp())
|
2005-01-11 00:24:59 +00:00
|
|
|
O << "\trankdir=\"BT\";\n";
|
|
|
|
|
2010-09-27 15:34:19 +00:00
|
|
|
if (!Title.empty())
|
|
|
|
O << "\tlabel=\"" << DOT::EscapeString(Title) << "\";\n";
|
2008-07-21 19:57:57 +00:00
|
|
|
else if (!GraphName.empty())
|
2002-10-16 01:34:18 +00:00
|
|
|
O << "\tlabel=\"" << DOT::EscapeString(GraphName) << "\";\n";
|
2009-11-30 12:38:13 +00:00
|
|
|
O << DTraits.getGraphProperties(G);
|
2002-10-16 01:34:18 +00:00
|
|
|
O << "\n";
|
|
|
|
}
|
|
|
|
|
2002-10-17 00:59:59 +00:00
|
|
|
void writeFooter() {
|
2002-10-16 01:34:18 +00:00
|
|
|
// Finish off the graph
|
|
|
|
O << "}\n";
|
|
|
|
}
|
2002-10-07 18:37:10 +00:00
|
|
|
|
2002-10-16 01:34:18 +00:00
|
|
|
void writeNodes() {
|
|
|
|
// Loop over the graph, printing it out...
|
|
|
|
for (node_iterator I = GTraits::nodes_begin(G), E = GTraits::nodes_end(G);
|
|
|
|
I != E; ++I)
|
2010-05-14 15:29:31 +00:00
|
|
|
if (!isNodeHidden(*I))
|
|
|
|
writeNode(*I);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNodeHidden(NodeType &Node) {
|
|
|
|
return isNodeHidden(&Node);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNodeHidden(NodeType *const *Node) {
|
|
|
|
return isNodeHidden(*Node);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNodeHidden(NodeType *Node) {
|
|
|
|
return DTraits.isNodeHidden(Node);
|
2007-09-19 21:26:49 +00:00
|
|
|
}
|
2009-02-20 22:51:36 +00:00
|
|
|
|
2007-09-19 21:26:49 +00:00
|
|
|
void writeNode(NodeType& Node) {
|
|
|
|
writeNode(&Node);
|
2002-10-16 01:34:18 +00:00
|
|
|
}
|
2005-04-21 20:48:15 +00:00
|
|
|
|
2005-01-10 23:05:07 +00:00
|
|
|
void writeNode(NodeType *const *Node) {
|
|
|
|
writeNode(*Node);
|
|
|
|
}
|
2005-04-21 20:48:15 +00:00
|
|
|
|
2002-10-16 01:34:18 +00:00
|
|
|
void writeNode(NodeType *Node) {
|
2009-11-30 12:38:13 +00:00
|
|
|
std::string NodeAttributes = DTraits.getNodeAttributes(Node, G);
|
2005-04-21 20:48:15 +00:00
|
|
|
|
2008-07-27 23:12:19 +00:00
|
|
|
O << "\tNode" << static_cast<const void*>(Node) << " [shape=record,";
|
2002-10-07 18:37:10 +00:00
|
|
|
if (!NodeAttributes.empty()) O << NodeAttributes << ",";
|
2005-01-11 00:24:59 +00:00
|
|
|
O << "label=\"{";
|
|
|
|
|
2009-11-30 12:38:13 +00:00
|
|
|
if (!DTraits.renderGraphFromBottomUp()) {
|
2009-11-30 12:38:47 +00:00
|
|
|
O << DOT::EscapeString(DTraits.getNodeLabel(Node, G));
|
2005-04-21 20:48:15 +00:00
|
|
|
|
2005-10-01 00:19:21 +00:00
|
|
|
// If we should include the address of the node in the label, do so now.
|
2009-11-30 12:38:13 +00:00
|
|
|
if (DTraits.hasNodeAddressLabel(Node, G))
|
2012-07-19 04:50:12 +00:00
|
|
|
O << "|" << static_cast<const void*>(Node);
|
2013-01-25 07:45:25 +00:00
|
|
|
|
|
|
|
std::string NodeDesc = DTraits.getNodeDescription(Node, G);
|
|
|
|
if (!NodeDesc.empty())
|
|
|
|
O << "|" << DOT::EscapeString(NodeDesc);
|
2005-10-01 00:19:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:52:05 +00:00
|
|
|
std::string edgeSourceLabels;
|
|
|
|
raw_string_ostream EdgeSourceLabels(edgeSourceLabels);
|
2009-11-30 12:24:40 +00:00
|
|
|
bool hasEdgeSourceLabels = getEdgeSourceLabels(EdgeSourceLabels, Node);
|
|
|
|
|
|
|
|
if (hasEdgeSourceLabels) {
|
2009-11-30 12:38:13 +00:00
|
|
|
if (!DTraits.renderGraphFromBottomUp()) O << "|";
|
2005-04-21 20:48:15 +00:00
|
|
|
|
2009-11-30 12:24:40 +00:00
|
|
|
O << "{" << EdgeSourceLabels.str() << "}";
|
2005-04-21 20:48:15 +00:00
|
|
|
|
2009-11-30 12:38:13 +00:00
|
|
|
if (DTraits.renderGraphFromBottomUp()) O << "|";
|
2002-10-07 18:37:10 +00:00
|
|
|
}
|
2005-10-01 00:19:21 +00:00
|
|
|
|
2009-11-30 12:38:13 +00:00
|
|
|
if (DTraits.renderGraphFromBottomUp()) {
|
2009-11-30 12:38:47 +00:00
|
|
|
O << DOT::EscapeString(DTraits.getNodeLabel(Node, G));
|
2005-04-21 20:48:15 +00:00
|
|
|
|
2005-10-01 00:19:21 +00:00
|
|
|
// If we should include the address of the node in the label, do so now.
|
2009-11-30 12:38:13 +00:00
|
|
|
if (DTraits.hasNodeAddressLabel(Node, G))
|
2012-07-19 04:50:12 +00:00
|
|
|
O << "|" << static_cast<const void*>(Node);
|
2013-01-25 07:45:25 +00:00
|
|
|
|
|
|
|
std::string NodeDesc = DTraits.getNodeDescription(Node, G);
|
|
|
|
if (!NodeDesc.empty())
|
|
|
|
O << "|" << DOT::EscapeString(NodeDesc);
|
2005-10-01 00:19:21 +00:00
|
|
|
}
|
|
|
|
|
2009-11-30 12:38:13 +00:00
|
|
|
if (DTraits.hasEdgeDestLabels()) {
|
2008-07-21 21:06:55 +00:00
|
|
|
O << "|{";
|
|
|
|
|
2009-11-30 12:38:13 +00:00
|
|
|
unsigned i = 0, e = DTraits.numEdgeDestLabels(Node);
|
2008-07-21 21:06:55 +00:00
|
|
|
for (; i != e && i != 64; ++i) {
|
|
|
|
if (i) O << "|";
|
2010-04-30 18:27:57 +00:00
|
|
|
O << "<d" << i << ">"
|
|
|
|
<< DOT::EscapeString(DTraits.getEdgeDestLabel(Node, i));
|
2008-07-21 21:06:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i != e)
|
|
|
|
O << "|<d64>truncated...";
|
|
|
|
O << "}";
|
|
|
|
}
|
|
|
|
|
2005-09-30 19:33:41 +00:00
|
|
|
O << "}\"];\n"; // Finish printing the "node" line
|
2005-04-21 20:48:15 +00:00
|
|
|
|
2002-10-07 18:37:10 +00:00
|
|
|
// Output all of the edges now
|
2009-11-30 12:24:40 +00:00
|
|
|
child_iterator EI = GTraits::child_begin(Node);
|
|
|
|
child_iterator EE = GTraits::child_end(Node);
|
2002-10-16 01:34:18 +00:00
|
|
|
for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
|
2010-05-14 15:29:31 +00:00
|
|
|
if (!DTraits.isNodeHidden(*EI))
|
|
|
|
writeEdge(Node, i, EI);
|
2004-02-11 20:44:17 +00:00
|
|
|
for (; EI != EE; ++EI)
|
2010-05-14 15:29:31 +00:00
|
|
|
if (!DTraits.isNodeHidden(*EI))
|
|
|
|
writeEdge(Node, 64, EI);
|
2002-10-16 01:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void writeEdge(NodeType *Node, unsigned edgeidx, child_iterator EI) {
|
|
|
|
if (NodeType *TargetNode = *EI) {
|
2002-10-16 02:03:18 +00:00
|
|
|
int DestPort = -1;
|
2009-11-30 12:38:13 +00:00
|
|
|
if (DTraits.edgeTargetsEdgeSource(Node, EI)) {
|
|
|
|
child_iterator TargetIt = DTraits.getEdgeTarget(Node, EI);
|
2002-10-16 01:34:18 +00:00
|
|
|
|
|
|
|
// Figure out which edge this targets...
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned Offset =
|
|
|
|
(unsigned)std::distance(GTraits::child_begin(TargetNode), TargetIt);
|
2003-11-16 20:21:15 +00:00
|
|
|
DestPort = static_cast<int>(Offset);
|
2002-10-07 18:37:10 +00:00
|
|
|
}
|
2002-10-16 02:03:18 +00:00
|
|
|
|
2011-03-01 22:07:55 +00:00
|
|
|
if (DTraits.getEdgeSourceLabel(Node, EI).empty())
|
2009-11-30 12:24:40 +00:00
|
|
|
edgeidx = -1;
|
|
|
|
|
2008-07-27 23:12:19 +00:00
|
|
|
emitEdge(static_cast<const void*>(Node), edgeidx,
|
|
|
|
static_cast<const void*>(TargetNode), DestPort,
|
2011-02-27 04:11:03 +00:00
|
|
|
DTraits.getEdgeAttributes(Node, EI, G));
|
2002-10-07 18:37:10 +00:00
|
|
|
}
|
|
|
|
}
|
2002-10-16 02:03:18 +00:00
|
|
|
|
|
|
|
/// emitSimpleNode - Outputs a simple (non-record) node
|
2002-10-16 20:15:38 +00:00
|
|
|
void emitSimpleNode(const void *ID, const std::string &Attr,
|
2014-04-07 04:17:22 +00:00
|
|
|
const std::string &Label, unsigned NumEdgeSources = 0,
|
|
|
|
const std::vector<std::string> *EdgeSourceLabels = nullptr) {
|
2002-10-16 02:03:18 +00:00
|
|
|
O << "\tNode" << ID << "[ ";
|
|
|
|
if (!Attr.empty())
|
|
|
|
O << Attr << ",";
|
2002-10-18 14:55:44 +00:00
|
|
|
O << " label =\"";
|
|
|
|
if (NumEdgeSources) O << "{";
|
|
|
|
O << DOT::EscapeString(Label);
|
2002-10-16 20:15:38 +00:00
|
|
|
if (NumEdgeSources) {
|
|
|
|
O << "|{";
|
2005-04-21 20:48:15 +00:00
|
|
|
|
2002-10-16 20:15:38 +00:00
|
|
|
for (unsigned i = 0; i != NumEdgeSources; ++i) {
|
|
|
|
if (i) O << "|";
|
2009-07-23 15:24:38 +00:00
|
|
|
O << "<s" << i << ">";
|
2010-04-30 18:27:57 +00:00
|
|
|
if (EdgeSourceLabels) O << DOT::EscapeString((*EdgeSourceLabels)[i]);
|
2002-10-16 20:15:38 +00:00
|
|
|
}
|
2002-10-18 14:55:44 +00:00
|
|
|
O << "}}";
|
2002-10-16 20:15:38 +00:00
|
|
|
}
|
2002-10-18 14:55:44 +00:00
|
|
|
O << "\"];\n";
|
2002-10-16 02:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// emitEdge - Output an edge from a simple node into the graph...
|
2002-10-16 20:15:38 +00:00
|
|
|
void emitEdge(const void *SrcNodeID, int SrcNodePort,
|
|
|
|
const void *DestNodeID, int DestNodePort,
|
|
|
|
const std::string &Attrs) {
|
2002-11-10 06:47:03 +00:00
|
|
|
if (SrcNodePort > 64) return; // Eminating from truncated part?
|
2011-04-15 05:18:47 +00:00
|
|
|
if (DestNodePort > 64) DestNodePort = 64; // Targeting the truncated part?
|
2002-11-10 06:47:03 +00:00
|
|
|
|
2002-10-16 02:03:18 +00:00
|
|
|
O << "\tNode" << SrcNodeID;
|
|
|
|
if (SrcNodePort >= 0)
|
2008-07-21 21:06:55 +00:00
|
|
|
O << ":s" << SrcNodePort;
|
2008-07-27 23:12:19 +00:00
|
|
|
O << " -> Node" << DestNodeID;
|
2009-11-30 12:38:13 +00:00
|
|
|
if (DestNodePort >= 0 && DTraits.hasEdgeDestLabels())
|
2009-11-30 12:37:39 +00:00
|
|
|
O << ":d" << DestNodePort;
|
2002-10-16 02:03:18 +00:00
|
|
|
|
|
|
|
if (!Attrs.empty())
|
|
|
|
O << "[" << Attrs << "]";
|
|
|
|
O << ";\n";
|
|
|
|
}
|
2010-07-22 07:46:31 +00:00
|
|
|
|
|
|
|
/// getOStream - Get the raw output stream into the graph file. Useful to
|
|
|
|
/// write fancy things using addCustomGraphFeatures().
|
|
|
|
raw_ostream &getOStream() {
|
|
|
|
return O;
|
|
|
|
}
|
2002-10-16 01:34:18 +00:00
|
|
|
};
|
2002-10-07 18:37:10 +00:00
|
|
|
|
2002-10-16 01:34:18 +00:00
|
|
|
template<typename GraphType>
|
2009-08-23 07:19:13 +00:00
|
|
|
raw_ostream &WriteGraph(raw_ostream &O, const GraphType &G,
|
|
|
|
bool ShortNames = false,
|
2011-11-15 16:26:38 +00:00
|
|
|
const Twine &Title = "") {
|
2002-10-16 01:34:18 +00:00
|
|
|
// Start the graph emission process...
|
2009-06-24 17:37:09 +00:00
|
|
|
GraphWriter<GraphType> W(O, G, ShortNames);
|
2002-10-17 00:59:59 +00:00
|
|
|
|
2010-09-27 16:44:11 +00:00
|
|
|
// Emit the graph.
|
2011-11-15 16:26:38 +00:00
|
|
|
W.writeGraph(Title.str());
|
2002-10-17 00:59:59 +00:00
|
|
|
|
2002-10-07 18:37:10 +00:00
|
|
|
return O;
|
|
|
|
}
|
|
|
|
|
2013-06-14 16:43:15 +00:00
|
|
|
std::string createGraphFilename(const Twine &Name, int &FD);
|
2006-08-23 20:34:57 +00:00
|
|
|
|
2013-06-13 17:20:48 +00:00
|
|
|
template <typename GraphType>
|
|
|
|
std::string WriteGraph(const GraphType &G, const Twine &Name,
|
|
|
|
bool ShortNames = false, const Twine &Title = "") {
|
2013-06-14 16:43:15 +00:00
|
|
|
int FD;
|
2014-05-22 23:32:18 +00:00
|
|
|
// Windows can't always handle long paths, so limit the length of the name.
|
|
|
|
std::string N = Name.str();
|
|
|
|
N = N.substr(0, std::min<std::size_t>(N.size(), 140));
|
|
|
|
std::string Filename = createGraphFilename(N, FD);
|
2013-06-14 16:43:15 +00:00
|
|
|
raw_fd_ostream O(FD, /*shouldClose=*/ true);
|
2011-01-17 17:34:43 +00:00
|
|
|
|
2013-06-14 16:43:15 +00:00
|
|
|
if (FD == -1) {
|
2013-06-13 17:20:48 +00:00
|
|
|
errs() << "error opening file '" << Filename << "' for writing!\n";
|
|
|
|
return "";
|
2011-01-17 17:34:43 +00:00
|
|
|
}
|
2009-02-20 22:51:36 +00:00
|
|
|
|
2013-06-14 16:43:15 +00:00
|
|
|
llvm::WriteGraph(O, G, ShortNames, Title);
|
|
|
|
errs() << " done. \n";
|
|
|
|
|
2011-01-17 17:34:43 +00:00
|
|
|
return Filename;
|
2006-06-27 16:49:46 +00:00
|
|
|
}
|
2009-02-20 22:51:36 +00:00
|
|
|
|
2006-06-27 16:49:46 +00:00
|
|
|
/// ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file,
|
|
|
|
/// then cleanup. For use from the debugger.
|
|
|
|
///
|
|
|
|
template<typename GraphType>
|
2011-11-15 16:26:38 +00:00
|
|
|
void ViewGraph(const GraphType &G, const Twine &Name,
|
|
|
|
bool ShortNames = false, const Twine &Title = "",
|
2009-07-09 17:06:18 +00:00
|
|
|
GraphProgram::Name Program = GraphProgram::DOT) {
|
2013-06-13 17:20:48 +00:00
|
|
|
std::string Filename = llvm::WriteGraph(G, Name, ShortNames, Title);
|
2006-06-27 16:49:46 +00:00
|
|
|
|
2013-06-13 17:20:48 +00:00
|
|
|
if (Filename.empty())
|
2006-06-27 16:49:46 +00:00
|
|
|
return;
|
2009-02-20 22:51:36 +00:00
|
|
|
|
2009-07-09 17:06:18 +00:00
|
|
|
DisplayGraph(Filename, true, Program);
|
2006-06-27 16:49:46 +00:00
|
|
|
}
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-10-07 18:37:10 +00:00
|
|
|
#endif
|