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
This commit is contained in:
Ted Kremenek
2007-11-01 00:57:37 +00:00
parent aef806e9cb
commit 066ff5b7f2
2 changed files with 69 additions and 55 deletions

View File

@ -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);
}