Change raw_fd_ostream to take flags as an optional bitmask
authorChris Lattner <sabre@nondot.org>
Sun, 23 Aug 2009 02:51:22 +0000 (02:51 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 23 Aug 2009 02:51:22 +0000 (02:51 +0000)
instead of as two bools.  Use this to add a F_Append flag
which has the obvious behavior.

Other unrelated changes conflated into this patch:

1. REmove EH stuff from llvm-dis and llvm-as, the try blocks
   are dead.
2. Simplify the filename inference code in llvm-as/llvm-dis,
   because raw_fd_ostream does the right thing with '-'.
3. Switch machine verifier to use raw_ostream instead of ostream
   (Which is the thing that needed append in the first place).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79807 91177308-0d34-0410-b5e6-96231b3b80d8

16 files changed:
include/llvm/Support/raw_ostream.h
lib/CodeGen/MachineVerifier.cpp
lib/Support/raw_ostream.cpp
tools/bugpoint/ExtractFunction.cpp
tools/gold/gold-plugin.cpp
tools/llc/llc.cpp
tools/llvm-as/llvm-as.cpp
tools/llvm-dis/llvm-dis.cpp
tools/llvm-extract/llvm-extract.cpp
tools/llvm-ld/llvm-ld.cpp
tools/llvm-link/llvm-link.cpp
tools/llvm-mc/llvm-mc.cpp
tools/lto/LTOCodeGenerator.cpp
tools/opt/opt.cpp
utils/FileUpdate/FileUpdate.cpp
utils/TableGen/TableGen.cpp

index c9a8787429f9aaeec84c0d851d7b763626d2b450..d9d023cc27350e95cea8f9ebab74ebc657c65897 100644 (file)
@@ -334,19 +334,32 @@ class raw_fd_ostream : public raw_ostream {
   virtual size_t preferred_buffer_size();
 
 public:
-  /// raw_fd_ostream - Open the specified file for writing. If an
-  /// error occurs, information about the error is put into ErrorInfo,
-  /// and the stream should be immediately destroyed; the string will
-  /// be empty if no error occurred.
+  
+  enum {
+    /// F_Force - When opening a file, this flag makes raw_fd_ostream overwrite
+    /// a file if it already exists instead of emitting an error.   This may not
+    /// be specified with F_Append.
+    F_Force  = 1,
+
+    /// F_Append - When opening a file, if it already exists append to the
+    /// existing file instead of returning an error.  This may not be specified
+    /// with F_Force.
+    F_Append = 2,
+
+    /// F_Binary - The file should be opened in binary mode on platforms that
+    /// support this distinction.
+    F_Binary = 4
+  };
+  
+  /// raw_fd_ostream - Open the specified file for writing. If an error occurs,
+  /// information about the error is put into ErrorInfo, and the stream should
+  /// be immediately destroyed; the string will be empty if no error occurred.
+  /// This allows optional flags to control how the file will be opened.
   ///
   /// \param Filename - The file to open. If this is "-" then the
   /// stream will use stdout instead.
-  /// \param Binary - The file should be opened in binary mode on
-  /// platforms that support this distinction.
-  /// \param Force - Don't consider the case where the file already
-  /// exists to be an error.
-  raw_fd_ostream(const char *Filename, bool Binary, bool Force,
-                 std::string &ErrorInfo);
+  raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
+                 unsigned Flags = 0);
 
   /// raw_fd_ostream ctor - FD is the file descriptor that this writes to.  If
   /// ShouldClose is true, this closes the file when the stream is destroyed.
index 238f90568fc56174ceed5745705d16df9f2be607..ea2f8279d742d89c13983126646e71a2c53c914e 100644 (file)
@@ -39,8 +39,6 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
-#include <fstream>
-
 using namespace llvm;
 
 namespace {
@@ -65,7 +63,7 @@ namespace {
     const bool allowPhysDoubleDefs;
 
     const char *const OutFileName;
-    std::ostream *OS;
+    raw_ostream *OS;
     const MachineFunction *MF;
     const TargetMachine *TM;
     const TargetRegisterInfo *TRI;
@@ -173,21 +171,24 @@ static RegisterPass<MachineVerifier>
 MachineVer("machineverifier", "Verify generated machine code");
 static const PassInfo *const MachineVerifyID = &MachineVer;
 
-FunctionPass *
-llvm::createMachineVerifierPass(bool allowPhysDoubleDefs)
-{
+FunctionPass *llvm::createMachineVerifierPass(bool allowPhysDoubleDefs) {
   return new MachineVerifier(allowPhysDoubleDefs);
 }
 
-bool
-MachineVerifier::runOnMachineFunction(MachineFunction &MF)
-{
-  std::ofstream OutFile;
+bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
+  raw_ostream *OutFile = 0;
   if (OutFileName) {
-    OutFile.open(OutFileName, std::ios::out | std::ios::app);
-    OS = &OutFile;
+    std::string ErrorInfo;
+    OutFile = new raw_fd_ostream(OutFileName, ErrorInfo,
+                                 raw_fd_ostream::F_Append);
+    if (!ErrorInfo.empty()) {
+      errs() << "Error opening '" << OutFileName << "': " << ErrorInfo << '\n';
+      exit(1);
+    }
+    
+    OS = OutFile;
   } else {
-    OS = cerr.stream();
+    OS = &errs();
   }
 
   foundErrors = 0;
@@ -212,14 +213,10 @@ MachineVerifier::runOnMachineFunction(MachineFunction &MF)
   }
   visitMachineFunctionAfter();
 
-  if (OutFileName)
-    OutFile.close();
-  else if (foundErrors) {
-    std::string msg;
-    raw_string_ostream Msg(msg);
-    Msg << "Found " << foundErrors << " machine code errors.";
-    llvm_report_error(Msg.str());
-  }
+  if (OutFile)
+    delete OutFile;
+  else if (foundErrors)
+    llvm_report_error("Found "+Twine(foundErrors)+" machine code errors.");
 
   // Clean up.
   regsLive.clear();
@@ -234,7 +231,7 @@ MachineVerifier::runOnMachineFunction(MachineFunction &MF)
 
 void MachineVerifier::report(const char *msg, const MachineFunction *MF) {
   assert(MF);
-  *OS << "\n";
+  *OS << '\n';
   if (!foundErrors++)
     MF->print(*OS);
   *OS << "*** Bad machine code: " << msg << " ***\n"
index 94507bd67ba004b65ffb2fee6377dc3980962432..2e151118d6a31c29be6ce2fa8dc10c50d797f847 100644 (file)
@@ -322,8 +322,12 @@ void format_object_base::home() {
 /// occurs, information about the error is put into ErrorInfo, and the
 /// stream should be immediately destroyed; the string will be empty
 /// if no error occurred.
-raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force,
-                               std::string &ErrorInfo) : pos(0) {
+raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
+                               unsigned Flags) : pos(0) {
+  // Verify that we don't have both "append" and "force".
+  assert((!(Flags & F_Force) || !(Flags & F_Append)) &&
+         "Cannot specify both 'force' and 'append' file creation flags!");
+  
   ErrorInfo.clear();
 
   // Handle "-" as stdout.
@@ -331,20 +335,26 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force,
     FD = STDOUT_FILENO;
     // If user requested binary then put stdout into binary mode if
     // possible.
-    if (Binary)
+    if (Flags & F_Binary)
       sys::Program::ChangeStdoutToBinary();
     ShouldClose = false;
     return;
   }
   
-  int Flags = O_WRONLY|O_CREAT|O_TRUNC;
+  int OpenFlags = O_WRONLY|O_CREAT;
 #ifdef O_BINARY
   if (Binary)
-    Flags |= O_BINARY;
+    OpenFlags |= O_BINARY;
 #endif
-  if (!Force)
-    Flags |= O_EXCL;
-  FD = open(Filename, Flags, 0664);
+  
+  if (Flags & F_Force)
+    OpenFlags |= O_TRUNC;
+  else if (Flags & F_Append)
+    OpenFlags |= O_APPEND;
+  else
+    OpenFlags |= O_EXCL;
+  
+  FD = open(Filename, OpenFlags, 0664);
   if (FD < 0) {
     ErrorInfo = "Error opening output file '" + std::string(Filename) + "'";
     ShouldClose = false;
@@ -354,14 +364,14 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force,
 }
 
 raw_fd_ostream::~raw_fd_ostream() {
-  if (FD >= 0) {
-    flush();
-    if (ShouldClose)
-      if (::close(FD) != 0)
-        error_detected();
-  }
+  if (FD < 0) return;
+  flush();
+  if (ShouldClose)
+    if (::close(FD) != 0)
+      error_detected();
 }
 
+
 void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
   assert (FD >= 0 && "File already closed.");
   pos += Size;
index 9fdcc1bdea2c6f3afeff0a3859a59f63308e3f12..b2e427c9bfb77988ed541ea9482e011ff10c183e 100644 (file)
@@ -336,9 +336,8 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const
   sys::RemoveFileOnSignal(uniqueFilename);
 
   std::string ErrorInfo;
-  raw_fd_ostream BlocksToNotExtractFile(uniqueFilename.c_str(),
-                                        /*Binary=*/false, /*Force=*/true,
-                                        ErrorInfo);
+  raw_fd_ostream BlocksToNotExtractFile(uniqueFilename.c_str(), ErrorInfo,
+                                        raw_fd_ostream::F_Force);
   if (!ErrorInfo.empty()) {
     outs() << "*** Basic Block extraction failed!\n";
     errs() << "Error writing list of blocks to not extract: " << ErrorInfo
index 9554b8adc314b55c4df3ae050c0853a793a0caab..16b3471853aa57da8bda395c22fa5c15dd505070 100644 (file)
@@ -362,10 +362,9 @@ ld_plugin_status all_symbols_read_hook(void) {
     (*message)(LDPL_ERROR, "%s", ErrMsg.c_str());
     return LDPS_ERR;
   }
-  raw_fd_ostream *objFile = new raw_fd_ostream(uniqueObjPath.c_str(),
-                                               /*Binary=*/true,
-                                               /*Force=*/true,
-                                               ErrMsg);
+  raw_fd_ostream *objFile = 
+    new raw_fd_ostream(uniqueObjPath.c_str(), ErrMsg,
+                       raw_fd_ostream::F_Force|raw_fd_ostream::F_Binary);
   if (!ErrMsg.empty()) {
     delete objFile;
     (*message)(LDPL_ERROR, "%s", ErrMsg.c_str());
index cbc1d7b1add9ea60b3e5799641761f1969489f76..423cf471ee2d807e4cc4ded00f60036f922e9984 100644 (file)
@@ -137,8 +137,10 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
     sys::RemoveFileOnSignal(sys::Path(OutputFilename));
 
     std::string error;
-    raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(),
-                                               /*Binary=*/true, Force, error);
+    raw_fd_ostream *FDOut =
+      new raw_fd_ostream(OutputFilename.c_str(), error,
+                         (Force ? raw_fd_ostream::F_Force : 0)|
+                         raw_fd_ostream::F_Binary);
     if (!error.empty()) {
       errs() << error << '\n';
       if (!Force)
@@ -187,8 +189,11 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
   sys::RemoveFileOnSignal(sys::Path(OutputFilename));
 
   std::string error;
-  raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(),
-                                             Binary, Force, error);
+  unsigned OpenFlags = 0;
+  if (Force) OpenFlags |= raw_fd_ostream::F_Force;
+  if (Binary) OpenFlags |= raw_fd_ostream::F_Binary;
+  raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(), error,
+                                             OpenFlags);
   if (!error.empty()) {
     errs() << error << '\n';
     if (!Force)
index 942dbebfa17015bcec69cc006cb92c574e13330b..06b3ad254ee65af03732c7577f183f9da8bfc8b8 100644 (file)
@@ -58,88 +58,64 @@ int main(int argc, char **argv) {
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
 
-  int exitCode = 0;
-  raw_ostream *Out = 0;
-  try {
-    // Parse the file now...
-    SMDiagnostic Err;
-    std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, Context));
-    if (M.get() == 0) {
-      Err.Print(argv[0], errs());
-      return 1;
-    }
+  // Parse the file now...
+  SMDiagnostic Err;
+  std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, Context));
+  if (M.get() == 0) {
+    Err.Print(argv[0], errs());
+    return 1;
+  }
 
-    if (!DisableVerify) {
-      std::string Err;
-      if (verifyModule(*M.get(), ReturnStatusAction, &Err)) {
-        errs() << argv[0]
-               << ": assembly parsed, but does not verify as correct!\n";
-        errs() << Err;
-        return 1;
-      
-    }
+  if (!DisableVerify) {
+    std::string Err;
+    if (verifyModule(*M.get(), ReturnStatusAction, &Err)) {
+      errs() << argv[0]
+             << ": assembly parsed, but does not verify as correct!\n";
+      errs() << Err;
+      return 1;
+    } 
+  }
 
-    if (DumpAsm) errs() << "Here's the assembly:\n" << *M.get();
+  if (DumpAsm) errs() << "Here's the assembly:\n" << *M.get();
 
-    if (OutputFilename != "") {   // Specified an output filename?
-      if (OutputFilename != "-") {  // Not stdout?
-        std::string ErrorInfo;
-        Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true,
-                                 Force, ErrorInfo);
-        if (!ErrorInfo.empty()) {
-          errs() << ErrorInfo << '\n';
-          if (!Force)
-            errs() << "Use -f command line argument to force output\n";
-          delete Out;
-          return 1;
-        }
-      } else {                      // Specified stdout
-        // FIXME: outs() is not binary!
-        Out = &outs();
-      }
+  // Infer the output filename if needed.
+  if (OutputFilename.empty()) {
+    if (InputFilename == "-") {
+      OutputFilename = "-";
     } else {
-      if (InputFilename == "-") {
-        OutputFilename = "-";
-        Out = &outs();
+      std::string IFN = InputFilename;
+      int Len = IFN.length();
+      if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
+        // Source ends in .ll
+        OutputFilename = std::string(IFN.begin(), IFN.end()-3);
       } else {
-        std::string IFN = InputFilename;
-        int Len = IFN.length();
-        if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
-          // Source ends in .ll
-          OutputFilename = std::string(IFN.begin(), IFN.end()-3);
-        } else {
-          OutputFilename = IFN;   // Append a .bc to it
-        }
-        OutputFilename += ".bc";
-
-        std::string ErrorInfo;
-        Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true,
-                                 Force, ErrorInfo);
-        if (!ErrorInfo.empty()) {
-          errs() << ErrorInfo << '\n';
-          if (!Force)
-            errs() << "Use -f command line argument to force output\n";
-          delete Out;
-          return 1;
-        }
-        // Make sure that the Out file gets unlinked from the disk if we get a
-        // SIGINT
-        sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+        OutputFilename = IFN;   // Append a .bc to it
       }
+      OutputFilename += ".bc";
     }
-
-    if (!DisableOutput)
-      if (Force || !CheckBitcodeOutputToConsole(Out,true))
-        WriteBitcodeToFile(M.get(), *Out);
-  } catch (const std::string& msg) {
-    errs() << argv[0] << ": " << msg << "\n";
-    exitCode = 1;
-  } catch (...) {
-    errs() << argv[0] << ": Unexpected unknown exception occurred.\n";
-    exitCode = 1;
   }
-
-  if (Out != &outs()) delete Out;
-  return exitCode;
+  
+  std::string ErrorInfo;
+  std::auto_ptr<raw_ostream> Out
+  (new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
+                      (Force?raw_fd_ostream::F_Force : 0) |
+                      raw_fd_ostream::F_Binary));
+  if (!ErrorInfo.empty()) {
+    errs() << ErrorInfo << '\n';
+    if (!Force)
+      errs() << "Use -f command line argument to force output\n";
+    return 1;
+  }
+  
+  
+  // Make sure that the Out file gets unlinked from the disk if we get a
+  // SIGINT.
+  if (OutputFilename != "-")
+    sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+
+  if (!DisableOutput)
+    if (Force || !CheckBitcodeOutputToConsole(Out.get(), true))
+      WriteBitcodeToFile(M.get(), *Out);
+  return 0;
 }
 
index 65e97c37dfcb5776813ffe5bde2e1f9143a765a3..2066fffd2904eb343ed9fc19ce866bbd1e6b363d 100644 (file)
@@ -50,90 +50,70 @@ int main(int argc, char **argv) {
   
   LLVMContext &Context = getGlobalContext();
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
-  try {
-    cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
-
-    raw_ostream *Out = &outs();  // Default to printing to stdout.
-    std::string ErrorMessage;
+  
+  
+  cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
 
-    std::auto_ptr<Module> M;
-   
-    if (MemoryBuffer *Buffer
-           = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
-      M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage));
-      delete Buffer;
-    }
+  std::string ErrorMessage;
+  std::auto_ptr<Module> M;
+  if (MemoryBuffer *Buffer
+         = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
+    M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage));
+    delete Buffer;
+  }
 
