13 #ifndef LLVM_SUPPORT_RAW_OSTREAM_H 14 #define LLVM_SUPPORT_RAW_OSTREAM_H 23 #include <system_error> 24 #include <type_traits> 28 class formatv_object_base;
29 class format_object_base;
30 class FormattedString;
31 class FormattedNumber;
66 char *OutBufStart, *OutBufEnd, *OutBufCur;
68 enum class BufferKind {
89 static const Colors BLACK = Colors::BLACK;
90 static const Colors RED = Colors::RED;
91 static const Colors GREEN = Colors::GREEN;
92 static const Colors YELLOW = Colors::YELLOW;
93 static const Colors BLUE = Colors::BLUE;
94 static const Colors MAGENTA = Colors::MAGENTA;
95 static const Colors CYAN = Colors::CYAN;
96 static const Colors WHITE = Colors::WHITE;
97 static const Colors SAVEDCOLOR = Colors::SAVEDCOLOR;
98 static const Colors RESET = Colors::RESET;
101 : BufferMode(unbuffered ? BufferKind::Unbuffered
102 : BufferKind::InternalBuffer) {
104 OutBufStart = OutBufEnd = OutBufCur =
nullptr;
113 uint64_t
tell()
const {
return current_pos() + GetNumBytesInBuffer(); }
126 SetBufferAndMode(
new char[Size], Size, BufferKind::InternalBuffer);
132 if (BufferMode != BufferKind::Unbuffered && OutBufStart ==
nullptr)
133 return preferred_buffer_size();
136 return OutBufEnd - OutBufStart;
144 SetBufferAndMode(
nullptr, 0, BufferKind::Unbuffered);
148 return OutBufCur - OutBufStart;
156 if (OutBufCur != OutBufStart)
161 if (OutBufCur >= OutBufEnd)
168 if (OutBufCur >= OutBufEnd)
175 if (OutBufCur >= OutBufEnd)
186 if (Size > (
size_t)(OutBufEnd - OutBufCur))
190 memcpy(OutBufCur, Str.
data(),
Size);
205 return write(Str.data(), Str.length());
209 return write(Str.data(), Str.size());
219 return this->operator<<(static_cast<unsigned long>(
N));
223 return this->operator<<(static_cast<long>(
N));
319 virtual void write_impl(
const char *Ptr,
size_t Size) = 0;
323 virtual uint64_t current_pos()
const = 0;
330 SetBufferAndMode(BufferStart, Size, BufferKind::ExternalBuffer);
334 virtual size_t preferred_buffer_size()
const;
345 void SetBufferAndMode(
char *BufferStart,
size_t Size, BufferKind
Mode);
349 void flush_nonempty();
353 void copy_to_buffer(
const char *Ptr,
size_t Size);
355 virtual void anchor();
360 template <
typename OStream,
typename T>
361 typename std::enable_if<!std::is_reference<OStream>::value &&
362 std::is_base_of<raw_ostream, OStream>::value,
366 return std::move(OS);
373 virtual void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset) = 0;
374 void anchor()
override;
379 void pwrite(
const char *Ptr,
size_t Size, uint64_t Offset) {
381 uint64_t Pos = tell();
385 assert(Size + Offset <= Pos &&
"We don't support extending the stream");
387 pwrite_impl(Ptr, Size, Offset);
400 bool SupportsSeeking =
false;
401 bool ColorEnabled =
true;
406 bool IsWindowsConsole =
false;
414 void write_impl(
const char *Ptr,
size_t Size)
override;
416 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
420 uint64_t current_pos()
const override {
return pos; }
423 size_t preferred_buffer_size()
const override;
426 void error_detected(std::error_code EC) { this->EC = EC; }
428 void anchor()
override;
465 uint64_t seek(uint64_t off);
468 bool bg=
false)
override;
473 bool is_displayed()
const override;
475 bool has_colors()
const override;
479 std::error_code
error()
const {
return EC; }
520 void write_impl(
const char *Ptr,
size_t Size)
override;
524 uint64_t current_pos()
const override {
return OS.size(); }
547 void write_impl(
const char *Ptr,
size_t Size)
override;
549 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
552 uint64_t current_pos()
const override;
565 void flush() =
delete;
574 void write_impl(
const char *Ptr,
size_t size)
override;
575 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
579 uint64_t current_pos()
const override;
590 virtual void anchor()
override;
599 #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
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)
raw_ostream & operator<<(int N)
void SetBuffer(char *BufferStart, size_t Size)
Use the provided buffer as the raw_ostream buffer.
LLVM_NODISCARD 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.
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.
void enable_colors(bool enable) override
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.
virtual void enable_colors(bool)
std::pair< llvm::MachO::Target, std::string > UUID
StringRef str()
Return a StringRef for the vector contents.
raw_ostream & operator<<(unsigned int N)
size_t GetNumBytesInBuffer() const
raw_ostream & operator<<(raw_ostream &OS, const Memory::ProtectionFlags &PF)
Debugging output for Memory::ProtectionFlags.
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
An abstract base class for streams implementations that also support a pwrite operation.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
LLVM Value Representation.
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.