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