-    if (M.get() == 0) {
-      errs() << argv[0] << ": ";
-      if (ErrorMessage.size())
-        errs() << ErrorMessage << "\n";
-      else
-        errs() << "bitcode didn't read correctly.\n";
-      return 1;
-    }
-    
-    if (DontPrint) {
-      // Just use stdout.  We won't actually print anything on it.
-    } else if (OutputFilename != "") {   // Specified an output filename?
-      if (OutputFilename != "-") { // Not stdout?
-        std::string ErrorInfo;
-        Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false,
-                                 Force, ErrorInfo);
-        if (!ErrorInfo.empty()) {
-          errs() << ErrorInfo << '\n';
-          if (!Force)
-            errs() << "Use -f command line argument to force output\n";
-          delete Out;
-          return 1;
-        }
-      }
+  if (M.get() == 0) {
+    errs() << argv[0] << ": ";
+    if (ErrorMessage.size())
+      errs() << ErrorMessage << "\n";
+    else
+      errs() << "bitcode didn't read correctly.\n";
+    return 1;
+  }
+  
+  // Just use stdout.  We won't actually print anything on it.
+  if (DontPrint)
+    OutputFilename = "-";
+  
+  if (OutputFilename.empty()) { // Unspecified output, infer it.
+    if (InputFilename == "-") {
+      OutputFilename = "-";
     } else {
-      if (InputFilename == "-") {
-        OutputFilename = "-";
-      } else {
-        std::string IFN = InputFilename;
-        int Len = IFN.length();
-        if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
-          // Source ends in .bc
-          OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".ll";
-        } else {
-          OutputFilename = IFN+".ll";
-        }
-
-        std::string ErrorInfo;
-        Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false,
-                                 Force, ErrorInfo);
-        if (!ErrorInfo.empty()) {
-          errs() << ErrorInfo << '\n';
-          if (!Force)
-            errs() << "Use -f command line argument to force output\n";
-          delete Out;
-          return 1;
-        }
-
-        // Make sure that the Out file gets unlinked from the disk if we get a
-        // SIGINT
-        sys::RemoveFileOnSignal(sys::Path(OutputFilename));
-      }
+      const std::string &IFN = InputFilename;
+      int Len = IFN.length();
+      // If the source ends in .bc, strip it off.
+      if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c')
+        OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".ll";
+      else
+        OutputFilename = IFN+".ll";
     }
