2013-01-20 02:19:39 +08:00
|
|
|
//===- BitstreamReader.cpp - BitstreamReader implementation ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Bitcode/BitstreamReader.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BitstreamCursor implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void BitstreamCursor::operator=(const BitstreamCursor &RHS) {
|
|
|
|
freeState();
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
BitStream = RHS.BitStream;
|
|
|
|
NextChar = RHS.NextChar;
|
|
|
|
CurWord = RHS.CurWord;
|
|
|
|
BitsInCurWord = RHS.BitsInCurWord;
|
|
|
|
CurCodeSize = RHS.CurCodeSize;
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Copy abbreviations, and bump ref counts.
|
|
|
|
CurAbbrevs = RHS.CurAbbrevs;
|
2013-02-19 17:48:30 +08:00
|
|
|
for (size_t i = 0, e = CurAbbrevs.size(); i != e; ++i)
|
2013-01-20 02:19:39 +08:00
|
|
|
CurAbbrevs[i]->addRef();
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Copy block scope and bump ref counts.
|
|
|
|
BlockScope = RHS.BlockScope;
|
2013-02-19 17:48:30 +08:00
|
|
|
for (size_t S = 0, e = BlockScope.size(); S != e; ++S) {
|
2013-01-20 02:19:39 +08:00
|
|
|
std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs;
|
2013-02-19 17:48:30 +08:00
|
|
|
for (size_t i = 0, e = Abbrevs.size(); i != e; ++i)
|
2013-01-20 02:19:39 +08:00
|
|
|
Abbrevs[i]->addRef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitstreamCursor::freeState() {
|
|
|
|
// Free all the Abbrevs.
|
2013-02-19 17:48:30 +08:00
|
|
|
for (size_t i = 0, e = CurAbbrevs.size(); i != e; ++i)
|
2013-01-20 02:19:39 +08:00
|
|
|
CurAbbrevs[i]->dropRef();
|
|
|
|
CurAbbrevs.clear();
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Free all the Abbrevs in the block scope.
|
2013-02-19 17:48:30 +08:00
|
|
|
for (size_t S = 0, e = BlockScope.size(); S != e; ++S) {
|
2013-01-20 02:19:39 +08:00
|
|
|
std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs;
|
2013-02-19 17:48:30 +08:00
|
|
|
for (size_t i = 0, e = Abbrevs.size(); i != e; ++i)
|
2013-01-20 02:19:39 +08:00
|
|
|
Abbrevs[i]->dropRef();
|
|
|
|
}
|
|
|
|
BlockScope.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter
|
|
|
|
/// the block, and return true if the block has an error.
|
|
|
|
bool BitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) {
|
|
|
|
// Save the current block's state on BlockScope.
|
|
|
|
BlockScope.push_back(Block(CurCodeSize));
|
|
|
|
BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Add the abbrevs specific to this block to the CurAbbrevs list.
|
|
|
|
if (const BitstreamReader::BlockInfo *Info =
|
|
|
|
BitStream->getBlockInfo(BlockID)) {
|
2013-02-19 17:48:30 +08:00
|
|
|
for (size_t i = 0, e = Info->Abbrevs.size(); i != e; ++i) {
|
2013-01-20 02:19:39 +08:00
|
|
|
CurAbbrevs.push_back(Info->Abbrevs[i]);
|
|
|
|
CurAbbrevs.back()->addRef();
|
|
|
|
}
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Get the codesize of this block.
|
|
|
|
CurCodeSize = ReadVBR(bitc::CodeLenWidth);
|
2013-01-22 02:04:19 +08:00
|
|
|
SkipToFourByteBoundary();
|
2013-01-20 02:19:39 +08:00
|
|
|
unsigned NumWords = Read(bitc::BlockSizeWidth);
|
|
|
|
if (NumWordsP) *NumWordsP = NumWords;
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Validate that this block is sane.
|
|
|
|
if (CurCodeSize == 0 || AtEndOfStream())
|
|
|
|
return true;
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
void BitstreamCursor::readAbbreviatedLiteral(const BitCodeAbbrevOp &Op,
|
|
|
|
SmallVectorImpl<uint64_t> &Vals) {
|
|
|
|
assert(Op.isLiteral() && "Not a literal");
|
|
|
|
// If the abbrev specifies the literal value to use, use it.
|
|
|
|
Vals.push_back(Op.getLiteralValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitstreamCursor::readAbbreviatedField(const BitCodeAbbrevOp &Op,
|
|
|
|
SmallVectorImpl<uint64_t> &Vals) {
|
|
|
|
assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!");
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
// Decode the value as we are commanded.
|
|
|
|
switch (Op.getEncoding()) {
|
|
|
|
case BitCodeAbbrevOp::Array:
|
|
|
|
case BitCodeAbbrevOp::Blob:
|
|
|
|
assert(0 && "Should not reach here");
|
|
|
|
case BitCodeAbbrevOp::Fixed:
|
|
|
|
Vals.push_back(Read((unsigned)Op.getEncodingData()));
|
|
|
|
break;
|
|
|
|
case BitCodeAbbrevOp::VBR:
|
|
|
|
Vals.push_back(ReadVBR64((unsigned)Op.getEncodingData()));
|
|
|
|
break;
|
|
|
|
case BitCodeAbbrevOp::Char6:
|
|
|
|
Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitstreamCursor::skipAbbreviatedField(const BitCodeAbbrevOp &Op) {
|
|
|
|
assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!");
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
// Decode the value as we are commanded.
|
|
|
|
switch (Op.getEncoding()) {
|
|
|
|
case BitCodeAbbrevOp::Array:
|
|
|
|
case BitCodeAbbrevOp::Blob:
|
|
|
|
assert(0 && "Should not reach here");
|
|
|
|
case BitCodeAbbrevOp::Fixed:
|
|
|
|
(void)Read((unsigned)Op.getEncodingData());
|
|
|
|
break;
|
|
|
|
case BitCodeAbbrevOp::VBR:
|
|
|
|
(void)ReadVBR64((unsigned)Op.getEncodingData());
|
|
|
|
break;
|
|
|
|
case BitCodeAbbrevOp::Char6:
|
|
|
|
(void)Read(6);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// skipRecord - Read the current record and discard it.
|
|
|
|
void BitstreamCursor::skipRecord(unsigned AbbrevID) {
|
|
|
|
// Skip unabbreviated records by reading past their entries.
|
|
|
|
if (AbbrevID == bitc::UNABBREV_RECORD) {
|
|
|
|
unsigned Code = ReadVBR(6);
|
|
|
|
(void)Code;
|
|
|
|
unsigned NumElts = ReadVBR(6);
|
|
|
|
for (unsigned i = 0; i != NumElts; ++i)
|
|
|
|
(void)ReadVBR64(6);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
|
|
|
|
const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
|
|
|
|
if (Op.isLiteral())
|
|
|
|
continue;
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
|
|
|
|
Op.getEncoding() != BitCodeAbbrevOp::Blob) {
|
|
|
|
skipAbbreviatedField(Op);
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
|
|
|
|
// Array case. Read the number of elements as a vbr6.
|
|
|
|
unsigned NumElts = ReadVBR(6);
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
// Get the element encoding.
|
|
|
|
assert(i+2 == e && "array op not second to last?");
|
|
|
|
const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
// Read all the elements.
|
|
|
|
for (; NumElts; --NumElts)
|
|
|
|
skipAbbreviatedField(EltEnc);
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
|
|
|
|
// Blob case. Read the number of bytes as a vbr6.
|
|
|
|
unsigned NumElts = ReadVBR(6);
|
2013-01-22 02:04:19 +08:00
|
|
|
SkipToFourByteBoundary(); // 32-bit alignment
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
// Figure out where the end of this blob will be including tail padding.
|
2013-01-22 02:18:25 +08:00
|
|
|
size_t NewEnd = GetCurrentBitNo()+((NumElts+3)&~3)*8;
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
// If this would read off the end of the bitcode file, just set the
|
|
|
|
// record to empty and return.
|
2013-01-22 02:18:25 +08:00
|
|
|
if (!canSkipToPos(NewEnd/8)) {
|
2013-01-20 08:00:00 +08:00
|
|
|
NextChar = BitStream->getBitcodeBytes().getExtent();
|
|
|
|
break;
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 08:00:00 +08:00
|
|
|
// Skip over the blob.
|
2013-01-22 02:18:25 +08:00
|
|
|
JumpToBit(NewEnd);
|
2013-01-20 08:00:00 +08:00
|
|
|
}
|
|
|
|
}
|
2013-01-20 02:19:39 +08:00
|
|
|
|
2013-01-20 09:06:48 +08:00
|
|
|
unsigned BitstreamCursor::readRecord(unsigned AbbrevID,
|
2013-01-20 02:19:39 +08:00
|
|
|
SmallVectorImpl<uint64_t> &Vals,
|
2013-01-20 09:06:48 +08:00
|
|
|
StringRef *Blob) {
|
2013-01-20 02:19:39 +08:00
|
|
|
if (AbbrevID == bitc::UNABBREV_RECORD) {
|
|
|
|
unsigned Code = ReadVBR(6);
|
|
|
|
unsigned NumElts = ReadVBR(6);
|
|
|
|
for (unsigned i = 0; i != NumElts; ++i)
|
|
|
|
Vals.push_back(ReadVBR64(6));
|
|
|
|
return Code;
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-05-11 06:17:10 +08:00
|
|
|
// Read the record code first.
|
|
|
|
assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?");
|
|
|
|
const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0);
|
|
|
|
if (CodeOp.isLiteral())
|
|
|
|
readAbbreviatedLiteral(CodeOp, Vals);
|
|
|
|
else
|
|
|
|
readAbbreviatedField(CodeOp, Vals);
|
|
|
|
unsigned Code = (unsigned)Vals.pop_back_val();
|
|
|
|
|
|
|
|
for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) {
|
2013-01-20 02:19:39 +08:00
|
|
|
const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
|
|
|
|
if (Op.isLiteral()) {
|
2013-01-20 08:00:00 +08:00
|
|
|
readAbbreviatedLiteral(Op, Vals);
|
2013-01-20 02:19:39 +08:00
|
|
|
continue;
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
|
|
|
|
Op.getEncoding() != BitCodeAbbrevOp::Blob) {
|
2013-01-20 08:00:00 +08:00
|
|
|
readAbbreviatedField(Op, Vals);
|
2013-01-20 02:19:39 +08:00
|
|
|
continue;
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
|
|
|
|
// Array case. Read the number of elements as a vbr6.
|
|
|
|
unsigned NumElts = ReadVBR(6);
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Get the element encoding.
|
|
|
|
assert(i+2 == e && "array op not second to last?");
|
|
|
|
const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Read all the elements.
|
|
|
|
for (; NumElts; --NumElts)
|
2013-01-20 08:00:00 +08:00
|
|
|
readAbbreviatedField(EltEnc, Vals);
|
2013-01-20 02:19:39 +08:00
|
|
|
continue;
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
|
|
|
|
// Blob case. Read the number of bytes as a vbr6.
|
|
|
|
unsigned NumElts = ReadVBR(6);
|
2013-01-22 02:04:19 +08:00
|
|
|
SkipToFourByteBoundary(); // 32-bit alignment
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Figure out where the end of this blob will be including tail padding.
|
2013-01-22 02:18:25 +08:00
|
|
|
size_t CurBitPos = GetCurrentBitNo();
|
|
|
|
size_t NewEnd = CurBitPos+((NumElts+3)&~3)*8;
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// If this would read off the end of the bitcode file, just set the
|
|
|
|
// record to empty and return.
|
2013-01-22 02:18:25 +08:00
|
|
|
if (!canSkipToPos(NewEnd/8)) {
|
2013-01-20 02:19:39 +08:00
|
|
|
Vals.append(NumElts, 0);
|
|
|
|
NextChar = BitStream->getBitcodeBytes().getExtent();
|
|
|
|
break;
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-22 02:24:49 +08:00
|
|
|
// Otherwise, inform the streamer that we need these bytes in memory.
|
|
|
|
const char *Ptr = (const char*)
|
|
|
|
BitStream->getBitcodeBytes().getPointer(CurBitPos/8, NumElts);
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-22 02:24:49 +08:00
|
|
|
// If we can return a reference to the data, do so to avoid copying it.
|
2013-01-20 09:06:48 +08:00
|
|
|
if (Blob) {
|
2013-01-22 02:24:49 +08:00
|
|
|
*Blob = StringRef(Ptr, NumElts);
|
2013-01-20 02:19:39 +08:00
|
|
|
} else {
|
2013-01-22 02:24:49 +08:00
|
|
|
// Otherwise, unpack into Vals with zero extension.
|
2013-01-22 02:18:25 +08:00
|
|
|
for (; NumElts; --NumElts)
|
2013-01-22 02:24:49 +08:00
|
|
|
Vals.push_back((unsigned char)*Ptr++);
|
2013-01-20 02:19:39 +08:00
|
|
|
}
|
|
|
|
// Skip over tail padding.
|
2013-01-22 02:18:25 +08:00
|
|
|
JumpToBit(NewEnd);
|
2013-01-20 02:19:39 +08:00
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
return Code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BitstreamCursor::ReadAbbrevRecord() {
|
|
|
|
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
|
|
|
|
unsigned NumOpInfo = ReadVBR(5);
|
|
|
|
for (unsigned i = 0; i != NumOpInfo; ++i) {
|
|
|
|
bool IsLiteral = Read(1) ? true : false;
|
|
|
|
if (IsLiteral) {
|
|
|
|
Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8)));
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3);
|
2013-02-09 15:07:29 +08:00
|
|
|
if (BitCodeAbbrevOp::hasEncodingData(E)) {
|
|
|
|
unsigned Data = ReadVBR64(5);
|
|
|
|
|
|
|
|
// As a special case, handle fixed(0) (i.e., a fixed field with zero bits)
|
|
|
|
// and vbr(0) as a literal zero. This is decoded the same way, and avoids
|
|
|
|
// a slow path in Read() to have to handle reading zero bits.
|
|
|
|
if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
|
|
|
|
Data == 0) {
|
|
|
|
Abbv->Add(BitCodeAbbrevOp(0));
|
|
|
|
continue;
|
|
|
|
}
|
2013-04-01 10:28:07 +08:00
|
|
|
|
2013-02-09 15:07:29 +08:00
|
|
|
Abbv->Add(BitCodeAbbrevOp(E, Data));
|
|
|
|
} else
|
2013-01-20 02:19:39 +08:00
|
|
|
Abbv->Add(BitCodeAbbrevOp(E));
|
|
|
|
}
|
|
|
|
CurAbbrevs.push_back(Abbv);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BitstreamCursor::ReadBlockInfoBlock() {
|
|
|
|
// If this is the second stream to get to the block info block, skip it.
|
|
|
|
if (BitStream->hasBlockInfoRecords())
|
|
|
|
return SkipBlock();
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true;
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
SmallVector<uint64_t, 64> Record;
|
|
|
|
BitstreamReader::BlockInfo *CurBlockInfo = 0;
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Read all the records for this module.
|
|
|
|
while (1) {
|
2013-01-20 10:13:19 +08:00
|
|
|
BitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrevs);
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 10:13:19 +08:00
|
|
|
switch (Entry.Kind) {
|
|
|
|
case llvm::BitstreamEntry::SubBlock: // Handled for us already.
|
|
|
|
case llvm::BitstreamEntry::Error:
|
|
|
|
return true;
|
|
|
|
case llvm::BitstreamEntry::EndBlock:
|
|
|
|
return false;
|
|
|
|
case llvm::BitstreamEntry::Record:
|
|
|
|
// The interesting case.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Read abbrev records, associate them with CurBID.
|
2013-01-20 10:13:19 +08:00
|
|
|
if (Entry.ID == bitc::DEFINE_ABBREV) {
|
2013-01-20 02:19:39 +08:00
|
|
|
if (!CurBlockInfo) return true;
|
|
|
|
ReadAbbrevRecord();
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the
|
|
|
|
// appropriate BlockInfo.
|
|
|
|
BitCodeAbbrev *Abbv = CurAbbrevs.back();
|
|
|
|
CurAbbrevs.pop_back();
|
|
|
|
CurBlockInfo->Abbrevs.push_back(Abbv);
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-07 06:14:06 +08:00
|
|
|
|
2013-01-20 02:19:39 +08:00
|
|
|
// Read a record.
|
|
|
|
Record.clear();
|
2013-01-20 10:13:19 +08:00
|
|
|
switch (readRecord(Entry.ID, Record)) {
|
2013-01-20 02:19:39 +08:00
|
|
|
default: break; // Default behavior, ignore unknown content.
|
|
|
|
case bitc::BLOCKINFO_CODE_SETBID:
|
|
|
|
if (Record.size() < 1) return true;
|
|
|
|
CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]);
|
|
|
|
break;
|
|
|
|
case bitc::BLOCKINFO_CODE_BLOCKNAME: {
|
|
|
|
if (!CurBlockInfo) return true;
|
|
|
|
if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name.
|
|
|
|
std::string Name;
|
|
|
|
for (unsigned i = 0, e = Record.size(); i != e; ++i)
|
|
|
|
Name += (char)Record[i];
|
|
|
|
CurBlockInfo->Name = Name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case bitc::BLOCKINFO_CODE_SETRECORDNAME: {
|
|
|
|
if (!CurBlockInfo) return true;
|
|
|
|
if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name.
|
|
|
|
std::string Name;
|
|
|
|
for (unsigned i = 1, e = Record.size(); i != e; ++i)
|
|
|
|
Name += (char)Record[i];
|
|
|
|
CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0],
|
|
|
|
Name));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|