X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FFormattedStream.h;h=58a18851687ca2b7732f43af1d68b0ef0b4af11f;hb=a00b80b04c5edb08639c1c6b32e9231fd8b066f7;hp=4b13ff2d5abc0ebf396fe6fcf21bbe37605ce541;hpb=95db93caa1130725123eb50479d0c51c09e8a2f4;p=oota-llvm.git diff --git a/include/llvm/Support/FormattedStream.h b/include/llvm/Support/FormattedStream.h index 4b13ff2d5ab..58a18851687 100644 --- a/include/llvm/Support/FormattedStream.h +++ b/include/llvm/Support/FormattedStream.h @@ -1,4 +1,4 @@ -//===-- llvm/CodeGen/FormattedStream.h - Formatted streams ------*- C++ -*-===// +//===-- llvm/Support/FormattedStream.h - Formatted streams ------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -26,17 +26,12 @@ namespace llvm public: /// DELETE_STREAM - Tell the destructor to delete the held stream. /// - const static bool DELETE_STREAM = true; + static const bool DELETE_STREAM = true; /// PRESERVE_STREAM - Tell the destructor to not delete the held /// stream. /// - const static bool PRESERVE_STREAM = false; - - /// MAX_COLUMN_PAD - This is the maximum column padding we ever - /// expect to see. - /// - const static unsigned MAX_COLUMN_PAD = 100; + static const bool PRESERVE_STREAM = false; private: /// TheStream - The real stream we output to. We set it to be @@ -49,28 +44,31 @@ namespace llvm /// bool DeleteStream; - /// Column - The current output column of the stream. The column - /// scheme is zero-based. + /// ColumnScanned - The current output column of the data that's + /// been flushed and the portion of the buffer that's been + /// scanned. The column scheme is zero-based. /// - unsigned Column; + unsigned ColumnScanned; - virtual void write_impl(const char *Ptr, size_t Size) { - ComputeColumn(Ptr, Size); - TheStream->write(Ptr, Size); - } + /// Scanned - This points to one past the last character in the + /// buffer we've scanned. + /// + const char *Scanned; + + virtual void write_impl(const char *Ptr, size_t Size); /// current_pos - Return the current position within the stream, /// not counting the bytes currently in the buffer. - virtual uint64_t current_pos() { + virtual uint64_t current_pos() const { // This has the same effect as calling TheStream.current_pos(), // but that interface is private. return TheStream->tell() - TheStream->GetNumBytesInBuffer(); } - /// ComputeColumn - Examine the current output and figure out - /// which column we end up in after output. + /// ComputeColumn - Examine the given output buffer and figure out which + /// column we end up in after output. /// - void ComputeColumn(const char *Ptr, size_t Size); + void ComputeColumn(const char *Ptr, size_t size); public: /// formatted_raw_ostream - Open the specified file for @@ -84,20 +82,21 @@ namespace llvm /// underneath it. /// formatted_raw_ostream(raw_ostream &Stream, bool Delete = false) - : raw_ostream(), TheStream(0), DeleteStream(false), Column(0) { + : raw_ostream(), TheStream(0), DeleteStream(false), ColumnScanned(0) { setStream(Stream, Delete); } explicit formatted_raw_ostream() - : raw_ostream(), TheStream(0), DeleteStream(false), Column(0) {} + : raw_ostream(), TheStream(0), DeleteStream(false), ColumnScanned(0) { + Scanned = 0; + } ~formatted_raw_ostream() { - if (DeleteStream) - delete TheStream; + flush(); + releaseStream(); } - + void setStream(raw_ostream &Stream, bool Delete = false) { - if (DeleteStream) - delete TheStream; + releaseStream(); TheStream = &Stream; DeleteStream = Delete; @@ -106,19 +105,35 @@ namespace llvm // own buffering, and it doesn't need or want TheStream to do another // layer of buffering underneath. Resize the buffer to what TheStream // had been using, and tell TheStream not to do its own buffering. - TheStream->flush(); - if (size_t BufferSize = TheStream->GetNumBytesInBuffer()) + if (size_t BufferSize = TheStream->GetBufferSize()) SetBufferSize(BufferSize); + else + SetUnbuffered(); TheStream->SetUnbuffered(); + + Scanned = 0; } - /// PadToColumn - Align the output to some column number. + /// PadToColumn - Align the output to some column number. If the current + /// column is already equal to or more than NewCol, PadToColumn inserts one + /// space. /// /// \param NewCol - The column to move to. - /// \param MinPad - The minimum space to give after the most - /// recent I/O, even if the current column + minpad > newcol. - /// - void PadToColumn(unsigned NewCol, unsigned MinPad = 0); + formatted_raw_ostream &PadToColumn(unsigned NewCol); + + private: + void releaseStream() { + // Delete the stream if needed. Otherwise, transfer the buffer + // settings from this raw_ostream back to the underlying stream. + if (!TheStream) + return; + if (DeleteStream) + delete TheStream; + else if (size_t BufferSize = GetBufferSize()) + TheStream->SetBufferSize(BufferSize); + else + TheStream->SetUnbuffered(); + } }; /// fouts() - This returns a reference to a formatted_raw_ostream for @@ -129,6 +144,10 @@ formatted_raw_ostream &fouts(); /// standard error. Use it like: ferrs() << "foo" << "bar"; formatted_raw_ostream &ferrs(); +/// fdbgs() - This returns a reference to a formatted_raw_ostream for +/// debug output. Use it like: fdbgs() << "foo" << "bar"; +formatted_raw_ostream &fdbgs(); + } // end llvm namespace