llvm.org GIT mirror llvm / 90a5c7d
add JumpToBit, an explicit init method, and a default ctor. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36613 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
1 changed file(s) with 28 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
5050 /// FirstChar - This remembers the first byte of the stream.
5151 const unsigned char *FirstChar;
5252 public:
53 BitstreamReader(const unsigned char *Start, const unsigned char *End)
54 : NextChar(Start), LastChar(End), FirstChar(Start) {
53 BitstreamReader() {
54 NextChar = FirstChar = LastChar = 0;
55 CurWord = 0;
56 BitsInCurWord = 0;
57 CurCodeSize = 0;
58 }
59
60 BitstreamReader(const unsigned char *Start, const unsigned char *End) {
61 init(Start, End);
62 }
63
64 void init(const unsigned char *Start, const unsigned char *End) {
65 NextChar = FirstChar = Start;
66 LastChar = End;
5567 assert(((End-Start) & 3) == 0 &&"Bitcode stream not a multiple of 4 bytes");
5668 CurWord = 0;
5769 BitsInCurWord = 0;
7688 /// GetCurrentBitNo - Return the bit # of the bit we are reading.
7789 uint64_t GetCurrentBitNo() const {
7890 return (NextChar-FirstChar)*8 + (32-BitsInCurWord);
91 }
92
93 /// JumpToBit - Reset the stream to the specified bit number.
94 void JumpToBit(uint64_t BitNo) {
95 unsigned WordNo = BitNo/32;
96 unsigned WordBitNo = BitNo & 31;
97 assert(WordNo < (unsigned)(LastChar-FirstChar) && "Invalid location");
98
99 // Move the cursor to the right word.
100 NextChar = FirstChar+WordNo;
101 BitsInCurWord = 0;
102
103 // Skip over any bits that are already consumed.
104 if (WordBitNo) Read(WordBitNo);
79105 }
80106
81107 /// GetAbbrevIDWidth - Return the number of bits used to encode an abbrev #.