summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-08 19:50:46 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-08 19:50:46 +0000
commit67135ebaff6428757c108f5187a05948ea01a831 (patch)
tree3a479c2d5e90d9b64946450ea5b38e5c0013d07b /llvm/lib/Bitcode
parent34660fb75acd0d072434890d22ccabeb5fdd911f (diff)
downloadbcm5719-llvm-67135ebaff6428757c108f5187a05948ea01a831.tar.gz
bcm5719-llvm-67135ebaff6428757c108f5187a05948ea01a831.zip
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(). llvm-svn: 43903
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r--llvm/lib/Bitcode/Reader/Deserialize.cpp29
-rw-r--r--llvm/lib/Bitcode/Writer/Serialize.cpp16
2 files changed, 38 insertions, 7 deletions
diff --git a/llvm/lib/Bitcode/Reader/Deserialize.cpp b/llvm/lib/Bitcode/Reader/Deserialize.cpp
index 99cb5d2e3ab..5d0c724b8b9 100644
--- a/llvm/lib/Bitcode/Reader/Deserialize.cpp
+++ b/llvm/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.");
diff --git a/llvm/lib/Bitcode/Writer/Serialize.cpp b/llvm/lib/Bitcode/Writer/Serialize.cpp
index b97462b629e..3baf9ad59aa 100644
--- a/llvm/lib/Bitcode/Writer/Serialize.cpp
+++ b/llvm/lib/Bitcode/Writer/Serialize.cpp
@@ -14,6 +14,10 @@
#include "llvm/Bitcode/Serialize.h"
#include "string.h"
+#ifdef DEBUG_BACKPATCH
+#include "llvm/Support/Streams.h"
+#endif
+
using namespace llvm;
Serializer::Serializer(BitstreamWriter& stream)
@@ -67,15 +71,13 @@ void Serializer::EmitCStr(const char* s, const char* end) {
Record.push_back(*s);
++s;
}
-
- EmitRecord();
}
void Serializer::EmitCStr(const char* s) {
EmitCStr(s,s+strlen(s));
}
-unsigned Serializer::getPtrId(const void* ptr) {
+SerializedPtrID Serializer::getPtrId(const void* ptr) {
if (!ptr)
return 0;
@@ -83,12 +85,20 @@ unsigned Serializer::getPtrId(const void* ptr) {
if (I == PtrMap.end()) {
unsigned id = PtrMap.size()+1;
+#ifdef DEBUG_BACKPATCH
+ llvm::cerr << "Registered PTR: " << ptr << " => " << id << "\n";
+#endif
PtrMap[ptr] = id;
return id;
}
else return I->second;
}
+bool Serializer::isRegistered(const void* ptr) const {
+ MapTy::const_iterator I = PtrMap.find(ptr);
+ return I != PtrMap.end();
+}
+
#define INT_EMIT(TYPE)\
void SerializeTrait<TYPE>::Emit(Serializer&S, TYPE X) { S.EmitInt(X); }
OpenPOWER on IntegriCloud