LLVM API Documentation
00001 //===- circular_raw_ostream.cpp - Implement circular_raw_ostream ----------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This implements support for circular buffered streams. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/Support/circular_raw_ostream.h" 00015 #include <algorithm> 00016 using namespace llvm; 00017 00018 void circular_raw_ostream::write_impl(const char *Ptr, size_t Size) { 00019 if (BufferSize == 0) { 00020 TheStream->write(Ptr, Size); 00021 return; 00022 } 00023 00024 // Write into the buffer, wrapping if necessary. 00025 while (Size != 0) { 00026 unsigned Bytes = 00027 std::min(unsigned(Size), unsigned(BufferSize - (Cur - BufferArray))); 00028 memcpy(Cur, Ptr, Bytes); 00029 Size -= Bytes; 00030 Cur += Bytes; 00031 if (Cur == BufferArray + BufferSize) { 00032 // Reset the output pointer to the start of the buffer. 00033 Cur = BufferArray; 00034 Filled = true; 00035 } 00036 } 00037 } 00038 00039 void circular_raw_ostream::flushBufferWithBanner() { 00040 if (BufferSize != 0) { 00041 // Write out the buffer 00042 TheStream->write(Banner, std::strlen(Banner)); 00043 flushBuffer(); 00044 } 00045 }