Chromium Code Reviews| Index: lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp |
| diff --git a/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp |
| index bdb7255f12c80ff33722b7f1c4b584247f70c5c4..6a27c1626bab39e35c77749511487b81ce900f7e 100644 |
| --- a/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp |
| +++ b/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp |
| @@ -54,21 +54,6 @@ Fatal(const std::string &ErrorMessage) const { |
| report_fatal_error(StrBuf.str()); |
| } |
| -void NaClBitstreamCursor::freeState() { |
| - // Free all the Abbrevs. |
| - for (size_t i = 0, e = CurAbbrevs.size(); i != e; ++i) |
| - CurAbbrevs[i]->dropRef(); |
| - CurAbbrevs.clear(); |
| - |
| - // Free all the Abbrevs in the block scope. |
| - for (size_t S = 0, e = BlockScope.size(); S != e; ++S) { |
| - std::vector<NaClBitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; |
| - for (size_t i = 0, e = Abbrevs.size(); i != e; ++i) |
| - Abbrevs[i]->dropRef(); |
| - } |
| - BlockScope.clear(); |
| -} |
| - |
| void NaClBitstreamCursor::reportInvalidAbbrevNumber(unsigned AbbrevNo) const { |
| std::string Buffer; |
| raw_string_ostream StrBuf(Buffer); |
| @@ -86,28 +71,17 @@ void NaClBitstreamCursor::reportInvalidJumpToBit(uint64_t BitNo) const { |
| /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter |
| /// the block, and return true if the block has an error. |
| bool NaClBitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) { |
| - // Save the current block's state on BlockScope. |
| - BlockScope.push_back(Block(CurCodeSize)); |
| - BlockScope.back().PrevAbbrevs.swap(CurAbbrevs); |
| - |
| - // Add the abbrevs specific to this block to the CurAbbrevs list. |
| - if (const NaClBitstreamReader::BlockInfo *Info = |
| - BitStream->getBlockInfo(BlockID)) { |
| - for (size_t i = 0, e = Info->Abbrevs.size(); i != e; ++i) { |
| - CurAbbrevs.push_back(Info->Abbrevs[i]); |
| - CurAbbrevs.back()->addRef(); |
| - } |
| - } |
| - |
| - // Get the codesize of this block. |
| - CurCodeSize.IsFixed = true; |
| - CurCodeSize.NumBits = ReadVBR(naclbitc::CodeLenWidth); |
| + constexpr bool IsFixed = true; |
|
Jim Stichnoth
2016/03/14 22:46:49
I think LLVM is still generally not using constexp
Karl
2016/03/15 20:29:41
Done.
|
| + NaClBitcodeSelectorAbbrev |
| + CodeAbbrev(IsFixed, ReadVBR(naclbitc::CodeLenWidth)); |
| + BlockScope.push_back(Block(&BitStream->getOrCreateBlockInfo(BlockID), |
| + CodeAbbrev)); |
| SkipToFourByteBoundary(); |
| unsigned NumWords = Read(naclbitc::BlockSizeWidth); |
| if (NumWordsP) *NumWordsP = NumWords; |
| // Validate that this block is sane. |
| - if (CurCodeSize.NumBits == 0 || AtEndOfStream()) |
| + if (BlockScope.back().getCodeAbbrev().NumBits == 0 || AtEndOfStream()) |
| return true; |
| return false; |
| @@ -332,7 +306,7 @@ void NaClBitstreamCursor::ReadAbbrevRecord(bool IsLocal, |
| SkipToByteBoundaryIfAligned(); |
| if (!Abbv->isValid()) |
| ErrHandler->Fatal("Invalid abbreviation specified in bitcode file"); |
| - CurAbbrevs.push_back(Abbv); |
| + BlockScope.back().addNewLocalAbbrev(Abbv); |
| if (Listener) { |
| Listener->ProcessAbbreviation(Abbv, IsLocal); |
| // Reset record information of the listener. |
| @@ -359,16 +333,21 @@ void NaClBitstreamCursor::SkipAbbrevRecord() { |
| bool NaClBitstreamCursor::ReadBlockInfoBlock(NaClAbbrevListener *Listener) { |
| // If this is the second stream to get to the block info block, skip it. |
| - if (BitStream->hasBlockInfoRecords()) |
| + if (BitStream->HasReadBlockInfoBlock) |
| return SkipBlock(); |
| + BitStream->HasReadBlockInfoBlock = true; |
| + |
| unsigned NumWords; |
| if (EnterSubBlock(naclbitc::BLOCKINFO_BLOCK_ID, &NumWords)) return true; |
| if (Listener) Listener->BeginBlockInfoBlock(NumWords); |
| NaClBitcodeRecordVector Record; |
| - NaClBitstreamReader::BlockInfo *CurBlockInfo = 0; |
| + Block &CurBlock = BlockScope.back(); |
| + NaClBitstreamReader::AbbrevList *UpdateAbbrevs = |
| + &CurBlock.GlobalAbbrevs->getAbbrevs(); |
| + bool FoundSetBID = false; |
| // Read records of the BlockInfo block. |
| while (1) { |
| @@ -389,15 +368,19 @@ bool NaClBitstreamCursor::ReadBlockInfoBlock(NaClAbbrevListener *Listener) { |
| // Read abbrev records, associate them with CurBID. |
| if (Entry.ID == naclbitc::DEFINE_ABBREV) { |
| - if (!CurBlockInfo) return true; |
| ReadAbbrevRecord(false, Listener); |
| - // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the |
| - // appropriate BlockInfo. |
| - NaClBitCodeAbbrev *Abbv = CurAbbrevs.back(); |
| - CurAbbrevs.pop_back(); |
| - CurBlockInfo->Abbrevs.push_back(Abbv); |
| - continue; |
| + // ReadAbbrevRecord installs as local abbreviation. Move it to |
|
Jim Stichnoth
2016/03/14 22:46:49
s/as/a/ ?
Karl
2016/03/15 20:29:41
Done.
|
| + // the appropriate BlockInfo if the corresponding SetBID record |
|
Jim Stichnoth
2016/03/14 22:46:49
reflow comment to 80-col
Karl
2016/03/15 20:29:41
Done.
|
| + // has been found. |
| + if (FoundSetBID) { |
| + NaClBitstreamReader::AbbrevListVector &LocalAbbrevs = |
| + CurBlock.LocalAbbrevs.Abbrevs; |
| + NaClBitCodeAbbrev *Abbv = LocalAbbrevs.back(); |
| + LocalAbbrevs.pop_back(); |
| + UpdateAbbrevs->push_back(Abbv); |
| + continue; |
| + } |
| } |
| // Read a record. |
| @@ -408,7 +391,9 @@ bool NaClBitstreamCursor::ReadBlockInfoBlock(NaClAbbrevListener *Listener) { |
| return true; |
| case naclbitc::BLOCKINFO_CODE_SETBID: |
| if (Record.size() < 1) return true; |
| - CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]); |
| + FoundSetBID = true; |
| + UpdateAbbrevs = |
| + &BitStream->getOrCreateBlockInfo((unsigned)Record[0]).getAbbrevs(); |
| if (Listener) { |
| Listener->Values = Record; |
| Listener->SetBID(); |