Index: include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h |
diff --git a/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h b/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h |
index 26d9cb6b2486bc3d76c32f3a2b33d7ee633ac67e..c23fdc2f91e2b81f251f5dbd771c642a4c66a103 100644 |
--- a/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h |
+++ b/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h |
@@ -33,7 +33,7 @@ class NaClBitstreamWriter { |
/// CurCodeSize - This is the declared size of code values used for the |
/// current block, in bits. |
- unsigned CurCodeSize; |
+ NaClBitcodeSelectorAbbrev CurCodeSize; |
/// BlockInfoCurBID - When emitting a BLOCKINFO_BLOCK, this is the currently |
/// selected BLOCK ID. |
@@ -43,10 +43,11 @@ class NaClBitstreamWriter { |
std::vector<NaClBitCodeAbbrev*> CurAbbrevs; |
struct Block { |
- unsigned PrevCodeSize; |
+ NaClBitcodeSelectorAbbrev PrevCodeSize; |
unsigned StartSizeWord; |
std::vector<NaClBitCodeAbbrev*> PrevAbbrevs; |
- Block(unsigned PCS, unsigned SSW) : PrevCodeSize(PCS), StartSizeWord(SSW) {} |
+ Block(const NaClBitcodeSelectorAbbrev& PCS, unsigned SSW) |
+ : PrevCodeSize(PCS), StartSizeWord(SSW) {} |
}; |
/// BlockScope - This tracks the current blocks that we have entered. |
@@ -94,7 +95,7 @@ class NaClBitstreamWriter { |
public: |
explicit NaClBitstreamWriter(SmallVectorImpl<char> &O) |
- : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {} |
+ : Out(O), CurBit(0), CurValue(0), CurCodeSize() {} |
~NaClBitstreamWriter() { |
assert(CurBit == 0 && "Unflused data remaining"); |
@@ -137,6 +138,10 @@ public: |
CurBit = (CurBit+NumBits) & 31; |
} |
+ void EmitBool(bool b) { |
Karl
2013/05/20 22:59:20
Deleting this, since it is no longer needed.
|
+ Emit((uint32_t) b, 1); |
+ } |
+ |
void Emit64(uint64_t Val, unsigned NumBits) { |
if (NumBits <= 32) |
Emit((uint32_t)Val, NumBits); |
@@ -156,6 +161,7 @@ public: |
void EmitVBR(uint32_t Val, unsigned NumBits) { |
assert(NumBits <= 32 && "Too many bits to emit!"); |
+ assert(NumBits > 1 && "Too few bits to emit!"); |
uint32_t Threshold = 1U << (NumBits-1); |
// Emit the bits with VBR encoding, NumBits-1 bits at a time. |
@@ -169,6 +175,7 @@ public: |
void EmitVBR64(uint64_t Val, unsigned NumBits) { |
assert(NumBits <= 32 && "Too many bits to emit!"); |
+ assert(NumBits > 1 && "Too few bits to emit!"); |
if ((uint32_t)Val == Val) |
return EmitVBR((uint32_t)Val, NumBits); |
@@ -186,7 +193,10 @@ public: |
/// EmitCode - Emit the specified code. |
void EmitCode(unsigned Val) { |
- Emit(Val, CurCodeSize); |
+ if (CurCodeSize.IsFixed) |
+ Emit(Val, CurCodeSize.NumBits); |
+ else |
+ EmitVBR(Val, CurCodeSize.NumBits); |
} |
//===--------------------------------------------------------------------===// |
@@ -207,16 +217,20 @@ public: |
return 0; |
} |
- void EnterSubblock(unsigned BlockID, unsigned CodeLen) { |
+ // Enter block using CodeLen bits to read the size of the code selector |
+ // associated with the block. |
+ void EnterSubblock(unsigned BlockID, |
+ const NaClBitcodeSelectorAbbrev& CodeLen) { |
// Block header: |
// [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen] |
EmitCode(naclbitc::ENTER_SUBBLOCK); |
EmitVBR(BlockID, naclbitc::BlockIDWidth); |
- EmitVBR(CodeLen, naclbitc::CodeLenWidth); |
+ EmitBool(CodeLen.IsFixed); |
jvoung (off chromium)
2013/05/17 23:40:48
See below: if the fixedabbrevcutoff variant isn't
Karl
2013/05/20 22:59:20
Deleted.
|
+ EmitVBR(CodeLen.NumBits, naclbitc::CodeLenWidth); |
FlushToWord(); |
unsigned BlockSizeWordIndex = GetWordIndex(); |
- unsigned OldCodeSize = CurCodeSize; |
+ NaClBitcodeSelectorAbbrev OldCodeSize(CurCodeSize); |
// Emit a placeholder, which will be replaced when the block is popped. |
Emit(0, naclbitc::BlockSizeWidth); |
@@ -239,6 +253,28 @@ public: |
} |
} |
+ // Enter block with no abbreviations. |
+ void EnterSubblock(unsigned BlockID) { |
+ NaClBitcodeSelectorAbbrev DefaultCodeLen; |
+ EnterSubblock(BlockID, DefaultCodeLen); |
+ } |
+ |
+ // Enter block with the given number of abbreviations. |
+ void EnterSubblock(unsigned BlockID, unsigned NumAbbrev) { |
+ NaClBitcodeSelectorAbbrev CodeLenAbbrev(NumAbbrev); |
+ EnterSubblock(BlockID, CodeLenAbbrev); |
+ } |
+ |
+ // Enter block with the given number of abbreviations NumAbbrev, |
+ // with the constraint that all abbreviations < FixedAbbrevCutoff will |
+ // be read using a single read. |
+ void EnterSubblock(unsigned BlockId, |
jvoung (off chromium)
2013/05/17 23:40:48
Is this actually used?
Karl
2013/05/20 22:59:20
Again, I'm over planning changes. Removing this ca
|
+ unsigned NumAbbrev, |
+ unsigned FixedAbbrevCutoff) { |
+ NaClBitcodeSelectorAbbrev CodeLenAbbrev(FixedAbbrevCutoff, NumAbbrev); |
+ EnterSubblock(BlockId, CodeLenAbbrev); |
+ } |
+ |
void ExitBlock() { |
assert(!BlockScope.empty() && "Block scope imbalance!"); |
@@ -501,8 +537,8 @@ public: |
//===--------------------------------------------------------------------===// |
/// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK. |
- void EnterBlockInfoBlock(unsigned CodeWidth) { |
- EnterSubblock(naclbitc::BLOCKINFO_BLOCK_ID, CodeWidth); |
+ void EnterBlockInfoBlock() { |
+ EnterSubblock(naclbitc::BLOCKINFO_BLOCK_ID); |
BlockInfoCurBID = ~0U; |
} |
private: |