Files
allwpilib/upstream_utils/llvm_patches/0009-Remove-unused-functions.patch
2026-05-26 21:55:50 -07:00

829 lines
27 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Sun, 8 May 2022 13:43:50 -0400
Subject: [PATCH 09/34] Remove unused functions
---
llvm/include/llvm/ADT/SmallString.h | 77 ------
llvm/include/llvm/Support/Errno.h | 9 -
llvm/include/llvm/Support/VersionTuple.h | 39 ---
llvm/include/llvm/Support/raw_ostream.h | 187 +------------
llvm/lib/Support/raw_ostream.cpp | 332 -----------------------
5 files changed, 8 insertions(+), 636 deletions(-)
diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h
index 9fab1a7726bc6745296f5ebb24aee4055408e5f5..cb6136d8fd1886e8dc444cb807b33a5f1e18aa44 100644
--- a/llvm/include/llvm/ADT/SmallString.h
+++ b/llvm/include/llvm/ADT/SmallString.h
@@ -88,15 +88,6 @@ public:
/// @name String Comparison
/// @{
- /// Check for string equality. This is more efficient than compare() when
- /// the relative ordering of inequal strings isn't needed.
- [[nodiscard]] bool equals(std::string_view RHS) const { return str() == RHS; }
-
- /// Check for string equality, ignoring case.
- [[nodiscard]] bool equals_insensitive(std::string_view RHS) const {
- return str().equals_insensitive(RHS);
- }
-
/// compare - Compare two strings; the result is negative, zero, or positive
/// if this string is lexicographically less than, equal to, or greater than
/// the \p RHS.
@@ -104,31 +95,6 @@ public:
return str().compare(RHS);
}
- /// compare_insensitive - Compare two strings, ignoring case.
- [[nodiscard]] int compare_insensitive(std::string_view RHS) const {
- return str().compare_insensitive(RHS);
- }
-
- /// compare_numeric - Compare two strings, treating sequences of digits as
- /// numbers.
- [[nodiscard]] int compare_numeric(std::string_view RHS) const {
- return str().compare_numeric(RHS);
- }
-
- /// @}
- /// @name String Predicates
- /// @{
-
- /// startswith - Check if this string starts with the given \p Prefix.
- [[nodiscard]] bool startswith(std::string_view Prefix) const {
- return str().startswith(Prefix);
- }
-
- /// endswith - Check if this string ends with the given \p Suffix.
- [[nodiscard]] bool endswith(std::string_view Suffix) const {
- return str().endswith(Suffix);
- }
-
/// @}
/// @name String Searching
/// @{
@@ -213,49 +179,6 @@ public:
}
/// @}
- /// @name Helpful Algorithms
- /// @{
-
- /// Return the number of occurrences of \p C in the string.
- [[nodiscard]] size_t count(char C) const { return str().count(C); }
-
- /// Return the number of non-overlapped occurrences of \p Str in the
- /// string.
- [[nodiscard]] size_t count(std::string_view Str) const {
- return str().count(Str);
- }
-
- /// @}
- /// @name Substring Operations
- /// @{
-
- /// Return a reference to the substring from [Start, Start + N).
- ///
- /// \param Start The index of the starting character in the substring; if
- /// the index is npos or greater than the length of the string then the
- /// empty substring will be returned.
- ///
- /// \param N The number of characters to included in the substring. If \p N
- /// exceeds the number of characters remaining in the string, the string
- /// suffix (starting with \p Start) will be returned.
- [[nodiscard]] std::string_view substr(
- size_t Start, size_t N = std::string_view::npos) const {
- return str().substr(Start, N);
- }
-
- /// Return a reference to the substring from [Start, End).
- ///
- /// \param Start The index of the starting character in the substring; if
- /// the index is npos or greater than the length of the string then the
- /// empty substring will be returned.
- ///
- /// \param End The index following the last character to include in the
- /// substring. If this is npos, or less than \p Start, or exceeds the
- /// number of characters remaining in the string, the string suffix
- /// (starting with \p Start) will be returned.
- [[nodiscard]] std::string_view slice(size_t Start, size_t End) const {
- return str().slice(Start, End);
- }
// Extra methods.
diff --git a/llvm/include/llvm/Support/Errno.h b/llvm/include/llvm/Support/Errno.h
index 64817257141bbc03098624437731d31ce66f7ce8..409f39a0b2d658bd6cefc75c68cec3ccceda98c9 100644
--- a/llvm/include/llvm/Support/Errno.h
+++ b/llvm/include/llvm/Support/Errno.h
@@ -20,15 +20,6 @@
namespace llvm {
namespace sys {
-/// Returns a string representation of the errno value, using whatever
-/// thread-safe variant of strerror() is available. Be sure to call this
-/// immediately after the function that set errno, or errno may have been
-/// overwritten by an intervening call.
-LLVM_ABI std::string StrError();
-
-/// Like the no-argument version above, but uses \p errnum instead of errno.
-LLVM_ABI std::string StrError(int errnum);
-
template <typename FailT, typename Fun, typename... Args>
inline decltype(auto) RetryAfterSignal(const FailT &Fail, const Fun &F,
const Args &... As) {
diff --git a/llvm/include/llvm/Support/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h
index 32c3ad9a9fc2c9827dc4afd81c6f9d03ec1b25c2..735f73d0447fb35fc64a0f449b45bab19947bf58 100644
--- a/llvm/include/llvm/Support/VersionTuple.h
+++ b/llvm/include/llvm/Support/VersionTuple.h
@@ -165,45 +165,6 @@ public:
friend bool operator>=(const VersionTuple &X, const VersionTuple &Y) {
return !(X < Y);
}
-
- friend hash_code hash_value(const VersionTuple &VT) {
- return hash_combine(VT.Major, VT.Minor, VT.Subminor, VT.Build);
- }
-
- template <typename HasherT, llvm::endianness Endianness>
- friend void addHash(HashBuilder<HasherT, Endianness> &HBuilder,
- const VersionTuple &VT) {
- HBuilder.add(VT.Major, VT.Minor, VT.Subminor, VT.Build);
- }
-
- /// Retrieve a string representation of the version number.
- LLVM_ABI std::string getAsString() const;
-};
-
-/// Print a version number.
-LLVM_ABI raw_ostream &operator<<(raw_ostream &Out, const VersionTuple &V);
-
-// Provide DenseMapInfo for version tuples.
-template <> struct DenseMapInfo<VersionTuple> {
- static inline VersionTuple getEmptyKey() { return VersionTuple(0x7FFFFFFF); }
- static inline VersionTuple getTombstoneKey() {
- return VersionTuple(0x7FFFFFFE);
- }
- static unsigned getHashValue(const VersionTuple &Value) {
- unsigned Result = Value.getMajor();
- if (auto Minor = Value.getMinor())
- Result = detail::combineHashValue(Result, *Minor);
- if (auto Subminor = Value.getSubminor())
- Result = detail::combineHashValue(Result, *Subminor);
- if (auto Build = Value.getBuild())
- Result = detail::combineHashValue(Result, *Build);
-
- return Result;
- }
-
- static bool isEqual(const VersionTuple &LHS, const VersionTuple &RHS) {
- return LHS == RHS;
- }
};
} // end namespace llvm
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 856b9f9342f1ca9ee358af2bf4998f506a9d539a..f346d36ca7a36ab2d9bcddc205db0abf50c2a136 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -275,32 +275,6 @@ public:
return write(Str.data(), Str.size());
}
- raw_ostream &operator<<(unsigned long N);
- raw_ostream &operator<<(long N);
- raw_ostream &operator<<(unsigned long long N);
- raw_ostream &operator<<(long long N);
- raw_ostream &operator<<(const void *P);
-
- raw_ostream &operator<<(unsigned int N) {
- return this->operator<<(static_cast<unsigned long>(N));
- }
-
- raw_ostream &operator<<(int N) {
- return this->operator<<(static_cast<long>(N));
- }
-
- raw_ostream &operator<<(double N);
-
- /// Output \p N in hexadecimal, without any prefix or padding.
- raw_ostream &write_hex(unsigned long long N);
-
- // Change the foreground color of text.
- raw_ostream &operator<<(Colors C);
-
- /// Output a formatted UUID with dash separators.
- using uuid_t = uint8_t[16];
- raw_ostream &write_uuid(const uuid_t UUID);
-
/// Output \p Str, turning '\\', '\t', '\n', '"', and anything that doesn't
/// satisfy llvm::isPrint into an escape sequence.
raw_ostream &write_escaped(std::string_view Str, bool UseHexEscapes = false);
@@ -308,21 +282,6 @@ public:
raw_ostream &write(unsigned char C);
raw_ostream &write(const char *Ptr, size_t Size);
- // Formatted output, see the format() function in Support/Format.h.
- raw_ostream &operator<<(const format_object_base &Fmt);
-
- // Formatted output, see the leftJustify() function in Support/Format.h.
- raw_ostream &operator<<(const FormattedString &);
-
- // Formatted output, see the formatHex() function in Support/Format.h.
- raw_ostream &operator<<(const FormattedNumber &);
-
- // Formatted output, see the formatv() function in Support/FormatVariadic.h.
- raw_ostream &operator<<(const formatv_object_base &);
-
- // Formatted output, see the format_bytes() function in Support/Format.h.
- raw_ostream &operator<<(const FormattedBytes &);
-
/// indent - Insert 'NumSpaces' spaces.
raw_ostream &indent(unsigned NumSpaces);
@@ -337,14 +296,19 @@ public:
/// @param BG if true change the background, default: change foreground
/// @returns itself so it can be used within << invocations
virtual raw_ostream &changeColor(enum Colors Color, bool Bold = false,
- bool BG = false);
+ bool BG = false) {
+ (void)Color;
+ (void)Bold;
+ (void)BG;
+ return *this;
+ }
/// Resets the colors to terminal defaults. Call this when you are done
/// outputting colored text, or before program exit.
- virtual raw_ostream &resetColor();
+ virtual raw_ostream &resetColor() { return *this; }
/// Reverses the foreground and background colors.
- virtual raw_ostream &reverseColor();
+ virtual raw_ostream &reverseColor() { return *this; }
/// This function determines if this stream is connected to a "tty" or
/// "console" window. That is, the output would be displayed to the user
@@ -415,10 +379,6 @@ private:
/// unused bytes in the buffer.
void copy_to_buffer(const char *Ptr, size_t Size);
- /// Compute whether colors should be used and do the necessary work such as
- /// flushing. The result is affected by calls to enable_color().
- bool prepare_colors();
-
virtual void anchor();
};
@@ -467,7 +427,6 @@ class LLVM_ABI raw_fd_ostream : public raw_pwrite_stream {
bool ShouldClose;
bool SupportsSeeking = false;
bool IsRegularFile = false;
- mutable std::optional<bool> HasColors;
/// Optional stream this stream is tied to. If this stream is written to, the
/// tied-to stream will be flushed first.
@@ -547,10 +506,6 @@ public:
/// to the offset specified from the beginning of the file.
uint64_t seek(uint64_t off);
- bool is_displayed() const override;
-
- bool has_colors() const override;
-
/// Tie this stream to the specified stream. Replaces any existing tied-to
/// stream. Specifying a nullptr unties the stream. This is intended for to
/// tie errs() to outs(), so that outs() is flushed whenever something is
@@ -576,38 +531,6 @@ public:
/// - from The Zen of Python, by Tim Peters
///
void clear_error() { EC = std::error_code(); }
-
- /// Locks the underlying file.
- ///
- /// @returns RAII object that releases the lock upon leaving the scope, if the
- /// locking was successful. Otherwise returns corresponding
- /// error code.
- ///
- /// The function blocks the current thread until the lock become available or
- /// error occurs.
- ///
- /// Possible use of this function may be as follows:
- ///
- /// @code{.cpp}
- /// if (auto L = stream.lock()) {
- /// // ... do action that require file to be locked.
- /// } else {
- /// handleAllErrors(std::move(L.takeError()), [&](ErrorInfoBase &EIB) {
- /// // ... handle lock error.
- /// });
- /// }
- /// @endcode
- [[nodiscard]] Expected<sys::fs::FileLocker> lock();
-
- /// Tries to lock the underlying file within the specified period.
- ///
- /// @returns RAII object that releases the lock upon leaving the scope, if the
- /// locking was successful. Otherwise returns corresponding
- /// error code.
- ///
- /// It is used as @ref lock.
- [[nodiscard]] Expected<sys::fs::FileLocker>
- tryLockFor(Duration const &Timeout);
};
/// This returns a reference to a raw_fd_ostream for standard output. Use it
@@ -637,19 +560,6 @@ public:
/// immediately destroyed.
LLVM_ABI raw_fd_stream(std::string_view Filename, std::error_code &EC);
- LLVM_ABI raw_fd_stream(int fd, bool shouldClose);
-
- /// This reads the \p Size bytes into a buffer pointed by \p Ptr.
- ///
- /// \param Ptr The start of the buffer to hold data to be read.
- ///
- /// \param Size The number of bytes to be read.
- ///
- /// On success, the number of bytes read is returned, and the file position is
- /// advanced by this number. On error, -1 is returned, use error() to get the
- /// error code.
- LLVM_ABI ssize_t read(char *Ptr, size_t Size);
-
/// Check if \p OS is a pointer of type raw_fd_stream*.
LLVM_ABI static bool classof(const raw_ostream *OS);
};
@@ -774,87 +684,6 @@ public:
~buffer_unique_ostream() override { *OS << str(); }
};
-// Helper struct to add indentation to raw_ostream. Instead of
-// OS.indent(6) << "more stuff";
-// you can use
-// OS << indent(6) << "more stuff";
-// which has better ergonomics (and clang-formats better as well).
-//
-// If indentation is always in increments of a fixed value, you can use Scale
-// to set that value once. So indent(1, 2) will add 2 spaces and
-// indent(1,2) + 1 will add 4 spaces.
-struct indent {
- // Indentation is represented as `NumIndents` steps of size `Scale` each.
- unsigned NumIndents;
- unsigned Scale;
-
- explicit indent(unsigned NumIndents, unsigned Scale = 1)
- : NumIndents(NumIndents), Scale(Scale) {}
-
- // These arithmeric operators preserve scale.
- void operator+=(unsigned N) { NumIndents += N; }
- void operator-=(unsigned N) {
- assert(NumIndents >= N && "Indentation underflow");
- NumIndents -= N;
- }
- indent operator+(unsigned N) const { return indent(NumIndents + N, Scale); }
- indent operator-(unsigned N) const {
- assert(NumIndents >= N && "Indentation undeflow");
- return indent(NumIndents - N, Scale);
- }
- indent &operator++() { // Prefix ++.
- ++NumIndents;
- return *this;
- }
- indent operator++(int) { // Postfix ++.
- indent Old = *this;
- ++NumIndents;
- return Old;
- }
- indent &operator--() { // Prefix --.
- assert(NumIndents >= 1);
- --NumIndents;
- return *this;
- }
- indent operator--(int) { // Postfix --.
- indent Old = *this;
- assert(NumIndents >= 1);
- --NumIndents;
- return Old;
- }
- indent &operator=(unsigned N) {
- NumIndents = N;
- return *this;
- }
-};
-
-inline raw_ostream &operator<<(raw_ostream &OS, const indent &Indent) {
- return OS.indent(Indent.NumIndents * Indent.Scale);
-}
-
-class Error;
-
-/// This helper creates an output stream and then passes it to \p Write.
-/// The stream created is based on the specified \p OutputFileName:
-/// llvm::outs for "-", raw_null_ostream for "/dev/null", and raw_fd_ostream
-/// for other names. For raw_fd_ostream instances, the stream writes to
-/// a temporary file. The final output file is atomically replaced with the
-/// temporary file after the \p Write function is finished.
-LLVM_ABI Error writeToOutput(std::string_view OutputFileName,
- std::function<Error(raw_ostream &)> Write);
-
-LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, std::nullopt_t);
-
-template <typename T, typename = decltype(std::declval<raw_ostream &>()
- << std::declval<const T &>())>
-raw_ostream &operator<<(raw_ostream &OS, const std::optional<T> &O) {
- if (O)
- OS << *O;
- else
- OS << std::nullopt;
- return OS;
-}
-
} // end namespace llvm
#endif // LLVM_SUPPORT_RAW_OSTREAM_H
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 5496df7f6f83debb8b13bb9b828cdbddab91b07b..32f5d5fb78b1a9e4288b875c64ded0040d6fdce6 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -19,7 +19,6 @@
#include "llvm/Config/config.h"
#include "llvm/Support/AutoConvert.h"
#include "llvm/Support/Compiler.h"
-#include "llvm/Support/Duration.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
@@ -116,49 +115,6 @@ void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size,
assert(OutBufStart <= OutBufEnd && "Invalid size!");
}
-raw_ostream &raw_ostream::operator<<(unsigned long N) {
- write_integer(*this, static_cast<uint64_t>(N), 0, IntegerStyle::Integer);
- return *this;
-}
-
-raw_ostream &raw_ostream::operator<<(long N) {
- write_integer(*this, static_cast<int64_t>(N), 0, IntegerStyle::Integer);
- return *this;
-}
-
-raw_ostream &raw_ostream::operator<<(unsigned long long N) {
- write_integer(*this, static_cast<uint64_t>(N), 0, IntegerStyle::Integer);
- return *this;
-}
-
-raw_ostream &raw_ostream::operator<<(long long N) {
- write_integer(*this, static_cast<int64_t>(N), 0, IntegerStyle::Integer);
- return *this;
-}
-
-raw_ostream &raw_ostream::write_hex(unsigned long long N) {
- llvm::write_hex(*this, N, HexPrintStyle::Lower);
- return *this;
-}
-
-raw_ostream &raw_ostream::operator<<(Colors C) {
- if (C == Colors::RESET)
- resetColor();
- else
- changeColor(C);
- return *this;
-}
-
-raw_ostream &raw_ostream::write_uuid(const uuid_t UUID) {
- for (int Idx = 0; Idx < 16; ++Idx) {
- *this << format("%02" PRIX32, UUID[Idx]);
- if (Idx == 3 || Idx == 5 || Idx == 7 || Idx == 9)
- *this << "-";
- }
- return *this;
-}
-
-
raw_ostream &raw_ostream::write_escaped(std::string_view Str,
bool UseHexEscapes) {
for (unsigned char c : Str) {
@@ -298,173 +254,6 @@ void raw_ostream::copy_to_buffer(const char *Ptr, size_t Size) {
OutBufCur += Size;
}
-// Formatted output.
-raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) {
- // If we have more than a few bytes left in our output buffer, try
- // formatting directly onto its end.
- size_t NextBufferSize = 127;
- size_t BufferBytesLeft = OutBufEnd - OutBufCur;
- if (BufferBytesLeft > 3) {
- size_t BytesUsed = Fmt.print(OutBufCur, BufferBytesLeft);
-
- // Common case is that we have plenty of space.
- if (BytesUsed <= BufferBytesLeft) {
- OutBufCur += BytesUsed;
- return *this;
- }
-
- // Otherwise, we overflowed and the return value tells us the size to try
- // again with.
- NextBufferSize = BytesUsed;
- }
-
- // If we got here, we didn't have enough space in the output buffer for the
- // string. Try printing into a SmallVector that is resized to have enough
- // space. Iterate until we win.
- SmallVector<char, 128> V;
-
- while (true) {
- V.resize(NextBufferSize);
-
- // Try formatting into the SmallVector.
- size_t BytesUsed = Fmt.print(V.data(), NextBufferSize);
-
- // If BytesUsed fit into the vector, we win.
- if (BytesUsed <= NextBufferSize)
- return write(V.data(), BytesUsed);
-
- // Otherwise, try again with a new size.
- assert(BytesUsed > NextBufferSize && "Didn't grow buffer!?");
- NextBufferSize = BytesUsed;
- }
-}
-
-raw_ostream &raw_ostream::operator<<(const formatv_object_base &Obj) {
- Obj.format(*this);
- return *this;
-}
-
-raw_ostream &raw_ostream::operator<<(const FormattedString &FS) {
- unsigned LeftIndent = 0;
- unsigned RightIndent = 0;
- const ssize_t Difference = FS.Width - FS.Str.size();
- if (Difference > 0) {
- switch (FS.Justify) {
- case FormattedString::JustifyNone:
- break;
- case FormattedString::JustifyLeft:
- RightIndent = Difference;
- break;
- case FormattedString::JustifyRight:
- LeftIndent = Difference;
- break;
- case FormattedString::JustifyCenter:
- LeftIndent = Difference / 2;
- RightIndent = Difference - LeftIndent;
- break;
- }
- }
- indent(LeftIndent);
- (*this) << FS.Str;
- indent(RightIndent);
- return *this;
-}
-
-raw_ostream &raw_ostream::operator<<(const FormattedNumber &FN) {
- if (FN.Hex) {
- HexPrintStyle Style;
- if (FN.Upper && FN.HexPrefix)
- Style = HexPrintStyle::PrefixUpper;
- else if (FN.Upper && !FN.HexPrefix)
- Style = HexPrintStyle::Upper;
- else if (!FN.Upper && FN.HexPrefix)
- Style = HexPrintStyle::PrefixLower;
- else
- Style = HexPrintStyle::Lower;
- llvm::write_hex(*this, FN.HexValue, Style, FN.Width);
- } else {
- llvm::SmallString<16> Buffer;
- llvm::raw_svector_ostream Stream(Buffer);
- llvm::write_integer(Stream, FN.DecValue, 0, IntegerStyle::Integer);
- if (Buffer.size() < FN.Width)
- indent(FN.Width - Buffer.size());
- (*this) << Buffer;
- }
- return *this;
-}
-
-raw_ostream &raw_ostream::operator<<(const FormattedBytes &FB) {
- if (FB.Bytes.empty())
- return *this;
-
- size_t LineIndex = 0;
- auto Bytes = FB.Bytes;
- const size_t Size = Bytes.size();
- HexPrintStyle HPS = FB.Upper ? HexPrintStyle::Upper : HexPrintStyle::Lower;
- uint64_t OffsetWidth = 0;
- if (FB.FirstByteOffset) {
- // Figure out how many nibbles are needed to print the largest offset
- // represented by this data set, so that we can align the offset field
- // to the right width.
- size_t Lines = Size / FB.NumPerLine;
- uint64_t MaxOffset = *FB.FirstByteOffset + Lines * FB.NumPerLine;
- unsigned Power = 0;
- if (MaxOffset > 0)
- Power = llvm::Log2_64_Ceil(MaxOffset);
- OffsetWidth = std::max<uint64_t>(4, llvm::alignTo(Power, 4) / 4);
- }
-
- // The width of a block of data including all spaces for group separators.
- unsigned NumByteGroups =
- alignTo(FB.NumPerLine, FB.ByteGroupSize) / FB.ByteGroupSize;
- unsigned BlockCharWidth = FB.NumPerLine * 2 + NumByteGroups - 1;
-
- while (!Bytes.empty()) {
- indent(FB.IndentLevel);
-
- if (FB.FirstByteOffset) {
- uint64_t Offset = *FB.FirstByteOffset;
- llvm::write_hex(*this, Offset + LineIndex, HPS, OffsetWidth);
- *this << ": ";
- }
-
- auto Line = Bytes.take_front(FB.NumPerLine);
-
- size_t CharsPrinted = 0;
- // Print the hex bytes for this line in groups
- for (size_t I = 0; I < Line.size(); ++I, CharsPrinted += 2) {
- if (I && (I % FB.ByteGroupSize) == 0) {
- ++CharsPrinted;
- *this << " ";
- }
- llvm::write_hex(*this, Line[I], HPS, 2);
- }
-
- if (FB.ASCII) {
- // Print any spaces needed for any bytes that we didn't print on this
- // line so that the ASCII bytes are correctly aligned.
- assert(BlockCharWidth >= CharsPrinted);
- indent(BlockCharWidth - CharsPrinted + 2);
- *this << "|";
-
- // Print the ASCII char values for each byte on this line
- for (uint8_t Byte : Line) {
- if (isPrint(Byte))
- *this << static_cast<char>(Byte);
- else
- *this << '.';
- }
- *this << '|';
- }
-
- Bytes = Bytes.drop_front(Line.size());
- LineIndex += Line.size();
- if (LineIndex < Size)
- *this << '\n';
- }
- return *this;
-}
-
template <char C>
static raw_ostream &write_padding(raw_ostream &OS, unsigned NumChars) {
static const char Chars[] = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C,
@@ -495,63 +284,8 @@ raw_ostream &raw_ostream::write_zeros(unsigned NumZeros) {
return write_padding<'\0'>(*this, NumZeros);
}
-bool raw_ostream::prepare_colors() {
- // Colors were explicitly disabled.
- if (!ColorEnabled)
- return false;
-
- // Colors require changing the terminal but this stream is not going to a
- // terminal.
- if (sys::Process::ColorNeedsFlush() && !is_displayed())
- return false;
-
- if (sys::Process::ColorNeedsFlush())
- flush();
-
- return true;
-}
-
-raw_ostream &raw_ostream::changeColor(enum Colors colors, bool bold, bool bg) {
- if (!prepare_colors())
- return *this;
-
- const char *colorcode =
- (colors == SAVEDCOLOR)
- ? sys::Process::OutputBold(bg)
- : sys::Process::OutputColor(static_cast<char>(colors), bold, bg);
- if (colorcode)
- write(colorcode, strlen(colorcode));
- return *this;
-}
-
-raw_ostream &raw_ostream::resetColor() {
- if (!prepare_colors())
- return *this;
-
- if (const char *colorcode = sys::Process::ResetColor())
- write(colorcode, strlen(colorcode));
- return *this;
-}
-
-raw_ostream &raw_ostream::reverseColor() {
- if (!prepare_colors())
- return *this;
-
- if (const char *colorcode = sys::Process::OutputReverse())
- write(colorcode, strlen(colorcode));
- return *this;
-}
-
void raw_ostream::anchor() {}
-//===----------------------------------------------------------------------===//
-// Formatted Output
-//===----------------------------------------------------------------------===//
-
-// Out of line virtual method.
-void format_object_base::home() {
-}
-
//===----------------------------------------------------------------------===//
// raw_fd_ostream
//===----------------------------------------------------------------------===//
@@ -859,31 +593,6 @@ size_t raw_fd_ostream::preferred_buffer_size() const {
#endif
}
-bool raw_fd_ostream::is_displayed() const {
- return sys::Process::FileDescriptorIsDisplayed(FD);
-}
-
-bool raw_fd_ostream::has_colors() const {
- if (!HasColors)
- HasColors = sys::Process::FileDescriptorHasColors(FD);
- return *HasColors;
-}
-
-Expected<sys::fs::FileLocker> raw_fd_ostream::lock() {
- std::error_code EC = sys::fs::lockFile(FD);
- if (!EC)
- return sys::fs::FileLocker(FD);
- return errorCodeToError(EC);
-}
-
-Expected<sys::fs::FileLocker>
-raw_fd_ostream::tryLockFor(Duration const& Timeout) {
- std::error_code EC = sys::fs::tryLockFile(FD, Timeout.getDuration());
- if (!EC)
- return sys::fs::FileLocker(FD);
- return errorCodeToError(EC);
-}
-
void raw_fd_ostream::anchor() {}
//===----------------------------------------------------------------------===//
@@ -937,19 +646,6 @@ raw_fd_stream::raw_fd_stream(std::string_view Filename, std::error_code &EC)
EC = std::make_error_code(std::errc::invalid_argument);
}
-raw_fd_stream::raw_fd_stream(int fd, bool shouldClose)
- : raw_fd_ostream(fd, shouldClose, false, OStreamKind::OK_FDStream) {}
-
-ssize_t raw_fd_stream::read(char *Ptr, size_t Size) {
- assert(get_fd() >= 0 && "File already closed.");
- ssize_t Ret = ::read(get_fd(), (void *)Ptr, Size);
- if (Ret >= 0)
- inc_pos(Ret);
- else
- error_detected(errnoAsErrorCode());
- return Ret;
-}
-
bool raw_fd_stream::classof(const raw_ostream *OS) {
return OS->get_kind() == OStreamKind::OK_FDStream;
}
@@ -1009,31 +705,3 @@ void raw_pwrite_stream::anchor() {}
void buffer_ostream::anchor() {}
void buffer_unique_ostream::anchor() {}
-
-Error llvm::writeToOutput(std::string_view OutputFileName,
- std::function<Error(raw_ostream &)> Write) {
- if (OutputFileName == "-")
- return Write(outs());
-
- if (OutputFileName == "/dev/null") {
- raw_null_ostream Out;
- return Write(Out);
- }
-
- unsigned Mode = sys::fs::all_read | sys::fs::all_write;
- Expected<sys::fs::TempFile> Temp =
- sys::fs::TempFile::create(OutputFileName + ".temp-stream-%%%%%%", Mode);
- if (!Temp)
- return createFileError(OutputFileName, Temp.takeError());
-
- raw_fd_ostream Out(Temp->FD, false);
-
- if (Error E = Write(Out)) {
- if (Error DiscardError = Temp->discard())
- return joinErrors(std::move(E), std::move(DiscardError));
- return E;
- }
- Out.flush();
-
- return Temp->keep(OutputFileName);
-}