James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 1 | From df2dc9fdb3d57e01423104a71a6a1d1d6382644a Mon Sep 17 00:00:00 2001 |
| 2 | From: PJ Reiniger <pj.reiniger@gmail.com> |
| 3 | Date: Sun, 8 May 2022 13:43:50 -0400 |
| 4 | Subject: [PATCH 10/28] Remove unused functions |
| 5 | |
| 6 | --- |
| 7 | llvm/include/llvm/ADT/SmallString.h | 80 ------ |
| 8 | llvm/include/llvm/Support/Errno.h | 9 - |
| 9 | llvm/include/llvm/Support/VersionTuple.h | 40 --- |
| 10 | llvm/include/llvm/Support/raw_ostream.h | 115 +------- |
| 11 | llvm/lib/Support/raw_ostream.cpp | 328 ----------------------- |
| 12 | 5 files changed, 8 insertions(+), 564 deletions(-) |
| 13 | |
| 14 | diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h |
| 15 | index 50cbdade4..bfa965fd6 100644 |
| 16 | --- a/llvm/include/llvm/ADT/SmallString.h |
| 17 | +++ b/llvm/include/llvm/ADT/SmallString.h |
| 18 | @@ -88,48 +88,12 @@ public: |
| 19 | /// @name String Comparison |
| 20 | /// @{ |
| 21 | |
| 22 | - /// Check for string equality. This is more efficient than compare() when |
| 23 | - /// the relative ordering of inequal strings isn't needed. |
| 24 | - bool equals(std::string_view RHS) const { |
| 25 | - return str().equals(RHS); |
| 26 | - } |
| 27 | - |
| 28 | - /// Check for string equality, ignoring case. |
| 29 | - bool equals_insensitive(std::string_view RHS) const { |
| 30 | - return str().equals_insensitive(RHS); |
| 31 | - } |
| 32 | - |
| 33 | /// Compare two strings; the result is -1, 0, or 1 if this string is |
| 34 | /// lexicographically less than, equal to, or greater than the \p RHS. |
| 35 | int compare(std::string_view RHS) const { |
| 36 | return str().compare(RHS); |
| 37 | } |
| 38 | |
| 39 | - /// compare_insensitive - Compare two strings, ignoring case. |
| 40 | - int compare_insensitive(std::string_view RHS) const { |
| 41 | - return str().compare_insensitive(RHS); |
| 42 | - } |
| 43 | - |
| 44 | - /// compare_numeric - Compare two strings, treating sequences of digits as |
| 45 | - /// numbers. |
| 46 | - int compare_numeric(std::string_view RHS) const { |
| 47 | - return str().compare_numeric(RHS); |
| 48 | - } |
| 49 | - |
| 50 | - /// @} |
| 51 | - /// @name String Predicates |
| 52 | - /// @{ |
| 53 | - |
| 54 | - /// startswith - Check if this string starts with the given \p Prefix. |
| 55 | - bool startswith(std::string_view Prefix) const { |
| 56 | - return str().startswith(Prefix); |
| 57 | - } |
| 58 | - |
| 59 | - /// endswith - Check if this string ends with the given \p Suffix. |
| 60 | - bool endswith(std::string_view Suffix) const { |
| 61 | - return str().endswith(Suffix); |
| 62 | - } |
| 63 | - |
| 64 | /// @} |
| 65 | /// @name String Searching |
| 66 | /// @{ |
| 67 | @@ -210,50 +174,6 @@ public: |
| 68 | } |
| 69 | |
| 70 | /// @} |
| 71 | - /// @name Helpful Algorithms |
| 72 | - /// @{ |
| 73 | - |
| 74 | - /// Return the number of occurrences of \p C in the string. |
| 75 | - size_t count(char C) const { |
| 76 | - return str().count(C); |
| 77 | - } |
| 78 | - |
| 79 | - /// Return the number of non-overlapped occurrences of \p Str in the |
| 80 | - /// string. |
| 81 | - size_t count(std::string_view Str) const { |
| 82 | - return str().count(Str); |
| 83 | - } |
| 84 | - |
| 85 | - /// @} |
| 86 | - /// @name Substring Operations |
| 87 | - /// @{ |
| 88 | - |
| 89 | - /// Return a reference to the substring from [Start, Start + N). |
| 90 | - /// |
| 91 | - /// \param Start The index of the starting character in the substring; if |
| 92 | - /// the index is npos or greater than the length of the string then the |
| 93 | - /// empty substring will be returned. |
| 94 | - /// |
| 95 | - /// \param N The number of characters to included in the substring. If \p N |
| 96 | - /// exceeds the number of characters remaining in the string, the string |
| 97 | - /// suffix (starting with \p Start) will be returned. |
| 98 | - std::string_view substr(size_t Start, size_t N = std::string_view::npos) const { |
| 99 | - return str().substr(Start, N); |
| 100 | - } |
| 101 | - |
| 102 | - /// Return a reference to the substring from [Start, End). |
| 103 | - /// |
| 104 | - /// \param Start The index of the starting character in the substring; if |
| 105 | - /// the index is npos or greater than the length of the string then the |
| 106 | - /// empty substring will be returned. |
| 107 | - /// |
| 108 | - /// \param End The index following the last character to include in the |
| 109 | - /// substring. If this is npos, or less than \p Start, or exceeds the |
| 110 | - /// number of characters remaining in the string, the string suffix |
| 111 | - /// (starting with \p Start) will be returned. |
| 112 | - std::string_view slice(size_t Start, size_t End) const { |
| 113 | - return str().slice(Start, End); |
| 114 | - } |
| 115 | |
| 116 | // Extra methods. |
| 117 | |
| 118 | diff --git a/llvm/include/llvm/Support/Errno.h b/llvm/include/llvm/Support/Errno.h |
| 119 | index 07df6765d..d9bf68bb3 100644 |
| 120 | --- a/llvm/include/llvm/Support/Errno.h |
| 121 | +++ b/llvm/include/llvm/Support/Errno.h |
| 122 | @@ -20,15 +20,6 @@ |
| 123 | namespace llvm { |
| 124 | namespace sys { |
| 125 | |
| 126 | -/// Returns a string representation of the errno value, using whatever |
| 127 | -/// thread-safe variant of strerror() is available. Be sure to call this |
| 128 | -/// immediately after the function that set errno, or errno may have been |
| 129 | -/// overwritten by an intervening call. |
| 130 | -std::string StrError(); |
| 131 | - |
| 132 | -/// Like the no-argument version above, but uses \p errnum instead of errno. |
| 133 | -std::string StrError(int errnum); |
| 134 | - |
| 135 | template <typename FailT, typename Fun, typename... Args> |
| 136 | inline decltype(auto) RetryAfterSignal(const FailT &Fail, const Fun &F, |
| 137 | const Args &... As) { |
| 138 | diff --git a/llvm/include/llvm/Support/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h |
| 139 | index 3d6573bf5..a28e12adc 100644 |
| 140 | --- a/llvm/include/llvm/Support/VersionTuple.h |
| 141 | +++ b/llvm/include/llvm/Support/VersionTuple.h |
| 142 | @@ -16,7 +16,6 @@ |
| 143 | |
| 144 | #include "llvm/ADT/DenseMapInfo.h" |
| 145 | #include "llvm/ADT/Hashing.h" |
| 146 | -#include "llvm/Support/HashBuilder.h" |
| 147 | #include <optional> |
| 148 | #include <string> |
| 149 | #include <tuple> |
| 150 | @@ -159,45 +158,6 @@ public: |
| 151 | friend bool operator>=(const VersionTuple &X, const VersionTuple &Y) { |
| 152 | return !(X < Y); |
| 153 | } |
| 154 | - |
| 155 | - friend llvm::hash_code hash_value(const VersionTuple &VT) { |
| 156 | - return llvm::hash_combine(VT.Major, VT.Minor, VT.Subminor, VT.Build); |
| 157 | - } |
| 158 | - |
| 159 | - template <typename HasherT, llvm::support::endianness Endianness> |
| 160 | - friend void addHash(HashBuilderImpl<HasherT, Endianness> &HBuilder, |
| 161 | - const VersionTuple &VT) { |
| 162 | - HBuilder.add(VT.Major, VT.Minor, VT.Subminor, VT.Build); |
| 163 | - } |
| 164 | - |
| 165 | - /// Retrieve a string representation of the version number. |
| 166 | - std::string getAsString() const; |
| 167 | -}; |
| 168 | - |
| 169 | -/// Print a version number. |
| 170 | -raw_ostream &operator<<(raw_ostream &Out, const VersionTuple &V); |
| 171 | - |
| 172 | -// Provide DenseMapInfo for version tuples. |
| 173 | -template <> struct DenseMapInfo<VersionTuple> { |
| 174 | - static inline VersionTuple getEmptyKey() { return VersionTuple(0x7FFFFFFF); } |
| 175 | - static inline VersionTuple getTombstoneKey() { |
| 176 | - return VersionTuple(0x7FFFFFFE); |
| 177 | - } |
| 178 | - static unsigned getHashValue(const VersionTuple &Value) { |
| 179 | - unsigned Result = Value.getMajor(); |
| 180 | - if (auto Minor = Value.getMinor()) |
| 181 | - Result = detail::combineHashValue(Result, *Minor); |
| 182 | - if (auto Subminor = Value.getSubminor()) |
| 183 | - Result = detail::combineHashValue(Result, *Subminor); |
| 184 | - if (auto Build = Value.getBuild()) |
| 185 | - Result = detail::combineHashValue(Result, *Build); |
| 186 | - |
| 187 | - return Result; |
| 188 | - } |
| 189 | - |
| 190 | - static bool isEqual(const VersionTuple &LHS, const VersionTuple &RHS) { |
| 191 | - return LHS == RHS; |
| 192 | - } |
| 193 | }; |
| 194 | |
| 195 | } // end namespace llvm |
| 196 | diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h |
| 197 | index a25ca5b7b..d4521c8e2 100644 |
| 198 | --- a/llvm/include/llvm/Support/raw_ostream.h |
| 199 | +++ b/llvm/include/llvm/Support/raw_ostream.h |
| 200 | @@ -248,32 +248,6 @@ public: |
| 201 | return write(Str.data(), Str.size()); |
| 202 | } |
| 203 | |
| 204 | - raw_ostream &operator<<(unsigned long N); |
| 205 | - raw_ostream &operator<<(long N); |
| 206 | - raw_ostream &operator<<(unsigned long long N); |
| 207 | - raw_ostream &operator<<(long long N); |
| 208 | - raw_ostream &operator<<(const void *P); |
| 209 | - |
| 210 | - raw_ostream &operator<<(unsigned int N) { |
| 211 | - return this->operator<<(static_cast<unsigned long>(N)); |
| 212 | - } |
| 213 | - |
| 214 | - raw_ostream &operator<<(int N) { |
| 215 | - return this->operator<<(static_cast<long>(N)); |
| 216 | - } |
| 217 | - |
| 218 | - raw_ostream &operator<<(double N); |
| 219 | - |
| 220 | - /// Output \p N in hexadecimal, without any prefix or padding. |
| 221 | - raw_ostream &write_hex(unsigned long long N); |
| 222 | - |
| 223 | - // Change the foreground color of text. |
| 224 | - raw_ostream &operator<<(Colors C); |
| 225 | - |
| 226 | - /// Output a formatted UUID with dash separators. |
| 227 | - using uuid_t = uint8_t[16]; |
| 228 | - raw_ostream &write_uuid(const uuid_t UUID); |
| 229 | - |
| 230 | /// Output \p Str, turning '\\', '\t', '\n', '"', and anything that doesn't |
| 231 | /// satisfy llvm::isPrint into an escape sequence. |
| 232 | raw_ostream &write_escaped(std::string_view Str, bool UseHexEscapes = false); |
| 233 | @@ -281,21 +255,6 @@ public: |
| 234 | raw_ostream &write(unsigned char C); |
| 235 | raw_ostream &write(const char *Ptr, size_t Size); |
| 236 | |
| 237 | - // Formatted output, see the format() function in Support/Format.h. |
| 238 | - raw_ostream &operator<<(const format_object_base &Fmt); |
| 239 | - |
| 240 | - // Formatted output, see the leftJustify() function in Support/Format.h. |
| 241 | - raw_ostream &operator<<(const FormattedString &); |
| 242 | - |
| 243 | - // Formatted output, see the formatHex() function in Support/Format.h. |
| 244 | - raw_ostream &operator<<(const FormattedNumber &); |
| 245 | - |
| 246 | - // Formatted output, see the formatv() function in Support/FormatVariadic.h. |
| 247 | - raw_ostream &operator<<(const formatv_object_base &); |
| 248 | - |
| 249 | - // Formatted output, see the format_bytes() function in Support/Format.h. |
| 250 | - raw_ostream &operator<<(const FormattedBytes &); |
| 251 | - |
| 252 | /// indent - Insert 'NumSpaces' spaces. |
| 253 | raw_ostream &indent(unsigned NumSpaces); |
| 254 | |
| 255 | @@ -310,14 +269,19 @@ public: |
| 256 | /// @param BG if true change the background, default: change foreground |
| 257 | /// @returns itself so it can be used within << invocations |
| 258 | virtual raw_ostream &changeColor(enum Colors Color, bool Bold = false, |
| 259 | - bool BG = false); |
| 260 | + bool BG = false) { |
| 261 | + (void)Color; |
| 262 | + (void)Bold; |
| 263 | + (void)BG; |
| 264 | + return *this; |
| 265 | + } |
| 266 | |
| 267 | /// Resets the colors to terminal defaults. Call this when you are done |
| 268 | /// outputting colored text, or before program exit. |
| 269 | - virtual raw_ostream &resetColor(); |
| 270 | + virtual raw_ostream &resetColor() { return *this; } |
| 271 | |
| 272 | /// Reverses the foreground and background colors. |
| 273 | - virtual raw_ostream &reverseColor(); |
| 274 | + virtual raw_ostream &reverseColor() { return *this; } |
| 275 | |
| 276 | /// This function determines if this stream is connected to a "tty" or |
| 277 | /// "console" window. That is, the output would be displayed to the user |
| 278 | @@ -392,10 +356,6 @@ private: |
| 279 | /// unused bytes in the buffer. |
| 280 | void copy_to_buffer(const char *Ptr, size_t Size); |
| 281 | |
| 282 | - /// Compute whether colors should be used and do the necessary work such as |
| 283 | - /// flushing. The result is affected by calls to enable_color(). |
| 284 | - bool prepare_colors(); |
| 285 | - |
| 286 | /// Flush the tied-to stream (if present) and then write the required data. |
| 287 | void flush_tied_then_write(const char *Ptr, size_t Size); |
| 288 | |
| 289 | @@ -447,7 +407,6 @@ class raw_fd_ostream : public raw_pwrite_stream { |
| 290 | bool ShouldClose; |
| 291 | bool SupportsSeeking = false; |
| 292 | bool IsRegularFile = false; |
| 293 | - mutable std::optional<bool> HasColors; |
| 294 | |
| 295 | #ifdef _WIN32 |
| 296 | /// True if this fd refers to a Windows console device. Mintty and other |
| 297 | @@ -523,10 +482,6 @@ public: |
| 298 | /// to the offset specified from the beginning of the file. |
| 299 | uint64_t seek(uint64_t off); |
| 300 | |
| 301 | - bool is_displayed() const override; |
| 302 | - |
| 303 | - bool has_colors() const override; |
| 304 | - |
| 305 | std::error_code error() const { return EC; } |
| 306 | |
| 307 | /// Return the value of the flag in this raw_fd_ostream indicating whether an |
| 308 | @@ -545,38 +500,6 @@ public: |
| 309 | /// - from The Zen of Python, by Tim Peters |
| 310 | /// |
| 311 | void clear_error() { EC = std::error_code(); } |
| 312 | - |
| 313 | - /// Locks the underlying file. |
| 314 | - /// |
| 315 | - /// @returns RAII object that releases the lock upon leaving the scope, if the |
| 316 | - /// locking was successful. Otherwise returns corresponding |
| 317 | - /// error code. |
| 318 | - /// |
| 319 | - /// The function blocks the current thread until the lock become available or |
| 320 | - /// error occurs. |
| 321 | - /// |
| 322 | - /// Possible use of this function may be as follows: |
| 323 | - /// |
| 324 | - /// @code{.cpp} |
| 325 | - /// if (auto L = stream.lock()) { |
| 326 | - /// // ... do action that require file to be locked. |
| 327 | - /// } else { |
| 328 | - /// handleAllErrors(std::move(L.takeError()), [&](ErrorInfoBase &EIB) { |
| 329 | - /// // ... handle lock error. |
| 330 | - /// }); |
| 331 | - /// } |
| 332 | - /// @endcode |
| 333 | - LLVM_NODISCARD Expected<sys::fs::FileLocker> lock(); |
| 334 | - |
| 335 | - /// Tries to lock the underlying file within the specified period. |
| 336 | - /// |
| 337 | - /// @returns RAII object that releases the lock upon leaving the scope, if the |
| 338 | - /// locking was successful. Otherwise returns corresponding |
| 339 | - /// error code. |
| 340 | - /// |
| 341 | - /// It is used as @ref lock. |
| 342 | - LLVM_NODISCARD |
| 343 | - Expected<sys::fs::FileLocker> tryLockFor(Duration const& Timeout); |
| 344 | }; |
| 345 | |
| 346 | /// This returns a reference to a raw_fd_ostream for standard output. Use it |
| 347 | @@ -606,17 +529,6 @@ public: |
| 348 | /// immediately destroyed. |
| 349 | raw_fd_stream(std::string_view Filename, std::error_code &EC); |
| 350 | |
| 351 | - /// This reads the \p Size bytes into a buffer pointed by \p Ptr. |
| 352 | - /// |
| 353 | - /// \param Ptr The start of the buffer to hold data to be read. |
| 354 | - /// |
| 355 | - /// \param Size The number of bytes to be read. |
| 356 | - /// |
| 357 | - /// On success, the number of bytes read is returned, and the file position is |
| 358 | - /// advanced by this number. On error, -1 is returned, use error() to get the |
| 359 | - /// error code. |
| 360 | - ssize_t read(char *Ptr, size_t Size); |
| 361 | - |
| 362 | /// Check if \p OS is a pointer of type raw_fd_stream*. |
| 363 | static bool classof(const raw_ostream *OS); |
| 364 | }; |
| 365 | @@ -734,17 +646,6 @@ public: |
| 366 | ~buffer_unique_ostream() override { *OS << str(); } |
| 367 | }; |
| 368 | |
| 369 | -class Error; |
| 370 | - |
| 371 | -/// This helper creates an output stream and then passes it to \p Write. |
| 372 | -/// The stream created is based on the specified \p OutputFileName: |
| 373 | -/// llvm::outs for "-", raw_null_ostream for "/dev/null", and raw_fd_ostream |
| 374 | -/// for other names. For raw_fd_ostream instances, the stream writes to |
| 375 | -/// a temporary file. The final output file is atomically replaced with the |
| 376 | -/// temporary file after the \p Write function is finished. |
| 377 | -Error writeToOutput(std::string_view OutputFileName, |
| 378 | - std::function<Error(raw_ostream &)> Write); |
| 379 | - |
| 380 | } // end namespace llvm |
| 381 | |
| 382 | #endif // LLVM_SUPPORT_RAW_OSTREAM_H |
| 383 | diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp |
| 384 | index ee01a9522..875eda7ba 100644 |
| 385 | --- a/llvm/lib/Support/raw_ostream.cpp |
| 386 | +++ b/llvm/lib/Support/raw_ostream.cpp |
| 387 | @@ -19,7 +19,6 @@ |
| 388 | #include "llvm/ADT/StringExtras.h" |
| 389 | #include "llvm/Config/config.h" |
| 390 | #include "llvm/Support/Compiler.h" |
| 391 | -#include "llvm/Support/Duration.h" |
| 392 | #include "llvm/Support/ErrorHandling.h" |
| 393 | #include "llvm/Support/FileSystem.h" |
| 394 | #include "llvm/Support/Format.h" |
| 395 | @@ -120,49 +119,6 @@ void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size, |
| 396 | assert(OutBufStart <= OutBufEnd && "Invalid size!"); |
| 397 | } |
| 398 | |
| 399 | -raw_ostream &raw_ostream::operator<<(unsigned long N) { |
| 400 | - write_integer(*this, static_cast<uint64_t>(N), 0, IntegerStyle::Integer); |
| 401 | - return *this; |
| 402 | -} |
| 403 | - |
| 404 | -raw_ostream &raw_ostream::operator<<(long N) { |
| 405 | - write_integer(*this, static_cast<int64_t>(N), 0, IntegerStyle::Integer); |
| 406 | - return *this; |
| 407 | -} |
| 408 | - |
| 409 | -raw_ostream &raw_ostream::operator<<(unsigned long long N) { |
| 410 | - write_integer(*this, static_cast<uint64_t>(N), 0, IntegerStyle::Integer); |
| 411 | - return *this; |
| 412 | -} |
| 413 | - |
| 414 | -raw_ostream &raw_ostream::operator<<(long long N) { |
| 415 | - write_integer(*this, static_cast<int64_t>(N), 0, IntegerStyle::Integer); |
| 416 | - return *this; |
| 417 | -} |
| 418 | - |
| 419 | -raw_ostream &raw_ostream::write_hex(unsigned long long N) { |
| 420 | - llvm::write_hex(*this, N, HexPrintStyle::Lower); |
| 421 | - return *this; |
| 422 | -} |
| 423 | - |
| 424 | -raw_ostream &raw_ostream::operator<<(Colors C) { |
| 425 | - if (C == Colors::RESET) |
| 426 | - resetColor(); |
| 427 | - else |
| 428 | - changeColor(C); |
| 429 | - return *this; |
| 430 | -} |
| 431 | - |
| 432 | -raw_ostream &raw_ostream::write_uuid(const uuid_t UUID) { |
| 433 | - for (int Idx = 0; Idx < 16; ++Idx) { |
| 434 | - *this << format("%02" PRIX32, UUID[Idx]); |
| 435 | - if (Idx == 3 || Idx == 5 || Idx == 7 || Idx == 9) |
| 436 | - *this << "-"; |
| 437 | - } |
| 438 | - return *this; |
| 439 | -} |
| 440 | - |
| 441 | - |
| 442 | raw_ostream &raw_ostream::write_escaped(std::string_view Str, |
| 443 | bool UseHexEscapes) { |
| 444 | for (unsigned char c : Str) { |
| 445 | @@ -308,172 +264,6 @@ void raw_ostream::flush_tied_then_write(const char *Ptr, size_t Size) { |
| 446 | write_impl(Ptr, Size); |
| 447 | } |
| 448 | |
| 449 | -// Formatted output. |
| 450 | -raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) { |
| 451 | - // If we have more than a few bytes left in our output buffer, try |
| 452 | - // formatting directly onto its end. |
| 453 | - size_t NextBufferSize = 127; |
| 454 | - size_t BufferBytesLeft = OutBufEnd - OutBufCur; |
| 455 | - if (BufferBytesLeft > 3) { |
| 456 | - size_t BytesUsed = Fmt.print(OutBufCur, BufferBytesLeft); |
| 457 | - |
| 458 | - // Common case is that we have plenty of space. |
| 459 | - if (BytesUsed <= BufferBytesLeft) { |
| 460 | - OutBufCur += BytesUsed; |
| 461 | - return *this; |
| 462 | - } |
| 463 | - |
| 464 | - // Otherwise, we overflowed and the return value tells us the size to try |
| 465 | - // again with. |
| 466 | - NextBufferSize = BytesUsed; |
| 467 | - } |
| 468 | - |
| 469 | - // If we got here, we didn't have enough space in the output buffer for the |
| 470 | - // string. Try printing into a SmallVector that is resized to have enough |
| 471 | - // space. Iterate until we win. |
| 472 | - SmallVector<char, 128> V; |
| 473 | - |
| 474 | - while (true) { |
| 475 | - V.resize(NextBufferSize); |
| 476 | - |
| 477 | - // Try formatting into the SmallVector. |
| 478 | - size_t BytesUsed = Fmt.print(V.data(), NextBufferSize); |
| 479 | - |
| 480 | - // If BytesUsed fit into the vector, we win. |
| 481 | - if (BytesUsed <= NextBufferSize) |
| 482 | - return write(V.data(), BytesUsed); |
| 483 | - |
| 484 | - // Otherwise, try again with a new size. |
| 485 | - assert(BytesUsed > NextBufferSize && "Didn't grow buffer!?"); |
| 486 | - NextBufferSize = BytesUsed; |
| 487 | - } |
| 488 | -} |
| 489 | - |
| 490 | -raw_ostream &raw_ostream::operator<<(const formatv_object_base &Obj) { |
| 491 | - Obj.format(*this); |
| 492 | - return *this; |
| 493 | -} |
| 494 | - |
| 495 | -raw_ostream &raw_ostream::operator<<(const FormattedString &FS) { |
| 496 | - unsigned LeftIndent = 0; |
| 497 | - unsigned RightIndent = 0; |
| 498 | - const ssize_t Difference = FS.Width - FS.Str.size(); |
| 499 | - if (Difference > 0) { |
| 500 | - switch (FS.Justify) { |
| 501 | - case FormattedString::JustifyNone: |
| 502 | - break; |
| 503 | - case FormattedString::JustifyLeft: |
| 504 | - RightIndent = Difference; |
| 505 | - break; |
| 506 | - case FormattedString::JustifyRight: |
| 507 | - LeftIndent = Difference; |
| 508 | - break; |
| 509 | - case FormattedString::JustifyCenter: |
| 510 | - LeftIndent = Difference / 2; |
| 511 | - RightIndent = Difference - LeftIndent; |
| 512 | - break; |
| 513 | - } |
| 514 | - } |
| 515 | - indent(LeftIndent); |
| 516 | - (*this) << FS.Str; |
| 517 | - indent(RightIndent); |
| 518 | - return *this; |
| 519 | -} |
| 520 | - |
| 521 | -raw_ostream &raw_ostream::operator<<(const FormattedNumber &FN) { |
| 522 | - if (FN.Hex) { |
| 523 | - HexPrintStyle Style; |
| 524 | - if (FN.Upper && FN.HexPrefix) |
| 525 | - Style = HexPrintStyle::PrefixUpper; |
| 526 | - else if (FN.Upper && !FN.HexPrefix) |
| 527 | - Style = HexPrintStyle::Upper; |
| 528 | - else if (!FN.Upper && FN.HexPrefix) |
| 529 | - Style = HexPrintStyle::PrefixLower; |
| 530 | - else |
| 531 | - Style = HexPrintStyle::Lower; |
| 532 | - llvm::write_hex(*this, FN.HexValue, Style, FN.Width); |
| 533 | - } else { |
| 534 | - llvm::SmallString<16> Buffer; |
| 535 | - llvm::raw_svector_ostream Stream(Buffer); |
| 536 | - llvm::write_integer(Stream, FN.DecValue, 0, IntegerStyle::Integer); |
| 537 | - if (Buffer.size() < FN.Width) |
| 538 | - indent(FN.Width - Buffer.size()); |
| 539 | - (*this) << Buffer; |
| 540 | - } |
| 541 | - return *this; |
| 542 | -} |
| 543 | - |
| 544 | -raw_ostream &raw_ostream::operator<<(const FormattedBytes &FB) { |
| 545 | - if (FB.Bytes.empty()) |
| 546 | - return *this; |
| 547 | - |
| 548 | - size_t LineIndex = 0; |
| 549 | - auto Bytes = FB.Bytes; |
| 550 | - const size_t Size = Bytes.size(); |
| 551 | - HexPrintStyle HPS = FB.Upper ? HexPrintStyle::Upper : HexPrintStyle::Lower; |
| 552 | - uint64_t OffsetWidth = 0; |
| 553 | - if (FB.FirstByteOffset.hasValue()) { |
| 554 | - // Figure out how many nibbles are needed to print the largest offset |
| 555 | - // represented by this data set, so that we can align the offset field |
| 556 | - // to the right width. |
| 557 | - size_t Lines = Size / FB.NumPerLine; |
| 558 | - uint64_t MaxOffset = *FB.FirstByteOffset + Lines * FB.NumPerLine; |
| 559 | - unsigned Power = 0; |
| 560 | - if (MaxOffset > 0) |
| 561 | - Power = llvm::Log2_64_Ceil(MaxOffset); |
| 562 | - OffsetWidth = std::max<uint64_t>(4, llvm::alignTo(Power, 4) / 4); |
| 563 | - } |
| 564 | - |
| 565 | - // The width of a block of data including all spaces for group separators. |
| 566 | - unsigned NumByteGroups = |
| 567 | - alignTo(FB.NumPerLine, FB.ByteGroupSize) / FB.ByteGroupSize; |
| 568 | - unsigned BlockCharWidth = FB.NumPerLine * 2 + NumByteGroups - 1; |
| 569 | - |
| 570 | - while (!Bytes.empty()) { |
| 571 | - indent(FB.IndentLevel); |
| 572 | - |
| 573 | - if (FB.FirstByteOffset.hasValue()) { |
| 574 | - uint64_t Offset = FB.FirstByteOffset.getValue(); |
| 575 | - llvm::write_hex(*this, Offset + LineIndex, HPS, OffsetWidth); |
| 576 | - *this << ": "; |
| 577 | - } |
| 578 | - |
| 579 | - auto Line = Bytes.take_front(FB.NumPerLine); |
| 580 | - |
| 581 | - size_t CharsPrinted = 0; |
| 582 | - // Print the hex bytes for this line in groups |
| 583 | - for (size_t I = 0; I < Line.size(); ++I, CharsPrinted += 2) { |
| 584 | - if (I && (I % FB.ByteGroupSize) == 0) { |
| 585 | - ++CharsPrinted; |
| 586 | - *this << " "; |
| 587 | - } |
| 588 | - llvm::write_hex(*this, Line[I], HPS, 2); |
| 589 | - } |
| 590 | - |
| 591 | - if (FB.ASCII) { |
| 592 | - // Print any spaces needed for any bytes that we didn't print on this |
| 593 | - // line so that the ASCII bytes are correctly aligned. |
| 594 | - assert(BlockCharWidth >= CharsPrinted); |
| 595 | - indent(BlockCharWidth - CharsPrinted + 2); |
| 596 | - *this << "|"; |
| 597 | - |
| 598 | - // Print the ASCII char values for each byte on this line |
| 599 | - for (uint8_t Byte : Line) { |
| 600 | - if (isPrint(Byte)) |
| 601 | - *this << static_cast<char>(Byte); |
| 602 | - else |
| 603 | - *this << '.'; |
| 604 | - } |
| 605 | - *this << '|'; |
| 606 | - } |
| 607 | - |
| 608 | - Bytes = Bytes.drop_front(Line.size()); |
| 609 | - LineIndex += Line.size(); |
| 610 | - if (LineIndex < Size) |
| 611 | - *this << '\n'; |
| 612 | - } |
| 613 | - return *this; |
| 614 | -} |
| 615 | |
| 616 | template <char C> |
| 617 | static raw_ostream &write_padding(raw_ostream &OS, unsigned NumChars) { |
| 618 | @@ -506,63 +296,8 @@ raw_ostream &raw_ostream::write_zeros(unsigned NumZeros) { |
| 619 | return write_padding<'\0'>(*this, NumZeros); |
| 620 | } |
| 621 | |
| 622 | -bool raw_ostream::prepare_colors() { |
| 623 | - // Colors were explicitly disabled. |
| 624 | - if (!ColorEnabled) |
| 625 | - return false; |
| 626 | - |
| 627 | - // Colors require changing the terminal but this stream is not going to a |
| 628 | - // terminal. |
| 629 | - if (sys::Process::ColorNeedsFlush() && !is_displayed()) |
| 630 | - return false; |
| 631 | - |
| 632 | - if (sys::Process::ColorNeedsFlush()) |
| 633 | - flush(); |
| 634 | - |
| 635 | - return true; |
| 636 | -} |
| 637 | - |
| 638 | -raw_ostream &raw_ostream::changeColor(enum Colors colors, bool bold, bool bg) { |
| 639 | - if (!prepare_colors()) |
| 640 | - return *this; |
| 641 | - |
| 642 | - const char *colorcode = |
| 643 | - (colors == SAVEDCOLOR) |
| 644 | - ? sys::Process::OutputBold(bg) |
| 645 | - : sys::Process::OutputColor(static_cast<char>(colors), bold, bg); |
| 646 | - if (colorcode) |
| 647 | - write(colorcode, strlen(colorcode)); |
| 648 | - return *this; |
| 649 | -} |
| 650 | - |
| 651 | -raw_ostream &raw_ostream::resetColor() { |
| 652 | - if (!prepare_colors()) |
| 653 | - return *this; |
| 654 | - |
| 655 | - if (const char *colorcode = sys::Process::ResetColor()) |
| 656 | - write(colorcode, strlen(colorcode)); |
| 657 | - return *this; |
| 658 | -} |
| 659 | - |
| 660 | -raw_ostream &raw_ostream::reverseColor() { |
| 661 | - if (!prepare_colors()) |
| 662 | - return *this; |
| 663 | - |
| 664 | - if (const char *colorcode = sys::Process::OutputReverse()) |
| 665 | - write(colorcode, strlen(colorcode)); |
| 666 | - return *this; |
| 667 | -} |
| 668 | - |
| 669 | void raw_ostream::anchor() {} |
| 670 | |
| 671 | -//===----------------------------------------------------------------------===// |
| 672 | -// Formatted Output |
| 673 | -//===----------------------------------------------------------------------===// |
| 674 | - |
| 675 | -// Out of line virtual method. |
| 676 | -void format_object_base::home() { |
| 677 | -} |
| 678 | - |
| 679 | //===----------------------------------------------------------------------===// |
| 680 | // raw_fd_ostream |
| 681 | //===----------------------------------------------------------------------===// |
| 682 | @@ -854,31 +589,6 @@ size_t raw_fd_ostream::preferred_buffer_size() const { |
| 683 | #endif |
| 684 | } |
| 685 | |
| 686 | -bool raw_fd_ostream::is_displayed() const { |
| 687 | - return sys::Process::FileDescriptorIsDisplayed(FD); |
| 688 | -} |
| 689 | - |
| 690 | -bool raw_fd_ostream::has_colors() const { |
| 691 | - if (!HasColors) |
| 692 | - HasColors = sys::Process::FileDescriptorHasColors(FD); |
| 693 | - return *HasColors; |
| 694 | -} |
| 695 | - |
| 696 | -Expected<sys::fs::FileLocker> raw_fd_ostream::lock() { |
| 697 | - std::error_code EC = sys::fs::lockFile(FD); |
| 698 | - if (!EC) |
| 699 | - return sys::fs::FileLocker(FD); |
| 700 | - return errorCodeToError(EC); |
| 701 | -} |
| 702 | - |
| 703 | -Expected<sys::fs::FileLocker> |
| 704 | -raw_fd_ostream::tryLockFor(Duration const& Timeout) { |
| 705 | - std::error_code EC = sys::fs::tryLockFile(FD, Timeout.getDuration()); |
| 706 | - if (!EC) |
| 707 | - return sys::fs::FileLocker(FD); |
| 708 | - return errorCodeToError(EC); |
| 709 | -} |
| 710 | - |
| 711 | void raw_fd_ostream::anchor() {} |
| 712 | |
| 713 | //===----------------------------------------------------------------------===// |
| 714 | @@ -921,16 +631,6 @@ raw_fd_stream::raw_fd_stream(std::string_view Filename, std::error_code &EC) |
| 715 | EC = std::make_error_code(std::errc::invalid_argument); |
| 716 | } |
| 717 | |
| 718 | -ssize_t raw_fd_stream::read(char *Ptr, size_t Size) { |
| 719 | - assert(get_fd() >= 0 && "File already closed."); |
| 720 | - ssize_t Ret = ::read(get_fd(), (void *)Ptr, Size); |
| 721 | - if (Ret >= 0) |
| 722 | - inc_pos(Ret); |
| 723 | - else |
| 724 | - error_detected(std::error_code(errno, std::generic_category())); |
| 725 | - return Ret; |
| 726 | -} |
| 727 | - |
| 728 | bool raw_fd_stream::classof(const raw_ostream *OS) { |
| 729 | return OS->get_kind() == OStreamKind::OK_FDStream; |
| 730 | } |
| 731 | @@ -986,31 +686,3 @@ void raw_pwrite_stream::anchor() {} |
| 732 | void buffer_ostream::anchor() {} |
| 733 | |
| 734 | void buffer_unique_ostream::anchor() {} |
| 735 | - |
| 736 | -Error llvm::writeToOutput(std::string_view OutputFileName, |
| 737 | - std::function<Error(raw_ostream &)> Write) { |
| 738 | - if (OutputFileName == "-") |
| 739 | - return Write(outs()); |
| 740 | - |
| 741 | - if (OutputFileName == "/dev/null") { |
| 742 | - raw_null_ostream Out; |
| 743 | - return Write(Out); |
| 744 | - } |
| 745 | - |
| 746 | - unsigned Mode = sys::fs::all_read | sys::fs::all_write | sys::fs::all_exe; |
| 747 | - Expected<sys::fs::TempFile> Temp = |
| 748 | - sys::fs::TempFile::create(OutputFileName + ".temp-stream-%%%%%%", Mode); |
| 749 | - if (!Temp) |
| 750 | - return createFileError(OutputFileName, Temp.takeError()); |
| 751 | - |
| 752 | - raw_fd_ostream Out(Temp->FD, false); |
| 753 | - |
| 754 | - if (Error E = Write(Out)) { |
| 755 | - if (Error DiscardError = Temp->discard()) |
| 756 | - return joinErrors(std::move(E), std::move(DiscardError)); |
| 757 | - return E; |
| 758 | - } |
| 759 | - Out.flush(); |
| 760 | - |
| 761 | - return Temp->keep(OutputFileName); |
| 762 | -} |