Go to the documentation of this file.
13 #ifndef LLVM_SUPPORT_RAW_OSTREAM_H
14 #define LLVM_SUPPORT_RAW_OSTREAM_H
25 #include <system_error>
26 #include <type_traits>
30 class formatv_object_base;
31 class format_object_base;
32 class FormattedString;
33 class FormattedNumber;
79 char *OutBufStart, *OutBufEnd, *OutBufCur;
80 bool ColorEnabled =
false;
86 enum class BufferKind {
120 : Kind(K), BufferMode(unbuffered ? BufferKind::Unbuffered
121 : BufferKind::InternalBuffer) {
123 OutBufStart = OutBufEnd = OutBufCur =
nullptr;
154 SetBufferAndMode(
new char[
Size],
Size, BufferKind::InternalBuffer);
160 if (BufferMode != BufferKind::Unbuffered && OutBufStart ==
nullptr)
164 return OutBufEnd - OutBufStart;
172 SetBufferAndMode(
nullptr, 0, BufferKind::Unbuffered);
176 return OutBufCur - OutBufStart;
184 if (OutBufCur != OutBufStart)
189 if (OutBufCur >= OutBufEnd)
196 if (OutBufCur >= OutBufEnd)
203 if (OutBufCur >= OutBufEnd)
214 if (
Size > (
size_t)(OutBufEnd - OutBufCur))
233 return write(Str.data(), Str.length());
237 return write(Str.data(), Str.size());
247 return this->operator<<(static_cast<unsigned long>(
N));
251 return this->operator<<(static_cast<long>(
N));
346 virtual void write_impl(
const char *Ptr,
size_t Size) = 0;
350 virtual uint64_t current_pos()
const = 0;
357 SetBufferAndMode(BufferStart,
Size, BufferKind::ExternalBuffer);
372 void SetBufferAndMode(
char *BufferStart,
size_t Size, BufferKind
Mode);
376 void flush_nonempty();
380 void copy_to_buffer(
const char *Ptr,
size_t Size);
384 bool prepare_colors();
387 void flush_tied_then_write(
const char *Ptr,
size_t Size);
389 virtual void anchor();
394 template <
typename OStream,
typename T>
395 std::enable_if_t<!std::is_reference<OStream>::value &&
396 std::is_base_of<raw_ostream, OStream>::value,
407 virtual void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset) = 0;
408 void anchor()
override;
416 uint64_t Pos =
tell();
435 bool SupportsSeeking =
false;
441 bool IsWindowsConsole =
false;
449 void write_impl(
const char *Ptr,
size_t Size)
override;
451 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
455 uint64_t current_pos()
const override {
return pos; }
458 size_t preferred_buffer_size()
const override;
460 void anchor()
override;
470 void inc_pos(uint64_t Delta) { pos += Delta; }
508 uint64_t
seek(uint64_t off);
514 std::error_code
error()
const {
return EC; }
568 raw_fd_ostream &
outs();
575 raw_fd_ostream &
errs();
578 raw_ostream &
nulls();
602 ssize_t
read(
char *Ptr,
size_t Size);
618 void write_impl(
const char *Ptr,
size_t Size)
override;
622 uint64_t current_pos()
const override {
return OS.size(); }
638 OS.reserve(
tell() + ExtraSize);
651 void write_impl(
const char *Ptr,
size_t Size)
override;
653 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
656 uint64_t current_pos()
const override;
669 void flush() =
delete;
682 void write_impl(
const char *Ptr,
size_t size)
override;
683 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t
Offset)
override;
687 uint64_t current_pos()
const override;
698 virtual void anchor()
override;
706 std::unique_ptr<raw_ostream> OS;
709 virtual void anchor()
override;
730 #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
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.
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.
bool has_colors() const override
This function determines if this stream is displayed and supports colors.
static constexpr Colors MAGENTA
LLVM_NODISCARD Expected< sys::fs::FileLocker > tryLockFor(std::chrono::milliseconds Timeout)
Tries to lock the underlying file within the specified period.
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.
~raw_string_ostream() override
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.
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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
LLVM_NODISCARD size_t size() const
size - Get the string size.
void reserve(size_type N)
std::string & str()
Flushes the stream contents to the target string and 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.