[cfe-commits] r57948 - /cfe/trunk/Driver/Backend.cpp

Daniel Dunbar daniel at zuster.org
Tue Oct 21 20:28:14 PDT 2008


Author: ddunbar
Date: Tue Oct 21 22:28:13 2008
New Revision: 57948

URL: http://llvm.org/viewvc/llvm-project?rev=57948&view=rev
Log:
Update to use raw_ostream for PrintModulePass.
 - Stop playing fast and loose with the std stream.

Modified:
    cfe/trunk/Driver/Backend.cpp

Modified: cfe/trunk/Driver/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/Backend.cpp?rev=57948&r1=57947&r2=57948&view=diff

==============================================================================
--- cfe/trunk/Driver/Backend.cpp (original)
+++ cfe/trunk/Driver/Backend.cpp Tue Oct 21 22:28:13 2008
@@ -46,6 +46,7 @@
     llvm::Module *TheModule;
     llvm::TargetData *TheTargetData;
     llvm::raw_ostream *AsmOutStream;
+    std::ostream *AsmStdOutStream;
 
     mutable FunctionPassManager *CodeGenPasses;
     mutable PassManager *PerModulePasses;
@@ -78,13 +79,16 @@
       InputFile(infile), 
       OutputFile(outfile), 
       Gen(CreateLLVMCodeGen(Diags, Features, InputFile, GenerateDebugInfo)),
-      TheModule(0), TheTargetData(0), AsmOutStream(0),
+      TheModule(0), TheTargetData(0), 
+      AsmOutStream(0), AsmStdOutStream(0),
       CodeGenPasses(0), PerModulePasses(0), PerFunctionPasses(0) {}
 
     ~BackendConsumer() {
       // FIXME: Move out of destructor.
       EmitAssembly();
 
+      if (AsmStdOutStream != llvm::cout.stream())
+        delete AsmStdOutStream;
       delete AsmOutStream;
       delete TheTargetData;
       delete TheModule;
@@ -165,11 +169,8 @@
   // This is ridiculous.
   // FIXME: These aren't being release for now. I'm just going to fix
   // things to use raw_ostream instead.
-  std::ostream *AsmStdOutStream = 0;
-  OStream *AsmLLVMOutStream = 0;
   if (OutputFile == "-" || (InputFile == "-" && OutputFile.empty())) {
     AsmStdOutStream = llvm::cout.stream();
-    AsmLLVMOutStream = &llvm::cout;
     AsmOutStream = new raw_stdout_ostream();
     sys::Program::ChangeStdoutToBinary();
   } else {
@@ -192,7 +193,6 @@
     AsmStdOutStream = new std::ofstream(OutputFile.c_str(),
                                         (std::ios_base::binary | 
                                          std::ios_base::out));
-    AsmLLVMOutStream = new OStream(AsmStdOutStream);
     AsmOutStream = new raw_os_ostream(*AsmStdOutStream);
     if (!Error.empty())
       return false;
@@ -201,7 +201,7 @@
   if (Action == Backend_EmitBC) {
     getPerModulePasses()->add(CreateBitcodeWriterPass(*AsmStdOutStream));
   } else if (Action == Backend_EmitLL) {
-    getPerModulePasses()->add(createPrintModulePass(AsmLLVMOutStream));
+    getPerModulePasses()->add(createPrintModulePass(AsmOutStream));
   } else {
     // From llvm-gcc:
     // If there are passes we have to run on the entire module, we do codegen





More information about the cfe-commits mailing list