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