[llvm-commits] [llvm] r112706 - in /llvm/trunk: include/llvm/Support/ lib/Support/ tools/bugpoint/ tools/llc/ tools/llvm-as/ tools/llvm-dis/ tools/llvm-extract/ tools/llvm-ld/ tools/llvm-link/ tools/llvm-mc/ tools/lto/ tools/opt/ utils/FileUpdate/ utils/TableGen/

Dan Gohman gohman at apple.com
Wed Sep 1 07:20:41 PDT 2010


Author: djg
Date: Wed Sep  1 09:20:41 2010
New Revision: 112706

URL: http://llvm.org/viewvc/llvm-project?rev=112706&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/Support/FormattedStream.h
    llvm/trunk/include/llvm/Support/raw_ostream.h
    llvm/trunk/lib/Support/FormattedStream.cpp
    llvm/trunk/lib/Support/raw_ostream.cpp
    llvm/trunk/tools/bugpoint/ExtractFunction.cpp
    llvm/trunk/tools/bugpoint/OptimizerDriver.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/lto/LTOCodeGenerator.h
    llvm/trunk/tools/opt/GraphPrinters.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/FormattedStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FormattedStream.h?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FormattedStream.h (original)
+++ llvm/trunk/include/llvm/Support/FormattedStream.h Wed Sep  1 09:20:41 2010
@@ -19,14 +19,10 @@
 
 namespace llvm 
 {
-  class formatted_tool_output_file;
-
   /// formatted_raw_ostream - Formatted raw_fd_ostream to handle
   /// asm-specific constructs.
   ///
   class formatted_raw_ostream : public raw_ostream {
-    friend class formatted_tool_output_file;
-
   public:
     /// DELETE_STREAM - Tell the destructor to delete the held stream.
     ///
@@ -140,38 +136,6 @@
     }
   };
 
-  /// formatted_tool_output_file - This is a subclass of formatted_raw_ostream
-  /// for use when the underlying stream is a tool_output_file. It exposes
-  /// keep() and several other member functions.
-  class formatted_tool_output_file : public formatted_raw_ostream {
-  private:
-    tool_output_file &get_tool_output_file() const {
-      return *static_cast<tool_output_file *>(TheStream);
-    }
-
-  public:
-    formatted_tool_output_file(tool_output_file &Stream, bool Delete = false) 
-      : formatted_raw_ostream(Stream, Delete) {}
-
-    formatted_tool_output_file() {}
-
-    ~formatted_tool_output_file();
-
-    void setStream(tool_output_file &Stream, bool Delete = false) {
-      return formatted_raw_ostream::setStream(Stream, Delete);
-    }
-
-    void keep()            { return get_tool_output_file().keep(); }
-    bool has_error() const { return get_tool_output_file().has_error(); }
-    void clear_error()     { return get_tool_output_file().clear_error(); }
-    void close() {
-      // The inner stream is unbuffered; flush the outer stream's buffer.
-      flush();
-      // The inner stream can close its file descriptor now.
-      return get_tool_output_file().close();
-    }
-  };
-
 /// fouts() - This returns a reference to a formatted_raw_ostream for
 /// standard output.  Use it like: fouts() << "foo" << "bar";
 formatted_raw_ostream &fouts();

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=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Wed Sep  1 09:20:41 2010
@@ -475,23 +475,43 @@
   ~raw_null_ostream();
 };
 
-/// tool_output_file - This class behaves like a raw_fd_ostream but adds a
+/// tool_output_file - This class contains a raw_fd_ostream and adds a
 /// few extra features commonly needed for compiler-like tool output files:
 ///   - The file is automatically deleted if the process is killed.
 ///   - The file is automatically deleted when the tool_output_file
 ///     object is destroyed unless the client calls keep().
-class tool_output_file : public raw_fd_ostream {
-  std::string Filename;
-  bool Keep;
+class tool_output_file {
+  /// Installer - This class is declared before the raw_fd_ostream so that
+  /// it is constructed before the raw_fd_ostream is constructed and
+  /// destructed after the raw_fd_ostream is destructed. It installs
+  /// cleanups in its constructor and uninstalls them in its destructor.
+  class CleanupInstaller {
+    /// Filename - The name of the file.
+    std::string Filename;
+  public:
+    /// Keep - The flag which indicates whether we should not delete the file.
+    bool Keep;
+
+    explicit CleanupInstaller(const char *filename);
+    ~CleanupInstaller();
+  } Installer;
+
+  /// OS - The contained stream. This is intentionally declared after
+  /// Installer.
+  raw_fd_ostream OS;
+
 public:
+  /// tool_output_file - This constructor's arguments are passed to
+  /// to raw_fd_ostream's constructor.
   tool_output_file(const char *filename, std::string &ErrorInfo,
                    unsigned Flags = 0);
 
-  ~tool_output_file();
+  /// os - Return the contained raw_fd_ostream.
+  raw_fd_ostream &os() { return OS; }
 
   /// keep - Indicate that the tool's job wrt this output file has been
   /// successful and the file should not be deleted.
-  void keep() { Keep = true; }
+  void keep() { Installer.Keep = true; }
 };
 
 } // end llvm namespace

