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
, bool wait
,
22 GraphProgram::Name program
) {
25 sys::Path
Graphviz(LLVM_PATH_GRAPHVIZ
);
27 std::vector
<const char*> args
;
28 args
.push_back(Graphviz
.c_str());
29 args
.push_back(Filename
.c_str());
32 cerr
<< "Running 'Graphviz' program... ";
33 if (sys::Program::ExecuteAndWait(Graphviz
, &args
[0],0,0,0,0,&ErrMsg
)) {
34 cerr
<< "Error viewing graph " << Filename
<< ": " << ErrMsg
<< "\n";
37 Filename
.eraseFromDisk();
40 #elif (HAVE_GV && (HAVE_DOT || HAVE_FDP || HAVE_NEATO || \
41 HAVE_TWOPI || HAVE_CIRCO))
42 sys::Path PSFilename
= Filename
;
43 PSFilename
.appendSuffix("ps");
47 // Set default grapher
49 prog
= sys::Path(LLVM_PATH_CIRCO
);
52 prog
= sys::Path(LLVM_PATH_TWOPI
);
55 prog
= sys::Path(LLVM_PATH_NEATO
);
58 prog
= sys::Path(LLVM_PATH_FDP
);
61 prog
= sys::Path(LLVM_PATH_DOT
);
64 // Find which program the user wants
66 if (program
== GraphProgram::DOT
) {
67 prog
= sys::Path(LLVM_PATH_DOT
);
71 if (program
== GraphProgram::FDP
) {
72 prog
= sys::Path(LLVM_PATH_FDP
);
76 if (program
== GraphProgram::NEATO
) {
77 prog
= sys::Path(LLVM_PATH_NEATO
);
81 if (program
== GraphProgram::TWOPI
) {
82 prog
= sys::Path(LLVM_PATH_TWOPI
);
86 if (program
== GraphProgram::CIRCO
) {
87 prog
= sys::Path(LLVM_PATH_CIRCO
);
91 std::vector
<const char*> args
;
92 args
.push_back(prog
.c_str());
93 args
.push_back("-Tps");
94 args
.push_back("-Nfontname=Courier");
95 args
.push_back("-Gsize=7.5,10");
96 args
.push_back(Filename
.c_str());
98 args
.push_back(PSFilename
.c_str());
101 cerr
<< "Running '" << prog
<< "' program... ";
103 if (sys::Program::ExecuteAndWait(prog
, &args
[0],0,0,0,0,&ErrMsg
)) {
104 cerr
<< "Error viewing graph " << Filename
<< ": '" << ErrMsg
<< "\n";
108 sys::Path
gv(LLVM_PATH_GV
);
110 args
.push_back(gv
.c_str());
111 args
.push_back(PSFilename
.c_str());
112 args
.push_back("-spartan");
117 if (sys::Program::ExecuteAndWait(gv
, &args
[0],0,0,0,0,&ErrMsg
)) {
118 cerr
<< "Error viewing graph: " << ErrMsg
<< "\n";
120 Filename
.eraseFromDisk();
121 PSFilename
.eraseFromDisk();
124 sys::Program::ExecuteNoWait(gv
, &args
[0],0,0,0,&ErrMsg
);
125 cerr
<< "Remember to erase graph files: " << Filename
<< " " << PSFilename
<< "\n";
129 sys::Path
dotty(LLVM_PATH_DOTTY
);
131 std::vector
<const char*> args
;
132 args
.push_back(dotty
.c_str());
133 args
.push_back(Filename
.c_str());
136 cerr
<< "Running 'dotty' program... ";
137 if (sys::Program::ExecuteAndWait(dotty
, &args
[0],0,0,0,0,&ErrMsg
)) {
138 cerr
<< "Error viewing graph " << Filename
<< ": " << ErrMsg
<< "\n";
140 #ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns
143 Filename
.eraseFromDisk();