1 //=- Deserialize.h - Generic Object Deserialization from Bitcode --*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Ted Kremenek and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interface for generic object deserialization from
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_BITCODE_SERIALIZE_INPUT
16 #define LLVM_BITCODE_SERIALIZE_INPUT
18 #include "llvm/Bitcode/BitstreamReader.h"
19 #include "llvm/Bitcode/Serialization.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/Support/Allocator.h"
28 BitstreamReader& Stream;
29 SmallVector<uint64_t,10> Record;
31 BumpPtrAllocator Allocator;
34 static inline unsigned getEmptyKey() { return ~((unsigned) 0x0); }
35 static inline unsigned getTombstoneKey() { return getEmptyKey()-1; }
36 static inline unsigned getHashValue(unsigned X) { return X; }
37 static inline bool isEqual(unsigned X, unsigned Y) { return X == Y; }
38 static inline bool isPod() { return true; }
42 BPatchNode* const Next;
44 BPatchNode(BPatchNode* n, void*& pref) : Next(n), PtrRef(pref) {}
50 BPatchEntry() : Head(NULL), Ptr(NULL) {}
51 static inline bool isPod() { return true; }
54 typedef llvm::DenseMap<unsigned,BPatchEntry,PtrIdInfo,BPatchEntry> MapTy;
59 Deserializer(BitstreamReader& stream);
64 return ReadInt() ? true : false;
68 inline T& Read(T& X) {
69 SerializeTrait<T>::Read(*this,X);
75 return SerializeTrait<T>::ReadVal(*this);
79 inline T* Materialize() {
80 return SerializeTrait<T>::Materialize(*this);
83 char* ReadCStr(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true);
84 void ReadCStr(std::vector<char>& buff, bool isNullTerm=false);
87 inline T* ReadOwnedPtr() {
88 unsigned PtrId = ReadInt();
89 T* x = SerializeTrait<T>::Materialize(*this);
94 void ReadPtr(void*& PtrRef);
95 void RegisterPtr(unsigned PtrId, void* Ptr);
98 void BackpatchPointers();
104 } // end namespace llvm