Modified: llvm/trunk/lib/Support/FormattedStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FormattedStream.cpp?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FormattedStream.cpp (original)
+++ llvm/trunk/lib/Support/FormattedStream.cpp Wed Sep  1 09:20:41 2010
@@ -98,6 +98,3 @@
   static formatted_raw_ostream S(dbgs());
   return S;
 }
-
-/// ~formatted_tool_output_file - Out-of-line destructor.
-formatted_tool_output_file::~formatted_tool_output_file() {}

Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Wed Sep  1 09:20:41 2010
@@ -670,25 +670,29 @@
 //  tool_output_file
 //===----------------------------------------------------------------------===//
 
-/// SetupRemoveOnSignal - This is a helper for tool_output_file's constructor
-/// to allow the signal handlers to be installed before constructing the
-/// base class raw_fd_ostream.
-static const char *SetupRemoveOnSignal(const char *Filename) {
+tool_output_file::CleanupInstaller::CleanupInstaller(const char *filename)
+  : Filename(filename), Keep(false) {
   // Arrange for the file to be deleted if the process is killed.
-  if (strcmp(Filename, "-") != 0)
+  if (Filename != "-")
     sys::RemoveFileOnSignal(sys::Path(Filename));
-  return Filename;
 }
 
-tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo, 
-                                   unsigned Flags)
-  : raw_fd_ostream(SetupRemoveOnSignal(filename), ErrorInfo, Flags),
-    Filename(filename),
-    Keep(!ErrorInfo.empty() /* If open fails, no cleanup is needed. */) {
-}
-
-tool_output_file::~tool_output_file() {
+tool_output_file::CleanupInstaller::~CleanupInstaller() {
   // Delete the file if the client hasn't told us not to.
   if (!Keep && Filename != "-")
     sys::Path(Filename).eraseFromDisk();
+
+  // Ok, the file is successfully written and closed, or deleted. There's no
+  // further need to clean it up on signals.
+  if (Filename != "-")
+    sys::DontRemoveFileOnSignal(sys::Path(Filename));
+}
+
+tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
+                                   unsigned Flags)
+  : Installer(filename),
+    OS(filename, ErrorInfo, Flags) {
+  // If open fails, no cleanup is needed.
+  if (!ErrorInfo.empty())
+    Installer.Keep = true;
 }

Modified: llvm/trunk/tools/bugpoint/ExtractFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ExtractFunction.cpp?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/ExtractFunction.cpp (original)
+++ llvm/trunk/tools/bugpoint/ExtractFunction.cpp Wed Sep  1 09:20:41 2010
@@ -339,15 +339,15 @@
     // If the BB doesn't have a name, give it one so we have something to key
     // off of.
     if (!BB->hasName()) BB->setName("tmpbb");
-    BlocksToNotExtractFile << BB->getParent()->getNameStr() << " "
-                           << BB->getName() << "\n";
+    BlocksToNotExtractFile.os() << BB->getParent()->getNameStr() << " "
+                                << BB->getName() << "\n";
   }
-  BlocksToNotExtractFile.close();
-  if (BlocksToNotExtractFile.has_error()) {
+  BlocksToNotExtractFile.os().close();
+  if (BlocksToNotExtractFile.os().has_error()) {
     errs() << "Error writing list of blocks to not extract: " << ErrorInfo
            << "\n";
     EmitProgressBitcode(M, "basicblockextractfail", true);
-    BlocksToNotExtractFile.clear_error();
+    BlocksToNotExtractFile.os().clear_error();
     return 0;
   }
   BlocksToNotExtractFile.keep();

Modified: llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/OptimizerDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/OptimizerDriver.cpp Wed Sep  1 09:20:41 2010
@@ -58,14 +58,14 @@
   tool_output_file Out(Filename.c_str(), ErrInfo,
                        raw_fd_ostream::F_Binary);
   if (ErrInfo.empty()) {
-    WriteBitcodeToFile(M, Out);
-    Out.close();
-    if (!Out.has_error()) {
+    WriteBitcodeToFile(M, Out.os());
+    Out.os().close();
+    if (!Out.os().has_error()) {
       Out.keep();
       return false;
     }
   }
-  Out.clear_error();
+  Out.os().clear_error();
   return true;
 }
 
@@ -140,11 +140,11 @@
     errs() << "Error opening bitcode file: " << inputFilename.str() << "\n";
     return 1;
   }
