//
// The LLVM Compiler Infrastructure
//
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
namespace llvm {
+ class Deserializer;
+
class BitstreamReader {
const unsigned char *NextChar;
const unsigned char *LastChar;
+ friend class Deserializer;
/// CurWord - This is the current data we have pulled from the stream but have
/// not returned to the client.
~BitstreamReader() {
// Abbrevs could still exist if the stream was broken. If so, don't leak
// them.
- for (unsigned i = 0, e = CurAbbrevs.size(); i != e; ++i)
+ for (unsigned i = 0, e = static_cast<unsigned>(CurAbbrevs.size());
+ i != e; ++i)
CurAbbrevs[i]->dropRef();
- for (unsigned S = 0, e = BlockScope.size(); S != e; ++S) {
+ for (unsigned S = 0, e = static_cast<unsigned>(BlockScope.size());
+ S != e; ++S) {
std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs;
- for (unsigned i = 0, e = Abbrevs.size(); i != e; ++i)
+ for (unsigned i = 0, e = static_cast<unsigned>(Abbrevs.size());
+ i != e; ++i)
Abbrevs[i]->dropRef();
}
while (!BlockInfoRecords.empty()) {
BlockInfo &Info = BlockInfoRecords.back();
// Free blockinfo abbrev info.
- for (unsigned i = 0, e = Info.Abbrevs.size(); i != e; ++i)
+ for (unsigned i = 0, e = static_cast<unsigned>(Info.Abbrevs.size());
+ i != e; ++i)
Info.Abbrevs[i]->dropRef();
BlockInfoRecords.pop_back();
}
}
- bool AtEndOfStream() const { return NextChar == LastChar; }
+ bool AtEndOfStream() const {
+ return NextChar == LastChar && BitsInCurWord == 0;
+ }
/// GetCurrentBitNo - Return the bit # of the bit we are reading.
uint64_t GetCurrentBitNo() const {
/// JumpToBit - Reset the stream to the specified bit number.
void JumpToBit(uint64_t BitNo) {
- unsigned ByteNo = (BitNo/8) & ~3;
- unsigned WordBitNo = BitNo & 31;
- assert(ByteNo < (unsigned)(LastChar-FirstChar) && "Invalid location");
+ uintptr_t ByteNo = uintptr_t(BitNo/8) & ~3;
+ uintptr_t WordBitNo = uintptr_t(BitNo) & 31;
+ assert(ByteNo < (uintptr_t)(LastChar-FirstChar) && "Invalid location");
// Move the cursor to the right word.
NextChar = FirstChar+ByteNo;
BitsInCurWord = 0;
+ CurWord = 0;
// Skip over any bits that are already consumed.
if (WordBitNo) {
NextChar -= 4;
- Read(WordBitNo);
+ Read(static_cast<unsigned>(WordBitNo));
}
}
if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID)
return &BlockInfoRecords.back();
- for (unsigned i = 0, e = BlockInfoRecords.size(); i != e; ++i)
+ for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
+ i != e; ++i)
if (BlockInfoRecords[i].BlockID == BlockID)
return &BlockInfoRecords[i];
return 0;
return false;
}
- /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, read and enter
- /// the block, returning the BlockID of the block we just entered.
+ /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter
+ /// the block, and return true if the block is valid.
bool EnterSubBlock(unsigned BlockID, unsigned *NumWordsP = 0) {
// Save the current block's state on BlockScope.
BlockScope.push_back(Block(CurCodeSize));
// Add the abbrevs specific to this block to the CurAbbrevs list.
if (BlockInfo *Info = getBlockInfo(BlockID)) {
- for (unsigned i = 0, e = Info->Abbrevs.size(); i != e; ++i) {
+ for (unsigned i = 0, e = static_cast<unsigned>(Info->Abbrevs.size());
+ i != e; ++i) {
CurAbbrevs.push_back(Info->Abbrevs[i]);
CurAbbrevs.back()->addRef();
}
// Block tail:
// [END_BLOCK, <align4bytes>]
SkipToWord();
+
+ PopBlockScope();
+ return false;
+ }
+
+private:
+ void PopBlockScope() {
CurCodeSize = BlockScope.back().PrevCodeSize;
// Delete abbrevs from popped scope.
- for (unsigned i = 0, e = CurAbbrevs.size(); i != e; ++i)
+ for (unsigned i = 0, e = static_cast<unsigned>(CurAbbrevs.size());
+ i != e; ++i)
CurAbbrevs[i]->dropRef();
BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
BlockScope.pop_back();
- return false;
- }
-
+ }
+
//===--------------------------------------------------------------------===//
// Record Processing
//===--------------------------------------------------------------------===//
switch (Op.getEncoding()) {
default: assert(0 && "Unknown encoding!");
case BitCodeAbbrevOp::Fixed:
- Vals.push_back(Read(Op.getEncodingData()));
+ Vals.push_back(Read((unsigned)Op.getEncodingData()));
break;
case BitCodeAbbrevOp::VBR:
- Vals.push_back(ReadVBR64(Op.getEncodingData()));
+ Vals.push_back(ReadVBR64((unsigned)Op.getEncodingData()));
break;
case BitCodeAbbrevOp::Char6:
Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6)));
}
}
- unsigned Code = Vals[0];
+ unsigned Code = (unsigned)Vals[0];
Vals.erase(Vals.begin());
return Code;
}
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
unsigned NumOpInfo = ReadVBR(5);
for (unsigned i = 0; i != NumOpInfo; ++i) {
- bool IsLiteral = Read(1);
+ bool IsLiteral = Read(1) ? true : false;
if (IsLiteral) {
Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8)));
continue;
default: break; // Default behavior, ignore unknown content.
case bitc::BLOCKINFO_CODE_SETBID:
if (Record.size() < 1) return true;
- CurBlockInfo = &getOrCreateBlockInfo(Record[0]);
+ CurBlockInfo = &getOrCreateBlockInfo((unsigned)Record[0]);
break;
}
}