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;
64 char *OutBufStart, *OutBufEnd, *OutBufCur;
87 : BufferMode(unbuffered ? Unbuffered : InternalBuffer) {
89 OutBufStart = OutBufEnd = OutBufCur =
nullptr;
111 SetBufferAndMode(
new char[Size], Size, InternalBuffer);
117 if (BufferMode != Unbuffered && OutBufStart ==
nullptr)
121 return OutBufEnd - OutBufStart;
129 SetBufferAndMode(
nullptr, 0, Unbuffered);
133 return OutBufCur - OutBufStart;
141 if (OutBufCur != OutBufStart)
146 if (OutBufCur >= OutBufEnd)
153 if (OutBufCur >= OutBufEnd)
160 if (OutBufCur >= OutBufEnd)
168 size_t Size = Str.
size();
171 if (Size > (
size_t)(OutBufEnd - OutBufCur))
175 memcpy(OutBufCur, Str.
data(), Size);
190 return write(Str.data(), Str.length());
194 return write(Str.data(), Str.size());
204 return this->operator<<(static_cast<unsigned long>(
N));
208 return this->operator<<(static_cast<long>(
N));
290 virtual void write_impl(
const char *
Ptr,
size_t Size) = 0;
293 virtual void handle();
297 virtual uint64_t current_pos()
const = 0;
304 SetBufferAndMode(BufferStart, Size, ExternalBuffer);
319 void SetBufferAndMode(
char *BufferStart,
size_t Size, BufferKind
Mode);
323 void flush_nonempty();
327 void copy_to_buffer(
const char *
Ptr,
size_t Size);
334 virtual void pwrite_impl(
const char *
Ptr,
size_t Size, uint64_t
Offset) = 0;
339 void pwrite(
const char *Ptr,
size_t Size, uint64_t Offset) {
341 uint64_t Pos =
tell();
345 assert(Size + Offset <= Pos &&
"We don't support extending the stream");
347 pwrite_impl(Ptr, Size, Offset);
367 bool SupportsSeeking;
370 void write_impl(
const char *
Ptr,
size_t Size)
override;
372 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
376 uint64_t current_pos()
const override {
return pos; }
379 size_t preferred_buffer_size()
const override;
382 void error_detected() {
Error =
true; }
412 uint64_t
seek(uint64_t off);
415 bool bg=
false)
override;
455 raw_ostream &
nulls();
467 void write_impl(
const char *
Ptr,
size_t Size)
override;
471 uint64_t current_pos()
const override {
return OS.size(); }
494 void write_impl(
const char *
Ptr,
size_t Size)
override;
496 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
499 uint64_t current_pos()
const override;
512 void flush() =
delete;
521 void write_impl(
const char *
Ptr,
size_t size)
override;
522 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
526 uint64_t current_pos()
const override;
544 #endif // LLVM_SUPPORT_RAW_OSTREAM_H
~raw_svector_ostream() override=default
bool has_colors() const override
This function determines if this stream is displayed and supports colors.
bool is_displayed() const override
This function determines if this stream is connected to a "tty" or "console" window.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
const char * getBufferStart() const
Return the beginning of the current stream buffer, or 0 if the stream is unbuffered.
raw_string_ostream(std::string &O)
buffer_ostream(raw_ostream &OS)
A raw_ostream that discards all output.
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
virtual bool has_colors() const
This function determines if this stream is displayed and supports colors.
~raw_string_ostream() override
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. ...
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an SmallVector or SmallString.
raw_ostream & operator<<(const std::string &Str)
raw_ostream & operator<<(const char *Str)
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
struct fuzzer::@269 Flags
raw_ostream & operator<<(int N)
void SetBuffer(char *BufferStart, size_t Size)
Use the provided buffer as the raw_ostream buffer.
uint64_t tell() const
tell - Return the current offset with the file.
raw_null_ostream()=default
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
~raw_fd_ostream() override
virtual bool is_displayed() const
This function determines if this stream is connected to a "tty" or "console" window.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
raw_ostream & operator<<(char C)
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
raw_ostream & resetColor() override
Resets the colors to terminal defaults.
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.
raw_fd_ostream(StringRef Filename, std::error_code &EC, sys::fs::OpenFlags Flags)
Open the specified file for writing.
raw_ostream(bool unbuffered=false)
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.
~raw_null_ostream() override
raw_ostream & write(unsigned char C)
size_t GetBufferSize() const
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '', ' ', '"', and anything that doesn't satisfy std::isprint into an escape...
Color
A "color", which is either even or odd.
StringRef str()
Return a StringRef for the vector contents.
virtual size_t preferred_buffer_size() const
Return an efficient buffer size for the underlying output mechanism.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
raw_ostream & operator<<(unsigned int N)
void SetBuffered()
Set the stream to be buffered, with an automatically determined buffer size.
raw_pwrite_stream(bool Unbuffered=false)
A raw_ostream that writes to a file descriptor.
pointer data()
Return a pointer to the vector's buffer, even if empty().
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
raw_ostream & operator<<(StringRef Str)
~buffer_ostream() override
void close()
Manually flush the stream and close the file.
An abstract base class for streams implementations that also support a pwrite operation.
void operator=(const raw_ostream &)=delete
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.
Lightweight error class with error context and mandatory checking.
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
raw_ostream & changeColor(enum Colors colors, bool bold=false, bool bg=false) override
Changes the foreground color of text that will be output from this point forward. ...
This class implements an extremely fast bulk output stream that can only output to a stream...
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_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)
raw_ostream & reverseColor() override
Reverses the foreground and background colors.
size_t GetNumBytesInBuffer() const
void clear_error()
Set the flag read by has_error() to false.