LLVM: include/llvm/Support/BinaryStreamArray.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef LLVM_SUPPORT_BINARYSTREAMARRAY_H
23#define LLVM_SUPPORT_BINARYSTREAMARRAY_H
24
30#include
31#include
32
33namespace llvm {
34
35
36
37
38
39
40
41
42
43
44
45
46
48
49
51 T &Item) const = delete;
52};
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
89
94
95public:
97
99
101
103 : Stream(Stream), Skew(Skew) {}
104
106 : Stream(Stream), E(E), Skew(Skew) {}
107
109 return Iterator(*this, E, Skew, nullptr);
110 }
111
113
115
118
120
123 assert(Begin >= Skew);
124
125
127 return {NewStream, E, Begin};
128 }
129
130
131
132
133
136 }
137
140
143 Stream = NewStream;
144 Skew = NewSkew;
145 }
146
148
149private:
151 Extractor E;
153};
154
155template <typename ValueType, typename Extractor>
158 std::forward_iterator_tag, const ValueType> {
161
162public:
165 : IterRef(Array.Stream.drop_front(Offset)), Extract(E),
166 Array(&Array), AbsOffset(Offset), HadError(HadError) {
168 moveToEnd();
169 else {
170 auto EC = Extract(IterRef, ThisLen, ThisValue);
171 if (EC) {
173 markError();
174 }
175 }
176 }
177
181
183 if (Array && R.Array) {
184
185 assert(Array == R.Array);
186 return IterRef == R.IterRef;
187 }
188
189
190 if (!Array && !R.Array)
191 return true;
192
193
194 return false;
195 }
196
198 assert(Array && !HasError);
199 return ThisValue;
200 }
201
203 for (unsigned I = 0; I < N; ++I) {
204
205
206 AbsOffset += ThisLen;
207 IterRef = IterRef.drop_front(ThisLen);
209
210
211 moveToEnd();
212 } else {
213
214 auto EC = Extract(IterRef, ThisLen, ThisValue);
215 if (EC) {
217 markError();
218 } else if (ThisLen == 0) {
219
220 moveToEnd();
221 }
222 }
223 }
224 return *this;
225 }
226
229
230private:
231 void moveToEnd() {
232 Array = nullptr;
233 ThisLen = 0;
234 }
235 void markError() {
236 moveToEnd();
237 HasError = true;
238 if (HadError != nullptr)
239 *HadError = true;
240 }
241
243 BinaryStreamRef IterRef;
244 Extractor Extract;
248 bool HasError{false};
249 bool *HadError{nullptr};
250};
251
252template class FixedStreamArrayIterator;
253
254
255
256
257
258
261
262public:
264
268 }
269
271 return Stream == Other.Stream;
272 }
273
275 return !(*this == Other);
276 }
277
280
285 if (auto EC = Stream.readBytes(Off, sizeof(T), Data)) {
286 assert(false && "Unexpected failure reading from stream");
287
288
290 }
292 return *reinterpret_cast<const T *>(Data.data());
293 }
294
296
298
301 }
302
305 }
306
310 return *(--I);
311 }
312
314
315private:
317};
318
319template
322 std::random_access_iterator_tag, const T> {
323
324public:
326 : Array(Array), Index(Index) {}
327
329 : Array(Other.Array), Index(Other.Index) {}
332 Array = Other.Array;
333 Index = Other.Index;
334 return *this;
335 }
336
337 const T &operator*() const { return Array[Index]; }
339
341 assert(Array == R.Array);
342 return (Index == R.Index) && (Array == R.Array);
343 }
344
346 Index += N;
347 return *this;
348 }
349
351 assert(std::ptrdiff_t(Index) >= N);
352 Index -= N;
353 return *this;
354 }
355
357 assert(Array == R.Array);
358 assert(Index >= R.Index);
359 return Index - R.Index;
360 }
361
364 return Index < RHS.Index;
365 }
366
367private:
370};
371
372}
373
374#endif
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
RefType drop_front(uint64_t N) const
Return a new BinaryStreamRef with the first N elements removed.
RefType slice(uint64_t Offset, uint64_t Len) const
Return a new BinaryStreamRef with the first Offset elements removed, and retaining exactly Len elemen...
uint64_t getLength() const
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
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.
Lightweight error class with error context and mandatory checking.
std::ptrdiff_t operator-(const FixedStreamArrayIterator< T > &R) const
FixedStreamArrayIterator< T > & operator+=(std::ptrdiff_t N)
FixedStreamArrayIterator< T > & operator=(const FixedStreamArrayIterator< T > &Other)
bool operator<(const FixedStreamArrayIterator< T > &RHS) const
bool operator==(const FixedStreamArrayIterator< T > &R) const
FixedStreamArrayIterator< T > & operator-=(std::ptrdiff_t N)
const T & operator*() const
FixedStreamArrayIterator(const FixedStreamArray< T > &Array, uint32_t Index)
FixedStreamArrayIterator(const FixedStreamArrayIterator< T > &Other)
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
FixedStreamArrayIterator< T > Iterator
BinaryStreamRef getUnderlyingStream() const
FixedStreamArrayIterator< T > begin() const
bool operator!=(const FixedStreamArray< T > &Other) const
FixedStreamArray & operator=(const FixedStreamArray &)=default
FixedStreamArrayIterator< T > end() const
bool operator==(const FixedStreamArray< T > &Other) const
friend class FixedStreamArrayIterator< T >
const T & operator[](uint32_t Index) const
FixedStreamArray(BinaryStreamRef Stream)
FixedStreamArray()=default
FixedStreamArray(const FixedStreamArray &)=default
VarStreamArray represents an array of variable length records backed by a stream.
VarStreamArrayIterator(const ArrayType &Array, const Extractor &E, uint32_t Offset, bool *HadError)
uint32_t getRecordLength() const
VarStreamArrayIterator(const Extractor &E)
~VarStreamArrayIterator()=default
VarStreamArrayIterator()=default
bool operator==(const IterType &R) const
IterType & operator+=(unsigned N)
const ValueType & operator*() const
VarStreamArray(BinaryStreamRef Stream, const Extractor &E, uint32_t Skew=0)
void setUnderlyingStream(BinaryStreamRef NewStream, uint32_t NewSkew=0)
Iterator at(uint32_t Offset) const
given an offset into the array's underlying stream, return an iterator to the record at that offset.
VarStreamArray(const Extractor &E)
Extractor & getExtractor()
BinaryStreamRef getUnderlyingStream() const
VarStreamArrayIterator< ValueType, Extractor > Iterator
bool isOffsetValid(uint32_t Offset) const
Iterator begin(bool *HadError=nullptr) const
const Extractor & getExtractor() const
VarStreamArray(BinaryStreamRef Stream, uint32_t Skew=0)
VarStreamArray< ValueType, Extractor > substream(uint32_t Begin, uint32_t End) const
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
This is an optimization pass for GlobalISel generic memory operations.
void consumeError(Error Err)
Consume a Error without doing anything.
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
bool isAddrAligned(Align Lhs, const void *Addr)
Checks that Addr is a multiple of the alignment.