llvm.org GIT mirror llvm / d4c4543
Make tool_output_file's raw_ostream instance a member variable instead of a base class. This makes it possible to unregister the file from FilesToRemove when the file is done. Also, this eliminates the need for formatted_tool_output_file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112706 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
19 changed file(s) with 205 addition(s) and 215 deletion(s). Raw diff Collapse all Expand all
1818
1919 namespace llvm
2020 {
21 class formatted_tool_output_file;
22
2321 /// formatted_raw_ostream - Formatted raw_fd_ostream to handle
2422 /// asm-specific constructs.
2523 ///
2624 class formatted_raw_ostream : public raw_ostream {
27 friend class formatted_tool_output_file;
28
2925 public:
3026 /// DELETE_STREAM - Tell the destructor to delete the held stream.
3127 ///
139135 }
140136 };
141137
142 /// formatted_tool_output_file - This is a subclass of formatted_raw_ostream
143 /// for use when the underlying stream is a tool_output_file. It exposes
144 /// keep() and several other member functions.
145 class formatted_tool_output_file : public formatted_raw_ostream {
146 private:
147 tool_output_file &get_tool_output_file() const {
148 return *static_cast(TheStream);
149 }
150
151 public:
152 formatted_tool_output_file(tool_output_file &Stream, bool Delete = false)
153 : formatted_raw_ostream(Stream, Delete) {}
154
155 formatted_tool_output_file() {}
156
157 ~formatted_tool_output_file();
158
159 void setStream(tool_output_file &Stream, bool Delete = false) {
160 return formatted_raw_ostream::setStream(Stream, Delete);
161 }
162
163 void keep() { return get_tool_output_file().keep(); }
164 bool has_error() const { return get_tool_output_file().has_error(); }
165 void clear_error() { return get_tool_output_file().clear_error(); }
166 void close() {
167 // The inner stream is unbuffered; flush the outer stream's buffer.
168 flush();
169 // The inner stream can close its file descriptor now.
170 return get_tool_output_file().close();
171 }
172 };
173
174138 /// fouts() - This returns a reference to a formatted_raw_ostream for
175139 /// standard output. Use it like: fouts() << "foo" << "bar";
176140 formatted_raw_ostream &fouts();
474474 ~raw_null_ostream();
475475 };
476476
477 /// tool_output_file - This class behaves like a raw_fd_ostream but adds a
477 /// tool_output_file - This class contains a raw_fd_ostream and adds a
478478 /// few extra features commonly needed for compiler-like tool output files:
479479 /// - The file is automatically deleted if the process is killed.
480480 /// - The file is automatically deleted when the tool_output_file
481481 /// object is destroyed unless the client calls keep().
482 class tool_output_file : public raw_fd_ostream {
483 std::string Filename;
484 bool Keep;
482 class tool_output_file {
483 /// Installer - This class is declared before the raw_fd_ostream so that
484 /// it is constructed before the raw_fd_ostream is constructed and
485 /// destructed after the raw_fd_ostream is destructed. It installs
486 /// cleanups in its constructor and uninstalls them in its destructor.
487 class CleanupInstaller {
488 /// Filename - The name of the file.
489 std::string Filename;
490 public:
491 /// Keep - The flag which indicates whether we should not delete the file.
492 bool Keep;
493
494 explicit CleanupInstaller(const char *filename);
495 ~CleanupInstaller();
496 } Installer;
497
498 /// OS - The contained stream. This is intentionally declared after
499 /// Installer.
500 raw_fd_ostream OS;
501
485502 public:
503 /// tool_output_file - This constructor's arguments are passed to
504 /// to raw_fd_ostream's constructor.
486505 tool_output_file(const char *filename, std::string &ErrorInfo,
487506 unsigned Flags = 0);
488507
489 ~tool_output_file();
508 /// os - Return the contained raw_fd_ostream.
509 raw_fd_ostream &os() { return OS; }
490510
491511 /// keep - Indicate that the tool's job wrt this output file has been
492512 /// successful and the file should not be deleted.
493 void keep() { Keep = true; }
513 void keep() { Installer.Keep = true; }
494514 };
495515
496516 } // end llvm namespace
9797 static formatted_raw_ostream S(dbgs());
9898 return S;
9999 }
100
101 /// ~formatted_tool_output_file - Out-of-line destructor.
102 formatted_tool_output_file::~formatted_tool_output_file() {}
669669 // tool_output_file
670670 //===----------------------------------------------------------------------===//
671671
672 /// SetupRemoveOnSignal - This is a helper for tool_output_file's constructor
673 /// to allow the signal handlers to be installed before constructing the
674 /// base class raw_fd_ostream.
675 static const char *SetupRemoveOnSignal(const char *Filename) {
672 tool_output_file::CleanupInstaller::CleanupInstaller(const char *filename)
673 : Filename(filename), Keep(false) {
676674 // Arrange for the file to be deleted if the process is killed.
677 if (strcmp(Filename, "-") != 0)
675 if (Filename != "-")
678676 sys::RemoveFileOnSignal(sys::Path(Filename));
679 return Filename;
680 }
681
682 tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
683 unsigned Flags)
684 : raw_fd_ostream(SetupRemoveOnSignal(filename), ErrorInfo, Flags),
685 Filename(filename),
686 Keep(!ErrorInfo.empty() /* If open fails, no cleanup is needed. */) {
687 }
688
689 tool_output_file::~tool_output_file() {
677 }
678
679 tool_output_file::CleanupInstaller::~CleanupInstaller() {
690680 // Delete the file if the client hasn't told us not to.
691681 if (!Keep && Filename != "-")
692682 sys::Path(Filename).eraseFromDisk();
693 }
683
684 // Ok, the file is successfully written and closed, or deleted. There's no
685 // further need to clean it up on signals.
686 if (Filename != "-")
687 sys::DontRemoveFileOnSignal(sys::Path(Filename));
688 }
689
690 tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
691 unsigned Flags)
692 : Installer(filename),
693 OS(filename, ErrorInfo, Flags) {
694 // If open fails, no cleanup is needed.
695 if (!ErrorInfo.empty())
696 Installer.Keep = true;
697 }
338338 // If the BB doesn't have a name, give it one so we have something to key
339339 // off of.
340340 if (!BB->hasName()) BB->setName("tmpbb");
341 BlocksToNotExtractFile << BB->getParent()->getNameStr() << " "
342 << BB->getName() << "\n";
343 }
344 BlocksToNotExtractFile.close();
345 if (BlocksToNotExtractFile.has_error()) {
341 BlocksToNotExtractFile.os() << BB->getParent()->getNameStr() << " "
342 << BB->getName() << "\n";
343 }
344 BlocksToNotExtractFile.os().close();
345 if (BlocksToNotExtractFile.os().has_error()) {
346346 errs() << "Error writing list of blocks to not extract: " << ErrorInfo
347347 << "\n";
348348 EmitProgressBitcode(M, "basicblockextractfail", true);
349 BlocksToNotExtractFile.clear_error();
349 BlocksToNotExtractFile.os().clear_error();
350350 return 0;
351351 }
352352 BlocksToNotExtractFile.keep();
5757 tool_output_file Out(Filename.c_str(), ErrInfo,
5858 raw_fd_ostream::F_Binary);
5959 if (ErrInfo.empty()) {
60 WriteBitcodeToFile(M, Out);
61 Out.close();
62 if (!Out.has_error()) {
60 WriteBitcodeToFile(M, Out.os());
61 Out.os().close();
62 if (!Out.os().has_error()) {
6363 Out.keep();
6464 return false;
6565 }
6666 }
67 Out.clear_error();
67 Out.os().clear_error();
6868 return true;
6969 }
7070
139139 errs() << "Error opening bitcode file: " << inputFilename.str() << "\n";
140140 return 1;
141141 }
142 WriteBitcodeToFile(Program, InFile);
143 InFile.close();
144 if (InFile.has_error()) {
142 WriteBitcodeToFile(Program, InFile.os());
143 InFile.os().close();
144 if (InFile.os().has_error()) {
145145 errs() << "Error writing bitcode file: " << inputFilename.str() << "\n";
146 InFile.clear_error();
146 InFile.os().clear_error();
147147 return 1;
148148 }
149149 InFile.keep();
122122 return outputFilename;
123123 }
124124
125 static formatted_tool_output_file *GetOutputStream(const char *TargetName,
126 Triple::OSType OS,
127 const char *ProgName) {
125 static tool_output_file *GetOutputStream(const char *TargetName,
126 Triple::OSType OS,
127 const char *ProgName) {
128128 // If we don't yet have an output filename, make one.
129129 if (OutputFilename.empty()) {
130130 if (InputFilename == "-")
182182 return 0;
183183 }
184184
185 formatted_tool_output_file *Out =
186 new formatted_tool_output_file(*FDOut,
187 formatted_raw_ostream::DELETE_STREAM);
188
189 return Out;
185 return FDOut;
190186 }
191187
192188 // main - Entry point for the llc compiler.
277273 TargetMachine &Target = *target.get();
278274
279275 // Figure out where we are going to send the output...
280 OwningPtr<formatted_tool_output_file> Out
276 OwningPtr<tool_output_file> Out
281277 (GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]));
282278 if (!Out) return 1;
283279
313309 Target.setMCRelaxAll(true);
314310 }
315311
316 // Ask the target to add backend passes as necessary.
317 if (Target.addPassesToEmitFile(PM, *Out, FileType, OLvl,
318 NoVerify)) {
319 errs() << argv[0] << ": target does not support generation of this"
320 << " file type!\n";
321 return 1;
322 }
323
324 PM.run(mod);
312 {
313 formatted_raw_ostream FOS(Out->os());
314
315 // Ask the target to add backend passes as necessary.
316 if (Target.addPassesToEmitFile(PM, FOS, FileType, OLvl, NoVerify)) {
317 errs() << argv[0] << ": target does not support generation of this"
318 << " file type!\n";
319 return 1;
320 }
321
322 PM.run(mod);
323 }
325324
326325 // Declare success.
327326 Out->keep();
7676 exit(1);
7777 }
7878
79 if (Force || !CheckBitcodeOutputToConsole(*Out, true))
80 WriteBitcodeToFile(M, *Out);
79 if (Force || !CheckBitcodeOutputToConsole(Out->os(), true))
80 WriteBitcodeToFile(M, Out->os());
8181
8282 // Declare success.
8383 Out->keep();
9797
9898 // All that llvm-dis does is write the assembly to a file.
9999 if (!DontPrint)
100 *Out << *M;
100 Out->os() << *M;
101101
102102 // Declare success.
103103 Out->keep();
133133 }
134134
135135 if (OutputAssembly)
136 Passes.add(createPrintModulePass(&Out));
137 else if (Force || !CheckBitcodeOutputToConsole(Out, true))
138 Passes.add(createBitcodeWriterPass(Out));
136 Passes.add(createPrintModulePass(&Out.os()));
137 else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
138 Passes.add(createBitcodeWriterPass(Out.os()));
139139
140140 Passes.run(*M.get());
141141
243243 }
244244
245245 // Write it out
246 WriteBitcodeToFile(M, Out);
246 WriteBitcodeToFile(M, Out.os());
247247 Out.keep();
248248 }
249249
431431 if (!ErrorInfo.empty())
432432 PrintAndExit(ErrorInfo, M);
433433
434 Out2 << "#!/bin/sh\n";
434 Out2.os() << "#!/bin/sh\n";
435435 // Allow user to setenv LLVMINTERP if lli is not in their PATH.
436 Out2 << "lli=${LLVMINTERP-lli}\n";
437 Out2 << "exec $lli \\\n";
436 Out2.os() << "lli=${LLVMINTERP-lli}\n";
437 Out2.os() << "exec $lli \\\n";
438438 // gcc accepts -l and implicitly searches /lib and /usr/lib.
439439 LibPaths.push_back("/lib");
440440 LibPaths.push_back("/usr/lib");
465465 if (FullLibraryPath.isEmpty())
466466 FullLibraryPath = sys::Path::FindLibrary(*i);
467467 if (!FullLibraryPath.isEmpty())
468 Out2 << " -load=" << FullLibraryPath.str() << " \\\n";
469 }
470 Out2 << " " << BitcodeOutputFilename << " ${1+\"$@\"}\n";
468 Out2.os() << " -load=" << FullLibraryPath.str() << " \\\n";
469 }
470 Out2.os() << " " << BitcodeOutputFilename << " ${1+\"$@\"}\n";
471471 Out2.keep();
472472 }
473473
129129
130130 if (Verbose) errs() << "Writing bitcode...\n";
131131 if (OutputAssembly) {
132 Out << *Composite;
133 } else if (Force || !CheckBitcodeOutputToConsole(Out, true))
134 WriteBitcodeToFile(Composite.get(), Out);
132 Out.os() << *Composite;
133 } else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
134 WriteBitcodeToFile(Composite.get(), Out.os());
135135
136136 // Declare success.
137137 Out.keep();
139139 return 0;
140140 }
141141
142 static formatted_tool_output_file *GetOutputStream() {
142 static tool_output_file *GetOutputStream() {
143143 if (OutputFilename == "")
144144 OutputFilename = "-";
145145
151151 delete Out;
152152 return 0;
153153 }
154
155 return new formatted_tool_output_file(*Out,
156 formatted_raw_ostream::DELETE_STREAM);
154
155 return Out;
157156 }
158157
159158 static int AsLexInput(const char *ProgName) {
188187 AsmLexer Lexer(*MAI);
189188 Lexer.setBuffer(SrcMgr.getMemoryBuffer(0));
190189
191 OwningPtr<formatted_tool_output_file> Out(GetOutputStream());
190 OwningPtr<tool_output_file> Out(GetOutputStream());
192191 if (!Out)
193192 return 1;
194193
203202 Error = true; // error already printed.
204203 break;
205204 case AsmToken::Identifier:
206 *Out << "identifier: " << Lexer.getTok().getString() << '\n';
205 Out->os() << "identifier: " << Lexer.getTok().getString() << '\n';
207206 break;
208207 case AsmToken::String:
209 *Out << "string: " << Lexer.getTok().getString() << '\n';
208 Out->os() << "string: " << Lexer.getTok().getString() << '\n';
210209 break;
211210 case AsmToken::Integer:
212 *Out << "int: " << Lexer.getTok().getString() << '\n';
211 Out->os() << "int: " << Lexer.getTok().getString() << '\n';
213212 break;
214213
215 case AsmToken::Amp: *Out << "Amp\n"; break;
216 case AsmToken::AmpAmp: *Out << "AmpAmp\n"; break;
217 case AsmToken::Caret: *Out << "Caret\n"; break;
218 case AsmToken::Colon: *Out << "Colon\n"; break;
219 case AsmToken::Comma: *Out << "Comma\n"; break;
220 case AsmToken::Dollar: *Out << "Dollar\n"; break;
221 case AsmToken::EndOfStatement: *Out << "EndOfStatement\n"; break;
222 case AsmToken::Eof: *Out << "Eof\n"; break;
223 case AsmToken::Equal: *Out << "Equal\n"; break;
224 case AsmToken::EqualEqual: *Out << "EqualEqual\n"; break;
225 case AsmToken::Exclaim: *Out << "Exclaim\n"; break;
226 case AsmToken::ExclaimEqual: *Out << "ExclaimEqual\n"; break;
227 case AsmToken::Greater: *Out << "Greater\n"; break;
228 case AsmToken::GreaterEqual: *Out << "GreaterEqual\n"; break;
229 case AsmToken::GreaterGreater: *Out << "GreaterGreater\n"; break;
230 case AsmToken::LParen: *Out << "LParen\n"; break;
231 case AsmToken::Less: *Out << "Less\n"; break;
232 case AsmToken::LessEqual: *Out << "LessEqual\n"; break;
233 case AsmToken::LessGreater: *Out << "LessGreater\n"; break;
234 case AsmToken::LessLess: *Out << "LessLess\n"; break;
235 case AsmToken::Minus: *Out << "Minus\n"; break;
236 case AsmToken::Percent: *Out << "Percent\n"; break;
237 case AsmToken::Pipe: *Out << "Pipe\n"; break;
238 case AsmToken::PipePipe: *Out << "PipePipe\n"; break;
239 case AsmToken::Plus: *Out << "Plus\n"; break;
240 case AsmToken::RParen: *Out << "RParen\n"; break;
241 case AsmToken::Slash: *Out << "Slash\n"; break;
242 case AsmToken::Star: *Out << "Star\n"; break;
243 case AsmToken::Tilde: *Out << "Tilde\n"; break;
214 case AsmToken::Amp: Out->os() << "Amp\n"; break;
215 case AsmToken::AmpAmp: Out->os() << "AmpAmp\n"; break;
216 case AsmToken::Caret: Out->os() << "Caret\n"; break;
217 case AsmToken::Colon: Out->os() << "Colon\n"; break;
218 case AsmToken::Comma: Out->os() << "Comma\n"; break;
219 case AsmToken::Dollar: Out->os() << "Dollar\n"; break;
220 case AsmToken::EndOfStatement: Out->os() << "EndOfStatement\n"; break;
221 case AsmToken::Eof: Out->os() << "Eof\n"; break;
222 case AsmToken::Equal: Out->os() << "Equal\n"; break;
223 case AsmToken::EqualEqual: Out->os() << "EqualEqual\n"; break;
224 case AsmToken::Exclaim: Out->os() << "Exclaim\n"; break;
225 case AsmToken::ExclaimEqual: Out->os() << "ExclaimEqual\n"; break;
226 case AsmToken::Greater: Out->os() << "Greater\n"; break;
227 case AsmToken::GreaterEqual: Out->os() << "GreaterEqual\n"; break;
228 case AsmToken::GreaterGreater: Out->os() << "GreaterGreater\n"; break;
229 case AsmToken::LParen: Out->os() << "LParen\n"; break;
230 case AsmToken::Less: Out->os() << "Less\n"; break;
231 case AsmToken::LessEqual: Out->os() << "LessEqual\n"; break;
232 case AsmToken::LessGreater: Out->os() << "LessGreater\n"; break;
233 case AsmToken::LessLess: Out->os() << "LessLess\n"; break;
234 case AsmToken::Minus: Out->os() << "Minus\n"; break;
235 case AsmToken::Percent: Out->os() << "Percent\n"; break;
236 case AsmToken::Pipe: Out->os() << "Pipe\n"; break;
237 case AsmToken::PipePipe: Out->os() << "PipePipe\n"; break;
238 case AsmToken::Plus: Out->os() << "Plus\n"; break;
239 case AsmToken::RParen: Out->os() << "RParen\n"; break;
240 case AsmToken::Slash: Out->os() << "Slash\n"; break;
241 case AsmToken::Star: Out->os() << "Star\n"; break;
242 case AsmToken::Tilde: Out->os() << "Tilde\n"; break;
244243 }
245244 }
246245
290289 return 1;
291290 }
292291
293 OwningPtr<formatted_tool_output_file> Out(GetOutputStream());
292 OwningPtr<tool_output_file> Out(GetOutputStream());
294293 if (!Out)
295294 return 1;
296295
296 formatted_raw_ostream FOS(Out->os());
297297 OwningPtr Str;
298298
299299 if (FileType == OFT_AssemblyFile) {
302302 MCCodeEmitter *CE = 0;
303303 if (ShowEncoding)
304304 CE = TheTarget->createCodeEmitter(*TM, Ctx);
305 Str.reset(createAsmStreamer(Ctx, *Out,
305 Str.reset(createAsmStreamer(Ctx, FOS,
306306 TM->getTargetData()->isLittleEndian(),
307307 /*asmverbose*/true, IP, CE, ShowInst));
308308 } else if (FileType == OFT_Null) {
312312 MCCodeEmitter *CE = TheTarget->createCodeEmitter(*TM, Ctx);
313313 TargetAsmBackend *TAB = TheTarget->createAsmBackend(TripleName);
314314 Str.reset(TheTarget->createObjectStreamer(TripleName, Ctx, *TAB,
315 *Out, CE, RelaxAll));
315 FOS, CE, RelaxAll));
316316 }
317317
318318 if (EnableLogging) {
358358 return 1;
359359 }
360360
361 OwningPtr<formatted_tool_output_file> Out(GetOutputStream());
361 OwningPtr<tool_output_file> Out(GetOutputStream());
362362 if (!Out)
363363 return 1;
364364
365365 int Res;
366366 if (Enhanced)
367 Res = Disassembler::disassembleEnhanced(TripleName, *Buffer, *Out);
367 Res = Disassembler::disassembleEnhanced(TripleName, *Buffer, Out->os());
368368 else
369 Res = Disassembler::disassemble(*TheTarget, TripleName, *Buffer, *Out);
369 Res = Disassembler::disassemble(*TheTarget, TripleName, *Buffer, Out->os());
370370
371371 // Keep output if no errors.
372372 if (Res == 0) Out->keep();
163163 }
164164
165165 // write bitcode to it
166 WriteBitcodeToFile(_linker.getModule(), Out);
167 Out.close();
168
169 if (Out.has_error()) {
166 WriteBitcodeToFile(_linker.getModule(), Out.os());
167 Out.os().close();
168
169 if (Out.os().has_error()) {
170170 errMsg = "could not write bitcode file: ";
171171 errMsg += path;
172 Out.clear_error();
172 Out.os().clear_error();
173173 return true;
174174 }
175175
189189 // generate assembly code
190190 bool genResult = false;
191191 {
192 tool_output_file asmFD(uniqueAsmPath.c_str(), errMsg);
193 formatted_tool_output_file asmFile(asmFD);
192 tool_output_file asmFile(uniqueAsmPath.c_str(), errMsg);
194193 if (!errMsg.empty())
195194 return NULL;
196 genResult = this->generateAssemblyCode(asmFile, errMsg);
197 asmFile.close();
198 if (asmFile.has_error()) {
199 asmFile.clear_error();
195 genResult = this->generateAssemblyCode(asmFile.os(), errMsg);
196 asmFile.os().close();
197 if (asmFile.os().has_error()) {
198 asmFile.os().clear_error();
200199 return NULL;
201200 }
202201 asmFile.keep();
367366 }
368367
369368 /// Optimize merged modules using various IPO passes
370 bool LTOCodeGenerator::generateAssemblyCode(formatted_raw_ostream& out,
369 bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
371370 std::string& errMsg)
372371 {
373372 if ( this->determineTarget(errMsg) )
402401
403402 codeGenPasses->add(new TargetData(*_target->getTargetData()));
404403
405 if (_target->addPassesToEmitFile(*codeGenPasses, out,
404 formatted_raw_ostream Out(out);
405
406 if (_target->addPassesToEmitFile(*codeGenPasses, Out,
406407 TargetMachine::CGFT_AssemblyFile,
407408 CodeGenOpt::Aggressive)) {
408409 errMsg = "target file type not supported";
4444 const void* compile(size_t* length, std::string& errMsg);
4545 void setCodeGenDebugOptions(const char *opts);
4646 private:
47 bool generateAssemblyCode(llvm::formatted_raw_ostream& out,
47 bool generateAssemblyCode(llvm::raw_ostream& out,
4848 std::string& errMsg);
4949 bool assemble(const std::string& asmPath,
5050 const std::string& objPath, std::string& errMsg);
3030 tool_output_file F(Filename.c_str(), ErrInfo);
3131
3232 if (ErrInfo.empty()) {
33 WriteGraph(F, GT);
34 F.close();
35 if (!F.has_error()) {
33 WriteGraph(F.os(), GT);
34 F.os().close();
35 if (!F.os().has_error()) {
3636 O << "\n";
3737 F.keep();
3838 return;
3939 }
4040 }
41 F.clear_error();
4241 O << " error opening file for writing!\n";
42 F.os().clear_error();
4343 }
4444
4545
358358 int main(int argc, char **argv) {
359359 sys::PrintStackTraceOnErrorSignal();
360360 llvm::PrettyStackTraceProgram X(argc, argv);
361
362 if (AnalyzeOnly && NoOutput) {
363 errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
364 return 1;
365 }
361366
362367 // Enable debug stream buffering.
363368 EnableDebugBuffering = true;
407412 // console, print out a warning message and refuse to do it. We don't
408413 // impress anyone by spewing tons of binary goo to a terminal.
409414 if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly)
410 if (CheckBitcodeOutputToConsole(*Out, !Quiet))
415 if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
411416 NoOutput = true;
412417
413418 // Create a PassManager to hold and optimize the collection of passes we are
483488 if (AnalyzeOnly) {
484489 switch (Kind) {
485490 case PT_BasicBlock:
486 Passes.add(new BasicBlockPassPrinter(PassInf, *Out));
491 Passes.add(new BasicBlockPassPrinter(PassInf, Out->os()));
487492 break;
488493 case PT_Loop:
489 Passes.add(new LoopPassPrinter(PassInf, *Out));
494 Passes.add(new LoopPassPrinter(PassInf, Out->os()));
490495 break;
491496 case PT_Function:
492 Passes.add(new FunctionPassPrinter(PassInf, *Out));
497 Passes.add(new FunctionPassPrinter(PassInf, Out->os()));
493498 break;
494499 case PT_CallGraphSCC:
495 Passes.add(new CallGraphSCCPassPrinter(PassInf, *Out));
500 Passes.add(new CallGraphSCCPassPrinter(PassInf, Out->os()));
496501 break;
497502 default:
498 Passes.add(new ModulePassPrinter(PassInf, *Out));
503 Passes.add(new ModulePassPrinter(PassInf, Out->os()));
499504 break;
500505 }
501506 }
535540 // Write bitcode or assembly to the output as the last step...
536541 if (!NoOutput && !AnalyzeOnly) {
537542 if (OutputAssembly)
538 Passes.add(createPrintModulePass(Out.get()));
543 Passes.add(createPrintModulePass(&Out->os()));
539544 else
540 Passes.add(createBitcodeWriterPass(*Out));
545 Passes.add(createBitcodeWriterPass(Out->os()));
541546 }
542547
543548 // Now that we have all of the passes ready, run them.
7777 return 1;
7878 }
7979
80 OutStream.write(In->getBufferStart(), In->getBufferSize());
80 OutStream.os().write(In->getBufferStart(), In->getBufferSize());
8181
8282 // Declare success.
8383 OutStream.keep();
225225 try {
226226 switch (Action) {
227227 case PrintRecords:
228 Out << Records; // No argument, dump all contents
228 Out.os() << Records; // No argument, dump all contents
229229 break;
230230 case GenEmitter:
231 CodeEmitterGen(Records).run(Out);
231 CodeEmitterGen(Records).run(Out.os());
232232 break;
233233
234234 case GenRegisterEnums:
235 RegisterInfoEmitter(Records).runEnums(Out);
235 RegisterInfoEmitter(Records).runEnums(Out.os());
236236 break;
237237 case GenRegister:
238 RegisterInfoEmitter(Records).run(Out);
238 RegisterInfoEmitter(Records).run(Out.os());
239239 break;
240240 case GenRegisterHeader:
241 RegisterInfoEmitter(Records).runHeader(Out);
241 RegisterInfoEmitter(Records).runHeader(Out.os());
242242 break;
243243 case GenInstrEnums:
244 InstrEnumEmitter(Records).run(Out);
244 InstrEnumEmitter(Records).run(Out.os());
245245 break;
246246 case GenInstrs:
247 InstrInfoEmitter(Records).run(Out);
247 InstrInfoEmitter(Records).run(Out.os());
248248 break;
249249 case GenCallingConv:
250 CallingConvEmitter(Records).run(Out);
250 CallingConvEmitter(Records).run(Out.os());
251251 break;
252252 case GenAsmWriter:
253 AsmWriterEmitter(Records).run(Out);
253 AsmWriterEmitter(Records).run(Out.os());
254254 break;
255255 case GenARMDecoder:
256 ARMDecoderEmitter(Records).run(Out);
256 ARMDecoderEmitter(Records).run(Out.os());
257257 break;
258258 case GenAsmMatcher:
259 AsmMatcherEmitter(Records).run(Out);
259 AsmMatcherEmitter(Records).run(Out.os());
260260 break;
261261 case GenClangAttrClasses:
262 ClangAttrClassEmitter(Records).run(Out);
262 ClangAttrClassEmitter(Records).run(Out.os());
263263 break;
264264 case GenClangAttrImpl:
265 ClangAttrImplEmitter(Records).run(Out);
265 ClangAttrImplEmitter(Records).run(Out.os());
266266 break;
267267 case GenClangAttrList:
268 ClangAttrListEmitter(Records).run(Out);
268 ClangAttrListEmitter(Records).run(Out.os());
269269 break;
270270 case GenClangAttrPCHRead:
271 ClangAttrPCHReadEmitter(Records).run(Out);
271 ClangAttrPCHReadEmitter(Records).run(Out.os());
272272 break;
273273 case GenClangAttrPCHWrite:
274 ClangAttrPCHWriteEmitter(Records).run(Out);
274 ClangAttrPCHWriteEmitter(Records).run(Out.os());
275275 break;
276276 case GenClangDiagsDefs:
277 ClangDiagsDefsEmitter(Records, ClangComponent).run(Out);
277 ClangDiagsDefsEmitter(Records, ClangComponent).run(Out.os());
278278 break;
279279 case GenClangDiagGroups:
280 ClangDiagGroupsEmitter(Records).run(Out);
280 ClangDiagGroupsEmitter(Records).run(Out.os());
281281 break;
282282 case GenClangDeclNodes:
283 ClangASTNodesEmitter(Records, "Decl", "Decl").run(Out);
284 ClangDeclContextEmitter(Records).run(Out);
283 ClangASTNodesEmitter(Records, "Decl", "Decl").run(Out.os());
284 ClangDeclContextEmitter(Records).run(Out.os());
285285 break;
286286 case GenClangStmtNodes:
287 ClangASTNodesEmitter(Records, "Stmt", "").run(Out);
287 ClangASTNodesEmitter(Records, "Stmt", "").run(Out.os());
288288 break;
289289 case GenDisassembler:
290 DisassemblerEmitter(Records).run(Out);
290 DisassemblerEmitter(Records).run(Out.os());
291291 break;
292292 case GenOptParserDefs:
293 OptParserEmitter(Records, true).run(Out);
293 OptParserEmitter(Records, true).run(Out.os());
294294 break;
295295 case GenOptParserImpl:
296 OptParserEmitter(Records, false).run(Out);
296 OptParserEmitter(Records, false).run(Out.os());
297297 break;
298298 case GenDAGISel:
299 DAGISelEmitter(Records).run(Out);
299 DAGISelEmitter(Records).run(Out.os());
300300 break;
301301 case GenFastISel:
302 FastISelEmitter(Records).run(Out);
302 FastISelEmitter(Records).run(Out.os());
303303 break;
304304 case GenSubtarget:
305 SubtargetEmitter(Records).run(Out);
305 SubtargetEmitter(Records).run(Out.os());
306306 break;
307307 case GenIntrinsic:
308 IntrinsicEmitter(Records).run(Out);
308 IntrinsicEmitter(Records).run(Out.os());
309309 break;
310310 case GenTgtIntrinsic:
311 IntrinsicEmitter(Records, true).run(Out);
311 IntrinsicEmitter(Records, true).run(Out.os());
312312 break;
313313 case GenLLVMCConf:
314 LLVMCConfigurationEmitter(Records).run(Out);
314 LLVMCConfigurationEmitter(Records).run(Out.os());
315315 break;
316316 case GenEDInfo:
317 EDEmitter(Records).run(Out);
317 EDEmitter(Records).run(Out.os());
318318 break;
319319 case GenArmNeon:
320 NeonEmitter(Records).run(Out);
320 NeonEmitter(Records).run(Out.os());
321321 break;
322322 case GenArmNeonSema:
323 NeonEmitter(Records).runHeader(Out);
323 NeonEmitter(Records).runHeader(Out.os());
324324 break;
325325 case PrintEnums:
326326 {
327327 std::vector Recs = Records.getAllDerivedDefinitions(Class);
328328 for (unsigned i = 0, e = Recs.size(); i != e; ++i)
329 Out << Recs[i]->getName() << ", ";
330 Out << "\n";
329 Out.os() << Recs[i]->getName() << ", ";
330 Out.os() << "\n";
331331 break;
332332 }
333333 default: