summaryrefslogtreecommitdiff
path: root/lib/Bitcode/Reader/Deserialize.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-01 00:57:37 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-01 00:57:37 +0000
commit066ff5b7f2de0fd263269e822858aa174e162a89 (patch)
tree998754ed112887ed825a90888a582f914431ad8a /lib/Bitcode/Reader/Deserialize.cpp
parentaef806e9cb021919be8f3a988af0478f3da75758 (diff)
downloadllvm-066ff5b7f2de0fd263269e822858aa174e162a89.tar.gz
llvm-066ff5b7f2de0fd263269e822858aa174e162a89.tar.bz2
llvm-066ff5b7f2de0fd263269e822858aa174e162a89.tar.xz
Rewrote backpatcher. Backpatcher now stores the "has final pointer"
flag in the **key** of the backpatch map, as opposed to the mapped value which contains either the final pointer, or a pointer to a chain of pointers that need to be backpatched. The bit flag was moved to the key because we were erroneously assuming that the backpatched pointers would be at an alignment of >= 2 bytes, which obviously doesn't work for character strings. Now we just steal the bit from the key. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43595 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Reader/Deserialize.cpp')
-rw-r--r--lib/Bitcode/Reader/Deserialize.cpp40
1 files changed, 19 insertions, 21 deletions
diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp
index 9bc0f1578e..e5a4d18aa2 100644
--- a/lib/Bitcode/Reader/Deserialize.cpp
+++ b/lib/Bitcode/Reader/Deserialize.cpp
@@ -25,7 +25,7 @@ Deserializer::~Deserializer() {
#ifdef NDEBUG
for (MapTy::iterator I=BPatchMap.begin(), E=BPatchMap.end(); I!=E; ++I)
- assert (I->second.hasFinalPtr() &&
+ assert (I->first.hasFinalPtr() &&
"Some pointers were not backpatched.");
#endif
}
@@ -99,9 +99,11 @@ void Deserializer::ReadCStr(std::vector<char>& buff, bool isNullTerm) {
}
void Deserializer::RegisterPtr(unsigned PtrId, const void* Ptr) {
- BPatchEntry& E = BPatchMap[PtrId];
- assert (!E.hasFinalPtr() && "Pointer already registered.");
- E.setFinalPtr(FreeList,Ptr);
+ MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId));
+
+ assert (!HasFinalPtr(E) && "Pointer already registered.");
+
+ SetPtr(E,Ptr);
}
void Deserializer::ReadUIntPtr(uintptr_t& PtrRef) {
@@ -111,11 +113,11 @@ void Deserializer::ReadUIntPtr(uintptr_t& PtrRef) {
PtrRef = 0;
return;
}
+
+ MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId));
- BPatchEntry& E = BPatchMap[PtrId];
-
- if (E.hasFinalPtr())
- PtrRef = E.getFinalPtr();
+ if (HasFinalPtr(E))
+ PtrRef = GetFinalPtr(E);
else {
// Register backpatch. Check the freelist for a BPNode.
BPNode* N;
@@ -127,8 +129,8 @@ void Deserializer::ReadUIntPtr(uintptr_t& PtrRef) {
else // No available BPNode. Allocate one.
N = (BPNode*) Allocator.Allocate<BPNode>();
- new (N) BPNode(E.getBPNode(),PtrRef);
- E.setBPNode(N);
+ new (N) BPNode(GetBPNode(E),PtrRef);
+ SetBPNode(E,N);
}
}
@@ -137,32 +139,28 @@ uintptr_t Deserializer::ReadInternalRefPtr() {
assert (PtrId != 0 && "References cannot refer the NULL address.");
- BPatchEntry& E = BPatchMap[PtrId];
+ MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId));
- assert (E.hasFinalPtr() &&
+ assert (!HasFinalPtr(E) &&
"Cannot backpatch references. Object must be already deserialized.");
- return E.getFinalPtr();
+ return GetFinalPtr(E);
}
-void Deserializer::BPatchEntry::setFinalPtr(BPNode*& FreeList, const void* P) {
- assert (!hasFinalPtr());
-
- // Perform backpatching.
-
+void Deserializer::BPEntry::SetPtr(BPNode*& FreeList, void* P) {
BPNode* Last = NULL;
- for (BPNode* N = getBPNode() ; N != NULL; N = N->Next) {
+ for (BPNode* N = Head; N != NULL; N=N->Next) {
Last = N;
N->PtrRef |= reinterpret_cast<uintptr_t>(P);
}
if (Last) {
Last->Next = FreeList;
- FreeList = getBPNode();
+ FreeList = Head;
}
- Ptr = reinterpret_cast<uintptr_t>(P);
+ Ptr = const_cast<void*>(P);
}