From eb9409dbb9c5fe963bf28973c5697fddfcaf48ce Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 31 Oct 2007 19:58:32 +0000 Subject: Implemented deserialization of references. References are handled just like pointers, except that they cannot be backpatched. This means that references are essentially non-owning pointers where the referred object must be deserialized prior to the reference being deserialized. Because of the nature of references, this ordering of objects is always possible. Fixed a bug in backpatching code (returning the backpatched pointer would accidentally include a bit flag). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43570 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Bitcode/Deserialize.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'include/llvm/Bitcode') diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h index 508b4deee8..72367e30d9 100644 --- a/include/llvm/Bitcode/Deserialize.h +++ b/include/llvm/Bitcode/Deserialize.h @@ -56,7 +56,7 @@ class Deserializer { BPatchEntry(void* P) : Ptr(reinterpret_cast(P)) {} - bool hasFinalPtr() const { return Ptr & 0x1 ? true : false; } + bool hasFinalPtr() const { return Ptr & 0x1 ? false : true; } void setFinalPtr(BPNode*& FreeList, void* P); BPNode* getBPNode() const { @@ -69,7 +69,10 @@ class Deserializer { Ptr = reinterpret_cast(N) | 0x1; } - uintptr_t getRawPtr() const { return Ptr; } + uintptr_t getFinalPtr() const { + assert (!(Ptr & 0x1) && "Backpatch pointer not yet deserialized."); + return Ptr; + } static inline bool isPod() { return true; } }; @@ -132,17 +135,30 @@ public: } template - void ReadPtr(T*& PtrRef) { ReadUIntPtr(reinterpret_cast(PtrRef));} - - void ReadPtr(uintptr_t& PtrRef) { ReadUIntPtr(PtrRef); } + void ReadPtr(T*& PtrRef) { + ReadUIntPtr(reinterpret_cast(PtrRef)); + } + template + void ReadPtr(const T*& PtrRef) { + ReadPtr(const_cast(PtrRef)); + } + void ReadUIntPtr(uintptr_t& PtrRef); + template + T& ReadRef() { + T* p = reinterpret_cast(ReadInternalRefPtr()); + return *p; + } + + void RegisterPtr(unsigned PtrId, void* Ptr); private: void ReadRecord(); bool inRecord(); + uintptr_t ReadInternalRefPtr(); }; } // end namespace llvm -- cgit v1.2.3-70-g09d2