diff options
67 files changed, 265 insertions, 194 deletions
diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index d7a0225030..1a43f5ee40 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -40,7 +40,7 @@ namespace llvm { class Section; class TargetAsmInfo; class Type; - class raw_ostream; + class formatted_raw_ostream; /// AsmPrinter - This class is intended to be used as a driving class for all /// asm writers. @@ -69,7 +69,7 @@ namespace llvm { public: /// Output stream on which we're printing assembly code. /// - raw_ostream &O; + formatted_raw_ostream &O; /// Target machine description. /// @@ -118,7 +118,7 @@ namespace llvm { mutable DebugLocTuple PrevDLT; protected: - explicit AsmPrinter(raw_ostream &o, TargetMachine &TM, + explicit AsmPrinter(formatted_raw_ostream &o, TargetMachine &TM, const TargetAsmInfo *T, bool V); public: diff --git a/include/llvm/Support/FormattedStream.h b/include/llvm/Support/FormattedStream.h index 2cead0a2f0..1c213abe2d 100644 --- a/include/llvm/Support/FormattedStream.h +++ b/include/llvm/Support/FormattedStream.h @@ -23,10 +23,23 @@ namespace llvm /// asm-specific constructs. /// class formatted_raw_ostream : public raw_ostream { + public: + /// DELETE_STREAM - Tell the destructor to delete the held stream. + /// + const static bool DELETE_STREAM = true; + /// PRESERVE_STREAM - Tell the destructor to not delete the held + /// stream. + /// + const static bool PRESERVE_STREAM = false; + private: /// TheStream - The real stream we output to. /// raw_ostream &TheStream; + /// DeleteStream - Do we need to delete TheStream in the + /// destructor? + /// + bool DeleteStream; /// Column - The current output column of the stream. The column /// scheme is zero-based. @@ -61,8 +74,13 @@ namespace llvm /// stream will use stdout instead. /// \param Binary - The file should be opened in binary mode on /// platforms that support this distinction. - formatted_raw_ostream(raw_ostream &Stream) - : raw_ostream(), TheStream(Stream), Column(0) {} + formatted_raw_ostream(raw_ostream &Stream, bool Delete = false) + : raw_ostream(), TheStream(Stream), DeleteStream(Delete), Column(0) {} + + ~formatted_raw_ostream() { + if (DeleteStream) + delete &TheStream; + } /// PadToColumn - Align the output to some column number. /// @@ -72,6 +90,16 @@ namespace llvm /// void PadToColumn(unsigned NewCol, unsigned MinPad = 0); }; -} + +/// fouts() - This returns a reference to a formatted_raw_ostream for +/// standard output. Use it like: fouts() << "foo" << "bar"; +formatted_raw_ostream &fouts(); + +/// ferrs() - This returns a reference to a formatted_raw_ostream for +/// standard error. Use it like: ferrs() << "foo" << "bar"; +formatted_raw_ostream &ferrs(); + +} // end llvm namespace + #endif diff --git a/include/llvm/Target/TargetMachine.h b/include/llvm/Target/TargetMachine.h index 21e778da40..ce293d5114 100644 --- a/include/llvm/Target/TargetMachine.h +++ b/include/llvm/Target/TargetMachine.h @@ -37,7 +37,7 @@ class PassManager; class Pass; class TargetMachOWriterInfo; class TargetELFWriterInfo; -class raw_ostream; +class formatted_raw_ostream; // Relocation model types. namespace Reloc { @@ -232,7 +232,7 @@ public: /// is not supported. /// virtual FileModel::Model addPassesToEmitFile(PassManagerBase &, - raw_ostream &, + formatted_raw_ostream &, CodeGenFileType, CodeGenOpt::Level) { return FileModel::None; @@ -296,7 +296,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 &, raw_ostream &, + virtual bool addPassesToEmitWholeFile(PassManager &, formatted_raw_ostream &, CodeGenFileType, CodeGenOpt::Level) { return true; @@ -329,7 +329,7 @@ public: /// target-specific passes in standard locations. /// virtual FileModel::Model addPassesToEmitFile(PassManagerBase &PM, - raw_ostream &Out, + formatted_raw_ostream &Out, CodeGenFileType FileType, CodeGenOpt::Level); @@ -413,7 +413,8 @@ public: /// the asmprinter, if asm emission is supported. If this is not supported, /// 'true' should be returned. virtual bool addAssemblyEmitter(PassManagerBase &, CodeGenOpt::Level, - bool /* VerboseAsmDefault */, raw_ostream &) { + bool /* VerboseAsmDefault */, + formatted_raw_ostream &) { return true; } diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 7e1d413fd1..7ac780f687 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -26,7 +26,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/Mangler.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/FormattedStream.h" #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetLowering.h" @@ -43,7 +43,7 @@ AsmVerbose("asm-verbose", cl::desc("Add comments to directives."), cl::init(cl::BOU_UNSET)); char AsmPrinter::ID = 0; -AsmPrinter::AsmPrinter(raw_ostream &o, TargetMachine &tm, +AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm, const TargetAsmInfo *T, bool VDef) : MachineFunctionPass(&ID), FunctionNumber(0), O(o), TM(tm), TAI(T), TRI(tm.getRegisterInfo()), @@ -736,7 +736,7 @@ static inline char toOctal(int X) { /// printStringChar - Print a char, escaped if necessary. /// -static void printStringChar(raw_ostream &O, unsigned char C) { +static void printStringChar(formatted_raw_ostream &O, unsigned char C) { if (C == '"') { O << "\\\""; } else if (C == '\\') { @@ -978,7 +978,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(raw_ostream &O, const ConstantArray *CVA, +static void printAsCString(formatted_raw_ostream &O, const ConstantArray *CVA, unsigned LastElt) { assert(CVA->isString() && "Array is not string compatible!"); diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index d7fde5f90a..b9f4edc7a8 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -22,7 +22,7 @@ #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/FormattedStream.h" using namespace llvm; namespace llvm { @@ -56,7 +56,7 @@ EnableFastISelOption("fast-isel", cl::Hidden, FileModel::Model LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, - raw_ostream &Out, + formatted_raw_ostream &Out, CodeGenFileType FileType, CodeGenOpt::Level OptLevel) { // Add common CodeGen passes. diff --git a/lib/Support/FormattedStream.cpp b/lib/Support/FormattedStream.cpp index df91641962..01dea3628c 100644 --- a/lib/Support/FormattedStream.cpp +++ b/lib/Support/FormattedStream.cpp @@ -55,3 +55,16 @@ void formatted_raw_ostream::PadToColumn(unsigned NewCol, unsigned MinPad) } } +/// fouts() - This returns a reference to a formatted_raw_ostream for +/// standard output. Use it like: fouts() << "foo" << "bar"; +formatted_raw_ostream &llvm::fouts() { + static formatted_raw_ostream S(outs()); + return S; +} + +/// ferrs() - This returns a reference to a formatted_raw_ostream for +/// standard error. Use it like: ferrs() << "foo" << "bar"; +formatted_raw_ostream &llvm::ferrs() { + static formatted_raw_ostream S(errs()); + return S; +} diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 42e6fda97b..23a756e4df 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -166,7 +166,7 @@ raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) { case 0: break; default: // Normally the string to emit is shorter than the buffer. - if (Size <= unsigned(OutBufEnd-OutBufStart)) { + if (Size <= unsigned(OutBufEnd-OutBufCur)) { memcpy(OutBufCur, Ptr, Size); break; } diff --git a/lib/Target/ARM/ARM.h b/lib/Target/ARM/ARM.h index 3c0cfa5121..f6ae6806fd 100644 --- a/lib/Target/ARM/ARM.h +++ b/lib/Target/ARM/ARM.h @@ -26,7 +26,7 @@ class FunctionPass; class MachineCodeEmitter; class JITCodeEmitter; class ObjectCodeEmitter; -class raw_ostream; +class formatted_raw_ostream; // Enums corresponding to ARM condition codes namespace ARMCC { @@ -93,7 +93,7 @@ inline static const char *ARMCondCodeToString(ARMCC::CondCodes CC) { } FunctionPass *createARMISelDag(ARMBaseTargetMachine &TM); -FunctionPass *createARMCodePrinterPass(raw_ostream &O, +FunctionPass *createARMCodePrinterPass(formatted_raw_ostream &O, ARMBaseTargetMachine &TM, bool Verbose); FunctionPass *createARMCodeEmitterPass(ARMBaseTargetMachine &TM, diff --git a/lib/Target/ARM/ARMTargetMachine.cpp b/lib/Target/ARM/ARMTargetMachine.cpp index a827784383..6ebc1fdcd2 100644 --- a/lib/Target/ARM/ARMTargetMachine.cpp +++ b/lib/Target/ARM/ARMTargetMachine.cpp @@ -18,7 +18,7 @@ #include "llvm/PassManager.h" #include "llvm/CodeGen/Passes.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/FormattedStream.h" #include "llvm/Target/TargetMachineRegistry.h" #include "llvm/Target/TargetOptions.h" using namespace llvm; @@ -183,7 +183,7 @@ bool ARMBaseTargetMachine::addPreEmitPass(PassManagerBase &PM, bool ARMBaseTargetMachine::addAssemblyEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool Verbose, - raw_ostream &Out) { + formatted_raw_ostream &Out) { // Output assembly language. assert(AsmPrinterCtor && "AsmPrinter was not linked in"); if (AsmPrinterCtor) @@ -206,7 +206,7 @@ bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM, if (DumpAsm) { assert(AsmPrinterCtor && "AsmPrinter was not linked in"); if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(errs(), *this, true)); + PM.add(AsmPrinterCtor(ferrs(), *this, true)); } return false; @@ -225,7 +225,7 @@ bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM, if (DumpAsm) { assert(AsmPrinterCtor && "AsmPrinter was not linked in"); if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(errs(), *this, true)); + PM.add(AsmPrinterCtor(ferrs(), *this, true)); } return false; @@ -244,7 +244,7 @@ bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM, if (DumpAsm) { assert(AsmPrinterCtor && "AsmPrinter was not linked in"); if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(errs(), *this, true)); + PM.add(AsmPrinterCtor(ferrs(), *this, true)); } return false; @@ -259,7 +259,7 @@ bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, if (DumpAsm) { assert(AsmPrinterCtor && "AsmPrinter was not linked in"); if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(errs(), *this, true)); + PM.add(AsmPrinterCtor(ferrs(), *this, true)); } return false; @@ -274,7 +274,7 @@ bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, if (DumpAsm) { assert(AsmPrinterCtor && "AsmPrinter was not linked in"); if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(errs(), *this, true)); + PM.add(AsmPrinterCtor(ferrs(), *this, true)); } return false; @@ -289,7 +289,7 @@ bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, if (DumpAsm) { assert(AsmPrinterCtor && "AsmPrinter was not linked in"); if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(errs(), *this, true)); + PM.add(AsmPrinterCtor(ferrs(), *this, true)); } return false; diff --git a/lib/Target/ARM/ARMTargetMachine.h b/lib/Target/ARM/ARMTargetMachine.h index 4d9734646c..56b18ae36a 100644 --- a/lib/Target/ARM/ARMTargetMachine.h +++ b/lib/Target/ARM/ARMTargetMachine.h @@ -41,7 +41,7 @@ private: protected: // To avoid having target depend on the asmprinter stuff libraries, asmprinter // set this functions to ctor pointer at startup time if they are linked in. - typedef FunctionPass *(*AsmPrinterCtorFn)(raw_ostream &o, + typedef FunctionPass *(*AsmPrinterCtorFn)(formatted_raw_ostream &o, ARMBaseTargetMachine &tm, bool verbose); static AsmPrinterCtorFn AsmPrinterCtor; @@ -71,7 +71,7 @@ public: virtual bool addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel); virtual bool addAssemblyEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, - bool Verbose, raw_ostream &Out); + bool Verbose, formatted_raw_ostream &Out); virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, MachineCodeEmitter &MCE); virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index 331d7aba05..a7593c91ae 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -38,7 +38,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/FormattedStream.h" #include <cctype> using namespace llvm; @@ -82,7 +82,7 @@ namespace { /// True if asm printer is printing a series of CONSTPOOL_ENTRY. bool InCPMode; public: - explicit ARMAsmPrinter(raw_ostream &O, TargetMachine &TM, + explicit ARMAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T, bool V) : AsmPrinter(O, TM, T, V), DW(0), AFI(NULL), MCP(NULL), InCPMode(false) { @@ -371,7 +371,7 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum, } } -static void printSOImm(raw_ostream &O, int64_t V, bool VerboseAsm, +static void printSOImm(formatted_raw_ostream &O, int64_t V, bool VerboseAsm, const TargetAsmInfo *TAI) { // Break it up into two parts that make up a shifter immediate. V = ARM_AM::getSOImmVal(V); @@ -1013,7 +1013,7 @@ bool ARMAsmPrinter::doInitialization(Module &M) { /// PrintUnmangledNameSafely - Print out the printable characters in the name. /// Don't print things like \\n or \\0. -static void PrintUnmangledNameSafely(const Value *V, raw_ostream &OS) { +static void PrintUnmangledNameSafely(const Value *V, formatted_raw_ostream &OS) { for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen(); Name != E; ++Name) if (isprint(*Name)) @@ -1253,7 +1253,7 @@ bool ARMAsmPrinter::doFinalization(Module &M) { /// using the given target machine description. This should work /// regardless of whether the function is in SSA form. /// -FunctionPass *llvm::createARMCodePrinterPass(raw_ostream &o, +FunctionPass *llvm::createARMCodePrinterPass(formatted_raw_ostream &o, ARMBaseTargetMachine &tm, bool verbose) { return new ARMAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose); diff --git a/lib/Target/Alpha/Alpha.h b/lib/Target/Alpha/Alpha.h index 071257a428..9226a5590f 100644 --- a/lib/Target/Alpha/Alpha.h +++ b/lib/Target/Alpha/Alpha.h @@ -23,10 +23,10 @@ namespace llvm { class FunctionPass; class MachineCodeEmitter; class ObjectCodeEmitter; - class raw_ostream; + class formatted_raw_ostream; FunctionPass *createAlphaISelDag(AlphaTargetMachine &TM); - FunctionPass *createAlphaCodePrinterPass(raw_ostream &OS, + FunctionPass *createAlphaCodePrinterPass(formatted_raw_ostream &OS, TargetMachine &TM, bool Verbose); FunctionPass *createAlphaPatternInstructionSelector(TargetMachine &TM); diff --git a/lib/Target/Alpha/AlphaTargetMachine.cpp b/lib/Target/Alpha/AlphaTargetMachine.cpp index 9b0f8d0695..625d0cea54 100644 --- a/lib/Target/Alpha/AlphaTargetMachine.cpp +++ b/lib/Target/Alpha/AlphaTargetMachine.cpp @@ -17,7 +17,7 @@ #include "llvm/Module.h" #include "llvm/PassManager.h" #include "llvm/Target/TargetMachineRegistry.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/FormattedStream.h" using namespace llvm; @@ -89,7 +89,7 @@ bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM, bool AlphaTargetMachi |