Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 1 | //===--- 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 Lattner | 42f77ab | 2008-08-23 20:34:06 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Format.h" |
Daniel Dunbar | 0d9eb9b | 2008-11-13 05:01:07 +0000 | [diff] [blame] | 16 | #include "llvm/System/Program.h" |
Chris Lattner | 097af7f | 2008-08-23 19:23:10 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | 969a46a | 2008-08-22 15:45:00 +0000 | [diff] [blame] | 18 | #include "llvm/Config/config.h" |
Daniel Dunbar | b372c11 | 2009-03-17 21:15:18 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Compiler.h" |
Chris Lattner | 07f51f7 | 2008-08-17 04:13:37 +0000 | [diff] [blame] | 20 | #include <ostream> |
Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 21 | |
Chris Lattner | 969a46a | 2008-08-22 15:45:00 +0000 | [diff] [blame] | 22 | #if defined(HAVE_UNISTD_H) |
| 23 | # include <unistd.h> |
| 24 | #endif |
| 25 | #if defined(HAVE_FCNTL_H) |
| 26 | # include <fcntl.h> |
| 27 | #endif |
Argyrios Kyrtzidis | b68dc36 | 2008-08-17 09:25:21 +0000 | [diff] [blame] | 28 | |
| 29 | #if defined(_MSC_VER) |
Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 30 | #include <io.h> |
Cedric Venet | a3f343f | 2008-08-24 11:56:40 +0000 | [diff] [blame] | 31 | #include <fcntl.h> |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 32 | #ifndef STDIN_FILENO |
| 33 | # define STDIN_FILENO 0 |
| 34 | #endif |
| 35 | #ifndef STDOUT_FILENO |
| 36 | # define STDOUT_FILENO 1 |
| 37 | #endif |
| 38 | #ifndef STDERR_FILENO |
| 39 | # define STDERR_FILENO 2 |
| 40 | #endif |
Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 41 | #endif |
| 42 | |
Chris Lattner | 969a46a | 2008-08-22 15:45:00 +0000 | [diff] [blame] | 43 | using namespace llvm; |
| 44 | |
| 45 | |
Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 46 | // An out of line virtual method to provide a home for the class vtable. |
| 47 | void raw_ostream::handle() {} |
| 48 | |
Owen Anderson | 66b17ba | 2008-08-21 20:58:52 +0000 | [diff] [blame] | 49 | raw_ostream &raw_ostream::operator<<(unsigned long N) { |
| 50 | // Zero is a special case. |
| 51 | if (N == 0) |
| 52 | return *this << '0'; |
| 53 | |
| 54 | char NumberBuffer[20]; |
| 55 | char *EndPtr = NumberBuffer+sizeof(NumberBuffer); |
| 56 | char *CurPtr = EndPtr; |
| 57 | |
| 58 | while (N) { |
| 59 | *--CurPtr = '0' + char(N % 10); |
| 60 | N /= 10; |
| 61 | } |
| 62 | return write(CurPtr, EndPtr-CurPtr); |
| 63 | } |
| 64 | |
| 65 | raw_ostream &raw_ostream::operator<<(long N) { |
| 66 | if (N < 0) { |
Daniel Dunbar | de75d7f | 2009-03-16 22:00:17 +0000 | [diff] [blame] | 67 | *this << '-'; |
Owen Anderson | 66b17ba | 2008-08-21 20:58:52 +0000 | [diff] [blame] | 68 | N = -N; |
| 69 | } |
| 70 | |
| 71 | return this->operator<<(static_cast<unsigned long>(N)); |
| 72 | } |
| 73 | |
| 74 | raw_ostream &raw_ostream::operator<<(unsigned long long N) { |
| 75 | // Zero is a special case. |
| 76 | if (N == 0) |
| 77 | return *this << '0'; |
| 78 | |
| 79 | char NumberBuffer[20]; |
| 80 | char *EndPtr = NumberBuffer+sizeof(NumberBuffer); |
| 81 | char *CurPtr = EndPtr; |
| 82 | |
| 83 | while (N) { |
| 84 | *--CurPtr = '0' + char(N % 10); |
| 85 | N /= 10; |
| 86 | } |
| 87 | return write(CurPtr, EndPtr-CurPtr); |
| 88 | } |
| 89 | |
| 90 | raw_ostream &raw_ostream::operator<<(long long N) { |
| 91 | if (N < 0) { |
Daniel Dunbar | de75d7f | 2009-03-16 22:00:17 +0000 | [diff] [blame] | 92 | *this << '-'; |
Owen Anderson | 66b17ba | 2008-08-21 20:58:52 +0000 | [diff] [blame] | 93 | N = -N; |
| 94 | } |
| 95 | |
| 96 | return this->operator<<(static_cast<unsigned long long>(N)); |
| 97 | } |
| 98 | |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 99 | raw_ostream &raw_ostream::operator<<(const void *P) { |
Daniel Dunbar | b451a0c | 2009-03-16 22:08:44 +0000 | [diff] [blame] | 100 | uintptr_t N = (uintptr_t) P; |
| 101 | *this << '0' << 'x'; |
| 102 | |
| 103 | // Zero is a special case. |
| 104 | if (N == 0) |
| 105 | return *this << '0'; |
| 106 | |
| 107 | char NumberBuffer[20]; |
| 108 | char *EndPtr = NumberBuffer+sizeof(NumberBuffer); |
| 109 | char *CurPtr = EndPtr; |
| 110 | |
| 111 | while (N) { |
| 112 | unsigned x = N % 16; |
| 113 | *--CurPtr = (x < 10 ? '0' + x : 'a' + x - 10); |
| 114 | N /= 16; |
| 115 | } |
| 116 | |
| 117 | return write(CurPtr, EndPtr-CurPtr); |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Daniel Dunbar | cf2a2c6 | 2009-03-16 22:55:06 +0000 | [diff] [blame] | 120 | void raw_ostream::flush_nonempty() { |
| 121 | assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty."); |
Daniel Dunbar | 89a66a9 | 2009-03-16 23:29:31 +0000 | [diff] [blame] | 122 | write_impl(OutBufStart, OutBufCur - OutBufStart); |
Daniel Dunbar | cf2a2c6 | 2009-03-16 22:55:06 +0000 | [diff] [blame] | 123 | OutBufCur = OutBufStart; |
| 124 | } |
| 125 | |
Daniel Dunbar | de75d7f | 2009-03-16 22:00:17 +0000 | [diff] [blame] | 126 | raw_ostream &raw_ostream::write(unsigned char C) { |
Daniel Dunbar | 262541b | 2009-03-17 01:36:56 +0000 | [diff] [blame] | 127 | // Group exceptional cases into a single branch. |
| 128 | if (OutBufCur >= OutBufEnd) { |
| 129 | if (Unbuffered) { |
| 130 | write_impl(reinterpret_cast<char*>(&C), 1); |
| 131 | return *this; |
| 132 | } |
| 133 | |
| 134 | if (!OutBufStart) |
| 135 | SetBufferSize(); |
| 136 | else |
| 137 | flush_nonempty(); |
Daniel Dunbar | d17d74b | 2009-03-17 01:13:35 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Daniel Dunbar | de75d7f | 2009-03-16 22:00:17 +0000 | [diff] [blame] | 140 | *OutBufCur++ = C; |
Daniel Dunbar | b451a0c | 2009-03-16 22:08:44 +0000 | [diff] [blame] | 141 | return *this; |
Daniel Dunbar | de75d7f | 2009-03-16 22:00:17 +0000 | [diff] [blame] | 142 | } |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 143 | |
Owen Anderson | 66b17ba | 2008-08-21 20:58:52 +0000 | [diff] [blame] | 144 | raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) { |
Daniel Dunbar | 262541b | 2009-03-17 01:36:56 +0000 | [diff] [blame] | 145 | // Group exceptional cases into a single branch. |
Daniel Dunbar | b372c11 | 2009-03-17 21:15:18 +0000 | [diff] [blame] | 146 | if (BUILTIN_EXPECT(OutBufCur+Size > OutBufEnd, false)) { |
Daniel Dunbar | 262541b | 2009-03-17 01:36:56 +0000 | [diff] [blame] | 147 | if (Unbuffered) { |
| 148 | write_impl(Ptr, Size); |
| 149 | return *this; |
| 150 | } |
Daniel Dunbar | d17d74b | 2009-03-17 01:13:35 +0000 | [diff] [blame] | 151 | |
Daniel Dunbar | 262541b | 2009-03-17 01:36:56 +0000 | [diff] [blame] | 152 | if (!OutBufStart) |
| 153 | SetBufferSize(); |
| 154 | else |
| 155 | flush_nonempty(); |
| 156 | } |
Owen Anderson | 66b17ba | 2008-08-21 20:58:52 +0000 | [diff] [blame] | 157 | |
| 158 | // Handle short strings specially, memcpy isn't very good at very short |
| 159 | // strings. |
| 160 | switch (Size) { |
| 161 | case 4: OutBufCur[3] = Ptr[3]; // FALL THROUGH |
| 162 | case 3: OutBufCur[2] = Ptr[2]; // FALL THROUGH |
| 163 | case 2: OutBufCur[1] = Ptr[1]; // FALL THROUGH |
| 164 | case 1: OutBufCur[0] = Ptr[0]; // FALL THROUGH |
| 165 | case 0: break; |
| 166 | default: |
| 167 | // Normally the string to emit is shorter than the buffer. |
| 168 | if (Size <= unsigned(OutBufEnd-OutBufStart)) { |
| 169 | memcpy(OutBufCur, Ptr, Size); |
| 170 | break; |
Daniel Dunbar | 89a66a9 | 2009-03-16 23:29:31 +0000 | [diff] [blame] | 171 | } |
Owen Anderson | 66b17ba | 2008-08-21 20:58:52 +0000 | [diff] [blame] | 172 | |
Daniel Dunbar | 89a66a9 | 2009-03-16 23:29:31 +0000 | [diff] [blame] | 173 | // Otherwise we are emitting a string larger than our buffer. We |
| 174 | // know we already flushed, so just write it out directly. |
| 175 | write_impl(Ptr, Size); |
| 176 | Size = 0; |
Owen Anderson | 66b17ba | 2008-08-21 20:58:52 +0000 | [diff] [blame] | 177 | break; |
| 178 | } |
| 179 | OutBufCur += Size; |
Daniel Dunbar | e77e434 | 2009-03-10 16:21:55 +0000 | [diff] [blame] | 180 | |
Owen Anderson | 66b17ba | 2008-08-21 20:58:52 +0000 | [diff] [blame] | 181 | return *this; |
| 182 | } |
| 183 | |
Chris Lattner | 097af7f | 2008-08-23 19:23:10 +0000 | [diff] [blame] | 184 | // Formatted output. |
| 185 | raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) { |
Daniel Dunbar | 262541b | 2009-03-17 01:36:56 +0000 | [diff] [blame] | 186 | // If we have more than a few bytes left in our output buffer, try |
| 187 | // formatting directly onto its end. |
| 188 | // |
| 189 | // FIXME: This test is a bit silly, since if we don't have enough |
| 190 | // space in the buffer we will have to flush the formatted output |
| 191 | // anyway. We should just flush upfront in such cases, and use the |
| 192 | // whole buffer as our scratch pad. Note, however, that this case is |
| 193 | // also necessary for correctness on unbuffered streams. |
Chris Lattner | 097af7f | 2008-08-23 19:23:10 +0000 | [diff] [blame] | 194 | unsigned NextBufferSize = 127; |
| 195 | if (OutBufEnd-OutBufCur > 3) { |
| 196 | unsigned BufferBytesLeft = OutBufEnd-OutBufCur; |
| 197 | unsigned BytesUsed = Fmt.print(OutBufCur, BufferBytesLeft); |
| 198 | |
| 199 | // Common case is that we have plenty of space. |
| 200 | if (BytesUsed < BufferBytesLeft) { |
| 201 | OutBufCur += BytesUsed; |
| 202 | return *this; |
| 203 | } |
| 204 | |
| 205 | // Otherwise, we overflowed and the return value tells us the size to try |
| 206 | // again with. |
| 207 | NextBufferSize = BytesUsed; |
| 208 | } |
| 209 | |
| 210 | // If we got here, we didn't have enough space in the output buffer for the |
| 211 | // string. Try printing into a SmallVector that is resized to have enough |
| 212 | // space. Iterate until we win. |
| 213 | SmallVector<char, 128> V; |
| 214 | |
| 215 | while (1) { |
| 216 | V.resize(NextBufferSize); |
| 217 | |
| 218 | // Try formatting into the SmallVector. |
| 219 | unsigned BytesUsed = Fmt.print(&V[0], NextBufferSize); |
| 220 | |
| 221 | // If BytesUsed fit into the vector, we win. |
Chris Lattner | f61ca1e | 2008-10-26 19:20:47 +0000 | [diff] [blame] | 222 | if (BytesUsed <= NextBufferSize) |
Chris Lattner | 097af7f | 2008-08-23 19:23:10 +0000 | [diff] [blame] | 223 | return write(&V[0], BytesUsed); |
| 224 | |
| 225 | // Otherwise, try again with a new size. |
| 226 | assert(BytesUsed > NextBufferSize && "Didn't grow buffer!?"); |
| 227 | NextBufferSize = BytesUsed; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | //===----------------------------------------------------------------------===// |
| 232 | // Formatted Output |
| 233 | //===----------------------------------------------------------------------===// |
| 234 | |
| 235 | // Out of line virtual method. |
| 236 | void format_object_base::home() { |
| 237 | } |
| 238 | |
Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 239 | //===----------------------------------------------------------------------===// |
| 240 | // raw_fd_ostream |
| 241 | //===----------------------------------------------------------------------===// |
| 242 | |
Daniel Dunbar | 48534b3 | 2008-10-21 19:53:10 +0000 | [diff] [blame] | 243 | /// raw_fd_ostream - Open the specified file for writing. If an error |
| 244 | /// occurs, information about the error is put into ErrorInfo, and the |
| 245 | /// stream should be immediately destroyed; the string will be empty |
| 246 | /// if no error occurred. |
Daniel Dunbar | 0d9eb9b | 2008-11-13 05:01:07 +0000 | [diff] [blame] | 247 | raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, |
Ted Kremenek | d75ba1c | 2008-12-04 22:51:11 +0000 | [diff] [blame] | 248 | std::string &ErrorInfo) : pos(0) { |
Daniel Dunbar | 48534b3 | 2008-10-21 19:53:10 +0000 | [diff] [blame] | 249 | ErrorInfo.clear(); |
| 250 | |
Chris Lattner | c52b128 | 2008-08-17 03:53:23 +0000 | [diff] [blame] | 251 | // Handle "-" as stdout. |
| 252 | if (Filename[0] == '-' && Filename[1] == 0) { |
| 253 | FD = STDOUT_FILENO; |
Daniel Dunbar | 0d9eb9b | 2008-11-13 05:01:07 +0000 | [diff] [blame] | 254 | // If user requested binary then put stdout into binary mode if |
| 255 | // possible. |
| 256 | if (Binary) |
| 257 | sys::Program::ChangeStdoutToBinary(); |
Chris Lattner | c52b128 | 2008-08-17 03:53:23 +0000 | [diff] [blame] | 258 | ShouldClose = false; |
| 259 | return; |
| 260 | } |
| 261 | |
Daniel Dunbar | 0d9eb9b | 2008-11-13 05:01:07 +0000 | [diff] [blame] | 262 | int Flags = O_WRONLY|O_CREAT|O_TRUNC; |
| 263 | #ifdef O_BINARY |
| 264 | if (Binary) |
| 265 | Flags |= O_BINARY; |
| 266 | #endif |
| 267 | FD = open(Filename, Flags, 0644); |
Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 268 | if (FD < 0) { |
| 269 | ErrorInfo = "Error opening output file '" + std::string(Filename) + "'"; |
| 270 | ShouldClose = false; |
| 271 | } else { |
| 272 | ShouldClose = true; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | raw_fd_ostream::~raw_fd_ostream() { |
Ted Kremenek | 43d1f02 | 2008-10-23 23:49:09 +0000 | [diff] [blame] | 277 | if (FD >= 0) { |
| 278 | flush(); |
| 279 | if (ShouldClose) |
| 280 | ::close(FD); |
| 281 | } |
Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Daniel Dunbar | 89a66a9 | 2009-03-16 23:29:31 +0000 | [diff] [blame] | 284 | void raw_fd_ostream::write_impl(const char *Ptr, unsigned Size) { |
Ted Kremenek | 43d1f02 | 2008-10-23 23:49:09 +0000 | [diff] [blame] | 285 | assert (FD >= 0 && "File already closed."); |
Daniel Dunbar | 89a66a9 | 2009-03-16 23:29:31 +0000 | [diff] [blame] | 286 | pos += Size; |
| 287 | ::write(FD, Ptr, Size); |
Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Ted Kremenek | 43d1f02 | 2008-10-23 23:49:09 +0000 | [diff] [blame] | 290 | void raw_fd_ostream::close() { |
| 291 | assert (ShouldClose); |
| 292 | ShouldClose = false; |
| 293 | flush(); |
| 294 | ::close(FD); |
| 295 | FD = -1; |
| 296 | } |
| 297 | |
Ted Kremenek | 9c27886 | 2009-01-26 21:42:04 +0000 | [diff] [blame] | 298 | uint64_t raw_fd_ostream::seek(uint64_t off) { |
| 299 | flush(); |
| 300 | pos = lseek(FD, off, SEEK_SET); |
| 301 | return pos; |
| 302 | } |
| 303 | |
Chris Lattner | 07f51f7 | 2008-08-17 04:13:37 +0000 | [diff] [blame] | 304 | //===----------------------------------------------------------------------===// |
| 305 | // raw_stdout/err_ostream |
| 306 | //===----------------------------------------------------------------------===// |
Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 307 | |
| 308 | raw_stdout_ostream::raw_stdout_ostream():raw_fd_ostream(STDOUT_FILENO, false) {} |
Daniel Dunbar | e77e434 | 2009-03-10 16:21:55 +0000 | [diff] [blame] | 309 | raw_stderr_ostream::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false, |
| 310 | true) {} |
Chris Lattner | 60d3962 | 2008-08-17 01:35:29 +0000 | [diff] [blame] | 311 | |
| 312 | // An out of line virtual method to provide a home for the class vtable. |
| 313 | void raw_stdout_ostream::handle() {} |
| 314 | void raw_stderr_ostream::handle() {} |
Chris Lattner | 07f51f7 | 2008-08-17 04:13:37 +0000 | [diff] [blame] | 315 | |
| 316 | /// outs() - This returns a reference to a raw_ostream for standard output. |
| 317 | /// Use it like: outs() << "foo" << "bar"; |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 318 | raw_ostream &llvm::outs() { |
Chris Lattner | 07f51f7 | 2008-08-17 04:13:37 +0000 | [diff] [blame] | 319 | static raw_stdout_ostream S; |
| 320 | return S; |
| 321 | } |
| 322 | |
| 323 | /// errs() - This returns a reference to a raw_ostream for standard error. |
| 324 | /// Use it like: errs() << "foo" << "bar"; |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 325 | raw_ostream &llvm::errs() { |
Chris Lattner | 07f51f7 | 2008-08-17 04:13:37 +0000 | [diff] [blame] | 326 | static raw_stderr_ostream S; |
| 327 | return S; |
| 328 | } |
| 329 | |
| 330 | //===----------------------------------------------------------------------===// |
| 331 | // raw_os_ostream |
| 332 | //===----------------------------------------------------------------------===// |
| 333 | |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 334 | raw_os_ostream::~raw_os_ostream() { |
| 335 | flush(); |
| 336 | } |
| 337 | |
Daniel Dunbar | 89a66a9 | 2009-03-16 23:29:31 +0000 | [diff] [blame] | 338 | void raw_os_ostream::write_impl(const char *Ptr, unsigned Size) { |
| 339 | OS.write(Ptr, Size); |
Chris Lattner | 07f51f7 | 2008-08-17 04:13:37 +0000 | [diff] [blame] | 340 | } |
Chris Lattner | 78a2812 | 2008-08-23 22:43:04 +0000 | [diff] [blame] | 341 | |
Douglas Gregor | 8f7be47 | 2009-04-20 07:34:17 +0000 | [diff] [blame^] | 342 | uint64_t raw_os_ostream::current_pos() { return OS.tellp(); } |
| 343 | |
| 344 | uint64_t raw_os_ostream::tell() { |
| 345 | return (uint64_t)OS.tellp() + GetNumBytesInBuffer(); |
| 346 | } |
| 347 | |
Chris Lattner | 78a2812 | 2008-08-23 22:43:04 +0000 | [diff] [blame] | 348 | //===----------------------------------------------------------------------===// |
| 349 | // raw_string_ostream |
| 350 | //===----------------------------------------------------------------------===// |
| 351 | |
| 352 | raw_string_ostream::~raw_string_ostream() { |
| 353 | flush(); |
| 354 | } |
| 355 | |
Daniel Dunbar | 89a66a9 | 2009-03-16 23:29:31 +0000 | [diff] [blame] | 356 | void raw_string_ostream::write_impl(const char *Ptr, unsigned Size) { |
| 357 | OS.append(Ptr, Size); |
Chris Lattner | 78a2812 | 2008-08-23 22:43:04 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | //===----------------------------------------------------------------------===// |
| 361 | // raw_svector_ostream |
| 362 | //===----------------------------------------------------------------------===// |
| 363 | |
| 364 | raw_svector_ostream::~raw_svector_ostream() { |
| 365 | flush(); |
| 366 | } |
| 367 | |
Daniel Dunbar | 89a66a9 | 2009-03-16 23:29:31 +0000 | [diff] [blame] | 368 | void raw_svector_ostream::write_impl(const char *Ptr, unsigned Size) { |
| 369 | OS.append(Ptr, Ptr + Size); |
Chris Lattner | 78a2812 | 2008-08-23 22:43:04 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Douglas Gregor | 8f7be47 | 2009-04-20 07:34:17 +0000 | [diff] [blame^] | 372 | uint64_t raw_svector_ostream::current_pos() { return OS.size(); } |
| 373 | |
| 374 | uint64_t raw_svector_ostream::tell() { |
| 375 | return OS.size() + GetNumBytesInBuffer(); |
| 376 | } |