// CurCodeSize - This is the declared size of code values used for the current
// block, in bits.
unsigned CurCodeSize;
-
+
+ /// CurAbbrevs - Abbrevs installed at in this block.
+ std::vector<BitCodeAbbrev*> CurAbbrevs;
+
struct Block {
unsigned PrevCodeSize;
unsigned StartSizeWord;
/// BlockScope - This tracks the current blocks that we have entered.
std::vector<Block> BlockScope;
- std::vector<BitCodeAbbrev*> CurAbbrevs;
public:
BitstreamWriter(std::vector<unsigned char> &O)
: Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {}
~BitstreamWriter() {
assert(CurBit == 0 && "Unflused data remaining");
- assert(BlockScope.empty() && "Block imbalance");
+ assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance");
}
//===--------------------------------------------------------------------===//
// Basic Primitives for emitting bits to the stream.
EmitVBR(CodeLen, bitc::CodeLenWidth);
FlushToWord();
BlockScope.push_back(Block(CurCodeSize, Out.size()/4));
-
- // Delete all abbrevs.
- for (unsigned i = 0, e = CurAbbrevs.size(); i != e; ++i)
- delete CurAbbrevs[i];
-
BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
+
// Emit a placeholder, which will be replaced when the block is popped.
Emit(0, bitc::BlockSizeWidth);
void ExitBlock() {
assert(!BlockScope.empty() && "Block scope imbalance!");
+
+ // Delete all abbrevs.
+ for (unsigned i = 0, e = CurAbbrevs.size(); i != e; ++i)
+ delete CurAbbrevs[i];
+
const Block &B = BlockScope.back();
// Block tail: