[llvm-commits] [llvm] r79807 - in /llvm/trunk: 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

Chris Lattner sabre at nondot.org
Sat Aug 22 19:51:22 PDT 2009


Author: lattner
Date: Sat Aug 22 21:51:22 2009
New Revision: 79807

URL: http://llvm.org/viewvc/llvm-project?rev=79807&view=rev
Log:
Change raw_fd_ostream to take flags as an optional bitmask 
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).



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

Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Sat Aug 22 21:51:22 2009
@@ -334,19 +334,32 @@
   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.

Modified: llvm/trunk/lib/CodeGen/MachineVerifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineVerifier.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/MachineVerifier.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineVerifier.cpp Sat Aug 22 21:51:22 2009
@@ -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 @@
     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 @@
 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 @@
   }
   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 @@
 
 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"

Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Sat Aug 22 21:51:22 2009
@@ -322,8 +322,12 @@
 /// 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 @@
     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() {
-  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;

Modified: llvm/trunk/tools/bugpoint/ExtractFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ExtractFunction.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/ExtractFunction.cpp (original)
+++ llvm/trunk/tools/bugpoint/ExtractFunction.cpp Sat Aug 22 21:51:22 2009
@@ -336,9 +336,8 @@
   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

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Sat Aug 22 21:51:22 2009
@@ -362,10 +362,9 @@
     (*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());

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Sat Aug 22 21:51:22 2009
@@ -137,8 +137,10 @@
     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 @@
   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)

Modified: llvm/trunk/tools/llvm-as/llvm-as.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-as/llvm-as.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-as/llvm-as.cpp (original)
+++ llvm/trunk/tools/llvm-as/llvm-as.cpp Sat Aug 22 21:51:22 2009
@@ -58,88 +58,64 @@
   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;
 }
 

Modified: llvm/trunk/tools/llvm-dis/llvm-dis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dis/llvm-dis.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-dis/llvm-dis.cpp (original)
+++ llvm/trunk/tools/llvm-dis/llvm-dis.cpp Sat Aug 22 21:51:22 2009
@@ -50,90 +50,70 @@
   
   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));
-      }
-    }
-
-    // All that llvm-dis does is write the assembly to a file.
-    if (!DontPrint) {
-      PassManager Passes;
-      Passes.add(createPrintModulePass(Out));
-      Passes.run(*M.get());
+      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;
+  }
 
-    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";
+  // Make sure that the Out file gets unlinked from the disk if we get a
+  // SIGINT.
+  if (OutputFilename != "-")
+    sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+
+  // 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;
 }
 

Modified: llvm/trunk/tools/llvm-extract/llvm-extract.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-extract/llvm-extract.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-extract/llvm-extract.cpp (original)
+++ llvm/trunk/tools/llvm-extract/llvm-extract.cpp Sat Aug 22 21:51:22 2009
@@ -114,8 +114,9 @@
 
   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)

Modified: llvm/trunk/tools/llvm-ld/llvm-ld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ld/llvm-ld.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-ld/llvm-ld.cpp (original)
+++ llvm/trunk/tools/llvm-ld/llvm-ld.cpp Sat Aug 22 21:51:22 2009
@@ -229,8 +229,8 @@
 
   // 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 @@
 
   // 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);
 

Modified: llvm/trunk/tools/llvm-link/llvm-link.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp Sat Aug 22 21:51:22 2009
@@ -122,8 +122,9 @@
   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)

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Sat Aug 22 21:51:22 2009
@@ -174,16 +174,18 @@
 }
 
 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)

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Sat Aug 22 21:51:22 2009
@@ -178,9 +178,8 @@
     // 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;

Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Sat Aug 22 21:51:22 2009
@@ -376,8 +376,9 @@
     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)

Modified: llvm/trunk/utils/FileUpdate/FileUpdate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileUpdate/FileUpdate.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/utils/FileUpdate/FileUpdate.cpp (original)
+++ llvm/trunk/utils/FileUpdate/FileUpdate.cpp Sat Aug 22 21:51:22 2009
@@ -65,8 +65,8 @@
   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';

Modified: llvm/trunk/utils/TableGen/TableGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TableGen.cpp?rev=79807&r1=79806&r2=79807&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/TableGen.cpp (original)
+++ llvm/trunk/utils/TableGen/TableGen.cpp Sat Aug 22 21:51:22 2009
@@ -171,8 +171,8 @@
   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 





More information about the llvm-commits mailing list