llvm.org GIT mirror llvm / 371da99
Remove old header. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92378 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 10 years ago
1 changed file(s) with 0 addition(s) and 516 deletion(s). Raw diff Collapse all Expand all
+0
-516
include/llvm/Bitcode/Deserialize.h less more
None //=- Deserialize.h - Generic Object Deserialization from Bitcode --*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the interface for generic object deserialization from
10 // LLVM bitcode.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_BITCODE_SERIALIZE_INPUT
15 #define LLVM_BITCODE_SERIALIZE_INPUT
16
17 #include "llvm/Bitcode/BitstreamReader.h"
18 #include "llvm/Bitcode/Serialization.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/Support/Allocator.h"
22 #include "llvm/System/DataTypes.h"
23 #include
24
25 namespace llvm {
26
27 struct BPNode {
28 BPNode* Next;
29 uintptr_t& PtrRef;
30
31 BPNode(BPNode* n, uintptr_t& pref)
32 : Next(n), PtrRef(pref) {
33 PtrRef = 0;
34 }
35 };
36
37 struct BPEntry {
38 union { BPNode* Head; void* Ptr; };
39 BPEntry() : Head(NULL) {}
40 void SetPtr(BPNode*& FreeList, void* P);
41 };
42
43 class BPKey {
44 unsigned Raw;
45 public:
46 BPKey(SerializedPtrID PtrId) : Raw(PtrId << 1) { assert (PtrId > 0); }
47 BPKey(unsigned code, unsigned) : Raw(code) {}
48
49 void MarkFinal() { Raw |= 0x1; }
50 bool hasFinalPtr() const { return Raw & 0x1 ? true : false; }
51 SerializedPtrID getID() const { return Raw >> 1; }
52
53 static inline BPKey getEmptyKey() { return BPKey(0,0); }
54 static inline BPKey getTombstoneKey() { return BPKey(1,0); }
55 static inline unsigned getHashValue(const BPKey& K) { return K.Raw & ~0x1; }
56
57 static bool isEqual(const BPKey& K1, const BPKey& K2) {
58 return (K1.Raw ^ K2.Raw) & ~0x1 ? false : true;
59 }
60 };
61
62 template <>
63 struct isPodLike { static const bool value = true; };
64 template <>
65 struct isPodLike { static const bool value = true; };
66
67 class Deserializer {
68
69 //===----------------------------------------------------------===//
70 // Internal type definitions.
71 //===----------------------------------------------------------===//
72
73
74 typedef llvm::DenseMap MapTy;
75
76 //===----------------------------------------------------------===//
77 // Publicly visible types.
78 //===----------------------------------------------------------===//
79
80 public:
81 struct Location {
82 uint64_t BitNo;
83 unsigned BlockID;
84 unsigned NumWords;
85
86 Location(uint64_t bit, unsigned bid, unsigned words)
87 : BitNo(bit), BlockID(bid), NumWords(words) {}
88
89 Location() : BitNo(0), BlockID(0), NumWords(0) {}
90
91 Location& operator=(Location& RHS) {
92 BitNo = RHS.BitNo;
93 BlockID = RHS.BlockID;
94 NumWords = RHS.NumWords;
95 return *this;
96 }
97
98 bool operator==(const Location& RHS) const { return BitNo == RHS.BitNo; }
99 bool operator!=(const Location& RHS) const { return BitNo != RHS.BitNo; }
100
101 bool contains(const Location& RHS) const {
102 if (RHS.BitNo < BitNo)
103 return false;
104
105 if ((RHS.BitNo - BitNo) >> 5 < NumWords)
106 return true;
107
108 return false;
109 }
110 };
111
112 //===----------------------------------------------------------===//
113 // Internal data members.
114 //===----------------------------------------------------------===//
115
116 private:
117 BitstreamCursor Stream;
118 SmallVector Record;
119 unsigned RecIdx;
120 BumpPtrAllocator Allocator;
121 BPNode* FreeList;
122 MapTy BPatchMap;
123 llvm::SmallVector BlockStack;
124 unsigned AbbrevNo;
125 unsigned RecordCode;
126 uint64_t StreamStart;
127
128 //===----------------------------------------------------------===//
129 // Public Interface.
130 //===----------------------------------------------------------===//
131
132 public:
133 Deserializer(BitstreamReader& stream);
134 ~Deserializer();
135
136 uint64_t ReadInt();
137 int64_t ReadSInt();
138 SerializedPtrID ReadPtrID() { return (SerializedPtrID) ReadInt(); }
139
140
141 bool ReadBool() {
142 return ReadInt() ? true : false;
143 }
144
145 template
146 inline T& Read(T& X) {
147 SerializeTrait::Read(*this,X);
148 return X;
149 }
150
151 template
152 inline T* Create() {
153 return SerializeTrait::Create(*this);
154 }
155
156 char* ReadCStr(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true);
157 void ReadCStr(std::vector& buff, bool isNullTerm=false, unsigned Idx=0);
158
159 template
160 inline T* ReadOwnedPtr(bool AutoRegister = true) {
161 SerializedPtrID PtrID = ReadPtrID();
162
163 if (!PtrID)
164 return NULL;
165
166 T* x = SerializeTrait::Create(*this);
167
168 if (AutoRegister)
169 RegisterPtr(PtrID,x);
170
171 return x;
172 }
173
174 template
175 inline T* ReadOwnedPtr(Arg1& arg1, bool AutoRegister = true) {
176 SerializedPtrID PtrID = ReadPtrID();
177
178 if (!PtrID)
179 return NULL;
180
181 T* x = SerializeTrait::Create(*this, arg1);
182
183 if (AutoRegister)
184 RegisterPtr(PtrID,x);
185
186 return x;
187 }
188
189 template
190 inline void ReadOwnedPtr(T*& Ptr, bool AutoRegister = true) {
191 Ptr = ReadOwnedPtr(AutoRegister);
192 }
193
194 template
195 void BatchReadOwnedPtrs(T1*& P1, T2*& P2,
196 bool A1=true, bool A2=true) {
197
198 SerializedPtrID ID1 = ReadPtrID();
199 SerializedPtrID ID2 = ReadPtrID();
200
201 P1 = (ID1) ? SerializeTrait::Create(*this) : NULL;
202 if (ID1 && A1) RegisterPtr(ID1,P1);
203
204 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
205 if (ID2 && A2) RegisterPtr(ID2,P2);
206 }
207
208 template
209 void BatchReadOwnedPtrs(T1*& P1, T2*& P2, Arg1& arg1,
210 bool A1=true, bool A2=true) {
211
212 SerializedPtrID ID1 = ReadPtrID();
213 SerializedPtrID ID2 = ReadPtrID();
214
215 P1 = (ID1) ? SerializeTrait::Create(*this, arg1) : NULL;
216 if (ID1 && A1) RegisterPtr(ID1,P1);
217
218 P2 = (ID2) ? SerializeTrait::Create(*this, arg1) : NULL;
219 if (ID2 && A2) RegisterPtr(ID2,P2);
220 }
221
222 template
223 void BatchReadOwnedPtrs(T1*& P1, T2*& P2, T3*& P3,
224 bool A1=true, bool A2=true, bool A3=true) {
225
226 SerializedPtrID ID1 = ReadPtrID();
227 SerializedPtrID ID2 = ReadPtrID();
228 SerializedPtrID ID3 = ReadPtrID();
229
230 P1 = (ID1) ? SerializeTrait::Create(*this) : NULL;
231 if (ID1 && A1) RegisterPtr(ID1,P1);
232
233 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
234 if (ID2 && A2) RegisterPtr(ID2,P2);
235
236 P3 = (ID3) ? SerializeTrait::Create(*this) : NULL;
237 if (ID3 && A3) RegisterPtr(ID3,P3);
238 }
239
240 template
241 void BatchReadOwnedPtrs(T1*& P1, T2*& P2, T3*& P3, Arg1& arg1,
242 bool A1=true, bool A2=true, bool A3=true) {
243
244 SerializedPtrID ID1 = ReadPtrID();
245 SerializedPtrID ID2 = ReadPtrID();
246 SerializedPtrID ID3 = ReadPtrID();
247
248 P1 = (ID1) ? SerializeTrait::Create(*this, arg1) : NULL;
249 if (ID1 && A1) RegisterPtr(ID1,P1);
250
251 P2 = (ID2) ? SerializeTrait::Create(*this, arg1) : NULL;
252 if (ID2 && A2) RegisterPtr(ID2,P2);
253
254 P3 = (ID3) ? SerializeTrait::Create(*this, arg1) : NULL;
255 if (ID3 && A3) RegisterPtr(ID3,P3);
256 }
257
258 template
259 void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, bool AutoRegister=true) {
260 llvm::SmallVector BatchIDVec;
261
262 for (unsigned i = 0; i < NumPtrs; ++i)
263 BatchIDVec.push_back(ReadPtrID());
264
265 for (unsigned i = 0; i < NumPtrs; ++i) {
266 SerializedPtrID& PtrID = BatchIDVec[i];
267
268 T* p = PtrID ? SerializeTrait::Create(*this) : NULL;
269
270 if (PtrID && AutoRegister)
271 RegisterPtr(PtrID,p);
272
273 Ptrs[i] = p;
274 }
275 }
276
277 template
278 void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, Arg1& arg1,
279 bool AutoRegister=true) {
280
281 llvm::SmallVector BatchIDVec;
282
283 for (unsigned i = 0; i < NumPtrs; ++i)
284 BatchIDVec.push_back(ReadPtrID());
285
286 for (unsigned i = 0; i < NumPtrs; ++i) {
287 SerializedPtrID& PtrID = BatchIDVec[i];
288
289 T* p = PtrID ? SerializeTrait::Create(*this, arg1) : NULL;
290
291 if (PtrID && AutoRegister)
292 RegisterPtr(PtrID,p);
293
294 Ptrs[i] = p;
295 }
296 }
297
298 template
299 void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2,
300 bool A1=true, bool A2=true) {
301
302 llvm::SmallVector BatchIDVec;
303
304 for (unsigned i = 0; i < NumT1Ptrs; ++i)
305 BatchIDVec.push_back(ReadPtrID());
306
307 SerializedPtrID ID2 = ReadPtrID();
308
309 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
310 SerializedPtrID& PtrID = BatchIDVec[i];
311
312 T1* p = PtrID ? SerializeTrait::Create(*this) : NULL;
313
314 if (PtrID && A1)
315 RegisterPtr(PtrID,p);
316
317 Ptrs[i] = p;
318 }
319
320 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
321 if (ID2 && A2) RegisterPtr(ID2,P2);
322 }
323
324 template
325 void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2, Arg1& arg1,
326 bool A1=true, bool A2=true) {
327
328 llvm::SmallVector BatchIDVec;
329
330 for (unsigned i = 0; i < NumT1Ptrs; ++i)
331 BatchIDVec.push_back(ReadPtrID());
332
333 SerializedPtrID ID2 = ReadPtrID();
334
335 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
336 SerializedPtrID& PtrID = BatchIDVec[i];
337
338 T1* p = PtrID ? SerializeTrait::Create(*this, arg1) : NULL;
339
340 if (PtrID && A1)
341 RegisterPtr(PtrID,p);
342
343 Ptrs[i] = p;
344 }
345
346 P2 = (ID2) ? SerializeTrait::Create(*this, arg1) : NULL;
347 if (ID2 && A2) RegisterPtr(ID2,P2);
348 }
349
350 template
351 void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs,
352 T2*& P2, T3*& P3,
353 bool A1=true, bool A2=true, bool A3=true) {
354
355 llvm::SmallVector BatchIDVec;
356
357 for (unsigned i = 0; i < NumT1Ptrs; ++i)
358 BatchIDVec.push_back(ReadPtrID());
359
360 SerializedPtrID ID2 = ReadPtrID();
361 SerializedPtrID ID3 = ReadPtrID();
362
363 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
364 SerializedPtrID& PtrID = BatchIDVec[i];
365
366 T1* p = PtrID ? SerializeTrait::Create(*this) : NULL;
367
368 if (PtrID && A1)
369 RegisterPtr(PtrID,p);
370
371 Ptrs[i] = p;
372 }
373
374 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
375 if (ID2 && A2) RegisterPtr(ID2,P2);
376
377 P3 = (ID3) ? SerializeTrait::Create(*this) : NULL;
378 if (ID3 && A3) RegisterPtr(ID3,P3);
379 }
380
381 template
382 void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs,
383 T2*& P2, T3*& P3, Arg1& arg1,
384 bool A1=true, bool A2=true, bool A3=true) {
385
386 llvm::SmallVector BatchIDVec;
387
388 for (unsigned i = 0; i < NumT1Ptrs; ++i)
389 BatchIDVec.push_back(ReadPtrID());
390
391 SerializedPtrID ID2 = ReadPtrID();
392 SerializedPtrID ID3 = ReadPtrID();
393
394 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
395 SerializedPtrID& PtrID = BatchIDVec[i];
396
397 T1* p = PtrID ? SerializeTrait::Create(*this, arg1) : NULL;
398
399 if (PtrID && A1)
400 RegisterPtr(PtrID,p);
401
402 Ptrs[i] = p;
403 }
404
405 P2 = (ID2) ? SerializeTrait::Create(*this, arg1) : NULL;
406 if (ID2 && A2) RegisterPtr(ID2,P2);
407
408 P3 = (ID3) ? SerializeTrait::Create(*this, arg1) : NULL;
409 if (ID3 && A3) RegisterPtr(ID3,P3);
410 }
411
412 template
413 void ReadPtr(T*& PtrRef, bool AllowBackpatch = true) {
414 ReadUIntPtr(reinterpret_cast(PtrRef), AllowBackpatch);
415 }
416
417 template
418 void ReadPtr(const T*& PtrRef, bool AllowBackpatch = true) {
419 ReadPtr(const_cast(PtrRef), AllowBackpatch);
420 }
421
422
423 template
424 void ReadPtr(T*& PtrRef, const SerializedPtrID& PtrID,
425 bool AllowBackpatch = true) {
426 ReadUIntPtr(reinterpret_cast(PtrRef), PtrID, AllowBackpatch);
427 }
428
429 template
430 void ReadPtr(const T*& PtrRef, const SerializedPtrID& PtrID,
431 bool AllowBackpatch = true) {
432
433 ReadPtr(const_cast(PtrRef), PtrID, AllowBackpatch);
434 }
435
436 template
437 T* ReadPtr() { T* x = 0; ReadPtr(x,false); return x; }
438
439 void ReadUIntPtr(uintptr_t& PtrRef, const SerializedPtrID& PtrID,
440 bool AllowBackpatch = true);
441
442 void ReadUIntPtr(uintptr_t& PtrRef, bool AllowBackpatch = true) {
443 ReadUIntPtr(PtrRef,ReadPtrID(),AllowBackpatch);
444 }
445
446 template
447 T& ReadRef() {
448 T* p = reinterpret_cast(ReadInternalRefPtr());
449 return *p;
450 }
451
452 void RegisterPtr(const SerializedPtrID& PtrID, const void* Ptr);
453
454 void RegisterPtr(const void* Ptr) {
455 RegisterPtr(ReadPtrID(),Ptr);
456 }
457
458 template
459 void RegisterRef(const T& x) {
460 RegisterPtr(&x);
461 }
462
463 template
464 void RegisterRef(const SerializedPtrID& PtrID, const T& x) {
465 RegisterPtr(PtrID,&x);
466 }
467
468 Location getCurrentBlockLocation();
469 unsigned getCurrentBlockID();
470 unsigned getAbbrevNo();
471
472 bool FinishedBlock(Location BlockLoc);
473 bool JumpTo(const Location& BlockLoc);
474 void Rewind();
475
476 bool AtEnd();
477 bool inRecord();
478 void SkipBlock();
479 bool SkipToBlock(unsigned BlockID);
480
481 unsigned getRecordCode();
482
483 BitstreamCursor &getStream() { return Stream; }
484
485 private:
486 bool AdvanceStream();
487 void ReadRecord();
488
489 uintptr_t ReadInternalRefPtr();
490
491 static inline bool HasFinalPtr(MapTy::value_type& V) {
492 return V.first.hasFinalPtr();
493 }
494
495 static inline uintptr_t GetFinalPtr(MapTy::value_type& V) {
496 return reinterpret_cast(V.second.Ptr);
497 }
498
499 static inline BPNode* GetBPNode(MapTy::value_type& V) {
500 return V.second.Head;
501 }
502
503 static inline void SetBPNode(MapTy::value_type& V, BPNode* N) {
504 V.second.Head = N;
505 }
506
507 void SetPtr(MapTy::value_type& V, const void* P) {
508 V.first.MarkFinal();
509 V.second.SetPtr(FreeList,const_cast(P));
510 }
511 };
512
513 } // end namespace llvm
514
515 #endif