-  WriteBitcodeToFile(Program, InFile);
-  InFile.close();
-  if (InFile.has_error()) {
+  WriteBitcodeToFile(Program, InFile.os());
+  InFile.os().close();
+  if (InFile.os().has_error()) {
     errs() << "Error writing bitcode file: " << inputFilename.str() << "\n";
-    InFile.clear_error();
+    InFile.os().clear_error();
     return 1;
   }
   InFile.keep();

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Wed Sep  1 09:20:41 2010
@@ -123,9 +123,9 @@
   return outputFilename;
 }
 
-static formatted_tool_output_file *GetOutputStream(const char *TargetName,
-                                                   Triple::OSType OS,
-                                                   const char *ProgName) {
+static tool_output_file *GetOutputStream(const char *TargetName,
+                                         Triple::OSType OS,
+                                         const char *ProgName) {
   // If we don't yet have an output filename, make one.
   if (OutputFilename.empty()) {
     if (InputFilename == "-")
@@ -183,11 +183,7 @@
     return 0;
   }
 
-  formatted_tool_output_file *Out =
-    new formatted_tool_output_file(*FDOut,
-                                   formatted_raw_ostream::DELETE_STREAM);
-
-  return Out;
+  return FDOut;
 }
 
 // main - Entry point for the llc compiler.
@@ -278,7 +274,7 @@
   TargetMachine &Target = *target.get();
 
   // Figure out where we are going to send the output...
-  OwningPtr<formatted_tool_output_file> Out
+  OwningPtr<tool_output_file> Out
     (GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]));
   if (!Out) return 1;
 
@@ -314,15 +310,18 @@
       Target.setMCRelaxAll(true);
   }
 
-  // Ask the target to add backend passes as necessary.
-  if (Target.addPassesToEmitFile(PM, *Out, FileType, OLvl,
-                                 NoVerify)) {
-    errs() << argv[0] << ": target does not support generation of this"
-           << " file type!\n";
-    return 1;
-  }
+  {
+    formatted_raw_ostream FOS(Out->os());
 
-  PM.run(mod);
+    // Ask the target to add backend passes as necessary.
+    if (Target.addPassesToEmitFile(PM, FOS, FileType, OLvl, NoVerify)) {
+      errs() << argv[0] << ": target does not support generation of this"
+             << " file type!\n";
+      return 1;
+    }
+
+    PM.run(mod);
+  }
 
   // Declare success.
   Out->keep();

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=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-as/llvm-as.cpp (original)
+++ llvm/trunk/tools/llvm-as/llvm-as.cpp Wed Sep  1 09:20:41 2010
@@ -77,8 +77,8 @@
     exit(1);
   }
 
-  if (Force || !CheckBitcodeOutputToConsole(*Out, true))
-    WriteBitcodeToFile(M, *Out);
+  if (Force || !CheckBitcodeOutputToConsole(Out->os(), true))
+    WriteBitcodeToFile(M, Out->os());
 
   // Declare success.
   Out->keep();

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=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dis/llvm-dis.cpp (original)
+++ llvm/trunk/tools/llvm-dis/llvm-dis.cpp Wed Sep  1 09:20:41 2010
@@ -98,7 +98,7 @@
 
   // All that llvm-dis does is write the assembly to a file.
   if (!DontPrint)
-    *Out << *M;
+    Out->os() << *M;
 
   // Declare success.
   Out->keep();

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=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-extract/llvm-extract.cpp (original)
+++ llvm/trunk/tools/llvm-extract/llvm-extract.cpp Wed Sep  1 09:20:41 2010
@@ -134,9 +134,9 @@
   }
 
   if (OutputAssembly)
-    Passes.add(createPrintModulePass(&Out));
-  else if (Force || !CheckBitcodeOutputToConsole(Out, true))
-    Passes.add(createBitcodeWriterPass(Out));
+    Passes.add(createPrintModulePass(&Out.os()));
+  else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
+    Passes.add(createBitcodeWriterPass(Out.os()));
 
   Passes.run(*M.get());
 

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=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ld/llvm-ld.cpp (original)
+++ llvm/trunk/tools/llvm-ld/llvm-ld.cpp Wed Sep  1 09:20:41 2010
@@ -244,7 +244,7 @@
   }
 
   // Write it out
