diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-10-25 00:10:21 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-10-25 00:10:21 +0000 |
commit | fe2a0123389adf0f2f66c413570d2daabdb5539d (patch) | |
tree | 43b79768756f6e621a013424fb535c458a85f16c /lib | |
parent | 8eadd5a6db79da067c773d1bd1cc13edc07788cc (diff) | |
download | external_llvm-fe2a0123389adf0f2f66c413570d2daabdb5539d.zip external_llvm-fe2a0123389adf0f2f66c413570d2daabdb5539d.tar.gz external_llvm-fe2a0123389adf0f2f66c413570d2daabdb5539d.tar.bz2 |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Bitcode/Reader/Deserialize.cpp | 54 | ||||
-rw-r--r-- | lib/Bitcode/Writer/Serialize.cpp | 12 |
2 files changed, 63 insertions, 3 deletions
diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp index cf5fe20..febb2d7 100644 --- a/lib/Bitcode/Reader/Deserialize.cpp +++ b/lib/Bitcode/Reader/Deserialize.cpp @@ -22,6 +22,21 @@ Deserializer::Deserializer(BitstreamReader& stream) Deserializer::~Deserializer() { assert (RecIdx >= Record.size() && "Still scanning bitcode record when deserialization completed."); + + BackpatchPointers(); +} + + +bool Deserializer::inRecord() { + if (Record.size() > 0) { + if (RecIdx >= Record.size()) { + RecIdx = 0; + Record.clear(); + return false; + } + else return true; + } + else return false; } void Deserializer::ReadRecord() { @@ -79,14 +94,49 @@ void Deserializer::ReadCStr(std::vector<char>& buff, bool isNullTerm) { buff.push_back('\0'); } +void Deserializer::RegisterPtr(unsigned PtrId,void* Ptr) { + BPatchEntry& E = BPatchMap[PtrId]; + assert (E.Ptr == NULL && "Pointer already registered."); + E.Ptr = Ptr; +} + +void Deserializer::ReadPtr(void*& PtrRef) { + unsigned PtrId = ReadInt(); + + BPatchEntry& E = BPatchMap[PtrId]; + + if (E.Ptr == NULL) { + // Register backpatch. + void* P = Allocator.Allocate<BPatchNode>(); + E.Head = new (P) BPatchNode(E.Head,PtrRef); + } + else + PtrRef = E.Ptr; +} + +void Deserializer::BackpatchPointers() { + for (MapTy::iterator I=BPatchMap.begin(),E=BPatchMap.end(); I!=E; ++I) { + + BPatchEntry& E = I->second; + assert (E.Ptr && "No pointer found for backpatch."); + + for (BPatchNode* N = E.Head; N != NULL; N = N->Next) + N->PtrRef = E.Ptr; + + E.Head = NULL; + } + + Allocator.Reset(); +} #define INT_READ(TYPE)\ void SerializeTrait<TYPE>::Read(Deserializer& D, TYPE& X) {\ - X = (TYPE) D.ReadInt(); } + X = (TYPE) D.ReadInt(); }\ +TYPE SerializeTrait<TYPE>::ReadVal(Deserializer& D) {\ + return (TYPE) D.ReadInt(); } INT_READ(bool) INT_READ(unsigned char) INT_READ(unsigned short) INT_READ(unsigned int) INT_READ(unsigned long) -INT_READ(unsigned long long) diff --git a/lib/Bitcode/Writer/Serialize.cpp b/lib/Bitcode/Writer/Serialize.cpp index 7293933..fbe1d10 100644 --- a/lib/Bitcode/Writer/Serialize.cpp +++ b/lib/Bitcode/Writer/Serialize.cpp @@ -57,6 +57,17 @@ void Serializer::EmitCStr(const char* s) { EmitCStr(s,s+strlen(s)); } +unsigned Serializer::getPtrId(void* ptr) { + MapTy::iterator I = PtrMap.find(ptr); + + if (I == PtrMap.end()) { + unsigned id = PtrMap.size(); + PtrMap[ptr] = id; + return id; + } + else return I->second; +} + #define INT_EMIT(TYPE)\ void SerializeTrait<TYPE>::Emit(Serializer&S, TYPE X) { S.EmitInt(X); } @@ -65,4 +76,3 @@ INT_EMIT(unsigned char) INT_EMIT(unsigned short) INT_EMIT(unsigned int) INT_EMIT(unsigned long) -INT_EMIT(unsigned long long) |