Use raw_ostream throughout the AsmPrinter.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55092 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 2eccc36..bf57a65 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -21,7 +21,7 @@
 #include "llvm/CodeGen/MachineJumpTableInfo.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/Support/Mangler.h"
-#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetData.h"
@@ -31,11 +31,12 @@
 #include "llvm/Target/TargetRegisterInfo.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include <cerrno>
 using namespace llvm;
 
 char AsmPrinter::ID = 0;
-AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
+AsmPrinter::AsmPrinter(raw_ostream &o, TargetMachine &tm,
                        const TargetAsmInfo *T)
   : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o),
     TM(tm), TAI(T), TRI(tm.getRegisterInfo()),
@@ -268,8 +269,9 @@
   EmitAlignment(Alignment);
   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
     O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
-      << CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << ' ';
-    WriteTypeSymbolic(O, CP[i].first.getType(), 0);
+      << CP[i].second << ":\t\t\t\t\t";
+    // O << TAI->getCommentString() << ' ' << 
+    //      WriteTypeSymbolic(O, CP[i].first.getType(), 0);
     O << '\n';
     if (CP[i].first.isMachineConstantPoolEntry())
       EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal);
@@ -495,7 +497,7 @@
     unsigned Byte = Value & 0x7f;
     Value >>= 7;
     if (Value) Byte |= 0x80;
-    O << "0x" << std::hex << Byte << std::dec;
+    O << "0x" <<  utohexstr(Byte);
     if (Value) O << ", ";
   } while (Value);
 }
@@ -511,7 +513,7 @@
     Value >>= 7;
     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
     if (IsMore) Byte |= 0x80;
-    O << "0x" << std::hex << Byte << std::dec;
+    O << "0x" << utohexstr(Byte);
     if (IsMore) O << ", ";
   } while (IsMore);
 }
@@ -523,7 +525,7 @@
 /// PrintHex - Print a value as a hexidecimal value.
 ///
 void AsmPrinter::PrintHex(int Value) const { 
-  O << "0x" << std::hex << Value << std::dec;
+  O << "0x" << utohexstr(static_cast<unsigned>(Value));
 }
 
 /// EOL - Print a newline character to asm stream.  If a comment is present
@@ -622,7 +624,7 @@
 
 /// printStringChar - Print a char, escaped if necessary.
 ///
