OLD | NEW |
---|---|
1 //===- NaClBitstreamReader.h -----------------------------------*- C++ -*-===// | 1 //===- NaClBitstreamReader.h -----------------------------------*- C++ -*-===// |
2 // Low-level bitstream reader interface | 2 // Low-level bitstream reader interface |
3 // | 3 // |
4 // The LLVM Compiler Infrastructure | 4 // The LLVM Compiler Infrastructure |
5 // | 5 // |
6 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source |
7 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. |
8 // | 8 // |
9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
10 // | 10 // |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 /// perfectly explicit what is going on. | 179 /// perfectly explicit what is going on. |
180 typedef uint32_t word_t; | 180 typedef uint32_t word_t; |
181 word_t CurWord; | 181 word_t CurWord; |
182 | 182 |
183 /// BitsInCurWord - This is the number of bits in CurWord that are valid. This | 183 /// BitsInCurWord - This is the number of bits in CurWord that are valid. This |
184 /// is always from [0...31/63] inclusive (depending on word size). | 184 /// is always from [0...31/63] inclusive (depending on word size). |
185 unsigned BitsInCurWord; | 185 unsigned BitsInCurWord; |
186 | 186 |
187 // CurCodeSize - This is the declared size of code values used for the current | 187 // CurCodeSize - This is the declared size of code values used for the current |
188 // block, in bits. | 188 // block, in bits. |
189 unsigned CurCodeSize; | 189 int32_t CurCodeSize; |
Karl
2013/05/17 20:52:18
Changed to be an instance of NaClBitcodeSelectorAb
| |
190 | 190 |
191 /// CurAbbrevs - Abbrevs installed at in this block. | 191 /// CurAbbrevs - Abbrevs installed at in this block. |
192 std::vector<NaClBitCodeAbbrev*> CurAbbrevs; | 192 std::vector<NaClBitCodeAbbrev*> CurAbbrevs; |
193 | 193 |
194 struct Block { | 194 struct Block { |
195 unsigned PrevCodeSize; | 195 int32_t PrevCodeSize; |
Karl
2013/05/17 20:52:18
Changed to be an instance of NaClBitcodeSelectorAb
| |
196 std::vector<NaClBitCodeAbbrev*> PrevAbbrevs; | 196 std::vector<NaClBitCodeAbbrev*> PrevAbbrevs; |
197 explicit Block(unsigned PCS) : PrevCodeSize(PCS) {} | 197 explicit Block(int32_t PCS) : PrevCodeSize(PCS) {} |
198 }; | 198 }; |
199 | 199 |
200 /// BlockScope - This tracks the codesize of parent blocks. | 200 /// BlockScope - This tracks the codesize of parent blocks. |
201 SmallVector<Block, 8> BlockScope; | 201 SmallVector<Block, 8> BlockScope; |
202 | 202 |
203 /// SignedValue - Convert unsigned to corresponding signed value, | |
204 /// based on the value of IsNegative. | |
205 int32_t SignedValue(uint32_t Val, bool IsNegative) { | |
Karl
2013/05/17 20:52:18
Removed, no longer used.
| |
206 int32_t Value = static_cast<int32_t>(Val); | |
207 return IsNegative ? -Value : Value; | |
208 } | |
203 | 209 |
204 public: | 210 public: |
205 NaClBitstreamCursor() : BitStream(0), NextChar(0) { | 211 NaClBitstreamCursor() : BitStream(0), NextChar(0) { |
206 } | 212 } |
207 NaClBitstreamCursor(const NaClBitstreamCursor &RHS) | 213 NaClBitstreamCursor(const NaClBitstreamCursor &RHS) |
208 : BitStream(0), NextChar(0) { | 214 : BitStream(0), NextChar(0) { |
209 operator=(RHS); | 215 operator=(RHS); |
210 } | 216 } |
211 | 217 |
212 explicit NaClBitstreamCursor(NaClBitstreamReader &R) : BitStream(&R) { | 218 explicit NaClBitstreamCursor(NaClBitstreamReader &R) : BitStream(&R) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 uint8_t buf[4] = { 0xFF, 0xFF, 0xFF, 0xFF }; | 254 uint8_t buf[4] = { 0xFF, 0xFF, 0xFF, 0xFF }; |
249 BitStream->getBitcodeBytes().readBytes(pos, sizeof(buf), buf, NULL); | 255 BitStream->getBitcodeBytes().readBytes(pos, sizeof(buf), buf, NULL); |
250 return *reinterpret_cast<support::ulittle32_t *>(buf); | 256 return *reinterpret_cast<support::ulittle32_t *>(buf); |
251 } | 257 } |
252 | 258 |
253 bool AtEndOfStream() { | 259 bool AtEndOfStream() { |
254 return BitsInCurWord == 0 && isEndPos(NextChar); | 260 return BitsInCurWord == 0 && isEndPos(NextChar); |
255 } | 261 } |
256 | 262 |
257 /// getAbbrevIDWidth - Return the number of bits used to encode an abbrev #. | 263 /// getAbbrevIDWidth - Return the number of bits used to encode an abbrev #. |
258 unsigned getAbbrevIDWidth() const { return CurCodeSize; } | 264 unsigned getAbbrevIDWidth() const { return CurCodeSize; } |
Karl
2013/05/17 20:52:18
return CurCodeSize -> return CurCodeSize.NumBits
| |
259 | 265 |
260 /// GetCurrentBitNo - Return the bit # of the bit we are reading. | 266 /// GetCurrentBitNo - Return the bit # of the bit we are reading. |
261 uint64_t GetCurrentBitNo() const { | 267 uint64_t GetCurrentBitNo() const { |
262 return NextChar*CHAR_BIT - BitsInCurWord; | 268 return NextChar*CHAR_BIT - BitsInCurWord; |
263 } | 269 } |
264 | 270 |
265 NaClBitstreamReader *getBitStreamReader() { | 271 NaClBitstreamReader *getBitStreamReader() { |
266 return BitStream; | 272 return BitStream; |
267 } | 273 } |
268 const NaClBitstreamReader *getBitStreamReader() const { | 274 const NaClBitstreamReader *getBitStreamReader() const { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 Result |= uint64_t(Piece & ((1U << (NumBits-1))-1)) << NextBit; | 441 Result |= uint64_t(Piece & ((1U << (NumBits-1))-1)) << NextBit; |
436 | 442 |
437 if ((Piece & (1U << (NumBits-1))) == 0) | 443 if ((Piece & (1U << (NumBits-1))) == 0) |
438 return Result; | 444 return Result; |
439 | 445 |
440 NextBit += NumBits-1; | 446 NextBit += NumBits-1; |
441 Piece = Read(NumBits); | 447 Piece = Read(NumBits); |
442 } | 448 } |
443 } | 449 } |
444 | 450 |
451 int32_t ReadIntVBR(unsigned NumBits) { | |
jvoung (off chromium)
2013/05/14 23:47:14
Can we just use BitcodeReader::decodeSignRotatedVa
Karl
2013/05/17 20:52:18
Removed. Use NaClDecodeSignRotatedValue.
| |
452 // Read extra bit for sign bit, and extract. | |
453 uint32_t Piece = Read(NumBits+1); | |
454 bool IsNegative = (Piece & (1U << NumBits)) == (1U << NumBits); | |
455 Piece &= (1U << (NumBits-1))-1; | |
456 | |
457 if ((Piece & (1U << (NumBits-1))) == 0) | |
458 return SignedValue(Piece, IsNegative); | |
459 | |
460 uint32_t Result = 0; | |
461 unsigned NextBit = 0; | |
462 while (1) { | |
463 Result |= (Piece & ((1U << (NumBits-1))-1)) << NextBit; | |
464 | |
465 if ((Piece & (1U << (NumBits-1))) == 0) | |
466 return SignedValue(Result, IsNegative); | |
467 | |
468 NextBit += NumBits-1; | |
469 Piece = Read(NumBits); | |
470 } | |
471 } | |
472 | |
445 private: | 473 private: |
446 void SkipToFourByteBoundary() { | 474 void SkipToFourByteBoundary() { |
447 // If word_t is 64-bits and if we've read less than 32 bits, just dump | 475 // If word_t is 64-bits and if we've read less than 32 bits, just dump |
448 // the bits we have up to the next 32-bit boundary. | 476 // the bits we have up to the next 32-bit boundary. |
449 if (sizeof(word_t) > 4 && | 477 if (sizeof(word_t) > 4 && |
450 BitsInCurWord >= 32) { | 478 BitsInCurWord >= 32) { |
451 CurWord >>= BitsInCurWord-32; | 479 CurWord >>= BitsInCurWord-32; |
452 BitsInCurWord = 32; | 480 BitsInCurWord = 32; |
453 return; | 481 return; |
454 } | 482 } |
455 | 483 |
456 BitsInCurWord = 0; | 484 BitsInCurWord = 0; |
457 CurWord = 0; | 485 CurWord = 0; |
458 } | 486 } |
459 public: | 487 public: |
460 | 488 |
461 unsigned ReadCode() { | 489 unsigned ReadCode() { |
462 return Read(CurCodeSize); | 490 return (CurCodeSize < 0) ? ReadVBR(-CurCodeSize) : Read(CurCodeSize); |
Karl
2013/05/17 20:52:18
Changed to:
return CurCodeSize.IsFixed
? Read(Cu
| |
463 } | 491 } |
464 | 492 |
465 | 493 |
466 // Block header: | 494 // Block header: |
467 // [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen] | 495 // [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen] |
468 | 496 |
469 /// ReadSubBlockID - Having read the ENTER_SUBBLOCK code, read the BlockID for | 497 /// ReadSubBlockID - Having read the ENTER_SUBBLOCK code, read the BlockID for |
470 /// the block. | 498 /// the block. |
471 unsigned ReadSubBlockID() { | 499 unsigned ReadSubBlockID() { |
472 return ReadVBR(naclbitc::BlockIDWidth); | 500 return ReadVBR(naclbitc::BlockIDWidth); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 // Abbrev Processing | 579 // Abbrev Processing |
552 //===--------------------------------------------------------------------===// | 580 //===--------------------------------------------------------------------===// |
553 void ReadAbbrevRecord(); | 581 void ReadAbbrevRecord(); |
554 | 582 |
555 bool ReadBlockInfoBlock(); | 583 bool ReadBlockInfoBlock(); |
556 }; | 584 }; |
557 | 585 |
558 } // End llvm namespace | 586 } // End llvm namespace |
559 | 587 |
560 #endif | 588 #endif |
OLD | NEW |