GraphWriter.cpp revision 9ba8a76f8baaa1092d60ccfbc04e7efdc207c98f
1//===-- GraphWriter.cpp - Implements GraphWriter support routines ---------===// 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 file implements misc. GraphWriter support routines. 11// 12//===----------------------------------------------------------------------===// 13 14#include "llvm/Support/GraphWriter.h" 15#include "llvm/Support/Streams.h" 16#include "llvm/System/Path.h" 17#include "llvm/System/Program.h" 18#include "llvm/Config/config.h" 19using namespace llvm; 20 21void llvm::DisplayGraph(const sys::Path &Filename) { 22 std::string ErrMsg; 23#if HAVE_GRAPHVIZ 24 sys::Path Graphviz(LLVM_PATH_GRAPHVIZ); 25 26 std::vector<const char*> args; 27 args.push_back(Graphviz.c_str()); 28 args.push_back(Filename.c_str()); 29 args.push_back(0); 30 31 cerr << "Running 'Graphviz' program... " << std::flush; 32 if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg)) { 33 cerr << "Error viewing graph: " << ErrMsg << "\n"; 34 } 35#elif (HAVE_GV && HAVE_DOT) 36 sys::Path PSFilename = Filename; 37 PSFilename.appendSuffix("ps"); 38 39 sys::Path dot(LLVM_PATH_DOT); 40 41 std::vector<const char*> args; 42 args.push_back(dot.c_str()); 43 args.push_back("-Tps"); 44 args.push_back("-Nfontname=Courier"); 45 args.push_back("-Gsize=7.5,10"); 46 args.push_back(Filename.c_str()); 47 args.push_back("-o"); 48 args.push_back(PSFilename.c_str()); 49 args.push_back(0); 50 51 cerr << "Running 'dot' program... " << std::flush; 52 if (sys::Program::ExecuteAndWait(dot, &args[0],0,0,0,0,&ErrMsg)) { 53 cerr << "Error viewing graph: '" << ErrMsg << "\n"; 54 } else { 55 cerr << " done. \n"; 56 57 sys::Path gv(LLVM_PATH_GV); 58 args.clear(); 59 args.push_back(gv.c_str()); 60 args.push_back(PSFilename.c_str()); 61 args.push_back(0); 62 63 ErrMsg.clear(); 64 if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg)) { 65 cerr << "Error viewing graph: " << ErrMsg << "\n"; 66 } 67 } 68 PSFilename.eraseFromDisk(); 69#elif HAVE_DOTTY 70 sys::Path dotty(LLVM_PATH_DOTTY); 71 72 std::vector<const char*> args; 73 args.push_back(Filename.c_str()); 74 args.push_back(0); 75 76 cerr << "Running 'dotty' program... " << std::flush; 77 if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,0,&ErrMsg)) { 78 cerr << "Error viewing graph: " << ErrMsg << "\n"; 79 } else { 80#ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns 81 return; 82#endif 83 } 84#endif 85 86 Filename.eraseFromDisk(); 87} 88