/home/arjun/llvm-project/llvm/lib/Support/circular_raw_ostream.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- circular_raw_ostream.cpp - Implement circular_raw_ostream ----------===// |
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 circular buffered streams. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "llvm/Support/circular_raw_ostream.h" |
14 | | #include <algorithm> |
15 | | using namespace llvm; |
16 | | |
17 | 0 | void circular_raw_ostream::write_impl(const char *Ptr, size_t Size) { |
18 | 0 | if (BufferSize == 0) { |
19 | 0 | TheStream->write(Ptr, Size); |
20 | 0 | return; |
21 | 0 | } |
22 | 0 | |
23 | 0 | // Write into the buffer, wrapping if necessary. |
24 | 0 | while (Size != 0) { |
25 | 0 | unsigned Bytes = |
26 | 0 | std::min(unsigned(Size), unsigned(BufferSize - (Cur - BufferArray))); |
27 | 0 | memcpy(Cur, Ptr, Bytes); |
28 | 0 | Size -= Bytes; |
29 | 0 | Cur += Bytes; |
30 | 0 | if (Cur == BufferArray + BufferSize) { |
31 | 0 | // Reset the output pointer to the start of the buffer. |
32 | 0 | Cur = BufferArray; |
33 | 0 | Filled = true; |
34 | 0 | } |
35 | 0 | } |
36 | 0 | } |
37 | | |
38 | 0 | void circular_raw_ostream::flushBufferWithBanner() { |
39 | 0 | if (BufferSize != 0) { |
40 | 0 | // Write out the buffer |
41 | 0 | TheStream->write(Banner, std::strlen(Banner)); |
42 | 0 | flushBuffer(); |
43 | 0 | } |
44 | 0 | } |