[llvm-commits] [llvm] r79842 - in /llvm/trunk: include/llvm/Support/ lib/Bitcode/Writer/ lib/CodeGen/ lib/Debugger/ lib/ExecutionEngine/Interpreter/ lib/ExecutionEngine/JIT/ lib/Support/

Chris Lattner sabre at nondot.org
Sun Aug 23 01:43:56 PDT 2009


Author: lattner
Date: Sun Aug 23 03:43:55 2009
New Revision: 79842

URL: http://llvm.org/viewvc/llvm-project?rev=79842&view=rev
Log:
remove some uses of llvm/Support/Streams.h


Modified:
    llvm/trunk/include/llvm/Support/Timer.h
    llvm/trunk/lib/Bitcode/Writer/Serialize.cpp
    llvm/trunk/lib/CodeGen/MachineInstr.cpp
    llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
    llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp
    llvm/trunk/lib/CodeGen/VirtRegMap.cpp
    llvm/trunk/lib/CodeGen/VirtRegMap.h
    llvm/trunk/lib/Debugger/ProgramInfo.cpp
    llvm/trunk/lib/Debugger/SourceLanguage-Unknown.cpp
    llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
    llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp
    llvm/trunk/lib/Support/CommandLine.cpp
    llvm/trunk/lib/Support/PluginLoader.cpp
    llvm/trunk/lib/Support/SlowOperationInformer.cpp
    llvm/trunk/lib/Support/Statistic.cpp
    llvm/trunk/lib/Support/Timer.cpp

Modified: llvm/trunk/include/llvm/Support/Timer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Timer.h?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/Timer.h (original)
+++ llvm/trunk/include/llvm/Support/Timer.h Sun Aug 23 03:43:55 2009
@@ -19,12 +19,12 @@
 #include "llvm/System/Mutex.h"
 #include <string>
 #include <vector>
