diff options
66 files changed, 448 insertions, 180 deletions
diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 52921531f2..08c3197a76 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -34,6 +34,7 @@ namespace llvm { class Mangler; class TargetAsmInfo; class Type; + class raw_ostream; /// AsmPrinter - This class is intended to be used as a driving class for all /// asm writers. @@ -64,7 +65,7 @@ namespace llvm { public: /// Output stream on which we're printing assembly code. /// - std::ostream &O; + raw_ostream &O; /// Target machine description. /// @@ -96,7 +97,7 @@ namespace llvm { bool IsInTextSection; protected: - AsmPrinter(std::ostream &o, TargetMachine &TM, const TargetAsmInfo *T); + AsmPrinter(raw_ostream &o, TargetMachine &TM, const TargetAsmInfo *T); public: virtual ~AsmPrinter(); diff --git a/include/llvm/CodeGen/DwarfWriter.h b/include/llvm/CodeGen/DwarfWriter.h index a0cfec766a..981513baee 100644 --- a/include/llvm/CodeGen/DwarfWriter.h +++ b/include/llvm/CodeGen/DwarfWriter.h @@ -31,6 +31,7 @@ class MachineModuleInfo; class MachineFunction; class Module; class TargetAsmInfo; +class raw_ostream; //===----------------------------------------------------------------------===// // DwarfWriter - Emits Dwarf debug and exception handling directives. @@ -48,7 +49,7 @@ private: public: - DwarfWriter(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T); + DwarfWriter(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T); virtual ~DwarfWriter(); /// SetModuleInfo - Set machine module info when it's known that pass manager diff --git a/include/llvm/CodeGen/FileWriters.h b/include/llvm/CodeGen/FileWriters.h index ac66b9d0bf..cb7aea476b 100644 --- a/include/llvm/CodeGen/FileWriters.h +++ b/include/llvm/CodeGen/FileWriters.h @@ -21,10 +21,11 @@ namespace llvm { class PassManagerBase; class MachineCodeEmitter; class TargetMachine; + class raw_ostream; - MachineCodeEmitter *AddELFWriter(PassManagerBase &FPM, std::ostream &O, + MachineCodeEmitter *AddELFWriter(PassManagerBase &FPM, raw_ostream &O, TargetMachine &TM); - MachineCodeEmitter *AddMachOWriter(PassManagerBase &FPM, std::ostream &O, + MachineCodeEmitter *AddMachOWriter(PassManagerBase &FPM, raw_ostream &O, TargetMachine &TM); } // end llvm namespace diff --git a/include/llvm/CodeGen/GCMetadataPrinter.h b/include/llvm/CodeGen/GCMetadataPrinter.h index 1ab138adec..1c0665bbd9 100644 --- a/include/llvm/CodeGen/GCMetadataPrinter.h +++ b/include/llvm/CodeGen/GCMetadataPrinter.h @@ -29,6 +29,7 @@ namespace llvm { class GCMetadataPrinter; + class raw_ostream; /// GCMetadataPrinterRegistry - The GC assembly printer registry uses all the /// defaults from Registry. @@ -63,10 +64,10 @@ namespace llvm { iterator end() { return S->end(); } /// beginAssembly/finishAssembly - Emit module metadata as assembly code. - virtual void beginAssembly(std::ostream &OS, AsmPrinter &AP, + virtual void beginAssembly(raw_ostream &OS, AsmPrinter &AP, const TargetAsmInfo &TAI); - virtual void finishAssembly(std::ostream &OS, AsmPrinter &AP, + virtual void finishAssembly(raw_ostream &OS, AsmPrinter &AP, const TargetAsmInfo &TAI); virtual ~GCMetadataPrinter(); diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index 471cebef63..c9506f198e 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -258,6 +258,11 @@ public: } void print(std::ostream &OS, const TargetMachine *TM = 0) const; void print(std::ostream *OS) const { if (OS) print(*OS); } + void print(raw_ostream *OS, const TargetMachine *TM) const { + if (OS) print(*OS, TM); + } + void print(raw_ostream &OS, const TargetMachine *TM = 0) const; + void print(raw_ostream *OS) const { if (OS) print(*OS); } void dump() const; //===--------------------------------------------------------------------===// @@ -316,6 +321,11 @@ inline std::ostream& operator<<(std::ostream &OS, const MachineInstr &MI) { return OS; } +inline raw_ostream& operator<<(raw_ostream &OS, const MachineInstr &MI) { + MI.print(OS); + return OS; +} + } // End llvm namespace #endif diff --git a/include/llvm/CodeGen/MachineOperand.h b/include/llvm/CodeGen/MachineOperand.h index 05984f601e..b4ba2f46fe 100644 --- a/include/llvm/CodeGen/MachineOperand.h +++ b/include/llvm/CodeGen/MachineOperand.h @@ -26,6 +26,7 @@ class GlobalValue; class MachineInstr; class TargetMachine; class MachineRegisterInfo; +class raw_ostream; /// MachineOperand class - Representation of each machine instruction operand. /// @@ -117,6 +118,7 @@ public: const MachineInstr *getParent() const { return ParentMI; } void print(std::ostream &os, const TargetMachine *TM = 0) const; + void print(raw_ostream &os, const TargetMachine *TM = 0) const; /// Accessors that tell you what kind of MachineOperand you're looking at. /// @@ -425,6 +427,11 @@ inline std::ostream &operator<<(std::ostream &OS, const MachineOperand &MO) { return OS; } +inline raw_ostream &operator<<(raw_ostream &OS, const MachineOperand& MO) { + MO.print(OS, 0); + return OS; +} + } // End llvm namespace #endif diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h index 1694520084..8019e44e35 100644 --- a/include/llvm/Support/raw_ostream.h +++ b/include/llvm/Support/raw_ostream.h @@ -14,6 +14,7 @@ #ifndef LLVM_SUPPORT_RAW_OSTREAM_H #define LLVM_SUPPORT_RAW_OSTREAM_H +#include "llvm/ADT/StringExtras.h" #include <cassert> #include <cstring> #include <string> @@ -72,7 +73,11 @@ public: return write(Str, strlen(Str)); } - raw_ostream &operator<<(unsigned N) { + raw_ostream &operator<<(const std::string& Str) { + return write(Str.data(), Str.length()); + } + + raw_ostream &operator<<(uint64_t N) { // Zero is a special case. if (N == 0) return *this << '0'; @@ -88,6 +93,34 @@ public: return write(CurPtr, EndPtr-CurPtr); } + raw_ostream &operator<<(int64_t N) { + if (N < 0) { + if (OutBufCur >= OutBufEnd) + flush_impl(); + *OutBufCur++ = '-'; + + N = -N; + } + + return this->operator<<(static_cast<uint64_t>(N)); + } + + raw_ostream &operator<<(uint32_t N) { + return this->operator<<(static_cast<uint64_t>(N)); + } + + raw_ostream &operator<<(int32_t N) { + return this->operator<<(static_cast<int64_t>(N)); + } + + raw_ostream &operator<<(size_t N) { + return this->operator<<(static_cast<uint64_t>(N)); + } + + raw_ostream &operator<<(double N) { + return this->operator<<(ftostr(N)); + } + raw_ostream &write(const char *Ptr, unsigned Size) { if (OutBufCur+Size > OutBufEnd) diff --git a/include/llvm/Target/TargetMachine.h b/include/llvm/Target/TargetMachine.h index e86af9fd8d..93c46ae28e 100644 --- a/include/llvm/Target/TargetMachine.h +++ b/include/llvm/Target/TargetMachine.h @@ -35,6 +35,7 @@ class PassManager; class Pass; class TargetMachOWriterInfo; class TargetELFWriterInfo; +class raw_ostream; // Relocation model types. namespace Reloc { @@ -196,7 +197,7 @@ public: /// is not supported. /// virtual FileModel::Model addPassesToEmitFile(PassManagerBase &, - std::ostream &, + raw_ostream &, CodeGenFileType, bool /*Fast*/) { return FileModel::None; @@ -227,7 +228,7 @@ public: /// require having the entire module at once. This is not recommended, do not /// use this. virtual bool WantsWholeFile() const { return false; } - virtual bool addPassesToEmitWholeFile(PassManager &, std::ostream &, + virtual bool addPassesToEmitWholeFile(PassManager &, raw_ostream &, CodeGenFileType, bool /*Fast*/) { return true; } @@ -253,7 +254,7 @@ public: /// target-specific passes in standard locations. /// virtual FileModel::Model addPassesToEmitFile(PassManagerBase &PM, - std::ostream &Out, + raw_ostream &Out, CodeGenFileType FileType, bool Fast); @@ -309,7 +310,7 @@ public: /// the asmprinter, if asm emission is supported. If this is not supported, /// 'true' should be returned. virtual bool addAssemblyEmitter(PassManagerBase &, bool /*Fast*/, - std::ostream &) { + raw_ostream &) { return true; } diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 2eccc36ccf..bf57a653ad 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 @@ void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section, 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 @@ void AsmPrinter::PrintULEB128(unsigned Value) const { 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 @@ void AsmPrinter::PrintSLEB128(int Value) const { 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 @@ void AsmPrinter::PrintSLEB128(int Value) const { /// 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 @@ static inline char toOctal(int X) { /// 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 @@ void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV, 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 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) { /// 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 5d6acc30ba..99e94e2ac0 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 @@ protected: // /// O - Stream to .s file. /// - std::ostream &O; + raw_ostream &O; /// Asm - Target of Dwarf emission. /// @@ -856,7 +857,7 @@ protected: 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 @@ public: //===--------------------------------------------------------------------===// // 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 @@ public: //===--------------------------------------------------------------------===// // 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 @@ void DIE::dump() { /// 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 761e910cb2..16abca22e1 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 @@ namespace { 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 @@ Y("ocaml", "ocaml 3.10-compatible collector"); 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 @@ static void EmitCamlGlobal(const Module &M, std::ostream &OS, AsmPrinter &AP, 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 @@ void OcamlGCMetadataPrinter::beginAssembly(std::ostream &OS, AsmPrinter &AP, /// (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 27f23f45cc..6f29112caf 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 @@ char ELFWriter::ID = 0; /// 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 @@ bool ELFCodeEmitter::finishFunction(MachineFunction &F) { // ELFWriter Implementation //===----------------------------------------------------------------------===// -ELFWriter::ELFWriter(std::ostream &o, Target |