mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 18:24:00 +00:00
Implemented prototype serialization of pointers, including support
for backpatching. Added Deserialize::ReadVal. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43319 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -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 <vector>
|
||||
|
||||
namespace llvm {
|
||||
@ -25,50 +28,79 @@ class Deserializer {
|
||||
BitstreamReader& Stream;
|
||||
SmallVector<uint64_t,10> 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<unsigned,BPatchEntry,PtrIdInfo,BPatchEntry> MapTy;
|
||||
|
||||
MapTy BPatchMap;
|
||||
|
||||
public:
|
||||
Deserializer(BitstreamReader& stream);
|
||||
~Deserializer();
|
||||
|
||||
|
||||
uint64_t ReadInt();
|
||||
bool ReadBool() {
|
||||
return ReadInt() ? true : false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T& Read(T& X) {
|
||||
SerializeTrait<T>::Read(*this,X);
|
||||
return X;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T ReadVal() {
|
||||
return SerializeTrait<T>::ReadVal(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T* Materialize() {
|
||||
return SerializeTrait<T>::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 <typename EnumT>
|
||||
EnumT ReadEnum(unsigned MinVal, unsigned MaxVal) {
|
||||
return static_cast<EnumT>(ReadInt(32));
|
||||
}
|
||||
|
||||
char* ReadCStr(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true);
|
||||
void ReadCStr(std::vector<char>& buff, bool isNullTerm=false);
|
||||
|
||||
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;
|
||||
|
||||
template <typename T>
|
||||
inline T* ReadOwnedPtr() {
|
||||
unsigned PtrId = ReadInt();
|
||||
T* x = SerializeTrait<T>::Materialize(*this);
|
||||
RegisterPtr(PtrId,x);
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
void ReadPtr(void*& PtrRef);
|
||||
void RegisterPtr(unsigned PtrId, void* Ptr);
|
||||
|
||||
|
||||
void BackpatchPointers();
|
||||
private:
|
||||
void ReadRecord();
|
||||
bool inRecord();
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user