1 //===- StreamInterface.h - Base interface for a stream of data --*- C++ -*-===// 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 #ifndef LLVM_DEBUGINFO_CODEVIEW_STREAMINTERFACE_H 11 #define LLVM_DEBUGINFO_CODEVIEW_STREAMINTERFACE_H 12 13 #include "llvm/ADT/ArrayRef.h" 14 #include "llvm/Support/Error.h" 15 #include <cstdint> 16 17 namespace llvm { 18 namespace codeview { 19 20 /// StreamInterface abstracts the notion of a data stream. This way, an 21 /// implementation could implement trivial reading from a contiguous memory 22 /// buffer or, as in the case of PDB files, reading from a set of possibly 23 /// discontiguous blocks. The implementation is required to return references 24 /// to stable memory, so if this is not possible (for example in the case of 25 /// a PDB file with discontiguous blocks, it must keep its own pool of temp 26 /// storage. 27 class StreamInterface { 28 public: ~StreamInterface()29 virtual ~StreamInterface() {} 30 31 // Given an offset into the stream and a number of bytes, attempt to read 32 // the bytes and set the output ArrayRef to point to a reference into the 33 // stream, without copying any data. 34 virtual Error readBytes(uint32_t Offset, uint32_t Size, 35 ArrayRef<uint8_t> &Buffer) const = 0; 36 37 // Given an offset into the stream, read as much as possible without copying 38 // any data. 39 virtual Error readLongestContiguousChunk(uint32_t Offset, 40 ArrayRef<uint8_t> &Buffer) const = 0; 41 42 // Attempt to write the given bytes into the stream at the desired offset. 43 // This will always necessitate a copy. Cannot shrink or grow the stream, 44 // only writes into existing allocated space. 45 virtual Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) const = 0; 46 47 virtual uint32_t getLength() const = 0; 48 49 virtual Error commit() const = 0; 50 }; 51 52 } // end namespace codeview 53 } // end namespace llvm 54 55 #endif // LLVM_DEBUGINFO_CODEVIEW_STREAMINTERFACE_H 56