LLVM: lib/Support/BinaryStreamRef.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
11
12using namespace llvm;
13
14namespace {
15
17public:
19
23 return BBS.readBytes(Offset, Size, Buffer);
24 }
27 return BBS.readLongestContiguousChunk(Offset, Buffer);
28 }
30
31private:
33};
34
36public:
38 : BBS(Data, Endian) {}
39
40
44 return BBS.readBytes(Offset, Size, Buffer);
45 }
48 return BBS.readLongestContiguousChunk(Offset, Buffer);
49 }
51
53 return BBS.writeBytes(Offset, Data);
54 }
55 Error commit() override { return BBS.commit(); }
56
57private:
59};
60}
61
65 std::optional<uint64_t> Length)
72
76 return EC;
78}
79
83 return EC;
84
85 if (auto EC =
87 return EC;
88
89
90
92 if (Buffer.size() > MaxLength)
93 Buffer = Buffer.slice(0, MaxLength);
95}
96
99
102 std::optional<uint64_t> Length)
104
109
112 if (auto EC = checkOffsetForWrite(Offset, Data.size()))
113 return EC;
114
116}
117
120}
121
122
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
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.
Common stuff for mutable and immutable StreamRefs.
BinaryStream * BorrowedImpl
Error checkOffsetForRead(uint64_t Offset, uint64_t DataSize) const
uint64_t getLength() const
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) const
Given an Offset into this BinaryStreamRef, return a reference to the largest buffer the stream could ...
Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) const
Given an Offset into this StreamRef and a Size, return a reference to a buffer owned by the stream.
BinaryStreamRef()=default
An interface for accessing data in a stream-like format, but which discourages copying.
virtual llvm::endianness getEndian() const =0
virtual uint64_t getLength()=0
Return the number of bytes of data in this stream.
virtual Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer)=0
Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...
virtual Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer)=0
Given an offset into the stream, read as much as possible without copying any data.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
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.
StringRef - Represent a constant reference to a string, i.e.
WritableBinaryStreamRef()=default
Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Data) const
Given an Offset into this WritableBinaryStreamRef and some input data, writes the data to the underly...
Error commit()
For buffered streams, commits changes to the backing store.
A BinaryStream which can be read from as well as written to.
virtual Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Data)=0
Attempt to write the given bytes into the stream at the desired offset.
virtual Error commit()=0
For buffered streams, commits changes to the backing store.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Implement std::hash so that hash_code can be used in STL containers.