2007-10-24 19:06:40 +00:00
|
|
|
//=- Deserialize.h - Generic Object Deserialization from Bitcode --*- C++ -*-=//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-10-24 19:06:40 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the interface for generic object deserialization from
|
|
|
|
// LLVM bitcode.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_BITCODE_SERIALIZE_INPUT
|
|
|
|
#define LLVM_BITCODE_SERIALIZE_INPUT
|
|
|
|
|
|
|
|
#include "llvm/Bitcode/BitstreamReader.h"
|
|
|
|
#include "llvm/Bitcode/Serialization.h"
|
2007-10-25 00:10:21 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/Support/Allocator.h"
|
2007-10-25 23:40:35 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2007-10-24 19:06:40 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class Deserializer {
|
2007-10-28 21:17:59 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------===//
|
|
|
|
// Internal type definitions.
|
|
|
|
//===----------------------------------------------------------===//
|
2007-10-25 00:10:21 +00:00
|
|
|
|
2007-10-28 21:17:59 +00:00
|
|
|
struct BPNode {
|
|
|
|
BPNode* Next;
|
2007-10-25 23:40:35 +00:00
|
|
|
uintptr_t& PtrRef;
|
2007-11-01 00:57:37 +00:00
|
|
|
|
2007-10-28 21:17:59 +00:00
|
|
|
BPNode(BPNode* n, uintptr_t& pref)
|
|
|
|
: Next(n), PtrRef(pref) {
|
2007-10-25 23:40:35 +00:00
|
|
|
PtrRef = 0;
|
|
|
|
}
|
2007-10-25 00:10:21 +00:00
|
|
|
};
|
|
|
|
|
2007-11-01 00:57:37 +00:00
|
|
|
struct BPEntry {
|
|
|
|
union { BPNode* Head; void* Ptr; };
|
|
|
|
|
|
|
|
BPEntry() : Head(NULL) {}
|
|
|
|
|
|
|
|
static inline bool isPod() { return true; }
|
|
|
|
|
|
|
|
void SetPtr(BPNode*& FreeList, void* P);
|
|
|
|
};
|
|
|
|
|
|
|
|
class BPKey {
|
|
|
|
unsigned Raw;
|
|
|
|
|
2007-10-28 21:17:59 +00:00
|
|
|
public:
|
2007-11-08 19:50:46 +00:00
|
|
|
BPKey(SerializedPtrID PtrId) : Raw(PtrId << 1) { assert (PtrId > 0); }
|
2007-11-05 18:13:03 +00:00
|
|
|
BPKey(unsigned code, unsigned) : Raw(code) {}
|
2007-10-28 21:17:59 +00:00
|
|
|
|
2007-11-01 00:57:37 +00:00
|
|
|
void MarkFinal() { Raw |= 0x1; }
|
|
|
|
bool hasFinalPtr() const { return Raw & 0x1 ? true : false; }
|
2007-11-08 19:50:46 +00:00
|
|
|
SerializedPtrID getID() const { return Raw >> 1; }
|
2007-10-28 21:17:59 +00:00
|
|
|
|
2007-11-05 18:13:03 +00:00
|
|
|
static inline BPKey getEmptyKey() { return BPKey(0,0); }
|
|
|
|
static inline BPKey getTombstoneKey() { return BPKey(1,0); }
|
2007-11-01 00:57:37 +00:00
|
|
|
static inline unsigned getHashValue(const BPKey& K) { return K.Raw & ~0x1; }
|
|
|
|
|
|
|
|
static bool isEqual(const BPKey& K1, const BPKey& K2) {
|
|
|
|
return (K1.Raw ^ K2.Raw) & ~0x1 ? false : true;
|
2007-10-28 21:17:59 +00:00
|
|
|
}
|
|
|
|
|
2007-11-01 00:57:37 +00:00
|
|
|
static bool isPod() { return true; }
|
2007-10-28 21:17:59 +00:00
|
|
|
};
|
2007-11-01 00:57:37 +00:00
|
|
|
|
|
|
|
typedef llvm::DenseMap<BPKey,BPEntry,BPKey,BPEntry> MapTy;
|
2007-10-25 00:10:21 +00:00
|
|
|
|
2007-10-28 21:17:59 +00:00
|
|
|
//===----------------------------------------------------------===//
|
2007-11-08 19:50:46 +00:00
|
|
|
// Publicly visible types.
|
2007-10-28 21:17:59 +00:00
|
|
|
//===----------------------------------------------------------===//
|
|
|
|
|
2007-11-08 19:50:46 +00:00
|
|
|
public:
|
2007-11-10 02:02:34 +00:00
|
|
|
struct Location {
|
|
|
|
uint64_t BitNo;
|
|
|
|
unsigned BlockID;
|
|
|
|
unsigned NumWords;
|
|
|
|
|
|
|
|
Location(uint64_t bit, unsigned bid, unsigned words)
|
|
|
|
: BitNo(bit), BlockID(bid), NumWords(words) {}
|
|
|
|
|
|
|
|
Location() : BitNo(0), BlockID(0), NumWords(0) {}
|
|
|
|
|
|
|
|
Location& operator=(Location& RHS) {
|
|
|
|
BitNo = RHS.BitNo;
|
|
|
|
BlockID = RHS.BlockID;
|
|
|
|
NumWords = RHS.NumWords;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const Location& RHS) const { return BitNo == RHS.BitNo; }
|
|
|
|
bool operator!=(const Location& RHS) const { return BitNo != RHS.BitNo; }
|
|
|
|
|
|
|
|
bool contains(const Location& RHS) const {
|
|
|
|
if (RHS.BitNo < BitNo)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((RHS.BitNo - BitNo) >> 5 < NumWords)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2007-11-08 19:50:46 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------===//
|
|
|
|
// Internal data members.
|
|
|
|
//===----------------------------------------------------------===//
|
|
|
|
|
|
|
|
private:
|
2007-10-28 21:17:59 +00:00
|
|
|
BitstreamReader& Stream;
|
2007-11-09 00:43:51 +00:00
|
|
|
SmallVector<uint64_t,20> Record;
|
2007-10-28 21:17:59 +00:00
|
|
|
unsigned RecIdx;
|
|
|
|
BumpPtrAllocator Allocator;
|
|
|
|
BPNode* FreeList;
|
2007-11-08 19:50:46 +00:00
|
|
|
MapTy BPatchMap;
|
2007-11-10 02:02:34 +00:00
|
|
|
llvm::SmallVector<Location,8> BlockStack;
|
2007-11-09 00:43:51 +00:00
|
|
|
unsigned AbbrevNo;
|
|
|
|
unsigned RecordCode;
|
2007-11-30 22:45:05 +00:00
|
|
|
uint64_t StreamStart;
|
2007-10-25 00:10:21 +00:00
|
|
|
|
2007-10-28 21:17:59 +00:00
|
|
|
//===----------------------------------------------------------===//
|
|
|
|
// Public Interface.
|
|
|
|
//===----------------------------------------------------------===//
|
|
|
|
|
2007-11-08 19:50:46 +00:00
|
|
|
public:
|
2007-10-24 19:06:40 +00:00
|
|
|
Deserializer(BitstreamReader& stream);
|
|
|
|
~Deserializer();
|
2007-10-25 00:10:21 +00:00
|
|
|
|
|
|
|
uint64_t ReadInt();
|
2007-11-07 18:24:34 +00:00
|
|
|
int64_t ReadSInt();
|
2007-11-08 19:50:46 +00:00
|
|
|
SerializedPtrID ReadPtrID() { return (SerializedPtrID) ReadInt(); }
|
|
|
|
|
2007-11-07 18:24:34 +00:00
|
|
|
|
2007-10-25 00:10:21 +00:00
|
|
|
bool ReadBool() {
|
|
|
|
return ReadInt() ? true : false;
|
|
|
|
}
|
|
|
|
|
2007-10-24 19:06:40 +00:00
|
|
|
template <typename T>
|
|
|
|
inline T& Read(T& X) {
|
|
|
|
SerializeTrait<T>::Read(*this,X);
|
|
|
|
return X;
|
|
|
|
}
|
2007-10-25 00:10:21 +00:00
|
|
|
|
2007-10-24 19:06:40 +00:00
|
|
|
template <typename T>
|
2007-11-13 00:25:08 +00:00
|
|
|
inline T* Create() {
|
|
|
|
return SerializeTrait<T>::Create(*this);
|
2007-10-24 19:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char* ReadCStr(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true);
|
2007-12-17 22:25:12 +00:00
|
|
|
void ReadCStr(std::vector<char>& buff, bool isNullTerm=false, unsigned Idx=0);
|
2007-10-25 00:10:21 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2007-11-06 22:21:14 +00:00
|
|
|
inline T* ReadOwnedPtr(bool AutoRegister = true) {
|
2007-11-08 19:50:46 +00:00
|
|
|
SerializedPtrID PtrID = ReadPtrID();
|
2007-10-25 18:42:52 +00:00
|
|
|
|
2007-11-07 22:30:29 +00:00
|
|
|
if (!PtrID)
|
2007-10-25 18:42:52 +00:00
|
|
|
return NULL;
|
|
|
|
|
2007-11-13 00:25:08 +00:00
|
|
|
T* x = SerializeTrait<T>::Create(*this);
|
2007-11-07 22:30:29 +00:00
|
|
|
|
2007-11-06 22:21:14 +00:00
|
|
|
if (AutoRegister)
|
2007-11-07 22:30:29 +00:00
|
|
|
RegisterPtr(PtrID,x);
|
2007-11-06 22:21:14 +00:00
|
|
|
|
2007-10-25 00:10:21 +00:00
|
|
|
return x;
|
|
|
|
}
|
2008-04-07 21:36:46 +00:00
|
|
|
|
|
|
|
template <typename T, typename Arg1>
|
|
|
|
inline T* ReadOwnedPtr(Arg1& arg1, bool AutoRegister = true) {
|
|
|
|
SerializedPtrID PtrID = ReadPtrID();
|
|
|
|
|
|
|
|
if (!PtrID)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
T* x = SerializeTrait<T>::Create(*this, arg1);
|
|
|
|
|
|
|
|
if (AutoRegister)
|
|
|
|
RegisterPtr(PtrID,x);
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2007-11-02 18:04:20 +00:00
|
|
|
template <typename T>
|
2007-11-06 22:21:14 +00:00
|
|
|
inline void ReadOwnedPtr(T*& Ptr, bool AutoRegister = true) {
|
|
|
|
Ptr = ReadOwnedPtr<T>(AutoRegister);
|
2007-11-02 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2007-11-07 22:30:29 +00:00
|
|
|
template <typename T1, typename T2>
|
|
|
|
void BatchReadOwnedPtrs(T1*& P1, T2*& P2,
|
|
|
|
bool A1=true, bool A2=true) {
|
|
|
|
|
2007-11-08 19:50:46 +00:00
|
|
|
SerializedPtrID ID1 = ReadPtrID();
|
2007-11-17 03:34:33 +00:00
|
|
|
SerializedPtrID ID2 = ReadPtrID();
|
2007-11-07 22:30:29 +00:00
|
|
|
|
2007-11-13 00:25:08 +00:00
|
|
|
P1 = (ID1) ? SerializeTrait<T1>::Create(*this) : NULL;
|
2007-11-07 22:30:29 +00:00
|
|
|
if (ID1 && A1) RegisterPtr(ID1,P1);
|
|
|
|
|
2007-11-13 00:25:08 +00:00
|
|
|
P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
|
2007-11-07 22:30:29 +00:00
|
|
|
if (ID2 && A2) RegisterPtr(ID2,P2);
|
|
|
|
}
|
|
|
|
|
2008-04-07 21:36:46 +00:00
|
|
|
template <typename T1, typename T2, typename Arg1>
|
|
|
|
void BatchReadOwnedPtrs(T1*& P1, T2*& P2, Arg1& arg1,
|
|
|
|
bool A1=true, bool A2=true) {
|
|
|
|
|
|
|
|
SerializedPtrID ID1 = ReadPtrID();
|
|
|
|
SerializedPtrID ID2 = ReadPtrID();
|
|
|
|
|
|
|
|
P1 = (ID1) ? SerializeTrait<T1>::Create(*this, arg1) : NULL;
|
|
|
|
if (ID1 && A1) RegisterPtr(ID1,P1);
|
|
|
|
|
|
|
|
P2 = (ID2) ? SerializeTrait<T2>::Create(*this, arg1) : NULL;
|
|
|
|
if (ID2 && A2) RegisterPtr(ID2,P2);
|
|
|
|
}
|
|
|
|
|
2007-11-07 22:30:29 +00:00
|
|
|
template <typename T1, typename T2, typename T3>
|
|
|
|
void BatchReadOwnedPtrs(T1*& P1, T2*& P2, T3*& P3,
|
|
|
|
bool A1=true, bool A2=true, bool A3=true) {
|
|
|
|
|
2007-11-08 19:50:46 +00:00
|
|
|
SerializedPtrID ID1 = ReadPtrID();
|
2007-11-17 03:34:33 +00:00
|
|
|
SerializedPtrID ID2 = ReadPtrID();
|
|
|
|
SerializedPtrID ID3 = ReadPtrID();
|
2007-11-07 22:30:29 +00:00
|
|
|
|
2007-11-13 00:25:08 +00:00
|
|
|
P1 = (ID1) ? SerializeTrait<T1>::Create(*this) : NULL;
|
2007-11-07 22:30:29 +00:00
|
|
|
if (ID1 && A1) RegisterPtr(ID1,P1);
|
|
|
|
|
2007-11-13 00:25:08 +00:00
|
|
|
P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
|
2007-11-07 22:30:29 +00:00
|
|
|
if (ID2 && A2) RegisterPtr(ID2,P2);
|
|
|
|
|
2007-11-17 00:40:45 +00:00
|
|
|
P3 = (ID3) ? SerializeTrait<T3>::Create(*this) : NULL;
|
2007-11-07 22:30:29 +00:00
|
|
|
if (ID3 && A3) RegisterPtr(ID3,P3);
|
|
|
|
}
|
2008-04-07 21:36:46 +00:00
|
|
|
|
|
|
|
template <typename T1, typename T2, typename T3, typename Arg1>
|
|
|
|
void BatchReadOwnedPtrs(T1*& P1, T2*& P2, T3*& P3, Arg1& arg1,
|
|
|
|
bool A1=true, bool A2=true, bool A3=true) {
|
|
|
|
|
|
|
|
SerializedPtrID ID1 = ReadPtrID();
|
|
|
|
SerializedPtrID ID2 = ReadPtrID();
|
|
|
|
SerializedPtrID ID3 = ReadPtrID();
|
|
|
|
|
|
|
|
P1 = (ID1) ? SerializeTrait<T1>::Create(*this, arg1) : NULL;
|
|
|
|
if (ID1 && A1) RegisterPtr(ID1,P1);
|
|
|
|
|
|
|
|
P2 = (ID2) ? SerializeTrait<T2>::Create(*this, arg1) : NULL;
|
|
|
|
if (ID2 && A2) RegisterPtr(ID2,P2);
|
|
|
|
|
|
|
|
P3 = (ID3) ? SerializeTrait<T3>::Create(*this, arg1) : NULL;
|
|
|
|
if (ID3 && A3) RegisterPtr(ID3,P3);
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:18:40 +00:00
|
|
|
template <typename T>
|
2007-11-08 00:04:50 +00:00
|
|
|
void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, bool AutoRegister=true) {
|
2007-11-15 00:05:03 +00:00
|
|
|
llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
|
2007-11-10 19:33:26 +00:00
|
|
|
|
2007-11-17 03:34:33 +00:00
|
|
|
for (unsigned i = 0; i < NumPtrs; ++i)
|
|
|
|
BatchIDVec.push_back(ReadPtrID());
|
2007-11-08 00:04:50 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < NumPtrs; ++i) {
|
2007-11-10 19:28:49 +00:00
|
|
|
SerializedPtrID& PtrID = BatchIDVec[i];
|
|
|
|
|
2007-11-13 00:25:08 +00:00
|
|
|
T* p = PtrID ? SerializeTrait<T>::Create(*this) : NULL;
|
2007-11-08 00:04:50 +00:00
|
|
|
|
|
|
|
if (PtrID && AutoRegister)
|
|
|
|
RegisterPtr(PtrID,p);
|
|
|
|
|
|
|
|
Ptrs[i] = p;
|
|
|
|
}
|
2007-11-13 00:13:57 +00:00
|
|
|
}
|
|
|
|
|
2008-04-07 21:36:46 +00:00
|
|
|
template <typename T, typename Arg1>
|
|
|
|
void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, Arg1& arg1,
|
|
|
|
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, arg1) : NULL;
|
|
|
|
|
|
|
|
if (PtrID && AutoRegister)
|
|
|
|
RegisterPtr(PtrID,p);
|
|
|
|
|
|
|
|
Ptrs[i] = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 08:05:03 +00:00
|
|
|
template <typename T1, typename T2>
|
|
|
|
void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2,
|
|
|
|
bool A1=true, bool A2=true) {
|
2007-11-17 00:40:45 +00:00
|
|
|
|
2007-11-17 03:34:33 +00:00
|
|
|
llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < NumT1Ptrs; ++i)
|
|
|
|
BatchIDVec.push_back(ReadPtrID());
|
2007-11-17 00:40:45 +00:00
|
|
|
|
2007-11-17 03:34:33 +00:00
|
|
|
SerializedPtrID ID2 = ReadPtrID();
|
2007-11-14 08:05:03 +00:00
|
|
|
|
|
|
|
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;
|
2007-11-17 03:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
P2 = (ID2) ? SerializeTrait<T2>::Create(*this) : NULL;
|
|
|
|
if (ID2 && A2) RegisterPtr(ID2,P2);
|
2007-11-14 08:05:03 +00:00
|
|
|
}
|
|
|
|
|
2008-04-07 21:36:46 +00:00
|
|
|
template <typename T1, typename T2, typename Arg1>
|
|
|
|
void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2, Arg1& arg1,
|
|
|
|
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, arg1) : NULL;
|
|
|
|
|
|
|
|
if (PtrID && A1)
|
|
|
|
RegisterPtr(PtrID,p);
|
|
|
|
|
|
|
|
Ptrs[i] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
P2 = (ID2) ? SerializeTrait<T2>::Create(*this, arg1) : NULL;
|
|
|
|
if (ID2 && A2) RegisterPtr(ID2,P2);
|
|
|
|
}
|
|
|
|
|
2007-11-13 00:13:57 +00:00
|
|
|
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) {
|
|
|
|
|
2007-11-15 00:05:03 +00:00
|
|
|
llvm::SmallVector<SerializedPtrID,10> BatchIDVec;
|
2007-11-13 00:13:57 +00:00
|
|
|
|
2007-11-17 03:34:33 +00:00
|
|
|
for (unsigned i = 0; i < NumT1Ptrs; ++i)
|
|
|
|
BatchIDVec.push_back(ReadPtrID());
|
2007-11-17 00:40:45 +00:00
|
|
|
|
2007-11-17 03:34:33 +00:00
|
|
|
SerializedPtrID ID2 = ReadPtrID();
|
|
|
|
SerializedPtrID ID3 = ReadPtrID();
|
2007-11-13 00:13:57 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < NumT1Ptrs; ++i) {
|
|
|
|
SerializedPtrID& PtrID = BatchIDVec[i];
|
|
|
|
|
2007-11-13 00:25:08 +00:00
|
|
|
T1* p = PtrID ? SerializeTrait<T1>::Create(*this) : NULL;
|
2007-11-13 00:13:57 +00:00
|
|
|
|
|
|
|
if (PtrID && A1)
|
|
|
|
RegisterPtr(PtrID,p);
|
|
|
|
|
|
|
|
Ptrs[i] = p;
|
|
|
|
}
|
2007-11-17 03:34:33 +00:00
|
|
|
|
|
|
|
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);
|
2007-11-08 00:04:50 +00:00
|
|
|
}
|
2008-04-07 21:36:46 +00:00
|
|
|
|
|
|
|
template <typename T1, typename T2, typename T3, typename Arg1>
|
|
|
|
void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs,
|
|
|
|
T2*& P2, T3*& P3, Arg1& arg1,
|
|
|
|
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, arg1) : NULL;
|
|
|
|
|
|
|
|
if (PtrID && A1)
|
|
|
|
RegisterPtr(PtrID,p);
|
|
|
|
|
|
|
|
Ptrs[i] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
P2 = (ID2) ? SerializeTrait<T2>::Create(*this, arg1) : NULL;
|
|
|
|
if (ID2 && A2) RegisterPtr(ID2,P2);
|
|
|
|
|
|
|
|
P3 = (ID3) ? SerializeTrait<T3>::Create(*this, arg1) : NULL;
|
|
|
|
if (ID3 && A3) RegisterPtr(ID3,P3);
|
|
|
|
}
|
|
|
|
|
2007-10-28 21:17:59 +00:00
|
|
|
template <typename T>
|
2007-11-06 22:21:14 +00:00
|
|
|
void ReadPtr(T*& PtrRef, bool AllowBackpatch = true) {
|
|
|
|
ReadUIntPtr(reinterpret_cast<uintptr_t&>(PtrRef), AllowBackpatch);
|
2007-10-31 19:58:32 +00:00
|
|
|
}
|
2007-10-28 21:17:59 +00:00
|
|
|
|
2007-10-31 19:58:32 +00:00
|
|
|
template <typename T>
|
2007-11-06 22:21:14 +00:00
|
|
|
void ReadPtr(const T*& PtrRef, bool AllowBackpatch = true) {
|
|
|
|
ReadPtr(const_cast<T*&>(PtrRef), AllowBackpatch);
|
2007-11-07 00:47:33 +00:00
|
|
|
}
|
|
|
|
|
2007-11-12 19:11:15 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2007-11-13 00:25:08 +00:00
|
|
|
void ReadPtr(T*& PtrRef, const SerializedPtrID& PtrID,
|
|
|
|
bool AllowBackpatch = true) {
|
2007-11-12 19:11:15 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-11-07 00:47:33 +00:00
|
|
|
template <typename T>
|
2008-05-01 17:08:00 +00:00
|
|
|
T* ReadPtr() { T* x = 0; ReadPtr<T>(x,false); return x; }
|
2007-10-31 19:58:32 +00:00
|
|
|
|
2007-11-12 19:11:15 +00:00
|
|
|
void ReadUIntPtr(uintptr_t& PtrRef, const SerializedPtrID& PtrID,
|
|
|
|
bool AllowBackpatch = true);
|
|
|
|
|
|
|
|
void ReadUIntPtr(uintptr_t& PtrRef, bool AllowBackpatch = true) {
|
|
|
|
ReadUIntPtr(PtrRef,ReadPtrID(),AllowBackpatch);
|
|
|
|
}
|
2007-10-26 20:23:27 +00:00
|
|
|
|
2007-10-31 19:58:32 +00:00
|
|
|
template <typename T>
|
|
|
|
T& ReadRef() {
|
|
|
|
T* p = reinterpret_cast<T*>(ReadInternalRefPtr());
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
|
2007-11-12 19:11:15 +00:00
|
|
|
void RegisterPtr(const SerializedPtrID& PtrID, const void* Ptr);
|
2007-10-31 19:58:32 +00:00
|
|
|
|
2007-10-31 22:42:03 +00:00
|
|
|
void RegisterPtr(const void* Ptr) {
|
2007-11-08 19:50:46 +00:00
|
|
|
RegisterPtr(ReadPtrID(),Ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void RegisterRef(const T& x) {
|
|
|
|
RegisterPtr(&x);
|
2007-10-31 22:42:03 +00:00
|
|
|
}
|
2007-11-05 21:36:35 +00:00
|
|
|
|
2007-11-08 19:50:46 +00:00
|
|
|
template<typename T>
|
2007-11-12 19:11:15 +00:00
|
|
|
void RegisterRef(const SerializedPtrID& PtrID, const T& x) {
|
2007-11-08 19:50:46 +00:00
|
|
|
RegisterPtr(PtrID,&x);
|
|
|
|
}
|
|
|
|
|
2007-11-09 00:43:51 +00:00
|
|
|
Location getCurrentBlockLocation();
|
|
|
|
unsigned getCurrentBlockID();
|
|
|
|
unsigned getAbbrevNo();
|
|
|
|
|
2007-11-08 19:50:46 +00:00
|
|
|
bool FinishedBlock(Location BlockLoc);
|
2007-11-10 02:02:34 +00:00
|
|
|
bool JumpTo(const Location& BlockLoc);
|
2007-11-30 22:45:05 +00:00
|
|
|
void Rewind();
|
2007-11-08 19:50:46 +00:00
|
|
|
|
2007-11-05 21:36:35 +00:00
|
|
|
bool AtEnd();
|
2007-11-06 19:49:16 +00:00
|
|
|
bool inRecord();
|
2007-11-09 00:43:51 +00:00
|
|
|
void SkipBlock();
|
2007-11-10 02:02:34 +00:00
|
|
|
bool SkipToBlock(unsigned BlockID);
|
2007-11-09 00:43:51 +00:00
|
|
|
|
|
|
|
unsigned getRecordCode();
|
2007-11-08 19:50:46 +00:00
|
|
|
|
2007-11-10 02:02:34 +00:00
|
|
|
BitstreamReader& getStream() { return Stream; }
|
|
|
|
|
2007-10-24 19:06:40 +00:00
|
|
|
private:
|
2007-11-09 00:43:51 +00:00
|
|
|
bool AdvanceStream();
|
|
|
|
void ReadRecord();
|
|
|
|
|
2007-10-31 19:58:32 +00:00
|
|
|
uintptr_t ReadInternalRefPtr();
|
2007-11-01 00:57:37 +00:00
|
|
|
|
|
|
|
static inline bool HasFinalPtr(MapTy::value_type& V) {
|
|
|
|
return V.first.hasFinalPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uintptr_t GetFinalPtr(MapTy::value_type& V) {
|
|
|
|
return reinterpret_cast<uintptr_t>(V.second.Ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BPNode* GetBPNode(MapTy::value_type& V) {
|
|
|
|
return V.second.Head;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SetBPNode(MapTy::value_type& V, BPNode* N) {
|
|
|
|
V.second.Head = N;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPtr(MapTy::value_type& V, const void* P) {
|
|
|
|
V.first.MarkFinal();
|
|
|
|
V.second.SetPtr(FreeList,const_cast<void*>(P));
|
|
|
|
}
|
2007-10-24 19:06:40 +00:00
|
|
|
};
|
2007-10-25 00:10:21 +00:00
|
|
|
|
2007-10-24 19:06:40 +00:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|