-#include <iosfwd>
 #include <cassert>
 
 namespace llvm {
 
 class TimerGroup;
+class raw_ostream;
 
 /// Timer - This class is used to track the amount of time spent between
 /// invocations of it's startTimer()/stopTimer() methods.  Given appropriate OS
@@ -112,7 +112,7 @@
 
   /// print - Print the current timer to standard error, and reset the "Started"
   /// flag.
-  void print(const Timer &Total, std::ostream &OS);
+  void print(const Timer &Total, raw_ostream &OS);
 
 private:
   friend class TimerGroup;

Modified: llvm/trunk/lib/Bitcode/Writer/Serialize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/Serialize.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/Serialize.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/Serialize.cpp Sun Aug 23 03:43:55 2009
@@ -12,11 +12,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Bitcode/Serialize.h"
-#include "string.h"
-
-#ifdef DEBUG_BACKPATCH
-#include "llvm/Support/Streams.h"
-#endif
+#include "llvm/Support/raw_ostream.h"
+#include <cstring>
 
 using namespace llvm;
 
@@ -86,7 +83,7 @@
   if (I == PtrMap.end()) {
     unsigned id = PtrMap.size()+1;
 #ifdef DEBUG_BACKPATCH
-    llvm::cerr << "Registered PTR: " << ptr << " => " << id << "\n";
+    errs() << "Registered PTR: " << ptr << " => " << id << "\n";
 #endif
     PtrMap[ptr] = id;
     return id;

Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Sun Aug 23 03:43:55 2009
@@ -26,7 +26,6 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/Streams.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/ADT/FoldingSet.h"
 using namespace llvm;

Modified: llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp Sun Aug 23 03:43:55 2009
@@ -24,7 +24,6 @@
 #include "llvm/Module.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/Streams.h"
 using namespace llvm;
 using namespace llvm::dwarf;
 

Modified: llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp (original)
+++ llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp Sun Aug 23 03:43:55 2009
@@ -2598,9 +2598,9 @@
 
 void SimpleRegisterCoalescing::printRegName(unsigned reg) const {
   if (TargetRegisterInfo::isPhysicalRegister(reg))
-    cerr << tri_->getName(reg);
+    errs() << tri_->getName(reg);
   else
-    cerr << "%reg" << reg;
+    errs() << "%reg" << reg;
 }
 
 void SimpleRegisterCoalescing::releaseMemory() {

Modified: llvm/trunk/lib/CodeGen/VirtRegMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/VirtRegMap.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/VirtRegMap.cpp (original)
+++ llvm/trunk/lib/CodeGen/VirtRegMap.cpp Sun Aug 23 03:43:55 2009
@@ -259,11 +259,6 @@
   return AnyUnused;
 }
 
-void VirtRegMap::print(std::ostream &OS, const Module* M) const {
-  raw_os_ostream RawOS(OS);
-  print(RawOS, M);
-}
-
 void VirtRegMap::print(raw_ostream &OS, const Module* M) const {
   const TargetRegisterInfo* TRI = MF->getTarget().getRegisterInfo();
 
@@ -283,5 +278,5 @@
 }
 
 void VirtRegMap::dump() const {
-  print(cerr);
+  print(errs());
 }

Modified: llvm/trunk/lib/CodeGen/VirtRegMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/VirtRegMap.h?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/VirtRegMap.h (original)
+++ llvm/trunk/lib/CodeGen/VirtRegMap.h Sun Aug 23 03:43:55 2009
@@ -24,7 +24,6 @@
 #include "llvm/ADT/IndexedMap.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/Streams.h"
 #include <map>
 
 namespace llvm {
@@ -482,25 +481,10 @@
       return 0;
     }
 
-    void print(std::ostream &OS, const Module* M = 0) const;
-    void print(std::ostream *OS) const { if (OS) print(*OS); }
     void print(raw_ostream &OS, const Module* M = 0) const;
-    void print(raw_ostream *OS) const { if (OS) print(*OS); }
     void dump() const;
   };
 
-  inline std::ostream *operator<<(std::ostream *OS, const VirtRegMap &VRM) {
-    VRM.print(OS);
-    return OS;
-  }
-  inline std::ostream &operator<<(std::ostream &OS, const VirtRegMap &VRM) {
-    VRM.print(OS);
-    return OS;
-  }
-  inline raw_ostream *operator<<(raw_ostream *OS, const VirtRegMap &VRM) {
-    VRM.print(OS);
-    return OS;
-  }
   inline raw_ostream &operator<<(raw_ostream &OS, const VirtRegMap &VRM) {
     VRM.print(OS);
     return OS;

Modified: llvm/trunk/lib/Debugger/ProgramInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Debugger/ProgramInfo.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/Debugger/ProgramInfo.cpp (original)
+++ llvm/trunk/lib/Debugger/ProgramInfo.cpp Sun Aug 23 03:43:55 2009
@@ -23,7 +23,6 @@
 #include "llvm/Debugger/SourceFile.h"
 #include "llvm/Debugger/SourceLanguage.h"
 #include "llvm/Support/SlowOperationInformer.h"
-#include "llvm/Support/Streams.h"
 #include "llvm/ADT/STLExtras.h"
 using namespace llvm;
 
@@ -184,7 +183,7 @@
             if (SD) {             // We found the first stop point!
               // This is just a sanity check.
               if (getSourceFile().getDescriptor() != SD)
-                cout << "WARNING: first line of function is not in the"
+                outs() << "WARNING: first line of function is not in the"
                      << " file that the function descriptor claims it is in.\n";
               break;
             }

Modified: llvm/trunk/lib/Debugger/SourceLanguage-Unknown.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Debugger/SourceLanguage-Unknown.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/Debugger/SourceLanguage-Unknown.cpp (original)
+++ llvm/trunk/lib/Debugger/SourceLanguage-Unknown.cpp Sun Aug 23 03:43:55 2009
@@ -15,9 +15,8 @@
 
 #include "llvm/Debugger/SourceLanguage.h"
 #include "llvm/Debugger/ProgramInfo.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
 #include <cassert>
-#include <ostream>
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
@@ -132,7 +131,7 @@
   SourceFunctionInfo *Found = IP.first->second;
   ++IP.first;
   if (IP.first != IP.second)
-    cout << "Whoa, found multiple functions with the same name.  I should"
+    outs() << "Whoa, found multiple functions with the same name.  I should"
          << " ask the user which one to use: FIXME!\n";
   return Found;
 }

Modified: llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Sun Aug 23 03:43:55 2009
@@ -24,7 +24,6 @@
 #include "llvm/Module.h"
 #include "llvm/Config/config.h"     // Detect libffi
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/Streams.h"
 #include "llvm/System/DynamicLibrary.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Support/ManagedStatic.h"
@@ -279,7 +278,7 @@
 #endif // USE_LIBFFI
 
   if (F->getName() == "__main")
-    cerr << "Tried to execute an unknown external function: "
+    errs() << "Tried to execute an unknown external function: "
       << F->getType()->getDescription() << " __main\n";
   else
     llvm_report_error("Tried to execute an unknown external function: " +
@@ -393,7 +392,8 @@
         sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break;
       case 's':
         sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break;
-      default:  cerr << "<unknown printf code '" << *FmtStr << "'!>";
+      default:
+        errs() << "<unknown printf code '" << *FmtStr << "'!>";
         ArgNo++; break;
       }
       strcpy(OutputBuffer, Buffer);
@@ -414,7 +414,7 @@
   NewArgs.push_back(PTOGV((void*)&Buffer[0]));
   NewArgs.insert(NewArgs.end(), Args.begin(), Args.end());
   GenericValue GV = lle_X_sprintf(FT, NewArgs);
-  cout << Buffer;
+  outs() << Buffer;
   return GV;
 }
 

Modified: llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp Sun Aug 23 03:43:55 2009
@@ -17,7 +17,6 @@
 
 #include "JIT.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/Streams.h"
 #include "llvm/System/DynamicLibrary.h"
 #include "llvm/Config/config.h"
 using namespace llvm;

Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Sun Aug 23 03:43:55 2009
@@ -851,13 +851,12 @@
 //
 void basic_parser_impl::printOptionInfo(const Option &O,
                                         size_t GlobalWidth) const {
-  cout << "  -" << O.ArgStr;
+  outs() << "  -" << O.ArgStr;
 
   if (const char *ValName = getValueName())
-    cout << "=<" << getValueStr(O, ValName) << ">";
+    outs() << "=<" << getValueStr(O, ValName) << '>';
 
-  cout << std::string(GlobalWidth-getOptionWidth(O), ' ') << " - "
-       << O.HelpStr << "\n";
+  outs().indent(GlobalWidth-getOptionWidth(O)) << " - " << O.HelpStr << '\n';
 }
 
 
@@ -990,21 +989,21 @@
                                           size_t GlobalWidth) const {
   if (O.hasArgStr()) {
     size_t L = std::strlen(O.ArgStr);
-    cout << "  -" << O.ArgStr << std::string(GlobalWidth-L-6, ' ')
-         << " - " << O.HelpStr << "\n";
+    outs() << "  -" << O.ArgStr << std::string(GlobalWidth-L-6, ' ')
+           << " - " << O.HelpStr << '\n';
 
     for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
       size_t NumSpaces = GlobalWidth-strlen(getOption(i))-8;
-      cout << "    =" << getOption(i) << std::string(NumSpaces, ' ')
-           << " -   " << getDescription(i) << "\n";
+      outs() << "    =" << getOption(i) << std::string(NumSpaces, ' ')
+             << " -   " << getDescription(i) << '\n';
     }
   } else {
     if (O.HelpStr[0])
-      cout << "  " << O.HelpStr << "\n";
+      outs() << "  " << O.HelpStr << "\n";
     for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
       size_t L = std::strlen(getOption(i));
-      cout << "    -" << getOption(i) << std::string(GlobalWidth-L-8, ' ')
-           << " - " << getDescription(i) << "\n";
+      outs() << "    -" << getOption(i) << std::string(GlobalWidth-L-8, ' ')
+             << " - " << getDescription(i) << "\n";
     }
   }
 }
@@ -1063,9 +1062,9 @@
     }
 
     if (ProgramOverview)
-      cout << "OVERVIEW: " << ProgramOverview << "\n";
+      outs() << "OVERVIEW: " << ProgramOverview << "\n";
 
-    cout << "USAGE: " << ProgramName << " [options]";
+    outs() << "USAGE: " << ProgramName << " [options]";
 
     // Print out the positional options.
     Option *CAOpt = 0;   // The cl::ConsumeAfter option, if it exists...
@@ -1075,28 +1074,28 @@
 
     for (size_t i = CAOpt != 0, e = PositionalOpts.size(); i != e; ++i) {
       if (PositionalOpts[i]->ArgStr[0])
-        cout << " --" << PositionalOpts[i]->ArgStr;
-      cout << " " << PositionalOpts[i]->HelpStr;
+        outs() << " --" << PositionalOpts[i]->ArgStr;
+      outs() << " " << PositionalOpts[i]->HelpStr;
     }
 
     // Print the consume after option info if it exists...
-    if (CAOpt) cout << " " << CAOpt->HelpStr;
+    if (CAOpt) outs() << " " << CAOpt->HelpStr;
 
