Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===--- Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp - Bitcode Writer -------===// | 1 //===--- Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp - Bitcode Writer -------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // Bitcode writer implementation. | 10 // Bitcode writer implementation. |
| 11 // | 11 // |
| 12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
| 13 | 13 |
| 14 #define DEBUG_TYPE "NaClBitcodeWriter" | |
| 15 | |
| 14 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" | 16 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" |
| 15 #include "NaClValueEnumerator.h" | 17 #include "NaClValueEnumerator.h" |
| 16 #include "llvm/ADT/Triple.h" | 18 #include "llvm/ADT/Triple.h" |
| 17 #include "llvm/Bitcode/NaCl/NaClBitstreamWriter.h" | 19 #include "llvm/Bitcode/NaCl/NaClBitstreamWriter.h" |
| 18 #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" | 20 #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" |
| 19 #include "llvm/IR/Constants.h" | 21 #include "llvm/IR/Constants.h" |
| 20 #include "llvm/IR/DerivedTypes.h" | 22 #include "llvm/IR/DerivedTypes.h" |
| 21 #include "llvm/IR/InlineAsm.h" | 23 #include "llvm/IR/InlineAsm.h" |
| 22 #include "llvm/IR/Instructions.h" | 24 #include "llvm/IR/Instructions.h" |
| 23 #include "llvm/IR/Module.h" | 25 #include "llvm/IR/Module.h" |
| 24 #include "llvm/IR/Operator.h" | 26 #include "llvm/IR/Operator.h" |
| 25 #include "llvm/IR/ValueSymbolTable.h" | 27 #include "llvm/IR/ValueSymbolTable.h" |
| 28 #include "llvm/Support/Debug.h" | |
| 26 #include "llvm/Support/CommandLine.h" | 29 #include "llvm/Support/CommandLine.h" |
| 27 #include "llvm/Support/ErrorHandling.h" | 30 #include "llvm/Support/ErrorHandling.h" |
| 28 #include "llvm/Support/MathExtras.h" | 31 #include "llvm/Support/MathExtras.h" |
| 29 #include "llvm/Support/Program.h" | 32 #include "llvm/Support/Program.h" |
| 30 #include "llvm/Support/raw_ostream.h" | 33 #include "llvm/Support/raw_ostream.h" |
| 31 #include <cctype> | 34 #include <cctype> |
| 32 #include <map> | 35 #include <map> |
| 33 using namespace llvm; | 36 using namespace llvm; |
| 34 | 37 |
| 35 /// These are manifest constants used by the bitcode writer. They do not need to | 38 /// These are manifest constants used by the bitcode writer. They do not need to |
| 36 /// be kept in sync with the reader, but need to be consistent within this file. | 39 /// be kept in sync with the reader, but need to be consistent within this file. |
|
jvoung (off chromium)
2013/05/17 23:40:48
Perhaps document that for each block type, there s
Karl
2013/05/20 22:59:20
Done.
| |
| 37 enum { | 40 enum { |
| 38 // VALUE_SYMTAB_BLOCK abbrev id's. | 41 // VALUE_SYMTAB_BLOCK abbrev id's. |
| 39 VST_ENTRY_8_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, | 42 VST_ENTRY_8_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
| 40 VST_ENTRY_7_ABBREV, | 43 VST_ENTRY_7_ABBREV, |
| 41 VST_ENTRY_6_ABBREV, | 44 VST_ENTRY_6_ABBREV, |
| 42 VST_BBENTRY_6_ABBREV, | 45 VST_BBENTRY_6_ABBREV, |
| 46 VST_MAX_ABBREV = VST_BBENTRY_6_ABBREV, | |
| 43 | 47 |
| 44 // CONSTANTS_BLOCK abbrev id's. | 48 // CONSTANTS_BLOCK abbrev id's. |
| 45 CONSTANTS_SETTYPE_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, | 49 CONSTANTS_SETTYPE_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
| 46 CONSTANTS_INTEGER_ABBREV, | 50 CONSTANTS_INTEGER_ABBREV, |
| 47 CONSTANTS_CE_CAST_Abbrev, | 51 CONSTANTS_CE_CAST_Abbrev, |
| 48 CONSTANTS_NULL_Abbrev, | 52 CONSTANTS_NULL_Abbrev, |
| 53 CONSTANTS_MAX_ABBREV = CONSTANTS_NULL_Abbrev, | |
| 54 | |
| 55 // CONSTANTS_BLOCK abbrev id's when global (extends list above). | |
| 56 CST_CONSTANTS_AGGREGATE_ABBREV = CONSTANTS_MAX_ABBREV+1, | |
| 57 CST_CONSTANTS_STRING_ABBREV, | |
| 58 CST_CONSTANTS_CSTRING_7_ABBREV, | |
| 59 CST_CONSTANTS_CSTRING_6_ABBREV, | |
| 60 CST_CONSTANTS_MAX_ABBREV = CST_CONSTANTS_CSTRING_6_ABBREV, | |
| 49 | 61 |
| 50 // FUNCTION_BLOCK abbrev id's. | 62 // FUNCTION_BLOCK abbrev id's. |
| 51 FUNCTION_INST_LOAD_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, | 63 FUNCTION_INST_LOAD_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
| 52 FUNCTION_INST_BINOP_ABBREV, | 64 FUNCTION_INST_BINOP_ABBREV, |
| 53 FUNCTION_INST_BINOP_FLAGS_ABBREV, | 65 FUNCTION_INST_BINOP_FLAGS_ABBREV, |
| 54 FUNCTION_INST_CAST_ABBREV, | 66 FUNCTION_INST_CAST_ABBREV, |
| 55 FUNCTION_INST_RET_VOID_ABBREV, | 67 FUNCTION_INST_RET_VOID_ABBREV, |
| 56 FUNCTION_INST_RET_VAL_ABBREV, | 68 FUNCTION_INST_RET_VAL_ABBREV, |
| 57 FUNCTION_INST_UNREACHABLE_ABBREV, | 69 FUNCTION_INST_UNREACHABLE_ABBREV, |
| 70 FUNCTION_INST_MAX_ABBREV = FUNCTION_INST_UNREACHABLE_ABBREV, | |
| 71 | |
| 72 // TYPE_BLOCK_ID_NEW abbrev id's. | |
| 73 TYPE_POINTER_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, | |
| 74 TYPE_FUNCTION_ABBREV, | |
| 75 TYPE_STRUCT_ANON_ABBREV, | |
| 76 TYPE_STRUCT_NAME_ABBREV, | |
| 77 TYPE_STRUCT_NAMED_ABBREV, | |
| 78 TYPE_ARRAY_ABBREV, | |
| 79 TYPE_MAX_ABBREV = TYPE_ARRAY_ABBREV, | |
| 80 | |
| 81 // META_DATA_BLOCK abbrev id's. | |
| 82 METADATA_STRING_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, | |
| 83 METADATA_MAX_ABBREV = METADATA_STRING_ABBREV, | |
| 84 | |
| 85 // MODULE_BLOCK abbrev id's. | |
| 86 MODULE_GLOBALVAR_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, | |
| 87 MODULE_MAX_ABBREV = MODULE_GLOBALVAR_ABBREV, | |
| 58 | 88 |
| 59 // SwitchInst Magic | 89 // SwitchInst Magic |
| 60 SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex | 90 SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex |
| 61 }; | 91 }; |
| 62 | 92 |
| 63 static unsigned GetEncodedCastOpcode(unsigned Opcode) { | 93 static unsigned GetEncodedCastOpcode(unsigned Opcode) { |
| 64 switch (Opcode) { | 94 switch (Opcode) { |
| 65 default: llvm_unreachable("Unknown cast instruction!"); | 95 default: llvm_unreachable("Unknown cast instruction!"); |
| 66 case Instruction::Trunc : return naclbitc::CAST_TRUNC; | 96 case Instruction::Trunc : return naclbitc::CAST_TRUNC; |
| 67 case Instruction::ZExt : return naclbitc::CAST_ZEXT; | 97 case Instruction::ZExt : return naclbitc::CAST_ZEXT; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 } | 183 } |
| 154 | 184 |
| 155 // Emit the finished record. | 185 // Emit the finished record. |
| 156 Stream.EmitRecord(Code, Vals, AbbrevToUse); | 186 Stream.EmitRecord(Code, Vals, AbbrevToUse); |
| 157 } | 187 } |
| 158 | 188 |
| 159 static void WriteAttributeGroupTable(const NaClValueEnumerator &VE, | 189 static void WriteAttributeGroupTable(const NaClValueEnumerator &VE, |
| 160 NaClBitstreamWriter &Stream) { | 190 NaClBitstreamWriter &Stream) { |
| 161 const std::vector<AttributeSet> &AttrGrps = VE.getAttributeGroups(); | 191 const std::vector<AttributeSet> &AttrGrps = VE.getAttributeGroups(); |
| 162 if (AttrGrps.empty()) return; | 192 if (AttrGrps.empty()) return; |
| 193 DEBUG(dbgs() << "-> WriteAbbributeGroupTable\n"); | |
| 163 | 194 |
| 164 Stream.EnterSubblock(naclbitc::PARAMATTR_GROUP_BLOCK_ID, 3); | 195 Stream.EnterSubblock(naclbitc::PARAMATTR_GROUP_BLOCK_ID); |
| 165 | 196 |
| 166 SmallVector<uint64_t, 64> Record; | 197 SmallVector<uint64_t, 64> Record; |
| 167 for (unsigned i = 0, e = AttrGrps.size(); i != e; ++i) { | 198 for (unsigned i = 0, e = AttrGrps.size(); i != e; ++i) { |
| 168 AttributeSet AS = AttrGrps[i]; | 199 AttributeSet AS = AttrGrps[i]; |
| 169 for (unsigned i = 0, e = AS.getNumSlots(); i != e; ++i) { | 200 for (unsigned i = 0, e = AS.getNumSlots(); i != e; ++i) { |
| 170 AttributeSet A = AS.getSlotAttributes(i); | 201 AttributeSet A = AS.getSlotAttributes(i); |
| 171 | 202 |
| 172 Record.push_back(VE.getAttributeGroupID(A)); | 203 Record.push_back(VE.getAttributeGroupID(A)); |
| 173 Record.push_back(AS.getSlotIndex(i)); | 204 Record.push_back(AS.getSlotIndex(i)); |
| 174 | 205 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 195 } | 226 } |
| 196 } | 227 } |
| 197 } | 228 } |
| 198 | 229 |
| 199 Stream.EmitRecord(naclbitc::PARAMATTR_GRP_CODE_ENTRY, Record); | 230 Stream.EmitRecord(naclbitc::PARAMATTR_GRP_CODE_ENTRY, Record); |
| 200 Record.clear(); | 231 Record.clear(); |
| 201 } | 232 } |
| 202 } | 233 } |
| 203 | 234 |
| 204 Stream.ExitBlock(); | 235 Stream.ExitBlock(); |
| 205 } | 236 DEBUG(dbgs() << "<- WriteAbbributeGroupTable\n");} |
|
jvoung (off chromium)
2013/05/17 23:40:48
nit: keep the last curly on a separate line.
Karl
2013/05/20 22:59:20
Done.
| |
| 206 | 237 |
| 207 static void WriteAttributeTable(const NaClValueEnumerator &VE, | 238 static void WriteAttributeTable(const NaClValueEnumerator &VE, |
| 208 NaClBitstreamWriter &Stream) { | 239 NaClBitstreamWriter &Stream) { |
| 209 const std::vector<AttributeSet> &Attrs = VE.getAttributes(); | 240 const std::vector<AttributeSet> &Attrs = VE.getAttributes(); |
| 210 if (Attrs.empty()) return; | 241 if (Attrs.empty()) return; |
| 242 DEBUG(dbgs() << "-> WriteAttributeTable\n"); | |
| 211 | 243 |
| 212 Stream.EnterSubblock(naclbitc::PARAMATTR_BLOCK_ID, 3); | 244 Stream.EnterSubblock(naclbitc::PARAMATTR_BLOCK_ID); |
| 213 | 245 |
| 214 SmallVector<uint64_t, 64> Record; | 246 SmallVector<uint64_t, 64> Record; |
| 215 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { | 247 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { |
| 216 const AttributeSet &A = Attrs[i]; | 248 const AttributeSet &A = Attrs[i]; |
| 217 for (unsigned i = 0, e = A.getNumSlots(); i != e; ++i) | 249 for (unsigned i = 0, e = A.getNumSlots(); i != e; ++i) |
| 218 Record.push_back(VE.getAttributeGroupID(A.getSlotAttributes(i))); | 250 Record.push_back(VE.getAttributeGroupID(A.getSlotAttributes(i))); |
| 219 | 251 |
| 220 Stream.EmitRecord(naclbitc::PARAMATTR_CODE_ENTRY, Record); | 252 Stream.EmitRecord(naclbitc::PARAMATTR_CODE_ENTRY, Record); |
| 221 Record.clear(); | 253 Record.clear(); |
| 222 } | 254 } |
| 223 | 255 |
| 224 Stream.ExitBlock(); | 256 Stream.ExitBlock(); |
| 257 DEBUG(dbgs() << "<- WriteAttributeTable\n"); | |
| 225 } | 258 } |
| 226 | 259 |
| 227 /// WriteTypeTable - Write out the type table for a module. | 260 /// WriteTypeTable - Write out the type table for a module. |
| 228 static void WriteTypeTable(const NaClValueEnumerator &VE, | 261 static void WriteTypeTable(const NaClValueEnumerator &VE, |
| 229 NaClBitstreamWriter &Stream) { | 262 NaClBitstreamWriter &Stream) { |
| 263 DEBUG(dbgs() << "-> WriteTypeTable\n"); | |
| 230 const NaClValueEnumerator::TypeList &TypeList = VE.getTypes(); | 264 const NaClValueEnumerator::TypeList &TypeList = VE.getTypes(); |
| 231 | 265 |
| 232 Stream.EnterSubblock(naclbitc::TYPE_BLOCK_ID_NEW, | 266 Stream.EnterSubblock(naclbitc::TYPE_BLOCK_ID_NEW, TYPE_MAX_ABBREV); |
| 233 4 /*count from # abbrevs */); | 267 |
| 234 SmallVector<uint64_t, 64> TypeVals; | 268 SmallVector<uint64_t, 64> TypeVals; |
| 235 | 269 |
| 236 uint64_t NumBits = Log2_32_Ceil(VE.getTypes().size()+1); | 270 uint64_t NumBits = NaClBitsNeededForValue(VE.getTypes().size()); |
| 237 | 271 |
| 238 // Abbrev for TYPE_CODE_POINTER. | 272 // Abbrev for TYPE_CODE_POINTER. |
| 239 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 273 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 240 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_POINTER)); | 274 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_POINTER)); |
| 241 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); | 275 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
| 242 Abbv->Add(NaClBitCodeAbbrevOp(0)); // Addrspace = 0 | 276 Abbv->Add(NaClBitCodeAbbrevOp(0)); // Addrspace = 0 |
| 243 unsigned PtrAbbrev = Stream.EmitAbbrev(Abbv); | 277 if (TYPE_POINTER_ABBREV != Stream.EmitAbbrev(Abbv)) |
| 278 llvm_unreachable("Unexpected abbrev ordering!"); | |
| 244 | 279 |
| 245 // Abbrev for TYPE_CODE_FUNCTION. | 280 // Abbrev for TYPE_CODE_FUNCTION. |
| 246 Abbv = new NaClBitCodeAbbrev(); | 281 Abbv = new NaClBitCodeAbbrev(); |
| 247 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_FUNCTION)); | 282 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_FUNCTION)); |
| 248 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // isvararg | 283 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // isvararg |
| 249 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | 284 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| 250 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); | 285 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
| 251 | 286 if (TYPE_FUNCTION_ABBREV != Stream.EmitAbbrev(Abbv)) |
| 252 unsigned FunctionAbbrev = Stream.EmitAbbrev(Abbv); | 287 llvm_unreachable("Unexpected abbrev ordering!"); |
| 253 | 288 |
| 254 // Abbrev for TYPE_CODE_STRUCT_ANON. | 289 // Abbrev for TYPE_CODE_STRUCT_ANON. |
| 255 Abbv = new NaClBitCodeAbbrev(); | 290 Abbv = new NaClBitCodeAbbrev(); |
| 256 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_ANON)); | 291 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_ANON)); |
| 257 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // ispacked | 292 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // ispacked |
| 258 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | 293 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| 259 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); | 294 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
| 260 | 295 if (TYPE_STRUCT_ANON_ABBREV != Stream.EmitAbbrev(Abbv)) |
| 261 unsigned StructAnonAbbrev = Stream.EmitAbbrev(Abbv); | 296 llvm_unreachable("Unexpected abbrev ordering!"); |
| 262 | 297 |
| 263 // Abbrev for TYPE_CODE_STRUCT_NAME. | 298 // Abbrev for TYPE_CODE_STRUCT_NAME. |
| 264 Abbv = new NaClBitCodeAbbrev(); | 299 Abbv = new NaClBitCodeAbbrev(); |
| 265 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_NAME)); | 300 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_NAME)); |
| 266 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | 301 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| 267 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Char6)); | 302 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Char6)); |
| 268 unsigned StructNameAbbrev = Stream.EmitAbbrev(Abbv); | 303 if (TYPE_STRUCT_NAME_ABBREV != Stream.EmitAbbrev(Abbv)) |
| 304 llvm_unreachable("Unexpected abbrev ordering!"); | |
| 269 | 305 |
| 270 // Abbrev for TYPE_CODE_STRUCT_NAMED. | 306 // Abbrev for TYPE_CODE_STRUCT_NAMED. |
| 271 Abbv = new NaClBitCodeAbbrev(); | 307 Abbv = new NaClBitCodeAbbrev(); |
| 272 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_NAMED)); | 308 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_NAMED)); |
| 273 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // ispacked | 309 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // ispacked |
| 274 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | 310 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| 275 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); | 311 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
| 276 | 312 if (TYPE_STRUCT_NAMED_ABBREV != Stream.EmitAbbrev(Abbv)) |
| 277 unsigned StructNamedAbbrev = Stream.EmitAbbrev(Abbv); | 313 llvm_unreachable("Unexpected abbrev ordering!"); |
| 278 | 314 |
| 279 // Abbrev for TYPE_CODE_ARRAY. | 315 // Abbrev for TYPE_CODE_ARRAY. |
| 280 Abbv = new NaClBitCodeAbbrev(); | 316 Abbv = new NaClBitCodeAbbrev(); |
| 281 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_ARRAY)); | 317 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_ARRAY)); |
| 282 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); // size | 318 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); // size |
| 283 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); | 319 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
| 284 | 320 if (TYPE_ARRAY_ABBREV != Stream.EmitAbbrev(Abbv)) |
| 285 unsigned ArrayAbbrev = Stream.EmitAbbrev(Abbv); | 321 llvm_unreachable("Unexpected abbrev ordering!"); |
| 286 | 322 |
| 287 // Emit an entry count so the reader can reserve space. | 323 // Emit an entry count so the reader can reserve space. |
| 288 TypeVals.push_back(TypeList.size()); | 324 TypeVals.push_back(TypeList.size()); |
| 289 Stream.EmitRecord(naclbitc::TYPE_CODE_NUMENTRY, TypeVals); | 325 Stream.EmitRecord(naclbitc::TYPE_CODE_NUMENTRY, TypeVals); |
| 290 TypeVals.clear(); | 326 TypeVals.clear(); |
| 291 | 327 |
| 292 // Loop over all of the types, emitting each in turn. | 328 // Loop over all of the types, emitting each in turn. |
| 293 for (unsigned i = 0, e = TypeList.size(); i != e; ++i) { | 329 for (unsigned i = 0, e = TypeList.size(); i != e; ++i) { |
| 294 Type *T = TypeList[i]; | 330 Type *T = TypeList[i]; |
| 295 int AbbrevToUse = 0; | 331 int AbbrevToUse = 0; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 312 Code = naclbitc::TYPE_CODE_INTEGER; | 348 Code = naclbitc::TYPE_CODE_INTEGER; |
| 313 TypeVals.push_back(cast<IntegerType>(T)->getBitWidth()); | 349 TypeVals.push_back(cast<IntegerType>(T)->getBitWidth()); |
| 314 break; | 350 break; |
| 315 case Type::PointerTyID: { | 351 case Type::PointerTyID: { |
| 316 PointerType *PTy = cast<PointerType>(T); | 352 PointerType *PTy = cast<PointerType>(T); |
| 317 // POINTER: [pointee type, address space] | 353 // POINTER: [pointee type, address space] |
| 318 Code = naclbitc::TYPE_CODE_POINTER; | 354 Code = naclbitc::TYPE_CODE_POINTER; |
| 319 TypeVals.push_back(VE.getTypeID(PTy->getElementType())); | 355 TypeVals.push_back(VE.getTypeID(PTy->getElementType())); |
| 320 unsigned AddressSpace = PTy->getAddressSpace(); | 356 unsigned AddressSpace = PTy->getAddressSpace(); |
| 321 TypeVals.push_back(AddressSpace); | 357 TypeVals.push_back(AddressSpace); |
| 322 if (AddressSpace == 0) AbbrevToUse = PtrAbbrev; | 358 if (AddressSpace == 0) AbbrevToUse = TYPE_POINTER_ABBREV; |
| 323 break; | 359 break; |
| 324 } | 360 } |
| 325 case Type::FunctionTyID: { | 361 case Type::FunctionTyID: { |
| 326 FunctionType *FT = cast<FunctionType>(T); | 362 FunctionType *FT = cast<FunctionType>(T); |
| 327 // FUNCTION: [isvararg, retty, paramty x N] | 363 // FUNCTION: [isvararg, retty, paramty x N] |
| 328 Code = naclbitc::TYPE_CODE_FUNCTION; | 364 Code = naclbitc::TYPE_CODE_FUNCTION; |
| 329 TypeVals.push_back(FT->isVarArg()); | 365 TypeVals.push_back(FT->isVarArg()); |
| 330 TypeVals.push_back(VE.getTypeID(FT->getReturnType())); | 366 TypeVals.push_back(VE.getTypeID(FT->getReturnType())); |
| 331 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) | 367 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) |
| 332 TypeVals.push_back(VE.getTypeID(FT->getParamType(i))); | 368 TypeVals.push_back(VE.getTypeID(FT->getParamType(i))); |
| 333 AbbrevToUse = FunctionAbbrev; | 369 AbbrevToUse = TYPE_FUNCTION_ABBREV; |
| 334 break; | 370 break; |
| 335 } | 371 } |
| 336 case Type::StructTyID: { | 372 case Type::StructTyID: { |
| 337 StructType *ST = cast<StructType>(T); | 373 StructType *ST = cast<StructType>(T); |
| 338 // STRUCT: [ispacked, eltty x N] | 374 // STRUCT: [ispacked, eltty x N] |
| 339 TypeVals.push_back(ST->isPacked()); | 375 TypeVals.push_back(ST->isPacked()); |
| 340 // Output all of the element types. | 376 // Output all of the element types. |
| 341 for (StructType::element_iterator I = ST->element_begin(), | 377 for (StructType::element_iterator I = ST->element_begin(), |
| 342 E = ST->element_end(); I != E; ++I) | 378 E = ST->element_end(); I != E; ++I) |
| 343 TypeVals.push_back(VE.getTypeID(*I)); | 379 TypeVals.push_back(VE.getTypeID(*I)); |
| 344 | 380 |
| 345 if (ST->isLiteral()) { | 381 if (ST->isLiteral()) { |
| 346 Code = naclbitc::TYPE_CODE_STRUCT_ANON; | 382 Code = naclbitc::TYPE_CODE_STRUCT_ANON; |
| 347 AbbrevToUse = StructAnonAbbrev; | 383 AbbrevToUse = TYPE_STRUCT_ANON_ABBREV; |
| 348 } else { | 384 } else { |
| 349 if (ST->isOpaque()) { | 385 if (ST->isOpaque()) { |
| 350 Code = naclbitc::TYPE_CODE_OPAQUE; | 386 Code = naclbitc::TYPE_CODE_OPAQUE; |
| 351 } else { | 387 } else { |
| 352 Code = naclbitc::TYPE_CODE_STRUCT_NAMED; | 388 Code = naclbitc::TYPE_CODE_STRUCT_NAMED; |
| 353 AbbrevToUse = StructNamedAbbrev; | 389 AbbrevToUse = TYPE_STRUCT_NAMED_ABBREV; |
| 354 } | 390 } |
| 355 | 391 |
| 356 // Emit the name if it is present. | 392 // Emit the name if it is present. |
| 357 if (!ST->getName().empty()) | 393 if (!ST->getName().empty()) |
| 358 WriteStringRecord(naclbitc::TYPE_CODE_STRUCT_NAME, ST->getName(), | 394 WriteStringRecord(naclbitc::TYPE_CODE_STRUCT_NAME, ST->getName(), |
| 359 StructNameAbbrev, Stream); | 395 TYPE_STRUCT_NAME_ABBREV, Stream); |
| 360 } | 396 } |
| 361 break; | 397 break; |
| 362 } | 398 } |
| 363 case Type::ArrayTyID: { | 399 case Type::ArrayTyID: { |
| 364 ArrayType *AT = cast<ArrayType>(T); | 400 ArrayType *AT = cast<ArrayType>(T); |
| 365 // ARRAY: [numelts, eltty] | 401 // ARRAY: [numelts, eltty] |
| 366 Code = naclbitc::TYPE_CODE_ARRAY; | 402 Code = naclbitc::TYPE_CODE_ARRAY; |
| 367 TypeVals.push_back(AT->getNumElements()); | 403 TypeVals.push_back(AT->getNumElements()); |
| 368 TypeVals.push_back(VE.getTypeID(AT->getElementType())); | 404 TypeVals.push_back(VE.getTypeID(AT->getElementType())); |
| 369 AbbrevToUse = ArrayAbbrev; | 405 AbbrevToUse = TYPE_ARRAY_ABBREV; |
| 370 break; | 406 break; |
| 371 } | 407 } |
| 372 case Type::VectorTyID: { | 408 case Type::VectorTyID: { |
| 373 VectorType *VT = cast<VectorType>(T); | 409 VectorType *VT = cast<VectorType>(T); |
| 374 // VECTOR [numelts, eltty] | 410 // VECTOR [numelts, eltty] |
| 375 Code = naclbitc::TYPE_CODE_VECTOR; | 411 Code = naclbitc::TYPE_CODE_VECTOR; |
| 376 TypeVals.push_back(VT->getNumElements()); | 412 TypeVals.push_back(VT->getNumElements()); |
| 377 TypeVals.push_back(VE.getTypeID(VT->getElementType())); | 413 TypeVals.push_back(VE.getTypeID(VT->getElementType())); |
| 378 break; | 414 break; |
| 379 } | 415 } |
| 380 } | 416 } |
| 381 | 417 |
| 382 // Emit the finished record. | 418 // Emit the finished record. |
| 383 Stream.EmitRecord(Code, TypeVals, AbbrevToUse); | 419 Stream.EmitRecord(Code, TypeVals, AbbrevToUse); |
| 384 TypeVals.clear(); | 420 TypeVals.clear(); |
| 385 } | 421 } |
| 386 | 422 |
| 387 Stream.ExitBlock(); | 423 Stream.ExitBlock(); |
| 424 DEBUG(dbgs() << "<- WriteTypeTable\n"); | |
| 388 } | 425 } |
| 389 | 426 |
| 390 static unsigned getEncodedLinkage(const GlobalValue *GV) { | 427 static unsigned getEncodedLinkage(const GlobalValue *GV) { |
| 391 switch (GV->getLinkage()) { | 428 switch (GV->getLinkage()) { |
| 392 case GlobalValue::ExternalLinkage: return 0; | 429 case GlobalValue::ExternalLinkage: return 0; |
| 393 case GlobalValue::WeakAnyLinkage: return 1; | 430 case GlobalValue::WeakAnyLinkage: return 1; |
| 394 case GlobalValue::AppendingLinkage: return 2; | 431 case GlobalValue::AppendingLinkage: return 2; |
| 395 case GlobalValue::InternalLinkage: return 3; | 432 case GlobalValue::InternalLinkage: return 3; |
| 396 case GlobalValue::LinkOnceAnyLinkage: return 4; | 433 case GlobalValue::LinkOnceAnyLinkage: return 4; |
| 397 case GlobalValue::DLLImportLinkage: return 5; | 434 case GlobalValue::DLLImportLinkage: return 5; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 426 case GlobalVariable::InitialExecTLSModel: return 3; | 463 case GlobalVariable::InitialExecTLSModel: return 3; |
| 427 case GlobalVariable::LocalExecTLSModel: return 4; | 464 case GlobalVariable::LocalExecTLSModel: return 4; |
| 428 } | 465 } |
| 429 llvm_unreachable("Invalid TLS model"); | 466 llvm_unreachable("Invalid TLS model"); |
| 430 } | 467 } |
| 431 | 468 |
| 432 // Emit top-level description of module, including target triple, inline asm, | 469 // Emit top-level description of module, including target triple, inline asm, |
| 433 // descriptors for global variables, and function prototype info. | 470 // descriptors for global variables, and function prototype info. |
| 434 static void WriteModuleInfo(const Module *M, const NaClValueEnumerator &VE, | 471 static void WriteModuleInfo(const Module *M, const NaClValueEnumerator &VE, |
| 435 NaClBitstreamWriter &Stream) { | 472 NaClBitstreamWriter &Stream) { |
| 473 DEBUG(dbgs() << "-> WriteModuleInfo\n"); | |
| 436 // Emit various pieces of data attached to a module. | 474 // Emit various pieces of data attached to a module. |
| 437 if (!M->getTargetTriple().empty()) | 475 if (!M->getTargetTriple().empty()) |
| 438 WriteStringRecord(naclbitc::MODULE_CODE_TRIPLE, M->getTargetTriple(), | 476 WriteStringRecord(naclbitc::MODULE_CODE_TRIPLE, M->getTargetTriple(), |
| 439 0/*TODO*/, Stream); | 477 0/*TODO*/, Stream); |
| 440 if (!M->getDataLayout().empty()) | 478 if (!M->getDataLayout().empty()) |
| 441 WriteStringRecord(naclbitc::MODULE_CODE_DATALAYOUT, M->getDataLayout(), | 479 WriteStringRecord(naclbitc::MODULE_CODE_DATALAYOUT, M->getDataLayout(), |
| 442 0/*TODO*/, Stream); | 480 0/*TODO*/, Stream); |
| 443 if (!M->getModuleInlineAsm().empty()) | 481 if (!M->getModuleInlineAsm().empty()) |
| 444 WriteStringRecord(naclbitc::MODULE_CODE_ASM, M->getModuleInlineAsm(), | 482 WriteStringRecord(naclbitc::MODULE_CODE_ASM, M->getModuleInlineAsm(), |
| 445 0/*TODO*/, Stream); | 483 0/*TODO*/, Stream); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 unsigned &Entry = GCMap[F->getGC()]; | 518 unsigned &Entry = GCMap[F->getGC()]; |
| 481 if (!Entry) { | 519 if (!Entry) { |
| 482 WriteStringRecord(naclbitc::MODULE_CODE_GCNAME, F->getGC(), | 520 WriteStringRecord(naclbitc::MODULE_CODE_GCNAME, F->getGC(), |
| 483 0/*TODO*/, Stream); | 521 0/*TODO*/, Stream); |
| 484 Entry = GCMap.size(); | 522 Entry = GCMap.size(); |
| 485 } | 523 } |
| 486 } | 524 } |
| 487 } | 525 } |
| 488 | 526 |
| 489 // Emit abbrev for globals, now that we know # sections and max alignment. | 527 // Emit abbrev for globals, now that we know # sections and max alignment. |
| 490 unsigned SimpleGVarAbbrev = 0; | 528 // Add an abbrev for common globals with no visibility or thread localness. |
| 491 if (!M->global_empty()) { | 529 { |
|
jvoung (off chromium)
2013/05/17 23:40:48
Why delete the predicate for global_empty()?
Karl
2013/05/20 22:59:20
I did this because these abbreviations appear comm
| |
| 492 // Add an abbrev for common globals with no visibility or thread localness. | |
| 493 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 530 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 494 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::MODULE_CODE_GLOBALVAR)); | 531 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::MODULE_CODE_GLOBALVAR)); |
| 495 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, | 532 Abbv->Add(NaClBitCodeAbbrevOp( |
| 496 Log2_32_Ceil(MaxGlobalType+1))); | 533 NaClBitCodeAbbrevOp::Fixed, NaClBitsNeededForValue(MaxGlobalType))); |
| 497 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // Constant. | 534 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // Constant. |
| 498 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // Initialize r. | 535 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // Initialize r. |
| 499 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // Linkage. | 536 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // Linkage. |
| 500 if (MaxAlignment == 0) // Alignment. | 537 if (MaxAlignment == 0) // Alignment. |
| 501 Abbv->Add(NaClBitCodeAbbrevOp(0)); | 538 Abbv->Add(NaClBitCodeAbbrevOp(0)); |
| 502 else { | 539 else { |
| 503 unsigned MaxEncAlignment = Log2_32(MaxAlignment)+1; | 540 unsigned MaxEncAlignment = Log2_32(MaxAlignment)+1; |
| 504 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, | 541 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, |
| 505 Log2_32_Ceil(MaxEncAlignment+1))); | 542 NaClBitsNeededForValue(MaxEncAlignment))); |
| 506 } | 543 } |
| 507 if (SectionMap.empty()) // Section. | 544 if (SectionMap.empty()) // Section. |
| 508 Abbv->Add(NaClBitCodeAbbrevOp(0)); | 545 Abbv->Add(NaClBitCodeAbbrevOp(0)); |
| 509 else | 546 else |
| 510 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, | 547 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, |
| 511 Log2_32_Ceil(SectionMap.size()+1))); | 548 NaClBitsNeededForValue(SectionMap.size()))); |
| 512 // Don't bother emitting vis + thread local. | 549 if (MODULE_GLOBALVAR_ABBREV != Stream.EmitAbbrev(Abbv)) |
| 513 SimpleGVarAbbrev = Stream.EmitAbbrev(Abbv); | 550 llvm_unreachable("Unexpected abbrev ordering!"); |
| 514 } | 551 } |
| 515 | 552 |
| 553 // Don't bother emitting vis + thread local. | |
| 554 | |
| 516 // Emit the global variable information. | 555 // Emit the global variable information. |
| 517 SmallVector<unsigned, 64> Vals; | 556 SmallVector<unsigned, 64> Vals; |
| 518 for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end(); | 557 for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end(); |
| 519 GV != E; ++GV) { | 558 GV != E; ++GV) { |
| 520 unsigned AbbrevToUse = 0; | 559 unsigned AbbrevToUse = 0; |
| 521 | 560 |
| 522 // GLOBALVAR: [type, isconst, initid, | 561 // GLOBALVAR: [type, isconst, initid, |
| 523 // linkage, alignment, section, visibility, threadlocal, | 562 // linkage, alignment, section, visibility, threadlocal, |
| 524 // unnamed_addr] | 563 // unnamed_addr] |
| 525 Vals.push_back(VE.getTypeID(GV->getType())); | 564 Vals.push_back(VE.getTypeID(GV->getType())); |
| 526 Vals.push_back(GV->isConstant()); | 565 Vals.push_back(GV->isConstant()); |
| 527 Vals.push_back(GV->isDeclaration() ? 0 : | 566 Vals.push_back(GV->isDeclaration() ? 0 : |
| 528 (VE.getValueID(GV->getInitializer()) + 1)); | 567 (VE.getValueID(GV->getInitializer()) + 1)); |
| 529 Vals.push_back(getEncodedLinkage(GV)); | 568 Vals.push_back(getEncodedLinkage(GV)); |
| 530 Vals.push_back(Log2_32(GV->getAlignment())+1); | 569 Vals.push_back(Log2_32(GV->getAlignment())+1); |
| 531 Vals.push_back(GV->hasSection() ? SectionMap[GV->getSection()] : 0); | 570 Vals.push_back(GV->hasSection() ? SectionMap[GV->getSection()] : 0); |
| 532 if (GV->isThreadLocal() || | 571 if (GV->isThreadLocal() || |
| 533 GV->getVisibility() != GlobalValue::DefaultVisibility || | 572 GV->getVisibility() != GlobalValue::DefaultVisibility || |
| 534 GV->hasUnnamedAddr() || GV->isExternallyInitialized()) { | 573 GV->hasUnnamedAddr() || GV->isExternallyInitialized()) { |
| 535 Vals.push_back(getEncodedVisibility(GV)); | 574 Vals.push_back(getEncodedVisibility(GV)); |
| 536 Vals.push_back(getEncodedThreadLocalMode(GV)); | 575 Vals.push_back(getEncodedThreadLocalMode(GV)); |
| 537 Vals.push_back(GV->hasUnnamedAddr()); | 576 Vals.push_back(GV->hasUnnamedAddr()); |
| 538 Vals.push_back(GV->isExternallyInitialized()); | 577 Vals.push_back(GV->isExternallyInitialized()); |
| 539 } else { | 578 } else { |
| 540 AbbrevToUse = SimpleGVarAbbrev; | 579 AbbrevToUse = MODULE_GLOBALVAR_ABBREV; |
| 541 } | 580 } |
| 542 | 581 |
| 543 Stream.EmitRecord(naclbitc::MODULE_CODE_GLOBALVAR, Vals, AbbrevToUse); | 582 Stream.EmitRecord(naclbitc::MODULE_CODE_GLOBALVAR, Vals, AbbrevToUse); |
| 544 Vals.clear(); | 583 Vals.clear(); |
| 545 } | 584 } |
| 546 | 585 |
| 547 // Emit the function proto information. | 586 // Emit the function proto information. |
| 548 for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { | 587 for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { |
| 549 // FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment, | 588 // FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment, |
| 550 // section, visibility, gc, unnamed_addr] | 589 // section, visibility, gc, unnamed_addr] |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 569 AI != E; ++AI) { | 608 AI != E; ++AI) { |
| 570 // ALIAS: [alias type, aliasee val#, linkage, visibility] | 609 // ALIAS: [alias type, aliasee val#, linkage, visibility] |
| 571 Vals.push_back(VE.getTypeID(AI->getType())); | 610 Vals.push_back(VE.getTypeID(AI->getType())); |
| 572 Vals.push_back(VE.getValueID(AI->getAliasee())); | 611 Vals.push_back(VE.getValueID(AI->getAliasee())); |
| 573 Vals.push_back(getEncodedLinkage(AI)); | 612 Vals.push_back(getEncodedLinkage(AI)); |
| 574 Vals.push_back(getEncodedVisibility(AI)); | 613 Vals.push_back(getEncodedVisibility(AI)); |
| 575 unsigned AbbrevToUse = 0; | 614 unsigned AbbrevToUse = 0; |
| 576 Stream.EmitRecord(naclbitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse); | 615 Stream.EmitRecord(naclbitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse); |
| 577 Vals.clear(); | 616 Vals.clear(); |
| 578 } | 617 } |
| 618 DEBUG(dbgs() << "<- WriteModuleInfo\n"); | |
| 579 } | 619 } |
| 580 | 620 |
| 581 static uint64_t GetOptimizationFlags(const Value *V) { | 621 static uint64_t GetOptimizationFlags(const Value *V) { |
| 582 uint64_t Flags = 0; | 622 uint64_t Flags = 0; |
| 583 | 623 |
| 584 if (const OverflowingBinaryOperator *OBO = | 624 if (const OverflowingBinaryOperator *OBO = |
| 585 dyn_cast<OverflowingBinaryOperator>(V)) { | 625 dyn_cast<OverflowingBinaryOperator>(V)) { |
| 586 if (OBO->hasNoSignedWrap()) | 626 if (OBO->hasNoSignedWrap()) |
| 587 Flags |= 1 << naclbitc::OBO_NO_SIGNED_WRAP; | 627 Flags |= 1 << naclbitc::OBO_NO_SIGNED_WRAP; |
| 588 if (OBO->hasNoUnsignedWrap()) | 628 if (OBO->hasNoUnsignedWrap()) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 } | 663 } |
| 624 unsigned MDCode = N->isFunctionLocal() ? naclbitc::METADATA_FN_NODE : | 664 unsigned MDCode = N->isFunctionLocal() ? naclbitc::METADATA_FN_NODE : |
| 625 naclbitc::METADATA_NODE; | 665 naclbitc::METADATA_NODE; |
| 626 Stream.EmitRecord(MDCode, Record, 0); | 666 Stream.EmitRecord(MDCode, Record, 0); |
| 627 Record.clear(); | 667 Record.clear(); |
| 628 } | 668 } |
| 629 | 669 |
| 630 static void WriteModuleMetadata(const Module *M, | 670 static void WriteModuleMetadata(const Module *M, |
| 631 const NaClValueEnumerator &VE, | 671 const NaClValueEnumerator &VE, |
| 632 NaClBitstreamWriter &Stream) { | 672 NaClBitstreamWriter &Stream) { |
| 673 DEBUG(dbgs() << "-> WriteModuleMetadata\n"); | |
| 633 const NaClValueEnumerator::ValueList &Vals = VE.getMDValues(); | 674 const NaClValueEnumerator::ValueList &Vals = VE.getMDValues(); |
| 634 bool StartedMetadataBlock = false; | 675 bool StartedMetadataBlock = false; |
| 635 unsigned MDSAbbrev = 0; | |
| 636 SmallVector<uint64_t, 64> Record; | 676 SmallVector<uint64_t, 64> Record; |
| 637 for (unsigned i = 0, e = Vals.size(); i != e; ++i) { | 677 for (unsigned i = 0, e = Vals.size(); i != e; ++i) { |
| 638 | 678 |
| 639 if (const MDNode *N = dyn_cast<MDNode>(Vals[i].first)) { | 679 if (const MDNode *N = dyn_cast<MDNode>(Vals[i].first)) { |
| 640 if (!N->isFunctionLocal() || !N->getFunction()) { | 680 if (!N->isFunctionLocal() || !N->getFunction()) { |
| 641 if (!StartedMetadataBlock) { | 681 if (!StartedMetadataBlock) { |
| 642 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); | 682 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, |
| 683 METADATA_MAX_ABBREV); | |
| 643 StartedMetadataBlock = true; | 684 StartedMetadataBlock = true; |
| 644 } | 685 } |
| 645 WriteMDNode(N, VE, Stream, Record); | 686 WriteMDNode(N, VE, Stream, Record); |
| 646 } | 687 } |
| 647 } else if (const MDString *MDS = dyn_cast<MDString>(Vals[i].first)) { | 688 } else if (const MDString *MDS = dyn_cast<MDString>(Vals[i].first)) { |
| 648 if (!StartedMetadataBlock) { | 689 if (!StartedMetadataBlock) { |
| 649 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); | 690 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, METADATA_MAX_ABBREV); |
| 650 | |
| 651 // Abbrev for METADATA_STRING. | |
| 652 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | |
| 653 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::METADATA_STRING)); | |
|
jvoung (off chromium)
2013/05/17 23:40:48
why is this now deleted instead of emitting an abb
Karl
2013/05/20 22:59:20
This was added as an abbreviation in the "BlockInf
| |
| 654 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | |
| 655 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); | |
| 656 MDSAbbrev = Stream.EmitAbbrev(Abbv); | |
| 657 StartedMetadataBlock = true; | 691 StartedMetadataBlock = true; |
| 658 } | 692 } |
| 659 | 693 |
| 660 // Code: [strchar x N] | 694 // Code: [strchar x N] |
| 661 Record.append(MDS->begin(), MDS->end()); | 695 Record.append(MDS->begin(), MDS->end()); |
| 662 | 696 |
| 663 // Emit the finished record. | 697 // Emit the finished record. |
| 664 Stream.EmitRecord(naclbitc::METADATA_STRING, Record, MDSAbbrev); | 698 // Stream.EmitRecord(naclbitc::METADATA_STRING, Record, MDSAbbrev); |
|
jvoung (off chromium)
2013/05/17 23:40:48
delete commented out?
Karl
2013/05/20 22:59:20
Done.
| |
| 699 Stream.EmitRecord(naclbitc::METADATA_STRING, Record, METADATA_STRING_ABBRE V); | |
|
jvoung (off chromium)
2013/05/17 23:40:48
80 col
Karl
2013/05/20 22:59:20
Done.
| |
| 665 Record.clear(); | 700 Record.clear(); |
| 666 } | 701 } |
| 667 } | 702 } |
| 668 | 703 |
| 669 // Write named metadata. | 704 // Write named metadata. |
| 670 for (Module::const_named_metadata_iterator I = M->named_metadata_begin(), | 705 for (Module::const_named_metadata_iterator I = M->named_metadata_begin(), |
| 671 E = M->named_metadata_end(); I != E; ++I) { | 706 E = M->named_metadata_end(); I != E; ++I) { |
| 672 const NamedMDNode *NMD = I; | 707 const NamedMDNode *NMD = I; |
| 673 if (!StartedMetadataBlock) { | 708 if (!StartedMetadataBlock) { |
| 674 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); | 709 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, METADATA_MAX_ABBREV); |
| 675 StartedMetadataBlock = true; | 710 StartedMetadataBlock = true; |
| 676 } | 711 } |
| 677 | 712 |
| 678 // Write name. | 713 // Write name. |
| 679 StringRef Str = NMD->getName(); | 714 StringRef Str = NMD->getName(); |
| 680 for (unsigned i = 0, e = Str.size(); i != e; ++i) | 715 for (unsigned i = 0, e = Str.size(); i != e; ++i) |
| 681 Record.push_back(Str[i]); | 716 Record.push_back(Str[i]); |
| 682 Stream.EmitRecord(naclbitc::METADATA_NAME, Record, 0/*TODO*/); | 717 Stream.EmitRecord(naclbitc::METADATA_NAME, Record, 0/*TODO*/); |
| 683 Record.clear(); | 718 Record.clear(); |
| 684 | 719 |
| 685 // Write named metadata operands. | 720 // Write named metadata operands. |
| 686 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) | 721 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) |
| 687 Record.push_back(VE.getValueID(NMD->getOperand(i))); | 722 Record.push_back(VE.getValueID(NMD->getOperand(i))); |
| 688 Stream.EmitRecord(naclbitc::METADATA_NAMED_NODE, Record, 0); | 723 Stream.EmitRecord(naclbitc::METADATA_NAMED_NODE, Record, 0); |
| 689 Record.clear(); | 724 Record.clear(); |
| 690 } | 725 } |
| 691 | 726 |
| 692 if (StartedMetadataBlock) | 727 if (StartedMetadataBlock) |
| 693 Stream.ExitBlock(); | 728 Stream.ExitBlock(); |
| 729 | |
| 730 DEBUG(dbgs() << "<- WriteModuleMetadata\n"); | |
| 694 } | 731 } |
| 695 | 732 |
| 696 static void WriteFunctionLocalMetadata(const Function &F, | 733 static void WriteFunctionLocalMetadata(const Function &F, |
| 697 const NaClValueEnumerator &VE, | 734 const NaClValueEnumerator &VE, |
| 698 NaClBitstreamWriter &Stream) { | 735 NaClBitstreamWriter &Stream) { |
| 736 DEBUG(dbgs() << "-> WriteFunctionLocalMetadata\n"); | |
| 699 bool StartedMetadataBlock = false; | 737 bool StartedMetadataBlock = false; |
| 700 SmallVector<uint64_t, 64> Record; | 738 SmallVector<uint64_t, 64> Record; |
| 701 const SmallVector<const MDNode *, 8> &Vals = VE.getFunctionLocalMDValues(); | 739 const SmallVector<const MDNode *, 8> &Vals = VE.getFunctionLocalMDValues(); |
| 702 for (unsigned i = 0, e = Vals.size(); i != e; ++i) | 740 for (unsigned i = 0, e = Vals.size(); i != e; ++i) |
| 703 if (const MDNode *N = Vals[i]) | 741 if (const MDNode *N = Vals[i]) |
| 704 if (N->isFunctionLocal() && N->getFunction() == &F) { | 742 if (N->isFunctionLocal() && N->getFunction() == &F) { |
| 705 if (!StartedMetadataBlock) { | 743 if (!StartedMetadataBlock) { |
| 706 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); | 744 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, |
| 745 METADATA_MAX_ABBREV); | |
| 707 StartedMetadataBlock = true; | 746 StartedMetadataBlock = true; |
| 708 } | 747 } |
| 709 WriteMDNode(N, VE, Stream, Record); | 748 WriteMDNode(N, VE, Stream, Record); |
| 710 } | 749 } |
| 711 | 750 |
| 712 if (StartedMetadataBlock) | 751 if (StartedMetadataBlock) |
| 713 Stream.ExitBlock(); | 752 Stream.ExitBlock(); |
| 753 DEBUG(dbgs() << "<- WriteFunctionLocalMetadata\n"); | |
| 714 } | 754 } |
| 715 | 755 |
| 716 static void WriteMetadataAttachment(const Function &F, | 756 static void WriteMetadataAttachment(const Function &F, |
| 717 const NaClValueEnumerator &VE, | 757 const NaClValueEnumerator &VE, |
| 718 NaClBitstreamWriter &Stream) { | 758 NaClBitstreamWriter &Stream) { |
| 719 Stream.EnterSubblock(naclbitc::METADATA_ATTACHMENT_ID, 3); | 759 Stream.EnterSubblock(naclbitc::METADATA_ATTACHMENT_ID); |
| 720 | 760 |
| 721 SmallVector<uint64_t, 64> Record; | 761 SmallVector<uint64_t, 64> Record; |
| 722 | 762 |
| 723 // Write metadata attachments | 763 // Write metadata attachments |
| 724 // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]] | 764 // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]] |
| 725 SmallVector<std::pair<unsigned, MDNode*>, 4> MDs; | 765 SmallVector<std::pair<unsigned, MDNode*>, 4> MDs; |
| 726 | 766 |
| 727 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) | 767 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) |
| 728 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); | 768 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); |
| 729 I != E; ++I) { | 769 I != E; ++I) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 750 NaClBitstreamWriter &Stream) { | 790 NaClBitstreamWriter &Stream) { |
| 751 SmallVector<uint64_t, 64> Record; | 791 SmallVector<uint64_t, 64> Record; |
| 752 | 792 |
| 753 // Write metadata kinds | 793 // Write metadata kinds |
| 754 // METADATA_KIND - [n x [id, name]] | 794 // METADATA_KIND - [n x [id, name]] |
| 755 SmallVector<StringRef, 8> Names; | 795 SmallVector<StringRef, 8> Names; |
| 756 M->getMDKindNames(Names); | 796 M->getMDKindNames(Names); |
| 757 | 797 |
| 758 if (Names.empty()) return; | 798 if (Names.empty()) return; |
| 759 | 799 |
| 760 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); | 800 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID); |
| 761 | 801 |
| 762 for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) { | 802 for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) { |
| 763 Record.push_back(MDKindID); | 803 Record.push_back(MDKindID); |
| 764 StringRef KName = Names[MDKindID]; | 804 StringRef KName = Names[MDKindID]; |
| 765 Record.append(KName.begin(), KName.end()); | 805 Record.append(KName.begin(), KName.end()); |
| 766 | 806 |
| 767 Stream.EmitRecord(naclbitc::METADATA_KIND, Record, 0); | 807 Stream.EmitRecord(naclbitc::METADATA_KIND, Record, 0); |
| 768 Record.clear(); | 808 Record.clear(); |
| 769 } | 809 } |
| 770 | 810 |
| 771 Stream.ExitBlock(); | 811 Stream.ExitBlock(); |
| 772 } | 812 } |
| 773 | 813 |
| 774 static void emitSignedInt64(SmallVectorImpl<uint64_t> &Vals, uint64_t V) { | 814 static void emitSignedInt64(SmallVectorImpl<uint64_t> &Vals, uint64_t V) { |
| 775 if ((int64_t)V >= 0) | 815 Vals.push_back(NaClEncodeSignRotatedValue((int64_t)V)); |
| 776 Vals.push_back(V << 1); | |
| 777 else | |
| 778 Vals.push_back((-V << 1) | 1); | |
| 779 } | 816 } |
| 780 | 817 |
| 781 static void EmitAPInt(SmallVectorImpl<uint64_t> &Vals, | 818 static void EmitAPInt(SmallVectorImpl<uint64_t> &Vals, |
| 782 unsigned &Code, unsigned &AbbrevToUse, const APInt &Val, | 819 unsigned &Code, unsigned &AbbrevToUse, const APInt &Val, |
| 783 bool EmitSizeForWideNumbers = false | 820 bool EmitSizeForWideNumbers = false |
| 784 ) { | 821 ) { |
| 785 if (Val.getBitWidth() <= 64) { | 822 if (Val.getBitWidth() <= 64) { |
| 786 uint64_t V = Val.getSExtValue(); | 823 uint64_t V = Val.getSExtValue(); |
| 787 emitSignedInt64(Vals, V); | 824 emitSignedInt64(Vals, V); |
| 788 Code = naclbitc::CST_CODE_INTEGER; | 825 Code = naclbitc::CST_CODE_INTEGER; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 804 } | 841 } |
| 805 Code = naclbitc::CST_CODE_WIDE_INTEGER; | 842 Code = naclbitc::CST_CODE_WIDE_INTEGER; |
| 806 } | 843 } |
| 807 } | 844 } |
| 808 | 845 |
| 809 static void WriteConstants(unsigned FirstVal, unsigned LastVal, | 846 static void WriteConstants(unsigned FirstVal, unsigned LastVal, |
| 810 const NaClValueEnumerator &VE, | 847 const NaClValueEnumerator &VE, |
| 811 NaClBitstreamWriter &Stream, bool isGlobal) { | 848 NaClBitstreamWriter &Stream, bool isGlobal) { |
| 812 if (FirstVal == LastVal) return; | 849 if (FirstVal == LastVal) return; |
| 813 | 850 |
| 814 Stream.EnterSubblock(naclbitc::CONSTANTS_BLOCK_ID, 4); | 851 Stream.EnterSubblock(naclbitc::CONSTANTS_BLOCK_ID, |
| 852 (isGlobal | |
| 853 ? CST_CONSTANTS_MAX_ABBREV | |
| 854 : CONSTANTS_MAX_ABBREV)); | |
| 815 | 855 |
| 816 unsigned AggregateAbbrev = 0; | 856 unsigned AggregateAbbrev = 0; |
| 817 unsigned String8Abbrev = 0; | 857 unsigned String8Abbrev = 0; |
| 818 unsigned CString7Abbrev = 0; | 858 unsigned CString7Abbrev = 0; |
| 819 unsigned CString6Abbrev = 0; | 859 unsigned CString6Abbrev = 0; |
| 820 // If this is a constant pool for the module, emit module-specific abbrevs. | 860 // If this is a constant pool for the module, emit module-specific abbrevs. |
| 861 // Note: These abbreviations are size specific (to LastVal), and hence, | |
| 862 // can be more efficient if LastVal is known (rather then generating | |
| 863 // up-front for all constant sections). | |
| 821 if (isGlobal) { | 864 if (isGlobal) { |
| 822 // Abbrev for CST_CODE_AGGREGATE. | 865 // Abbrev for CST_CODE_AGGREGATE. |
| 823 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 866 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 824 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_AGGREGATE)); | 867 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_AGGREGATE)); |
| 825 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | 868 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| 826 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, | 869 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, |
| 827 Log2_32_Ceil(LastVal+1))); | 870 NaClBitsNeededForValue(LastVal))); |
| 828 AggregateAbbrev = Stream.EmitAbbrev(Abbv); | 871 AggregateAbbrev = Stream.EmitAbbrev(Abbv); |
| 872 if (CST_CONSTANTS_AGGREGATE_ABBREV != AggregateAbbrev) | |
| 873 llvm_unreachable("Unexpected abbrev ordering!"); | |
| 829 | 874 |
| 830 // Abbrev for CST_CODE_STRING. | 875 // Abbrev for CST_CODE_STRING. |
| 831 Abbv = new NaClBitCodeAbbrev(); | 876 Abbv = new NaClBitCodeAbbrev(); |
| 832 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_STRING)); | 877 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_STRING)); |
| 833 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | 878 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| 834 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); | 879 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); |
| 835 String8Abbrev = Stream.EmitAbbrev(Abbv); | 880 String8Abbrev = Stream.EmitAbbrev(Abbv); |
| 881 if (CST_CONSTANTS_STRING_ABBREV != String8Abbrev) | |
| 882 llvm_unreachable("Unexpected abbrev ordering!"); | |
| 883 | |
| 836 // Abbrev for CST_CODE_CSTRING. | 884 // Abbrev for CST_CODE_CSTRING. |
| 837 Abbv = new NaClBitCodeAbbrev(); | 885 Abbv = new NaClBitCodeAbbrev(); |
| 838 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CSTRING)); | 886 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CSTRING)); |
| 839 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | 887 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| 840 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 7)); | 888 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 7)); |
| 841 CString7Abbrev = Stream.EmitAbbrev(Abbv); | 889 CString7Abbrev = Stream.EmitAbbrev(Abbv); |
| 890 if (CST_CONSTANTS_CSTRING_7_ABBREV != CString7Abbrev) | |
| 891 llvm_unreachable("Unexpected abbrev ordering!"); | |
| 892 | |
| 842 // Abbrev for CST_CODE_CSTRING. | 893 // Abbrev for CST_CODE_CSTRING. |
| 843 Abbv = new NaClBitCodeAbbrev(); | 894 Abbv = new NaClBitCodeAbbrev(); |
| 844 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CSTRING)); | 895 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CSTRING)); |
| 845 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | 896 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| 846 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Char6)); | 897 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Char6)); |
| 847 CString6Abbrev = Stream.EmitAbbrev(Abbv); | 898 CString6Abbrev = Stream.EmitAbbrev(Abbv); |
| 899 if (CST_CONSTANTS_CSTRING_6_ABBREV != CString6Abbrev) | |
| 900 llvm_unreachable("Unexpected abbrev ordering!"); | |
| 901 | |
| 902 DEBUG(dbgs() << "-- emitted abbreviations\n"); | |
| 848 } | 903 } |
| 849 | 904 |
| 905 | |
| 850 SmallVector<uint64_t, 64> Record; | 906 SmallVector<uint64_t, 64> Record; |
| 851 | 907 |
| 852 const NaClValueEnumerator::ValueList &Vals = VE.getValues(); | 908 const NaClValueEnumerator::ValueList &Vals = VE.getValues(); |
| 853 Type *LastTy = 0; | 909 Type *LastTy = 0; |
| 854 for (unsigned i = FirstVal; i != LastVal; ++i) { | 910 for (unsigned i = FirstVal; i != LastVal; ++i) { |
| 855 const Value *V = Vals[i].first; | 911 const Value *V = Vals[i].first; |
| 856 // If we need to switch types, do so now. | 912 // If we need to switch types, do so now. |
| 857 if (V->getType() != LastTy) { | 913 if (V->getType() != LastTy) { |
| 858 LastTy = V->getType(); | 914 LastTy = V->getType(); |
| 859 Record.push_back(VE.getTypeID(LastTy)); | 915 Record.push_back(VE.getTypeID(LastTy)); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1045 #ifndef NDEBUG | 1101 #ifndef NDEBUG |
| 1046 C->dump(); | 1102 C->dump(); |
| 1047 #endif | 1103 #endif |
| 1048 llvm_unreachable("Unknown constant!"); | 1104 llvm_unreachable("Unknown constant!"); |
| 1049 } | 1105 } |
| 1050 Stream.EmitRecord(Code, Record, AbbrevToUse); | 1106 Stream.EmitRecord(Code, Record, AbbrevToUse); |
| 1051 Record.clear(); | 1107 Record.clear(); |
| 1052 } | 1108 } |
| 1053 | 1109 |
| 1054 Stream.ExitBlock(); | 1110 Stream.ExitBlock(); |
| 1111 DEBUG(dbgs() << "<- WriteConstants\n"); | |
| 1055 } | 1112 } |
| 1056 | 1113 |
| 1057 static void WriteModuleConstants(const NaClValueEnumerator &VE, | 1114 static void WriteModuleConstants(const NaClValueEnumerator &VE, |
| 1058 NaClBitstreamWriter &Stream) { | 1115 NaClBitstreamWriter &Stream) { |
| 1059 const NaClValueEnumerator::ValueList &Vals = VE.getValues(); | 1116 const NaClValueEnumerator::ValueList &Vals = VE.getValues(); |
| 1060 | 1117 |
| 1061 // Find the first constant to emit, which is the first non-globalvalue value. | 1118 // Find the first constant to emit, which is the first non-globalvalue value. |
| 1062 // We know globalvalues have been emitted by WriteModuleInfo. | 1119 // We know globalvalues have been emitted by WriteModuleInfo. |
| 1063 for (unsigned i = 0, e = Vals.size(); i != e; ++i) { | 1120 for (unsigned i = 0, e = Vals.size(); i != e; ++i) { |
| 1064 if (!isa<GlobalValue>(Vals[i].first)) { | 1121 if (!isa<GlobalValue>(Vals[i].first)) { |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1469 | 1526 |
| 1470 Stream.EmitRecord(Code, Vals, AbbrevToUse); | 1527 Stream.EmitRecord(Code, Vals, AbbrevToUse); |
| 1471 Vals.clear(); | 1528 Vals.clear(); |
| 1472 } | 1529 } |
| 1473 | 1530 |
| 1474 // Emit names for globals/functions etc. | 1531 // Emit names for globals/functions etc. |
| 1475 static void WriteValueSymbolTable(const ValueSymbolTable &VST, | 1532 static void WriteValueSymbolTable(const ValueSymbolTable &VST, |
| 1476 const NaClValueEnumerator &VE, | 1533 const NaClValueEnumerator &VE, |
| 1477 NaClBitstreamWriter &Stream) { | 1534 NaClBitstreamWriter &Stream) { |
| 1478 if (VST.empty()) return; | 1535 if (VST.empty()) return; |
| 1479 Stream.EnterSubblock(naclbitc::VALUE_SYMTAB_BLOCK_ID, 4); | 1536 Stream.EnterSubblock(naclbitc::VALUE_SYMTAB_BLOCK_ID, VST_MAX_ABBREV); |
| 1480 | 1537 |
| 1481 // FIXME: Set up the abbrev, we know how many values there are! | 1538 // FIXME: Set up the abbrev, we know how many values there are! |
| 1482 // FIXME: We know if the type names can use 7-bit ascii. | 1539 // FIXME: We know if the type names can use 7-bit ascii. |
| 1483 SmallVector<unsigned, 64> NameVals; | 1540 SmallVector<unsigned, 64> NameVals; |
| 1484 | 1541 |
| 1485 for (ValueSymbolTable::const_iterator SI = VST.begin(), SE = VST.end(); | 1542 for (ValueSymbolTable::const_iterator SI = VST.begin(), SE = VST.end(); |
| 1486 SI != SE; ++SI) { | 1543 SI != SE; ++SI) { |
| 1487 | 1544 |
| 1488 const ValueName &Name = *SI; | 1545 const ValueName &Name = *SI; |
| 1489 | 1546 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1525 // Emit the finished record. | 1582 // Emit the finished record. |
| 1526 Stream.EmitRecord(Code, NameVals, AbbrevToUse); | 1583 Stream.EmitRecord(Code, NameVals, AbbrevToUse); |
| 1527 NameVals.clear(); | 1584 NameVals.clear(); |
| 1528 } | 1585 } |
| 1529 Stream.ExitBlock(); | 1586 Stream.ExitBlock(); |
| 1530 } | 1587 } |
| 1531 | 1588 |
| 1532 /// WriteFunction - Emit a function body to the module stream. | 1589 /// WriteFunction - Emit a function body to the module stream. |
| 1533 static void WriteFunction(const Function &F, NaClValueEnumerator &VE, | 1590 static void WriteFunction(const Function &F, NaClValueEnumerator &VE, |
| 1534 NaClBitstreamWriter &Stream) { | 1591 NaClBitstreamWriter &Stream) { |
| 1535 Stream.EnterSubblock(naclbitc::FUNCTION_BLOCK_ID, 4); | 1592 Stream.EnterSubblock(naclbitc::FUNCTION_BLOCK_ID, FUNCTION_INST_MAX_ABBREV); |
| 1536 VE.incorporateFunction(F); | 1593 VE.incorporateFunction(F); |
| 1537 | 1594 |
| 1538 SmallVector<unsigned, 64> Vals; | 1595 SmallVector<unsigned, 64> Vals; |
| 1539 | 1596 |
| 1540 // Emit the number of basic blocks, so the reader can create them ahead of | 1597 // Emit the number of basic blocks, so the reader can create them ahead of |
| 1541 // time. | 1598 // time. |
| 1542 Vals.push_back(VE.getBasicBlocks().size()); | 1599 Vals.push_back(VE.getBasicBlocks().size()); |
| 1543 Stream.EmitRecord(naclbitc::FUNC_CODE_DECLAREBLOCKS, Vals); | 1600 Stream.EmitRecord(naclbitc::FUNC_CODE_DECLAREBLOCKS, Vals); |
| 1544 Vals.clear(); | 1601 Vals.clear(); |
| 1545 | 1602 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1600 VE.purgeFunction(); | 1657 VE.purgeFunction(); |
| 1601 Stream.ExitBlock(); | 1658 Stream.ExitBlock(); |
| 1602 } | 1659 } |
| 1603 | 1660 |
| 1604 // Emit blockinfo, which defines the standard abbreviations etc. | 1661 // Emit blockinfo, which defines the standard abbreviations etc. |
| 1605 static void WriteBlockInfo(const NaClValueEnumerator &VE, | 1662 static void WriteBlockInfo(const NaClValueEnumerator &VE, |
| 1606 NaClBitstreamWriter &Stream) { | 1663 NaClBitstreamWriter &Stream) { |
| 1607 // We only want to emit block info records for blocks that have multiple | 1664 // We only want to emit block info records for blocks that have multiple |
| 1608 // instances: CONSTANTS_BLOCK, FUNCTION_BLOCK and VALUE_SYMTAB_BLOCK. | 1665 // instances: CONSTANTS_BLOCK, FUNCTION_BLOCK and VALUE_SYMTAB_BLOCK. |
| 1609 // Other blocks can define their abbrevs inline. | 1666 // Other blocks can define their abbrevs inline. |
| 1610 Stream.EnterBlockInfoBlock(2); | 1667 Stream.EnterBlockInfoBlock(); |
| 1611 | 1668 |
| 1612 { // 8-bit fixed-width VST_ENTRY/VST_BBENTRY strings. | 1669 { // 8-bit fixed-width VST_ENTRY/VST_BBENTRY strings. |
| 1613 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 1670 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 1614 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 3)); | 1671 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 3)); |
| 1615 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); | 1672 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); |
| 1616 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | 1673 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
| 1617 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); | 1674 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); |
| 1618 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, | 1675 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, |
| 1619 Abbv) != VST_ENTRY_8_ABBREV) | 1676 Abbv) != VST_ENTRY_8_ABBREV) |
| 1620 llvm_unreachable("Unexpected abbrev ordering!"); | 1677 llvm_unreachable("Unexpected abbrev ordering!"); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1649 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, | 1706 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, |
| 1650 Abbv) != VST_BBENTRY_6_ABBREV) | 1707 Abbv) != VST_BBENTRY_6_ABBREV) |
| 1651 llvm_unreachable("Unexpected abbrev ordering!"); | 1708 llvm_unreachable("Unexpected abbrev ordering!"); |
| 1652 } | 1709 } |
| 1653 | 1710 |
| 1654 | 1711 |
| 1655 | 1712 |
| 1656 { // SETTYPE abbrev for CONSTANTS_BLOCK. | 1713 { // SETTYPE abbrev for CONSTANTS_BLOCK. |
| 1657 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 1714 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 1658 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_SETTYPE)); | 1715 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_SETTYPE)); |
| 1659 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, | 1716 Abbv->Add(NaClBitCodeAbbrevOp( |
| 1660 Log2_32_Ceil(VE.getTypes().size()+1))); | 1717 NaClBitCodeAbbrevOp::Fixed, |
| 1718 NaClBitsNeededForValue(VE.getTypes().size()))); | |
| 1661 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, | 1719 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, |
| 1662 Abbv) != CONSTANTS_SETTYPE_ABBREV) | 1720 Abbv) != CONSTANTS_SETTYPE_ABBREV) |
| 1663 llvm_unreachable("Unexpected abbrev ordering!"); | 1721 llvm_unreachable("Unexpected abbrev ordering!"); |
| 1664 } | 1722 } |
| 1665 | 1723 |
| 1666 { // INTEGER abbrev for CONSTANTS_BLOCK. | 1724 { // INTEGER abbrev for CONSTANTS_BLOCK. |
| 1667 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 1725 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 1668 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_INTEGER)); | 1726 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_INTEGER)); |
| 1669 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); | 1727 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); |
| 1670 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, | 1728 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, |
| 1671 Abbv) != CONSTANTS_INTEGER_ABBREV) | 1729 Abbv) != CONSTANTS_INTEGER_ABBREV) |
| 1672 llvm_unreachable("Unexpected abbrev ordering!"); | 1730 llvm_unreachable("Unexpected abbrev ordering!"); |
| 1673 } | 1731 } |
| 1674 | 1732 |
| 1675 { // CE_CAST abbrev for CONSTANTS_BLOCK. | 1733 { // CE_CAST abbrev for CONSTANTS_BLOCK. |
| 1676 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 1734 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 1677 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CE_CAST)); | 1735 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CE_CAST)); |
| 1678 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // cast opc | 1736 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // cast opc |
| 1679 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, // typeid | 1737 Abbv->Add(NaClBitCodeAbbrevOp( |
| 1680 Log2_32_Ceil(VE.getTypes().size()+1))); | 1738 NaClBitCodeAbbrevOp::Fixed, // typeid |
| 1739 NaClBitsNeededForValue(VE.getTypes().size()))); | |
| 1681 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); // value id | 1740 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); // value id |
| 1682 | 1741 |
| 1683 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, | 1742 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, |
| 1684 Abbv) != CONSTANTS_CE_CAST_Abbrev) | 1743 Abbv) != CONSTANTS_CE_CAST_Abbrev) |
| 1685 llvm_unreachable("Unexpected abbrev ordering!"); | 1744 llvm_unreachable("Unexpected abbrev ordering!"); |
| 1686 } | 1745 } |
| 1687 { // NULL abbrev for CONSTANTS_BLOCK. | 1746 { // NULL abbrev for CONSTANTS_BLOCK. |
| 1688 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 1747 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 1689 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_NULL)); | 1748 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_NULL)); |
| 1690 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, | 1749 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1722 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // opc | 1781 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // opc |
| 1723 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 7)); // flags | 1782 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 7)); // flags |
| 1724 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1783 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
| 1725 Abbv) != FUNCTION_INST_BINOP_FLAGS_ABBREV) | 1784 Abbv) != FUNCTION_INST_BINOP_FLAGS_ABBREV) |
| 1726 llvm_unreachable("Unexpected abbrev ordering!"); | 1785 llvm_unreachable("Unexpected abbrev ordering!"); |
| 1727 } | 1786 } |
| 1728 { // INST_CAST abbrev for FUNCTION_BLOCK. | 1787 { // INST_CAST abbrev for FUNCTION_BLOCK. |
| 1729 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 1788 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 1730 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_CAST)); | 1789 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_CAST)); |
| 1731 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // OpVal | 1790 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // OpVal |
| 1732 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, // dest ty | 1791 Abbv->Add(NaClBitCodeAbbrevOp( |
| 1733 Log2_32_Ceil(VE.getTypes().size()+1))); | 1792 NaClBitCodeAbbrevOp::Fixed, // dest ty |
| 1793 NaClBitsNeededForValue(VE.getTypes().size()))); | |
| 1734 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // opc | 1794 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // opc |
| 1735 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1795 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
| 1736 Abbv) != FUNCTION_INST_CAST_ABBREV) | 1796 Abbv) != FUNCTION_INST_CAST_ABBREV) |
| 1737 llvm_unreachable("Unexpected abbrev ordering!"); | 1797 llvm_unreachable("Unexpected abbrev ordering!"); |
| 1738 } | 1798 } |
| 1739 | 1799 |
| 1740 { // INST_RET abbrev for FUNCTION_BLOCK. | 1800 { // INST_RET abbrev for FUNCTION_BLOCK. |
| 1741 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 1801 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 1742 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_RET)); | 1802 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_RET)); |
| 1743 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1803 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
| 1744 Abbv) != FUNCTION_INST_RET_VOID_ABBREV) | 1804 Abbv) != FUNCTION_INST_RET_VOID_ABBREV) |
| 1745 llvm_unreachable("Unexpected abbrev ordering!"); | 1805 llvm_unreachable("Unexpected abbrev ordering!"); |
| 1746 } | 1806 } |
| 1747 { // INST_RET abbrev for FUNCTION_BLOCK. | 1807 { // INST_RET abbrev for FUNCTION_BLOCK. |
| 1748 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 1808 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 1749 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_RET)); | 1809 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_RET)); |
| 1750 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // ValID | 1810 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // ValID |
| 1751 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1811 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
| 1752 Abbv) != FUNCTION_INST_RET_VAL_ABBREV) | 1812 Abbv) != FUNCTION_INST_RET_VAL_ABBREV) |
| 1753 llvm_unreachable("Unexpected abbrev ordering!"); | 1813 llvm_unreachable("Unexpected abbrev ordering!"); |
| 1754 } | 1814 } |
| 1755 { // INST_UNREACHABLE abbrev for FUNCTION_BLOCK. | 1815 { // INST_UNREACHABLE abbrev for FUNCTION_BLOCK. |
| 1756 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | 1816 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
| 1757 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_UNREACHABLE)); | 1817 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_UNREACHABLE)); |
| 1758 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1818 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
| 1759 Abbv) != FUNCTION_INST_UNREACHABLE_ABBREV) | 1819 Abbv) != FUNCTION_INST_UNREACHABLE_ABBREV) |
| 1760 llvm_unreachable("Unexpected abbrev ordering!"); | 1820 llvm_unreachable("Unexpected abbrev ordering!"); |
| 1761 } | 1821 } |
| 1762 | 1822 |
| 1823 { // Abbrev for METADATA_STRING. | |
| 1824 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); | |
|
jvoung (off chromium)
2013/05/17 23:40:48
why is this moved into the function block?
Karl
2013/05/20 22:59:20
This isn't in the the function block. It is the Bl
| |
| 1825 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::METADATA_STRING)); | |
| 1826 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); | |
| 1827 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); | |
| 1828 if (Stream.EmitBlockInfoAbbrev(naclbitc::METADATA_BLOCK_ID, | |
| 1829 Abbv) != METADATA_STRING_ABBREV) | |
| 1830 llvm_unreachable("Unexpected abbrev ordering!"); | |
| 1831 } | |
| 1832 | |
| 1763 Stream.ExitBlock(); | 1833 Stream.ExitBlock(); |
| 1764 } | 1834 } |
| 1765 | 1835 |
| 1766 /// WriteModule - Emit the specified module to the bitstream. | 1836 /// WriteModule - Emit the specified module to the bitstream. |
| 1767 static void WriteModule(const Module *M, NaClBitstreamWriter &Stream) { | 1837 static void WriteModule(const Module *M, NaClBitstreamWriter &Stream) { |
| 1768 Stream.EnterSubblock(naclbitc::MODULE_BLOCK_ID, 3); | 1838 DEBUG(dbgs() << "-> WriteModule\n"); |
| 1839 Stream.EnterSubblock(naclbitc::MODULE_BLOCK_ID, MODULE_MAX_ABBREV); | |
| 1769 | 1840 |
| 1770 SmallVector<unsigned, 1> Vals; | 1841 SmallVector<unsigned, 1> Vals; |
| 1771 unsigned CurVersion = 1; | 1842 unsigned CurVersion = 1; |
| 1772 Vals.push_back(CurVersion); | 1843 Vals.push_back(CurVersion); |
| 1773 Stream.EmitRecord(naclbitc::MODULE_CODE_VERSION, Vals); | 1844 Stream.EmitRecord(naclbitc::MODULE_CODE_VERSION, Vals); |
| 1774 | 1845 |
| 1775 // Analyze the module, enumerating globals, functions, etc. | 1846 // Analyze the module, enumerating globals, functions, etc. |
| 1776 NaClValueEnumerator VE(M); | 1847 NaClValueEnumerator VE(M); |
| 1777 | 1848 |
| 1778 // Emit blockinfo, which defines the standard abbreviations etc. | 1849 // Emit blockinfo, which defines the standard abbreviations etc. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1802 | 1873 |
| 1803 // Emit names for globals/functions etc. | 1874 // Emit names for globals/functions etc. |
| 1804 WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream); | 1875 WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream); |
| 1805 | 1876 |
| 1806 // Emit function bodies. | 1877 // Emit function bodies. |
| 1807 for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) | 1878 for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) |
| 1808 if (!F->isDeclaration()) | 1879 if (!F->isDeclaration()) |
| 1809 WriteFunction(*F, VE, Stream); | 1880 WriteFunction(*F, VE, Stream); |
| 1810 | 1881 |
| 1811 Stream.ExitBlock(); | 1882 Stream.ExitBlock(); |
| 1883 DEBUG(dbgs() << "<- WriteModule\n"); | |
| 1812 } | 1884 } |
| 1813 | 1885 |
| 1814 /// EmitDarwinBCHeader - If generating a bc file on darwin, we have to emit a | 1886 /// EmitDarwinBCHeader - If generating a bc file on darwin, we have to emit a |
| 1815 /// header and trailer to make it compatible with the system archiver. To do | 1887 /// header and trailer to make it compatible with the system archiver. To do |
| 1816 /// this we emit the following header, and then emit a trailer that pads the | 1888 /// this we emit the following header, and then emit a trailer that pads the |
| 1817 /// file out to be a multiple of 16 bytes. | 1889 /// file out to be a multiple of 16 bytes. |
| 1818 /// | 1890 /// |
| 1819 /// struct bc_header { | 1891 /// struct bc_header { |
| 1820 /// uint32_t Magic; // 0x0B17C0DE | 1892 /// uint32_t Magic; // 0x0B17C0DE |
| 1821 /// uint32_t Version; // Version, currently always 0. | 1893 /// uint32_t Version; // Version, currently always 0. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1914 // Emit the module. | 1986 // Emit the module. |
| 1915 WriteModule(M, Stream); | 1987 WriteModule(M, Stream); |
| 1916 } | 1988 } |
| 1917 | 1989 |
| 1918 if (TT.isOSDarwin()) | 1990 if (TT.isOSDarwin()) |
| 1919 EmitDarwinBCHeaderAndTrailer(Buffer, TT); | 1991 EmitDarwinBCHeaderAndTrailer(Buffer, TT); |
| 1920 | 1992 |
| 1921 // Write the generated bitstream to "Out". | 1993 // Write the generated bitstream to "Out". |
| 1922 Out.write((char*)&Buffer.front(), Buffer.size()); | 1994 Out.write((char*)&Buffer.front(), Buffer.size()); |
| 1923 } | 1995 } |
| OLD | NEW |