X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FBitcode%2FDeserialize.h;h=f5adcffe25c183ec82c3af2b8f6fc50f5329d49f;hb=fe2a0123389adf0f2f66c413570d2daabdb5539d;hp=6ee09aaa34465d85ca2bd33d0dbd5915dda725fb;hpb=8eadd5a6db79da067c773d1bd1cc13edc07788cc;p=oota-llvm.git diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h index 6ee09aaa344..f5adcffe25c 100644 --- a/include/llvm/Bitcode/Deserialize.h +++ b/include/llvm/Bitcode/Deserialize.h @@ -17,6 +17,9 @@ #include "llvm/Bitcode/BitstreamReader.h" #include "llvm/Bitcode/Serialization.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Allocator.h" #include namespace llvm { @@ -25,50 +28,79 @@ class Deserializer { BitstreamReader& Stream; SmallVector Record; unsigned RecIdx; + BumpPtrAllocator Allocator; + + struct PtrIdInfo { + static inline unsigned getEmptyKey() { return ~((unsigned) 0x0); } + static inline unsigned getTombstoneKey() { return getEmptyKey()-1; } + static inline unsigned getHashValue(unsigned X) { return X; } + static inline bool isEqual(unsigned X, unsigned Y) { return X == Y; } + static inline bool isPod() { return true; } + }; + + struct BPatchNode { + BPatchNode* const Next; + void*& PtrRef; + BPatchNode(BPatchNode* n, void*& pref) : Next(n), PtrRef(pref) {} + }; + + struct BPatchEntry { + BPatchNode* Head; + void* Ptr; + BPatchEntry() : Head(NULL), Ptr(NULL) {} + static inline bool isPod() { return true; } + }; + + typedef llvm::DenseMap MapTy; + + MapTy BPatchMap; + public: Deserializer(BitstreamReader& stream); ~Deserializer(); - + + uint64_t ReadInt(); + bool ReadBool() { + return ReadInt() ? true : false; + } + template inline T& Read(T& X) { SerializeTrait::Read(*this,X); return X; } + template + inline T ReadVal() { + return SerializeTrait::ReadVal(*this); + } + template inline T* Materialize() { return SerializeTrait::Materialize(*this); } - - uint64_t ReadInt(); - bool ReadBool() { return ReadInt() ? true : false; } - - // FIXME: Substitute a better implementation which calculates the minimum - // number of bits needed to serialize the enum. - template - EnumT ReadEnum(unsigned MinVal, unsigned MaxVal) { - return static_cast(ReadInt(32)); - } char* ReadCStr(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true); void ReadCStr(std::vector& buff, bool isNullTerm=false); + + template + inline T* ReadOwnedPtr() { + unsigned PtrId = ReadInt(); + T* x = SerializeTrait::Materialize(*this); + RegisterPtr(PtrId,x); + return x; + } + void ReadPtr(void*& PtrRef); + void RegisterPtr(unsigned PtrId, void* Ptr); + + + void BackpatchPointers(); private: - void ReadRecord(); - - inline bool inRecord() { - if (Record.size() > 0) { - if (RecIdx >= Record.size()) { - RecIdx = 0; - Record.clear(); - return false; - } - else return true; - } - else return false; - } + void ReadRecord(); + bool inRecord(); }; - + } // end namespace llvm #endif