-  WriteBitcodeToFile(M, Out);
+  WriteBitcodeToFile(M, Out.os());
   Out.keep();
 }
 
@@ -432,10 +432,10 @@
   if (!ErrorInfo.empty())
     PrintAndExit(ErrorInfo, M);
 
-  Out2 << "#!/bin/sh\n";
+  Out2.os() << "#!/bin/sh\n";
   // Allow user to setenv LLVMINTERP if lli is not in their PATH.
-  Out2 << "lli=${LLVMINTERP-lli}\n";
-  Out2 << "exec $lli \\\n";
+  Out2.os() << "lli=${LLVMINTERP-lli}\n";
+  Out2.os() << "exec $lli \\\n";
   // gcc accepts -l<lib> and implicitly searches /lib and /usr/lib.
   LibPaths.push_back("/lib");
   LibPaths.push_back("/usr/lib");
@@ -466,9 +466,9 @@
     if (FullLibraryPath.isEmpty())
       FullLibraryPath = sys::Path::FindLibrary(*i);
     if (!FullLibraryPath.isEmpty())
-      Out2 << "    -load=" << FullLibraryPath.str() << " \\\n";
+      Out2.os() << "    -load=" << FullLibraryPath.str() << " \\\n";
   }
-  Out2 << "    "  << BitcodeOutputFilename << " ${1+\"$@\"}\n";
+  Out2.os() << "    "  << BitcodeOutputFilename << " ${1+\"$@\"}\n";
   Out2.keep();
 }
 

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=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp Wed Sep  1 09:20:41 2010
@@ -130,9 +130,9 @@
 
   if (Verbose) errs() << "Writing bitcode...\n";
   if (OutputAssembly) {
-    Out << *Composite;
-  } else if (Force || !CheckBitcodeOutputToConsole(Out, true))
-    WriteBitcodeToFile(Composite.get(), Out);
+    Out.os() << *Composite;
+  } else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
+    WriteBitcodeToFile(Composite.get(), Out.os());
 
   // Declare success.
   Out.keep();

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=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Wed Sep  1 09:20:41 2010
@@ -140,7 +140,7 @@
   return 0;
 }
 
