mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-24 08:24:33 +00:00
Added "random access" to the Deserializer to allow a client to jump to any
serialized block in the bitstream, including a block in an entirely different nesting than the current block. This is useful for deserializing objects from a bitstream in an order different from the order that they were serialized. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43973 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -80,7 +80,36 @@ class Deserializer {
|
||||
//===----------------------------------------------------------===//
|
||||
|
||||
public:
|
||||
typedef uint64_t Location;
|
||||
struct Location {
|
||||
uint64_t BitNo;
|
||||
unsigned BlockID;
|
||||
unsigned NumWords;
|
||||
|
||||
Location(uint64_t bit, unsigned bid, unsigned words)
|
||||
: BitNo(bit), BlockID(bid), NumWords(words) {}
|
||||
|
||||
Location() : BitNo(0), BlockID(0), NumWords(0) {}
|
||||
|
||||
Location& operator=(Location& RHS) {
|
||||
BitNo = RHS.BitNo;
|
||||
BlockID = RHS.BlockID;
|
||||
NumWords = RHS.NumWords;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Location& RHS) const { return BitNo == RHS.BitNo; }
|
||||
bool operator!=(const Location& RHS) const { return BitNo != RHS.BitNo; }
|
||||
|
||||
bool contains(const Location& RHS) const {
|
||||
if (RHS.BitNo < BitNo)
|
||||
return false;
|
||||
|
||||
if ((RHS.BitNo - BitNo) >> 5 < NumWords)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------===//
|
||||
// Internal data members.
|
||||
@ -93,9 +122,10 @@ private:
|
||||
BumpPtrAllocator Allocator;
|
||||
BPNode* FreeList;
|
||||
MapTy BPatchMap;
|
||||
llvm::SmallVector<std::pair<Location,unsigned>,5> BlockStack;
|
||||
llvm::SmallVector<Location,8> BlockStack;
|
||||
unsigned AbbrevNo;
|
||||
unsigned RecordCode;
|
||||
Location StreamStart;
|
||||
|
||||
//===----------------------------------------------------------===//
|
||||
// Public Interface.
|
||||
@ -238,13 +268,18 @@ public:
|
||||
unsigned getAbbrevNo();
|
||||
|
||||
bool FinishedBlock(Location BlockLoc);
|
||||
bool JumpTo(const Location& BlockLoc);
|
||||
void Rewind() { JumpTo(StreamStart); }
|
||||
|
||||
bool AtEnd();
|
||||
bool inRecord();
|
||||
void SkipBlock();
|
||||
bool SkipToBlock(unsigned BlockID);
|
||||
|
||||
unsigned getRecordCode();
|
||||
|
||||
BitstreamReader& getStream() { return Stream; }
|
||||
|
||||
private:
|
||||
bool AdvanceStream();
|
||||
void ReadRecord();
|
||||
|
Reference in New Issue
Block a user