14 #ifndef LLVM_SUPPORT_RAW_OSTREAM_H 15 #define LLVM_SUPPORT_RAW_OSTREAM_H 24 #include <system_error> 28 class formatv_object_base;
29 class format_object_base;
30 class FormattedString;
31 class FormattedNumber;
66 char *OutBufStart, *OutBufEnd, *OutBufCur;
89 : BufferMode(unbuffered ? Unbuffered : InternalBuffer) {
91 OutBufStart = OutBufEnd = OutBufCur =
nullptr;
100 uint64_t
tell()
const {
return current_pos() + GetNumBytesInBuffer(); }
113 SetBufferAndMode(
new char[Size], Size, InternalBuffer);
119 if (BufferMode != Unbuffered && OutBufStart ==
nullptr)
120 return preferred_buffer_size();
123 return OutBufEnd - OutBufStart;
131 SetBufferAndMode(
nullptr, 0, Unbuffered);
135 return OutBufCur - OutBufStart;
143 if (OutBufCur != OutBufStart)
148 if (OutBufCur >= OutBufEnd)
155 if (OutBufCur >= OutBufEnd)
162 if (OutBufCur >= OutBufEnd)
173 if (Size > (
size_t)(OutBufEnd - OutBufCur))
192 return write(Str.data(), Str.length());
196 return write(Str.data(), Str.size());
206 return this->operator<<(static_cast<unsigned long>(
N));
210 return this->operator<<(static_cast<long>(
N));
299 virtual void write_impl(
const char *Ptr,
size_t Size) = 0;
303 virtual uint64_t current_pos()
const = 0;
310 SetBufferAndMode(BufferStart, Size, ExternalBuffer);
314 virtual size_t preferred_buffer_size()
const;
325 void SetBufferAndMode(
char *BufferStart,
size_t Size, BufferKind
Mode);
329 void flush_nonempty();
333 void copy_to_buffer(
const char *Ptr,
size_t Size);
335 virtual void anchor();
342 virtual void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset) = 0;
343 void anchor()
override;
348 void pwrite(
const char *Ptr,
size_t Size, uint64_t Offset) {
350 uint64_t Pos = tell();
354 assert(Size + Offset <= Pos &&
"We don't support extending the stream");
356 pwrite_impl(Ptr, Size, Offset);
370 bool SupportsSeeking;
375 bool IsWindowsConsole =
false;
383 void write_impl(
const char *Ptr,
size_t Size)
override;
385 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
389 uint64_t current_pos()
const override {
return pos; }
392 size_t preferred_buffer_size()
const override;
395 void error_detected(std::error_code EC) { this->EC = EC; }
397 void anchor()
override;
434 uint64_t seek(uint64_t off);
437 bool bg=
false)
override;
442 bool is_displayed()
const override;
444 bool has_colors()
const override;
446 std::error_code
error()
const {
return EC; }
487 void write_impl(
const char *Ptr,
size_t Size)
override;
491 uint64_t current_pos()
const override {
return OS.size(); }
514 void write_impl(
const char *Ptr,
size_t Size)
override;
516 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
519 uint64_t current_pos()
const override;
532 void flush() =
delete;
541 void write_impl(
const char *Ptr,
size_t size)
override;
542 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
546 uint64_t current_pos()
const override;
557 virtual void anchor()
override;
566 #endif // LLVM_SUPPORT_RAW_OSTREAM_H
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
uint8_t[16] uuid_t
Output a formatted UUID with dash separators.
raw_string_ostream(std::string &O)
This class represents lattice values for constants.
buffer_ostream(raw_ostream &OS)
A raw_ostream that discards all output.
size_t GetBufferSize() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
virtual raw_ostream & changeColor(enum Colors Color, bool Bold=false, bool BG=false)
Changes the foreground color of text that will be output from this point forward. ...
A raw_ostream that writes to an SmallVector or SmallString.
raw_ostream & operator<<(const std::string &Str)
std::error_code error() const
raw_ostream & operator<<(const char *Str)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
raw_ostream & operator<<(int N)
void SetBuffer(char *BufferStart, size_t Size)
Use the provided buffer as the raw_ostream buffer.
raw_ostream & operator<<(char C)
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
void SetUnbuffered()
Set the stream to be unbuffered.
raw_ostream & operator<<(unsigned char C)
void pwrite(const char *Ptr, size_t Size, uint64_t Offset)
virtual raw_ostream & reverseColor()
Reverses the foreground and background colors.
const char * getBufferStart() const
Return the beginning of the current stream buffer, or 0 if the stream is unbuffered.
raw_ostream(bool unbuffered=false)
static void write(bool isBE, void *P, T V)
virtual bool has_colors() const
This function determines if this stream is displayed and supports colors.
void SetBufferSize(size_t Size)
Set the stream to be buffered, using the specified buffer size.
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
Color
A "color", which is either even or odd.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
virtual bool is_displayed() const
This function determines if this stream is connected to a "tty" or "console" window.
StringRef str()
Return a StringRef for the vector contents.
raw_ostream & operator<<(unsigned int N)
size_t GetNumBytesInBuffer() const
raw_pwrite_stream(bool Unbuffered=false)
void write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, Optional< size_t > Width=None)
A raw_ostream that writes to a file descriptor.
pointer data()
Return a pointer to the vector's buffer, even if empty().
raw_ostream & operator<<(StringRef Str)
~buffer_ostream() override
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
An abstract base class for streams implementations that also support a pwrite operation.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
virtual raw_ostream & resetColor()
Resets the colors to terminal defaults.
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
uint64_t tell() const
tell - Return the current offset with the file.
This class implements an extremely fast bulk output stream that can only output to a stream...
raw_svector_ostream(SmallVectorImpl< char > &O)
Construct a new raw_svector_ostream.
StringRef - Represent a constant reference to a string, i.e.
raw_ostream & operator<<(signed char C)
void clear_error()
Set the flag read by has_error() to false.