-static formatted_tool_output_file *GetOutputStream() {
+static tool_output_file *GetOutputStream() {
   if (OutputFilename == "")
     OutputFilename = "-";
 
@@ -152,9 +152,8 @@
     delete Out;
     return 0;
   }
-  
-  return new formatted_tool_output_file(*Out,
-                                        formatted_raw_ostream::DELETE_STREAM);
+
+  return Out;
 }
 
 static int AsLexInput(const char *ProgName) {
@@ -189,7 +188,7 @@
   AsmLexer Lexer(*MAI);
   Lexer.setBuffer(SrcMgr.getMemoryBuffer(0));
 
-  OwningPtr<formatted_tool_output_file> Out(GetOutputStream());
+  OwningPtr<tool_output_file> Out(GetOutputStream());
   if (!Out)
     return 1;
 
@@ -204,44 +203,44 @@
       Error = true; // error already printed.
       break;
     case AsmToken::Identifier:
-      *Out << "identifier: " << Lexer.getTok().getString() << '\n';
+      Out->os() << "identifier: " << Lexer.getTok().getString() << '\n';
       break;
     case AsmToken::String:
-      *Out << "string: " << Lexer.getTok().getString() << '\n';
+      Out->os() << "string: " << Lexer.getTok().getString() << '\n';
       break;
     case AsmToken::Integer:
-      *Out << "int: " << Lexer.getTok().getString() << '\n';
+      Out->os() << "int: " << Lexer.getTok().getString() << '\n';
       break;
 
-    case AsmToken::Amp:            *Out << "Amp\n"; break;
-    case AsmToken::AmpAmp:         *Out << "AmpAmp\n"; break;
-    case AsmToken::Caret:          *Out << "Caret\n"; break;
-    case AsmToken::Colon:          *Out << "Colon\n"; break;
-    case AsmToken::Comma:          *Out << "Comma\n"; break;
-    case AsmToken::Dollar:         *Out << "Dollar\n"; break;
-    case AsmToken::EndOfStatement: *Out << "EndOfStatement\n"; break;
-    case AsmToken::Eof:            *Out << "Eof\n"; break;
-    case AsmToken::Equal:          *Out << "Equal\n"; break;
-    case AsmToken::EqualEqual:     *Out << "EqualEqual\n"; break;
-    case AsmToken::Exclaim:        *Out << "Exclaim\n"; break;
-    case AsmToken::ExclaimEqual:   *Out << "ExclaimEqual\n"; break;
-    case AsmToken::Greater:        *Out << "Greater\n"; break;
-    case AsmToken::GreaterEqual:   *Out << "GreaterEqual\n"; break;
-    case AsmToken::GreaterGreater: *Out << "GreaterGreater\n"; break;
-    case AsmToken::LParen:         *Out << "LParen\n"; break;
-    case AsmToken::Less:           *Out << "Less\n"; break;
-    case AsmToken::LessEqual:      *Out << "LessEqual\n"; break;
-    case AsmToken::LessGreater:    *Out << "LessGreater\n"; break;
-    case AsmToken::LessLess:       *Out << "LessLess\n"; break;
-    case AsmToken::Minus:          *Out << "Minus\n"; break;
-    case AsmToken::Percent:        *Out << "Percent\n"; break;
-    case AsmToken::Pipe:           *Out << "Pipe\n"; break;
-    case AsmToken::PipePipe:       *Out << "PipePipe\n"; break;
-    case AsmToken::Plus:           *Out << "Plus\n"; break;
-    case AsmToken::RParen:         *Out << "RParen\n"; break;
-    case AsmToken::Slash:          *Out << "Slash\n"; break;
-    case AsmToken::Star:           *Out << "Star\n"; break;
-    case AsmToken::Tilde:          *Out << "Tilde\n"; break;
+    case AsmToken::Amp:            Out->os() << "Amp\n"; break;
+    case AsmToken::AmpAmp:         Out->os() << "AmpAmp\n"; break;
+    case AsmToken::Caret:          Out->os() << "Caret\n"; break;
+    case AsmToken::Colon:          Out->os() << "Colon\n"; break;
+    case AsmToken::Comma:          Out->os() << "Comma\n"; break;
+    case AsmToken::Dollar:         Out->os() << "Dollar\n"; break;
+    case AsmToken::EndOfStatement: Out->os() << "EndOfStatement\n"; break;
+    case AsmToken::Eof:            Out->os() << "Eof\n"; break;
+    case AsmToken::Equal:          Out->os() << "Equal\n"; break;
+    case AsmToken::EqualEqual:     Out->os() << "EqualEqual\n"; break;
+    case AsmToken::Exclaim:        Out->os() << "Exclaim\n"; break;
+    case AsmToken::ExclaimEqual:   Out->os() << "ExclaimEqual\n"; break;
+    case AsmToken::Greater:        Out->os() << "Greater\n"; break;
+    case AsmToken::GreaterEqual:   Out->os() << "GreaterEqual\n"; break;
+    case AsmToken::GreaterGreater: Out->os() << "GreaterGreater\n"; break;
+    case AsmToken::LParen:         Out->os() << "LParen\n"; break;
+    case AsmToken::Less:           Out->os() << "Less\n"; break;
+    case AsmToken::LessEqual:      Out->os() << "LessEqual\n"; break;
+    case AsmToken::LessGreater:    Out->os() << "LessGreater\n"; break;
+    case AsmToken::LessLess:       Out->os() << "LessLess\n"; break;
+    case AsmToken::Minus:          Out->os() << "Minus\n"; break;
+    case AsmToken::Percent:        Out->os() << "Percent\n"; break;
+    case AsmToken::Pipe:           Out->os() << "Pipe\n"; break;
+    case AsmToken::PipePipe:       Out->os() << "PipePipe\n"; break;
+    case AsmToken::Plus:           Out->os() << "Plus\n"; break;
+    case AsmToken::RParen:         Out->os() << "RParen\n"; break;
+    case AsmToken::Slash:          Out->os() << "Slash\n"; break;
+    case AsmToken::Star:           Out->os() << "Star\n"; break;
+    case AsmToken::Tilde:          Out->os() << "Tilde\n"; break;
     }
   }
 
@@ -291,10 +290,11 @@
     return 1;
   }
 
-  OwningPtr<formatted_tool_output_file> Out(GetOutputStream());
+  OwningPtr<tool_output_file> Out(GetOutputStream());
   if (!Out)
     return 1;
 
+  formatted_raw_ostream FOS(Out->os());
   OwningPtr<MCStreamer> Str;
 
   if (FileType == OFT_AssemblyFile) {
@@ -303,7 +303,7 @@
     MCCodeEmitter *CE = 0;
     if (ShowEncoding)
       CE = TheTarget->createCodeEmitter(*TM, Ctx);
-    Str.reset(createAsmStreamer(Ctx, *Out,
+    Str.reset(createAsmStreamer(Ctx, FOS,
                                 TM->getTargetData()->isLittleEndian(),
                                 /*asmverbose*/true, IP, CE, ShowInst));
   } else if (FileType == OFT_Null) {
@@ -313,7 +313,7 @@
     MCCodeEmitter *CE = TheTarget->createCodeEmitter(*TM, Ctx);
     TargetAsmBackend *TAB = TheTarget->createAsmBackend(TripleName);
     Str.reset(TheTarget->createObjectStreamer(TripleName, Ctx, *TAB,
-                                              *Out, CE, RelaxAll));
+                                              FOS, CE, RelaxAll));
   }
 
   if (EnableLogging) {
@@ -359,15 +359,15 @@
     return 1;
   }
   
