summaryrefslogtreecommitdiff
path: root/llvm/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
commitfb764e52b0f47cd97f3389c1ad8a69291eb91324 (patch)
treecd12eeb36a95be23d0a93a523c8885e990d02ab5 /llvm/lib/Bitcode/Reader/Deserialize.cpp
parentdf0768e1b1d3cc9584179d170a7fb0359c78d00d (diff)
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. llvm-svn: 43595
Diffstat (limited to 'llvm/lib/Bitcode/Reader/Deserialize.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/Deserialize.cpp40
1 files changed, 19 insertions, 21 deletions
diff --git a/llvm/lib/Bitcode/Reader/Deserialize.cpp b/llvm/lib/Bitcode/Reader/Deserialize.cpp
index 9bc0f1578e79..e5a4d18aa2bf 100644
--- a/llvm/lib/Bitcode/Reader/Deserialize.cpp
+++ b/llvm/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);
}