1 //===-- SelectionDAGPrinter.cpp - Implement SelectionDAG::viewGraph() -----===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This implements the SelectionDAG::viewGraph method.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/SelectionDAG.h"
15 #include "llvm/CodeGen/MachineFunction.h"
16 #include "llvm/Function.h"
17 #include "llvm/Support/GraphWriter.h"
23 struct DOTGraphTraits<SelectionDAG*> : public DefaultDOTGraphTraits {
24 static std::string getGraphName(const SelectionDAG *G) {
25 return G->getMachineFunction().getFunction()->getName();
27 static std::string getNodeLabel(const SDNode *Node,
28 const SelectionDAG *Graph) {
29 return Node->getOperationName();
32 static std::string getNodeAttributes(const SDNode *N) {
33 return "shape=Mrecord";
36 static void addCustomGraphFeatures(SelectionDAG *G,
37 GraphWriter<SelectionDAG*> &GW) {
38 GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot");
39 GW.emitEdge(0, -1, G->getRoot().Val, -1, "");
44 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
45 /// rendered using 'dot'.
47 void SelectionDAG::viewGraph() {
48 std::string Filename = "/tmp/dag." +
49 getMachineFunction().getFunction()->getName() + ".dot";
50 std::cerr << "Writing '" << Filename << "'... ";
51 std::ofstream F(Filename.c_str());
54 std::cerr << " error opening file for writing!\n";
62 std::cerr << "Running 'dot' program... " << std::flush;
63 if (system(("dot -Tps -Nfontname=Courier -Gsize=7.5,10 " + Filename
64 + " > /tmp/dag.tempgraph.ps").c_str())) {
65 std::cerr << "Error running dot: 'dot' not in path?\n";
68 system("gv /tmp/dag.tempgraph.ps");
70 system(("rm " + Filename + " /tmp/dag.tempgraph.ps").c_str());