Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
raw_ostream.cpp
Go to the documentation of this file.
1//===--- raw_ostream.cpp - Implement the raw_ostream classes --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This implements support for bulk buffered stream output.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/Support/raw_ostream.h"
14#include "llvm/ADT/StringExtras.h"
15#include "llvm/Config/config.h"
16#include "llvm/Support/AutoConvert.h"
17#include "llvm/Support/Compiler.h"
18#include "llvm/Support/Duration.h"
19#include "llvm/Support/ErrorHandling.h"
20#include "llvm/Support/FileSystem.h"
21#include "llvm/Support/Format.h"
22#include "llvm/Support/FormatVariadic.h"
23#include "llvm/Support/MathExtras.h"
24#include "llvm/Support/NativeFormatting.h"
25#include "llvm/Support/Process.h"
26#include "llvm/Support/Program.h"
27#include <algorithm>
28#include <cerrno>
29#include <cstdio>
30#include <sys/stat.h>
31
32// <fcntl.h> may provide O_BINARY.
33# include <fcntl.h>
34
35#if defined(HAVE_UNISTD_H)
36# include <unistd.h>
37#endif
38
39#if defined(__CYGWIN__)
40#include <io.h>
41#endif
42
43#if defined(_MSC_VER)
44#include <io.h>
45#ifndef STDIN_FILENO
46# define STDIN_FILENO 0
47#endif
48#ifndef STDOUT_FILENO
49# define STDOUT_FILENO 1
50#endif
51#ifndef STDERR_FILENO
52# define STDERR_FILENO 2
53#endif
54#endif
55
56#ifdef _WIN32
57#include "llvm/Support/ConvertUTF.h"
58#include "llvm/Support/Signals.h"
59#include "llvm/Support/Windows/WindowsSupport.h"
60#endif
61
62using namespacellvm;
63
64constexprraw_ostream::Colorsraw_ostream::BLACK;
65constexprraw_ostream::Colorsraw_ostream::RED;
66constexprraw_ostream::Colorsraw_ostream::GREEN;
67constexprraw_ostream::Colorsraw_ostream::YELLOW;
68constexprraw_ostream::Colorsraw_ostream::BLUE;
69constexprraw_ostream::Colorsraw_ostream::MAGENTA;
70constexprraw_ostream::Colorsraw_ostream::CYAN;
71constexprraw_ostream::Colorsraw_ostream::WHITE;
72constexprraw_ostream::Colorsraw_ostream::SAVEDCOLOR;
73constexprraw_ostream::Colorsraw_ostream::RESET;
74
75raw_ostream::~raw_ostream() {
76// raw_ostream's subclasses should take care to flush the buffer
77// in their destructors.
78assert(OutBufCur == OutBufStart &&
79"raw_ostream destructor called with non-empty buffer!");
80
81if (BufferMode == BufferKind::InternalBuffer)
82delete [] OutBufStart;
83}
84
85size_traw_ostream::preferred_buffer_size() const{
86#ifdef _WIN32
87// On Windows BUFSIZ is only 512 which results in more calls to write. This
88// overhead can cause significant performance degradation. Therefore use a
89// better default.
90return (16 * 1024);
91#else
92// BUFSIZ is intended to be a reasonable default.
93return BUFSIZ;
94#endif
95}
96
97voidraw_ostream::SetBuffered() {
98// Ask the subclass to determine an appropriate buffer size.
99if (size_tSize =preferred_buffer_size())
100SetBufferSize(Size);
101else
102// It may return 0, meaning this stream should be unbuffered.
103SetUnbuffered();
104}
105
106void raw_ostream::SetBufferAndMode(char *BufferStart,size_tSize,
107 BufferKind Mode) {
108assert(((Mode == BufferKind::Unbuffered && !BufferStart &&Size == 0) ||
109 (Mode != BufferKind::Unbuffered && BufferStart &&Size != 0)) &&
110"stream must be unbuffered or have at least one byte");
111// Make sure the current buffer is free of content (we can't flush here; the
112// child buffer management logic will be in write_impl).
113assert(GetNumBytesInBuffer() == 0 &&"Current buffer is non-empty!");
114
115if (BufferMode == BufferKind::InternalBuffer)
116delete [] OutBufStart;
117 OutBufStart = BufferStart;
118 OutBufEnd = OutBufStart+Size;
119 OutBufCur = OutBufStart;
120 BufferMode = Mode;
121
122assert(OutBufStart <= OutBufEnd &&"Invalid size!");
123}
124
125raw_ostream &raw_ostream::operator<<(unsignedlongN) {
126write_integer(*this,static_cast<uint64_t>(N), 0,IntegerStyle::Integer);
127return *this;
128}
129
130raw_ostream &raw_ostream::operator<<(longN) {
131write_integer(*this,static_cast<int64_t>(N), 0,IntegerStyle::Integer);
132return *this;
133}
134
135raw_ostream &raw_ostream::operator<<(unsignedlonglongN) {
136write_integer(*this,static_cast<uint64_t>(N), 0,IntegerStyle::Integer);
137return *this;
138}
139
140raw_ostream &raw_ostream::operator<<(longlongN) {
141write_integer(*this,static_cast<int64_t>(N), 0,IntegerStyle::Integer);
142return *this;
143}
144
145raw_ostream &raw_ostream::write_hex(unsignedlonglongN) {
146llvm::write_hex(*this,N,HexPrintStyle::Lower);
147return *this;
148}
149
150raw_ostream &raw_ostream::operator<<(ColorsC) {
151if (C ==Colors::RESET)
152resetColor();
153else
154changeColor(C);
155return *this;
156}
157
158raw_ostream &raw_ostream::write_uuid(constuuid_tUUID) {
159for (intIdx = 0;Idx < 16; ++Idx) {
160 *this <<format("%02" PRIX32,UUID[Idx]);
161if (Idx == 3 ||Idx == 5 ||Idx == 7 ||Idx == 9)
162 *this <<"-";
163 }
164return *this;
165}
166
167
168raw_ostream &raw_ostream::write_escaped(StringRef Str,
169bool UseHexEscapes) {
170for (unsignedchar c : Str) {
171switch (c) {
172case'\\':
173 *this <<'\\' <<'\\';
174break;
175case'\t':
176 *this <<'\\' <<'t';
177break;
178case'\n':
179 *this <<'\\' <<'n';
180break;
181case'"':
182 *this <<'\\' <<'"';
183break;
184default:
185if (isPrint(c)) {
186 *this << c;
187break;
188 }
189
190// Write out the escaped representation.
191if (UseHexEscapes) {
192 *this <<'\\' <<'x';
193 *this << hexdigit((c >> 4) & 0xF);
194 *this << hexdigit((c >> 0) & 0xF);
195 }else {
196// Always use a full 3-character octal escape.
197 *this <<'\\';
198 *this <<char('0' + ((c >> 6) & 7));
199 *this <<char('0' + ((c >> 3) & 7));
200 *this <<char('0' + ((c >> 0) & 7));
201 }
202 }
203 }
204
205return *this;
206}
207
208raw_ostream &raw_ostream::operator<<(constvoid *P) {
209llvm::write_hex(*this, (uintptr_t)P,HexPrintStyle::PrefixLower);
210return *this;
211}
212
213raw_ostream &raw_ostream::operator<<(doubleN) {
214llvm::write_double(*this,N,FloatStyle::Exponent);
215return *this;
216}
217
218void raw_ostream::flush_nonempty() {
219assert(OutBufCur > OutBufStart &&"Invalid call to flush_nonempty.");
220size_tLength = OutBufCur - OutBufStart;
221 OutBufCur = OutBufStart;
222 write_impl(OutBufStart,Length);
223}
224
225raw_ostream &raw_ostream::write(unsignedcharC) {
226// Group exceptional cases into a single branch.
227if (LLVM_UNLIKELY(OutBufCur >= OutBufEnd)) {
228if (LLVM_UNLIKELY(!OutBufStart)) {
229if (BufferMode == BufferKind::Unbuffered) {
230 write_impl(reinterpret_cast<char *>(&C), 1);
231return *this;
232 }
233// Set up a buffer and start over.
234SetBuffered();
235returnwrite(C);
236 }
237
238 flush_nonempty();
239 }
240
241 *OutBufCur++ =C;
242return *this;
243}
244
245raw_ostream &raw_ostream::write(constchar *Ptr,size_tSize) {
246// Group exceptional cases into a single branch.
247if (LLVM_UNLIKELY(size_t(OutBufEnd - OutBufCur) <Size)) {
248if (LLVM_UNLIKELY(!OutBufStart)) {
249if (BufferMode == BufferKind::Unbuffered) {
250 write_impl(Ptr,Size);
251return *this;
252 }
253// Set up a buffer and start over.
254SetBuffered();
255returnwrite(Ptr,Size);
256 }
257
258size_t NumBytes = OutBufEnd - OutBufCur;
259
260// If the buffer is empty at this point we have a string that is larger
261// than the buffer. Directly write the chunk that is a multiple of the
262// preferred buffer size and put the remainder in the buffer.
263if (LLVM_UNLIKELY(OutBufCur == OutBufStart)) {
264assert(NumBytes != 0 &&"undefined behavior");
265size_t BytesToWrite =Size - (Size % NumBytes);
266 write_impl(Ptr, BytesToWrite);
267size_t BytesRemaining =Size - BytesToWrite;
268if (BytesRemaining >size_t(OutBufEnd - OutBufCur)) {
269// Too much left over to copy into our buffer.
270returnwrite(Ptr + BytesToWrite, BytesRemaining);
271 }
272 copy_to_buffer(Ptr + BytesToWrite, BytesRemaining);
273return *this;
274 }
275
276// We don't have enough space in the buffer to fit the string in. Insert as
277// much as possible, flush and start over with the remainder.
278 copy_to_buffer(Ptr, NumBytes);
279 flush_nonempty();
280returnwrite(Ptr + NumBytes,Size - NumBytes);
281 }
282
283 copy_to_buffer(Ptr,Size);
284
285return *this;
286}
287
288void raw_ostream::copy_to_buffer(constchar *Ptr,size_tSize) {
289assert(Size <=size_t(OutBufEnd - OutBufCur) &&"Buffer overrun!");
290
291// Handle short strings specially, memcpy isn't very good at very short
292// strings.
293switch (Size) {
294case 4: OutBufCur[3] =Ptr[3]; [[fallthrough]];
295case 3: OutBufCur[2] =Ptr[2]; [[fallthrough]];
296case 2: OutBufCur[1] =Ptr[1]; [[fallthrough]];
297case 1: OutBufCur[0] =Ptr[0]; [[fallthrough]];
298case 0:break;
299default:
300 memcpy(OutBufCur,Ptr,Size);
301break;
302 }
303
304 OutBufCur +=Size;
305}
306
307// Formatted output.
308raw_ostream &raw_ostream::operator<<(constformat_object_base &Fmt) {
309// If we have more than a few bytes left in our output buffer, try
310// formatting directly onto its end.
311size_t NextBufferSize = 127;
312size_t BufferBytesLeft = OutBufEnd - OutBufCur;
313if (BufferBytesLeft > 3) {
314size_t BytesUsed = Fmt.print(OutBufCur, BufferBytesLeft);
315
316// Common case is that we have plenty of space.
317if (BytesUsed <= BufferBytesLeft) {
318 OutBufCur += BytesUsed;
319return *this;
320 }
321
322// Otherwise, we overflowed and the return value tells us the size to try
323// again with.
324 NextBufferSize = BytesUsed;
325 }
326
327// If we got here, we didn't have enough space in the output buffer for the
328// string. Try printing into a SmallVector that is resized to have enough
329// space. Iterate until we win.
330SmallVector<char, 128> V;
331
332while (true) {
333 V.resize(NextBufferSize);
334
335// Try formatting into the SmallVector.
336size_t BytesUsed = Fmt.print(V.data(), NextBufferSize);
337
338// If BytesUsed fit into the vector, we win.
339if (BytesUsed <= NextBufferSize)
340returnwrite(V.data(), BytesUsed);
341
342// Otherwise, try again with a new size.
343assert(BytesUsed > NextBufferSize &&"Didn't grow buffer!?");
344 NextBufferSize = BytesUsed;
345 }
346}
347
348raw_ostream &raw_ostream::operator<<(constformatv_object_base &Obj) {
349 Obj.format(*this);
350return *this;
351}
352
353raw_ostream &raw_ostream::operator<<(constFormattedString &FS) {
354unsigned LeftIndent = 0;
355unsigned RightIndent = 0;
356const ssize_t Difference = FS.Width - FS.Str.size();
357if (Difference > 0) {
358switch (FS.Justify) {
359caseFormattedString::JustifyNone:
360break;
361caseFormattedString::JustifyLeft:
362 RightIndent = Difference;
363break;
364caseFormattedString::JustifyRight:
365 LeftIndent = Difference;
366break;
367caseFormattedString::JustifyCenter:
368 LeftIndent = Difference / 2;
369 RightIndent = Difference - LeftIndent;
370break;
371 }
372 }
373indent(LeftIndent);
374 (*this) << FS.Str;
375indent(RightIndent);
376return *this;
377}
378
379raw_ostream &raw_ostream::operator<<(constFormattedNumber &FN) {
380if (FN.Hex) {
381HexPrintStyle Style;
382if (FN.Upper && FN.HexPrefix)
383 Style =HexPrintStyle::PrefixUpper;
384elseif (FN.Upper && !FN.HexPrefix)
385 Style =HexPrintStyle::Upper;
386elseif (!FN.Upper && FN.HexPrefix)
387 Style =HexPrintStyle::PrefixLower;
388else
389 Style =HexPrintStyle::Lower;
390llvm::write_hex(*this, FN.HexValue, Style, FN.Width);
391 }else {
392llvm::SmallString<16> Buffer;
393llvm::raw_svector_ostream Stream(Buffer);
394llvm::write_integer(Stream, FN.DecValue, 0,IntegerStyle::Integer);
395if (Buffer.size() < FN.Width)
396indent(FN.Width - Buffer.size());
397 (*this) << Buffer;
398 }
399return *this;
400}
401
402raw_ostream &raw_ostream::operator<<(constFormattedBytes &FB) {
403if (FB.Bytes.empty())
404return *this;
405
406size_t LineIndex = 0;
407auto Bytes = FB.Bytes;
408constsize_tSize = Bytes.size();
409HexPrintStyle HPS = FB.Upper ?HexPrintStyle::Upper :HexPrintStyle::Lower;
410uint64_t OffsetWidth = 0;
411if (FB.FirstByteOffset) {
412// Figure out how many nibbles are needed to print the largest offset
413// represented by this data set, so that we can align the offset field
414// to the right width.
415size_t Lines =Size / FB.NumPerLine;
416uint64_t MaxOffset = *FB.FirstByteOffset + Lines * FB.NumPerLine;
417unsigned Power = 0;
418if (MaxOffset > 0)
419 Power =llvm::Log2_64_Ceil(MaxOffset);
420 OffsetWidth = std::max<uint64_t>(4,llvm::alignTo(Power, 4) / 4);
421 }
422
423// The width of a block of data including all spaces for group separators.
424unsigned NumByteGroups =
425alignTo(FB.NumPerLine, FB.ByteGroupSize) / FB.ByteGroupSize;
426unsigned BlockCharWidth = FB.NumPerLine * 2 + NumByteGroups - 1;
427
428while (!Bytes.empty()) {
429indent(FB.IndentLevel);
430
431if (FB.FirstByteOffset) {
432uint64_tOffset = *FB.FirstByteOffset;
433llvm::write_hex(*this,Offset + LineIndex, HPS, OffsetWidth);
434 *this <<": ";
435 }
436
437auto Line = Bytes.take_front(FB.NumPerLine);
438
439size_t CharsPrinted = 0;
440// Print the hex bytes for this line in groups
441for (size_tI = 0;I < Line.size(); ++I, CharsPrinted += 2) {
442if (I && (I % FB.ByteGroupSize) == 0) {
443 ++CharsPrinted;
444 *this <<" ";
445 }
446llvm::write_hex(*this, Line[I], HPS, 2);
447 }
448
449if (FB.ASCII) {
450// Print any spaces needed for any bytes that we didn't print on this
451// line so that the ASCII bytes are correctly aligned.
452assert(BlockCharWidth >= CharsPrinted);
453indent(BlockCharWidth - CharsPrinted + 2);
454 *this <<"|";
455
456// Print the ASCII char values for each byte on this line
457for (uint8_t Byte : Line) {
458if (isPrint(Byte))
459 *this << static_cast<char>(Byte);
460else
461 *this <<'.';
462 }
463 *this <<'|';
464 }
465
466 Bytes = Bytes.drop_front(Line.size());
467 LineIndex += Line.size();
468if (LineIndex <Size)
469 *this <<'\n';
470 }
471return *this;
472}
473
474template <char C>
475staticraw_ostream &write_padding(raw_ostream &OS,unsigned NumChars) {
476staticconstchar Chars[] = {C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,
477C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,
478C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,
479C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,
480C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C};
481
482// Usually the indentation is small, handle it with a fastpath.
483if (NumChars < std::size(Chars))
484returnOS.write(Chars, NumChars);
485
486while (NumChars) {
487unsigned NumToWrite = std::min(NumChars, (unsigned)std::size(Chars) - 1);
488OS.write(Chars, NumToWrite);
489 NumChars -= NumToWrite;
490 }
491returnOS;
492}
493
494/// indent - Insert 'NumSpaces' spaces.
495raw_ostream &raw_ostream::indent(unsigned NumSpaces) {
496return write_padding<' '>(*this, NumSpaces);
497}
498
499/// write_zeros - Insert 'NumZeros' nulls.
500raw_ostream &raw_ostream::write_zeros(unsigned NumZeros) {
501return write_padding<'\0'>(*this, NumZeros);
502}
503
504bool raw_ostream::prepare_colors() {
505// Colors were explicitly disabled.
506if (!ColorEnabled)
507returnfalse;
508
509// Colors require changing the terminal but this stream is not going to a
510// terminal.
511if (sys::Process::ColorNeedsFlush() && !is_displayed())
512returnfalse;
513
514if (sys::Process::ColorNeedsFlush())
515flush();
516
517returntrue;
518}
519
520raw_ostream &raw_ostream::changeColor(enumColors colors,bool bold,bool bg) {
521if (!prepare_colors())
522return *this;
523
524constchar *colorcode =
525 (colors ==SAVEDCOLOR)
526 ?sys::Process::OutputBold(bg)
527 :sys::Process::OutputColor(static_cast<char>(colors), bold, bg);
528if (colorcode)
529write(colorcode, strlen(colorcode));
530return *this;
531}
532
533raw_ostream &raw_ostream::resetColor() {
534if (!prepare_colors())
535return *this;
536
537if (constchar *colorcode =sys::Process::ResetColor())
538write(colorcode, strlen(colorcode));
539return *this;
540}
541
542raw_ostream &raw_ostream::reverseColor() {
543if (!prepare_colors())
544return *this;
545
546if (constchar *colorcode =sys::Process::OutputReverse())
547write(colorcode, strlen(colorcode));
548return *this;
549}
550
551void raw_ostream::anchor() {}
552
553//===----------------------------------------------------------------------===//
554// Formatted Output
555//===----------------------------------------------------------------------===//
556
557// Out of line virtual method.
558voidformat_object_base::home() {
559}
560
561//===----------------------------------------------------------------------===//
562// raw_fd_ostream
563//===----------------------------------------------------------------------===//
564
565staticintgetFD(StringRef Filename, std::error_code &EC,
566sys::fs::CreationDisposition Disp,sys::fs::FileAccessAccess,
567sys::fs::OpenFlags Flags) {
568assert((Access &sys::fs::FA_Write) &&
569"Cannot make a raw_ostream from a read-only descriptor!");
570
571// Handle "-" as stdout. Note that when we do this, we consider ourself
572// the owner of stdout and may set the "binary" flag globally based on Flags.
573if (Filename =="-") {
574 EC = std::error_code();
575// Change stdout's text/binary mode based on the Flags.
576sys::ChangeStdoutMode(Flags);
577return STDOUT_FILENO;
578 }
579
580int FD;
581if (Access &sys::fs::FA_Read)
582 EC =sys::fs::openFileForReadWrite(Filename, FD, Disp, Flags);
583else
584 EC =sys::fs::openFileForWrite(Filename, FD, Disp, Flags);
585if (EC)
586return -1;
587
588return FD;
589}
590
591raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC)
592 :raw_fd_ostream(Filename, EC, sys::fs::CD_CreateAlways, sys::fs::FA_Write,
593 sys::fs::OF_None) {}
594
595raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
596sys::fs::CreationDisposition Disp)
597 :raw_fd_ostream(Filename, EC, Disp, sys::fs::FA_Write, sys::fs::OF_None) {}
598
599raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
600sys::fs::FileAccessAccess)
601 :raw_fd_ostream(Filename, EC, sys::fs::CD_CreateAlways,Access,
602 sys::fs::OF_None) {}
603
604raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
605sys::fs::OpenFlags Flags)
606 :raw_fd_ostream(Filename, EC, sys::fs::CD_CreateAlways, sys::fs::FA_Write,
607 Flags) {}
608
609raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
610sys::fs::CreationDisposition Disp,
611sys::fs::FileAccessAccess,
612sys::fs::OpenFlags Flags)
613 :raw_fd_ostream(getFD(Filename, EC, Disp,Access, Flags),true) {}
614
615/// FD is the file descriptor that this writes to. If ShouldClose is true, this
616/// closes the file when the stream is destroyed.
617raw_fd_ostream::raw_fd_ostream(int fd,bool shouldClose,bool unbuffered,
618OStreamKind K)
619 :raw_pwrite_stream(unbuffered, K), FD(fd), ShouldClose(shouldClose) {
620if (FD < 0 ) {
621 ShouldClose =false;
622return;
623 }
624
625enable_colors(true);
626
627// Do not attempt to close stdout or stderr. We used to try to maintain the
628// property that tools that support writing file to stdout should not also
629// write informational output to stdout, but in practice we were never able to
630// maintain this invariant. Many features have been added to LLVM and clang
631// (-fdump-record-layouts, optimization remarks, etc) that print to stdout, so
632// users must simply be aware that mixed output and remarks is a possibility.
633if (FD <= STDERR_FILENO)
634 ShouldClose =false;
635
636#ifdef _WIN32
637// Check if this is a console device. This is not equivalent to isatty.
638 IsWindowsConsole =
639 ::GetFileType((HANDLE)::_get_osfhandle(fd)) == FILE_TYPE_CHAR;
640#endif
641
642// Get the starting position.
643 off_t loc = ::lseek(FD, 0, SEEK_CUR);
644sys::fs::file_statusStatus;
645 std::error_code EC = status(FD,Status);
646 IsRegularFile =Status.type() ==sys::fs::file_type::regular_file;
647#ifdef _WIN32
648// MSVCRT's _lseek(SEEK_CUR) doesn't return -1 for pipes.
649 SupportsSeeking = !EC && IsRegularFile;
650#else
651 SupportsSeeking = !EC && loc != (off_t)-1;
652#endif
653if (!SupportsSeeking)
654 pos = 0;
655else
656 pos =static_cast<uint64_t>(loc);
657}
658
659raw_fd_ostream::~raw_fd_ostream() {
660if (FD >= 0) {
661flush();
662if (ShouldClose) {
663if (auto EC =sys::Process::SafelyCloseFileDescriptor(FD))
664error_detected(EC);
665 }
666 }
667
668#ifdef __MINGW32__
669// On mingw, global dtors should not call exit().
670// report_fatal_error() invokes exit(). We know report_fatal_error()
671// might not write messages to stderr when any errors were detected
672// on FD == 2.
673if (FD == 2)return;
674#endif
675
676// If there are any pending errors, report them now. Clients wishing
677// to avoid report_fatal_error calls should check for errors with
678// has_error() and clear the error flag with clear_error() before
679// destructing raw_ostream objects which may have errors.
680if (has_error())
681report_fatal_error(Twine("IO failure on output stream: ") +
682error().message(),
683/*gen_crash_diag=*/false);
684}
685
686#if defined(_WIN32)
687// The most reliable way to print unicode in a Windows console is with
688// WriteConsoleW. To use that, first transcode from UTF-8 to UTF-16. This
689// assumes that LLVM programs always print valid UTF-8 to the console. The data
690// might not be UTF-8 for two major reasons:
691// 1. The program is printing binary (-filetype=obj -o -), in which case it
692// would have been gibberish anyway.
693// 2. The program is printing text in a semi-ascii compatible codepage like
694// shift-jis or cp1252.
695//
696// Most LLVM programs don't produce non-ascii text unless they are quoting
697// user source input. A well-behaved LLVM program should either validate that
698// the input is UTF-8 or transcode from the local codepage to UTF-8 before
699// quoting it. If they don't, this may mess up the encoding, but this is still
700// probably the best compromise we can make.
701staticbool write_console_impl(int FD,StringRefData) {
702SmallVector<wchar_t, 256> WideText;
703
704// Fall back to ::write if it wasn't valid UTF-8.
705if (auto EC = sys::windows::UTF8ToUTF16(Data, WideText))
706returnfalse;
707
708// On Windows 7 and earlier, WriteConsoleW has a low maximum amount of data
709// that can be written to the console at a time.
710size_t MaxWriteSize = WideText.size();
711if (!RunningWindows8OrGreater())
712 MaxWriteSize = 32767;
713
714size_t WCharsWritten = 0;
715do {
716size_t WCharsToWrite =
717 std::min(MaxWriteSize, WideText.size() - WCharsWritten);
718 DWORD ActuallyWritten;
719boolSuccess =
720 ::WriteConsoleW((HANDLE)::_get_osfhandle(FD), &WideText[WCharsWritten],
721 WCharsToWrite, &ActuallyWritten,
722/*Reserved=*/nullptr);
723
724// The most likely reason for WriteConsoleW to fail is that FD no longer
725// points to a console. Fall back to ::write. If this isn't the first loop
726// iteration, something is truly wrong.
727if (!Success)
728returnfalse;
729
730 WCharsWritten += ActuallyWritten;
731 }while (WCharsWritten != WideText.size());
732returntrue;
733}
734#endif
735
736void raw_fd_ostream::write_impl(constchar *Ptr,size_tSize) {
737if (TiedStream)
738 TiedStream->flush();
739
740assert(FD >= 0 &&"File already closed.");
741 pos +=Size;
742
743#if defined(_WIN32)
744// If this is a Windows console device, try re-encoding from UTF-8 to UTF-16
745// and using WriteConsoleW. If that fails, fall back to plain write().
746if (IsWindowsConsole)
747if (write_console_impl(FD,StringRef(Ptr,Size)))
748return;
749#endif
750
751// The maximum write size is limited to INT32_MAX. A write
752// greater than SSIZE_MAX is implementation-defined in POSIX,
753// and Windows _write requires 32 bit input.
754size_t MaxWriteSize = INT32_MAX;
755
756#if defined(__linux__)
757// It is observed that Linux returns EINVAL for a very large write (>2G).
758// Make it a reasonably small value.
759 MaxWriteSize = 1024 * 1024 * 1024;
760#endif
761
762do {
763size_t ChunkSize = std::min(Size, MaxWriteSize);
764 ssize_t ret =::write(FD,Ptr, ChunkSize);
765
766if (ret < 0) {
767// If it's a recoverable error, swallow it and retry the write.
768//
769// Ideally we wouldn't ever see EAGAIN or EWOULDBLOCK here, since
770// raw_ostream isn't designed to do non-blocking I/O. However, some
771// programs, such as old versions of bjam, have mistakenly used
772// O_NONBLOCK. For compatibility, emulate blocking semantics by
773// spinning until the write succeeds. If you don't want spinning,
774// don't use O_NONBLOCK file descriptors with raw_ostream.
775if (errno == EINTR || errno == EAGAIN
776#ifdef EWOULDBLOCK
777 || errno == EWOULDBLOCK
778#endif
779 )
780continue;
781
782#ifdef _WIN32
783// Windows equivalents of SIGPIPE/EPIPE.
784DWORD WinLastError = GetLastError();
785if (WinLastError == ERROR_BROKEN_PIPE ||
786 (WinLastError == ERROR_NO_DATA && errno == EINVAL)) {
787 llvm::sys::CallOneShotPipeSignalHandler();
788 errno = EPIPE;
789 }
790#endif
791// Otherwise it's a non-recoverable error. Note it and quit.
792error_detected(errnoAsErrorCode());
793break;
794 }
795
796// The write may have written some or all of the data. Update the
797// size and buffer pointer to reflect the remainder that needs
798// to be written. If there are no bytes left, we're done.
799Ptr += ret;
800Size -= ret;
801 }while (Size > 0);
802}
803
804voidraw_fd_ostream::close() {
805assert(ShouldClose);
806 ShouldClose =false;
807flush();
808if (auto EC =sys::Process::SafelyCloseFileDescriptor(FD))
809error_detected(EC);
810 FD = -1;
811}
812
813uint64_traw_fd_ostream::seek(uint64_t off) {
814assert(SupportsSeeking &&"Stream does not support seeking!");
815flush();
816#ifdef _WIN32
817 pos = ::_lseeki64(FD, off, SEEK_SET);
818#else
819 pos = ::lseek(FD, off, SEEK_SET);
820#endif
821if (pos == (uint64_t)-1)
822error_detected(errnoAsErrorCode());
823return pos;
824}
825
826void raw_fd_ostream::pwrite_impl(constchar *Ptr,size_tSize,
827uint64_tOffset) {
828uint64_t Pos =tell();
829seek(Offset);
830write(Ptr,Size);
831seek(Pos);
832}
833
834size_t raw_fd_ostream::preferred_buffer_size() const{
835#if defined(_WIN32)
836// Disable buffering for console devices. Console output is re-encoded from
837// UTF-8 to UTF-16 on Windows, and buffering it would require us to split the
838// buffer on a valid UTF-8 codepoint boundary. Terminal buffering is disabled
839// below on most other OSs, so do the same thing on Windows and avoid that
840// complexity.
841if (IsWindowsConsole)
842return 0;
843returnraw_ostream::preferred_buffer_size();
844#elif defined(__MVS__)
845// The buffer size on z/OS is defined with macro BUFSIZ, which can be
846// retrieved by invoking function raw_ostream::preferred_buffer_size().
847returnraw_ostream::preferred_buffer_size();
848#else
849assert(FD >= 0 &&"File not yet open!");
850structstat statbuf;
851if (fstat(FD, &statbuf) != 0)
852return 0;
853
854// If this is a terminal, don't use buffering. Line buffering
855// would be a more traditional thing to do, but it's not worth
856// the complexity.
857if (S_ISCHR(statbuf.st_mode) &&is_displayed())
858return 0;
859// Return the preferred block size.
860return statbuf.st_blksize;
861#endif
862}
863
864boolraw_fd_ostream::is_displayed() const{
865returnsys::Process::FileDescriptorIsDisplayed(FD);
866}
867
868boolraw_fd_ostream::has_colors() const{
869if (!HasColors)
870 HasColors =sys::Process::FileDescriptorHasColors(FD);
871return *HasColors;
872}
873
874Expected<sys::fs::FileLocker>raw_fd_ostream::lock() {
875 std::error_code EC =sys::fs::lockFile(FD);
876if (!EC)
877returnsys::fs::FileLocker(FD);
878returnerrorCodeToError(EC);
879}
880
881Expected<sys::fs::FileLocker>
882raw_fd_ostream::tryLockFor(Durationconst& Timeout) {
883 std::error_code EC =sys::fs::tryLockFile(FD, Timeout.getDuration());
884if (!EC)
885returnsys::fs::FileLocker(FD);
886returnerrorCodeToError(EC);
887}
888
889void raw_fd_ostream::anchor() {}
890
891//===----------------------------------------------------------------------===//
892// outs(), errs(), nulls()
893//===----------------------------------------------------------------------===//
894
895raw_fd_ostream &llvm::outs() {
896// Set buffer settings to model stdout behavior.
897 std::error_code EC;
898#ifdef __MVS__
899 EC = enablezOSAutoConversion(STDOUT_FILENO);
900assert(!EC);
901#endif
902staticraw_fd_ostream S("-", EC,sys::fs::OF_None);
903assert(!EC);
904return S;
905}
906
907raw_fd_ostream &llvm::errs() {
908// Set standard error to be unbuffered.
909#ifdef __MVS__
910 std::error_code EC = enablezOSAutoConversion(STDERR_FILENO);
911assert(!EC);
912#endif
913staticraw_fd_ostream S(STDERR_FILENO,false,true);
914return S;
915}
916
917/// nulls() - This returns a reference to a raw_ostream which discards output.
918raw_ostream &llvm::nulls() {
919staticraw_null_ostream S;
920return S;
921}
922
923//===----------------------------------------------------------------------===//
924// File Streams
925//===----------------------------------------------------------------------===//
926
927raw_fd_stream::raw_fd_stream(StringRef Filename, std::error_code &EC)
928 :raw_fd_ostream(getFD(Filename, EC, sys::fs::CD_CreateAlways,
929 sys::fs::FA_Write | sys::fs::FA_Read,
930 sys::fs::OF_None),
931true,false,OStreamKind::OK_FDStream) {
932if (EC)
933return;
934
935if (!isRegularFile())
936 EC = std::make_error_code(std::errc::invalid_argument);
937}
938
939raw_fd_stream::raw_fd_stream(int fd,bool shouldClose)
940 :raw_fd_ostream(fd, shouldClose,false,OStreamKind::OK_FDStream) {}
941
942ssize_traw_fd_stream::read(char *Ptr,size_tSize) {
943assert(get_fd() >= 0 &&"File already closed.");
944 ssize_t Ret =::read(get_fd(), (void *)Ptr,Size);
945if (Ret >= 0)
946inc_pos(Ret);
947else
948error_detected(errnoAsErrorCode());
949return Ret;
950}
951
952boolraw_fd_stream::classof(constraw_ostream *OS) {
953returnOS->get_kind() ==OStreamKind::OK_FDStream;
954}
955
956//===----------------------------------------------------------------------===//
957// raw_string_ostream
958//===----------------------------------------------------------------------===//
959
960void raw_string_ostream::write_impl(constchar *Ptr,size_tSize) {
961OS.append(Ptr,Size);
962}
963
964//===----------------------------------------------------------------------===//
965// raw_svector_ostream
966//===----------------------------------------------------------------------===//
967
968uint64_t raw_svector_ostream::current_pos() const{returnOS.size(); }
969
970void raw_svector_ostream::write_impl(constchar *Ptr,size_tSize) {
971OS.append(Ptr,Ptr +Size);
972}
973
974void raw_svector_ostream::pwrite_impl(constchar *Ptr,size_tSize,
975uint64_tOffset) {
976 memcpy(OS.data() +Offset,Ptr,Size);
977}
978
979boolraw_svector_ostream::classof(constraw_ostream *OS) {
980returnOS->get_kind() ==OStreamKind::OK_SVecStream;
981}
982
983//===----------------------------------------------------------------------===//
984// raw_null_ostream
985//===----------------------------------------------------------------------===//
986
987raw_null_ostream::~raw_null_ostream() {
988#ifndef NDEBUG
989// ~raw_ostream asserts that the buffer is empty. This isn't necessary
990// with raw_null_ostream, but it's better to have raw_null_ostream follow
991// the rules than to change the rules just for raw_null_ostream.
992flush();
993#endif
994}
995
996void raw_null_ostream::write_impl(constchar *Ptr,size_tSize) {
997}
998
999uint64_t raw_null_ostream::current_pos() const{
1000return 0;
1001}
1002
1003void raw_null_ostream::pwrite_impl(constchar *Ptr,size_tSize,
1004uint64_tOffset) {}
1005
1006void raw_pwrite_stream::anchor() {}
1007
1008void buffer_ostream::anchor() {}
1009
1010void buffer_unique_ostream::anchor() {}
1011
1012Errorllvm::writeToOutput(StringRef OutputFileName,
1013 std::function<Error(raw_ostream &)>Write) {
1014if (OutputFileName =="-")
1015returnWrite(outs());
1016
1017if (OutputFileName =="/dev/null") {
1018raw_null_ostream Out;
1019returnWrite(Out);
1020 }
1021
1022unsignedMode =sys::fs::all_read |sys::fs::all_write;
1023Expected<sys::fs::TempFile> Temp =
1024sys::fs::TempFile::create(OutputFileName +".temp-stream-%%%%%%",Mode);
1025if (!Temp)
1026returncreateFileError(OutputFileName, Temp.takeError());
1027
1028raw_fd_ostream Out(Temp->FD,false);
1029
1030if (ErrorE =Write(Out)) {
1031if (Error DiscardError = Temp->discard())
1032returnjoinErrors(std::move(E), std::move(DiscardError));
1033returnE;
1034 }
1035 Out.flush();
1036
1037return Temp->keep(OutputFileName);
1038}
Success
#define Success
Definition:AArch64Disassembler.cpp:220
AutoConvert.h
true
basic Basic Alias true
Definition:BasicAliasAnalysis.cpp:1981
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Compiler.h
LLVM_UNLIKELY
#define LLVM_UNLIKELY(EXPR)
Definition:Compiler.h:320
ConvertUTF.h
Access
DXIL Resource Access
Definition:DXILResourceAccess.cpp:296
Idx
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Definition:DeadArgumentElimination.cpp:353
Duration.h
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
FileSystem.h
FormatVariadic.h
Format.h
I
#define I(x, y, z)
Definition:MD5.cpp:58
MathExtras.h
NativeFormatting.h
P
#define P(N)
Process.h
Provides a library for accessing information about this process and other processes on the operating ...
Program.h
Mode
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
Signals.h
StringExtras.h
This file contains some functions that are useful when dealing with strings.
Ptr
@ Ptr
Definition:TargetLibraryInfo.cpp:77
UUID
std::pair< llvm::MachO::Target, std::string > UUID
Definition:TextStubCommon.h:24
WindowsSupport.h
char
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition:ArrayRef.h:163
llvm::Duration
Definition:Duration.h:20
llvm::Duration::getDuration
std::chrono::milliseconds getDuration() const
Definition:Duration.h:24
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition:Error.h:608
llvm::FormattedBytes
Definition:Format.h:216
llvm::FormattedNumber
This is a helper class used for format_hex() and format_decimal().
Definition:Format.h:165
llvm::FormattedString
This is a helper class for left_justify, right_justify, and center_justify.
Definition:Format.h:130
llvm::FormattedString::JustifyLeft
@ JustifyLeft
Definition:Format.h:132
llvm::FormattedString::JustifyCenter
@ JustifyCenter
Definition:Format.h:132
llvm::FormattedString::JustifyRight
@ JustifyRight
Definition:Format.h:132
llvm::FormattedString::JustifyNone
@ JustifyNone
Definition:Format.h:132
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition:SmallString.h:26
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::format_object_base
This is a helper class used for handling formatted output.
Definition:Format.h:39
llvm::format_object_base::home
virtual void home()
Definition:raw_ostream.cpp:558
llvm::format_object_base::print
unsigned print(char *Buffer, unsigned BufferSize) const
Format the object into the specified buffer.
Definition:Format.h:55
llvm::formatv_object_base
Definition:FormatVariadic.h:65
llvm::formatv_object_base::format
void format(raw_ostream &S) const
Definition:FormatVariadic.h:80
llvm::raw_fd_ostream
A raw_ostream that writes to a file descriptor.
Definition:raw_ostream.h:460
llvm::raw_fd_ostream::is_displayed
bool is_displayed() const override
This function determines if this stream is connected to a "tty" or "console" window.
Definition:raw_ostream.cpp:864
llvm::raw_fd_ostream::has_error
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
Definition:raw_ostream.h:562
llvm::raw_fd_ostream::error
std::error_code error() const
Definition:raw_ostream.h:556
llvm::raw_fd_ostream::close
void close()
Manually flush the stream and close the file.
Definition:raw_ostream.cpp:804
llvm::raw_fd_ostream::inc_pos
void inc_pos(uint64_t Delta)
Definition:raw_ostream.h:503
llvm::raw_fd_ostream::lock
Expected< sys::fs::FileLocker > lock()
Locks the underlying file.
Definition:raw_ostream.cpp:874
llvm::raw_fd_ostream::~raw_fd_ostream
~raw_fd_ostream() override
Definition:raw_ostream.cpp:659
llvm::raw_fd_ostream::has_colors
bool has_colors() const override
This function determines if this stream is displayed and supports colors.
Definition:raw_ostream.cpp:868
llvm::raw_fd_ostream::isRegularFile
bool isRegularFile() const
Definition:raw_ostream.h:539
llvm::raw_fd_ostream::seek
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
Definition:raw_ostream.cpp:813
llvm::raw_fd_ostream::get_fd
int get_fd() const
Return the file descriptor.
Definition:raw_ostream.h:500
llvm::raw_fd_ostream::tryLockFor
Expected< sys::fs::FileLocker > tryLockFor(Duration const &Timeout)
Tries to lock the underlying file within the specified period.
Definition:raw_ostream.cpp:882
llvm::raw_fd_ostream::raw_fd_ostream
raw_fd_ostream(StringRef Filename, std::error_code &EC)
Open the specified file for writing.
Definition:raw_ostream.cpp:591
llvm::raw_fd_ostream::error_detected
void error_detected(std::error_code EC)
Set the flag indicating that an output error has been encountered.
Definition:raw_ostream.h:497
llvm::raw_fd_stream::classof
static bool classof(const raw_ostream *OS)
Check if OS is a pointer of type raw_fd_stream*.
Definition:raw_ostream.cpp:952
llvm::raw_fd_stream::raw_fd_stream
raw_fd_stream(StringRef Filename, std::error_code &EC)
Open the specified file for reading/writing/seeking.
Definition:raw_ostream.cpp:927
llvm::raw_fd_stream::read
ssize_t read(char *Ptr, size_t Size)
This reads the Size bytes into a buffer pointed by Ptr.
Definition:raw_ostream.cpp:942
llvm::raw_null_ostream
A raw_ostream that discards all output.
Definition:raw_ostream.h:731
llvm::raw_null_ostream::~raw_null_ostream
~raw_null_ostream() override
Definition:raw_ostream.cpp:987
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
llvm::raw_ostream::YELLOW
static constexpr Colors YELLOW
Definition:raw_ostream.h:117
llvm::raw_ostream::write_zeros
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
Definition:raw_ostream.cpp:500
llvm::raw_ostream::tell
uint64_t tell() const
tell - Return the current offset with the file.
Definition:raw_ostream.h:147
llvm::raw_ostream::SetBufferSize
void SetBufferSize(size_t Size)
Set the stream to be buffered, using the specified buffer size.
Definition:raw_ostream.h:167
llvm::raw_ostream::CYAN
static constexpr Colors CYAN
Definition:raw_ostream.h:120
llvm::raw_ostream::Colors
Colors
Definition:raw_ostream.h:93
llvm::raw_ostream::Colors::RESET
@ RESET
llvm::raw_ostream::changeColor
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.
Definition:raw_ostream.cpp:520
llvm::raw_ostream::write_hex
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
Definition:raw_ostream.cpp:145
llvm::raw_ostream::resetColor
virtual raw_ostream & resetColor()
Resets the colors to terminal defaults.
Definition:raw_ostream.cpp:533
llvm::raw_ostream::write_uuid
raw_ostream & write_uuid(const uuid_t UUID)
Definition:raw_ostream.cpp:158
llvm::raw_ostream::operator<<
raw_ostream & operator<<(char C)
Definition:raw_ostream.h:203
llvm::raw_ostream::flush
void flush()
Definition:raw_ostream.h:198
llvm::raw_ostream::~raw_ostream
virtual ~raw_ostream()
Definition:raw_ostream.cpp:75
llvm::raw_ostream::write_escaped
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
Definition:raw_ostream.cpp:168
llvm::raw_ostream::reverseColor
virtual raw_ostream & reverseColor()
Reverses the foreground and background colors.
Definition:raw_ostream.cpp:542
llvm::raw_ostream::BLUE
static constexpr Colors BLUE
Definition:raw_ostream.h:118
llvm::raw_ostream::preferred_buffer_size
virtual size_t preferred_buffer_size() const
Return an efficient buffer size for the underlying output mechanism.
Definition:raw_ostream.cpp:85
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition:raw_ostream.cpp:225
llvm::raw_ostream::SetUnbuffered
void SetUnbuffered()
Set the stream to be unbuffered.
Definition:raw_ostream.h:185
llvm::raw_ostream::is_displayed
virtual bool is_displayed() const
This function determines if this stream is connected to a "tty" or "console" window.
Definition:raw_ostream.h:347
llvm::raw_ostream::indent
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
Definition:raw_ostream.cpp:495
llvm::raw_ostream::RESET
static constexpr Colors RESET
Definition:raw_ostream.h:131
llvm::raw_ostream::uuid_t
uint8_t[16] uuid_t
Output a formatted UUID with dash separators.
Definition:raw_ostream.h:296
llvm::raw_ostream::MAGENTA
static constexpr Colors MAGENTA
Definition:raw_ostream.h:119
llvm::raw_ostream::enable_colors
virtual void enable_colors(bool enable)
Definition:raw_ostream.h:355
llvm::raw_ostream::SAVEDCOLOR
static constexpr Colors SAVEDCOLOR
Definition:raw_ostream.h:130
llvm::raw_ostream::GetNumBytesInBuffer
size_t GetNumBytesInBuffer() const
Definition:raw_ostream.h:190
llvm::raw_ostream::BLACK
static constexpr Colors BLACK
Definition:raw_ostream.h:114
llvm::raw_ostream::OStreamKind
OStreamKind
Definition:raw_ostream.h:55
llvm::raw_ostream::OStreamKind::OK_SVecStream
@ OK_SVecStream
llvm::raw_ostream::OStreamKind::OK_FDStream
@ OK_FDStream
llvm::raw_ostream::GREEN
static constexpr Colors GREEN
Definition:raw_ostream.h:116
llvm::raw_ostream::RED
static constexpr Colors RED
Definition:raw_ostream.h:115
llvm::raw_ostream::get_kind
OStreamKind get_kind() const
Definition:raw_ostream.h:149
llvm::raw_ostream::SetBuffered
void SetBuffered()
Set the stream to be buffered, with an automatically determined buffer size.
Definition:raw_ostream.cpp:97
llvm::raw_ostream::WHITE
static constexpr Colors WHITE
Definition:raw_ostream.h:121
llvm::raw_pwrite_stream
An abstract base class for streams implementations that also support a pwrite operation.
Definition:raw_ostream.h:434
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition:raw_ostream.h:691
llvm::raw_svector_ostream::classof
static bool classof(const raw_ostream *OS)
Definition:raw_ostream.cpp:979
llvm::sys::Process::SafelyCloseFileDescriptor
static std::error_code SafelyCloseFileDescriptor(int FD)
llvm::sys::Process::OutputColor
static const char * OutputColor(char c, bool bold, bool bg)
This function returns the colorcode escape sequences.
llvm::sys::Process::FileDescriptorIsDisplayed
static bool FileDescriptorIsDisplayed(int fd)
This function determines if the given file descriptor is connected to a "tty" or "console" window.
llvm::sys::Process::OutputBold
static const char * OutputBold(bool bg)
Same as OutputColor, but only enables the bold attribute.
llvm::sys::Process::FileDescriptorHasColors
static bool FileDescriptorHasColors(int fd)
This function determines if the given file descriptor is displayd and supports colors.
llvm::sys::Process::OutputReverse
static const char * OutputReverse()
This function returns the escape sequence to reverse forground and background colors.
llvm::sys::Process::ResetColor
static const char * ResetColor()
Resets the terminals colors, or returns an escape sequence to do so.
llvm::sys::Process::ColorNeedsFlush
static bool ColorNeedsFlush()
Whether changing colors requires the output to be flushed.
llvm::sys::fs::FileLocker
RAII class that facilitates file locking.
Definition:FileSystem.h:1219
llvm::sys::fs::TempFile::create
static Expected< TempFile > create(const Twine &Model, unsigned Mode=all_read|all_write, OpenFlags ExtraFlags=OF_None)
This creates a temporary file with createUniqueFile and schedules it for deletion with sys::RemoveFil...
Definition:Path.cpp:1325
llvm::sys::fs::file_status
Represents the result of a call to sys::fs::status().
Definition:FileSystem.h:221
uint64_t
uint8_t
ErrorHandling.h
false
Definition:StackSlotColoring.cpp:193
llvm::AMDGPU::SDWA::DWORD
@ DWORD
Definition:SIDefines.h:910
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::sys::fs::openFileForReadWrite
std::error_code openFileForReadWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
Definition:FileSystem.h:1099
llvm::sys::fs::tryLockFile
std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))
Try to locks the file during the specified time.
llvm::sys::fs::FileAccess
FileAccess
Definition:FileSystem.h:744
llvm::sys::fs::FA_Read
@ FA_Read
Definition:FileSystem.h:745
llvm::sys::fs::FA_Write
@ FA_Write
Definition:FileSystem.h:746
llvm::sys::fs::OpenFlags
OpenFlags
Definition:FileSystem.h:749
llvm::sys::fs::OF_None
@ OF_None
Definition:FileSystem.h:750
llvm::sys::fs::file_type::regular_file
@ regular_file
llvm::sys::fs::lockFile
std::error_code lockFile(int FD)
Lock the file.
llvm::sys::fs::CreationDisposition
CreationDisposition
Definition:FileSystem.h:722
llvm::sys::fs::openFileForWrite
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
Definition:FileSystem.h:1058
llvm::sys::fs::all_write
@ all_write
Definition:FileSystem.h:96
llvm::sys::fs::all_read
@ all_read
Definition:FileSystem.h:95
llvm::sys::ChangeStdoutMode
std::error_code ChangeStdoutMode(fs::OpenFlags Flags)
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::Length
@ Length
Definition:DWP.cpp:480
llvm::createFileError
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition:Error.h:1385
llvm::Write
@ Write
Definition:CodeGenData.h:108
llvm::Log2_64_Ceil
unsigned Log2_64_Ceil(uint64_t Value)
Return the ceil log base 2 of the specified value, 64 if the value is zero.
Definition:MathExtras.h:360
llvm::outs
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
Definition:raw_ostream.cpp:895
llvm::FloatStyle::Exponent
@ Exponent
llvm::RunningWindows8OrGreater
bool RunningWindows8OrGreater()
Determines if the program is running on Windows 8 or newer.
llvm::write_integer
void write_integer(raw_ostream &S, unsigned int N, size_t MinDigits, IntegerStyle Style)
Definition:NativeFormatting.cpp:104
llvm::HexPrintStyle
HexPrintStyle
Definition:NativeFormatting.h:22
llvm::HexPrintStyle::Upper
@ Upper
llvm::HexPrintStyle::PrefixUpper
@ PrefixUpper
llvm::HexPrintStyle::Lower
@ Lower
llvm::HexPrintStyle::PrefixLower
@ PrefixLower
llvm::joinErrors
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition:Error.h:438
llvm::write
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
Definition:DWP.cpp:625
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::writeToOutput
Error writeToOutput(StringRef OutputFileName, std::function< Error(raw_ostream &)> Write)
This helper creates an output stream and then passes it to Write.
Definition:raw_ostream.cpp:1012
llvm::nulls
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
Definition:raw_ostream.cpp:918
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition:Format.h:125
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition:raw_ostream.cpp:907
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition:Alignment.h:155
llvm::write_hex
void write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, std::optional< size_t > Width=std::nullopt)
Definition:NativeFormatting.cpp:134
llvm::write_double
void write_double(raw_ostream &S, double D, FloatStyle Style, std::optional< size_t > Precision=std::nullopt)
Definition:NativeFormatting.cpp:164
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition:Error.cpp:111
llvm::errnoAsErrorCode
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.
Definition:Error.h:1226
llvm::Data
@ Data
Definition:SIMachineScheduler.h:55
llvm::IntegerStyle::Integer
@ Integer
getFD
static int getFD(StringRef Filename, std::error_code &EC, sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access, sys::fs::OpenFlags Flags)
Definition:raw_ostream.cpp:565
write_padding
static raw_ostream & write_padding(raw_ostream &OS, unsigned NumChars)
Definition:raw_ostream.cpp:475
raw_ostream.h
N
#define N
Status
Definition:SIModeRegister.cpp:29
llvm::indent
Definition:raw_ostream.h:781

Generated on Thu Jul 17 2025 13:50:27 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp