Use raw_ostream throughout the AsmPrinter.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55092 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp
index ad3964d..275aac2 100644
--- a/tools/lto/LTOCodeGenerator.cpp
+++ b/tools/lto/LTOCodeGenerator.cpp
@@ -27,6 +27,7 @@
 #include "llvm/Support/SystemUtils.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Signals.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/LoopPass.h"
@@ -162,9 +163,12 @@
     sys::RemoveFileOnSignal(uniqueAsmPath);
        
     // generate assembly code
-    std::ofstream asmFile(uniqueAsmPath.c_str());
-    bool genResult = this->generateAssemblyCode(asmFile, errMsg);
-    asmFile.close();
+    std::string error;
+    bool genResult = false;
+    {
+      raw_fd_ostream asmFile(uniqueAsmPath.c_str(), error);
+      genResult = this->generateAssemblyCode(asmFile, errMsg);
+    }
     if ( genResult ) {
         if ( uniqueAsmPath.exists() )
             uniqueAsmPath.eraseFromDisk();
@@ -309,7 +313,8 @@
 }
 
 /// Optimize merged modules using various IPO passes
-bool LTOCodeGenerator::generateAssemblyCode(std::ostream& out, std::string& errMsg)
+bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
+                                            std::string& errMsg)
 {
     if (  this->determineTarget(errMsg) ) 
         return true;