SelectionDAGPrinter.cpp revision 66328480bb3eb6aa52e2c155657f3d19d4efea7a
1//===-- SelectionDAGPrinter.cpp - Implement SelectionDAG::viewGraph() -----===// 2// 3// The LLVM Compiler Infrastructure 4// 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. 7// 8//===----------------------------------------------------------------------===// 9// 10// This implements the SelectionDAG::viewGraph method. 11// 12//===----------------------------------------------------------------------===// 13 14#include "llvm/CodeGen/SelectionDAG.h" 15#include "llvm/CodeGen/MachineFunction.h" 16#include "llvm/Function.h" 17#include "llvm/Support/GraphWriter.h" 18#include <fstream> 19using namespace llvm; 20 21/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG 22/// rendered using 'dot'. 23/// 24void SelectionDAG::viewGraph() { 25 std::string Filename = "/tmp/dag." + 26 getMachineFunction().getFunction()->getName() + ".dot"; 27 std::cerr << "Writing '" << Filename << "'... "; 28 std::ofstream F(Filename.c_str()); 29 30 if (!F) { 31 std::cerr << " error opening file for writing!\n"; 32 return; 33 } 34 35 WriteGraph(F, this); 36 F.close(); 37 std::cerr << "\n"; 38 39 std::cerr << "Running 'dot' program... " << std::flush; 40 if (system(("dot -Tps -Nfontname=Courier -Gsize=7.5,10 " + Filename 41 + " > /tmp/dag.tempgraph.ps").c_str())) { 42 std::cerr << "Error running dot: 'dot' not in path?\n"; 43 } else { 44 std::cerr << "\n"; 45 system("gv /tmp/dag.tempgraph.ps"); 46 } 47 system(("rm " + Filename + " /tmp/dag.tempgraph.ps").c_str()); 48} 49