+ P1 = (ID1) ? SerializeTrait<T1>::Create(*this) : NULL;
+ if (ID1 && A1) RegisterPtr(ID1,P1);
+
+ P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
+ if (ID2 && A2) RegisterPtr(ID2,P2);
+ }
+
+ template <typename T1, typename T2, typename T3>
+ void BatchReadOwnedPtrs(T1*& P1, T2*& P2, T3*& P3,
+ bool A1=true, bool A2=true, bool A3=true) {
+
+ SerializedPtrID ID1 = ReadPtrID();
+ SerializedPtrID ID2 = ReadPtrID();
+ SerializedPtrID ID3 = ReadPtrID();
+
+ P1 = (ID1) ? SerializeTrait<T1>::Create(*this) : NULL;
+ if (ID1 && A1) RegisterPtr(ID1,P1);
+
+ P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
+ if (ID2 && A2) RegisterPtr(ID2,P2);
+
+ P3 = (ID3) ? SerializeTrait<T3>::Create(*this) : NULL;
+ if (ID3 && A3) RegisterPtr(ID3,P3);
+ }
+
+ template <typename T>
+ void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, bool AutoRegister=true) {
+ llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
+
+ for (unsigned i = 0; i < NumPtrs; ++i)
+ BatchIDVec.push_back(ReadPtrID());
+
+ for (unsigned i = 0; i < NumPtrs; ++i) {
+ SerializedPtrID& PtrID = BatchIDVec[i];
+
+ T* p = PtrID ? SerializeTrait<T>::Create(*this) : NULL;
+
+ if (PtrID && AutoRegister)
+ RegisterPtr(PtrID,p);
+
+ Ptrs[i] = p;
+ }
+ }
+
+ template <typename T1, typename T2>
+ void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2,
+ bool A1=true, bool A2=true) {
+
+ llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
+
+ for (unsigned i = 0; i < NumT1Ptrs; ++i)
+ BatchIDVec.push_back(ReadPtrID());
+
+ SerializedPtrID ID2 = ReadPtrID();
+
+ for (unsigned i = 0; i < NumT1Ptrs; ++i) {
+ SerializedPtrID& PtrID = BatchIDVec[i];
+
+ T1* p = PtrID ? SerializeTrait<T1>::Create(*this) : NULL;
+
+ if (PtrID && A1)
+ RegisterPtr(PtrID,p);
+
+ Ptrs[i] = p;
+ }
+
+ P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
+ if (ID2 && A2) RegisterPtr(ID2,P2);
+ }
+
+ template <typename T1, typename T2, typename T3>
+ void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs,
+ T2*& P2, T3*& P3,
+ bool A1=true, bool A2=true, bool A3=true) {
+
+ llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
+
+ for (unsigned i = 0; i < NumT1Ptrs; ++i)
+ BatchIDVec.push_back(ReadPtrID());
+
+ SerializedPtrID ID2 = ReadPtrID();
+ SerializedPtrID ID3 = ReadPtrID();
+
+ for (unsigned i = 0; i < NumT1Ptrs; ++i) {
+ SerializedPtrID& PtrID = BatchIDVec[i];
+
+ T1* p = PtrID ? SerializeTrait<T1>::Create(*this) : NULL;
+
+ if (PtrID && A1)
+ RegisterPtr(PtrID,p);
+
+ Ptrs[i] = p;
+ }
+
+ P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
+ if (ID2 && A2) RegisterPtr(ID2,P2);
+
+ P3 = (ID3) ? SerializeTrait<T3>::Create(*this) : NULL;
+ if (ID3 && A3) RegisterPtr(ID3,P3);
+ }
+
+ template <typename T>
+ void ReadPtr(T*& PtrRef, bool AllowBackpatch = true) {
+ ReadUIntPtr(reinterpret_cast<uintptr_t&>(PtrRef), AllowBackpatch);
+ }
+
+ template <typename T>
+ void ReadPtr(const T*& PtrRef, bool AllowBackpatch = true) {
+ ReadPtr(const_cast<T*&>(PtrRef), AllowBackpatch);
+ }
+
+
+ template <typename T>
+ void ReadPtr(T*& PtrRef, const SerializedPtrID& PtrID,
+ bool AllowBackpatch = true) {
+ ReadUIntPtr(reinterpret_cast<uintptr_t&>(PtrRef), PtrID, AllowBackpatch);
+ }
+
+ template <typename T>
+ void ReadPtr(const T*& PtrRef, const SerializedPtrID& PtrID,
+ bool AllowBackpatch = true) {
+
+ ReadPtr(const_cast<T*&>(PtrRef), PtrID, AllowBackpatch);
+ }
+
+ template <typename T>
+ T* ReadPtr() { T* x; ReadPtr<T>(x,false); return x; }
+
+ void ReadUIntPtr(uintptr_t& PtrRef, const SerializedPtrID& PtrID,
+ bool AllowBackpatch = true);
+
+ void ReadUIntPtr(uintptr_t& PtrRef, bool AllowBackpatch = true) {
+ ReadUIntPtr(PtrRef,ReadPtrID(),AllowBackpatch);
+ }
+
+ template <typename T>
+ T& ReadRef() {
+ T* p = reinterpret_cast<T*>(ReadInternalRefPtr());
+ return *p;
+ }
+
+ void RegisterPtr(const SerializedPtrID& PtrID, const void* Ptr);
+
+ void RegisterPtr(const void* Ptr) {
+ RegisterPtr(ReadPtrID(),Ptr);
+ }
+
+ template<typename T>
+ void RegisterRef(const T& x) {
+ RegisterPtr(&x);
+ }
+
+ template<typename T>
+ void RegisterRef(const SerializedPtrID& PtrID, const T& x) {
+ RegisterPtr(PtrID,&x);
+ }
+
+ Location getCurrentBlockLocation();
+ unsigned getCurrentBlockID();
+ unsigned getAbbrevNo();
+
+ bool FinishedBlock(Location BlockLoc);
+ bool JumpTo(const Location& BlockLoc);
+ void Rewind();
+
+ bool AtEnd();