blob: c6d609bfc74256294930952dc262caaf01313dd6 [file] [log] [blame]
Chris Lattner60d39622008-08-17 01:35:29 +00001//===--- raw_ostream.cpp - Implement the raw_ostream classes --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This implements support for bulk buffered stream output.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Support/raw_ostream.h"
Chris Lattner42f77ab2008-08-23 20:34:06 +000015#include "llvm/Support/Format.h"
Daniel Dunbar0d9eb9b2008-11-13 05:01:07 +000016#include "llvm/System/Program.h"
Torok Edwine8ebb0f2009-06-04 07:09:50 +000017#include "llvm/System/Process.h"
Chris Lattner097af7f2008-08-23 19:23:10 +000018#include "llvm/ADT/SmallVector.h"
Chris Lattner969a46a2008-08-22 15:45:00 +000019#include "llvm/Config/config.h"
Daniel Dunbarb372c112009-03-17 21:15:18 +000020#include "llvm/Support/Compiler.h"
Daniel Dunbar579fb872009-07-15 08:11:46 +000021#include "llvm/Support/ErrorHandling.h"
Chris Lattner07f51f72008-08-17 04:13:37 +000022#include <ostream>
Dan Gohman208ec0f2009-08-13 17:27:29 +000023#include <sys/stat.h>
24#include <sys/types.h>
Chris Lattner60d39622008-08-17 01:35:29 +000025
Chris Lattner969a46a2008-08-22 15:45:00 +000026#if defined(HAVE_UNISTD_H)
27# include <unistd.h>
28#endif
29#if defined(HAVE_FCNTL_H)
30# include <fcntl.h>
31#endif
Argyrios Kyrtzidisb68dc362008-08-17 09:25:21 +000032
33#if defined(_MSC_VER)
Chris Lattner60d39622008-08-17 01:35:29 +000034#include <io.h>
Cedric Veneta3f343f2008-08-24 11:56:40 +000035#include <fcntl.h>
Owen Andersoncb371882008-08-21 00:14:44 +000036#ifndef STDIN_FILENO
37# define STDIN_FILENO 0
38#endif
39#ifndef STDOUT_FILENO
40# define STDOUT_FILENO 1
41#endif
42#ifndef STDERR_FILENO
43# define STDERR_FILENO 2
44#endif
Chris Lattner60d39622008-08-17 01:35:29 +000045#endif
46
Chris Lattner969a46a2008-08-22 15:45:00 +000047using namespace llvm;
48
Dan Gohmane87b2ab2009-07-15 23:25:33 +000049raw_ostream::~raw_ostream() {
Dan Gohman9a312542009-07-27 20:49:44 +000050 // raw_ostream's subclasses should take care to flush the buffer
51 // in their destructors.
52 assert(OutBufCur == OutBufStart &&
53 "raw_ostream destructor called with non-empty buffer!");
54
Dan Gohmane87b2ab2009-07-15 23:25:33 +000055 delete [] OutBufStart;
56
57 // If there are any pending errors, report them now. Clients wishing
58 // to avoid llvm_report_error calls should check for errors with
59 // has_error() and clear the error flag with clear_error() before
60 // destructing raw_ostream objects which may have errors.
61 if (Error)
62 llvm_report_error("IO failure on output stream.");
63}
Chris Lattner969a46a2008-08-22 15:45:00 +000064
Chris Lattner60d39622008-08-17 01:35:29 +000065// An out of line virtual method to provide a home for the class vtable.
66void raw_ostream::handle() {}
67
Dan Gohman208ec0f2009-08-13 17:27:29 +000068size_t raw_ostream::preferred_buffer_size() {
69 // BUFSIZ is intended to be a reasonable default.
70 return BUFSIZ;
71}
72
73void raw_ostream::SetBuffered() {
74 // Ask the subclass to determine an appropriate buffer size.
75 SetBufferSize(preferred_buffer_size());
76}
77
Dan Gohman524dea42009-08-13 15:58:55 +000078void raw_ostream::SetBufferSize(size_t Size) {
79 assert(Size >= 64 &&
80 "Buffer size must be somewhat large for invariants to hold");
81 flush();
82
83 delete [] OutBufStart;
84 OutBufStart = new char[Size];
85 OutBufEnd = OutBufStart+Size;
86 OutBufCur = OutBufStart;
87 Unbuffered = false;
88}
89
90void raw_ostream::SetUnbuffered() {
91 flush();
92
93 delete [] OutBufStart;
94 OutBufStart = OutBufEnd = OutBufCur = 0;
95 Unbuffered = true;
96}
97
Owen Anderson66b17ba2008-08-21 20:58:52 +000098raw_ostream &raw_ostream::operator<<(unsigned long N) {
99 // Zero is a special case.
100 if (N == 0)
101 return *this << '0';
102
103 char NumberBuffer[20];
104 char *EndPtr = NumberBuffer+sizeof(NumberBuffer);
105 char *CurPtr = EndPtr;
106
107 while (N) {
108 *--CurPtr = '0' + char(N % 10);
109 N /= 10;
110 }
111 return write(CurPtr, EndPtr-CurPtr);
112}
113
114raw_ostream &raw_ostream::operator<<(long N) {
115 if (N < 0) {
Daniel Dunbarde75d7f2009-03-16 22:00:17 +0000116 *this << '-';
Owen Anderson66b17ba2008-08-21 20:58:52 +0000117 N = -N;
118 }
119
120 return this->operator<<(static_cast<unsigned long>(N));
121}
122
123raw_ostream &raw_ostream::operator<<(unsigned long long N) {
Daniel Dunbar78a3dd82009-07-29 06:45:14 +0000124 // Output using 32-bit div/mod when possible.
125 if (N == static_cast<unsigned long>(N))
126 return this->operator<<(static_cast<unsigned long>(N));
127
Owen Anderson66b17ba2008-08-21 20:58:52 +0000128 char NumberBuffer[20];
129 char *EndPtr = NumberBuffer+sizeof(NumberBuffer);
130 char *CurPtr = EndPtr;
131
132 while (N) {
133 *--CurPtr = '0' + char(N % 10);
134 N /= 10;
135 }
136 return write(CurPtr, EndPtr-CurPtr);
137}
138
139raw_ostream &raw_ostream::operator<<(long long N) {
140 if (N < 0) {
Daniel Dunbarde75d7f2009-03-16 22:00:17 +0000141 *this << '-';
Owen Anderson66b17ba2008-08-21 20:58:52 +0000142 N = -N;
143 }
144
145 return this->operator<<(static_cast<unsigned long long>(N));
146}
147
Daniel Dunbar48018e02009-07-30 18:21:23 +0000148raw_ostream &raw_ostream::write_hex(unsigned long long N) {
Daniel Dunbarb451a0c2009-03-16 22:08:44 +0000149 // Zero is a special case.
150 if (N == 0)
151 return *this << '0';
152
153 char NumberBuffer[20];
154 char *EndPtr = NumberBuffer+sizeof(NumberBuffer);
155 char *CurPtr = EndPtr;
156
157 while (N) {
Dan Gohmanad60f662009-07-16 15:24:40 +0000158 uintptr_t x = N % 16;
Daniel Dunbarb451a0c2009-03-16 22:08:44 +0000159 *--CurPtr = (x < 10 ? '0' + x : 'a' + x - 10);
160 N /= 16;
161 }
162
163 return write(CurPtr, EndPtr-CurPtr);
Chris Lattner944fac72008-08-23 22:23:09 +0000164}
165
Daniel Dunbar48018e02009-07-30 18:21:23 +0000166raw_ostream &raw_ostream::operator<<(const void *P) {
167 *this << '0' << 'x';
168
169 return write_hex((uintptr_t) P);
170}
171
Daniel Dunbarcf2a2c62009-03-16 22:55:06 +0000172void raw_ostream::flush_nonempty() {
173 assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty.");
Daniel Dunbar89a66a92009-03-16 23:29:31 +0000174 write_impl(OutBufStart, OutBufCur - OutBufStart);
Daniel Dunbarcf2a2c62009-03-16 22:55:06 +0000175 OutBufCur = OutBufStart;
176}
177
Daniel Dunbarde75d7f2009-03-16 22:00:17 +0000178raw_ostream &raw_ostream::write(unsigned char C) {
Daniel Dunbar262541b2009-03-17 01:36:56 +0000179 // Group exceptional cases into a single branch.
180 if (OutBufCur >= OutBufEnd) {
181 if (Unbuffered) {
182 write_impl(reinterpret_cast<char*>(&C), 1);
183 return *this;
184 }
185
186 if (!OutBufStart)
Dan Gohman208ec0f2009-08-13 17:27:29 +0000187 SetBuffered();
Daniel Dunbar262541b2009-03-17 01:36:56 +0000188 else
189 flush_nonempty();
Daniel Dunbard17d74b2009-03-17 01:13:35 +0000190 }
191
Daniel Dunbarde75d7f2009-03-16 22:00:17 +0000192 *OutBufCur++ = C;
Daniel Dunbarb451a0c2009-03-16 22:08:44 +0000193 return *this;
Daniel Dunbarde75d7f2009-03-16 22:00:17 +0000194}
Chris Lattner944fac72008-08-23 22:23:09 +0000195
Dan Gohmanad60f662009-07-16 15:24:40 +0000196raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) {
Daniel Dunbar262541b2009-03-17 01:36:56 +0000197 // Group exceptional cases into a single branch.
Daniel Dunbarb372c112009-03-17 21:15:18 +0000198 if (BUILTIN_EXPECT(OutBufCur+Size > OutBufEnd, false)) {
Dan Gohman33e49ef2009-08-13 15:44:52 +0000199 if (BUILTIN_EXPECT(!OutBufStart, false)) {
200 if (Unbuffered) {
201 write_impl(Ptr, Size);
202 return *this;
203 }
204 // Set up a buffer and start over.
Dan Gohman208ec0f2009-08-13 17:27:29 +0000205 SetBuffered();
Dan Gohman33e49ef2009-08-13 15:44:52 +0000206 return write(Ptr, Size);
207 }
208 // Write out the data in buffer-sized blocks until the remainder
209 // fits within the buffer.
210 do {
211 size_t NumBytes = OutBufEnd - OutBufCur;
212 copy_to_buffer(Ptr, NumBytes);
Daniel Dunbar262541b2009-03-17 01:36:56 +0000213 flush_nonempty();
Dan Gohman33e49ef2009-08-13 15:44:52 +0000214 Ptr += NumBytes;
215 Size -= NumBytes;
216 } while (OutBufCur+Size > OutBufEnd);
Daniel Dunbar262541b2009-03-17 01:36:56 +0000217 }
Dan Gohman33e49ef2009-08-13 15:44:52 +0000218
219 copy_to_buffer(Ptr, Size);
220
221 return *this;
222}
223
224void raw_ostream::copy_to_buffer(const char *Ptr, size_t Size) {
Owen Anderson66b17ba2008-08-21 20:58:52 +0000225 // Handle short strings specially, memcpy isn't very good at very short
226 // strings.
227 switch (Size) {
228 case 4: OutBufCur[3] = Ptr[3]; // FALL THROUGH
229 case 3: OutBufCur[2] = Ptr[2]; // FALL THROUGH
230 case 2: OutBufCur[1] = Ptr[1]; // FALL THROUGH
231 case 1: OutBufCur[0] = Ptr[0]; // FALL THROUGH
232 case 0: break;
233 default:
Dan Gohman33e49ef2009-08-13 15:44:52 +0000234 memcpy(OutBufCur, Ptr, Size);
Owen Anderson66b17ba2008-08-21 20:58:52 +0000235 break;
236 }
Daniel Dunbare77e4342009-03-10 16:21:55 +0000237
Dan Gohman33e49ef2009-08-13 15:44:52 +0000238 OutBufCur += Size;
Owen Anderson66b17ba2008-08-21 20:58:52 +0000239}
240
Chris Lattner097af7f2008-08-23 19:23:10 +0000241// Formatted output.
242raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) {
Daniel Dunbar262541b2009-03-17 01:36:56 +0000243 // If we have more than a few bytes left in our output buffer, try
244 // formatting directly onto its end.
245 //
246 // FIXME: This test is a bit silly, since if we don't have enough
247 // space in the buffer we will have to flush the formatted output
248 // anyway. We should just flush upfront in such cases, and use the
249 // whole buffer as our scratch pad. Note, however, that this case is
250 // also necessary for correctness on unbuffered streams.
Dan Gohmanad60f662009-07-16 15:24:40 +0000251 size_t NextBufferSize = 127;
Chris Lattner097af7f2008-08-23 19:23:10 +0000252 if (OutBufEnd-OutBufCur > 3) {
Dan Gohmanad60f662009-07-16 15:24:40 +0000253 size_t BufferBytesLeft = OutBufEnd-OutBufCur;
254 size_t BytesUsed = Fmt.print(OutBufCur, BufferBytesLeft);
Chris Lattner097af7f2008-08-23 19:23:10 +0000255
256 // Common case is that we have plenty of space.
257 if (BytesUsed < BufferBytesLeft) {
258 OutBufCur += BytesUsed;
259 return *this;
260 }
261
262 // Otherwise, we overflowed and the return value tells us the size to try
263 // again with.
264 NextBufferSize = BytesUsed;
265 }
266
267 // If we got here, we didn't have enough space in the output buffer for the
268 // string. Try printing into a SmallVector that is resized to have enough
269 // space. Iterate until we win.
270 SmallVector<char, 128> V;
271
272 while (1) {
273 V.resize(NextBufferSize);
274
275 // Try formatting into the SmallVector.
Dan Gohmanad60f662009-07-16 15:24:40 +0000276 size_t BytesUsed = Fmt.print(&V[0], NextBufferSize);
Chris Lattner097af7f2008-08-23 19:23:10 +0000277
278 // If BytesUsed fit into the vector, we win.
Chris Lattnerf61ca1e2008-10-26 19:20:47 +0000279 if (BytesUsed <= NextBufferSize)
Chris Lattner097af7f2008-08-23 19:23:10 +0000280 return write(&V[0], BytesUsed);
281
282 // Otherwise, try again with a new size.
283 assert(BytesUsed > NextBufferSize && "Didn't grow buffer!?");
284 NextBufferSize = BytesUsed;
285 }
286}
287
288//===----------------------------------------------------------------------===//
289// Formatted Output
290//===----------------------------------------------------------------------===//
291
292// Out of line virtual method.
293void format_object_base::home() {
294}
295
Chris Lattner60d39622008-08-17 01:35:29 +0000296//===----------------------------------------------------------------------===//
297// raw_fd_ostream
298//===----------------------------------------------------------------------===//
299
Daniel Dunbar48534b32008-10-21 19:53:10 +0000300/// raw_fd_ostream - Open the specified file for writing. If an error
301/// occurs, information about the error is put into ErrorInfo, and the
302/// stream should be immediately destroyed; the string will be empty
303/// if no error occurred.
Dan Gohmana1bdced2009-07-15 17:29:42 +0000304raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force,
Ted Kremenekd75ba1c2008-12-04 22:51:11 +0000305 std::string &ErrorInfo) : pos(0) {
Daniel Dunbar48534b32008-10-21 19:53:10 +0000306 ErrorInfo.clear();
307
Chris Lattnerc52b1282008-08-17 03:53:23 +0000308 // Handle "-" as stdout.
309 if (Filename[0] == '-' && Filename[1] == 0) {
310 FD = STDOUT_FILENO;
Daniel Dunbar0d9eb9b2008-11-13 05:01:07 +0000311 // If user requested binary then put stdout into binary mode if
312 // possible.
313 if (Binary)
314 sys::Program::ChangeStdoutToBinary();
Chris Lattnerc52b1282008-08-17 03:53:23 +0000315 ShouldClose = false;
316 return;
317 }
318
Daniel Dunbar0d9eb9b2008-11-13 05:01:07 +0000319 int Flags = O_WRONLY|O_CREAT|O_TRUNC;
320#ifdef O_BINARY
321 if (Binary)
322 Flags |= O_BINARY;
323#endif
Dan Gohmana1bdced2009-07-15 17:29:42 +0000324 if (!Force)
325 Flags |= O_EXCL;
Dan Gohman9f79d3e2009-07-15 16:39:40 +0000326 FD = open(Filename, Flags, 0664);
Chris Lattner60d39622008-08-17 01:35:29 +0000327 if (FD < 0) {
328 ErrorInfo = "Error opening output file '" + std::string(Filename) + "'";
329 ShouldClose = false;
330 } else {
331 ShouldClose = true;
332 }
333}
334
335raw_fd_ostream::~raw_fd_ostream() {
Ted Kremenek43d1f022008-10-23 23:49:09 +0000336 if (FD >= 0) {
337 flush();
338 if (ShouldClose)
Dan Gohmand3a974f2009-07-15 16:43:01 +0000339 if (::close(FD) != 0)
Dan Gohmane87b2ab2009-07-15 23:25:33 +0000340 error_detected();
Ted Kremenek43d1f022008-10-23 23:49:09 +0000341 }
Chris Lattner60d39622008-08-17 01:35:29 +0000342}
343
Dan Gohmanad60f662009-07-16 15:24:40 +0000344void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
Ted Kremenek43d1f022008-10-23 23:49:09 +0000345 assert (FD >= 0 && "File already closed.");
Daniel Dunbar89a66a92009-03-16 23:29:31 +0000346 pos += Size;
Daniel Dunbar579fb872009-07-15 08:11:46 +0000347 if (::write(FD, Ptr, Size) != (ssize_t) Size)
Dan Gohmane87b2ab2009-07-15 23:25:33 +0000348 error_detected();
Chris Lattner60d39622008-08-17 01:35:29 +0000349}
350
Ted Kremenek43d1f022008-10-23 23:49:09 +0000351void raw_fd_ostream::close() {
352 assert (ShouldClose);
353 ShouldClose = false;
354 flush();
Dan Gohmand3a974f2009-07-15 16:43:01 +0000355 if (::close(FD) != 0)
Dan Gohmane87b2ab2009-07-15 23:25:33 +0000356 error_detected();
Ted Kremenek43d1f022008-10-23 23:49:09 +0000357 FD = -1;
358}
359
Ted Kremenek9c278862009-01-26 21:42:04 +0000360uint64_t raw_fd_ostream::seek(uint64_t off) {
361 flush();
Daniel Dunbar579fb872009-07-15 08:11:46 +0000362 pos = ::lseek(FD, off, SEEK_SET);
Dan Gohmand3a974f2009-07-15 16:43:01 +0000363 if (pos != off)
Dan Gohmane87b2ab2009-07-15 23:25:33 +0000364 error_detected();
Ted Kremenek9c278862009-01-26 21:42:04 +0000365 return pos;
366}
367
Dan Gohman208ec0f2009-08-13 17:27:29 +0000368size_t raw_fd_ostream::preferred_buffer_size() {
369#if !defined(_MSC_VER) // Windows reportedly doesn't have st_blksize.
370 assert(FD >= 0 && "File not yet open!");
371 struct stat statbuf;
372 if (fstat(FD, &statbuf) == 0)
373 return statbuf.st_blksize;
374 error_detected();
375#endif
376 return raw_ostream::preferred_buffer_size();
377}
378
Torok Edwine8ebb0f2009-06-04 07:09:50 +0000379raw_ostream &raw_fd_ostream::changeColor(enum Colors colors, bool bold,
380 bool bg) {
381 if (sys::Process::ColorNeedsFlush())
382 flush();
383 const char *colorcode =
384 (colors == SAVEDCOLOR) ? sys::Process::OutputBold(bg)
385 : sys::Process::OutputColor(colors, bold, bg);
386 if (colorcode) {
Dan Gohmanad60f662009-07-16 15:24:40 +0000387 size_t len = strlen(colorcode);
Torok Edwine8ebb0f2009-06-04 07:09:50 +0000388 write(colorcode, len);
389 // don't account colors towards output characters
390 pos -= len;
391 }
392 return *this;
393}
394
395raw_ostream &raw_fd_ostream::resetColor() {
396 if (sys::Process::ColorNeedsFlush())
397 flush();
398 const char *colorcode = sys::Process::ResetColor();
399 if (colorcode) {
Dan Gohmanad60f662009-07-16 15:24:40 +0000400 size_t len = strlen(colorcode);
Torok Edwine8ebb0f2009-06-04 07:09:50 +0000401 write(colorcode, len);
402 // don't account colors towards output characters
403 pos -= len;
404 }
405 return *this;
406}
407
Chris Lattner07f51f72008-08-17 04:13:37 +0000408//===----------------------------------------------------------------------===//
409// raw_stdout/err_ostream
410//===----------------------------------------------------------------------===//
Chris Lattner60d39622008-08-17 01:35:29 +0000411
412raw_stdout_ostream::raw_stdout_ostream():raw_fd_ostream(STDOUT_FILENO, false) {}
Daniel Dunbare77e4342009-03-10 16:21:55 +0000413raw_stderr_ostream::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false,
414 true) {}
Chris Lattner60d39622008-08-17 01:35:29 +0000415
416// An out of line virtual method to provide a home for the class vtable.
417void raw_stdout_ostream::handle() {}
418void raw_stderr_ostream::handle() {}
Chris Lattner07f51f72008-08-17 04:13:37 +0000419
420/// outs() - This returns a reference to a raw_ostream for standard output.
421/// Use it like: outs() << "foo" << "bar";
Owen Andersoncb371882008-08-21 00:14:44 +0000422raw_ostream &llvm::outs() {
Chris Lattner07f51f72008-08-17 04:13:37 +0000423 static raw_stdout_ostream S;
424 return S;
425}
426
427/// errs() - This returns a reference to a raw_ostream for standard error.
428/// Use it like: errs() << "foo" << "bar";
Owen Andersoncb371882008-08-21 00:14:44 +0000429raw_ostream &llvm::errs() {
Chris Lattner07f51f72008-08-17 04:13:37 +0000430 static raw_stderr_ostream S;
431 return S;
432}
433
Daniel Dunbar34ccf032009-07-16 21:17:53 +0000434/// nulls() - This returns a reference to a raw_ostream which discards output.
435raw_ostream &llvm::nulls() {
436 static raw_null_ostream S;
437 return S;
438}
439
Chris Lattner07f51f72008-08-17 04:13:37 +0000440//===----------------------------------------------------------------------===//
441// raw_os_ostream
442//===----------------------------------------------------------------------===//
443
Chris Lattner944fac72008-08-23 22:23:09 +0000444raw_os_ostream::~raw_os_ostream() {
445 flush();
446}
447
Dan Gohmanad60f662009-07-16 15:24:40 +0000448void raw_os_ostream::write_impl(const char *Ptr, size_t Size) {
Daniel Dunbar89a66a92009-03-16 23:29:31 +0000449 OS.write(Ptr, Size);
Chris Lattner07f51f72008-08-17 04:13:37 +0000450}
Chris Lattner78a28122008-08-23 22:43:04 +0000451
Douglas Gregor8f7be472009-04-20 07:34:17 +0000452uint64_t raw_os_ostream::current_pos() { return OS.tellp(); }
453
454uint64_t raw_os_ostream::tell() {
455 return (uint64_t)OS.tellp() + GetNumBytesInBuffer();
456}
457
Chris Lattner78a28122008-08-23 22:43:04 +0000458//===----------------------------------------------------------------------===//
459// raw_string_ostream
460//===----------------------------------------------------------------------===//
461
462raw_string_ostream::~raw_string_ostream() {
463 flush();
464}
465
Dan Gohmanad60f662009-07-16 15:24:40 +0000466void raw_string_ostream::write_impl(const char *Ptr, size_t Size) {
Daniel Dunbar89a66a92009-03-16 23:29:31 +0000467 OS.append(Ptr, Size);
Chris Lattner78a28122008-08-23 22:43:04 +0000468}
469
470//===----------------------------------------------------------------------===//
471// raw_svector_ostream
472//===----------------------------------------------------------------------===//
473
474raw_svector_ostream::~raw_svector_ostream() {
475 flush();
476}
477
Dan Gohmanad60f662009-07-16 15:24:40 +0000478void raw_svector_ostream::write_impl(const char *Ptr, size_t Size) {
Daniel Dunbar89a66a92009-03-16 23:29:31 +0000479 OS.append(Ptr, Ptr + Size);
Chris Lattner78a28122008-08-23 22:43:04 +0000480}
481
Douglas Gregor8f7be472009-04-20 07:34:17 +0000482uint64_t raw_svector_ostream::current_pos() { return OS.size(); }
483
484uint64_t raw_svector_ostream::tell() {
485 return OS.size() + GetNumBytesInBuffer();
486}
Daniel Dunbar34ccf032009-07-16 21:17:53 +0000487
488//===----------------------------------------------------------------------===//
489// raw_null_ostream
490//===----------------------------------------------------------------------===//
491
Dan Gohmanf78c8352009-07-27 21:46:02 +0000492raw_null_ostream::~raw_null_ostream() {
493#ifndef NDEBUG
494 // ~raw_ostream asserts that the buffer is empty. This isn't necessary
495 // with raw_null_ostream, but it's better to have raw_null_ostream follow
496 // the rules than to change the rules just for raw_null_ostream.
497 flush();
498#endif
499}
500
Daniel Dunbar34ccf032009-07-16 21:17:53 +0000501void raw_null_ostream::write_impl(const char *Ptr, size_t Size) {
502}
503
504uint64_t raw_null_ostream::current_pos() {
505 return 0;
506}