-    cout << "\n\n";
+    outs() << "\n\n";
 
     // Compute the maximum argument length...
     MaxArgLen = 0;
     for (size_t i = 0, e = Opts.size(); i != e; ++i)
       MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
 
-    cout << "OPTIONS:\n";
+    outs() << "OPTIONS:\n";
     for (size_t i = 0, e = Opts.size(); i != e; ++i)
       Opts[i].second->printOptionInfo(MaxArgLen);
 
     // Print any extra help the user has declared.
     for (std::vector<const char *>::iterator I = MoreHelp->begin(),
           E = MoreHelp->end(); I != E; ++I)
-      cout << *I;
+      outs() << *I;
     MoreHelp->clear();
 
     // Halt the program since help information was printed
@@ -1125,42 +1124,43 @@
 class VersionPrinter {
 public:
   void print() {
-        cout << "Low Level Virtual Machine (http://llvm.org/):\n";
-        cout << "  " << PACKAGE_NAME << " version " << PACKAGE_VERSION;
+    raw_ostream &stdout = outs();
+    stdout << "Low Level Virtual Machine (http://llvm.org/):\n";
+    stdout << "  " << PACKAGE_NAME << " version " << PACKAGE_VERSION;
 #ifdef LLVM_VERSION_INFO
-        cout << LLVM_VERSION_INFO;
+    stdout << LLVM_VERSION_INFO;
 #endif
-        cout << "\n  ";
+    stdout << "\n  ";
 #ifndef __OPTIMIZE__
-        cout << "DEBUG build";
+    stdout << "DEBUG build";
 #else
-        cout << "Optimized build";
+    stdout << "Optimized build";
 #endif
 #ifndef NDEBUG
-        cout << " with assertions";
+    stdout << " with assertions";
 #endif
-        cout << ".\n";
-        cout << "  Built " << __DATE__ << "(" << __TIME__ << ").\n";
-        cout << "\n";
-        cout << "  Registered Targets:\n";
-
-        std::vector<std::pair<std::string, const Target*> > Targets;
-        size_t Width = 0;
-        for (TargetRegistry::iterator it = TargetRegistry::begin(), 
-               ie = TargetRegistry::end(); it != ie; ++it) {
-          Targets.push_back(std::make_pair(it->getName(), &*it));
-          Width = std::max(Width, ::strlen(it->getName()));
-        }
-        std::sort(Targets.begin(), Targets.end());
-
-        for (unsigned i = 0, e = Targets.size(); i != e; ++i) {
-          const Target *T = Targets[i].second;
-          cout << "    " << T->getName()
+    stdout << ".\n";
+    stdout << "  Built " << __DATE__ << "(" << __TIME__ << ").\n";
+    stdout << "\n";
+    stdout << "  Registered Targets:\n";
+
+      std::vector<std::pair<std::string, const Target*> > Targets;
+      size_t Width = 0;
+      for (TargetRegistry::iterator it = TargetRegistry::begin(), 
+             ie = TargetRegistry::end(); it != ie; ++it) {
+        Targets.push_back(std::make_pair(it->getName(), &*it));
+        Width = std::max(Width, ::strlen(it->getName()));
+      }
+      std::sort(Targets.begin(), Targets.end());
+
+      for (unsigned i = 0, e = Targets.size(); i != e; ++i) {
+        const Target *T = Targets[i].second;
+        stdout << "    " << T->getName()
                << std::string(Width - ::strlen(T->getName()), ' ') << " - "
                << T->getShortDescription() << "\n";
-        }
-        if (Targets.empty())
-          cout << "    (none)\n";
+      }
+      if (Targets.empty())
+        stdout << "    (none)\n";
   }
   void operator=(bool OptionWasSpecified) {
     if (OptionWasSpecified) {

Modified: llvm/trunk/lib/Support/PluginLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PluginLoader.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/Support/PluginLoader.cpp (original)
+++ llvm/trunk/lib/Support/PluginLoader.cpp Sun Aug 23 03:43:55 2009
@@ -14,10 +14,9 @@
 #define DONT_GET_PLUGIN_LOADER_OPTION
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/PluginLoader.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/System/DynamicLibrary.h"
 #include "llvm/System/Mutex.h"
-#include <ostream>
 #include <vector>
 using namespace llvm;
 
@@ -28,8 +27,8 @@
   sys::SmartScopedLock<true> Lock(*PluginsLock);
   std::string Error;
   if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
-    cerr << "Error opening '" << Filename << "': " << Error
-         << "\n  -load request ignored.\n";
+    errs() << "Error opening '" << Filename << "': " << Error
+           << "\n  -load request ignored.\n";
   } else {
     Plugins->push_back(Filename);
   }

Modified: llvm/trunk/lib/Support/SlowOperationInformer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SlowOperationInformer.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/Support/SlowOperationInformer.cpp (original)
+++ llvm/trunk/lib/Support/SlowOperationInformer.cpp Sun Aug 23 03:43:55 2009
@@ -12,7 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Support/SlowOperationInformer.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Alarm.h"
 #include <sstream>
 #include <cassert>
@@ -28,8 +28,8 @@
   if (LastPrintAmount) {
     // If we have printed something, make _sure_ we print the 100% amount, and
     // also print a newline.
-    cout << std::string(LastPrintAmount, '\b') << "Progress "
-         << OperationName << ": 100%  \n";
+    outs() << std::string(LastPrintAmount, '\b') << "Progress "
+           << OperationName << ": 100%  \n";
   }
 }
 
@@ -40,7 +40,7 @@
 bool SlowOperationInformer::progress(unsigned Amount) {
   int status = sys::AlarmStatus();
   if (status == -1) {
-    cout << "\n";
+    outs() << "\n";
     LastPrintAmount = 0;
     return true;
   }
@@ -61,6 +61,7 @@
     OS << "%  ";
 
   LastPrintAmount = OS.str().size();
-  cout << ToPrint+OS.str() << std::flush;
+  outs() << ToPrint+OS.str();
+  outs().flush();
   return false;
 }

Modified: llvm/trunk/lib/Support/Statistic.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Statistic.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/Support/Statistic.cpp (original)
+++ llvm/trunk/lib/Support/Statistic.cpp Sun Aug 23 03:43:55 2009
@@ -24,16 +24,15 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Mutex.h"
 #include "llvm/ADT/StringExtras.h"
 #include <algorithm>
-#include <ostream>
 #include <cstring>
 using namespace llvm;
 
 // GetLibSupportInfoOutputFile - Return a file stream to print our output on.
-namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
+namespace llvm { extern raw_ostream *GetLibSupportInfoOutputFile(); }
 
 /// -stats - Command line option to cause transformations to emit stats about
 /// what they did.
@@ -96,7 +95,7 @@
   if (Stats.empty()) return;
 
   // Get the stream to write to.
-  std::ostream &OutStream = *GetLibSupportInfoOutputFile();
+  raw_ostream &OutStream = *GetLibSupportInfoOutputFile();
 
   // Figure out how long the biggest Value and Name fields are.
   unsigned MaxNameLen = 0, MaxValLen = 0;
@@ -125,8 +124,9 @@
     
   }
   