+  }
+  
+  std::string ErrorInfo;
+  std::auto_ptr<raw_fd_ostream> 
+  Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
+                         (Force?raw_fd_ostream::F_Force : 0) |
+                         raw_fd_ostream::F_Binary));
+  if (!ErrorInfo.empty()) {
+    errs() << ErrorInfo << '\n';
+    if (!Force)
+      errs() << "Use -f command line argument to force output\n";
+    return 1;
+  }
 
-    // All that llvm-dis does is write the assembly to a file.
-    if (!DontPrint) {
-      PassManager Passes;
-      Passes.add(createPrintModulePass(Out));
-      Passes.run(*M.get());
-    }
+  // Make sure that the Out file gets unlinked from the disk if we get a
+  // SIGINT.
+  if (OutputFilename != "-")
+    sys::RemoveFileOnSignal(sys::Path(OutputFilename));
 
-    if (Out != &outs())
-      delete Out;
-    return 0;
-  } catch (const std::string& msg) {
-    errs() << argv[0] << ": " << msg << "\n";
-  } catch (...) {
-    errs() << argv[0] << ": Unexpected unknown exception occurred.\n";
+  // All that llvm-dis does is write the assembly to a file.
+  if (!DontPrint) {
+    PassManager Passes;
+    Passes.add(createPrintModulePass(Out.get()));
+    Passes.run(*M.get());
   }
 
-  return 1;
+  return 0;
 }
 
