10 #ifndef LLVM_SUPPORT_BINARYITEMSTREAM_H 11 #define LLVM_SUPPORT_BINARYITEMSTREAM_H 23 static size_t length(
const T &Item) =
delete;
34 template <
typename T,
typename Traits = BinaryItemTraits<T>>
44 auto ExpectedIndex = translateOffsetIndex(Offset);
46 return ExpectedIndex.takeError();
47 const auto &Item = Items[*ExpectedIndex];
48 if (
auto EC = checkOffsetForRead(Offset, Size))
50 if (Size > Traits::length(Item))
58 auto ExpectedIndex = translateOffsetIndex(Offset);
60 return ExpectedIndex.takeError();
61 Buffer = Traits::bytes(Items[*ExpectedIndex]);
71 return ItemEndOffsets.empty() ? 0 : ItemEndOffsets.back();
75 void computeItemOffsets() {
76 ItemEndOffsets.clear();
77 ItemEndOffsets.reserve(Items.size());
79 for (
const auto &Item : Items) {
81 assert(Len > 0 &&
"no empty items");
83 ItemEndOffsets.push_back(CurrentOffset);
89 if (Offset >= getLength())
94 size_t Idx = std::distance(ItemEndOffsets.begin(), Iter);
95 assert(Idx < Items.size() &&
"binary search for offset failed");
103 std::vector<uint32_t> ItemEndOffsets;
108 #endif // LLVM_SUPPORT_BINARYITEMSTREAM_H ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
This class represents lattice values for constants.
static ArrayRef< uint8_t > bytes(const T &Item)=delete
Error readLongestContiguousChunk(uint32_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
Tagged union holding either a T or a Error.
auto lower_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
An interface for accessing data in a stream-like format, but which discourages copying.
llvm::support::endianness getEndian() const override
BinaryItemStream(llvm::support::endianness Endian)
Error readBytes(uint32_t Offset, uint32_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...
static ErrorSuccess success()
Create a success value.
static size_t length(const T &Item)=delete
uint32_t getLength() override
Return the number of bytes of data in this stream.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
BinaryItemStream represents a sequence of objects stored in some kind of external container but for w...
Lightweight error class with error context and mandatory checking.
void setItems(ArrayRef< T > ItemArray)