1 //===-- GraphWriter.cpp - Implements GraphWriter support routines ---------===//
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 file implements misc. GraphWriter support routines.
12 //===----------------------------------------------------------------------===//
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"
21 void llvm::DisplayGraph(const sys::Path &Filename) {
24 sys::Path Graphviz(LLVM_PATH_GRAPHVIZ);
26 std::vector<const char*> args;
27 args.push_back(Graphviz.c_str());
28 args.push_back(Filename.c_str());
31 cerr << "Running 'Graphviz' program... " << std::flush;
32 if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,&ErrMsg)) {
33 cerr << "Error viewing graph: " << ErrMsg << "\n";
35 #elif (HAVE_GV && HAVE_DOT)
36 sys::Path PSFilename = Filename;
37 PSFilename.appendSuffix("ps");
39 sys::Path dot(LLVM_PATH_DOT);
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());
48 args.push_back(PSFilename.c_str());
51 cerr << "Running 'dot' program... " << std::flush;
52 if (sys::Program::ExecuteAndWait(dot, &args[0],0,0,0,&ErrMsg)) {
53 cerr << "Error viewing graph: '" << ErrMsg << "\n";
57 sys::Path gv(LLVM_PATH_GV);
59 args.push_back(gv.c_str());
60 args.push_back(PSFilename.c_str());
64 if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,&ErrMsg)) {
65 cerr << "Error viewing graph: " << ErrMsg << "\n";
68 PSFilename.eraseFromDisk();
70 sys::Path dotty(LLVM_PATH_DOTTY);
72 std::vector<const char*> args;
73 args.push_back(Filename.c_str());
76 cerr << "Running 'dotty' program... " << std::flush;
77 if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,&ErrMsg)) {
78 cerr << "Error viewing graph: " << ErrMsg << "\n";
80 #ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns
86 Filename.eraseFromDisk();