-  OutStream << std::endl;  // Flush the output stream...
+  OutStream << '\n';  // Flush the output stream...
+  OutStream.flush();
   
-  if (&OutStream != cerr.stream() && &OutStream != cout.stream())
+  if (&OutStream != &outs() && &OutStream != &errs())
     delete &OutStream;   // Close the file.
 }

Modified: llvm/trunk/lib/Support/Timer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Timer.cpp?rev=79842&r1=79841&r2=79842&view=diff

==============================================================================
--- llvm/trunk/lib/Support/Timer.cpp (original)
+++ llvm/trunk/lib/Support/Timer.cpp Sun Aug 23 03:43:55 2009
@@ -14,16 +14,16 @@
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Format.h"
 #include "llvm/System/Process.h"
 #include <algorithm>
-#include <fstream>
 #include <functional>
 #include <map>
 using namespace llvm;
 
 // GetLibSupportInfoOutputFile - Return a file stream to print our output on.
-namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
+namespace llvm { extern raw_ostream *GetLibSupportInfoOutputFile(); }
 
 // getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
 // of constructor/destructor ordering being unspecified by C++.  Basically the
@@ -269,38 +269,17 @@
 //   TimerGroup Implementation
 //===----------------------------------------------------------------------===//
 
-// printAlignedFP - Simulate the printf "%A.Bf" format, where A is the
-// TotalWidth size, and B is the AfterDec size.
-//
-static void printAlignedFP(double Val, unsigned AfterDec, unsigned TotalWidth,
-                           std::ostream &OS) {
-  assert(TotalWidth >= AfterDec+1 && "Bad FP Format!");
-  OS.width(TotalWidth-AfterDec-1);
-  char OldFill = OS.fill();
-  OS.fill(' ');
-  OS << (int)Val;  // Integer part;
-  OS << ".";
-  OS.width(AfterDec);
-  OS.fill('0');
-  unsigned ResultFieldSize = 1;
-  while (AfterDec--) ResultFieldSize *= 10;
-  OS << (int)(Val*ResultFieldSize) % ResultFieldSize;
-  OS.fill(OldFill);
-}
 
