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