10#ifndef LLVM_SUPPORT_BINARYBYTESTREAM_H
11#define LLVM_SUPPORT_BINARYBYTESTREAM_H
61 const char *CharData =
reinterpret_cast<const char *
>(
Data.
data());
93 : Data(Data), ImmutableStream(Data,
Endian) {}
118 uint8_t *DataPtr =
const_cast<uint8_t *
>(Data.
data());
135 std::vector<uint8_t> Data;
184 if (RequiredSize > Data.size())
185 Data.resize(RequiredSize);
205 StreamImpl(std::unique_ptr<FileOutputBuffer> Buffer,
209 Buffer->getBufferEnd()),
211 FileBuffer(std::move(Buffer)) {}
213 Error commit()
override {
214 if (FileBuffer->commit())
215 return make_error<BinaryStreamError>(
221 uint8_t *getBufferStart()
const {
return FileBuffer->getBufferStart(); }
224 uint8_t *getBufferEnd()
const {
return FileBuffer->getBufferEnd(); }
227 std::unique_ptr<FileOutputBuffer> FileBuffer;
244 return Impl.readLongestContiguousChunk(
Offset, Buffer);
An implementation of WritableBinaryStream which can write at its end causing the underlying data to g...
BinaryStreamFlags getFlags() const override
Return the properties of this stream.
Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Buffer) override
Attempt to write the given bytes into the stream at the desired offset.
llvm::endianness getEndian() const override
AppendingBinaryByteStream(llvm::endianness Endian)
Error commit() override
For buffered streams, commits changes to the backing store.
MutableArrayRef< uint8_t > data()
uint64_t getLength() override
Return the number of bytes of data in this stream.
Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...
Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
void insert(uint64_t Offset, ArrayRef< uint8_t > Bytes)
AppendingBinaryByteStream()=default
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
ArrayRef< uint8_t > data() const
BinaryByteStream(ArrayRef< uint8_t > Data, llvm::endianness Endian)
Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
BinaryByteStream()=default
Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...
uint64_t getLength() override
Return the number of bytes of data in this stream.
llvm::endianness getEndian() const override
BinaryByteStream(StringRef Data, llvm::endianness Endian)
An interface for accessing data in a stream-like format, but which discourages copying.
Error checkOffsetForRead(uint64_t Offset, uint64_t DataSize)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
An implementation of WritableBinaryStream backed by an llvm FileOutputBuffer.
FileBufferByteStream(std::unique_ptr< FileOutputBuffer > Buffer, llvm::endianness Endian)
uint64_t getLength() override
Return the number of bytes of data in this stream.
llvm::endianness getEndian() const override
Error commit() override
For buffered streams, commits changes to the backing store.
Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Data) override
Attempt to write the given bytes into the stream at the desired offset.
uint8_t * getBufferEnd() const
Returns a pointer to the end of the buffer.
uint8_t * getBufferStart() const
Returns a pointer to the start of the buffer.
Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...
An implementation of BinaryStream whose data is backed by an llvm MemoryBuffer object.
std::unique_ptr< MemoryBuffer > MemBuffer
MemoryBufferByteStream(std::unique_ptr< MemoryBuffer > Buffer, llvm::endianness Endian)
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
MutableArrayRef< uint8_t > data() const
uint64_t getLength() override
Return the number of bytes of data in this stream.
Error commit() override
For buffered streams, commits changes to the backing store.
llvm::endianness getEndian() const override
Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Buffer) override
Attempt to write the given bytes into the stream at the desired offset.
MutableBinaryByteStream(MutableArrayRef< uint8_t > Data, llvm::endianness Endian)
MutableBinaryByteStream()=default
Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...
StringRef - Represent a constant reference to a string, i.e.
A BinaryStream which can be read from as well as written to.
Error checkOffsetForWrite(uint64_t Offset, uint64_t DataSize)
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.