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"
23 #include "llvm/Support/DataTypes.h"
29 BitstreamReader& Stream;
30 SmallVector<uint64_t,10> Record;
32 BumpPtrAllocator Allocator;
35 static inline unsigned getEmptyKey() { return ~((unsigned) 0x0); }
36 static inline unsigned getTombstoneKey() { return getEmptyKey()-1; }
37 static inline unsigned getHashValue(unsigned X) { return X; }
38 static inline bool isEqual(unsigned X, unsigned Y) { return X == Y; }
39 static inline bool isPod() { return true; }
43 BPatchNode* const Next;
45 BPatchNode(BPatchNode* n, void*& pref)
46 : Next(n), PtrRef(reinterpret_cast<uintptr_t&>(pref)) {
54 BPatchEntry() : Head(NULL), Ptr(NULL) {}
55 static inline bool isPod() { return true; }
58 typedef llvm::DenseMap<unsigned,BPatchEntry,PtrIdInfo,BPatchEntry> MapTy;
63 Deserializer(BitstreamReader& stream);
68 return ReadInt() ? true : false;
72 inline T& Read(T& X) {
73 SerializeTrait<T>::Read(*this,X);
79 return SerializeTrait<T>::ReadVal(*this);
83 inline T* Materialize() {
84 return SerializeTrait<T>::Materialize(*this);
87 char* ReadCStr(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true);
88 void ReadCStr(std::vector<char>& buff, bool isNullTerm=false);
91 inline T* ReadOwnedPtr() {
92 unsigned PtrId = ReadInt();
97 T* x = SerializeTrait<T>::Materialize(*this);
102 void ReadPtr(void*& PtrRef);
103 void RegisterPtr(unsigned PtrId, void* Ptr);
106 void BackpatchPointers();
112 } // end namespace llvm