10 #ifndef LLVM_SUPPORT_BINARYSTREAMARRAY_H
11 #define LLVM_SUPPORT_BINARYSTREAMARRAY_H
48 T &Item)
const =
delete;
102 : Stream(Stream), E(E) {}
119 return Iterator(*
this,
E, Offset,
nullptr);
133 template <
typename ValueType,
typename Extractor>
134 class VarStreamArrayIterator
135 :
public iterator_facade_base<VarStreamArrayIterator<ValueType, Extractor>,
136 std::forward_iterator_tag, ValueType> {
137 typedef VarStreamArrayIterator<ValueType, Extractor> IterType;
138 typedef VarStreamArray<ValueType, Extractor> ArrayType;
147 : IterRef(Array.Stream.drop_front(Offset)), Extract(E),
148 Array(&Array), AbsOffset(Offset), HadError(HadError) {
152 auto EC = Extract(IterRef, ThisLen, ThisValue);
165 if (Array && R.Array) {
168 return IterRef == R.IterRef;
172 if (!Array && !R.Array)
180 assert(Array && !HasError);
185 assert(Array && !HasError);
190 for (
unsigned I = 0;
I <
N; ++
I) {
193 AbsOffset += ThisLen;
201 auto EC = Extract(IterRef, ThisLen, ThisValue);
205 }
else if (ThisLen == 0) {
225 if (HadError !=
nullptr)
230 BinaryStreamRef IterRef;
232 const ArrayType *Array{
nullptr};
235 bool HasError{
false};
236 bool *HadError{
nullptr};
258 return Stream == Other.Stream;
262 return !(*
this ==
Other);
271 if (
auto EC = Stream.
readBytes(Off,
sizeof(
T), Data)) {
272 assert(
false &&
"Unexpected failure reading from stream");
278 return *
reinterpret_cast<const T *
>(Data.data());
305 template <
typename T>
306 class FixedStreamArrayIterator
307 :
public iterator_facade_base<FixedStreamArrayIterator<T>,
308 std::random_access_iterator_tag, const T> {
312 : Array(Array), Index(Index) {}
326 return (Index == R.Index) && (Array == R.Array);
335 assert(std::ptrdiff_t(Index) >= N);
343 return Index - R.Index;
346 bool operator<(const FixedStreamArrayIterator<T> &RHS)
const {
347 assert(Array == RHS.Array);
348 return Index < RHS.Index;
358 #endif // LLVM_SUPPORT_BINARYSTREAMARRAY_H
const ValueType & operator*() const
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
std::ptrdiff_t operator-(const FixedStreamArrayIterator< T > &R) const
void setUnderlyingStream(BinaryStreamRef S)
const Extractor & getExtractor() const
VarStreamArray(const Extractor &E)
RefType drop_front(uint32_t N) const
Return a new BinaryStreamRef with the first N elements removed.
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
FixedStreamArrayIterator< T > begin() const
const T & operator*() const
FixedStreamArrayIterator< T > Iterator
FixedStreamArrayIterator< T > end() const
FixedStreamArrayIterator< T > & operator=(const FixedStreamArrayIterator< T > &Other)
VarStreamArray(BinaryStreamRef Stream, const Extractor &E)
VarStreamArray(BinaryStreamRef Stream)
FixedStreamArray & operator=(const FixedStreamArray &)=default
VarStreamArrayIterator(const ArrayType &Array, const Extractor &E, uint32_t Offset, bool *HadError)
FixedStreamArray()=default
Extractor & getExtractor()
~VarStreamArrayIterator()=default
VarStreamArrayIterator< ValueType, Extractor > Iterator
size_t alignmentAdjustment(const void *Ptr, size_t Alignment)
Returns the necessary adjustment for aligning Ptr to Alignment bytes, rounding up.
VarStreamArrayIterator(const Extractor &E)
bool operator==(const FixedStreamArrayIterator< T > &R) const
IterType & operator+=(unsigned N)
void consumeError(Error Err)
Consume a Error without doing anything.
FixedStreamArray(BinaryStreamRef Stream)
VarStreamArrayIterator(const ArrayType &Array, const Extractor &E, bool *HadError)
FixedStreamArrayIterator(const FixedStreamArray< T > &Array, uint32_t Index)
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
VarStreamArray represents an array of variable length records backed by a stream. ...
FixedStreamArrayIterator< T > & operator-=(std::ptrdiff_t N)
uint32_t getLength() const
VarStreamArrayIterator()=default
FixedStreamArrayIterator< T > & operator+=(std::ptrdiff_t N)
bool operator==(const FixedStreamArray< T > &Other) const
bool operator!=(const FixedStreamArray< T > &Other) const
BinaryStreamRef getUnderlyingStream() const
Iterator at(uint32_t Offset) const
given an offset into the array's underlying stream, return an iterator to the record at that offset...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const T & operator[](uint32_t Index) const
Error readBytes(uint32_t Offset, uint32_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...
Lightweight error class with error context and mandatory checking.
Iterator begin(bool *HadError=nullptr) const
uint32_t getRecordLength() const
bool operator==(const IterType &R) const
BinaryStreamRef getUnderlyingStream() const