Eugene Zelenko | 72208a8 | 2017-06-21 23:19:47 +0000 | [diff] [blame] | 1 | //===- GraphWriter.cpp - Implements GraphWriter support routines ----------===// |
Reid Spencer | ee7eaa2 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Reid Spencer | ee7eaa2 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements misc. GraphWriter support routines. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Chris Lattner | 2091cc8 | 2006-07-28 22:21:01 +0000 | [diff] [blame] | 13 | #include "llvm/Support/GraphWriter.h" |
Eugene Zelenko | 72208a8 | 2017-06-21 23:19:47 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/SmallString.h" |
| 15 | #include "llvm/ADT/SmallVector.h" |
| 16 | #include "llvm/ADT/StringRef.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/Config/config.h" |
| 18 | #include "llvm/Support/CommandLine.h" |
Eugene Zelenko | 72208a8 | 2017-06-21 23:19:47 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Compiler.h" |
| 20 | #include "llvm/Support/ErrorHandling.h" |
| 21 | #include "llvm/Support/ErrorOr.h" |
Rafael Espindola | ce61b1e | 2013-06-13 17:20:48 +0000 | [diff] [blame] | 22 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Program.h" |
Eugene Zelenko | 72208a8 | 2017-06-21 23:19:47 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
| 25 | #include <cassert> |
| 26 | #include <system_error> |
| 27 | #include <string> |
| 28 | #include <vector> |
| 29 | |
Reid Spencer | ee7eaa2 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 32 | static cl::opt<bool> ViewBackground("view-background", cl::Hidden, |
| 33 | cl::desc("Execute graph viewer in the background. Creates tmp file litter.")); |
| 34 | |
Chris Lattner | 4883d90 | 2009-08-23 07:19:13 +0000 | [diff] [blame] | 35 | std::string llvm::DOT::EscapeString(const std::string &Label) { |
| 36 | std::string Str(Label); |
| 37 | for (unsigned i = 0; i != Str.length(); ++i) |
| 38 | switch (Str[i]) { |
| 39 | case '\n': |
| 40 | Str.insert(Str.begin()+i, '\\'); // Escape character... |
| 41 | ++i; |
| 42 | Str[i] = 'n'; |
| 43 | break; |
| 44 | case '\t': |
| 45 | Str.insert(Str.begin()+i, ' '); // Convert to two spaces |
| 46 | ++i; |
| 47 | Str[i] = ' '; |
| 48 | break; |
| 49 | case '\\': |
| 50 | if (i+1 != Str.length()) |
| 51 | switch (Str[i+1]) { |
| 52 | case 'l': continue; // don't disturb \l |
| 53 | case '|': case '{': case '}': |
| 54 | Str.erase(Str.begin()+i); continue; |
| 55 | default: break; |
| 56 | } |
Galina Kistanova | 6fa60f5 | 2017-05-22 22:46:31 +0000 | [diff] [blame] | 57 | LLVM_FALLTHROUGH; |
Chris Lattner | 4883d90 | 2009-08-23 07:19:13 +0000 | [diff] [blame] | 58 | case '{': case '}': |
| 59 | case '<': case '>': |
| 60 | case '|': case '"': |
| 61 | Str.insert(Str.begin()+i, '\\'); // Escape character... |
| 62 | ++i; // don't infinite loop |
| 63 | break; |
| 64 | } |
| 65 | return Str; |
| 66 | } |
| 67 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 68 | /// Get a color string for this node number. Simply round-robin selects |
Andrew Trick | b36388a | 2013-01-25 07:45:25 +0000 | [diff] [blame] | 69 | /// from a reasonable number of colors. |
| 70 | StringRef llvm::DOT::getColorString(unsigned ColorNumber) { |
| 71 | static const int NumColors = 20; |
| 72 | static const char* Colors[NumColors] = { |
| 73 | "aaaaaa", "aa0000", "00aa00", "aa5500", "0055ff", "aa00aa", "00aaaa", |
| 74 | "555555", "ff5555", "55ff55", "ffff55", "5555ff", "ff55ff", "55ffff", |
| 75 | "ffaaaa", "aaffaa", "ffffaa", "aaaaff", "ffaaff", "aaffff"}; |
| 76 | return Colors[ColorNumber % NumColors]; |
| 77 | } |
| 78 | |
Rafael Espindola | 6a6f04a | 2013-06-14 16:43:15 +0000 | [diff] [blame] | 79 | std::string llvm::createGraphFilename(const Twine &Name, int &FD) { |
| 80 | FD = -1; |
| 81 | SmallString<128> Filename; |
Rafael Espindola | 3acea39 | 2014-06-12 21:46:39 +0000 | [diff] [blame] | 82 | std::error_code EC = sys::fs::createTemporaryFile(Name, "dot", FD, Filename); |
Rafael Espindola | 6a6f04a | 2013-06-14 16:43:15 +0000 | [diff] [blame] | 83 | if (EC) { |
| 84 | errs() << "Error: " << EC.message() << "\n"; |
Rafael Espindola | ce61b1e | 2013-06-13 17:20:48 +0000 | [diff] [blame] | 85 | return ""; |
| 86 | } |
Rafael Espindola | 6a6f04a | 2013-06-14 16:43:15 +0000 | [diff] [blame] | 87 | |
| 88 | errs() << "Writing '" << Filename << "'... "; |
Rafael Espindola | ce61b1e | 2013-06-13 17:20:48 +0000 | [diff] [blame] | 89 | return Filename.str(); |
| 90 | } |
| 91 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 92 | // Execute the graph viewer. Return true if there were errors. |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 93 | static bool ExecGraphViewer(StringRef ExecPath, std::vector<StringRef> &args, |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 94 | StringRef Filename, bool wait, |
| 95 | std::string &ErrMsg) { |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 96 | if (wait) { |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 97 | if (sys::ExecuteAndWait(ExecPath, args, None, {}, 0, 0, &ErrMsg)) { |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 98 | errs() << "Error: " << ErrMsg << "\n"; |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 99 | return true; |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 100 | } |
Rafael Espindola | 81e7fd0 | 2014-01-10 21:40:29 +0000 | [diff] [blame] | 101 | sys::fs::remove(Filename); |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 102 | errs() << " done. \n"; |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 103 | } else { |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 104 | sys::ExecuteNoWait(ExecPath, args, None, {}, 0, &ErrMsg); |
Yaron Keren | 075759a | 2015-03-30 15:42:36 +0000 | [diff] [blame] | 105 | errs() << "Remember to erase graph file: " << Filename << "\n"; |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 106 | } |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 107 | return false; |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 108 | } |
Chris Lattner | 4883d90 | 2009-08-23 07:19:13 +0000 | [diff] [blame] | 109 | |
Benjamin Kramer | 51f6096c | 2015-03-23 12:30:58 +0000 | [diff] [blame] | 110 | namespace { |
Eugene Zelenko | 72208a8 | 2017-06-21 23:19:47 +0000 | [diff] [blame] | 111 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 112 | struct GraphSession { |
| 113 | std::string LogBuffer; |
Eugene Zelenko | 72208a8 | 2017-06-21 23:19:47 +0000 | [diff] [blame] | 114 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 115 | bool TryFindProgram(StringRef Names, std::string &ProgramPath) { |
| 116 | raw_string_ostream Log(LogBuffer); |
| 117 | SmallVector<StringRef, 8> parts; |
Chandler Carruth | e4405e9 | 2015-09-10 06:12:31 +0000 | [diff] [blame] | 118 | Names.split(parts, '|'); |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 119 | for (auto Name : parts) { |
Michael J. Spencer | d48829b | 2014-11-07 21:30:36 +0000 | [diff] [blame] | 120 | if (ErrorOr<std::string> P = sys::findProgramByName(Name)) { |
Michael J. Spencer | f9074b5 | 2014-11-04 01:29:59 +0000 | [diff] [blame] | 121 | ProgramPath = *P; |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 122 | return true; |
Michael J. Spencer | f9074b5 | 2014-11-04 01:29:59 +0000 | [diff] [blame] | 123 | } |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 124 | Log << " Tried '" << Name << "'\n"; |
| 125 | } |
| 126 | return false; |
| 127 | } |
| 128 | }; |
Eugene Zelenko | 72208a8 | 2017-06-21 23:19:47 +0000 | [diff] [blame] | 129 | |
| 130 | } // end anonymous namespace |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 131 | |
| 132 | static const char *getProgramName(GraphProgram::Name program) { |
| 133 | switch (program) { |
| 134 | case GraphProgram::DOT: |
| 135 | return "dot"; |
| 136 | case GraphProgram::FDP: |
| 137 | return "fdp"; |
| 138 | case GraphProgram::NEATO: |
| 139 | return "neato"; |
| 140 | case GraphProgram::TWOPI: |
| 141 | return "twopi"; |
| 142 | case GraphProgram::CIRCO: |
| 143 | return "circo"; |
| 144 | } |
Alp Toker | 1feec4b | 2014-06-02 04:34:10 +0000 | [diff] [blame] | 145 | llvm_unreachable("bad kind"); |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | bool llvm::DisplayGraph(StringRef FilenameRef, bool wait, |
David Greene | 4417b4c | 2009-07-09 17:06:18 +0000 | [diff] [blame] | 149 | GraphProgram::Name program) { |
Rafael Espindola | 48944e7 | 2013-06-13 17:27:45 +0000 | [diff] [blame] | 150 | std::string Filename = FilenameRef; |
Reid Spencer | 944645a | 2006-08-21 06:04:45 +0000 | [diff] [blame] | 151 | std::string ErrMsg; |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 152 | std::string ViewerPath; |
| 153 | GraphSession S; |
Reid Spencer | ee7eaa2 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 154 | |
Matthias Braun | e376d16 | 2015-04-03 17:22:36 +0000 | [diff] [blame] | 155 | #ifdef __APPLE__ |
Charlie Turner | 0912de3 | 2015-07-02 09:32:07 +0000 | [diff] [blame] | 156 | wait &= !ViewBackground; |
Matthias Braun | e376d16 | 2015-04-03 17:22:36 +0000 | [diff] [blame] | 157 | if (S.TryFindProgram("open", ViewerPath)) { |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 158 | std::vector<StringRef> args; |
| 159 | args.push_back(ViewerPath); |
Matthias Braun | e376d16 | 2015-04-03 17:22:36 +0000 | [diff] [blame] | 160 | if (wait) |
| 161 | args.push_back("-W"); |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 162 | args.push_back(Filename); |
Matthias Braun | e376d16 | 2015-04-03 17:22:36 +0000 | [diff] [blame] | 163 | errs() << "Trying 'open' program... "; |
| 164 | if (!ExecGraphViewer(ViewerPath, args, Filename, wait, ErrMsg)) |
| 165 | return false; |
| 166 | } |
| 167 | #endif |
| 168 | if (S.TryFindProgram("xdg-open", ViewerPath)) { |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 169 | std::vector<StringRef> args; |
| 170 | args.push_back(ViewerPath); |
| 171 | args.push_back(Filename); |
Matthias Braun | e376d16 | 2015-04-03 17:22:36 +0000 | [diff] [blame] | 172 | errs() << "Trying 'xdg-open' program... "; |
| 173 | if (!ExecGraphViewer(ViewerPath, args, Filename, wait, ErrMsg)) |
| 174 | return false; |
| 175 | } |
| 176 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 177 | // Graphviz |
| 178 | if (S.TryFindProgram("Graphviz", ViewerPath)) { |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 179 | std::vector<StringRef> args; |
| 180 | args.push_back(ViewerPath); |
| 181 | args.push_back(Filename); |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 182 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 183 | errs() << "Running 'Graphviz' program... "; |
| 184 | return ExecGraphViewer(ViewerPath, args, Filename, wait, ErrMsg); |
Dan Gohman | a0da889 | 2010-09-27 16:28:34 +0000 | [diff] [blame] | 185 | } |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 186 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 187 | // xdot |
| 188 | if (S.TryFindProgram("xdot|xdot.py", ViewerPath)) { |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 189 | std::vector<StringRef> args; |
| 190 | args.push_back(ViewerPath); |
| 191 | args.push_back(Filename); |
Dan Gohman | a0da889 | 2010-09-27 16:28:34 +0000 | [diff] [blame] | 192 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 193 | args.push_back("-f"); |
| 194 | args.push_back(getProgramName(program)); |
Dan Gohman | a0da889 | 2010-09-27 16:28:34 +0000 | [diff] [blame] | 195 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 196 | errs() << "Running 'xdot.py' program... "; |
| 197 | return ExecGraphViewer(ViewerPath, args, Filename, wait, ErrMsg); |
| 198 | } |
| 199 | |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 200 | enum ViewerKind { |
| 201 | VK_None, |
| 202 | VK_OSXOpen, |
| 203 | VK_XDGOpen, |
| 204 | VK_Ghostview, |
| 205 | VK_CmdStart |
| 206 | }; |
| 207 | ViewerKind Viewer = VK_None; |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 208 | #ifdef __APPLE__ |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 209 | if (!Viewer && S.TryFindProgram("open", ViewerPath)) |
| 210 | Viewer = VK_OSXOpen; |
David Greene | 4417b4c | 2009-07-09 17:06:18 +0000 | [diff] [blame] | 211 | #endif |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 212 | if (!Viewer && S.TryFindProgram("gv", ViewerPath)) |
| 213 | Viewer = VK_Ghostview; |
| 214 | if (!Viewer && S.TryFindProgram("xdg-open", ViewerPath)) |
| 215 | Viewer = VK_XDGOpen; |
Nico Weber | 712e8d2 | 2018-04-29 00:45:03 +0000 | [diff] [blame] | 216 | #ifdef _WIN32 |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 217 | if (!Viewer && S.TryFindProgram("cmd", ViewerPath)) { |
| 218 | Viewer = VK_CmdStart; |
| 219 | } |
| 220 | #endif |
David Greene | 4417b4c | 2009-07-09 17:06:18 +0000 | [diff] [blame] | 221 | |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 222 | // PostScript or PDF graph generator + PostScript/PDF viewer |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 223 | std::string GeneratorPath; |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 224 | if (Viewer && |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 225 | (S.TryFindProgram(getProgramName(program), GeneratorPath) || |
Alp Toker | 54b6ab0 | 2014-06-02 04:14:23 +0000 | [diff] [blame] | 226 | S.TryFindProgram("dot|fdp|neato|twopi|circo", GeneratorPath))) { |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 227 | std::string OutputFilename = |
| 228 | Filename + (Viewer == VK_CmdStart ? ".pdf" : ".ps"); |
Reid Spencer | ee7eaa2 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 229 | |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 230 | std::vector<StringRef> args; |
| 231 | args.push_back(GeneratorPath); |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 232 | if (Viewer == VK_CmdStart) |
| 233 | args.push_back("-Tpdf"); |
| 234 | else |
| 235 | args.push_back("-Tps"); |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 236 | args.push_back("-Nfontname=Courier"); |
| 237 | args.push_back("-Gsize=7.5,10"); |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 238 | args.push_back(Filename); |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 239 | args.push_back("-o"); |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 240 | args.push_back(OutputFilename); |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 241 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 242 | errs() << "Running '" << GeneratorPath << "' program... "; |
David Greene | 9dadbbd | 2009-07-08 21:53:41 +0000 | [diff] [blame] | 243 | |
Michael Kruse | 020296a | 2015-09-18 10:56:30 +0000 | [diff] [blame] | 244 | if (ExecGraphViewer(GeneratorPath, args, Filename, true, ErrMsg)) |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 245 | return true; |
Reid Spencer | ee7eaa2 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 246 | |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 247 | // The lifetime of StartArg must include the call of ExecGraphViewer |
| 248 | // because the args are passed as vector of char*. |
| 249 | std::string StartArg; |
| 250 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 251 | args.clear(); |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 252 | args.push_back(ViewerPath); |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 253 | switch (Viewer) { |
| 254 | case VK_OSXOpen: |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 255 | args.push_back("-W"); |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 256 | args.push_back(OutputFilename); |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 257 | break; |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 258 | case VK_XDGOpen: |
Alp Toker | e3fbe2c | 2014-06-04 03:57:44 +0000 | [diff] [blame] | 259 | wait = false; |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 260 | args.push_back(OutputFilename); |
Alp Toker | e3fbe2c | 2014-06-04 03:57:44 +0000 | [diff] [blame] | 261 | break; |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 262 | case VK_Ghostview: |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 263 | args.push_back("--spartan"); |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 264 | args.push_back(OutputFilename); |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 265 | break; |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 266 | case VK_CmdStart: |
| 267 | args.push_back("/S"); |
| 268 | args.push_back("/C"); |
| 269 | StartArg = |
| 270 | (StringRef("start ") + (wait ? "/WAIT " : "") + OutputFilename).str(); |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 271 | args.push_back(StartArg); |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 272 | break; |
| 273 | case VK_None: |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 274 | llvm_unreachable("Invalid viewer"); |
| 275 | } |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 276 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 277 | ErrMsg.clear(); |
Michael Kruse | c1c9f8a | 2015-08-18 12:17:37 +0000 | [diff] [blame] | 278 | return ExecGraphViewer(ViewerPath, args, OutputFilename, wait, ErrMsg); |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 279 | } |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 280 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 281 | // dotty |
| 282 | if (S.TryFindProgram("dotty", ViewerPath)) { |
Zachary Turner | 08426e1 | 2018-06-12 17:43:52 +0000 | [diff] [blame] | 283 | std::vector<StringRef> args; |
| 284 | args.push_back(ViewerPath); |
| 285 | args.push_back(Filename); |
Andrew Trick | edbb3b2 | 2012-03-07 00:18:27 +0000 | [diff] [blame] | 286 | |
Chris Lattner | 33154c1 | 2010-04-13 04:35:39 +0000 | [diff] [blame] | 287 | // Dotty spawns another app and doesn't wait until it returns |
Nico Weber | 712e8d2 | 2018-04-29 00:45:03 +0000 | [diff] [blame] | 288 | #ifdef _WIN32 |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 289 | wait = false; |
Reid Spencer | ee7eaa2 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 290 | #endif |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 291 | errs() << "Running 'dotty' program... "; |
| 292 | return ExecGraphViewer(ViewerPath, args, Filename, wait, ErrMsg); |
| 293 | } |
| 294 | |
| 295 | errs() << "Error: Couldn't find a usable graph viewer program:\n"; |
| 296 | errs() << S.LogBuffer << "\n"; |
| 297 | return true; |
Reid Spencer | ee7eaa2 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 298 | } |