-static void printVal(double Val, double Total, std::ostream &OS) {
+static void printVal(double Val, double Total, raw_ostream &OS) {
   if (Total < 1e-7)   // Avoid dividing by zero...
     OS << "        -----     ";
   else {
-    OS << "  ";
-    printAlignedFP(Val, 4, 7, OS);
-    OS << " (";
-    printAlignedFP(Val*100/Total, 1, 5, OS);
-    OS << "%)";
+    OS << "  " << format("%7.4f", Val) << " (";
+    OS << format("%5.1f", Val*100/Total) << "%)";
   }
 }
 
-void Timer::print(const Timer &Total, std::ostream &OS) {
+void Timer::print(const Timer &Total, raw_ostream &OS) {
   if (&Total < this) {
     Total.Lock.acquire();
     Lock.acquire();
@@ -320,13 +299,11 @@
   OS << "  ";
 
   if (Total.MemUsed) {
-    OS.width(9);
-    OS << MemUsed << "  ";
+    OS << format("%9lld", (long long)MemUsed) << "  ";
   }
   if (Total.PeakMem) {
     if (PeakMem) {
-      OS.width(9);
-      OS << PeakMem << "  ";
+      OS << format("%9lld", (long long)PeakMem) << "  ";
     } else
       OS << "           ";
   }
@@ -344,23 +321,25 @@
 }
 
 // GetLibSupportInfoOutputFile - Return a file stream to print our output on...
-std::ostream *
+raw_ostream *
 llvm::GetLibSupportInfoOutputFile() {
   std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
   if (LibSupportInfoOutputFilename.empty())
-    return cerr.stream();
+    return &errs();
   if (LibSupportInfoOutputFilename == "-")
-    return cout.stream();
+    return &outs();
 
-  std::ostream *Result = new std::ofstream(LibSupportInfoOutputFilename.c_str(),
-                                           std::ios::app);
-  if (!Result->good()) {
-    cerr << "Error opening info-output-file '"
+  
+  std::string Error;
+  raw_ostream *Result = new raw_fd_ostream(LibSupportInfoOutputFilename.c_str(),
+                                           Error, raw_fd_ostream::F_Append);
+  if (Error.empty())
+    return Result;
+  
+  errs() << "Error opening info-output-file '"
          << LibSupportInfoOutputFilename << " for appending!\n";
-    delete Result;
-    return cerr.stream();
-  }
-  return Result;
+  delete Result;
+  return &errs();
 }
 
 
@@ -375,7 +354,7 @@
     unsigned Padding = (80-Name.length())/2;
     if (Padding > 80) Padding = 0;         // Don't allow "negative" numbers
 
-    std::ostream *OutStream = GetLibSupportInfoOutputFile();
+    raw_ostream *OutStream = GetLibSupportInfoOutputFile();
 
     ++NumTimers;
     {  // Scope to contain Total timer... don't allow total timer to drop us to
@@ -397,10 +376,8 @@
       if (this != DefaultTimerGroup) {
         *OutStream << "  Total Execution Time: ";
 
-        printAlignedFP(Total.getProcessTime(), 4, 5, *OutStream);
-        *OutStream << " seconds (";
-        printAlignedFP(Total.getWallTime(), 4, 5, *OutStream);
-        *OutStream << " wall clock)\n";
+        *OutStream << format("%5.4f", Total.getProcessTime()) << " seconds (";
+        *OutStream << format("%5.4f", Total.getWallTime()) << " wall clock)\n";
       }
       *OutStream << "\n";
 
@@ -422,13 +399,14 @@
         TimersToPrint[i].print(Total, *OutStream);
 
       Total.print(Total, *OutStream);
-      *OutStream << std::endl;  // Flush output
+      *OutStream << '\n';
+      OutStream->flush();
     }
     --NumTimers;
 
     TimersToPrint.clear();
 
-    if (OutStream != cerr.stream() && OutStream != cout.stream())
+    if (OutStream != &errs() && OutStream != &outs())
       delete OutStream;   // Close the file...
   }
 }





More information about the llvm-commits mailing list