blob: 73126e29258c76c579ada9c8723604f37f50aecf [file] [log] [blame]
Reid Spencer9d5b5322006-06-27 16:49:46 +00001//===-- 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/System/Path.h"
15#include "llvm/System/Program.h"
16#include "llvm/Config/config.h"
17
18#include <iostream>
19
20using namespace llvm;
21
22namespace llvm {
23
24void DisplayGraph(const sys::Path& Filename)
25{
26#if HAVE_GRAPHVIZ
27 sys::Path Graphviz(LLVM_PATH_GRAPHVIZ);
28
29 std::vector<const char*> args;
30 args.push_back(Graphviz.c_str());
31 args.push_back(Filename.c_str());
32 args.push_back(0);
33
34 std::cerr << "Running 'Graphviz' program... " << std::flush;
35 if (sys::Program::ExecuteAndWait(Graphviz, &args[0])) {
36 std::cerr << "Error viewing graph: 'Graphviz' not in path?\n";
37 }
38#elif (HAVE_GV && HAVE_DOT)
39 sys::Path PSFilename = Filename;
40 PSFilename.appendSuffix("ps");
41
42 sys::Path dot(LLVM_PATH_DOT);
43
44 std::vector<const char*> args;
45 args.push_back(dot.c_str());
46 args.push_back("-Tps");
47 args.push_back("-Nfontname=Courier");
48 args.push_back("-Gsize=7.5,10");
49 args.push_back(Filename.c_str());
50 args.push_back("-o");
51 args.push_back(PSFilename.c_str());
52 args.push_back(0);
53
54 std::cerr << "Running 'dot' program... " << std::flush;
55 if (sys::Program::ExecuteAndWait(dot, &args[0])) {
56 std::cerr << "Error viewing graph: 'dot' not in path?\n";
57 } else {
58 std::cerr << " done. \n";
59
60 sys::Path gv(LLVM_PATH_GV);
61 args.clear();
62 args.push_back(gv.c_str());
63 args.push_back(PSFilename.c_str());
64 args.push_back(0);
65
66 sys::Program::ExecuteAndWait(gv, &args[0]);
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 std::cerr << "Running 'dotty' program... " << std::flush;
77 if (sys::Program::ExecuteAndWait(dotty, &args[0])) {
78 std::cerr << "Error viewing graph: 'dotty' not in path?\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
89} // End llvm namespace