LLVM API Documentation
00001 //===-- GraphWriter.cpp - Implements GraphWriter support routines ---------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements misc. GraphWriter support routines. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/Support/GraphWriter.h" 00015 #include "llvm/Support/Streams.h" 00016 #include "llvm/System/Path.h" 00017 #include "llvm/System/Program.h" 00018 #include "llvm/Config/config.h" 00019 using namespace llvm; 00020 00021 void llvm::DisplayGraph(const sys::Path &Filename) { 00022 std::string ErrMsg; 00023 #if HAVE_GRAPHVIZ 00024 sys::Path Graphviz(LLVM_PATH_GRAPHVIZ); 00025 00026 std::vector<const char*> args; 00027 args.push_back(Graphviz.c_str()); 00028 args.push_back(Filename.c_str()); 00029 args.push_back(0); 00030 00031 cerr << "Running 'Graphviz' program... " << std::flush; 00032 if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg)) { 00033 cerr << "Error viewing graph: " << ErrMsg << "\n"; 00034 } 00035 #elif (HAVE_GV && HAVE_DOT) 00036 sys::Path PSFilename = Filename; 00037 PSFilename.appendSuffix("ps"); 00038 00039 sys::Path dot(LLVM_PATH_DOT); 00040 00041 std::vector<const char*> args; 00042 args.push_back(dot.c_str()); 00043 args.push_back("-Tps"); 00044 args.push_back("-Nfontname=Courier"); 00045 args.push_back("-Gsize=7.5,10"); 00046 args.push_back(Filename.c_str()); 00047 args.push_back("-o"); 00048 args.push_back(PSFilename.c_str()); 00049 args.push_back(0); 00050 00051 cerr << "Running 'dot' program... " << std::flush; 00052 if (sys::Program::ExecuteAndWait(dot, &args[0],0,0,0,0,&ErrMsg)) { 00053 cerr << "Error viewing graph: '" << ErrMsg << "\n"; 00054 } else { 00055 cerr << " done. \n"; 00056 00057 sys::Path gv(LLVM_PATH_GV); 00058 args.clear(); 00059 args.push_back(gv.c_str()); 00060 args.push_back(PSFilename.c_str()); 00061 args.push_back("-spartan"); 00062 args.push_back(0); 00063 00064 ErrMsg.clear(); 00065 if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg)) { 00066 cerr << "Error viewing graph: " << ErrMsg << "\n"; 00067 } 00068 } 00069 PSFilename.eraseFromDisk(); 00070 #elif HAVE_DOTTY 00071 sys::Path dotty(LLVM_PATH_DOTTY); 00072 00073 std::vector<const char*> args; 00074 args.push_back(dotty.c_str()); 00075 args.push_back(Filename.c_str()); 00076 args.push_back(0); 00077 00078 cerr << "Running 'dotty' program... " << std::flush; 00079 if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,0,&ErrMsg)) { 00080 cerr << "Error viewing graph: " << ErrMsg << "\n"; 00081 } else { 00082 #ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns 00083 return; 00084 #endif 00085 } 00086 #endif 00087 00088 Filename.eraseFromDisk(); 00089 }