diff options
Diffstat (limited to 'include/llvm/Bitcode')
-rw-r--r-- | include/llvm/Bitcode/Archive.h | 4 | ||||
-rw-r--r-- | include/llvm/Bitcode/BitCodes.h | 34 | ||||
-rw-r--r-- | include/llvm/Bitcode/BitstreamReader.h | 132 | ||||
-rw-r--r-- | include/llvm/Bitcode/BitstreamWriter.h | 112 | ||||
-rw-r--r-- | include/llvm/Bitcode/Deserialize.h | 202 | ||||
-rw-r--r-- | include/llvm/Bitcode/LLVMBitCodes.h | 40 | ||||
-rw-r--r-- | include/llvm/Bitcode/ReaderWriter.h | 6 | ||||
-rw-r--r-- | include/llvm/Bitcode/Serialization.h | 8 | ||||
-rw-r--r-- | include/llvm/Bitcode/SerializationFwd.h | 4 | ||||
-rw-r--r-- | include/llvm/Bitcode/Serialize.h | 86 |
10 files changed, 314 insertions, 314 deletions
diff --git a/include/llvm/Bitcode/Archive.h b/include/llvm/Bitcode/Archive.h index 6ba11531dd..a3631ace54 100644 --- a/include/llvm/Bitcode/Archive.h +++ b/include/llvm/Bitcode/Archive.h @@ -204,7 +204,7 @@ class ArchiveMember : public ilist_node<ArchiveMember> { /// applications and the linkers. Consequently, the implementation of the class /// is optimized for reading. class Archive { - + /// @name Types /// @{ public: @@ -485,7 +485,7 @@ class Archive { void writeSymbolTable(std::ofstream& ARFile); /// Writes one ArchiveMember to an ofstream. If an error occurs, returns - /// false, otherwise true. If an error occurs and error is non-null then + /// false, otherwise true. If an error occurs and error is non-null then /// it will be set to an error message. /// @returns false Writing member succeeded /// @returns true Writing member failed, \p error set to error message diff --git a/include/llvm/Bitcode/BitCodes.h b/include/llvm/Bitcode/BitCodes.h index 111b1e4fea..277ae9e1d4 100644 --- a/include/llvm/Bitcode/BitCodes.h +++ b/include/llvm/Bitcode/BitCodes.h @@ -29,7 +29,7 @@ namespace bitc { CodeLenWidth = 4, // Codelen are VBR-4. BlockSizeWidth = 32 // BlockSize up to 2^32 32-bit words = 16GB per block. }; - + // The standard abbrev namespace always has a way to exit a block, enter a // nested block, define abbrevs, and define an unabbreviated record. enum FixedAbbrevIDs { @@ -41,16 +41,16 @@ namespace bitc { /// single bit to indicate if it is a literal encoding. If so, the value is /// emitted with a vbr8. If not, the encoding is emitted as 3 bits followed /// by the info value as a vbr5 if needed. - DEFINE_ABBREV = 2, - + DEFINE_ABBREV = 2, + // UNABBREV_RECORDs are emitted with a vbr6 for the record code, followed by // a vbr6 for the # operands, followed by vbr6's for each operand. UNABBREV_RECORD = 3, - + // This is not a code, this is a marker for the first abbrev assignment. FIRST_APPLICATION_ABBREV = 4 }; - + /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO /// block, which contains metadata about other blocks in the file. enum StandardBlockIDs { @@ -58,11 +58,11 @@ namespace bitc { /// standard abbrevs that should be available to all blocks of a specified /// ID. BLOCKINFO_BLOCK_ID = 0, - + // Block IDs 1-7 are reserved for future expansion. FIRST_APPLICATION_BLOCKID = 8 }; - + /// BlockInfoCodes - The blockinfo block contains metadata about user-defined /// blocks. enum BlockInfoCodes { @@ -71,7 +71,7 @@ namespace bitc { // block, instead of the BlockInfo block. // BLOCKNAME: give string name to block, if desired. }; - + } // End bitc namespace /// BitCodeAbbrevOp - This describes one or more operands in an abbreviation. @@ -90,24 +90,24 @@ public: Array = 3, // A sequence of fields, next field species elt encoding. Char6 = 4 // A 6-bit fixed field which maps to [a-zA-Z0-9._]. }; - + explicit BitCodeAbbrevOp(uint64_t V) : Val(V), IsLiteral(true) {} explicit BitCodeAbbrevOp(Encoding E, uint64_t Data = 0) : Val(Data), IsLiteral(false), Enc(E) {} - + bool isLiteral() const { return IsLiteral; } bool isEncoding() const { return !IsLiteral; } // Accessors for literals. uint64_t getLiteralValue() const { assert(isLiteral()); return Val; } - + // Accessors for encoding info. Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; } uint64_t getEncodingData() const { assert(isEncoding() && hasEncodingData()); return Val; } - + bool hasEncodingData() const { return hasEncodingData(getEncoding()); } static bool hasEncodingData(Encoding E) { switch (E) { @@ -120,7 +120,7 @@ public: return false; } } - + /// isChar6 - Return true if this character is legal in the Char6 encoding. static bool isChar6(char C) { if (C >= 'a' && C <= 'z') return true; @@ -138,7 +138,7 @@ public: assert(0 && "Not a value Char6 character!"); return 0; } - + static char DecodeChar6(unsigned V) { assert((V & ~63) == 0 && "Not a Char6 encoded character!"); if (V < 26) return V+'a'; @@ -149,7 +149,7 @@ public: assert(0 && "Not a value Char6 character!"); return ' '; } - + }; /// BitCodeAbbrev - This class represents an abbreviation record. An @@ -161,7 +161,7 @@ class BitCodeAbbrev { ~BitCodeAbbrev() {} public: BitCodeAbbrev() : RefCount(1) {} - + void addRef() { ++RefCount; } void dropRef() { if (--RefCount == 0) delete this; } @@ -171,7 +171,7 @@ public: const BitCodeAbbrevOp &getOperandInfo(unsigned N) const { return OperandList[N]; } - + void Add(const BitCodeAbbrevOp &OpInfo) { OperandList.push_back(OpInfo); } diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h index 3b7a9b61e6..7cbd10f532 100644 --- a/include/llvm/Bitcode/BitstreamReader.h +++ b/include/llvm/Bitcode/BitstreamReader.h @@ -19,35 +19,35 @@ #include <vector> 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. uint32_t CurWord; - + /// BitsInCurWord - This is the number of bits in CurWord that are valid. This /// is always from [0...31] inclusive. unsigned BitsInCurWord; - + // CurCodeSize - This is the declared size of code values used for the current // block, in bits. unsigned CurCodeSize; /// CurAbbrevs - Abbrevs installed at in this block. std::vector<BitCodeAbbrev*> CurAbbrevs; - + struct Block { unsigned PrevCodeSize; std::vector<BitCodeAbbrev*> PrevAbbrevs; explicit Block(unsigned PCS) : PrevCodeSize(PCS) {} }; - + /// BlockScope - This tracks the codesize of parent blocks. SmallVector<Block, 8> BlockScope; @@ -58,7 +58,7 @@ class BitstreamReader { std::vector<BitCodeAbbrev*> Abbrevs; }; std::vector<BlockInfo> BlockInfoRecords; - + /// FirstChar - This remembers the first byte of the stream. const unsigned char *FirstChar; public: @@ -72,7 +72,7 @@ public: BitstreamReader(const unsigned char *Start, const unsigned char *End) { init(Start, End); } - + void init(const unsigned char *Start, const unsigned char *End) { NextChar = FirstChar = Start; LastChar = End; @@ -81,7 +81,7 @@ public: BitsInCurWord = 0; CurCodeSize = 2; } - + ~BitstreamReader() { // Abbrevs could still exist if the stream was broken. If so, don't leak // them. @@ -96,7 +96,7 @@ public: i != e; ++i) Abbrevs[i]->dropRef(); } - + // Free the BlockInfoRecords. while (!BlockInfoRecords.empty()) { BlockInfo &Info = BlockInfoRecords.back(); @@ -107,37 +107,37 @@ public: BlockInfoRecords.pop_back(); } } - + bool AtEndOfStream() const { return NextChar == LastChar && BitsInCurWord == 0; } - + /// GetCurrentBitNo - Return the bit # of the bit we are reading. uint64_t GetCurrentBitNo() const { return (NextChar-FirstChar)*8 + ((32-BitsInCurWord) & 31); } - + /// JumpToBit - Reset the stream to the specified bit number. void JumpToBit(uint64_t BitNo) { 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(static_cast<unsigned>(WordBitNo)); } } - + /// GetAbbrevIDWidth - Return the number of bits used to encode an abbrev #. unsigned GetAbbrevIDWidth() const { return CurCodeSize; } - + uint32_t Read(unsigned NumBits) { // If the field is fully contained by CurWord, return it quickly. if (BitsInCurWord >= NumBits) { @@ -153,20 +153,20 @@ public: BitsInCurWord = 0; return 0; } - + unsigned R = CurWord; // Read the next word from the stream. CurWord = (NextChar[0] << 0) | (NextChar[1] << 8) | (NextChar[2] << 16) | (NextChar[3] << 24); NextChar += 4; - + // Extract NumBits-BitsInCurWord from what we just read. unsigned BitsLeft = NumBits-BitsInCurWord; - + // Be careful here, BitsLeft is in the range [1..32] inclusive. R |= (CurWord & (~0U >> (32-BitsLeft))) << BitsInCurWord; - + // BitsLeft bits have just been used up from CurWord. if (BitsLeft != 32) CurWord >>= BitsLeft; @@ -175,14 +175,14 @@ public: BitsInCurWord = 32-BitsLeft; return R; } - + uint64_t Read64(unsigned NumBits) { if (NumBits <= 32) return Read(NumBits); - + uint64_t V = Read(32); return V | (uint64_t)Read(NumBits-32) << 32; } - + uint32_t ReadVBR(unsigned NumBits) { uint32_t Piece = Read(NumBits); if ((Piece & (1U << (NumBits-1))) == 0) @@ -195,25 +195,25 @@ public: if ((Piece & (1U << (NumBits-1))) == 0) return Result; - + NextBit += NumBits-1; Piece = Read(NumBits); } } - + uint64_t ReadVBR64(unsigned NumBits) { uint64_t Piece = Read(NumBits); if ((Piece & (1U << (NumBits-1))) == 0) return Piece; - + uint64_t Result = 0; unsigned NextBit = 0; while (1) { Result |= (Piece & ((1U << (NumBits-1))-1)) << NextBit; - + if ((Piece & (1U << (NumBits-1))) == 0) return Result; - + NextBit += NumBits-1; Piece = Read(NumBits); } @@ -224,7 +224,7 @@ public: CurWord = 0; } - + unsigned ReadCode() { return Read(CurCodeSize); } @@ -232,7 +232,7 @@ public: //===--------------------------------------------------------------------===// // Block Manipulation //===--------------------------------------------------------------------===// - + private: /// getBlockInfo - If there is block info for the specified ID, return it, /// otherwise return null. @@ -240,7 +240,7 @@ private: // Common case, the most recent entry matches BlockID. if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID) return &BlockInfoRecords.back(); - + for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size()); i != e; ++i) if (BlockInfoRecords[i].BlockID == BlockID) @@ -248,8 +248,8 @@ private: return 0; } public: - - + + // Block header: // [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen] @@ -258,7 +258,7 @@ public: unsigned ReadSubBlockID() { return ReadVBR(bitc::BlockIDWidth); } - + /// SkipBlock - Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip /// over the body of this block. If the block record is malformed, return /// true. @@ -268,23 +268,23 @@ public: ReadVBR(bitc::CodeLenWidth); SkipToWord(); unsigned NumWords = Read(bitc::BlockSizeWidth); - + // Check that the block wasn't partially defined, and that the offset isn't // bogus. if (AtEndOfStream() || NextChar+NumWords*4 > LastChar) return true; - + NextChar += NumWords*4; return false; } - + /// 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)); BlockScope.back().PrevAbbrevs.swap(CurAbbrevs); - + // Add the abbrevs specific to this block to the CurAbbrevs list. if (BlockInfo *Info = getBlockInfo(BlockID)) { for (unsigned i = 0, e = static_cast<unsigned>(Info->Abbrevs.size()); @@ -293,50 +293,50 @@ public: CurAbbrevs.back()->addRef(); } } - + // Get the codesize of this block. CurCodeSize = ReadVBR(bitc::CodeLenWidth); SkipToWord(); unsigned NumWords = Read(bitc::BlockSizeWidth); if (NumWordsP) *NumWordsP = NumWords; - + // Validate that this block is sane. if (CurCodeSize == 0 || AtEndOfStream() || NextChar+NumWords*4 > LastChar) return true; - + return false; } - + bool ReadBlockEnd() { if (BlockScope.empty()) return true; - + // 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 = static_cast<unsigned>(CurAbbrevs.size()); i != e; ++i) CurAbbrevs[i]->dropRef(); - + BlockScope.back().PrevAbbrevs.swap(CurAbbrevs); BlockScope.pop_back(); - } - + } + //===--------------------------------------------------------------------===// // Record Processing //===--------------------------------------------------------------------===// - + private: - void ReadAbbreviatedField(const BitCodeAbbrevOp &Op, + void ReadAbbreviatedField(const BitCodeAbbrevOp &Op, SmallVectorImpl<uint64_t> &Vals) { if (Op.isLiteral()) { // If the abbrev specifies the literal value to use, use it. @@ -366,7 +366,7 @@ public: Vals.push_back(ReadVBR64(6)); return Code; } - + unsigned AbbrevNo = AbbrevID-bitc::FIRST_APPLICATION_ABBREV; assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!"); BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo]; @@ -388,16 +388,16 @@ public: ReadAbbreviatedField(EltEnc, Vals); } } - + unsigned Code = (unsigned)Vals[0]; Vals.erase(Vals.begin()); return Code; } - + //===--------------------------------------------------------------------===// // Abbrev Processing //===--------------------------------------------------------------------===// - + void ReadAbbrevRecord() { BitCodeAbbrev *Abbv = new BitCodeAbbrev(); unsigned NumOpInfo = ReadVBR(5); @@ -416,30 +416,30 @@ public: } CurAbbrevs.push_back(Abbv); } - + //===--------------------------------------------------------------------===// // BlockInfo Block Reading //===--------------------------------------------------------------------===// - -private: + +private: BlockInfo &getOrCreateBlockInfo(unsigned BlockID) { if (BlockInfo *BI = getBlockInfo(BlockID)) return *BI; - + // Otherwise, add a new record. BlockInfoRecords.push_back(BlockInfo()); BlockInfoRecords.back().BlockID = BlockID; return BlockInfoRecords.back(); } - + public: - + bool ReadBlockInfoBlock() { if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true; SmallVector<uint64_t, 64> Record; BlockInfo *CurBlockInfo = 0; - + // Read all the records for this module. while (1) { unsigned Code = ReadCode(); @@ -455,7 +455,7 @@ public: 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(); @@ -473,7 +473,7 @@ public: CurBlockInfo = &getOrCreateBlockInfo((unsigned)Record[0]); break; } - } + } } }; diff --git a/include/llvm/Bitcode/BitstreamWriter.h b/include/llvm/Bitcode/BitstreamWriter.h index 7fd23fe416..aed7c2f48a 100644 --- a/include/llvm/Bitcode/BitstreamWriter.h +++ b/include/llvm/Bitcode/BitstreamWriter.h @@ -25,10 +25,10 @@ class BitstreamWriter { /// CurBit - Always between 0 and 31 inclusive, specifies the next bit to use. unsigned CurBit; - + /// CurValue - The current value. Only bits < CurBit are valid. uint32_t CurValue; - + /// CurCodeSize - This is the declared size of code values used for the /// current block, in bits. unsigned CurCodeSize; @@ -36,7 +36,7 @@ class BitstreamWriter { /// BlockInfoCurBID - When emitting a BLOCKINFO_BLOCK, this is the currently /// selected BLOCK ID. unsigned BlockInfoCurBID; - + /// CurAbbrevs - Abbrevs installed at in this block. std::vector<BitCodeAbbrev*> CurAbbrevs; @@ -46,10 +46,10 @@ class BitstreamWriter { std::vector<BitCodeAbbrev*> PrevAbbrevs; Block(unsigned PCS, unsigned SSW) : PrevCodeSize(PCS), StartSizeWord(SSW) {} }; - + /// BlockScope - This tracks the current blocks that we have entered. std::vector<Block> BlockScope; - + /// BlockInfo - This contains information emitted to BLOCKINFO_BLOCK blocks. /// These describe abbreviations that all blocks of the specified ID inherit. struct BlockInfo { @@ -57,15 +57,15 @@ class BitstreamWriter { std::vector<BitCodeAbbrev*> Abbrevs; }; std::vector<BlockInfo> BlockInfoRecords; - + public: - explicit BitstreamWriter(std::vector<unsigned char> &O) + explicit BitstreamWriter(std::vector<unsigned char> &O) : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {} ~BitstreamWriter() { assert(CurBit == 0 && "Unflused data remaining"); assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance"); - + // Free the BlockInfoRecords. while (!BlockInfoRecords.empty()) { BlockInfo &Info = BlockInfoRecords.back(); @@ -82,7 +82,7 @@ public: //===--------------------------------------------------------------------===// // Basic Primitives for emitting bits to the stream. //===--------------------------------------------------------------------===// - + void Emit(uint32_t Val, unsigned NumBits) { assert(NumBits <= 32 && "Invalid value size!"); assert((Val & ~(~0U >> (32-NumBits))) == 0 && "High bits set!"); @@ -91,21 +91,21 @@ public: CurBit += NumBits; return; } - + // Add the current word. unsigned V = CurValue; Out.push_back((unsigned char)(V >> 0)); Out.push_back((unsigned char)(V >> 8)); Out.push_back((unsigned char)(V >> 16)); Out.push_back((unsigned char)(V >> 24)); - + if (CurBit) CurValue = Val >> (32-CurBit); else CurValue = 0; CurBit = (CurBit+NumBits) & 31; } - + void Emit64(uint64_t Val, unsigned NumBits) { if (NumBits <= 32) Emit((uint32_t)Val, NumBits); @@ -114,7 +114,7 @@ public: Emit((uint32_t)(Val >> 32), NumBits-32); } } - + void FlushToWord() { if (CurBit) { unsigned V = CurValue; @@ -126,40 +126,40 @@ public: CurValue = 0; } } - + void EmitVBR(uint32_t Val, unsigned NumBits) { uint32_t Threshold = 1U << (NumBits-1); - + // Emit the bits with VBR encoding, NumBits-1 bits at a time. while (Val >= Threshold) { Emit((Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits); Val >>= NumBits-1; } - + Emit(Val, NumBits); } - + void EmitVBR64(uint64_t Val, unsigned NumBits) { if ((uint32_t)Val == Val) return EmitVBR((uint32_t)Val, NumBits); - + uint64_t Threshold = 1U << (NumBits-1); - + // Emit the bits with VBR encoding, NumBits-1 bits at a time. while (Val >= Threshold) { Emit(((uint32_t)Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits); Val >>= NumBits-1; } - + Emit((uint32_t)Val, NumBits); } - + /// EmitCode - Emit the specified code. void EmitCode(unsigned Val) { Emit(Val, CurCodeSize); } - + // BackpatchWord - Backpatch a 32-bit word in the output with the specified // value. void BackpatchWord(unsigned ByteNo, unsigned NewWord) { @@ -168,25 +168,25 @@ public: Out[ByteNo++] = (unsigned char)(NewWord >> 16); Out[ByteNo ] = (unsigned char)(NewWord >> 24); } - + //===--------------------------------------------------------------------===// // Block Manipulation //===--------------------------------------------------------------------===// - + /// getBlockInfo - If there is block info for the specified ID, return it, /// otherwise return null. BlockInfo *getBlockInfo(unsigned BlockID) { // Common case, the most recent entry matches BlockID. if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID) return &BlockInfoRecords.back(); - + for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size()); i != e; ++i) if (BlockInfoRecords[i].BlockID == BlockID) return &BlockInfoRecords[i]; return 0; } - + void EnterSubblock(unsigned BlockID, unsigned CodeLen) { // Block header: // [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen] @@ -194,15 +194,15 @@ public: EmitVBR(BlockID, bitc::BlockIDWidth); EmitVBR(CodeLen, bitc::CodeLenWidth); FlushToWord(); - + unsigned BlockSizeWordLoc = static_cast<unsigned>(Out.size()); unsigned OldCodeSize = CurCodeSize; - + // Emit a placeholder, which will be replaced when the block is popped. Emit(0, bitc::BlockSizeWidth); - + CurCodeSize = CodeLen; - + // Push the outer block's abbrev set onto the stack, start out with an // empty abbrev set. BlockScope.push_back(Block(OldCodeSize, BlockSizeWordLoc/4)); @@ -218,17 +218,17 @@ public: } } } - + void ExitBlock() { assert(!BlockScope.empty() && "Block scope imbalance!"); - + // Delete all abbrevs. for (unsigned i = 0, e = static_cast<unsigned>(CurAbbrevs.size()); i != e; ++i) CurAbbrevs[i]->dropRef(); - + const Block &B = BlockScope.back(); - + // Block tail: // [END_BLOCK, <align4bytes>] EmitCode(bitc::END_BLOCK); @@ -237,20 +237,20 @@ public: // Compute the size of the block, in words, not counting the size field. unsigned SizeInWords= static_cast<unsigned>(Out.size())/4-B.StartSizeWord-1; unsigned ByteNo = B.StartSizeWord*4; - + // Update the block size field in the header of this sub-block. BackpatchWord(ByteNo, SizeInWords); - + // Restore the inner block's code size and abbrev table. CurCodeSize = B.PrevCodeSize; BlockScope.back().PrevAbbrevs.swap(CurAbbrevs); BlockScope.pop_back(); } - + //===--------------------------------------------------------------------===// // Record Emission //===--------------------------------------------------------------------===// - + private: /// EmitAbbreviatedField - Emit a single scalar field value with the specified /// encoding. @@ -263,7 +263,7 @@ private: "Invalid abbrev for record!"); return; } - + // Encode the value as we are commanded. switch (Op.getEncoding()) { default: assert(0 && "Unknown encoding!"); @@ -276,10 +276,10 @@ private: case BitCodeAbbrevOp::Char6: Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6); break; - } + } } public: - + /// EmitRecord - Emit the specified record to the stream, using an abbrev if /// we have one to compress the output. template<typename uintty> @@ -289,12 +289,12 @@ public: unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV; assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!"); BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo]; - + EmitCode(Abbrev); - + // Insert the code into Vals to treat it uniformly. Vals.insert(Vals.begin(), Code); - + unsigned RecordIdx = 0; for (unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos()); i != e; ++i) { @@ -307,10 +307,10 @@ public: // Array case. assert(i+2 == e && "array op not second to last?"); const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); - + // Emit a vbr6 to indicate the number of elements present. EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6); - + // Emit each field. for (; RecordIdx != Vals.size(); ++RecordIdx) EmitAbbreviatedField(EltEnc, Vals[RecordIdx]); @@ -331,7 +331,7 @@ public: //===--------------------------------------------------------------------===// // Abbrev Emission //===--------------------------------------------------------------------===// - + private: // Emit the abbreviation as a DEFINE_ABBREV record. void EncodeAbbrev(BitCodeAbbrev *Abbv) { @@ -351,7 +351,7 @@ private: } } public: - + /// EmitAbbrev - This emits an abbreviation to the stream. Note that this /// method takes ownership of the specified abbrev. unsigned EmitAbbrev(BitCodeAbbrev *Abbv) { @@ -361,17 +361,17 @@ public: return static_cast<unsigned>(CurAbbrevs.size())-1 + bitc::FIRST_APPLICATION_ABBREV; } - + //===--------------------------------------------------------------------===// // BlockInfo Block Emission //===--------------------------------------------------------------------===// - + /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK. void EnterBlockInfoBlock(unsigned CodeWidth) { EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, CodeWidth); BlockInfoCurBID = -1U; } -private: +private: /// SwitchToBlockID - If we aren't already talking about the specified block /// ID, emit a BLOCKINFO_CODE_SETBID record. void SwitchToBlockID(unsigned BlockID) { @@ -385,25 +385,25 @@ private: BlockInfo &getOrCreateBlockInfo(unsigned BlockID) { if (BlockInfo *BI = getBlockInfo(BlockID)) return *BI; - + // Otherwise, add a new record. BlockInfoRecords.push_back(BlockInfo()); BlockInfoRecords.back().BlockID = BlockID; return BlockInfoRecords.back(); } - + public: - + /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified /// BlockID. unsigned EmitBlockInfoAbbrev(unsigned BlockID, BitCodeAbbrev *Abbv) { SwitchToBlockID(BlockID); EncodeAbbrev(Abbv); - + // Add the abbrev to the specified block record. BlockInfo &Info = getOrCreateBlockInfo(BlockID); Info.Abbrevs.push_back(Abbv); - + return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV; } }; diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h index 8c9ea89d15..cc85d9fb5e 100644 --- a/include/llvm/Bitcode/Deserialize.h +++ b/include/llvm/Bitcode/Deserialize.h @@ -24,44 +24,44 @@ #include <vector> namespace llvm { - -class Deserializer { + +class Deserializer { //===----------------------------------------------------------===// // Internal type definitions. //===----------------------------------------------------------===// - + struct BPNode { BPNode* Next; uintptr_t& PtrRef; - - BPNode(BPNode* n, uintptr_t& pref) + + BPNode(BPNode* n, uintptr_t& pref) : Next(n), PtrRef(pref) { PtrRef = 0; } }; - - struct BPEntry { + + struct BPEntry { union { BPNode* Head; void* Ptr; }; - + BPEntry() : Head(NULL) {} - + static inline bool isPod() { return true; } - - void SetPtr(BPNode*& FreeList, void* P); - }; - + + void SetPtr(BPNode*& FreeList, void* P); + }; + class BPKey { unsigned Raw; - + public: BPKey(SerializedPtrID PtrId) : Raw(PtrId << 1) { assert (PtrId > 0); } BPKey(unsigned code, unsigned) : Raw(code) {} - + void MarkFinal() { Raw |= 0x1; } bool hasFinalPtr() const { return Raw & 0x1 ? true : false; } SerializedPtrID getID() const { return Raw >> 1; } - + static inline BPKey getEmptyKey() { return BPKey(0,0); } static inline BPKey getTombstoneKey() { return BPKey(1,0); } static inline unsigned getHashValue(const BPKey& K) { return K.Raw & ~0x1; } @@ -69,25 +69,25 @@ class Deserializer { static bool isEqual(const BPKey& K1, const BPKey& K2) { return (K1.Raw ^ K2.Raw) & ~0x1 ? false : true; } - + static bool isPod() { return true; } }; - + typedef llvm::DenseMap<BPKey,BPEntry,BPKey,BPEntry> MapTy; //===----------------------------------------------------------===// // Publicly visible types. //===----------------------------------------------------------===// - -public: + +public: struct Location { uint64_t BitNo; unsigned BlockID; unsigned NumWords; - - Location(uint64_t bit, unsigned bid, unsigned words) + + Location(uint64_t bit, unsigned bid, unsigned words) : BitNo(bit), BlockID(bid), NumWords(words) {} - + Location() : BitNo(0), BlockID(0), NumWords(0) {} Location& operator=(Location& RHS) { @@ -96,21 +96,21 @@ public: NumWords = RHS.NumWords; return *this; } - - bool operator==(const Location& RHS) const { return BitNo == RHS.BitNo; } + + bool operator==(const Location& RHS) const { return BitNo == RHS.BitNo; } bool operator!=(const Location& RHS) const { return BitNo != RHS.BitNo; } - + bool contains(const Location& RHS) const { if (RHS.BitNo < BitNo) return false; if ((RHS.BitNo - BitNo) >> 5 < NumWords) return true; - + return false; } }; - + //===----------------------------------------------------------===// // Internal data members. //===----------------------------------------------------------===// @@ -126,20 +126,20 @@ private: unsigned AbbrevNo; unsigned RecordCode; uint64_t StreamStart; - + //===----------------------------------------------------------===// // Public Interface. |