Added an automatic cast to "std::ostream*" etc. from OStream. We then can
rework the hacks that had us passing OStream in. We pass in std::ostream*
instead, check for null, and then dispatch to the correct print() method.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32636 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/IPA/CallGraph.cpp b/lib/Analysis/IPA/CallGraph.cpp
index 6e8ca18..dcaeaf9 100644
--- a/lib/Analysis/IPA/CallGraph.cpp
+++ b/lib/Analysis/IPA/CallGraph.cpp
@@ -74,8 +74,8 @@
     AU.setPreservesAll();
   }
 
-  void print(OStream &o, const Module *M) const {
-    if (o.stream()) print(*o.stream(), M);
+  void print(std::ostream *o, const Module *M) const {
+    if (o) print(*o, M);
   }
 
   virtual void print(std::ostream &o, const Module *M) const {
diff --git a/lib/Analysis/Trace.cpp b/lib/Analysis/Trace.cpp
index a0aa955..3e3b1b9 100644
--- a/lib/Analysis/Trace.cpp
+++ b/lib/Analysis/Trace.cpp
@@ -31,13 +31,12 @@
 
 /// print - Write trace to output stream.
 ///
-void Trace::print(OStream &O) const {
+void Trace::print(std::ostream &O) const {
   Function *F = getFunction ();
   O << "; Trace from function " << F->getName() << ", blocks:\n";
   for (const_iterator i = begin(), e = end(); i != e; ++i) {
     O << "; ";
-    if (O.stream())
-      WriteAsOperand(*O.stream(), *i, true, getModule());
+    WriteAsOperand(O, *i, true, getModule());
     O << "\n";
   }
   O << "; Trace parent function: \n" << *F;
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index c6bc22e..19a5919 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -1297,4 +1297,6 @@
 
   // make sure it hits disk now
   Out.stream()->flush();
+  void * p;
+  Out << std::hex << p << "\n";
 }
diff --git a/lib/CodeGen/DwarfWriter.cpp b/lib/CodeGen/DwarfWriter.cpp
index 8f62396..2500d58 100644
--- a/lib/CodeGen/DwarfWriter.cpp
+++ b/lib/CodeGen/DwarfWriter.cpp
@@ -137,8 +137,8 @@
   }
   
 #ifndef NDEBUG
-  void print(OStream &O) const {
-    if (O.stream()) print(*O.stream());
+  void print(std::ostream *O) const {
+    if (O) print(*O);
   }
   void print(std::ostream &O) const {
     O << ".debug_" << Tag;
@@ -245,8 +245,8 @@
   void Emit(const Dwarf &DW) const; 
       
 #ifndef NDEBUG
-  void print(OStream &O) {
-    if (O.stream()) print(*O.stream());
+  void print(std::ostream *O) {
+    if (O) print(*O);
   }
   void print(std::ostream &O);
   void dump();
@@ -335,8 +335,8 @@
   void Profile(FoldingSetNodeID &ID) ;
       
 #ifndef NDEBUG
-  void print(OStream &O, unsigned IncIndent = 0) {
-    if (O.stream()) print(*O.stream(), IncIndent);
+  void print(std::ostream *O, unsigned IncIndent = 0) {
+    if (O) print(*O, IncIndent);
   }
   void print(std::ostream &O, unsigned IncIndent = 0);
   void dump();
@@ -386,8 +386,8 @@
   virtual void Profile(FoldingSetNodeID &ID) = 0;
       
 #ifndef NDEBUG
-  void print(OStream &O) {
-    if (O.stream()) print(*O.stream());
+  void print(std::ostream *O) {
+    if (O) print(*O);
   }
   virtual void print(std::ostream &O) = 0;
   void dump();
diff --git a/lib/CodeGen/LiveInterval.cpp b/lib/CodeGen/LiveInterval.cpp
index 63a80fd..0ca1600 100644
--- a/lib/CodeGen/LiveInterval.cpp
+++ b/lib/CodeGen/LiveInterval.cpp
@@ -475,7 +475,7 @@
   cerr << *this << "\n";
 }
 
-void LiveInterval::print(OStream OS, const MRegisterInfo *MRI) const {
+void LiveInterval::print(std::ostream &OS, const MRegisterInfo *MRI) const {
   if (MRI && MRegisterInfo::isPhysicalRegister(reg))
     OS << MRI->getName(reg);
   else
diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAGSimple.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAGSimple.cpp
index 65da788..0b10a22 100644
--- a/lib/CodeGen/SelectionDAG/ScheduleDAGSimple.cpp
+++ b/lib/CodeGen/SelectionDAG/ScheduleDAGSimple.cpp
@@ -473,7 +473,8 @@
   
   /// print - Print ordering to specified output stream.
   ///
-  void print(OStream &O) const;
+  void print(std::ostream &O) const;
+  void print(std::ostream *O) const { if (O) print(*O); }
   
   void dump(const char *tag) const;
   
@@ -485,7 +486,8 @@
 
   /// printNI - Print node info.
   ///
-  void printNI(OStream &O, NodeInfo *NI) const;
+  void printNI(std::ostream &O, NodeInfo *NI) const;
+  void printNI(std::ostream *O, NodeInfo *NI) const { if (O) printNI(O, NI); }
   
   /// printChanges - Hilight changes in order caused by scheduling.
   ///
@@ -636,7 +638,7 @@
 
 /// print - Print ordering to specified output stream.
 ///
-void ScheduleDAGSimple::print(OStream &O) const {
+void ScheduleDAGSimple::print(std::ostream &O) const {
 #ifndef NDEBUG
   O << "Ordering\n";
   for (unsigned i = 0, N = Ordering.size(); i < N; i++) {
@@ -710,16 +712,16 @@
 
 /// printNI - Print node info.
 ///
-void ScheduleDAGSimple::printNI(OStream &O, NodeInfo *NI) const {
+void ScheduleDAGSimple::printNI(std::ostream &O, NodeInfo *NI) const {
 #ifndef NDEBUG
   SDNode *Node = NI->Node;
-  *(O.stream()) << " "
-                << std::hex << Node << std::dec
-                << ", Lat=" << NI->Latency
-                << ", Slot=" << NI->Slot
-                << ", ARITY=(" << Node->getNumOperands() << ","
-                << Node->getNumValues() << ")"
-                << " " << Node->getOperationName(&DAG);
+  O << " "
+    << std::hex << Node << std::dec
+    << ", Lat=" << NI->Latency
+    << ", Slot=" << NI->Slot
+    << ", ARITY=(" << Node->getNumOperands() << ","
+    << Node->getNumValues() << ")"
+    << " " << Node->getOperationName(&DAG);
   if (isFlagDefiner(Node)) O << "<#";
   if (isFlagUser(Node)) O << ">#";
 #endif
diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp
index 82c88ed..26b6eeb 100644
--- a/lib/CodeGen/VirtRegMap.cpp
+++ b/lib/CodeGen/VirtRegMap.cpp
@@ -113,11 +113,6 @@
 }
 
 void VirtRegMap::print(std::ostream &OS) const {
-  OStream LOS(OS);
-  print(LOS);
-}
-
-void VirtRegMap::print(OStream &OS) const {
   const MRegisterInfo* MRI = MF.getTarget().getRegisterInfo();
 
   OS << "********** REGISTER MAP **********\n";
@@ -136,8 +131,7 @@
 }
 
 void VirtRegMap::dump() const {
-  OStream OS = DOUT;
-  print(OS);
+  print(DOUT);
 }
 
 
diff --git a/lib/CodeGen/VirtRegMap.h b/lib/CodeGen/VirtRegMap.h
index 342d800..84cf238 100644
--- a/lib/CodeGen/VirtRegMap.h
+++ b/lib/CodeGen/VirtRegMap.h
@@ -145,10 +145,14 @@
     }
 
     void print(std::ostream &OS) const;
-    void print(OStream &OS) const;
+    void print(std::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;
diff --git a/lib/Support/Debug.cpp b/lib/Support/Debug.cpp
index 949e3d9..6e67ed8 100644
--- a/lib/Support/Debug.cpp
+++ b/lib/Support/Debug.cpp
@@ -68,9 +68,9 @@
 // places the std::c* I/O streams into one .cpp file and relieves the whole
 // program from having to have hundreds of static c'tor/d'tors for them.
 // 
-OStream llvm::getErrorOutputStream(const char *DebugType) {
+OStream &llvm::getErrorOutputStream(const char *DebugType) {
   if (DebugFlag && isCurrentDebugType(DebugType))
     return cerr;
   else
-    return NullStream;
+    return cnull;
 }
diff --git a/lib/Support/Streams.cpp b/lib/Support/Streams.cpp
index 02aec1f..3d20e9a 100644
--- a/lib/Support/Streams.cpp
+++ b/lib/Support/Streams.cpp
@@ -16,7 +16,7 @@
 #include <iostream>
 using namespace llvm;
 
-OStream llvm::NullStream;
+OStream llvm::cnull;
 OStream llvm::cout(std::cout);
 OStream llvm::cerr(std::cerr);
 IStream llvm::cin(std::cin);
diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp
index 2adfb3e..f0ae385 100644
--- a/lib/Transforms/Utils/LowerSwitch.cpp
+++ b/lib/Transforms/Utils/LowerSwitch.cpp
@@ -96,7 +96,8 @@
 
 // operator<< - Used for debugging purposes.
 //
-OStream& operator<<(OStream &O, const std::vector<LowerSwitch::Case> &C) {
+std::ostream& operator<<(std::ostream &O,
+                         const std::vector<LowerSwitch::Case> &C) {
   O << "[";
 
   for (std::vector<LowerSwitch::Case>::const_iterator B = C.begin(),
@@ -107,6 +108,10 @@
 
   return O << "]";
 }
+OStream& operator<<(OStream &O, const std::vector<LowerSwitch::Case> &C) {
+  if (O.stream()) *O.stream() << C;
+  return O;
+}
 
 // switchConvert - Convert the switch statement into a binary lookup of
 // the case values. The function recursively builds this tree.