It's not legal to fold a load from a narrower stack slot into a wider instruction...
[llvm/avr.git] / lib / Support / GraphWriter.cpp
blobc8bca6ef887cc892d24488299c136cdcbde9655f
1 //===-- GraphWriter.cpp - Implements GraphWriter support routines ---------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements misc. GraphWriter support routines.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/GraphWriter.h"
15 #include "llvm/System/Path.h"
16 #include "llvm/System/Program.h"
17 #include "llvm/Config/config.h"
18 using namespace llvm;
20 std::string llvm::DOT::EscapeString(const std::string &Label) {
21 std::string Str(Label);
22 for (unsigned i = 0; i != Str.length(); ++i)
23 switch (Str[i]) {
24 case '\n':
25 Str.insert(Str.begin()+i, '\\'); // Escape character...
26 ++i;
27 Str[i] = 'n';
28 break;
29 case '\t':
30 Str.insert(Str.begin()+i, ' '); // Convert to two spaces
31 ++i;
32 Str[i] = ' ';
33 break;
34 case '\\':
35 if (i+1 != Str.length())
36 switch (Str[i+1]) {
37 case 'l': continue; // don't disturb \l
38 case '|': case '{': case '}':
39 Str.erase(Str.begin()+i); continue;
40 default: break;
42 case '{': case '}':
43 case '<': case '>':
44 case '|': case '"':
45 Str.insert(Str.begin()+i, '\\'); // Escape character...
46 ++i; // don't infinite loop
47 break;
49 return Str;
54 void llvm::DisplayGraph(const sys::Path &Filename, bool wait,
55 GraphProgram::Name program) {
56 std::string ErrMsg;
57 #if HAVE_GRAPHVIZ
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());
63 args.push_back(0);
65 errs() << "Running 'Graphviz' program... ";
66 if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg))
67 errs() << "Error viewing graph " << Filename.str() << ": " << ErrMsg
68 << "\n";
69 else
70 Filename.eraseFromDisk();
72 #elif (HAVE_GV && (HAVE_DOT || HAVE_FDP || HAVE_NEATO || \
73 HAVE_TWOPI || HAVE_CIRCO))
74 sys::Path PSFilename = Filename;
75 PSFilename.appendSuffix("ps");
77 sys::Path prog;
79 // Set default grapher
80 #if HAVE_CIRCO
81 prog = sys::Path(LLVM_PATH_CIRCO);
82 #endif
83 #if HAVE_TWOPI
84 prog = sys::Path(LLVM_PATH_TWOPI);
85 #endif
86 #if HAVE_NEATO
87 prog = sys::Path(LLVM_PATH_NEATO);
88 #endif
89 #if HAVE_FDP
90 prog = sys::Path(LLVM_PATH_FDP);
91 #endif
92 #if HAVE_DOT
93 prog = sys::Path(LLVM_PATH_DOT);
94 #endif
96 // Find which program the user wants
97 #if HAVE_DOT
98 if (program == GraphProgram::DOT)
99 prog = sys::Path(LLVM_PATH_DOT);
100 #endif
101 #if (HAVE_FDP)
102 if (program == GraphProgram::FDP)
103 prog = sys::Path(LLVM_PATH_FDP);
104 #endif
105 #if (HAVE_NEATO)
106 if (program == GraphProgram::NEATO)
107 prog = sys::Path(LLVM_PATH_NEATO);
108 #endif
109 #if (HAVE_TWOPI)
110 if (program == GraphProgram::TWOPI)
111 prog = sys::Path(LLVM_PATH_TWOPI);
112 #endif
113 #if (HAVE_CIRCO)
114 if (program == GraphProgram::CIRCO)
115 prog = sys::Path(LLVM_PATH_CIRCO);
116 #endif
118 std::vector<const char*> args;
119 args.push_back(prog.c_str());
120 args.push_back("-Tps");
121 args.push_back("-Nfontname=Courier");
122 args.push_back("-Gsize=7.5,10");
123 args.push_back(Filename.c_str());
124 args.push_back("-o");
125 args.push_back(PSFilename.c_str());
126 args.push_back(0);
128 errs() << "Running '" << prog.str() << "' program... ";
130 if (sys::Program::ExecuteAndWait(prog, &args[0], 0, 0, 0, 0, &ErrMsg)) {
131 errs() << "Error viewing graph " << Filename.str() << ": '"
132 << ErrMsg << "\n";
133 } else {
134 errs() << " done. \n";
136 sys::Path gv(LLVM_PATH_GV);
137 args.clear();
138 args.push_back(gv.c_str());
139 args.push_back(PSFilename.c_str());
140 args.push_back("-spartan");
141 args.push_back(0);
143 ErrMsg.clear();
144 if (wait) {
145 if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg))
146 errs() << "Error viewing graph: " << ErrMsg << "\n";
147 Filename.eraseFromDisk();
148 PSFilename.eraseFromDisk();
150 else {
151 sys::Program::ExecuteNoWait(gv, &args[0],0,0,0,&ErrMsg);
152 errs() << "Remember to erase graph files: " << Filename.str() << " "
153 << PSFilename.str() << "\n";
156 #elif HAVE_DOTTY
157 sys::Path dotty(LLVM_PATH_DOTTY);
159 std::vector<const char*> args;
160 args.push_back(dotty.c_str());
161 args.push_back(Filename.c_str());
162 args.push_back(0);
164 errs() << "Running 'dotty' program... ";
165 if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,0,&ErrMsg)) {
166 errs() << "Error viewing graph " << Filename.str() << ": "
167 << ErrMsg << "\n";
168 } else {
169 #ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns
170 return;
171 #endif
172 Filename.eraseFromDisk();
174 #endif