diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-11-08 19:50:46 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-11-08 19:50:46 +0000 |
commit | ec8cd0655523627004ae4dac8e363ffa7bd25936 (patch) | |
tree | d52777fd7834c4670b697826a2f9dd103f697672 /lib/Bitcode/Reader/Deserialize.cpp | |
parent | b410df995c592491746ed76039edb62f5cdbf8cf (diff) |
Added typedef "SerializedPtrID" to represent the pointer handle written to disk
instead of just using "unsigned". This gives us more flexibility in changing
the definition of the handle later, and is more self-documenting.
Added tracking of block stack in the Deserializer. Now clients can query
if they are still within a block using the methods GetCurrentBlockLocation()
and FinishedBlock().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43903 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Reader/Deserialize.cpp')
-rw-r--r-- | lib/Bitcode/Reader/Deserialize.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp index 99cb5d2e3a..5d0c724b8b 100644 --- a/lib/Bitcode/Reader/Deserialize.cpp +++ b/lib/Bitcode/Reader/Deserialize.cpp @@ -63,15 +63,16 @@ void Deserializer::ReadRecord() { Code = Stream.ReadCode(); if (Code == bitc::ENTER_SUBBLOCK) { - // No known subblocks, always skip them. + BlockLocs.push_back(Stream.GetCurrentBitNo()); unsigned id = Stream.ReadSubBlockID(); Stream.EnterSubBlock(id); continue; } - if (Code == bitc::END_BLOCK) { + if (Code == bitc::END_BLOCK) { bool x = Stream.ReadBlockEnd(); assert (!x && "Error at block end."); + BlockLocs.pop_back(); continue; } @@ -88,6 +89,26 @@ void Deserializer::ReadRecord() { assert (Record.size() > 0 || Stream.AtEndOfStream()); } +Deserializer::Location Deserializer::GetCurrentBlockLocation() { + if (!inRecord()) + ReadRecord(); + + assert (!BlockLocs.empty()); + return BlockLocs.back(); +} + +bool Deserializer::FinishedBlock(Location BlockLoc) { + if (!inRecord()) + ReadRecord(); + + for (llvm::SmallVector<Location,5>::reverse_iterator + I=BlockLocs.rbegin(), E=BlockLocs.rend(); I!=E; ++I) + if (*I == BlockLoc) + return false; + + return true; +} + bool Deserializer::AtEnd() { if (inRecord()) return false; @@ -159,7 +180,7 @@ void Deserializer::RegisterPtr(unsigned PtrId, const void* Ptr) { } void Deserializer::ReadUIntPtr(uintptr_t& PtrRef, bool AllowBackpatch) { - unsigned PtrId = ReadInt(); + SerializedPtrID PtrId = ReadPtrID(); if (PtrId == 0) { PtrRef = 0; @@ -194,7 +215,7 @@ void Deserializer::ReadUIntPtr(uintptr_t& PtrRef, bool AllowBackpatch) { } uintptr_t Deserializer::ReadInternalRefPtr() { - unsigned PtrId = ReadInt(); + SerializedPtrID PtrId = ReadPtrID(); assert (PtrId != 0 && "References cannot refer the NULL address."); |