-  OwningPtr<formatted_tool_output_file> Out(GetOutputStream());
+  OwningPtr<tool_output_file> Out(GetOutputStream());
   if (!Out)
     return 1;
 
   int Res;
   if (Enhanced)
-    Res = Disassembler::disassembleEnhanced(TripleName, *Buffer, *Out);
+    Res = Disassembler::disassembleEnhanced(TripleName, *Buffer, Out->os());
   else
-    Res = Disassembler::disassemble(*TheTarget, TripleName, *Buffer, *Out);
+    Res = Disassembler::disassemble(*TheTarget, TripleName, *Buffer, Out->os());
 
   // Keep output if no errors.
   if (Res == 0) Out->keep();

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Wed Sep  1 09:20:41 2010
@@ -164,13 +164,13 @@
   }
     
   // write bitcode to it
-  WriteBitcodeToFile(_linker.getModule(), Out);
-  Out.close();
+  WriteBitcodeToFile(_linker.getModule(), Out.os());
+  Out.os().close();
 
-  if (Out.has_error()) {
+  if (Out.os().has_error()) {
     errMsg = "could not write bitcode file: ";
     errMsg += path;
-    Out.clear_error();
+    Out.os().clear_error();
     return true;
   }
   
@@ -190,14 +190,13 @@
     // generate assembly code
     bool genResult = false;
     {
-      tool_output_file asmFD(uniqueAsmPath.c_str(), errMsg);
-      formatted_tool_output_file asmFile(asmFD);
+      tool_output_file asmFile(uniqueAsmPath.c_str(), errMsg);
       if (!errMsg.empty())
         return NULL;
-      genResult = this->generateAssemblyCode(asmFile, errMsg);
-      asmFile.close();
-      if (asmFile.has_error()) {
-        asmFile.clear_error();
+      genResult = this->generateAssemblyCode(asmFile.os(), errMsg);
+      asmFile.os().close();
+      if (asmFile.os().has_error()) {
+        asmFile.os().clear_error();
         return NULL;
       }
       asmFile.keep();
@@ -368,7 +367,7 @@
 }
 
 /// Optimize merged modules using various IPO passes
-bool LTOCodeGenerator::generateAssemblyCode(formatted_raw_ostream& out,
+bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
                                             std::string& errMsg)
 {
     if ( this->determineTarget(errMsg) ) 
@@ -403,7 +402,9 @@
 
     codeGenPasses->add(new TargetData(*_target->getTargetData()));
 
-    if (_target->addPassesToEmitFile(*codeGenPasses, out,
+    formatted_raw_ostream Out(out);
+
+    if (_target->addPassesToEmitFile(*codeGenPasses, Out,
                                      TargetMachine::CGFT_AssemblyFile,
                                      CodeGenOpt::Aggressive)) {
       errMsg = "target file type not supported";

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.h?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.h (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.h Wed Sep  1 09:20:41 2010
@@ -45,7 +45,7 @@
     const void*         compile(size_t* length, std::string& errMsg);
     void                setCodeGenDebugOptions(const char *opts); 
 private:
-    bool                generateAssemblyCode(llvm::formatted_raw_ostream& out, 
+    bool                generateAssemblyCode(llvm::raw_ostream& out, 
                                              std::string& errMsg);
     bool                assemble(const std::string& asmPath, 
                             const std::string& objPath, std::string& errMsg);

Modified: llvm/trunk/tools/opt/GraphPrinters.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/GraphPrinters.cpp?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/opt/GraphPrinters.cpp (original)
+++ llvm/trunk/tools/opt/GraphPrinters.cpp Wed Sep  1 09:20:41 2010
@@ -31,16 +31,16 @@
   tool_output_file F(Filename.c_str(), ErrInfo);
 
   if (ErrInfo.empty()) {
-    WriteGraph(F, GT);
-    F.close();
-    if (!F.has_error()) {
+    WriteGraph(F.os(), GT);
+    F.os().close();
+    if (!F.os().has_error()) {
       O << "\n";
       F.keep();
       return;
     }
   }
-  F.clear_error();
   O << "  error opening file for writing!\n";
+  F.os().clear_error();
 }
 
 

Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Wed Sep  1 09:20:41 2010
@@ -359,6 +359,11 @@
 int main(int argc, char **argv) {
   sys::PrintStackTraceOnErrorSignal();
   llvm::PrettyStackTraceProgram X(argc, argv);
+
+  if (AnalyzeOnly && NoOutput) {
+    errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
+    return 1;
+  }
   
   // Enable debug stream buffering.
   EnableDebugBuffering = true;
@@ -408,7 +413,7 @@
   // console, print out a warning message and refuse to do it.  We don't
   // impress anyone by spewing tons of binary goo to a terminal.
   if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly)
-    if (CheckBitcodeOutputToConsole(*Out, !Quiet))
+    if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
       NoOutput = true;
 
   // Create a PassManager to hold and optimize the collection of passes we are
@@ -484,19 +489,19 @@
       if (AnalyzeOnly) {
         switch (Kind) {
         case PT_BasicBlock:
-          Passes.add(new BasicBlockPassPrinter(PassInf, *Out));
+          Passes.add(new BasicBlockPassPrinter(PassInf, Out->os()));
           break;
         case PT_Loop:
-          Passes.add(new LoopPassPrinter(PassInf, *Out));
+          Passes.add(new LoopPassPrinter(PassInf, Out->os()));
           break;
         case PT_Function:
-          Passes.add(new FunctionPassPrinter(PassInf, *Out));
+          Passes.add(new FunctionPassPrinter(PassInf, Out->os()));
           break;
         case PT_CallGraphSCC:
-          Passes.add(new CallGraphSCCPassPrinter(PassInf, *Out));
+          Passes.add(new CallGraphSCCPassPrinter(PassInf, Out->os()));
           break;
         default:
-          Passes.add(new ModulePassPrinter(PassInf, *Out));
+          Passes.add(new ModulePassPrinter(PassInf, Out->os()));
           break;
         }
       }
@@ -536,9 +541,9 @@
   // Write bitcode or assembly to the output as the last step...
   if (!NoOutput && !AnalyzeOnly) {
     if (OutputAssembly)
-      Passes.add(createPrintModulePass(Out.get()));
+      Passes.add(createPrintModulePass(&Out->os()));
     else
-      Passes.add(createBitcodeWriterPass(*Out));
+      Passes.add(createBitcodeWriterPass(Out->os()));
   }
 
   // Now that we have all of the passes ready, run them.

Modified: llvm/trunk/utils/FileUpdate/FileUpdate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileUpdate/FileUpdate.cpp?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/utils/FileUpdate/FileUpdate.cpp (original)
+++ llvm/trunk/utils/FileUpdate/FileUpdate.cpp Wed Sep  1 09:20:41 2010
@@ -78,7 +78,7 @@
     return 1;
   }
 
-  OutStream.write(In->getBufferStart(), In->getBufferSize());
+  OutStream.os().write(In->getBufferStart(), In->getBufferSize());
 
   // Declare success.
   OutStream.keep();

Modified: llvm/trunk/utils/TableGen/TableGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TableGen.cpp?rev=112706&r1=112705&r2=112706&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/TableGen.cpp (original)
+++ llvm/trunk/utils/TableGen/TableGen.cpp Wed Sep  1 09:20:41 2010
@@ -226,109 +226,109 @@
   try {
     switch (Action) {
     case PrintRecords:
-      Out << Records;           // No argument, dump all contents
+      Out.os() << Records;           // No argument, dump all contents
       break;
     case GenEmitter:
-      CodeEmitterGen(Records).run(Out);
+      CodeEmitterGen(Records).run(Out.os());
       break;
 
     case GenRegisterEnums:
-      RegisterInfoEmitter(Records).runEnums(Out);
+      RegisterInfoEmitter(Records).runEnums(Out.os());
       break;
     case GenRegister:
-      RegisterInfoEmitter(Records).run(Out);
+      RegisterInfoEmitter(Records).run(Out.os());
       break;
     case GenRegisterHeader:
-      RegisterInfoEmitter(Records).runHeader(Out);
+      RegisterInfoEmitter(Records).runHeader(Out.os());
       break;
     case GenInstrEnums:
-      InstrEnumEmitter(Records).run(Out);
+      InstrEnumEmitter(Records).run(Out.os());
       break;
     case GenInstrs:
-      InstrInfoEmitter(Records).run(Out);
+      InstrInfoEmitter(Records).run(Out.os());
       break;
     case GenCallingConv:
-      CallingConvEmitter(Records).run(Out);
+      CallingConvEmitter(Records).run(Out.os());
       break;
     case GenAsmWriter:
-      AsmWriterEmitter(Records).run(Out);
+      AsmWriterEmitter(Records).run(Out.os());
       break;
     case GenARMDecoder:
-      ARMDecoderEmitter(Records).run(Out);
+      ARMDecoderEmitter(Records).run(Out.os());
       break;
     case GenAsmMatcher:
-      AsmMatcherEmitter(Records).run(Out);
+      AsmMatcherEmitter(Records).run(Out.os());
       break;
     case GenClangAttrClasses:
-      ClangAttrClassEmitter(Records).run(Out);
+      ClangAttrClassEmitter(Records).run(Out.os());
       break;
     case GenClangAttrImpl:
-      ClangAttrImplEmitter(Records).run(Out);
+      ClangAttrImplEmitter(Records).run(Out.os());
       break;
     case GenClangAttrList:
-      ClangAttrListEmitter(Records).run(Out);
+      ClangAttrListEmitter(Records).run(Out.os());
       break;
     case GenClangAttrPCHRead:
-      ClangAttrPCHReadEmitter(Records).run(Out);
+      ClangAttrPCHReadEmitter(Records).run(Out.os());
       break;
     case GenClangAttrPCHWrite:
-      ClangAttrPCHWriteEmitter(Records).run(Out);
+      ClangAttrPCHWriteEmitter(Records).run(Out.os());
       break;
     case GenClangDiagsDefs:
-      ClangDiagsDefsEmitter(Records, ClangComponent).run(Out);
+      ClangDiagsDefsEmitter(Records, ClangComponent).run(Out.os());
       break;
     case GenClangDiagGroups:
-      ClangDiagGroupsEmitter(Records).run(Out);
+      ClangDiagGroupsEmitter(Records).run(Out.os());
       break;
     case GenClangDeclNodes:
-      ClangASTNodesEmitter(Records, "Decl", "Decl").run(Out);
-      ClangDeclContextEmitter(Records).run(Out);
+      ClangASTNodesEmitter(Records, "Decl", "Decl").run(Out.os());
+      ClangDeclContextEmitter(Records).run(Out.os());
       break;
     case GenClangStmtNodes:
-      ClangASTNodesEmitter(Records, "Stmt", "").run(Out);
+      ClangASTNodesEmitter(Records, "Stmt", "").run(Out.os());
       break;
     case GenDisassembler:
-      DisassemblerEmitter(Records).run(Out);
+      DisassemblerEmitter(Records).run(Out.os());
       break;
     case GenOptParserDefs:
-      OptParserEmitter(Records, true).run(Out);
+      OptParserEmitter(Records, true).run(Out.os());
       break;
     case GenOptParserImpl:
-      OptParserEmitter(Records, false).run(Out);
+      OptParserEmitter(Records, false).run(Out.os());
       break;
     case GenDAGISel:
-      DAGISelEmitter(Records).run(Out);
+      DAGISelEmitter(Records).run(Out.os());
       break;
     case GenFastISel:
-      FastISelEmitter(Records).run(Out);
+      FastISelEmitter(Records).run(Out.os());
       break;
     case GenSubtarget:
-      SubtargetEmitter(Records).run(Out);
+      SubtargetEmitter(Records).run(Out.os());
       break;
     case GenIntrinsic:
-      IntrinsicEmitter(Records).run(Out);
+      IntrinsicEmitter(Records).run(Out.os());
       break;
     case GenTgtIntrinsic:
-      IntrinsicEmitter(Records, true).run(Out);
+      IntrinsicEmitter(Records, true).run(Out.os());
       break;
     case GenLLVMCConf:
-      LLVMCConfigurationEmitter(Records).run(Out);
+      LLVMCConfigurationEmitter(Records).run(Out.os());
       break;
     case GenEDInfo:
-      EDEmitter(Records).run(Out);
+      EDEmitter(Records).run(Out.os());
       break;
     case GenArmNeon:
-      NeonEmitter(Records).run(Out);
+      NeonEmitter(Records).run(Out.os());
       break;
     case GenArmNeonSema:
-      NeonEmitter(Records).runHeader(Out);
+      NeonEmitter(Records).runHeader(Out.os());
       break;
     case PrintEnums:
     {
       std::vector<Record*> Recs = Records.getAllDerivedDefinitions(Class);
       for (unsigned i = 0, e = Recs.size(); i != e; ++i)
-        Out << Recs[i]->getName() << ", ";
-      Out << "\n";
+        Out.os() << Recs[i]->getName() << ", ";
+      Out.os() << "\n";
       break;
     }
     default:





More information about the llvm-commits mailing list