aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Bitcode
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-10 02:02:34 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-10 02:02:34 +0000
commit1a8a08a690a06194653f54453ac41e0e0e7bd3a4 (patch)
tree7f03c9e6a0ea1cb1d05ed19207df570e4271f696 /include/llvm/Bitcode
parent13faf5c13c951741e9bdfeabd5f9047f1f28d95b (diff)
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
Diffstat (limited to 'include/llvm/Bitcode')
-rw-r--r--include/llvm/Bitcode/Deserialize.h39
1 files changed, 37 insertions, 2 deletions
diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h
index 4ab35c04b1..8a9be99199 100644
--- a/include/llvm/Bitcode/Deserialize.h
+++ b/include/llvm/Bitcode/Deserialize.h
@@ -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();