-static void printStringChar(std::ostream &O, unsigned char C) {
+static void printStringChar(raw_ostream &O, char C) {
   if (C == '"') {
     O << "\\\"";
   } else if (C == '\\') {
@@ -706,7 +708,7 @@
 
   unsigned FillValue = TAI->getTextAlignFillValue();
   UseFillExpr &= IsInTextSection && FillValue;
-  if (UseFillExpr) O << ",0x" << std::hex << FillValue << std::dec;
+  if (UseFillExpr) O << ",0x" << utohexstr(FillValue);
   O << '\n';
 }
 
@@ -855,7 +857,7 @@
 /// printAsCString - Print the specified array as a C compatible string, only if
 /// the predicate isString is true.
 ///
-static void printAsCString(std::ostream &O, const ConstantArray *CVA,
+static void printAsCString(raw_ostream &O, const ConstantArray *CVA,
                            unsigned LastElt) {
   assert(CVA->isString() && "Array is not string compatible!");
 
diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
index 5d6acc3..99e94e2 100644
--- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
@@ -28,6 +28,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Mangler.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Path.h"
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetRegisterInfo.h"
@@ -820,7 +821,7 @@
   //
   /// O - Stream to .s file.
   ///
-  std::ostream &O;
+  raw_ostream &O;
 
   /// Asm - Target of Dwarf emission.
   ///
@@ -856,7 +857,7 @@
   const char * const Flavor;
 
   unsigned SetCounter;
-  Dwarf(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T,
+  Dwarf(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T,
         const char *flavor)
   : O(OS)
   , Asm(A)
@@ -2673,7 +2674,7 @@
   //===--------------------------------------------------------------------===//
   // Main entry points.
   //
-  DwarfDebug(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
+  DwarfDebug(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
   : Dwarf(OS, A, T, "dbg")
   , CompileUnits()
   , AbbreviationsSet(InitAbbreviationsSetSize)
@@ -3479,7 +3480,7 @@
   //===--------------------------------------------------------------------===//
   // Main entry points.
   //
-  DwarfException(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
+  DwarfException(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
   : Dwarf(OS, A, T, "eh")
   , shouldEmitTable(false)
   , shouldEmitMoves(false)
@@ -3879,7 +3880,7 @@
 /// DwarfWriter Implementation
 ///
 
-DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A,
+DwarfWriter::DwarfWriter(raw_ostream &OS, AsmPrinter *A,
                          const TargetAsmInfo *T) {
   DE = new DwarfException(OS, A, T);
   DD = new DwarfDebug(OS, A, T);
diff --git a/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp b/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
index 761e910..16abca2 100644
--- a/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
@@ -15,6 +15,7 @@
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/GCMetadataPrinter.h"
 #include "llvm/Module.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
@@ -25,10 +26,10 @@
 
   class VISIBILITY_HIDDEN OcamlGCMetadataPrinter : public GCMetadataPrinter {
   public:
-    void beginAssembly(std::ostream &OS, AsmPrinter &AP,
+    void beginAssembly(raw_ostream &OS, AsmPrinter &AP,
                        const TargetAsmInfo &TAI);
     
-    void finishAssembly(std::ostream &OS, AsmPrinter &AP,
+    void finishAssembly(raw_ostream &OS, AsmPrinter &AP,
                         const TargetAsmInfo &TAI);
   };
   
@@ -39,7 +40,7 @@
 
 void llvm::linkOcamlGCPrinter() { }
 
-static void EmitCamlGlobal(const Module &M, std::ostream &OS, AsmPrinter &AP,
+static void EmitCamlGlobal(const Module &M, raw_ostream &OS, AsmPrinter &AP,
                            const TargetAsmInfo &TAI, const char *Id) {
   const std::string &MId = M.getModuleIdentifier();
   
@@ -59,7 +60,7 @@
   OS << Mangled << ":\n";
 }
 
-void OcamlGCMetadataPrinter::beginAssembly(std::ostream &OS, AsmPrinter &AP,
+void OcamlGCMetadataPrinter::beginAssembly(raw_ostream &OS, AsmPrinter &AP,
                                            const TargetAsmInfo &TAI) {
   AP.SwitchToTextSection(TAI.getTextSection());
   EmitCamlGlobal(getModule(), OS, AP, TAI, "code_begin");
@@ -84,7 +85,7 @@
 /// (FrameSize and LiveOffsets would overflow). FrameTablePrinter will abort if
 /// either condition is detected in a function which uses the GC.
 /// 
-void OcamlGCMetadataPrinter::finishAssembly(std::ostream &OS, AsmPrinter &AP,
+void OcamlGCMetadataPrinter::finishAssembly(raw_ostream &OS, AsmPrinter &AP,
                                             const TargetAsmInfo &TAI) {
   const char *AddressDirective;
   int AddressAlignLog;
diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp
index 27f23f4..6f29112 100644
--- a/lib/CodeGen/ELFWriter.cpp
+++ b/lib/CodeGen/ELFWriter.cpp
@@ -44,6 +44,7 @@
 #include "llvm/Support/Mangler.h"
 #include "llvm/Support/OutputBuffer.h"
 #include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
 #include <list>
 using namespace llvm;
 
@@ -51,7 +52,7 @@
 /// AddELFWriter - Concrete function to add the ELF writer to the function pass
 /// manager.
 MachineCodeEmitter *llvm::AddELFWriter(PassManagerBase &PM,
-                                       std::ostream &O,
+                                       raw_ostream &O,
                                        TargetMachine &TM) {
   ELFWriter *EW = new ELFWriter(O, TM);
   PM.add(EW);
@@ -193,7 +194,7 @@
 //                          ELFWriter Implementation
 //===----------------------------------------------------------------------===//
 
-ELFWriter::ELFWriter(std::ostream &o, TargetMachine &tm) 
+ELFWriter::ELFWriter(raw_ostream &o, TargetMachine &tm) 
   : MachineFunctionPass((intptr_t)&ID), O(o), TM(tm) {
   e_flags = 0;    // e_flags defaults to 0, no flags.
 
@@ -536,7 +537,7 @@
     if (S.Align)
       for (size_t NewFileOff = (FileOff+S.Align-1) & ~(S.Align-1);
            FileOff != NewFileOff; ++FileOff)
-        O.put((char)0xAB);
+        O << (char)0xAB;
     O.write((char*)&S.SectionData[0], S.SectionData.size());
     FileOff += S.SectionData.size();
 
@@ -557,7 +558,7 @@
   // Align output for the section table.
   for (size_t NewFileOff = (FileOff+TableAlign-1) & ~(TableAlign-1);
        FileOff != NewFileOff; ++FileOff)
-    O.put((char)0xAB);
+    O << (char)0xAB;
 
   // Emit the section table itself.
   O.write((char*)&Table[0], Table.size());
diff --git a/lib/CodeGen/ELFWriter.h b/lib/CodeGen/ELFWriter.h
index be3b39b..31aa05a 100644
--- a/lib/CodeGen/ELFWriter.h
+++ b/lib/CodeGen/ELFWriter.h
@@ -23,6 +23,7 @@
   class Mangler;
   class MachineCodeEmitter;
   class ELFCodeEmitter;
+  class raw_ostream;
 
   /// ELFWriter - This class implements the common target-independent code for
   /// writing ELF files.  Targets should derive a class from this to
@@ -37,7 +38,7 @@
       return *(MachineCodeEmitter*)MCE;
     }
 
-    ELFWriter(std::ostream &O, TargetMachine &TM);
+    ELFWriter(raw_ostream &O, TargetMachine &TM);
     ~ELFWriter();
 
     typedef std::vector<unsigned char> DataBuffer;
@@ -45,7 +46,7 @@
   protected:
     /// Output stream to send the resultant object file to.
     ///
-    std::ostream &O;
+    raw_ostream &O;
 
     /// Target machine description.
     ///
diff --git a/lib/CodeGen/GCMetadataPrinter.cpp b/lib/CodeGen/GCMetadataPrinter.cpp
index 4964503..5a5ef84 100644
--- a/lib/CodeGen/GCMetadataPrinter.cpp
+++ b/lib/CodeGen/GCMetadataPrinter.cpp
@@ -19,12 +19,12 @@
 
 GCMetadataPrinter::~GCMetadataPrinter() { }
 
-void GCMetadataPrinter::beginAssembly(std::ostream &OS, AsmPrinter &AP,
+void GCMetadataPrinter::beginAssembly(raw_ostream &OS, AsmPrinter &AP,
                                       const TargetAsmInfo &TAI) {
   // Default is no action.
 }
 
-void GCMetadataPrinter::finishAssembly(std::ostream &OS, AsmPrinter &AP,
+void GCMetadataPrinter::finishAssembly(raw_ostream &OS, AsmPrinter &AP,
                                        const TargetAsmInfo &TAI) {
   // Default is no action.
 }
diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp
index 938e1ae..fb918f3 100644
--- a/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/lib/CodeGen/LLVMTargetMachine.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
 static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
@@ -50,7 +51,7 @@
 
 FileModel::Model
 LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
-                                       std::ostream &Out,
+                                       raw_ostream &Out,
                                        CodeGenFileType FileType,
                                        bool Fast) {
   // Standard LLVM-Level Passes.
diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp
index bed2c5c..9f1cb00 100644
--- a/lib/CodeGen/MachOWriter.cpp
+++ b/lib/CodeGen/MachOWriter.cpp
@@ -37,6 +37,7 @@
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/OutputBuffer.h"
 #include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <cstring>
 using namespace llvm;
@@ -44,7 +45,7 @@
 /// AddMachOWriter - Concrete function to add the Mach-O writer to the function
 /// pass manager.
 MachineCodeEmitter *llvm::AddMachOWriter(PassManagerBase &PM,
-                                         std::ostream &O,
+                                         raw_ostream &O,
                                          TargetMachine &TM) {
   MachOWriter *MOW = new MachOWriter(O, TM);
   PM.add(MOW);
@@ -334,7 +335,7 @@
 //===----------------------------------------------------------------------===//
 
 char MachOWriter::ID = 0;
-MachOWriter::MachOWriter(std::ostream &o, TargetMachine &tm) 
+MachOWriter::MachOWriter(raw_ostream &o, TargetMachine &tm) 
   : MachineFunctionPass((intptr_t)&ID), O(o), TM(tm) {
   is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
   isLittleEndian = TM.getTargetData()->isLittleEndian();
diff --git a/lib/CodeGen/MachOWriter.h b/lib/CodeGen/MachOWriter.h
index 44fa7d4..e2b6fa8 100644
--- a/lib/CodeGen/MachOWriter.h
+++ b/lib/CodeGen/MachOWriter.h
@@ -29,6 +29,7 @@
   class MachineCodeEmitter;
   class MachOCodeEmitter;
   class OutputBuffer;
+  class raw_ostream;
 
   /// MachOSym - This struct contains information about each symbol that is
   /// added to logical symbol table for the module.  This is eventually
@@ -90,7 +91,7 @@
       return *(MachineCodeEmitter*)MCE;
     }
 
-    MachOWriter(std::ostream &O, TargetMachine &TM);
+    MachOWriter(raw_ostream &O, TargetMachine &TM);
     virtual ~MachOWriter();
 
     virtual const char *getPassName() const {
@@ -101,7 +102,7 @@
   protected:
     /// Output stream to send the resultant object file to.
     ///
-    std::ostream &O;
+    raw_ostream &O;
 
     /// Target machine description.
     ///