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/Path.h"
16 #include "llvm/Support/Program.h"
17 #include "llvm/Config/config.h"
20 std::string
llvm::DOT::EscapeString(const std::string
&Label
) {
21 std::string
Str(Label
);
22 for (unsigned i
= 0; i
!= Str
.length(); ++i
)
25 Str
.insert(Str
.begin()+i
, '\\'); // Escape character...
30 Str
.insert(Str
.begin()+i
, ' '); // Convert to two spaces
35 if (i
+1 != Str
.length())
37 case 'l': continue; // don't disturb \l
38 case '|': case '{': case '}':
39 Str
.erase(Str
.begin()+i
); continue;
45 Str
.insert(Str
.begin()+i
, '\\'); // Escape character...
46 ++i
; // don't infinite loop
54 void llvm::DisplayGraph(const sys::Path
&Filename
, bool wait
,
55 GraphProgram::Name program
) {
58 sys::Path
Graphviz(LLVM_PATH_GRAPHVIZ
);
60 std::vector
<const char*> args
;
61 args
.push_back(Graphviz
.c_str());
62 args
.push_back(Filename
.c_str());
65 errs() << "Running 'Graphviz' program... ";
66 if (sys::Program::ExecuteAndWait(Graphviz
, &args
[0],0,0,0,0,&ErrMsg
)) {
67 errs() << "Error: " << ErrMsg
<< "\n";
70 Filename
.eraseFromDisk();
71 errs() << " done. \n";
74 std::vector
<const char*> args
;
75 args
.push_back(LLVM_PATH_XDOT_PY
);
76 args
.push_back(Filename
.c_str());
79 case GraphProgram::DOT
: args
.push_back("-f"); args
.push_back("dot"); break;
80 case GraphProgram::FDP
: args
.push_back("-f"); args
.push_back("fdp"); break;
81 case GraphProgram::NEATO
: args
.push_back("-f"); args
.push_back("neato");break;
82 case GraphProgram::TWOPI
: args
.push_back("-f"); args
.push_back("twopi");break;
83 case GraphProgram::CIRCO
: args
.push_back("-f"); args
.push_back("circo");break;
84 default: errs() << "Unknown graph layout name; using default.\n";
89 errs() << "Running 'xdot.py' program... ";
90 if (sys::Program::ExecuteAndWait(sys::Path(LLVM_PATH_XDOT_PY
),
91 &args
[0],0,0,0,0,&ErrMsg
)) {
92 errs() << "Error: " << ErrMsg
<< "\n";
95 Filename
.eraseFromDisk();
96 errs() << " done. \n";
98 #elif (HAVE_GV && (HAVE_DOT || HAVE_FDP || HAVE_NEATO || \
99 HAVE_TWOPI || HAVE_CIRCO))
100 sys::Path PSFilename
= Filename
;
101 PSFilename
.appendSuffix("ps");
105 // Set default grapher
107 prog
= sys::Path(LLVM_PATH_CIRCO
);
110 prog
= sys::Path(LLVM_PATH_TWOPI
);
113 prog
= sys::Path(LLVM_PATH_NEATO
);
116 prog
= sys::Path(LLVM_PATH_FDP
);
119 prog
= sys::Path(LLVM_PATH_DOT
);
122 // Find which program the user wants
124 if (program
== GraphProgram::DOT
)
125 prog
= sys::Path(LLVM_PATH_DOT
);
128 if (program
== GraphProgram::FDP
)
129 prog
= sys::Path(LLVM_PATH_FDP
);
132 if (program
== GraphProgram::NEATO
)
133 prog
= sys::Path(LLVM_PATH_NEATO
);
136 if (program
== GraphProgram::TWOPI
)
137 prog
= sys::Path(LLVM_PATH_TWOPI
);
140 if (program
== GraphProgram::CIRCO
)
141 prog
= sys::Path(LLVM_PATH_CIRCO
);
144 std::vector
<const char*> args
;
145 args
.push_back(prog
.c_str());
146 args
.push_back("-Tps");
147 args
.push_back("-Nfontname=Courier");
148 args
.push_back("-Gsize=7.5,10");
149 args
.push_back(Filename
.c_str());
150 args
.push_back("-o");
151 args
.push_back(PSFilename
.c_str());
154 errs() << "Running '" << prog
.str() << "' program... ";
156 if (sys::Program::ExecuteAndWait(prog
, &args
[0], 0, 0, 0, 0, &ErrMsg
)) {
157 errs() << "Error: " << ErrMsg
<< "\n";
160 errs() << " done. \n";
162 sys::Path
gv(LLVM_PATH_GV
);
164 args
.push_back(gv
.c_str());
165 args
.push_back(PSFilename
.c_str());
166 args
.push_back("--spartan");
171 if (sys::Program::ExecuteAndWait(gv
, &args
[0],0,0,0,0,&ErrMsg
))
172 errs() << "Error: " << ErrMsg
<< "\n";
173 Filename
.eraseFromDisk();
174 PSFilename
.eraseFromDisk();
177 sys::Program::ExecuteNoWait(gv
, &args
[0],0,0,0,&ErrMsg
);
178 errs() << "Remember to erase graph files: " << Filename
.str() << " "
179 << PSFilename
.str() << "\n";
182 sys::Path
dotty(LLVM_PATH_DOTTY
);
184 std::vector
<const char*> args
;
185 args
.push_back(dotty
.c_str());
186 args
.push_back(Filename
.c_str());
189 errs() << "Running 'dotty' program... ";
190 if (sys::Program::ExecuteAndWait(dotty
, &args
[0],0,0,0,0,&ErrMsg
)) {
191 errs() << "Error: " << ErrMsg
<< "\n";
193 // Dotty spawns another app and doesn't wait until it returns
194 #if defined (__MINGW32__) || defined (_WINDOWS)
197 Filename
.eraseFromDisk();