diff options
Diffstat (limited to 'lib/Bitcode')
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 28 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 75 |
2 files changed, 51 insertions, 52 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 737e35f8f6..23d632a330 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -182,7 +182,7 @@ const Type *BitcodeReader::getTypeByID(unsigned ID, bool isTypeTable) { //===----------------------------------------------------------------------===// bool BitcodeReader::ParseParamAttrBlock() { - if (Stream.EnterSubBlock()) + if (Stream.EnterSubBlock(bitc::PARAMATTR_BLOCK_ID)) return Error("Malformed block record"); if (!ParamAttrs.empty()) @@ -239,7 +239,7 @@ bool BitcodeReader::ParseParamAttrBlock() { bool BitcodeReader::ParseTypeTable() { - if (Stream.EnterSubBlock()) + if (Stream.EnterSubBlock(bitc::TYPE_BLOCK_ID)) return Error("Malformed block record"); if (!TypeList.empty()) @@ -378,7 +378,7 @@ bool BitcodeReader::ParseTypeTable() { bool BitcodeReader::ParseTypeSymbolTable() { - if (Stream.EnterSubBlock()) + if (Stream.EnterSubBlock(bitc::TYPE_SYMTAB_BLOCK_ID)) return Error("Malformed block record"); SmallVector<uint64_t, 64> Record; @@ -426,7 +426,7 @@ bool BitcodeReader::ParseTypeSymbolTable() { } bool BitcodeReader::ParseValueSymbolTable() { - if (Stream.EnterSubBlock()) + if (Stream.EnterSubBlock(bitc::VALUE_SYMTAB_BLOCK_ID)) return Error("Malformed block record"); SmallVector<uint64_t, 64> Record; @@ -536,7 +536,7 @@ bool BitcodeReader::ResolveGlobalAndAliasInits() { bool BitcodeReader::ParseConstants() { - if (Stream.EnterSubBlock()) + if (Stream.EnterSubBlock(bitc::CONSTANTS_BLOCK_ID)) return Error("Malformed block record"); SmallVector<uint64_t, 64> Record; @@ -768,7 +768,7 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) { if (TheModule) return Error("Multiple MODULE_BLOCKs in same stream"); - if (Stream.EnterSubBlock()) + if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID)) return Error("Malformed block record"); // Otherwise, create the module. @@ -1022,11 +1022,19 @@ bool BitcodeReader::ParseBitcode() { unsigned BlockID = Stream.ReadSubBlockID(); // We only know the MODULE subblock ID. - if (BlockID == bitc::MODULE_BLOCK_ID) { + switch (BlockID) { + case bitc::BLOCKINFO_BLOCK_ID: + if (Stream.ReadBlockInfoBlock()) + return Error("Malformed BlockInfoBlock"); + break; + case bitc::MODULE_BLOCK_ID: if (ParseModule(Buffer->getBufferIdentifier())) return true; - } else if (Stream.SkipBlock()) { - return Error("Malformed block record"); + break; + default: + if (Stream.SkipBlock()) + return Error("Malformed block record"); + break; } } @@ -1072,7 +1080,7 @@ Module *BitcodeReader::materializeModule(std::string *ErrInfo) { /// ParseFunctionBody - Lazily parse the specified function body block. bool BitcodeReader::ParseFunctionBody(Function *F) { - if (Stream.EnterSubBlock()) + if (Stream.EnterSubBlock(bitc::FUNCTION_BLOCK_ID)) return Error("Malformed block record"); unsigned ModuleValueListSize = ValueList.size(); diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 6ee3a4a347..35e75da303 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -714,36 +714,6 @@ static void WriteValueSymbolTable(const ValueSymbolTable &VST, if (VST.empty()) return; Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 3); - { // 8-bit fixed-width VST_ENTRY/VST_BBENTRY strings. - BitCodeAbbrev *Abbv = new BitCodeAbbrev(); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); - if (Stream.EmitAbbrev(Abbv) != VST_ENTRY_8_ABBREV) - assert(0 && "Unexpected abbrev ordering!"); - } - - { // 7-bit fixed width VST_ENTRY strings. - BitCodeAbbrev *Abbv = new BitCodeAbbrev(); - Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_ENTRY)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); - if (Stream.EmitAbbrev(Abbv) != VST_ENTRY_7_ABBREV) - assert(0 && "Unexpected abbrev ordering!"); - } - { // 7-bit fixed width VST_BBENTRY strings. - BitCodeAbbrev *Abbv = new BitCodeAbbrev(); - Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_BBENTRY)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); - if (Stream.EmitAbbrev(Abbv) != VST_BBENTRY_7_ABBREV) - assert(0 && "Unexpected abbrev ordering!"); - } - - // FIXME: Set up the abbrev, we know how many values there are! // FIXME: We know if the type names can use 7-bit ascii. SmallVector<unsigned, 64> NameVals; @@ -909,19 +879,40 @@ static void WriteBlockInfo(BitstreamWriter &Stream) { // We only want to emit block info records for blocks that have multiple // instances: CONSTANTS_BLOCK, FUNCTION_BLOCK and VALUE_SYMTAB_BLOCK. Other // blocks can defined their abbrevs inline. - Stream.EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, 2); - -#if 0 - // Configure TYPE_SYMTAB_BLOCK's. - - // Add an abbrev for VST_ENTRY where the characters each fit in 7 bits. - BitCodeAbbrev *Abbv = new BitCodeAbbrev(); - Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_ENTRY)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8); // Value ID - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage. + Stream.EnterBlockInfoBlock(2); + + { // 8-bit fixed-width VST_ENTRY/VST_BBENTRY strings. + BitCodeAbbrev *Abbv = new BitCodeAbbrev(); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); + if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID, + Abbv) != VST_ENTRY_8_ABBREV) + assert(0 && "Unexpected abbrev ordering!"); + } + + { // 7-bit fixed width VST_ENTRY strings. + BitCodeAbbrev *Abbv = new BitCodeAbbrev(); + Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_ENTRY)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); + if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID, + Abbv) != VST_ENTRY_7_ABBREV) + assert(0 && "Unexpected abbrev ordering!"); + } + { // 7-bit fixed width VST_BBENTRY strings. + BitCodeAbbrev *Abbv = new BitCodeAbbrev(); + Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_BBENTRY)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); + if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID, + Abbv) != VST_BBENTRY_7_ABBREV) + assert(0 && "Unexpected abbrev ordering!"); + } - xxx = Stream.EmitAbbrev(Abbv); -#endif Stream.ExitBlock(); } |