blob: f0090d8d93f932bb2e84885980ff87da924ff6f6 [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) {
Dan Gohmanc6126e82009-08-13 20:32:03 +0000225 assert(Size <= size_t(OutBufEnd - OutBufCur) && "Buffer overrun!");
Dan Gohman4e8e6422009-08-13 18:38:15 +0000226
Owen Anderson66b17ba2008-08-21 20:58:52 +0000227 // Handle short strings specially, memcpy isn't very good at very short
228 // strings.
229 switch (Size) {
230 case 4: OutBufCur[3] = Ptr[3]; // FALL THROUGH
231 case 3: OutBufCur[2] = Ptr[2]; // FALL THROUGH
232 case 2: OutBufCur[1] = Ptr[1]; // FALL THROUGH
233 case 1: OutBufCur[0] = Ptr[0]; // FALL THROUGH
234 case 0: break;
235 default:
Dan Gohman33e49ef2009-08-13 15:44:52 +0000236 memcpy(OutBufCur, Ptr, Size);
Owen Anderson66b17ba2008-08-21 20:58:52 +0000237 break;
238 }
Daniel Dunbare77e4342009-03-10 16:21:55 +0000239
Dan Gohman33e49ef2009-08-13 15:44:52 +0000240 OutBufCur += Size;
Owen Anderson66b17ba2008-08-21 20:58:52 +0000241}
242
Chris Lattner097af7f2008-08-23 19:23:10 +0000243// Formatted output.
244raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) {
Daniel Dunbar262541b2009-03-17 01:36:56 +0000245 // If we have more than a few bytes left in our output buffer, try
246 // formatting directly onto its end.
247 //
248 // FIXME: This test is a bit silly, since if we don't have enough
249 // space in the buffer we will have to flush the formatted output
250 // anyway. We should just flush upfront in such cases, and use the
251 // whole buffer as our scratch pad. Note, however, that this case is
252 // also necessary for correctness on unbuffered streams.
Dan Gohmanad60f662009-07-16 15:24:40 +0000253 size_t NextBufferSize = 127;
Chris Lattner097af7f2008-08-23 19:23:10 +0000254 if (OutBufEnd-OutBufCur > 3) {
Dan Gohmanad60f662009-07-16 15:24:40 +0000255 size_t BufferBytesLeft = OutBufEnd-OutBufCur;
256 size_t BytesUsed = Fmt.print(OutBufCur, BufferBytesLeft);
Chris Lattner097af7f2008-08-23 19:23:10 +0000257
258 // Common case is that we have plenty of space.
259 if (BytesUsed < BufferBytesLeft) {
260 OutBufCur += BytesUsed;
261 return *this;
262 }
263
264 // Otherwise, we overflowed and the return value tells us the size to try
265 // again with.
266 NextBufferSize = BytesUsed;
267 }
268
269 // If we got here, we didn't have enough space in the output buffer for the
270 // string. Try printing into a SmallVector that is resized to have enough
271 // space. Iterate until we win.
272 SmallVector<char, 128> V;
273
274 while (1) {
275 V.resize(NextBufferSize);
276
277 // Try formatting into the SmallVector.
Dan Gohmanad60f662009-07-16 15:24:40 +0000278 size_t BytesUsed = Fmt.print(&V[0], NextBufferSize);
Chris Lattner097af7f2008-08-23 19:23:10 +0000279
280 // If BytesUsed fit into the vector, we win.
Chris Lattnerf61ca1e2008-10-26 19:20:47 +0000281 if (BytesUsed <= NextBufferSize)
Chris Lattner097af7f2008-08-23 19:23:10 +0000282 return write(&V[0], BytesUsed);
283
284 // Otherwise, try again with a new size.
285 assert(BytesUsed > NextBufferSize && "Didn't grow buffer!?");
286 NextBufferSize = BytesUsed;
287 }
288}
289
290//===----------------------------------------------------------------------===//
291// Formatted Output
292//===----------------------------------------------------------------------===//
293
294// Out of line virtual method.
295void format_object_base::home() {
296}
297
Chris Lattner60d39622008-08-17 01:35:29 +0000298//===----------------------------------------------------------------------===//
299// raw_fd_ostream
300//===----------------------------------------------------------------------===//
301
Daniel Dunbar48534b32008-10-21 19:53:10 +0000302/// raw_fd_ostream - Open the specified file for writing. If an error
303/// occurs, information about the error is put into ErrorInfo, and the
304/// stream should be immediately destroyed; the string will be empty
305/// if no error occurred.
Dan Gohmana1bdced2009-07-15 17:29:42 +0000306raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force,
Ted Kremenekd75ba1c2008-12-04 22:51:11 +0000307 std::string &ErrorInfo) : pos(0) {
Daniel Dunbar48534b32008-10-21 19:53:10 +0000308 ErrorInfo.clear();
309
Chris Lattnerc52b1282008-08-17 03:53:23 +0000310 // Handle "-" as stdout.
311 if (Filename[0] == '-' && Filename[1] == 0) {
312 FD = STDOUT_FILENO;
Daniel Dunbar0d9eb9b2008-11-13 05:01:07 +0000313 // If user requested binary then put stdout into binary mode if
314 // possible.
315 if (Binary)
316 sys::Program::ChangeStdoutToBinary();
Chris Lattnerc52b1282008-08-17 03:53:23 +0000317 ShouldClose = false;
318 return;
319 }
320
Daniel Dunbar0d9eb9b2008-11-13 05:01:07 +0000321 int Flags = O_WRONLY|O_CREAT|O_TRUNC;
322#ifdef O_BINARY
323 if (Binary)
324 Flags |= O_BINARY;
325#endif
Dan Gohmana1bdced2009-07-15 17:29:42 +0000326 if (!Force)
327 Flags |= O_EXCL;
Dan Gohman9f79d3e2009-07-15 16:39:40 +0000328 FD = open(Filename, Flags, 0664);
Chris Lattner60d39622008-08-17 01:35:29 +0000329 if (FD < 0) {
330 ErrorInfo = "Error opening output file '" + std::string(Filename) + "'";
331 ShouldClose = false;
332 } else {
333 ShouldClose = true;
334 }
335}
336
337raw_fd_ostream::~raw_fd_ostream() {
Ted Kremenek43d1f022008-10-23 23:49:09 +0000338 if (FD >= 0) {
339 flush();
340 if (ShouldClose)
Dan Gohmand3a974f2009-07-15 16:43:01 +0000341 if (::close(FD) != 0)
Dan Gohmane87b2ab2009-07-15 23:25:33 +0000342 error_detected();
Ted Kremenek43d1f022008-10-23 23:49:09 +0000343 }
Chris Lattner60d39622008-08-17 01:35:29 +0000344}
345
Dan Gohmanad60f662009-07-16 15:24:40 +0000346void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
Ted Kremenek43d1f022008-10-23 23:49:09 +0000347 assert (FD >= 0 && "File already closed.");
Daniel Dunbar89a66a92009-03-16 23:29:31 +0000348 pos += Size;
Daniel Dunbar579fb872009-07-15 08:11:46 +0000349 if (::write(FD, Ptr, Size) != (ssize_t) Size)
Dan Gohmane87b2ab2009-07-15 23:25:33 +0000350 error_detected();
Chris Lattner60d39622008-08-17 01:35:29 +0000351}
352
Ted Kremenek43d1f022008-10-23 23:49:09 +0000353void raw_fd_ostream::close() {
354 assert (ShouldClose);
355 ShouldClose = false;
356 flush();
Dan Gohmand3a974f2009-07-15 16:43:01 +0000357 if (::close(FD) != 0)
Dan Gohmane87b2ab2009-07-15 23:25:33 +0000358 error_detected();
Ted Kremenek43d1f022008-10-23 23:49:09 +0000359 FD = -1;
360}
361
Ted Kremenek9c278862009-01-26 21:42:04 +0000362uint64_t raw_fd_ostream::seek(uint64_t off) {
363 flush();
Daniel Dunbar579fb872009-07-15 08:11:46 +0000364 pos = ::lseek(FD, off, SEEK_SET);
Dan Gohmand3a974f2009-07-15 16:43:01 +0000365 if (pos != off)
Dan Gohmane87b2ab2009-07-15 23:25:33 +0000366 error_detected();
Ted Kremenek9c278862009-01-26 21:42:04 +0000367 return pos;
368}
369
Dan Gohman208ec0f2009-08-13 17:27:29 +0000370size_t raw_fd_ostream::preferred_buffer_size() {
371#if !defined(_MSC_VER) // Windows reportedly doesn't have st_blksize.
372 assert(FD >= 0 && "File not yet open!");
373 struct stat statbuf;
374 if (fstat(FD, &statbuf) == 0)
375 return statbuf.st_blksize;
376 error_detected();
377#endif
378 return raw_ostream::preferred_buffer_size();
379}
380
Torok Edwine8ebb0f2009-06-04 07:09:50 +0000381raw_ostream &raw_fd_ostream::changeColor(enum Colors colors, bool bold,
382 bool bg) {
383 if (sys::Process::ColorNeedsFlush())
384 flush();
385 const char *colorcode =
386 (colors == SAVEDCOLOR) ? sys::Process::OutputBold(bg)
387 : sys::Process::OutputColor(colors, bold, bg);
388 if (colorcode) {
Dan Gohmanad60f662009-07-16 15:24:40 +0000389 size_t len = strlen(colorcode);
Torok Edwine8ebb0f2009-06-04 07:09:50 +0000390 write(colorcode, len);
391 // don't account colors towards output characters
392 pos -= len;
393 }
394 return *this;
395}
396
397raw_ostream &raw_fd_ostream::resetColor() {
398 if (sys::Process::ColorNeedsFlush())
399 flush();
400 const char *colorcode = sys::Process::ResetColor();
401 if (colorcode) {
Dan Gohmanad60f662009-07-16 15:24:40 +0000402 size_t len = strlen(colorcode);
Torok Edwine8ebb0f2009-06-04 07:09:50 +0000403 write(colorcode, len);
404 // don't account colors towards output characters
405 pos -= len;
406 }
407 return *this;
408}
409
Chris Lattner07f51f72008-08-17 04:13:37 +0000410//===----------------------------------------------------------------------===//
411// raw_stdout/err_ostream
412//===----------------------------------------------------------------------===//
Chris Lattner60d39622008-08-17 01:35:29 +0000413
414raw_stdout_ostream::raw_stdout_ostream():raw_fd_ostream(STDOUT_FILENO, false) {}
Daniel Dunbare77e4342009-03-10 16:21:55 +0000415raw_stderr_ostream::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false,
416 true) {}
Chris Lattner60d39622008-08-17 01:35:29 +0000417
418// An out of line virtual method to provide a home for the class vtable.
419void raw_stdout_ostream::handle() {}
420void raw_stderr_ostream::handle() {}
Chris Lattner07f51f72008-08-17 04:13:37 +0000421
422/// outs() - This returns a reference to a raw_ostream for standard output.
423/// Use it like: outs() << "foo" << "bar";
Owen Andersoncb371882008-08-21 00:14:44 +0000424raw_ostream &llvm::outs() {
Chris Lattner07f51f72008-08-17 04:13:37 +0000425 static raw_stdout_ostream S;
426 return S;
427}
428
429/// errs() - This returns a reference to a raw_ostream for standard error.
430/// Use it like: errs() << "foo" << "bar";
Owen Andersoncb371882008-08-21 00:14:44 +0000431raw_ostream &llvm::errs() {
Chris Lattner07f51f72008-08-17 04:13:37 +0000432 static raw_stderr_ostream S;
433 return S;
434}
435
Daniel Dunbar34ccf032009-07-16 21:17:53 +0000436/// nulls() - This returns a reference to a raw_ostream which discards output.
437raw_ostream &llvm::nulls() {
438 static raw_null_ostream S;
439 return S;
440}
441
Chris Lattner07f51f72008-08-17 04:13:37 +0000442//===----------------------------------------------------------------------===//
443// raw_os_ostream
444//===----------------------------------------------------------------------===//
445
Dan Gohmanad60f662009-07-16 15:24:40 +0000446void raw_os_ostream::write_impl(const char *Ptr, size_t Size) {
Daniel Dunbar89a66a92009-03-16 23:29:31 +0000447 OS.write(Ptr, Size);
Chris Lattner07f51f72008-08-17 04:13:37 +0000448}
Chris Lattner78a28122008-08-23 22:43:04 +0000449
Douglas Gregor8f7be472009-04-20 07:34:17 +0000450uint64_t raw_os_ostream::current_pos() { return OS.tellp(); }
451
452uint64_t raw_os_ostream::tell() {
453 return (uint64_t)OS.tellp() + GetNumBytesInBuffer();
454}
455
Chris Lattner78a28122008-08-23 22:43:04 +0000456//===----------------------------------------------------------------------===//
457// raw_string_ostream
458//===----------------------------------------------------------------------===//
459
Dan Gohmanad60f662009-07-16 15:24:40 +0000460void raw_string_ostream::write_impl(const char *Ptr, size_t Size) {
Daniel Dunbar89a66a92009-03-16 23:29:31 +0000461 OS.append(Ptr, Size);
Chris Lattner78a28122008-08-23 22:43:04 +0000462}
463
464//===----------------------------------------------------------------------===//
465// raw_svector_ostream
466//===----------------------------------------------------------------------===//
467
Dan Gohmanad60f662009-07-16 15:24:40 +0000468void raw_svector_ostream::write_impl(const char *Ptr, size_t Size) {
Daniel Dunbar89a66a92009-03-16 23:29:31 +0000469 OS.append(Ptr, Ptr + Size);
Chris Lattner78a28122008-08-23 22:43:04 +0000470}
471
Douglas Gregor8f7be472009-04-20 07:34:17 +0000472uint64_t raw_svector_ostream::current_pos() { return OS.size(); }
473
474uint64_t raw_svector_ostream::tell() {
475 return OS.size() + GetNumBytesInBuffer();
476}
Daniel Dunbar34ccf032009-07-16 21:17:53 +0000477
478//===----------------------------------------------------------------------===//
479// raw_null_ostream
480//===----------------------------------------------------------------------===//
481
Dan Gohmanf78c8352009-07-27 21:46:02 +0000482raw_null_ostream::~raw_null_ostream() {
483#ifndef NDEBUG
484 // ~raw_ostream asserts that the buffer is empty. This isn't necessary
485 // with raw_null_ostream, but it's better to have raw_null_ostream follow
486 // the rules than to change the rules just for raw_null_ostream.
487 flush();
488#endif
489}
490
Daniel Dunbar34ccf032009-07-16 21:17:53 +0000491void raw_null_ostream::write_impl(const char *Ptr, size_t Size) {
492}
493
494uint64_t raw_null_ostream::current_pos() {
495 return 0;
496}