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
112 bool valid() const { return Stream.valid(); }
113
115
118
119 bool empty() const { return Stream.getLength() == 0; }
120
123 assert(Begin >= Skew);
124
125
127 return {NewStream, E, Begin};
128 }
129
130
131
132
133
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) {
167 if (IterRef.getLength() == 0)
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);
208 if (IterRef.getLength() == 0) {
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;
245 const ArrayType *Array{nullptr};
246 uint32_t ThisLen{0};
247 uint32_t AbsOffset{0};
248 bool HasError{false};
249 bool *HadError{nullptr};
250};
251
252template class FixedStreamArrayIterator;
253
254
255
256
257
258
261
262public:
264
267 assert(Stream.getLength() % sizeof(T) == 0);
268 }
269
271 return Stream == Other.Stream;
272 }
273
275 return !(*this == Other);
276 }
277
280
283 uint32_t Off = Index * sizeof(T);
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
295 uint32_t size() const { return Stream.getLength() / sizeof(T); }
296
298
302
306
312
314
315private:
317};
318
319template
322 std::random_access_iterator_tag, const T> {
323
324public:
326 : Array(Array), Index(Index) {}
327
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
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
RefType slice(uint64_t Offset, uint64_t Len) const
Return a new BinaryStreamRef with the first Offset elements removed, and retaining exactly Len elemen...
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Lightweight error class with error context and mandatory checking.
const T & operator*()
Definition BinaryStreamArray.h:338
std::ptrdiff_t operator-(const FixedStreamArrayIterator< T > &R) const
Definition BinaryStreamArray.h:356
FixedStreamArrayIterator< T > & operator+=(std::ptrdiff_t N)
Definition BinaryStreamArray.h:345
FixedStreamArrayIterator< T > & operator=(const FixedStreamArrayIterator< T > &Other)
Definition BinaryStreamArray.h:331
bool operator<(const FixedStreamArrayIterator< T > &RHS) const
Definition BinaryStreamArray.h:362
bool operator==(const FixedStreamArrayIterator< T > &R) const
Definition BinaryStreamArray.h:340
FixedStreamArrayIterator< T > & operator-=(std::ptrdiff_t N)
Definition BinaryStreamArray.h:350
const T & operator*() const
Definition BinaryStreamArray.h:337
FixedStreamArrayIterator(const FixedStreamArray< T > &Array, uint32_t Index)
Definition BinaryStreamArray.h:325
FixedStreamArrayIterator(const FixedStreamArrayIterator< T > &Other)
Definition BinaryStreamArray.h:328
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
Definition BinaryStreamArray.h:259
BinaryStreamRef getUnderlyingStream() const
Definition BinaryStreamArray.h:313
FixedStreamArrayIterator< T > begin() const
Definition BinaryStreamArray.h:299
bool operator!=(const FixedStreamArray< T > &Other) const
Definition BinaryStreamArray.h:274
FixedStreamArray & operator=(const FixedStreamArray &)=default
uint32_t size() const
Definition BinaryStreamArray.h:295
FixedStreamArrayIterator< T > end() const
Definition BinaryStreamArray.h:303
bool operator==(const FixedStreamArray< T > &Other) const
Definition BinaryStreamArray.h:270
bool empty() const
Definition BinaryStreamArray.h:297
const T & front() const
Definition BinaryStreamArray.h:307
friend class FixedStreamArrayIterator< T >
Definition BinaryStreamArray.h:260
const T & operator[](uint32_t Index) const
Definition BinaryStreamArray.h:281
FixedStreamArrayIterator< CrossModuleExport > Iterator
Definition BinaryStreamArray.h:263
const T & back() const
Definition BinaryStreamArray.h:308
FixedStreamArray(BinaryStreamRef Stream)
Definition BinaryStreamArray.h:266
FixedStreamArray()=default
FixedStreamArray(const FixedStreamArray &)=default
VarStreamArray represents an array of variable length records backed by a stream.
Definition BinaryStreamArray.h:158
VarStreamArrayIterator(const ArrayType &Array, const Extractor &E, uint32_t Offset, bool *HadError)
Definition BinaryStreamArray.h:163
uint32_t getRecordLength() const
Definition BinaryStreamArray.h:228
VarStreamArrayIterator(const Extractor &E)
Definition BinaryStreamArray.h:179
uint32_t offset() const
Definition BinaryStreamArray.h:227
~VarStreamArrayIterator()=default
VarStreamArrayIterator()=default
bool operator==(const IterType &R) const
Definition BinaryStreamArray.h:182
IterType & operator+=(unsigned N)
Definition BinaryStreamArray.h:202
const ValueType & operator*() const
Definition BinaryStreamArray.h:197
Definition BinaryStreamArray.h:92
VarStreamArray(BinaryStreamRef Stream, const Extractor &E, uint32_t Skew=0)
Definition BinaryStreamArray.h:105
void setUnderlyingStream(BinaryStreamRef NewStream, uint32_t NewSkew=0)
Definition BinaryStreamArray.h:142
uint32_t skew() const
Definition BinaryStreamArray.h:116
Iterator at(uint32_t Offset) const
Definition BinaryStreamArray.h:134
VarStreamArray(const Extractor &E)
Definition BinaryStreamArray.h:100
bool empty() const
Definition BinaryStreamArray.h:119
void drop_front()
Definition BinaryStreamArray.h:147
Extractor & getExtractor()
Definition BinaryStreamArray.h:139
Iterator end() const
Definition BinaryStreamArray.h:117
bool valid() const
Definition BinaryStreamArray.h:112
BinaryStreamRef getUnderlyingStream() const
Definition BinaryStreamArray.h:141
bool isOffsetValid(uint32_t Offset) const
Definition BinaryStreamArray.h:114
Iterator begin(bool *HadError=nullptr) const
Definition BinaryStreamArray.h:108
const Extractor & getExtractor() const
Definition BinaryStreamArray.h:138
VarStreamArrayIterator< CVSymbol, VarStreamArrayExtractor< CVSymbol > > Iterator
Definition BinaryStreamArray.h:96
VarStreamArray(BinaryStreamRef Stream, uint32_t Skew=0)
Definition BinaryStreamArray.h:102
VarStreamArray< ValueType, Extractor > substream(uint32_t Begin, uint32_t End) const
Definition BinaryStreamArray.h:121
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.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
void consumeError(Error Err)
Consume a Error without doing anything.
bool isAddrAligned(Align Lhs, const void *Addr)
Checks that Addr is a multiple of the alignment.
static constexpr Align Of()
Allow constructions of constexpr Align from types.