1 //===-- GraphWriter.cpp - Implements GraphWriter support routines ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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,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,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());
61 args
.push_back("-spartan");
65 if (sys::Program::ExecuteAndWait(gv
, &args
[0],0,0,0,0,&ErrMsg
)) {
66 cerr
<< "Error viewing graph: " << ErrMsg
<< "\n";
69 PSFilename
.eraseFromDisk();
71 sys::Path
dotty(LLVM_PATH_DOTTY
);
73 std::vector
<const char*> args
;
74 args
.push_back(dotty
.c_str());
75 args
.push_back(Filename
.c_str());
78 cerr
<< "Running 'dotty' program... " << std::flush
;
79 if (sys::Program::ExecuteAndWait(dotty
, &args
[0],0,0,0,0,&ErrMsg
)) {
80 cerr
<< "Error viewing graph: " << ErrMsg
<< "\n";
82 #ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns
88 Filename
.eraseFromDisk();