Chromium Code Reviews| Index: lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp |
| diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp |
| index 1d7d8dc23c94c02b098db1abc58f68c618d3a480..f7d335da94108ebd455c1b5ec488826a1416a2c4 100644 |
| --- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp |
| +++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp |
| @@ -32,6 +32,11 @@ |
| #include <map> |
| using namespace llvm; |
| +/* To turn on debugging for this file, change value of NACL_DEBUGGING to 1. |
|
Karl
2013/05/17 20:52:18
Replaced this with llvm's DEBUG.
|
| + */ |
| +#define NACL_DEBUGGING 0 |
| +#include "llvm/Bitcode/NaCl/NaClDebugging.h" |
| + |
| /// These are manifest constants used by the bitcode writer. They do not need to |
| /// be kept in sync with the reader, but need to be consistent within this file. |
| enum { |
| @@ -40,12 +45,21 @@ enum { |
| VST_ENTRY_7_ABBREV, |
| VST_ENTRY_6_ABBREV, |
| VST_BBENTRY_6_ABBREV, |
| + VST_MAX_ABBREV = VST_BBENTRY_6_ABBREV, |
| // CONSTANTS_BLOCK abbrev id's. |
| CONSTANTS_SETTYPE_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
| CONSTANTS_INTEGER_ABBREV, |
| CONSTANTS_CE_CAST_Abbrev, |
| CONSTANTS_NULL_Abbrev, |
| + CONSTANTS_MAX_ABBREV = CONSTANTS_NULL_Abbrev, |
| + |
| + // CONSTANTS_BLOCK abbrev id's when global (extends list above). |
| + CST_CONSTANTS_AGGREGATE_ABBREV = CONSTANTS_MAX_ABBREV+1, |
| + CST_CONSTANTS_STRING_ABBREV, |
| + CST_CONSTANTS_CSTRING_7_ABBREV, |
| + CST_CONSTANTS_CSTRING_6_ABBREV, |
| + CST_CONSTANTS_MAX_ABBREV = CST_CONSTANTS_CSTRING_6_ABBREV, |
| // FUNCTION_BLOCK abbrev id's. |
| FUNCTION_INST_LOAD_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
| @@ -55,6 +69,24 @@ enum { |
| FUNCTION_INST_RET_VOID_ABBREV, |
| FUNCTION_INST_RET_VAL_ABBREV, |
| FUNCTION_INST_UNREACHABLE_ABBREV, |
| + FUNCTION_INST_MAX_ABBREV = FUNCTION_INST_UNREACHABLE_ABBREV, |
| + |
| + // TYPE_BLOCK_ID_NEW abbrev id's. |
| + TYPE_POINTER_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
| + TYPE_FUNCTION_ABBREV, |
| + TYPE_STRUCT_ANON_ABBREV, |
| + TYPE_STRUCT_NAME_ABBREV, |
| + TYPE_STRUCT_NAMED_ABBREV, |
| + TYPE_ARRAY_ABBREV, |
| + TYPE_MAX_ABBREV = TYPE_ARRAY_ABBREV, |
| + |
| + // META_DATA_BLOCK abbrev id's. |
| + METADATA_STRING_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
| + METADATA_MAX_ABBREV = METADATA_STRING_ABBREV, |
| + |
| + // MODULE_BLOCK abbrev id's. |
| + MODULE_GLOBALVAR_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
| + MODULE_MAX_ABBREV = MODULE_GLOBALVAR_ABBREV, |
| // SwitchInst Magic |
| SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex |
| @@ -160,8 +192,9 @@ static void WriteAttributeGroupTable(const NaClValueEnumerator &VE, |
| NaClBitstreamWriter &Stream) { |
| const std::vector<AttributeSet> &AttrGrps = VE.getAttributeGroups(); |
| if (AttrGrps.empty()) return; |
| + NACL_DEBUG(outs() << "-> WriteAbbributeGroupTable\n"); |
| - Stream.EnterSubblock(naclbitc::PARAMATTR_GROUP_BLOCK_ID, 3); |
| + Stream.EnterSubblock(naclbitc::PARAMATTR_GROUP_BLOCK_ID); |
| SmallVector<uint64_t, 64> Record; |
| for (unsigned i = 0, e = AttrGrps.size(); i != e; ++i) { |
| @@ -202,14 +235,15 @@ static void WriteAttributeGroupTable(const NaClValueEnumerator &VE, |
| } |
| Stream.ExitBlock(); |
| -} |
| + NACL_DEBUG(outs() << "<- WriteAbbributeGroupTable\n");} |
| static void WriteAttributeTable(const NaClValueEnumerator &VE, |
| NaClBitstreamWriter &Stream) { |
| const std::vector<AttributeSet> &Attrs = VE.getAttributes(); |
| if (Attrs.empty()) return; |
| + NACL_DEBUG(outs() << "-> WriteAttributeTable\n"); |
| - Stream.EnterSubblock(naclbitc::PARAMATTR_BLOCK_ID, 3); |
| + Stream.EnterSubblock(naclbitc::PARAMATTR_BLOCK_ID); |
| SmallVector<uint64_t, 64> Record; |
| for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { |
| @@ -222,15 +256,17 @@ static void WriteAttributeTable(const NaClValueEnumerator &VE, |
| } |
| Stream.ExitBlock(); |
| + NACL_DEBUG(outs() << "<- WriteAttributeTable\n"); |
| } |
| /// WriteTypeTable - Write out the type table for a module. |
| static void WriteTypeTable(const NaClValueEnumerator &VE, |
| NaClBitstreamWriter &Stream) { |
| + NACL_DEBUG(outs() << "-> WriteTypeTable\n"); |
| const NaClValueEnumerator::TypeList &TypeList = VE.getTypes(); |
| - Stream.EnterSubblock(naclbitc::TYPE_BLOCK_ID_NEW, |
| - 4 /*count from # abbrevs */); |
| + Stream.EnterSubblock(naclbitc::TYPE_BLOCK_ID_NEW, TYPE_MAX_ABBREV); |
| + |
| SmallVector<uint64_t, 64> TypeVals; |
| uint64_t NumBits = Log2_32_Ceil(VE.getTypes().size()+1); |
| @@ -240,7 +276,8 @@ static void WriteTypeTable(const NaClValueEnumerator &VE, |
| Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_POINTER)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
| Abbv->Add(NaClBitCodeAbbrevOp(0)); // Addrspace = 0 |
| - unsigned PtrAbbrev = Stream.EmitAbbrev(Abbv); |
| + if (TYPE_POINTER_ABBREV != Stream.EmitAbbrev(Abbv)) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| // Abbrev for TYPE_CODE_FUNCTION. |
| Abbv = new NaClBitCodeAbbrev(); |
| @@ -248,8 +285,8 @@ static void WriteTypeTable(const NaClValueEnumerator &VE, |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // isvararg |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
| - |
| - unsigned FunctionAbbrev = Stream.EmitAbbrev(Abbv); |
| + if (TYPE_FUNCTION_ABBREV != Stream.EmitAbbrev(Abbv)) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| // Abbrev for TYPE_CODE_STRUCT_ANON. |
| Abbv = new NaClBitCodeAbbrev(); |
| @@ -257,15 +294,16 @@ static void WriteTypeTable(const NaClValueEnumerator &VE, |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // ispacked |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
| - |
| - unsigned StructAnonAbbrev = Stream.EmitAbbrev(Abbv); |
| + if (TYPE_STRUCT_ANON_ABBREV != Stream.EmitAbbrev(Abbv)) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| // Abbrev for TYPE_CODE_STRUCT_NAME. |
| Abbv = new NaClBitCodeAbbrev(); |
| Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_NAME)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Char6)); |
| - unsigned StructNameAbbrev = Stream.EmitAbbrev(Abbv); |
| + if (TYPE_STRUCT_NAME_ABBREV != Stream.EmitAbbrev(Abbv)) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| // Abbrev for TYPE_CODE_STRUCT_NAMED. |
| Abbv = new NaClBitCodeAbbrev(); |
| @@ -273,16 +311,16 @@ static void WriteTypeTable(const NaClValueEnumerator &VE, |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // ispacked |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
| - |
| - unsigned StructNamedAbbrev = Stream.EmitAbbrev(Abbv); |
| + if (TYPE_STRUCT_NAMED_ABBREV != Stream.EmitAbbrev(Abbv)) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| // Abbrev for TYPE_CODE_ARRAY. |
| Abbv = new NaClBitCodeAbbrev(); |
| Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_ARRAY)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); // size |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
| - |
| - unsigned ArrayAbbrev = Stream.EmitAbbrev(Abbv); |
| + if (TYPE_ARRAY_ABBREV != Stream.EmitAbbrev(Abbv)) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| // Emit an entry count so the reader can reserve space. |
| TypeVals.push_back(TypeList.size()); |
| @@ -319,7 +357,7 @@ static void WriteTypeTable(const NaClValueEnumerator &VE, |
| TypeVals.push_back(VE.getTypeID(PTy->getElementType())); |
| unsigned AddressSpace = PTy->getAddressSpace(); |
| TypeVals.push_back(AddressSpace); |
| - if (AddressSpace == 0) AbbrevToUse = PtrAbbrev; |
| + if (AddressSpace == 0) AbbrevToUse = TYPE_POINTER_ABBREV; |
| break; |
| } |
| case Type::FunctionTyID: { |
| @@ -330,7 +368,7 @@ static void WriteTypeTable(const NaClValueEnumerator &VE, |
| TypeVals.push_back(VE.getTypeID(FT->getReturnType())); |
| for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) |
| TypeVals.push_back(VE.getTypeID(FT->getParamType(i))); |
| - AbbrevToUse = FunctionAbbrev; |
| + AbbrevToUse = TYPE_FUNCTION_ABBREV; |
| break; |
| } |
| case Type::StructTyID: { |
| @@ -344,19 +382,19 @@ static void WriteTypeTable(const NaClValueEnumerator &VE, |
| if (ST->isLiteral()) { |
| Code = naclbitc::TYPE_CODE_STRUCT_ANON; |
| - AbbrevToUse = StructAnonAbbrev; |
| + AbbrevToUse = TYPE_STRUCT_ANON_ABBREV; |
| } else { |
| if (ST->isOpaque()) { |
| Code = naclbitc::TYPE_CODE_OPAQUE; |
| } else { |
| Code = naclbitc::TYPE_CODE_STRUCT_NAMED; |
| - AbbrevToUse = StructNamedAbbrev; |
| + AbbrevToUse = TYPE_STRUCT_NAMED_ABBREV; |
| } |
| // Emit the name if it is present. |
| if (!ST->getName().empty()) |
| WriteStringRecord(naclbitc::TYPE_CODE_STRUCT_NAME, ST->getName(), |
| - StructNameAbbrev, Stream); |
| + TYPE_STRUCT_NAME_ABBREV, Stream); |
| } |
| break; |
| } |
| @@ -366,7 +404,7 @@ static void WriteTypeTable(const NaClValueEnumerator &VE, |
| Code = naclbitc::TYPE_CODE_ARRAY; |
| TypeVals.push_back(AT->getNumElements()); |
| TypeVals.push_back(VE.getTypeID(AT->getElementType())); |
| - AbbrevToUse = ArrayAbbrev; |
| + AbbrevToUse = TYPE_ARRAY_ABBREV; |
| break; |
| } |
| case Type::VectorTyID: { |
| @@ -385,6 +423,7 @@ static void WriteTypeTable(const NaClValueEnumerator &VE, |
| } |
| Stream.ExitBlock(); |
| + NACL_DEBUG(outs() << "<- WriteTypeTable\n"); |
| } |
| static unsigned getEncodedLinkage(const GlobalValue *GV) { |
| @@ -433,6 +472,7 @@ static unsigned getEncodedThreadLocalMode(const GlobalVariable *GV) { |
| // descriptors for global variables, and function prototype info. |
| static void WriteModuleInfo(const Module *M, const NaClValueEnumerator &VE, |
| NaClBitstreamWriter &Stream) { |
| + NACL_DEBUG(outs() << "-> WriteModuleInfo\n"); |
| // Emit various pieces of data attached to a module. |
| if (!M->getTargetTriple().empty()) |
| WriteStringRecord(naclbitc::MODULE_CODE_TRIPLE, M->getTargetTriple(), |
| @@ -511,6 +551,8 @@ static void WriteModuleInfo(const Module *M, const NaClValueEnumerator &VE, |
| Log2_32_Ceil(SectionMap.size()+1))); |
| // Don't bother emitting vis + thread local. |
| SimpleGVarAbbrev = Stream.EmitAbbrev(Abbv); |
| + if (MODULE_GLOBALVAR_ABBREV != SimpleGVarAbbrev) |
|
jvoung (off chromium)
2013/05/14 23:47:14
to be consistent with the other refactorings, you
Karl
2013/05/17 20:52:18
Added this to all levels, so that abbreviations ca
|
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| } |
| // Emit the global variable information. |
| @@ -537,7 +579,7 @@ static void WriteModuleInfo(const Module *M, const NaClValueEnumerator &VE, |
| Vals.push_back(GV->hasUnnamedAddr()); |
| Vals.push_back(GV->isExternallyInitialized()); |
| } else { |
| - AbbrevToUse = SimpleGVarAbbrev; |
| + AbbrevToUse = MODULE_GLOBALVAR_ABBREV; |
| } |
| Stream.EmitRecord(naclbitc::MODULE_CODE_GLOBALVAR, Vals, AbbrevToUse); |
| @@ -576,6 +618,7 @@ static void WriteModuleInfo(const Module *M, const NaClValueEnumerator &VE, |
| Stream.EmitRecord(naclbitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse); |
| Vals.clear(); |
| } |
| + NACL_DEBUG(outs() << "<- WriteModuleInfo\n"); |
| } |
| static uint64_t GetOptimizationFlags(const Value *V) { |
| @@ -630,6 +673,7 @@ static void WriteMDNode(const MDNode *N, |
| static void WriteModuleMetadata(const Module *M, |
| const NaClValueEnumerator &VE, |
| NaClBitstreamWriter &Stream) { |
| + NACL_DEBUG(outs() << "-> WriteModuleMetadata\n"); |
| const NaClValueEnumerator::ValueList &Vals = VE.getMDValues(); |
| bool StartedMetadataBlock = false; |
| unsigned MDSAbbrev = 0; |
| @@ -639,14 +683,15 @@ static void WriteModuleMetadata(const Module *M, |
| if (const MDNode *N = dyn_cast<MDNode>(Vals[i].first)) { |
| if (!N->isFunctionLocal() || !N->getFunction()) { |
| if (!StartedMetadataBlock) { |
| - Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); |
| + Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, |
| + METADATA_MAX_ABBREV); |
| StartedMetadataBlock = true; |
| } |
| WriteMDNode(N, VE, Stream, Record); |
| } |
| } else if (const MDString *MDS = dyn_cast<MDString>(Vals[i].first)) { |
| if (!StartedMetadataBlock) { |
| - Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); |
| + Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, METADATA_MAX_ABBREV); |
| // Abbrev for METADATA_STRING. |
|
Karl
2013/05/17 20:52:18
Moved this local abbreviation to the "global" crea
|
| NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| @@ -654,6 +699,8 @@ static void WriteModuleMetadata(const Module *M, |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); |
| MDSAbbrev = Stream.EmitAbbrev(Abbv); |
| + if (METADATA_STRING_ABBREV != MDSAbbrev) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| StartedMetadataBlock = true; |
| } |
| @@ -671,7 +718,7 @@ static void WriteModuleMetadata(const Module *M, |
| E = M->named_metadata_end(); I != E; ++I) { |
| const NamedMDNode *NMD = I; |
| if (!StartedMetadataBlock) { |
| - Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); |
| + Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, METADATA_MAX_ABBREV); |
| StartedMetadataBlock = true; |
| } |
| @@ -691,11 +738,14 @@ static void WriteModuleMetadata(const Module *M, |
| if (StartedMetadataBlock) |
| Stream.ExitBlock(); |
| + |
| + NACL_DEBUG(outs() << "<- WriteModuleMetadata\n"); |
| } |
| static void WriteFunctionLocalMetadata(const Function &F, |
| const NaClValueEnumerator &VE, |
| NaClBitstreamWriter &Stream) { |
| + NACL_DEBUG(outs() << "-> WriteFunctionLocalMetadata\n"); |
| bool StartedMetadataBlock = false; |
| SmallVector<uint64_t, 64> Record; |
| const SmallVector<const MDNode *, 8> &Vals = VE.getFunctionLocalMDValues(); |
| @@ -703,7 +753,8 @@ static void WriteFunctionLocalMetadata(const Function &F, |
| if (const MDNode *N = Vals[i]) |
| if (N->isFunctionLocal() && N->getFunction() == &F) { |
| if (!StartedMetadataBlock) { |
| - Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); |
| + Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, |
| + METADATA_MAX_ABBREV); |
| StartedMetadataBlock = true; |
| } |
| WriteMDNode(N, VE, Stream, Record); |
| @@ -711,12 +762,13 @@ static void WriteFunctionLocalMetadata(const Function &F, |
| if (StartedMetadataBlock) |
| Stream.ExitBlock(); |
| + NACL_DEBUG(outs() << "<- WriteFunctionLocalMetadata\n"); |
| } |
| static void WriteMetadataAttachment(const Function &F, |
| const NaClValueEnumerator &VE, |
| NaClBitstreamWriter &Stream) { |
| - Stream.EnterSubblock(naclbitc::METADATA_ATTACHMENT_ID, 3); |
| + Stream.EnterSubblock(naclbitc::METADATA_ATTACHMENT_ID); |
| SmallVector<uint64_t, 64> Record; |
| @@ -757,7 +809,7 @@ static void WriteModuleMetadataStore(const Module *M, |
| if (Names.empty()) return; |
| - Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); |
| + Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID); |
| for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) { |
| Record.push_back(MDKindID); |
| @@ -811,7 +863,11 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, |
| NaClBitstreamWriter &Stream, bool isGlobal) { |
| if (FirstVal == LastVal) return; |
| - Stream.EnterSubblock(naclbitc::CONSTANTS_BLOCK_ID, 4); |
| + NACL_DEBUG(outs() << "-> WriteConstants(" << isGlobal << ")\n"); |
| + Stream.EnterSubblock(naclbitc::CONSTANTS_BLOCK_ID, |
| + (isGlobal |
| + ? CST_CONSTANTS_MAX_ABBREV |
| + : CONSTANTS_MAX_ABBREV)); |
| unsigned AggregateAbbrev = 0; |
|
Karl
2013/05/17 20:52:18
Note that the constant abbreviations (or at least
|
| unsigned String8Abbrev = 0; |
| @@ -826,6 +882,8 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, |
| Log2_32_Ceil(LastVal+1))); |
| AggregateAbbrev = Stream.EmitAbbrev(Abbv); |
| + if (CST_CONSTANTS_AGGREGATE_ABBREV != AggregateAbbrev) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| // Abbrev for CST_CODE_STRING. |
| Abbv = new NaClBitCodeAbbrev(); |
| @@ -833,18 +891,26 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); |
| String8Abbrev = Stream.EmitAbbrev(Abbv); |
| + if (CST_CONSTANTS_STRING_ABBREV != String8Abbrev) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| + |
| // Abbrev for CST_CODE_CSTRING. |
| Abbv = new NaClBitCodeAbbrev(); |
| Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CSTRING)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 7)); |
| CString7Abbrev = Stream.EmitAbbrev(Abbv); |
| + if (CST_CONSTANTS_CSTRING_7_ABBREV != CString7Abbrev) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| + |
| // Abbrev for CST_CODE_CSTRING. |
| Abbv = new NaClBitCodeAbbrev(); |
| Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CSTRING)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Char6)); |
| CString6Abbrev = Stream.EmitAbbrev(Abbv); |
| + if (CST_CONSTANTS_CSTRING_6_ABBREV != CString6Abbrev) |
| + llvm_unreachable("Unexpected abbrev ordering!"); |
| } |
| SmallVector<uint64_t, 64> Record; |
| @@ -1052,6 +1118,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, |
| } |
| Stream.ExitBlock(); |
| + NACL_DEBUG(outs() << "<- WriteConstants\n"); |
| } |
| static void WriteModuleConstants(const NaClValueEnumerator &VE, |
| @@ -1476,7 +1543,7 @@ static void WriteValueSymbolTable(const ValueSymbolTable &VST, |
| const NaClValueEnumerator &VE, |
| NaClBitstreamWriter &Stream) { |
| if (VST.empty()) return; |
| - Stream.EnterSubblock(naclbitc::VALUE_SYMTAB_BLOCK_ID, 4); |
| + Stream.EnterSubblock(naclbitc::VALUE_SYMTAB_BLOCK_ID, VST_MAX_ABBREV); |
| // FIXME: Set up the abbrev, we know how many values there are! |
| // FIXME: We know if the type names can use 7-bit ascii. |
| @@ -1532,7 +1599,7 @@ static void WriteValueSymbolTable(const ValueSymbolTable &VST, |
| /// WriteFunction - Emit a function body to the module stream. |
| static void WriteFunction(const Function &F, NaClValueEnumerator &VE, |
| NaClBitstreamWriter &Stream) { |
| - Stream.EnterSubblock(naclbitc::FUNCTION_BLOCK_ID, 4); |
| + Stream.EnterSubblock(naclbitc::FUNCTION_BLOCK_ID, FUNCTION_INST_MAX_ABBREV); |
| VE.incorporateFunction(F); |
| SmallVector<unsigned, 64> Vals; |
| @@ -1607,7 +1674,7 @@ static void WriteBlockInfo(const NaClValueEnumerator &VE, |
| // 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 define their abbrevs inline. |
| - Stream.EnterBlockInfoBlock(2); |
| + Stream.EnterBlockInfoBlock(); |
| { // 8-bit fixed-width VST_ENTRY/VST_BBENTRY strings. |
| NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| @@ -1765,7 +1832,8 @@ static void WriteBlockInfo(const NaClValueEnumerator &VE, |
| /// WriteModule - Emit the specified module to the bitstream. |
| static void WriteModule(const Module *M, NaClBitstreamWriter &Stream) { |
| - Stream.EnterSubblock(naclbitc::MODULE_BLOCK_ID, 3); |
| + NACL_DEBUG(outs() << "-> WriteModule\n"); |
| + Stream.EnterSubblock(naclbitc::MODULE_BLOCK_ID, MODULE_MAX_ABBREV); |
| SmallVector<unsigned, 1> Vals; |
| unsigned CurVersion = 1; |
| @@ -1809,6 +1877,7 @@ static void WriteModule(const Module *M, NaClBitstreamWriter &Stream) { |
| WriteFunction(*F, VE, Stream); |
| Stream.ExitBlock(); |
| + NACL_DEBUG(outs() << "<- WriteModule\n"); |
| } |
| /// EmitDarwinBCHeader - If generating a bc file on darwin, we have to emit a |