1 //===-- llvm/CodeGen/FormattedStream.h - Formatted streams ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains raw_ostream implementations for streams to do
11 // things like pretty-print comments.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_FORMATTEDSTREAM_H
16 #define LLVM_SUPPORT_FORMATTEDSTREAM_H
18 #include "llvm/Support/raw_ostream.h"
22 /// formatted_raw_ostream - Formatted raw_fd_ostream to handle
23 /// asm-specific constructs.
25 class formatted_raw_ostream : public raw_ostream {
27 /// TheStream - The real stream we output to.
29 raw_ostream &TheStream;
31 /// Column - The current output column of the stream. The column
32 /// scheme is zero-based.
36 virtual void write_impl(const char *Ptr, unsigned Size) {
37 ComputeColumn(Ptr, Size);
38 TheStream.write(Ptr, Size);
41 /// current_pos - Return the current position within the stream,
42 /// not counting the bytes currently in the buffer.
43 virtual uint64_t current_pos() {
44 // This has the same effect as calling TheStream.current_pos(),
45 // but that interface is private.
46 return TheStream.tell() - TheStream.GetNumBytesInBuffer();
49 /// ComputeColumn - Examine the current output and figure out
50 /// which column we end up in after output.
52 void ComputeColumn(const char *Ptr, unsigned Size);
55 /// formatted_raw_ostream - Open the specified file for
56 /// writing. If an error occurs, information about the error is
57 /// put into ErrorInfo, and the stream should be immediately
58 /// destroyed; the string will be empty if no error occurred.
60 /// \param Filename - The file to open. If this is "-" then the
61 /// stream will use stdout instead.
62 /// \param Binary - The file should be opened in binary mode on
63 /// platforms that support this distinction.
64 formatted_raw_ostream(raw_ostream &Stream)
65 : raw_ostream(), TheStream(Stream), Column(0) {}
67 /// PadToColumn - Align the output to some column number.
69 /// \param NewCol - The column to move to.
70 /// \param MinPad - The minimum space to give after the most
71 /// recent I/O, even if the current column + minpad > newcol.
73 void PadToColumn(unsigned NewCol, unsigned MinPad = 0);