index 6b7846f38e43624192e80cd525352a1d48822a29..16e039bcbfe2699c9f9876dd62c802c1d2ff2750 100644 (file)
@@ -114,8 +114,9 @@ int main(int argc, char **argv) {
 
   if (OutputFilename != "-") {  // Not stdout?
     std::string ErrorInfo;
-    Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true,
-                             Force, ErrorInfo);
+    Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
+                             raw_fd_ostream::F_Binary |
+                             (Force ? raw_fd_ostream::F_Force : 0));
     if (!ErrorInfo.empty()) {
       errs() << ErrorInfo << '\n';
       if (!Force)
index 17035e2a31fe4a47dd3961994986021fa6a7a6aa..f789b15d3a2c87006870f54fc0ad97bdc9d61b6c 100644 (file)
@@ -229,8 +229,8 @@ void GenerateBitcode(Module* M, const std::string& FileName) {
 
   // Create the output file.
   std::string ErrorInfo;
-  raw_fd_ostream Out(FileName.c_str(), /*Binary=*/true, /*Force=*/true,
-                     ErrorInfo);
+  raw_fd_ostream Out(FileName.c_str(), ErrorInfo,
+                     raw_fd_ostream::F_Force | raw_fd_ostream::F_Binary);
   if (!ErrorInfo.empty())
     PrintAndExit(ErrorInfo);
 
@@ -427,8 +427,8 @@ static void EmitShellScript(char **argv) {
 
   // Output the script to start the program...
   std::string ErrorInfo;
-  raw_fd_ostream Out2(OutputFilename.c_str(), /*Binary=*/false, /*Force=*/true,
-                      ErrorInfo);
+  raw_fd_ostream Out2(OutputFilename.c_str(), ErrorInfo,
+                      llvm::raw_fd_ostream::F_Force);
   if (!ErrorInfo.empty())
     PrintAndExit(ErrorInfo);
 
index a287c479a741a96606d47af38077394dd3edfef2..3d10ee3c4d89c3db5b2783d5383cf7f6a4087882 100644 (file)
@@ -122,8 +122,9 @@ int main(int argc, char **argv) {
   raw_ostream *Out = &outs();  // Default to printing to stdout...
   if (OutputFilename != "-") {
     std::string ErrorInfo;
-    Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true,
-                             Force, ErrorInfo);
+    Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
+                             raw_fd_ostream::F_Binary |
+                             (Force ? raw_fd_ostream::F_Force : 0));
     if (!ErrorInfo.empty()) {
       errs() << ErrorInfo << '\n';
       if (!Force)
index 4f5b8a0ba27e13a5709a07bd2b7b8e2eb42251db..af72fbcf49b00e3ea8d92a2de224d58a09746f78 100644 (file)
@@ -174,16 +174,18 @@ static const Target *GetTarget(const char *ProgName) {
 }
 
 static formatted_raw_ostream *GetOutputStream() {
-  if (OutputFilename == "" || OutputFilename == "-")
-    return &fouts();
+  if (OutputFilename == "")
+    OutputFilename = "-";
 
   // Make sure that the Out file gets unlinked from the disk if we get a
-  // SIGINT
-  sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+  // SIGINT.
+  if (OutputFilename != "-")
+    sys::RemoveFileOnSignal(sys::Path(OutputFilename));
 
   std::string Err;
-  raw_fd_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(),
-                                           /*Binary=*/false, Force, Err);
+  raw_fd_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), Err,
+                                           raw_fd_ostream::F_Binary |
+                                         (Force ? raw_fd_ostream::F_Force : 0));
   if (!Err.empty()) {
     errs() << Err << '\n';
     if (!Force)
index f76168e3f539b4e20e71354be73c1d4df9343fbe..36be5231815598147581b8384a26c347b6f21218 100644 (file)
@@ -178,9 +178,8 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
     // generate assembly code
     bool genResult = false;
     {
-      raw_fd_ostream asmFD(uniqueAsmPath.c_str(),
-                           /*Binary=*/false, /*Force=*/true,
-                           errMsg);
+      raw_fd_ostream asmFD(uniqueAsmPath.c_str(), errMsg,
+                           raw_fd_ostream::F_Force);
       formatted_raw_ostream asmFile(asmFD);
       if (!errMsg.empty())
         return NULL;
index 40f3fb930742266f2b9ac3550e3d77599c3415e1..4f241986401729f6839c13b8a6b1c282d76fb8bd 100644 (file)
@@ -376,8 +376,9 @@ int main(int argc, char **argv) {
     raw_ostream *Out = &outs();  // Default to printing to stdout...
     if (OutputFilename != "-") {
       std::string ErrorInfo;
-      Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true,
-                               Force, ErrorInfo);
+      Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
+                               raw_fd_ostream::F_Binary |
+                               (Force ? raw_fd_ostream::F_Force : 0));
       if (!ErrorInfo.empty()) {
         errs() << ErrorInfo << '\n';
         if (!Force)
index 8d5d6b1b905ce776f4d7dbd95605e2787e32baa5..da760e65e8227b0e52a3432106c372d582d3217e 100644 (file)
@@ -65,8 +65,8 @@ int main(int argc, char **argv) {
   if (!Quiet)
     outs() << argv[0] << ": Updating '" << OutputFilename
            << "', contents changed.\n";
-  raw_fd_ostream OutStream(OutputFilename.c_str(), /*Binary=*/true,
-                           /*Force=*/true, ErrorStr);
+  raw_fd_ostream OutStream(OutputFilename.c_str(), ErrorStr,
+                           raw_fd_ostream::F_Force|raw_fd_ostream::F_Binary);
   if (!ErrorStr.empty()) {
     errs() << argv[0] << ": Unable to write output '"
            << OutputFilename << "': " << ErrorStr << '\n';
index 315bb657a07b079072a149e56e2195df041897d3..3e284f941966842192d20b308d976b839b8553b3 100644 (file)
@@ -171,8 +171,8 @@ int main(int argc, char **argv) {
   raw_ostream *Out = &outs();
   if (OutputFilename != "-") {
     std::string Error;
-    Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false,
-                             /*Force=*/true, Error);
+    Out = new raw_fd_ostream(OutputFilename.c_str(), Error,
+                             raw_fd_ostream::F_Force);
 
     if (!Error.empty()) {
       errs() << argv[0] << ": error opening " << OutputFilename