mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-16 11:24:39 +00:00
Updated Deserializer class to provide more information about the current
block that is being visited in the bitstream. The client can also now skip blocks before reading them, and query the current abbreviation number as seen from the perspective of the Deserializer. This allows the client to be more interactive in the deserialization process (if they so choose). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43916 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -88,12 +88,14 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BitstreamReader& Stream;
|
BitstreamReader& Stream;
|
||||||
SmallVector<uint64_t,10> Record;
|
SmallVector<uint64_t,20> Record;
|
||||||
unsigned RecIdx;
|
unsigned RecIdx;
|
||||||
BumpPtrAllocator Allocator;
|
BumpPtrAllocator Allocator;
|
||||||
BPNode* FreeList;
|
BPNode* FreeList;
|
||||||
MapTy BPatchMap;
|
MapTy BPatchMap;
|
||||||
llvm::SmallVector<uint64_t,5> BlockLocs;
|
llvm::SmallVector<std::pair<Location,unsigned>,5> BlockStack;
|
||||||
|
unsigned AbbrevNo;
|
||||||
|
unsigned RecordCode;
|
||||||
|
|
||||||
//===----------------------------------------------------------===//
|
//===----------------------------------------------------------===//
|
||||||
// Public Interface.
|
// Public Interface.
|
||||||
@@ -231,14 +233,22 @@ public:
|
|||||||
RegisterPtr(PtrID,&x);
|
RegisterPtr(PtrID,&x);
|
||||||
}
|
}
|
||||||
|
|
||||||
Location GetCurrentBlockLocation();
|
Location getCurrentBlockLocation();
|
||||||
|
unsigned getCurrentBlockID();
|
||||||
|
unsigned getAbbrevNo();
|
||||||
|
|
||||||
bool FinishedBlock(Location BlockLoc);
|
bool FinishedBlock(Location BlockLoc);
|
||||||
|
|
||||||
bool AtEnd();
|
bool AtEnd();
|
||||||
bool inRecord();
|
bool inRecord();
|
||||||
|
void SkipBlock();
|
||||||
|
|
||||||
|
unsigned getRecordCode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ReadRecord();
|
bool AdvanceStream();
|
||||||
|
void ReadRecord();
|
||||||
|
|
||||||
uintptr_t ReadInternalRefPtr();
|
uintptr_t ReadInternalRefPtr();
|
||||||
|
|
||||||
static inline bool HasFinalPtr(MapTy::value_type& V) {
|
static inline bool HasFinalPtr(MapTy::value_type& V) {
|
||||||
|
@@ -20,14 +20,14 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
Deserializer::Deserializer(BitstreamReader& stream)
|
Deserializer::Deserializer(BitstreamReader& stream)
|
||||||
: Stream(stream), RecIdx(0), FreeList(NULL) {
|
: Stream(stream), RecIdx(0), FreeList(NULL), AbbrevNo(0), RecordCode(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Deserializer::~Deserializer() {
|
Deserializer::~Deserializer() {
|
||||||
assert (RecIdx >= Record.size() &&
|
assert (RecIdx >= Record.size() &&
|
||||||
"Still scanning bitcode record when deserialization completed.");
|
"Still scanning bitcode record when deserialization completed.");
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef DEBUG_BACKPATCH
|
||||||
for (MapTy::iterator I=BPatchMap.begin(), E=BPatchMap.end(); I!=E; ++I)
|
for (MapTy::iterator I=BPatchMap.begin(), E=BPatchMap.end(); I!=E; ++I)
|
||||||
assert (I->first.hasFinalPtr() &&
|
assert (I->first.hasFinalPtr() &&
|
||||||
"Some pointers were not backpatched.");
|
"Some pointers were not backpatched.");
|
||||||
@@ -40,82 +40,131 @@ bool Deserializer::inRecord() {
|
|||||||
if (RecIdx >= Record.size()) {
|
if (RecIdx >= Record.size()) {
|
||||||
RecIdx = 0;
|
RecIdx = 0;
|
||||||
Record.clear();
|
Record.clear();
|
||||||
|
AbbrevNo = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else return true;
|
else
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Deserializer::AdvanceStream() {
|
||||||
|
assert (!inRecord() &&
|
||||||
|
"Cannot advance stream. Still processing a record.");
|
||||||
|
|
||||||
|
if (AbbrevNo == bitc::ENTER_SUBBLOCK ||
|
||||||
|
AbbrevNo >= bitc::UNABBREV_RECORD)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
while (!Stream.AtEndOfStream()) {
|
||||||
|
|
||||||
|
AbbrevNo = Stream.ReadCode();
|
||||||
|
|
||||||
|
switch (AbbrevNo) {
|
||||||
|
case bitc::ENTER_SUBBLOCK: {
|
||||||
|
unsigned id = Stream.ReadSubBlockID();
|
||||||
|
BlockStack.push_back(std::make_pair(Stream.GetCurrentBitNo(),id));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case bitc::END_BLOCK: {
|
||||||
|
bool x = Stream.ReadBlockEnd();
|
||||||
|
assert (!x && "Error at block end.");
|
||||||
|
BlockStack.pop_back();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
case bitc::DEFINE_ABBREV:
|
||||||
|
Stream.ReadAbbrevRecord();
|
||||||
|
continue;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Deserializer::ReadRecord() {
|
void Deserializer::ReadRecord() {
|
||||||
// FIXME: Check if we haven't run off the edge of the stream.
|
|
||||||
// FIXME: Handle abbreviations.
|
|
||||||
|
|
||||||
assert (Record.size() == 0);
|
|
||||||
|
|
||||||
unsigned Code;
|
while (AdvanceStream() && AbbrevNo == bitc::ENTER_SUBBLOCK) {
|
||||||
|
assert (!BlockStack.empty());
|
||||||
while (true) {
|
Stream.EnterSubBlock(BlockStack.back().second);
|
||||||
|
AbbrevNo = 0;
|
||||||
if (Stream.AtEndOfStream())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Code = Stream.ReadCode();
|
|
||||||
|
|
||||||
if (Code == bitc::ENTER_SUBBLOCK) {
|
|
||||||
BlockLocs.push_back(Stream.GetCurrentBitNo());
|
|
||||||
unsigned id = Stream.ReadSubBlockID();
|
|
||||||
Stream.EnterSubBlock(id);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Code == bitc::END_BLOCK) {
|
|
||||||
bool x = Stream.ReadBlockEnd();
|
|
||||||
assert (!x && "Error at block end.");
|
|
||||||
BlockLocs.pop_back();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Code == bitc::DEFINE_ABBREV) {
|
|
||||||
Stream.ReadAbbrevRecord();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Stream.AtEndOfStream())
|
||||||
|
return;
|
||||||
|
|
||||||
assert (Record.size() == 0);
|
assert (Record.size() == 0);
|
||||||
Stream.ReadRecord(Code,Record);
|
assert (AbbrevNo >= bitc::UNABBREV_RECORD);
|
||||||
assert (Record.size() > 0 || Stream.AtEndOfStream());
|
RecordCode = Stream.ReadRecord(AbbrevNo,Record);
|
||||||
|
assert (Record.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Deserializer::Location Deserializer::GetCurrentBlockLocation() {
|
void Deserializer::SkipBlock() {
|
||||||
|
assert (!inRecord());
|
||||||
|
assert (AbbrevNo == bitc::ENTER_SUBBLOCK);
|
||||||
|
Stream.SkipBlock();
|
||||||
|
AbbrevNo = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Deserializer::Location Deserializer::getCurrentBlockLocation() {
|
||||||
if (!inRecord())
|
if (!inRecord())
|
||||||
ReadRecord();
|
AdvanceStream();
|
||||||
|
|
||||||
assert (!BlockLocs.empty());
|
return BlockStack.back().first;
|
||||||
return BlockLocs.back();
|
}
|
||||||
|
|
||||||
|
unsigned Deserializer::getCurrentBlockID() {
|
||||||
|
if (!inRecord())
|
||||||
|
AdvanceStream();
|
||||||
|
|
||||||
|
return BlockStack.back().second;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned Deserializer::getRecordCode() {
|
||||||
|
if (!inRecord()) {
|
||||||
|
AdvanceStream();
|
||||||
|
assert (AbbrevNo >= bitc::UNABBREV_RECORD);
|
||||||
|
ReadRecord();
|
||||||
|
}
|
||||||
|
|
||||||
|
return RecordCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Deserializer::FinishedBlock(Location BlockLoc) {
|
bool Deserializer::FinishedBlock(Location BlockLoc) {
|
||||||
if (!inRecord())
|
if (!inRecord())
|
||||||
ReadRecord();
|
AdvanceStream();
|
||||||
|
|
||||||
for (llvm::SmallVector<Location,5>::reverse_iterator
|
for (llvm::SmallVector<std::pair<Location,unsigned>,5>::reverse_iterator
|
||||||
I=BlockLocs.rbegin(), E=BlockLocs.rend(); I!=E; ++I)
|
I=BlockStack.rbegin(), E=BlockStack.rend(); I!=E; ++I)
|
||||||
if (*I == BlockLoc)
|
if (I->first == BlockLoc)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned Deserializer::getAbbrevNo() {
|
||||||
|
if (!inRecord())
|
||||||
|
AdvanceStream();
|
||||||
|
|
||||||
|
return AbbrevNo;
|
||||||
|
}
|
||||||
|
|
||||||
bool Deserializer::AtEnd() {
|
bool Deserializer::AtEnd() {
|
||||||
if (inRecord())
|
if (inRecord())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ReadRecord();
|
if (!AdvanceStream())
|
||||||
|
return true;
|
||||||
|
|
||||||
return Stream.AtEndOfStream();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Deserializer::ReadInt() {
|
uint64_t Deserializer::ReadInt() {
|
||||||
|
Reference in New Issue
Block a user