X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FBitcode%2FBitstreamWriter.h;h=f76bb88dee8c8214850e9e189074872636109125;hb=5eca075b74d62c621b160aa216b4cd50829a2cc7;hp=ef7d7e7ef4284939e032d1023295a86b97bdfbe0;hpb=cdf2b3b2f88d6f961b664e3f67a8ee37b46b0d27;p=oota-llvm.git diff --git a/include/llvm/Bitcode/BitstreamWriter.h b/include/llvm/Bitcode/BitstreamWriter.h index ef7d7e7ef42..f76bb88dee8 100644 --- a/include/llvm/Bitcode/BitstreamWriter.h +++ b/include/llvm/Bitcode/BitstreamWriter.h @@ -2,8 +2,8 @@ // // 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. // //===----------------------------------------------------------------------===// // @@ -70,7 +70,8 @@ public: 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(Info.Abbrevs.size()); + i != e; ++i) Info.Abbrevs[i]->dropRef(); BlockInfoRecords.pop_back(); } @@ -156,6 +157,15 @@ public: Emit(Val, CurCodeSize); } + // BackpatchWord - Backpatch a 32-bit word in the output with the specified + // value. + void BackpatchWord(unsigned ByteNo, unsigned NewWord) { + Out[ByteNo++] = (unsigned char)(NewWord >> 0); + Out[ByteNo++] = (unsigned char)(NewWord >> 8); + Out[ByteNo++] = (unsigned char)(NewWord >> 16); + Out[ByteNo ] = (unsigned char)(NewWord >> 24); + } + //===--------------------------------------------------------------------===// // Block Manipulation //===--------------------------------------------------------------------===// @@ -167,7 +177,8 @@ public: 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(BlockInfoRecords.size()); + i != e; ++i) if (BlockInfoRecords[i].BlockID == BlockID) return &BlockInfoRecords[i]; return 0; @@ -181,7 +192,7 @@ public: EmitVBR(CodeLen, bitc::CodeLenWidth); FlushToWord(); - unsigned BlockSizeWordLoc = Out.size(); + unsigned BlockSizeWordLoc = static_cast(Out.size()); unsigned OldCodeSize = CurCodeSize; // Emit a placeholder, which will be replaced when the block is popped. @@ -197,7 +208,8 @@ public: // If there is a blockinfo for this BlockID, add all the predefined abbrevs // to the abbrev list. if (BlockInfo *Info = getBlockInfo(BlockID)) { - for (unsigned i = 0, e = Info->Abbrevs.size(); i != e; ++i) { + for (unsigned i = 0, e = static_cast(Info->Abbrevs.size()); + i != e; ++i) { CurAbbrevs.push_back(Info->Abbrevs[i]); Info->Abbrevs[i]->addRef(); } @@ -208,7 +220,8 @@ public: assert(!BlockScope.empty() && "Block scope imbalance!"); // Delete all abbrevs. - for (unsigned i = 0, e = CurAbbrevs.size(); i != e; ++i) + for (unsigned i = 0, e = static_cast(CurAbbrevs.size()); + i != e; ++i) CurAbbrevs[i]->dropRef(); const Block &B = BlockScope.back(); @@ -219,14 +232,11 @@ public: FlushToWord(); // Compute the size of the block, in words, not counting the size field. - unsigned SizeInWords = Out.size()/4-B.StartSizeWord - 1; + unsigned SizeInWords= static_cast(Out.size())/4-B.StartSizeWord-1; unsigned ByteNo = B.StartSizeWord*4; // Update the block size field in the header of this sub-block. - Out[ByteNo++] = (unsigned char)(SizeInWords >> 0); - Out[ByteNo++] = (unsigned char)(SizeInWords >> 8); - Out[ByteNo++] = (unsigned char)(SizeInWords >> 16); - Out[ByteNo++] = (unsigned char)(SizeInWords >> 24); + BackpatchWord(ByteNo, SizeInWords); // Restore the inner block's code size and abbrev table. CurCodeSize = B.PrevCodeSize; @@ -283,7 +293,8 @@ public: Vals.insert(Vals.begin(), Code); unsigned RecordIdx = 0; - for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { + for (unsigned i = 0, e = static_cast(Abbv->getNumOperandInfos()); + i != e; ++i) { const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); if (Op.isLiteral() || Op.getEncoding() != BitCodeAbbrevOp::Array) { assert(RecordIdx < Vals.size() && "Invalid abbrev/record"); @@ -295,7 +306,7 @@ public: const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); // Emit a vbr6 to indicate the number of elements present. - EmitVBR(Vals.size()-RecordIdx, 6); + EmitVBR(static_cast(Vals.size()-RecordIdx), 6); // Emit each field. for (; RecordIdx != Vals.size(); ++RecordIdx) @@ -308,8 +319,8 @@ public: // form. EmitCode(bitc::UNABBREV_RECORD); EmitVBR(Code, 6); - EmitVBR(Vals.size(), 6); - for (unsigned i = 0, e = Vals.size(); i != e; ++i) + EmitVBR(static_cast(Vals.size()), 6); + for (unsigned i = 0, e = static_cast(Vals.size()); i != e; ++i) EmitVBR64(Vals[i], 6); } } @@ -323,7 +334,8 @@ private: void EncodeAbbrev(BitCodeAbbrev *Abbv) { EmitCode(bitc::DEFINE_ABBREV); EmitVBR(Abbv->getNumOperandInfos(), 5); - for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { + for (unsigned i = 0, e = static_cast(Abbv->getNumOperandInfos()); + i != e; ++i) { const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); Emit(Op.isLiteral(), 1); if (Op.isLiteral()) { @@ -343,7 +355,8 @@ public: // Emit the abbreviation as a record. EncodeAbbrev(Abbv); CurAbbrevs.push_back(Abbv); - return CurAbbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV; + return static_cast(CurAbbrevs.size())-1 + + bitc::FIRST_APPLICATION_ABBREV; } //===--------------------------------------------------------------------===//