Chromium Code Reviews| Index: include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
| diff --git a/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h b/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
| index 58c0a5d7fa355db91828922fbf45fccab9afcfcd..b75c42f4199ce16331b42702bcda491bf75e2eaf 100644 |
| --- a/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
| +++ b/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
| @@ -186,20 +186,26 @@ class NaClBitstreamCursor { |
| // CurCodeSize - This is the declared size of code values used for the current |
| // block, in bits. |
| - unsigned CurCodeSize; |
| + int32_t CurCodeSize; |
|
Karl
2013/05/17 20:52:18
Changed to be an instance of NaClBitcodeSelectorAb
|
| /// CurAbbrevs - Abbrevs installed at in this block. |
| std::vector<NaClBitCodeAbbrev*> CurAbbrevs; |
| struct Block { |
| - unsigned PrevCodeSize; |
| + int32_t PrevCodeSize; |
|
Karl
2013/05/17 20:52:18
Changed to be an instance of NaClBitcodeSelectorAb
|
| std::vector<NaClBitCodeAbbrev*> PrevAbbrevs; |
| - explicit Block(unsigned PCS) : PrevCodeSize(PCS) {} |
| + explicit Block(int32_t PCS) : PrevCodeSize(PCS) {} |
| }; |
| /// BlockScope - This tracks the codesize of parent blocks. |
| SmallVector<Block, 8> BlockScope; |
| + /// SignedValue - Convert unsigned to corresponding signed value, |
| + /// based on the value of IsNegative. |
| + int32_t SignedValue(uint32_t Val, bool IsNegative) { |
|
Karl
2013/05/17 20:52:18
Removed, no longer used.
|
| + int32_t Value = static_cast<int32_t>(Val); |
| + return IsNegative ? -Value : Value; |
| + } |
| public: |
| NaClBitstreamCursor() : BitStream(0), NextChar(0) { |
| @@ -442,6 +448,28 @@ public: |
| } |
| } |
| + 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.
|
| + // Read extra bit for sign bit, and extract. |
| + uint32_t Piece = Read(NumBits+1); |
| + bool IsNegative = (Piece & (1U << NumBits)) == (1U << NumBits); |
| + Piece &= (1U << (NumBits-1))-1; |
| + |
| + if ((Piece & (1U << (NumBits-1))) == 0) |
| + return SignedValue(Piece, IsNegative); |
| + |
| + uint32_t Result = 0; |
| + unsigned NextBit = 0; |
| + while (1) { |
| + Result |= (Piece & ((1U << (NumBits-1))-1)) << NextBit; |
| + |
| + if ((Piece & (1U << (NumBits-1))) == 0) |
| + return SignedValue(Result, IsNegative); |
| + |
| + NextBit += NumBits-1; |
| + Piece = Read(NumBits); |
| + } |
| + } |
| + |
| private: |
| void SkipToFourByteBoundary() { |
| // If word_t is 64-bits and if we've read less than 32 bits, just dump |
| @@ -459,7 +487,7 @@ private: |
| public: |
| unsigned ReadCode() { |
| - return Read(CurCodeSize); |
| + return (CurCodeSize < 0) ? ReadVBR(-CurCodeSize) : Read(CurCodeSize); |
|
Karl
2013/05/17 20:52:18
Changed to:
return CurCodeSize.IsFixed
? Read(Cu
|
| } |