Reverting back to original 1.8 version so I can manually merge in patch.
[llvm-complete.git] / lib / Support / GraphWriter.cpp
blobf3255d815c6c7659934069dba8c1419686c629a8
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.
12 //===----------------------------------------------------------------------===//
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;
21 void llvm::DisplayGraph(const sys::Path &Filename) {
22 #if HAVE_GRAPHVIZ
23 sys::Path Graphviz(LLVM_PATH_GRAPHVIZ);
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);
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";
34 #elif (HAVE_GV && HAVE_DOT)
35 sys::Path PSFilename = Filename;
36 PSFilename.appendSuffix("ps");
38 sys::Path dot(LLVM_PATH_DOT);
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);
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";
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);
62 sys::Program::ExecuteAndWait(gv, &args[0]);
64 PSFilename.eraseFromDisk();
65 #elif HAVE_DOTTY
66 sys::Path dotty(LLVM_PATH_DOTTY);
68 std::vector<const char*> args;
69 args.push_back(Filename.c_str());
70 args.push_back(0);
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
80 #endif
82 Filename.eraseFromDisk();