Go to the documentation of this file.
13 #ifndef LLVM_SUPPORT_RAW_OSTREAM_H
14 #define LLVM_SUPPORT_RAW_OSTREAM_H
25 #if __cplusplus > 201402L
26 #include <string_view>
28 #include <system_error>
29 #include <type_traits>
34 class formatv_object_base;
35 class format_object_base;
36 class FormattedString;
37 class FormattedNumber;
83 char *OutBufStart, *OutBufEnd, *OutBufCur;
84 bool ColorEnabled =
false;
90 enum class BufferKind {
124 : Kind(K), BufferMode(unbuffered ? BufferKind::Unbuffered
125 : BufferKind::InternalBuffer) {
127 OutBufStart = OutBufEnd = OutBufCur =
nullptr;
158 SetBufferAndMode(
new char[Size], Size, BufferKind::InternalBuffer);
164 if (BufferMode != BufferKind::Unbuffered && OutBufStart ==
nullptr)
168 return OutBufEnd - OutBufStart;
176 SetBufferAndMode(
nullptr, 0, BufferKind::Unbuffered);
180 return OutBufCur - OutBufStart;
188 if (OutBufCur != OutBufStart)
193 if (OutBufCur >= OutBufEnd)
200 if (OutBufCur >= OutBufEnd)
207 if (OutBufCur >= OutBufEnd)
215 size_t Size = Str.size();
218 if (Size > (
size_t)(OutBufEnd - OutBufCur))
219 return write(Str.data(), Size);
222 memcpy(OutBufCur, Str.data(), Size);
237 return write(Str.data(), Str.length());
240 #if __cplusplus > 201402L
242 return write(Str.data(), Str.length());
247 return write(Str.data(), Str.size());
257 return this->operator<<(static_cast<unsigned long>(
N));
261 return this->operator<<(static_cast<long>(
N));
358 virtual void write_impl(
const char *Ptr,
size_t Size) = 0;
362 virtual uint64_t current_pos()
const = 0;
369 SetBufferAndMode(BufferStart, Size, BufferKind::ExternalBuffer);
384 void SetBufferAndMode(
char *BufferStart,
size_t Size, BufferKind
Mode);
388 void flush_nonempty();
392 void copy_to_buffer(
const char *Ptr,
size_t Size);
396 bool prepare_colors();
399 void flush_tied_then_write(
const char *Ptr,
size_t Size);
401 virtual void anchor();
406 template <
typename OStream,
typename T>
407 std::enable_if_t<!std::is_reference<OStream>::value &&
408 std::is_base_of<raw_ostream, OStream>::value,
419 virtual void pwrite_impl(
const char *Ptr,
size_t Size,
uint64_t Offset) = 0;
420 void anchor()
override;
432 assert(Size + Offset <= Pos &&
"We don't support extending the stream");
434 pwrite_impl(Ptr, Size, Offset);
447 bool SupportsSeeking =
false;
448 bool IsRegularFile =
false;
454 bool IsWindowsConsole =
false;
462 void write_impl(
const char *Ptr,
size_t Size)
override;
464 void pwrite_impl(
const char *Ptr,
size_t Size,
uint64_t Offset)
override;
468 uint64_t current_pos()
const override {
return pos; }
471 size_t preferred_buffer_size()
const override;
473 void anchor()
override;
529 std::error_code
error()
const {
return EC; }
583 raw_fd_ostream &
outs();
590 raw_fd_ostream &
errs();
593 raw_ostream &
nulls();
617 ssize_t
read(
char *Ptr,
size_t Size);
636 void write_impl(
const char *Ptr,
size_t Size)
override;
640 uint64_t current_pos()
const override {
return OS.size(); }
650 std::string &
str() {
return OS; }
653 OS.reserve(
tell() + ExtraSize);
666 void write_impl(
const char *Ptr,
size_t Size)
override;
668 void pwrite_impl(
const char *Ptr,
size_t Size,
uint64_t Offset)
override;
671 uint64_t current_pos()
const override;
684 void flush() =
delete;
697 void write_impl(
const char *Ptr,
size_t size)
override;
698 void pwrite_impl(
const char *Ptr,
size_t Size,
uint64_t Offset)
override;
702 uint64_t current_pos()
const override;
713 virtual void anchor()
override;
721 std::unique_ptr<raw_ostream> OS;
724 virtual void anchor()
override;
749 #endif // LLVM_SUPPORT_RAW_OSTREAM_H
uint64_t tell() const
tell - Return the current offset with the file.
~buffer_unique_ostream() override
bool supportsSeeking() const
This is an optimization pass for GlobalISel generic memory operations.
virtual void reserveExtraSpace(uint64_t ExtraSize)
If possible, pre-allocate ExtraSize bytes for stream data.
void close()
Manually flush the stream and close the file.
void reserveExtraSpace(uint64_t ExtraSize) override
If possible, pre-allocate ExtraSize bytes for stream data.
buffer_ostream(raw_ostream &OS)
void SetBuffered()
Set the stream to be buffered, with an automatically determined buffer size.
void operator=(const raw_ostream &)=delete
void SetUnbuffered()
Set the stream to be unbuffered.
OStreamKind get_kind() const
raw_ostream(bool unbuffered=false, OStreamKind K=OStreamKind::OK_OStream)
virtual bool is_displayed() const
This function determines if this stream is connected to a "tty" or "console" window.
bool colors_enabled() const
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
A raw_ostream that writes to an std::string.
buffer_unique_ostream(std::unique_ptr< raw_ostream > OS)
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
void SetBuffer(char *BufferStart, size_t Size)
Use the provided buffer as the raw_ostream buffer.
raw_fd_ostream(StringRef Filename, std::error_code &EC)
Open the specified file for writing.
static constexpr Colors GREEN
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static constexpr Colors RED
Tagged union holding either a T or a Error.
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
LLVM_NODISCARD Expected< sys::fs::FileLocker > tryLockFor(Duration const &Timeout)
Tries to lock the underlying file within the specified period.
bool has_colors() const override
This function determines if this stream is displayed and supports colors.
static constexpr Colors MAGENTA
static bool classof(const raw_ostream *OS)
Check if OS is a pointer of type raw_fd_stream*.
raw_ostream & operator<<(StringRef Str)
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.
virtual size_t preferred_buffer_size() const
Return an efficient buffer size for the underlying output mechanism.
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
void inc_pos(uint64_t Delta)
int get_fd() const
Return the file descriptor.
Error writeToOutput(StringRef OutputFileName, std::function< Error(raw_ostream &)> Write)
This helper creates an output stream and then passes it to Write.
(vector float) vec_cmpeq(*A, *B) C
void clear_error()
Set the flag read by has_error() to false.
raw_ostream & operator<<(unsigned int N)
~raw_null_ostream() override
raw_ostream & write(unsigned char C)
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
size_t GetNumBytesInBuffer() const
void error_detected(std::error_code EC)
Set the flag indicating that an output error has been encountered.
static constexpr Colors WHITE
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
raw_string_ostream(std::string &O)
virtual void enable_colors(bool enable)
An abstract base class for streams implementations that also support a pwrite operation.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
raw_ostream & operator<<(const SmallVectorImpl< char > &Str)
void tie(raw_ostream *TieTo)
Tie this stream to the specified stream.
raw_ostream & operator<<(int N)
ssize_t read(char *Ptr, size_t Size)
This reads the Size bytes into a buffer pointed by Ptr.
raw_null_ostream()=default
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
print Print MemDeps of function
std::pair< llvm::MachO::Target, std::string > UUID
raw_ostream & operator<<(const char *Str)
static constexpr Colors CYAN
A raw_ostream that discards all output.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
virtual raw_ostream & reverseColor()
Reverses the foreground and background colors.
size_t GetBufferSize() const
std::error_code error() const
StringRef - Represent a constant reference to a string, i.e.
raw_ostream & operator<<(signed char C)
StringRef str() const
Return a StringRef for the vector contents.
bool is_displayed() const override
This function determines if this stream is connected to a "tty" or "console" window.
A raw_ostream that writes to a file descriptor.
raw_ostream & operator<<(char C)
virtual bool has_colors() const
This function determines if this stream is displayed and supports colors.
static constexpr Colors RESET
void pwrite(const char *Ptr, size_t Size, uint64_t Offset)
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
~raw_svector_ostream() override=default
static constexpr Colors SAVEDCOLOR
~raw_fd_ostream() override
raw_ostream & operator<<(const std::string &Str)
raw_pwrite_stream(bool Unbuffered=false, OStreamKind K=OStreamKind::OK_OStream)
LLVM_NODISCARD Expected< sys::fs::FileLocker > lock()
Locks the underlying file.
raw_fd_stream(StringRef Filename, std::error_code &EC)
Open the specified file for reading/writing/seeking.
void SetBufferSize(size_t Size)
Set the stream to be buffered, using the specified buffer size.
void reserveExtraSpace(uint64_t ExtraSize) override
If possible, pre-allocate ExtraSize bytes for stream data.
A raw_ostream of a file for reading/writing/seeking.
~buffer_ostream() override
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
static constexpr Colors BLACK
A raw_ostream that writes to an SmallVector or SmallString.
virtual raw_ostream & resetColor()
Resets the colors to terminal defaults.
static constexpr Colors BLUE
uint8_t[16] uuid_t
Output a formatted UUID with dash separators.
const char * getBufferStart() const
Return the beginning of the current stream buffer, or 0 if the stream is unbuffered.
static constexpr Colors YELLOW
void reserve(size_type N)
bool isRegularFile() const
std::string & str()
Returns the string's reference.
LLVM Value Representation.
raw_ostream & write_uuid(const uuid_t UUID)
raw_ostream & operator<<(unsigned char C)
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
raw_svector_ostream(SmallVectorImpl< char > &O)
Construct a new raw_svector_ostream.