- void 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;
- }
-
- BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3);
- if (BitCodeAbbrevOp::hasEncodingData(E))
- Abbv->Add(BitCodeAbbrevOp(E, ReadVBR64(5)));
- else
- Abbv->Add(BitCodeAbbrevOp(E));
- }
- CurAbbrevs.push_back(Abbv);
- }
-
-public:
-
- bool ReadBlockInfoBlock() {
- // If this is the second stream to get to the block info block, skip it.
- if (BitStream->hasBlockInfoRecords())
- return SkipBlock();
-
- if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true;
-
- SmallVector<uint64_t, 64> Record;
- BitstreamReader::BlockInfo *CurBlockInfo = 0;
-
- // Read all the records for this module.
- while (1) {
- unsigned Code = ReadCode();
- if (Code == bitc::END_BLOCK)
- return ReadBlockEnd();
- if (Code == bitc::ENTER_SUBBLOCK) {
- ReadSubBlockID();
- if (SkipBlock()) return true;
- continue;
- }
-
- // Read abbrev records, associate them with CurBID.
- if (Code == bitc::DEFINE_ABBREV) {
- if (!CurBlockInfo) return true;
- ReadAbbrevRecord();
-
- // 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;
- }
-
- // Read a record.
- Record.clear();
- switch (ReadRecord(Code, Record)) {
- 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;
- }
- }
- }
- }