[llvm-commits] [llvm] r75283 - in /llvm/trunk: include/llvm/CodeGen/AsmFormatter.h include/llvm/CodeGen/AsmStream.h include/llvm/Support/FormattedStream.h include/llvm/Support/raw_ostream.h lib/CodeGen/AsmStream.cpp lib/Support/FormattedStream.cpp lib/Support/raw_ostream.cpp
David Greene
greened at obbligato.org
Fri Jul 10 14:14:45 PDT 2009
Author: greened
Date: Fri Jul 10 16:14:44 2009
New Revision: 75283
URL: http://llvm.org/viewvc/llvm-project?rev=75283&view=rev
Log:
Make changes suggested by Chris and eliminate newly-added raw_ostream
hooks as they're no longer needed.
The major change with this patch is to make formatted_raw_ostream usable
by any client of raw_ostream.
Added:
llvm/trunk/include/llvm/CodeGen/AsmFormatter.h
llvm/trunk/include/llvm/Support/FormattedStream.h
- copied, changed from r75208, llvm/trunk/include/llvm/CodeGen/AsmStream.h
llvm/trunk/lib/Support/FormattedStream.cpp
- copied, changed from r75256, llvm/trunk/lib/CodeGen/AsmStream.cpp
Removed:
llvm/trunk/include/llvm/CodeGen/AsmStream.h
llvm/trunk/lib/CodeGen/AsmStream.cpp
Modified:
llvm/trunk/include/llvm/Support/raw_ostream.h
llvm/trunk/lib/Support/raw_ostream.cpp
Added: llvm/trunk/include/llvm/CodeGen/AsmFormatter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmFormatter.h?rev=75283&view=auto
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmFormatter.h (added)
+++ llvm/trunk/include/llvm/CodeGen/AsmFormatter.h Fri Jul 10 16:14:44 2009
@@ -0,0 +1,65 @@
+//===-- llvm/CodeGen/AsmFormatter.h - Formatted asm framework ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains various I/O manipulators to pretty-print asm.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Target/TargetAsmInfo.h"
+
+namespace llvm
+{
+ /// AsmComment - An I/O manipulator to output an end-of-line comment
+ ///
+ class AsmComment : public Column {
+ private:
+ /// CommentColumn - The column at which to output a comment
+ ///
+ static const int CommentColumn = 60;
+ /// Text - The comment to output
+ ///
+ std::string Text;
+ /// TAI - Target information from the code generator
+ ///
+ const TargetAsmInfo &TAI;
+
+ public:
+ AsmComment(const TargetAsmInfo &T)
+ : Column(CommentColumn), Text(""), TAI(T) {}
+
+ AsmComment(const std::string &Cmnt,
+ const TargetAsmInfo &T)
+ : Column(CommentColumn), Text(Cmnt), TAI(T) {}
+
+ /// operator() - Store a comments tring for later processing.
+ ///
+ AsmComment &operator()(const std::string &Cmnt) {
+ Text = Cmnt;
+ return *this;
+ }
+
+ /// operator() - Make Comment a functor invoktable by a stream
+ /// output operator. This intentially hides Column's operator().
+ ///
+ formatted_raw_ostream &operator()(formatted_raw_ostream &Out) const {
+ Column::operator()(Out);
+ Out << TAI.getCommentString() << " " << Text;
+ return(Out);
+ }
+ };
+
+ /// operator<< - Support comment formatting in formatted streams.
+ ///
+ inline formatted_raw_ostream &operator<<(formatted_raw_ostream &Out,
+ const AsmComment &Func)
+ {
+ return(Func(Out));
+ }
+}
Removed: llvm/trunk/include/llvm/CodeGen/AsmStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmStream.h?rev=75282&view=auto
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmStream.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmStream.h (removed)
@@ -1,179 +0,0 @@
-//===-- llvm/CodeGen/AsmStream.h - AsmStream Framework --------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file contains raw_ostream implementations for ASM printers to
-// do things like pretty-print comments.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CODEGEN_ASMSTREAM_H
-#define LLVM_CODEGEN_ASMSTREAM_H
-
-#include "llvm/Target/TargetAsmInfo.h"
-#include "llvm/Support/raw_ostream.h"
-
-namespace llvm
-{
- /// raw_asm_fd_ostream - Formatted raw_fd_ostream to handle
- /// asm-specific constructs
- ///
- class raw_asm_fd_ostream : public raw_fd_ostream {
- private:
- bool formatted;
- int column;
-
- protected:
- void ComputeColumn(void) {
- if (formatted) {
- // Keep track of the current column by scanning the string for
- // special characters
-
- // Find the last newline. This is our column start. If there
- // is no newline, start with the current column.
- char *nlpos = NULL;
- for (char *pos = CurBufPtr(), *epos = StartBufPtr(); pos > epos; --pos) {
- if (*(pos-1) == '\n') {
- nlpos = pos-1;
- // The newline will be counted, setting this to zero. We
- // need to do it this way in case nlpos is CurBufPtr().
- column = -1;
- break;
- }
- }
-
- if (nlpos == NULL) {
- nlpos = StartBufPtr();
- }
-
- // Walk through looking for tabs and advance column as appropriate
- for (char *pos = nlpos, *epos = CurBufPtr(); pos != epos; ++pos) {
- ++column;
- if (*pos == '\t') {
- // Advance to next tab stop (every eight characters)
- column += ((8 - (column & 0x7)) & 0x7);
- assert(!(column & 0x3) && "Column out of alignment");
- }
- }
- }
- }
-
- virtual void AboutToFlush(void) {
- ComputeColumn();
- }
-
- public:
- /// raw_asm_fd_ostream - Open the specified file for writing. If
- /// an error occurs, information about the error is put into
- /// ErrorInfo, and the stream should be immediately destroyed; the
- /// string will be empty if no error occurred.
- ///
- /// \param Filename - The file to open. If this is "-" then the
- /// stream will use stdout instead.
- /// \param Binary - The file should be opened in binary mode on
- /// platforms that support this distinction.
- raw_asm_fd_ostream(const char *Filename, bool Binary, std::string &ErrorInfo)
- : raw_fd_ostream(Filename, Binary, ErrorInfo),
- formatted(!Binary), column(0) {}
-
- /// raw_asm_fd_ostream ctor - FD is the file descriptor that this
- /// writes to. If ShouldClose is true, this closes the file when
- /// the stream is destroyed.
- raw_asm_fd_ostream(int fd, bool shouldClose,
- bool unbuffered=false)
- : raw_fd_ostream(fd, shouldClose, unbuffered),
- formatted(true), column(0) {
- if (unbuffered) {
- assert(0 && "asm stream must be buffered");
- // Force buffering
- SetBufferSize();
- }
- }
-
-
- /// SetColumn - Align the output to some column number
- ///
- void setColumn(int newcol, int minpad = 0) {
- if (formatted) {
- flush();
-
- // Output spaces until we reach the desired column
- int num = newcol - column;
- if (num <= 0) {
- num = minpad;
- }
-
- // TODO: Write a whole string at a time
- while (num-- > 0) {
- write(' ');
- }
- }
- };
- };
-
- /// Column - An I/O manipulator to advance the output to a certain column
- ///
- class Column {
- private:
- int column;
-
- public:
- explicit Column(int c)
- : column(c) {}
-
- raw_asm_fd_ostream &operator()(raw_asm_fd_ostream &out) const {
- // Make at least one space before the comment
- out.setColumn(column, 1);
- return(out);
- }
- };
-
- inline raw_asm_fd_ostream &operator<<(raw_asm_fd_ostream &out, const Column &column)
- {
- return(column(out));
- }
-
- /// Comment - An I/O manipulator to output an end-of-line comment
- ///
- class Comment
- : public Column {
- private:
- static const int CommentColumn = 60;
- std::string text;
- const TargetAsmInfo &TAI;
-
- public:
- Comment(const std::string &comment,
- const TargetAsmInfo &tai)
- : Column(CommentColumn), text(comment), TAI(tai) {}
-
- raw_asm_fd_ostream &operator()(raw_asm_fd_ostream &out) const {
- Column::operator()(out);
- out << TAI.getCommentString() << " " << text;
- return(out);
- }
- };
-
- inline raw_asm_fd_ostream &operator<<(raw_asm_fd_ostream &out,
- const Comment &comment)
- {
- return(comment(out));
- }
-
- /// Asm stream equivalent for std streams
- ///
-
- /// WARNING: Do NOT use these streams in the constructors of global
- /// objects. There is no mechanism to ensure they are initialized
- /// before other global objects.
- ///
- extern raw_asm_fd_ostream asmouts;
- extern raw_asm_fd_ostream asmerrs;
-}
-
-#endif
Copied: llvm/trunk/include/llvm/Support/FormattedStream.h (from r75208, llvm/trunk/include/llvm/CodeGen/AsmStream.h)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FormattedStream.h?p2=llvm/trunk/include/llvm/Support/FormattedStream.h&p1=llvm/trunk/include/llvm/CodeGen/AsmStream.h&r1=75208&r2=75283&rev=75283&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmStream.h (original)
+++ llvm/trunk/include/llvm/Support/FormattedStream.h Fri Jul 10 16:14:44 2009
@@ -1,21 +1,20 @@
-//===-- llvm/CodeGen/AsmStream.h - AsmStream Framework --------*- C++ -*-===//
+//===-- llvm/CodeGen/FormattedStream.h - Formatted streams ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
-// This file contains raw_ostream implementations for ASM printers to
-// do things like pretty-print comments.
+// This file contains raw_ostream implementations for streams to do
+// things like pretty-print comments.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CODEGEN_ASMSTREAM_H
#define LLVM_CODEGEN_ASMSTREAM_H
-#include "llvm/Target/TargetAsmInfo.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm
@@ -23,157 +22,85 @@
/// raw_asm_fd_ostream - Formatted raw_fd_ostream to handle
/// asm-specific constructs
///
- class raw_asm_fd_ostream : public raw_fd_ostream {
+ class formatted_raw_ostream : public raw_ostream {
private:
- bool formatted;
- int column;
+ /// TheStream - The real stream we output to
+ ///
+ raw_ostream &TheStream;
+
+ /// Column - The current output column of the stream
+ ///
+ unsigned Column;
- protected:
- void ComputeColumn(void) {
- if (formatted) {
- // Keep track of the current column by scanning the string for
- // special characters
-
- // Find the last newline. This is our column start. If there
- // is no newline, start with the current column.
- char *nlpos = NULL;
- for (char *pos = CurBufPtr(), *epos = StartBufPtr(); pos > epos; --pos) {
- if (*(pos-1) == '\n') {
- nlpos = pos-1;
- // The newline will be counted, setting this to zero. We
- // need to do it this way in case nlpos is CurBufPtr().
- column = -1;
- break;
- }
- }
-
- if (nlpos == NULL) {
- nlpos = StartBufPtr();
- }
-
- // Walk through looking for tabs and advance column as appropriate
- for (char *pos = nlpos, *epos = CurBufPtr(); pos != epos; ++pos) {
- ++column;
- if (*pos == '\t') {
- // Advance to next tab stop (every eight characters)
- column += ((8 - (column & 0x7)) & 0x7);
- assert(!(column & 0x3) && "Column out of alignment");
- }
- }
- }
+ virtual void write_impl(const char *Ptr, unsigned Size) {
+ ComputeColumn(Ptr, Size);
+ TheStream.write(Ptr, Size);
}
- virtual void AboutToFlush(void) {
- ComputeColumn();
+ /// current_pos - Return the current position within the stream,
+ /// not counting the bytes currently in the buffer.
+ virtual uint64_t current_pos() {
+ // 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.
+ ///
+ void ComputeColumn(const char *Ptr, unsigned Size);
+
public:
- /// raw_asm_fd_ostream - Open the specified file for writing. If
- /// an error occurs, information about the error is put into
- /// ErrorInfo, and the stream should be immediately destroyed; the
- /// string will be empty if no error occurred.
+ /// formatted_raw_ostream - Open the specified file for
+ /// writing. If an error occurs, information about the error is
+ /// put into ErrorInfo, and the stream should be immediately
+ /// destroyed; the string will be empty if no error occurred.
///
/// \param Filename - The file to open. If this is "-" then the
/// stream will use stdout instead.
/// \param Binary - The file should be opened in binary mode on
/// platforms that support this distinction.
- raw_asm_fd_ostream(const char *Filename, bool Binary, std::string &ErrorInfo)
- : raw_fd_ostream(Filename, Binary, ErrorInfo),
- formatted(!Binary), column(0) {}
-
- /// raw_asm_fd_ostream ctor - FD is the file descriptor that this
- /// writes to. If ShouldClose is true, this closes the file when
- /// the stream is destroyed.
- raw_asm_fd_ostream(int fd, bool shouldClose,
- bool unbuffered=false)
- : raw_fd_ostream(fd, shouldClose, unbuffered),
- formatted(true), column(0) {
- if (unbuffered) {
- assert(0 && "asm stream must be buffered");
- // Force buffering
- SetBufferSize();
- }
- }
+ formatted_raw_ostream(raw_ostream &Stream)
+ : raw_ostream(), TheStream(Stream), Column(0) {}
-
- /// SetColumn - Align the output to some column number
+ /// PadToColumn - Align the output to some column number
+ ///
+ /// \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 setColumn(int newcol, int minpad = 0) {
- if (formatted) {
- flush();
-
- // Output spaces until we reach the desired column
- int num = newcol - column;
- if (num <= 0) {
- num = minpad;
- }
-
- // TODO: Write a whole string at a time
- while (num-- > 0) {
- write(' ');
- }
- }
- };
+ void PadToColumn(unsigned NewCol, unsigned MinPad = 0);
};
/// Column - An I/O manipulator to advance the output to a certain column
///
class Column {
private:
- int column;
+ /// Col - The column to move to
+ ///
+ unsigned int Col;
public:
- explicit Column(int c)
- : column(c) {}
+ explicit Column(unsigned int c)
+ : Col(c) {}
- raw_asm_fd_ostream &operator()(raw_asm_fd_ostream &out) const {
- // Make at least one space before the comment
- out.setColumn(column, 1);
- return(out);
+ /// operator() - Make Column a functor invokable by a stream
+ /// output operator.
+ ///
+ formatted_raw_ostream &operator()(formatted_raw_ostream &Out) const {
+ // Make at least one space before the next output
+ Out.PadToColumn(Col, 1);
+ return(Out);
}
};
- inline raw_asm_fd_ostream &operator<<(raw_asm_fd_ostream &out, const Column &column)
- {
- return(column(out));
- }
-
- /// Comment - An I/O manipulator to output an end-of-line comment
+ /// operator<< - Support coulmn-setting in formatted streams.
///
- class Comment
- : public Column {
- private:
- static const int CommentColumn = 60;
- std::string text;
- const TargetAsmInfo &TAI;
-
- public:
- Comment(const std::string &comment,
- const TargetAsmInfo &tai)
- : Column(CommentColumn), text(comment), TAI(tai) {}
-
- raw_asm_fd_ostream &operator()(raw_asm_fd_ostream &out) const {
- Column::operator()(out);
- out << TAI.getCommentString() << " " << text;
- return(out);
- }
- };
-
- inline raw_asm_fd_ostream &operator<<(raw_asm_fd_ostream &out,
- const Comment &comment)
+ inline formatted_raw_ostream &operator<<(formatted_raw_ostream &Out,
+ const Column &Func)
{
- return(comment(out));
+ return(Func(Out));
}
-
- /// Asm stream equivalent for std streams
- ///
-
- /// WARNING: Do NOT use these streams in the constructors of global
- /// objects. There is no mechanism to ensure they are initialized
- /// before other global objects.
- ///
- extern raw_asm_fd_ostream asmouts;
- extern raw_asm_fd_ostream asmerrs;
}
#endif
Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=75283&r1=75282&r2=75283&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Fri Jul 10 16:14:44 2009
@@ -44,22 +44,6 @@
char *OutBufStart, *OutBufEnd, *OutBufCur;
bool Unbuffered;
-protected:
- /// CurBufPtr - Get a pointer to the current location in the buffer.
- ///
- char *CurBufPtr(void) { return OutBufCur; }
- /// StartBufPtr - Get a pointer to the start of the buffer
- ///
- char *StartBufPtr(void) { return OutBufStart; }
- /// EndBufPtr - Get a pointer to the end of the buffer
- ///
- char *EndBufPtr(void) { return OutBufEnd; }
-
- /// AboutToFlush- Called when the buffer is about to be flushed,
- /// allowing derived classes to take some action.
- ///
- virtual void AboutToFlush(void) {};
-
public:
// color order matches ANSI escape sequence, don't change
enum Colors {
Removed: llvm/trunk/lib/CodeGen/AsmStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmStream.cpp?rev=75282&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmStream.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmStream.cpp (removed)
@@ -1,19 +0,0 @@
-//===-- llvm/CodeGen/AsmStream.cpp - AsmStream Framework --------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file contains instantiations of "standard" AsmOStreams.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CodeGen/AsmStream.h"
-
-namespace llvm {
- raw_asm_fd_ostream asmouts(STDOUT_FILENO, false);
- raw_asm_fd_ostream asmerrs(STDERR_FILENO, false);
-}
Copied: llvm/trunk/lib/Support/FormattedStream.cpp (from r75256, llvm/trunk/lib/CodeGen/AsmStream.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FormattedStream.cpp?p2=llvm/trunk/lib/Support/FormattedStream.cpp&p1=llvm/trunk/lib/CodeGen/AsmStream.cpp&r1=75256&r2=75283&rev=75283&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmStream.cpp (original)
+++ llvm/trunk/lib/Support/FormattedStream.cpp Fri Jul 10 16:14:44 2009
@@ -11,9 +11,64 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/CodeGen/AsmStream.h"
+#include "llvm/Support/FormattedStream.h"
namespace llvm {
- raw_asm_fd_ostream asmouts(STDOUT_FILENO, false);
- raw_asm_fd_ostream asmerrs(STDERR_FILENO, false);
+ /// ComputeColumn - Examine the current output and figure out which
+ /// column we end up in after output.
+ ///
+ void formatted_raw_ostream::ComputeColumn(const char *Ptr, unsigned Size)
+ {
+ // Keep track of the current column by scanning the string for
+ // special characters
+
+ // Find the last newline. This is our column start. If there
+ // is no newline, start with the current column.
+ const char *nlpos = NULL;
+ for (const char *pos = Ptr + Size, *epos = Ptr; pos > epos; --pos) {
+ if (*(pos-1) == '\n') {
+ nlpos = pos-1;
+ // The newline will be counted, setting this to zero. We
+ // need to do it this way in case nlpos is Ptr.
+ Column = -1;
+ break;
+ }
+ }
+
+ if (nlpos == NULL) {
+ nlpos = Ptr;
+ }
+
+ // Walk through looking for tabs and advance column as appropriate
+ for (const char *pos = nlpos, *epos = Ptr + Size; pos != epos; ++pos) {
+ ++Column;
+ if (*pos == '\t') {
+ // Advance to next tab stop (every eight characters)
+ Column += ((8 - (Column & 0x7)) & 0x7);
+ assert(!(Column & 0x3) && "Column out of alignment");
+ }
+ }
+ }
+
+ /// PadToColumn - Align the output to some column number
+ ///
+ /// \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 formatted_raw_ostream::PadToColumn(unsigned NewCol, unsigned MinPad)
+ {
+ flush();
+
+ // Output spaces until we reach the desired column
+ unsigned num = NewCol - Column;
+ if (NewCol < Column || num < MinPad) {
+ num = MinPad;
+ }
+
+ // TODO: Write a whole string at a time
+ while (num-- > 0) {
+ write(' ');
+ }
+ }
}
Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=75283&r1=75282&r2=75283&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Fri Jul 10 16:14:44 2009
@@ -120,7 +120,6 @@
void raw_ostream::flush_nonempty() {
assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty.");
- AboutToFlush();
write_impl(OutBufStart, OutBufCur - OutBufStart);
OutBufCur = OutBufStart;
}
More information about the llvm-commits
mailing list