OLD | NEW |
---|---|
1 //===- NaClBitcodeReader.cpp ----------------------------------------------===// | 1 //===- NaClBitcodeReader.cpp ----------------------------------------------===// |
2 // Internal NaClBitcodeReader implementation | 2 // Internal NaClBitcodeReader implementation |
3 // | 3 // |
4 // The LLVM Compiler Infrastructure | 4 // The LLVM Compiler Infrastructure |
5 // | 5 // |
6 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source |
7 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. |
8 // | 8 // |
9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
10 | 10 |
11 #define DEBUG_TYPE "NaClBitcodeReader" | |
12 | |
11 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" | 13 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" |
12 #include "NaClBitcodeReader.h" | 14 #include "NaClBitcodeReader.h" |
13 #include "llvm/ADT/SmallString.h" | 15 #include "llvm/ADT/SmallString.h" |
14 #include "llvm/ADT/SmallVector.h" | 16 #include "llvm/ADT/SmallVector.h" |
15 #include "llvm/AutoUpgrade.h" | 17 #include "llvm/AutoUpgrade.h" |
16 #include "llvm/IR/Constants.h" | 18 #include "llvm/IR/Constants.h" |
17 #include "llvm/IR/DerivedTypes.h" | 19 #include "llvm/IR/DerivedTypes.h" |
18 #include "llvm/IR/InlineAsm.h" | 20 #include "llvm/IR/InlineAsm.h" |
19 #include "llvm/IR/IntrinsicInst.h" | 21 #include "llvm/IR/IntrinsicInst.h" |
20 #include "llvm/IR/Module.h" | 22 #include "llvm/IR/Module.h" |
21 #include "llvm/IR/OperandTraits.h" | 23 #include "llvm/IR/OperandTraits.h" |
22 #include "llvm/IR/Operator.h" | 24 #include "llvm/IR/Operator.h" |
25 #include "llvm/Support/Debug.h" | |
23 #include "llvm/Support/DataStream.h" | 26 #include "llvm/Support/DataStream.h" |
24 #include "llvm/Support/MathExtras.h" | 27 #include "llvm/Support/MathExtras.h" |
25 #include "llvm/Support/MemoryBuffer.h" | 28 #include "llvm/Support/MemoryBuffer.h" |
26 using namespace llvm; | 29 using namespace llvm; |
27 | 30 |
28 enum { | 31 enum { |
29 SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex | 32 SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex |
30 }; | 33 }; |
31 | 34 |
32 void NaClBitcodeReader::materializeForwardReferencedFunctions() { | 35 void NaClBitcodeReader::materializeForwardReferencedFunctions() { |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 assert((!Alignment || isPowerOf2_32(Alignment)) && | 446 assert((!Alignment || isPowerOf2_32(Alignment)) && |
444 "Alignment must be a power of two."); | 447 "Alignment must be a power of two."); |
445 | 448 |
446 if (Alignment) | 449 if (Alignment) |
447 B.addAlignmentAttr(Alignment); | 450 B.addAlignmentAttr(Alignment); |
448 B.addRawValue(((EncodedAttrs & (0xfffffULL << 32)) >> 11) | | 451 B.addRawValue(((EncodedAttrs & (0xfffffULL << 32)) >> 11) | |
449 (EncodedAttrs & 0xffff)); | 452 (EncodedAttrs & 0xffff)); |
450 } | 453 } |
451 | 454 |
452 bool NaClBitcodeReader::ParseAttributeBlock() { | 455 bool NaClBitcodeReader::ParseAttributeBlock() { |
456 DEBUG(dbgs() << "-> ParseAttributeBlock\n"); | |
453 if (Stream.EnterSubBlock(naclbitc::PARAMATTR_BLOCK_ID)) | 457 if (Stream.EnterSubBlock(naclbitc::PARAMATTR_BLOCK_ID)) |
454 return Error("Malformed block record"); | 458 return Error("Malformed block record"); |
455 | 459 |
456 if (!MAttributes.empty()) | 460 if (!MAttributes.empty()) |
457 return Error("Multiple PARAMATTR blocks found!"); | 461 return Error("Multiple PARAMATTR blocks found!"); |
458 | 462 |
459 SmallVector<uint64_t, 64> Record; | 463 SmallVector<uint64_t, 64> Record; |
460 | 464 |
461 SmallVector<AttributeSet, 8> Attrs; | 465 SmallVector<AttributeSet, 8> Attrs; |
462 | 466 |
463 // Read all the records. | 467 // Read all the records. |
464 while (1) { | 468 while (1) { |
465 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); | 469 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
466 | 470 |
467 switch (Entry.Kind) { | 471 switch (Entry.Kind) { |
468 case NaClBitstreamEntry::SubBlock: // Handled for us already. | 472 case NaClBitstreamEntry::SubBlock: // Handled for us already. |
469 case NaClBitstreamEntry::Error: | 473 case NaClBitstreamEntry::Error: |
470 return Error("Error at end of PARAMATTR block"); | 474 return Error("Error at end of PARAMATTR block"); |
471 case NaClBitstreamEntry::EndBlock: | 475 case NaClBitstreamEntry::EndBlock: |
476 DEBUG(dbgs() << "<- ParseAttributeBlock\n"); | |
472 return false; | 477 return false; |
473 case NaClBitstreamEntry::Record: | 478 case NaClBitstreamEntry::Record: |
474 // The interesting case. | 479 // The interesting case. |
475 break; | 480 break; |
476 } | 481 } |
477 | 482 |
478 // Read a record. | 483 // Read a record. |
479 Record.clear(); | 484 Record.clear(); |
480 switch (Stream.readRecord(Entry.ID, Record)) { | 485 switch (Stream.readRecord(Entry.ID, Record)) { |
481 default: // Default behavior: ignore. | 486 default: // Default behavior: ignore. |
(...skipping 19 matching lines...) Expand all Loading... | |
501 | 506 |
502 MAttributes.push_back(AttributeSet::get(Context, Attrs)); | 507 MAttributes.push_back(AttributeSet::get(Context, Attrs)); |
503 Attrs.clear(); | 508 Attrs.clear(); |
504 break; | 509 break; |
505 } | 510 } |
506 } | 511 } |
507 } | 512 } |
508 } | 513 } |
509 | 514 |
510 bool NaClBitcodeReader::ParseAttributeGroupBlock() { | 515 bool NaClBitcodeReader::ParseAttributeGroupBlock() { |
516 DEBUG(dbgs() << "-> ParseAttributeGroupBlock\n"); | |
511 if (Stream.EnterSubBlock(naclbitc::PARAMATTR_GROUP_BLOCK_ID)) | 517 if (Stream.EnterSubBlock(naclbitc::PARAMATTR_GROUP_BLOCK_ID)) |
512 return Error("Malformed block record"); | 518 return Error("Malformed block record"); |
513 | 519 |
514 if (!MAttributeGroups.empty()) | 520 if (!MAttributeGroups.empty()) |
515 return Error("Multiple PARAMATTR_GROUP blocks found!"); | 521 return Error("Multiple PARAMATTR_GROUP blocks found!"); |
516 | 522 |
517 SmallVector<uint64_t, 64> Record; | 523 SmallVector<uint64_t, 64> Record; |
518 | 524 |
519 // Read all the records. | 525 // Read all the records. |
520 while (1) { | 526 while (1) { |
521 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); | 527 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
522 | 528 |
523 switch (Entry.Kind) { | 529 switch (Entry.Kind) { |
524 case NaClBitstreamEntry::SubBlock: // Handled for us already. | 530 case NaClBitstreamEntry::SubBlock: // Handled for us already. |
525 case NaClBitstreamEntry::Error: | 531 case NaClBitstreamEntry::Error: |
526 return Error("Error at end of PARAMATTR_GROUP block"); | 532 return Error("Error at end of PARAMATTR_GROUP block"); |
527 case NaClBitstreamEntry::EndBlock: | 533 case NaClBitstreamEntry::EndBlock: |
534 DEBUG(dbgs() << "<- ParseAttributeGroupBlock\n"); | |
528 return false; | 535 return false; |
529 case NaClBitstreamEntry::Record: | 536 case NaClBitstreamEntry::Record: |
530 // The interesting case. | 537 // The interesting case. |
531 break; | 538 break; |
532 } | 539 } |
533 | 540 |
534 // Read a record. | 541 // Read a record. |
535 Record.clear(); | 542 Record.clear(); |
536 switch (Stream.readRecord(Entry.ID, Record)) { | 543 switch (Stream.readRecord(Entry.ID, Record)) { |
537 default: // Default behavior: ignore. | 544 default: // Default behavior: ignore. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
577 } | 584 } |
578 | 585 |
579 MAttributeGroups[GrpID] = AttributeSet::get(Context, Idx, B); | 586 MAttributeGroups[GrpID] = AttributeSet::get(Context, Idx, B); |
580 break; | 587 break; |
581 } | 588 } |
582 } | 589 } |
583 } | 590 } |
584 } | 591 } |
585 | 592 |
586 bool NaClBitcodeReader::ParseTypeTable() { | 593 bool NaClBitcodeReader::ParseTypeTable() { |
594 DEBUG(dbgs() << "-> ParseTypeTable\n"); | |
587 if (Stream.EnterSubBlock(naclbitc::TYPE_BLOCK_ID_NEW)) | 595 if (Stream.EnterSubBlock(naclbitc::TYPE_BLOCK_ID_NEW)) |
588 return Error("Malformed block record"); | 596 return Error("Malformed block record"); |
589 | 597 |
598 DEBUG(dbgs() << "<- ParseTypeTable\n"); | |
590 return ParseTypeTableBody(); | 599 return ParseTypeTableBody(); |
591 } | 600 } |
592 | 601 |
593 bool NaClBitcodeReader::ParseTypeTableBody() { | 602 bool NaClBitcodeReader::ParseTypeTableBody() { |
594 if (!TypeList.empty()) | 603 if (!TypeList.empty()) |
595 return Error("Multiple TYPE_BLOCKs found!"); | 604 return Error("Multiple TYPE_BLOCKs found!"); |
596 | 605 |
597 SmallVector<uint64_t, 64> Record; | 606 SmallVector<uint64_t, 64> Record; |
598 unsigned NumRecords = 0; | 607 unsigned NumRecords = 0; |
599 | 608 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
803 | 812 |
804 if (NumRecords >= TypeList.size()) | 813 if (NumRecords >= TypeList.size()) |
805 return Error("invalid TYPE table"); | 814 return Error("invalid TYPE table"); |
806 assert(ResultTy && "Didn't read a type?"); | 815 assert(ResultTy && "Didn't read a type?"); |
807 assert(TypeList[NumRecords] == 0 && "Already read type?"); | 816 assert(TypeList[NumRecords] == 0 && "Already read type?"); |
808 TypeList[NumRecords++] = ResultTy; | 817 TypeList[NumRecords++] = ResultTy; |
809 } | 818 } |
810 } | 819 } |
811 | 820 |
812 bool NaClBitcodeReader::ParseValueSymbolTable() { | 821 bool NaClBitcodeReader::ParseValueSymbolTable() { |
822 DEBUG(dbgs() << "-> ParseValueSymbolTable\n"); | |
813 if (Stream.EnterSubBlock(naclbitc::VALUE_SYMTAB_BLOCK_ID)) | 823 if (Stream.EnterSubBlock(naclbitc::VALUE_SYMTAB_BLOCK_ID)) |
814 return Error("Malformed block record"); | 824 return Error("Malformed block record"); |
815 | 825 |
816 SmallVector<uint64_t, 64> Record; | 826 SmallVector<uint64_t, 64> Record; |
817 | 827 |
818 // Read all the records for this value table. | 828 // Read all the records for this value table. |
819 SmallString<128> ValueName; | 829 SmallString<128> ValueName; |
820 while (1) { | 830 while (1) { |
821 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); | 831 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
822 | 832 |
823 switch (Entry.Kind) { | 833 switch (Entry.Kind) { |
824 case NaClBitstreamEntry::SubBlock: // Handled for us already. | 834 case NaClBitstreamEntry::SubBlock: // Handled for us already. |
825 case NaClBitstreamEntry::Error: | 835 case NaClBitstreamEntry::Error: |
826 return Error("malformed value symbol table block"); | 836 return Error("malformed value symbol table block"); |
827 case NaClBitstreamEntry::EndBlock: | 837 case NaClBitstreamEntry::EndBlock: |
838 DEBUG(dbgs() << "<- ParseValueSymbolTable\n"); | |
828 return false; | 839 return false; |
829 case NaClBitstreamEntry::Record: | 840 case NaClBitstreamEntry::Record: |
830 // The interesting case. | 841 // The interesting case. |
831 break; | 842 break; |
832 } | 843 } |
833 | 844 |
834 // Read a record. | 845 // Read a record. |
835 Record.clear(); | 846 Record.clear(); |
836 switch (Stream.readRecord(Entry.ID, Record)) { | 847 switch (Stream.readRecord(Entry.ID, Record)) { |
837 default: // Default behavior: unknown type. | 848 default: // Default behavior: unknown type. |
(...skipping 21 matching lines...) Expand all Loading... | |
859 ValueName.clear(); | 870 ValueName.clear(); |
860 break; | 871 break; |
861 } | 872 } |
862 } | 873 } |
863 } | 874 } |
864 } | 875 } |
865 | 876 |
866 bool NaClBitcodeReader::ParseMetadata() { | 877 bool NaClBitcodeReader::ParseMetadata() { |
867 unsigned NextMDValueNo = MDValueList.size(); | 878 unsigned NextMDValueNo = MDValueList.size(); |
868 | 879 |
880 DEBUG(dbgs() << "-> ParseMetadata\n"); | |
869 if (Stream.EnterSubBlock(naclbitc::METADATA_BLOCK_ID)) | 881 if (Stream.EnterSubBlock(naclbitc::METADATA_BLOCK_ID)) |
870 return Error("Malformed block record"); | 882 return Error("Malformed block record"); |
871 | 883 |
872 SmallVector<uint64_t, 64> Record; | 884 SmallVector<uint64_t, 64> Record; |
873 | 885 |
874 // Read all the records. | 886 // Read all the records. |
875 while (1) { | 887 while (1) { |
876 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); | 888 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
877 | 889 |
878 switch (Entry.Kind) { | 890 switch (Entry.Kind) { |
879 case NaClBitstreamEntry::SubBlock: // Handled for us already. | 891 case NaClBitstreamEntry::SubBlock: // Handled for us already. |
880 case NaClBitstreamEntry::Error: | 892 case NaClBitstreamEntry::Error: |
881 Error("malformed metadata block"); | 893 Error("malformed metadata block"); |
882 return true; | 894 return true; |
883 case NaClBitstreamEntry::EndBlock: | 895 case NaClBitstreamEntry::EndBlock: |
896 DEBUG(dbgs() << "<- ParseMetadata\n"); | |
884 return false; | 897 return false; |
885 case NaClBitstreamEntry::Record: | 898 case NaClBitstreamEntry::Record: |
886 // The interesting case. | 899 // The interesting case. |
887 break; | 900 break; |
888 } | 901 } |
889 | 902 |
890 bool IsFunctionLocal = false; | 903 bool IsFunctionLocal = false; |
891 // Read a record. | 904 // Read a record. |
892 Record.clear(); | 905 Record.clear(); |
893 unsigned Code = Stream.readRecord(Entry.ID, Record); | 906 unsigned Code = Stream.readRecord(Entry.ID, Record); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 | 967 |
955 unsigned NewKind = TheModule->getMDKindID(Name.str()); | 968 unsigned NewKind = TheModule->getMDKindID(Name.str()); |
956 if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second) | 969 if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second) |
957 return Error("Conflicting METADATA_KIND records"); | 970 return Error("Conflicting METADATA_KIND records"); |
958 break; | 971 break; |
959 } | 972 } |
960 } | 973 } |
961 } | 974 } |
962 } | 975 } |
963 | 976 |
964 /// decodeSignRotatedValue - Decode a signed value stored with the sign bit in | |
965 /// the LSB for dense VBR encoding. | |
966 uint64_t NaClBitcodeReader::decodeSignRotatedValue(uint64_t V) { | |
967 if ((V & 1) == 0) | |
968 return V >> 1; | |
969 if (V != 1) | |
970 return -(V >> 1); | |
971 // There is no such thing as -0 with integers. "-0" really means MININT. | |
972 return 1ULL << 63; | |
973 } | |
974 | |
975 /// ResolveGlobalAndAliasInits - Resolve all of the initializers for global | 977 /// ResolveGlobalAndAliasInits - Resolve all of the initializers for global |
976 /// values and aliases that we can. | 978 /// values and aliases that we can. |
977 bool NaClBitcodeReader::ResolveGlobalAndAliasInits() { | 979 bool NaClBitcodeReader::ResolveGlobalAndAliasInits() { |
978 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInitWorklist; | 980 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInitWorklist; |
979 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInitWorklist; | 981 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInitWorklist; |
980 | 982 |
981 GlobalInitWorklist.swap(GlobalInits); | 983 GlobalInitWorklist.swap(GlobalInits); |
982 AliasInitWorklist.swap(AliasInits); | 984 AliasInitWorklist.swap(AliasInits); |
983 | 985 |
984 while (!GlobalInitWorklist.empty()) { | 986 while (!GlobalInitWorklist.empty()) { |
(...skipping 21 matching lines...) Expand all Loading... | |
1006 return Error("Alias initializer is not a constant!"); | 1008 return Error("Alias initializer is not a constant!"); |
1007 } | 1009 } |
1008 AliasInitWorklist.pop_back(); | 1010 AliasInitWorklist.pop_back(); |
1009 } | 1011 } |
1010 return false; | 1012 return false; |
1011 } | 1013 } |
1012 | 1014 |
1013 static APInt ReadWideAPInt(ArrayRef<uint64_t> Vals, unsigned TypeBits) { | 1015 static APInt ReadWideAPInt(ArrayRef<uint64_t> Vals, unsigned TypeBits) { |
1014 SmallVector<uint64_t, 8> Words(Vals.size()); | 1016 SmallVector<uint64_t, 8> Words(Vals.size()); |
1015 std::transform(Vals.begin(), Vals.end(), Words.begin(), | 1017 std::transform(Vals.begin(), Vals.end(), Words.begin(), |
1016 NaClBitcodeReader::decodeSignRotatedValue); | 1018 NaClDecodeSignRotatedValue); |
1017 | 1019 |
1018 return APInt(TypeBits, Words); | 1020 return APInt(TypeBits, Words); |
1019 } | 1021 } |
1020 | 1022 |
1021 bool NaClBitcodeReader::ParseConstants() { | 1023 bool NaClBitcodeReader::ParseConstants() { |
1024 DEBUG(dbgs() << "-> ParseConstants\n"); | |
1022 if (Stream.EnterSubBlock(naclbitc::CONSTANTS_BLOCK_ID)) | 1025 if (Stream.EnterSubBlock(naclbitc::CONSTANTS_BLOCK_ID)) |
1023 return Error("Malformed block record"); | 1026 return Error("Malformed block record"); |
1024 | 1027 |
1025 SmallVector<uint64_t, 64> Record; | 1028 SmallVector<uint64_t, 64> Record; |
1026 | 1029 |
1027 // Read all the records for this value table. | 1030 // Read all the records for this value table. |
1028 Type *CurTy = Type::getInt32Ty(Context); | 1031 Type *CurTy = Type::getInt32Ty(Context); |
1029 unsigned NextCstNo = ValueList.size(); | 1032 unsigned NextCstNo = ValueList.size(); |
1030 while (1) { | 1033 while (1) { |
1031 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); | 1034 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
1032 | 1035 |
1033 switch (Entry.Kind) { | 1036 switch (Entry.Kind) { |
1034 case NaClBitstreamEntry::SubBlock: // Handled for us already. | 1037 case NaClBitstreamEntry::SubBlock: // Handled for us already. |
1035 case NaClBitstreamEntry::Error: | 1038 case NaClBitstreamEntry::Error: |
1036 return Error("malformed block record in AST file"); | 1039 return Error("malformed block record in AST file"); |
1037 case NaClBitstreamEntry::EndBlock: | 1040 case NaClBitstreamEntry::EndBlock: |
1038 if (NextCstNo != ValueList.size()) | 1041 if (NextCstNo != ValueList.size()) |
1039 return Error("Invalid constant reference!"); | 1042 return Error("Invalid constant reference!"); |
1040 | 1043 |
1041 // Once all the constants have been read, go through and resolve forward | 1044 // Once all the constants have been read, go through and resolve forward |
1042 // references. | 1045 // references. |
1043 ValueList.ResolveConstantForwardRefs(); | 1046 ValueList.ResolveConstantForwardRefs(); |
1047 DEBUG(dbgs() << "<- ParseConstants\n"); | |
1044 return false; | 1048 return false; |
1045 case NaClBitstreamEntry::Record: | 1049 case NaClBitstreamEntry::Record: |
1046 // The interesting case. | 1050 // The interesting case. |
1047 break; | 1051 break; |
1048 } | 1052 } |
1049 | 1053 |
1050 // Read a record. | 1054 // Read a record. |
1051 Record.clear(); | 1055 Record.clear(); |
1052 Value *V = 0; | 1056 Value *V = 0; |
1053 unsigned BitCode = Stream.readRecord(Entry.ID, Record); | 1057 unsigned BitCode = Stream.readRecord(Entry.ID, Record); |
1054 switch (BitCode) { | 1058 switch (BitCode) { |
1055 default: // Default behavior: unknown constant | 1059 default: // Default behavior: unknown constant |
1056 case naclbitc::CST_CODE_UNDEF: // UNDEF | 1060 case naclbitc::CST_CODE_UNDEF: // UNDEF |
1057 V = UndefValue::get(CurTy); | 1061 V = UndefValue::get(CurTy); |
1058 break; | 1062 break; |
1059 case naclbitc::CST_CODE_SETTYPE: // SETTYPE: [typeid] | 1063 case naclbitc::CST_CODE_SETTYPE: // SETTYPE: [typeid] |
1060 if (Record.empty()) | 1064 if (Record.empty()) |
1061 return Error("Malformed CST_SETTYPE record"); | 1065 return Error("Malformed CST_SETTYPE record"); |
1062 if (Record[0] >= TypeList.size()) | 1066 if (Record[0] >= TypeList.size()) |
1063 return Error("Invalid Type ID in CST_SETTYPE record"); | 1067 return Error("Invalid Type ID in CST_SETTYPE record"); |
1064 CurTy = TypeList[Record[0]]; | 1068 CurTy = TypeList[Record[0]]; |
1065 continue; // Skip the ValueList manipulation. | 1069 continue; // Skip the ValueList manipulation. |
1066 case naclbitc::CST_CODE_NULL: // NULL | 1070 case naclbitc::CST_CODE_NULL: // NULL |
1067 V = Constant::getNullValue(CurTy); | 1071 V = Constant::getNullValue(CurTy); |
1068 break; | 1072 break; |
1069 case naclbitc::CST_CODE_INTEGER: // INTEGER: [intval] | 1073 case naclbitc::CST_CODE_INTEGER: // INTEGER: [intval] |
1070 if (!CurTy->isIntegerTy() || Record.empty()) | 1074 if (!CurTy->isIntegerTy() || Record.empty()) |
1071 return Error("Invalid CST_INTEGER record"); | 1075 return Error("Invalid CST_INTEGER record"); |
1072 V = ConstantInt::get(CurTy, decodeSignRotatedValue(Record[0])); | 1076 V = ConstantInt::get(CurTy, NaClDecodeSignRotatedValue(Record[0])); |
1073 break; | 1077 break; |
1074 case naclbitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n x intval] | 1078 case naclbitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n x intval] |
1075 if (!CurTy->isIntegerTy() || Record.empty()) | 1079 if (!CurTy->isIntegerTy() || Record.empty()) |
1076 return Error("Invalid WIDE_INTEGER record"); | 1080 return Error("Invalid WIDE_INTEGER record"); |
1077 | 1081 |
1078 APInt VInt = ReadWideAPInt(Record, | 1082 APInt VInt = ReadWideAPInt(Record, |
1079 cast<IntegerType>(CurTy)->getBitWidth()); | 1083 cast<IntegerType>(CurTy)->getBitWidth()); |
1080 V = ConstantInt::get(Context, VInt); | 1084 V = ConstantInt::get(Context, VInt); |
1081 | 1085 |
1082 break; | 1086 break; |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1408 break; | 1412 break; |
1409 } | 1413 } |
1410 } | 1414 } |
1411 | 1415 |
1412 ValueList.AssignValue(V, NextCstNo); | 1416 ValueList.AssignValue(V, NextCstNo); |
1413 ++NextCstNo; | 1417 ++NextCstNo; |
1414 } | 1418 } |
1415 } | 1419 } |
1416 | 1420 |
1417 bool NaClBitcodeReader::ParseUseLists() { | 1421 bool NaClBitcodeReader::ParseUseLists() { |
1422 DEBUG(dbgs() << "-> ParseUseLists\n"); | |
1418 if (Stream.EnterSubBlock(naclbitc::USELIST_BLOCK_ID)) | 1423 if (Stream.EnterSubBlock(naclbitc::USELIST_BLOCK_ID)) |
1419 return Error("Malformed block record"); | 1424 return Error("Malformed block record"); |
1420 | 1425 |
1421 SmallVector<uint64_t, 64> Record; | 1426 SmallVector<uint64_t, 64> Record; |
1422 | 1427 |
1423 // Read all the records. | 1428 // Read all the records. |
1424 while (1) { | 1429 while (1) { |
1425 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); | 1430 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
1426 | 1431 |
1427 switch (Entry.Kind) { | 1432 switch (Entry.Kind) { |
1428 case NaClBitstreamEntry::SubBlock: // Handled for us already. | 1433 case NaClBitstreamEntry::SubBlock: // Handled for us already. |
1429 case NaClBitstreamEntry::Error: | 1434 case NaClBitstreamEntry::Error: |
1430 return Error("malformed use list block"); | 1435 return Error("malformed use list block"); |
1431 case NaClBitstreamEntry::EndBlock: | 1436 case NaClBitstreamEntry::EndBlock: |
1437 DEBUG(dbgs() << "<- ParseUseLists\n"); | |
1432 return false; | 1438 return false; |
1433 case NaClBitstreamEntry::Record: | 1439 case NaClBitstreamEntry::Record: |
1434 // The interesting case. | 1440 // The interesting case. |
1435 break; | 1441 break; |
1436 } | 1442 } |
1437 | 1443 |
1438 // Read a use list record. | 1444 // Read a use list record. |
1439 Record.clear(); | 1445 Record.clear(); |
1440 switch (Stream.readRecord(Entry.ID, Record)) { | 1446 switch (Stream.readRecord(Entry.ID, Record)) { |
1441 default: // Default behavior: unknown type. | 1447 default: // Default behavior: unknown type. |
1442 break; | 1448 break; |
1443 case naclbitc::USELIST_CODE_ENTRY: { // USELIST_CODE_ENTRY: TBD. | 1449 case naclbitc::USELIST_CODE_ENTRY: { // USELIST_CODE_ENTRY: TBD. |
1444 unsigned RecordLength = Record.size(); | 1450 unsigned RecordLength = Record.size(); |
1445 if (RecordLength < 1) | 1451 if (RecordLength < 1) |
1446 return Error ("Invalid UseList reader!"); | 1452 return Error ("Invalid UseList reader!"); |
1447 UseListRecords.push_back(Record); | 1453 UseListRecords.push_back(Record); |
1448 break; | 1454 break; |
1449 } | 1455 } |
1450 } | 1456 } |
1451 } | 1457 } |
1452 } | 1458 } |
1453 | 1459 |
1454 /// RememberAndSkipFunctionBody - When we see the block for a function body, | 1460 /// RememberAndSkipFunctionBody - When we see the block for a function body, |
1455 /// remember where it is and then skip it. This lets us lazily deserialize the | 1461 /// remember where it is and then skip it. This lets us lazily deserialize the |
1456 /// functions. | 1462 /// functions. |
1457 bool NaClBitcodeReader::RememberAndSkipFunctionBody() { | 1463 bool NaClBitcodeReader::RememberAndSkipFunctionBody() { |
1464 DEBUG(dbgs() << "-> RememberAndSkipFunctionBody\n"); | |
1458 // Get the function we are talking about. | 1465 // Get the function we are talking about. |
1459 if (FunctionsWithBodies.empty()) | 1466 if (FunctionsWithBodies.empty()) |
1460 return Error("Insufficient function protos"); | 1467 return Error("Insufficient function protos"); |
1461 | 1468 |
1462 Function *Fn = FunctionsWithBodies.back(); | 1469 Function *Fn = FunctionsWithBodies.back(); |
1463 FunctionsWithBodies.pop_back(); | 1470 FunctionsWithBodies.pop_back(); |
1464 | 1471 |
1465 // Save the current stream state. | 1472 // Save the current stream state. |
1466 uint64_t CurBit = Stream.GetCurrentBitNo(); | 1473 uint64_t CurBit = Stream.GetCurrentBitNo(); |
1467 DeferredFunctionInfo[Fn] = CurBit; | 1474 DeferredFunctionInfo[Fn] = CurBit; |
1468 | 1475 |
1469 // Skip over the function block for now. | 1476 // Skip over the function block for now. |
1470 if (Stream.SkipBlock()) | 1477 if (Stream.SkipBlock()) |
1471 return Error("Malformed block record"); | 1478 return Error("Malformed block record"); |
1479 DEBUG(dbgs() << "<- RememberAndSkipFunctionBody\n"); | |
1472 return false; | 1480 return false; |
1473 } | 1481 } |
1474 | 1482 |
1475 bool NaClBitcodeReader::GlobalCleanup() { | 1483 bool NaClBitcodeReader::GlobalCleanup() { |
1476 // Patch the initializers for globals and aliases up. | 1484 // Patch the initializers for globals and aliases up. |
1477 ResolveGlobalAndAliasInits(); | 1485 ResolveGlobalAndAliasInits(); |
1478 if (!GlobalInits.empty() || !AliasInits.empty()) | 1486 if (!GlobalInits.empty() || !AliasInits.empty()) |
1479 return Error("Malformed global initializer set"); | 1487 return Error("Malformed global initializer set"); |
1480 | 1488 |
1481 // Look for intrinsic functions which need to be upgraded at some point | 1489 // Look for intrinsic functions which need to be upgraded at some point |
(...skipping 10 matching lines...) Expand all Loading... | |
1492 GI != GE; ++GI) | 1500 GI != GE; ++GI) |
1493 UpgradeGlobalVariable(GI); | 1501 UpgradeGlobalVariable(GI); |
1494 // Force deallocation of memory for these vectors to favor the client that | 1502 // Force deallocation of memory for these vectors to favor the client that |
1495 // want lazy deserialization. | 1503 // want lazy deserialization. |
1496 std::vector<std::pair<GlobalVariable*, unsigned> >().swap(GlobalInits); | 1504 std::vector<std::pair<GlobalVariable*, unsigned> >().swap(GlobalInits); |
1497 std::vector<std::pair<GlobalAlias*, unsigned> >().swap(AliasInits); | 1505 std::vector<std::pair<GlobalAlias*, unsigned> >().swap(AliasInits); |
1498 return false; | 1506 return false; |
1499 } | 1507 } |
1500 | 1508 |
1501 bool NaClBitcodeReader::ParseModule(bool Resume) { | 1509 bool NaClBitcodeReader::ParseModule(bool Resume) { |
1510 DEBUG(dbgs() << "-> ParseModule\n"); | |
1502 if (Resume) | 1511 if (Resume) |
1503 Stream.JumpToBit(NextUnreadBit); | 1512 Stream.JumpToBit(NextUnreadBit); |
1504 else if (Stream.EnterSubBlock(naclbitc::MODULE_BLOCK_ID)) | 1513 else if (Stream.EnterSubBlock(naclbitc::MODULE_BLOCK_ID)) |
1505 return Error("Malformed block record"); | 1514 return Error("Malformed block record"); |
1506 | 1515 |
1507 SmallVector<uint64_t, 64> Record; | 1516 SmallVector<uint64_t, 64> Record; |
1508 std::vector<std::string> SectionTable; | 1517 std::vector<std::string> SectionTable; |
1509 std::vector<std::string> GCTable; | 1518 std::vector<std::string> GCTable; |
1510 | 1519 |
1511 // Read all the records for this module. | 1520 // Read all the records for this module. |
1512 while (1) { | 1521 while (1) { |
1513 NaClBitstreamEntry Entry = Stream.advance(); | 1522 NaClBitstreamEntry Entry = Stream.advance(); |
1514 | 1523 |
1515 switch (Entry.Kind) { | 1524 switch (Entry.Kind) { |
1516 case NaClBitstreamEntry::Error: | 1525 case NaClBitstreamEntry::Error: |
1517 Error("malformed module block"); | 1526 Error("malformed module block"); |
1518 return true; | 1527 return true; |
1519 case NaClBitstreamEntry::EndBlock: | 1528 case NaClBitstreamEntry::EndBlock: |
1529 DEBUG(dbgs() << "<- ParseModule\n"); | |
1520 return GlobalCleanup(); | 1530 return GlobalCleanup(); |
1521 | 1531 |
1522 case NaClBitstreamEntry::SubBlock: | 1532 case NaClBitstreamEntry::SubBlock: |
1523 switch (Entry.ID) { | 1533 switch (Entry.ID) { |
1524 default: // Skip unknown content. | 1534 default: // Skip unknown content. |
1535 dbgs() << "Skip unknown context\n"; | |
jvoung (off chromium)
2013/05/17 23:40:48
Put this under DEBUG() also
Karl
2013/05/20 22:59:20
Done.
| |
1525 if (Stream.SkipBlock()) | 1536 if (Stream.SkipBlock()) |
1526 return Error("Malformed block record"); | 1537 return Error("Malformed block record"); |
1527 break; | 1538 break; |
1528 case naclbitc::BLOCKINFO_BLOCK_ID: | 1539 case naclbitc::BLOCKINFO_BLOCK_ID: |
1529 if (Stream.ReadBlockInfoBlock()) | 1540 if (Stream.ReadBlockInfoBlock()) |
1530 return Error("Malformed BlockInfoBlock"); | 1541 return Error("Malformed BlockInfoBlock"); |
1531 break; | 1542 break; |
1532 case naclbitc::PARAMATTR_BLOCK_ID: | 1543 case naclbitc::PARAMATTR_BLOCK_ID: |
1533 if (ParseAttributeBlock()) | 1544 if (ParseAttributeBlock()) { |
1545 DEBUG(dbgs() << "<- ParseModule\n"); | |
1534 return true; | 1546 return true; |
1547 } | |
1535 break; | 1548 break; |
1536 case naclbitc::PARAMATTR_GROUP_BLOCK_ID: | 1549 case naclbitc::PARAMATTR_GROUP_BLOCK_ID: |
1537 if (ParseAttributeGroupBlock()) | 1550 if (ParseAttributeGroupBlock()) { |
1551 DEBUG(dbgs() << "<- ParseModule\n"); | |
1538 return true; | 1552 return true; |
1553 } | |
1539 break; | 1554 break; |
1540 case naclbitc::TYPE_BLOCK_ID_NEW: | 1555 case naclbitc::TYPE_BLOCK_ID_NEW: |
1541 if (ParseTypeTable()) | 1556 if (ParseTypeTable()) { |
1557 DEBUG(dbgs() << "<- ParseModule\n"); | |
1542 return true; | 1558 return true; |
1559 } | |
1543 break; | 1560 break; |
1544 case naclbitc::VALUE_SYMTAB_BLOCK_ID: | 1561 case naclbitc::VALUE_SYMTAB_BLOCK_ID: |
1545 if (ParseValueSymbolTable()) | 1562 if (ParseValueSymbolTable()) { |
1563 DEBUG(dbgs() << "<- ParseModule\n"); | |
1546 return true; | 1564 return true; |
1565 } | |
1547 SeenValueSymbolTable = true; | 1566 SeenValueSymbolTable = true; |
1548 break; | 1567 break; |
1549 case naclbitc::CONSTANTS_BLOCK_ID: | 1568 case naclbitc::CONSTANTS_BLOCK_ID: |
1550 if (ParseConstants() || ResolveGlobalAndAliasInits()) | 1569 if (ParseConstants() || ResolveGlobalAndAliasInits()) { |
1570 DEBUG(dbgs() << "<- ParseModule\n"); | |
1551 return true; | 1571 return true; |
1572 } | |
1552 break; | 1573 break; |
1553 case naclbitc::METADATA_BLOCK_ID: | 1574 case naclbitc::METADATA_BLOCK_ID: |
1554 if (ParseMetadata()) | 1575 if (ParseMetadata()) { |
1576 DEBUG(dbgs() << "<- ParseModule\n"); | |
jvoung (off chromium)
2013/05/17 23:40:48
nit: Is it necessary to print the debug "<-" in th
Karl
2013/05/20 22:59:20
Good point. Did this in some places, but not every
| |
1555 return true; | 1577 return true; |
1578 } | |
1556 break; | 1579 break; |
1557 case naclbitc::FUNCTION_BLOCK_ID: | 1580 case naclbitc::FUNCTION_BLOCK_ID: |
1558 // If this is the first function body we've seen, reverse the | 1581 // If this is the first function body we've seen, reverse the |
1559 // FunctionsWithBodies list. | 1582 // FunctionsWithBodies list. |
1560 if (!SeenFirstFunctionBody) { | 1583 if (!SeenFirstFunctionBody) { |
1561 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end()); | 1584 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end()); |
1562 if (GlobalCleanup()) | 1585 if (GlobalCleanup()) { |
1586 DEBUG(dbgs() << "<- ParseModule\n"); | |
1563 return true; | 1587 return true; |
1588 } | |
1564 SeenFirstFunctionBody = true; | 1589 SeenFirstFunctionBody = true; |
1565 } | 1590 } |
1566 | 1591 |
1567 if (RememberAndSkipFunctionBody()) | 1592 if (RememberAndSkipFunctionBody()) { |
1593 DEBUG(dbgs() << "<- ParseModule\n"); | |
1568 return true; | 1594 return true; |
1595 } | |
1569 // For streaming bitcode, suspend parsing when we reach the function | 1596 // For streaming bitcode, suspend parsing when we reach the function |
1570 // bodies. Subsequent materialization calls will resume it when | 1597 // bodies. Subsequent materialization calls will resume it when |
1571 // necessary. For streaming, the function bodies must be at the end of | 1598 // necessary. For streaming, the function bodies must be at the end of |
1572 // the bitcode. If the bitcode file is old, the symbol table will be | 1599 // the bitcode. If the bitcode file is old, the symbol table will be |
1573 // at the end instead and will not have been seen yet. In this case, | 1600 // at the end instead and will not have been seen yet. In this case, |
1574 // just finish the parse now. | 1601 // just finish the parse now. |
1575 if (LazyStreamer && SeenValueSymbolTable) { | 1602 if (LazyStreamer && SeenValueSymbolTable) { |
1576 NextUnreadBit = Stream.GetCurrentBitNo(); | 1603 NextUnreadBit = Stream.GetCurrentBitNo(); |
1604 DEBUG(dbgs() << "<- ParseModule\n"); | |
1577 return false; | 1605 return false; |
1578 } | 1606 } |
1579 break; | 1607 break; |
1580 case naclbitc::USELIST_BLOCK_ID: | 1608 case naclbitc::USELIST_BLOCK_ID: |
1581 if (ParseUseLists()) | 1609 if (ParseUseLists()) { |
1610 DEBUG(dbgs() << "<- ParseModule\n"); | |
1582 return true; | 1611 return true; |
1612 } | |
1583 break; | 1613 break; |
1584 } | 1614 } |
1585 continue; | 1615 continue; |
1586 | 1616 |
1587 case NaClBitstreamEntry::Record: | 1617 case NaClBitstreamEntry::Record: |
1588 // The interesting case. | 1618 // The interesting case. |
1589 break; | 1619 break; |
1590 } | 1620 } |
1591 | 1621 |
1592 | 1622 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1854 Stream.Read(6) == 2 && Stream.Read(24) == 0xa0a0a && | 1884 Stream.Read(6) == 2 && Stream.Read(24) == 0xa0a0a && |
1855 Stream.AtEndOfStream()) | 1885 Stream.AtEndOfStream()) |
1856 return false; | 1886 return false; |
1857 | 1887 |
1858 return Error("Invalid record at top-level"); | 1888 return Error("Invalid record at top-level"); |
1859 } | 1889 } |
1860 } | 1890 } |
1861 } | 1891 } |
1862 | 1892 |
1863 bool NaClBitcodeReader::ParseModuleTriple(std::string &Triple) { | 1893 bool NaClBitcodeReader::ParseModuleTriple(std::string &Triple) { |
1894 DEBUG(dbgs() << "-> ParseModuleTriple\n"); | |
1864 if (Stream.EnterSubBlock(naclbitc::MODULE_BLOCK_ID)) | 1895 if (Stream.EnterSubBlock(naclbitc::MODULE_BLOCK_ID)) |
1865 return Error("Malformed block record"); | 1896 return Error("Malformed block record"); |
1866 | 1897 |
1867 SmallVector<uint64_t, 64> Record; | 1898 SmallVector<uint64_t, 64> Record; |
1868 | 1899 |
1869 // Read all the records for this module. | 1900 // Read all the records for this module. |
1870 while (1) { | 1901 while (1) { |
1871 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); | 1902 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
1872 | 1903 |
1873 switch (Entry.Kind) { | 1904 switch (Entry.Kind) { |
1874 case NaClBitstreamEntry::SubBlock: // Handled for us already. | 1905 case NaClBitstreamEntry::SubBlock: // Handled for us already. |
1875 case NaClBitstreamEntry::Error: | 1906 case NaClBitstreamEntry::Error: |
1876 return Error("malformed module block"); | 1907 return Error("malformed module block"); |
1877 case NaClBitstreamEntry::EndBlock: | 1908 case NaClBitstreamEntry::EndBlock: |
1909 DEBUG(dbgs() << "<- ParseModuleTriple\n"); | |
1878 return false; | 1910 return false; |
1879 case NaClBitstreamEntry::Record: | 1911 case NaClBitstreamEntry::Record: |
1880 // The interesting case. | 1912 // The interesting case. |
1881 break; | 1913 break; |
1882 } | 1914 } |
1883 | 1915 |
1884 // Read a record. | 1916 // Read a record. |
1885 switch (Stream.readRecord(Entry.ID, Record)) { | 1917 switch (Stream.readRecord(Entry.ID, Record)) { |
1886 default: break; // Default behavior, ignore unknown content. | 1918 default: break; // Default behavior, ignore unknown content. |
1887 case naclbitc::MODULE_CODE_TRIPLE: { // TRIPLE: [strchr x N] | 1919 case naclbitc::MODULE_CODE_TRIPLE: { // TRIPLE: [strchr x N] |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1933 | 1965 |
1934 case NaClBitstreamEntry::Record: | 1966 case NaClBitstreamEntry::Record: |
1935 Stream.skipRecord(Entry.ID); | 1967 Stream.skipRecord(Entry.ID); |
1936 continue; | 1968 continue; |
1937 } | 1969 } |
1938 } | 1970 } |
1939 } | 1971 } |
1940 | 1972 |
1941 /// ParseMetadataAttachment - Parse metadata attachments. | 1973 /// ParseMetadataAttachment - Parse metadata attachments. |
1942 bool NaClBitcodeReader::ParseMetadataAttachment() { | 1974 bool NaClBitcodeReader::ParseMetadataAttachment() { |
1975 DEBUG(dbgs() << "-> ParseMetadataAttachment\n"); | |
1943 if (Stream.EnterSubBlock(naclbitc::METADATA_ATTACHMENT_ID)) | 1976 if (Stream.EnterSubBlock(naclbitc::METADATA_ATTACHMENT_ID)) |
1944 return Error("Malformed block record"); | 1977 return Error("Malformed block record"); |
1945 | 1978 |
1946 SmallVector<uint64_t, 64> Record; | 1979 SmallVector<uint64_t, 64> Record; |
1947 while (1) { | 1980 while (1) { |
1948 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); | 1981 NaClBitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
1949 | 1982 |
1950 switch (Entry.Kind) { | 1983 switch (Entry.Kind) { |
1951 case NaClBitstreamEntry::SubBlock: // Handled for us already. | 1984 case NaClBitstreamEntry::SubBlock: // Handled for us already. |
1952 case NaClBitstreamEntry::Error: | 1985 case NaClBitstreamEntry::Error: |
1953 return Error("malformed metadata block"); | 1986 return Error("malformed metadata block"); |
1954 case NaClBitstreamEntry::EndBlock: | 1987 case NaClBitstreamEntry::EndBlock: |
1988 DEBUG(dbgs() << "<- ParseMetadataAttachment\n"); | |
1955 return false; | 1989 return false; |
1956 case NaClBitstreamEntry::Record: | 1990 case NaClBitstreamEntry::Record: |
1957 // The interesting case. | 1991 // The interesting case. |
1958 break; | 1992 break; |
1959 } | 1993 } |
1960 | 1994 |
1961 // Read a metadata attachment record. | 1995 // Read a metadata attachment record. |
1962 Record.clear(); | 1996 Record.clear(); |
1963 switch (Stream.readRecord(Entry.ID, Record)) { | 1997 switch (Stream.readRecord(Entry.ID, Record)) { |
1964 default: // Default behavior: ignore. | 1998 default: // Default behavior: ignore. |
(...skipping 13 matching lines...) Expand all Loading... | |
1978 Inst->setMetadata(I->second, cast<MDNode>(Node)); | 2012 Inst->setMetadata(I->second, cast<MDNode>(Node)); |
1979 } | 2013 } |
1980 break; | 2014 break; |
1981 } | 2015 } |
1982 } | 2016 } |
1983 } | 2017 } |
1984 } | 2018 } |
1985 | 2019 |
1986 /// ParseFunctionBody - Lazily parse the specified function body block. | 2020 /// ParseFunctionBody - Lazily parse the specified function body block. |
1987 bool NaClBitcodeReader::ParseFunctionBody(Function *F) { | 2021 bool NaClBitcodeReader::ParseFunctionBody(Function *F) { |
2022 DEBUG(dbgs() << "-> ParseFunctionBody\n"); | |
1988 if (Stream.EnterSubBlock(naclbitc::FUNCTION_BLOCK_ID)) | 2023 if (Stream.EnterSubBlock(naclbitc::FUNCTION_BLOCK_ID)) |
1989 return Error("Malformed block record"); | 2024 return Error("Malformed block record"); |
1990 | 2025 |
1991 InstructionList.clear(); | 2026 InstructionList.clear(); |
1992 unsigned ModuleValueListSize = ValueList.size(); | 2027 unsigned ModuleValueListSize = ValueList.size(); |
1993 unsigned ModuleMDValueListSize = MDValueList.size(); | 2028 unsigned ModuleMDValueListSize = MDValueList.size(); |
1994 | 2029 |
1995 // Add all the function arguments to the value table. | 2030 // Add all the function arguments to the value table. |
1996 for(Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I) | 2031 for(Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I) |
1997 ValueList.push_back(I); | 2032 ValueList.push_back(I); |
(...skipping 11 matching lines...) Expand all Loading... | |
2009 | 2044 |
2010 switch (Entry.Kind) { | 2045 switch (Entry.Kind) { |
2011 case NaClBitstreamEntry::Error: | 2046 case NaClBitstreamEntry::Error: |
2012 return Error("Bitcode error in function block"); | 2047 return Error("Bitcode error in function block"); |
2013 case NaClBitstreamEntry::EndBlock: | 2048 case NaClBitstreamEntry::EndBlock: |
2014 goto OutOfRecordLoop; | 2049 goto OutOfRecordLoop; |
2015 | 2050 |
2016 case NaClBitstreamEntry::SubBlock: | 2051 case NaClBitstreamEntry::SubBlock: |
2017 switch (Entry.ID) { | 2052 switch (Entry.ID) { |
2018 default: // Skip unknown content. | 2053 default: // Skip unknown content. |
2054 dbgs() << "default skip block\n"; | |
2019 if (Stream.SkipBlock()) | 2055 if (Stream.SkipBlock()) |
2020 return Error("Malformed block record"); | 2056 return Error("Malformed block record"); |
2021 break; | 2057 break; |
2022 case naclbitc::CONSTANTS_BLOCK_ID: | 2058 case naclbitc::CONSTANTS_BLOCK_ID: |
2023 if (ParseConstants()) return true; | 2059 if (ParseConstants()) { |
2060 DEBUG(dbgs() << "-> ParseFunctionBody\n"); | |
2061 return true; | |
2062 } | |
2024 NextValueNo = ValueList.size(); | 2063 NextValueNo = ValueList.size(); |
2025 break; | 2064 break; |
2026 case naclbitc::VALUE_SYMTAB_BLOCK_ID: | 2065 case naclbitc::VALUE_SYMTAB_BLOCK_ID: |
2027 if (ParseValueSymbolTable()) return true; | 2066 if (ParseValueSymbolTable()) { |
2067 DEBUG(dbgs() << "-> ParseFunctionBody\n"); | |
2068 return true; | |
2069 } | |
2028 break; | 2070 break; |
2029 case naclbitc::METADATA_ATTACHMENT_ID: | 2071 case naclbitc::METADATA_ATTACHMENT_ID: |
2030 if (ParseMetadataAttachment()) return true; | 2072 if (ParseMetadataAttachment()) { |
2073 DEBUG(dbgs() << "-> ParseFunctionBody\n"); | |
2074 return true; | |
2075 } | |
2031 break; | 2076 break; |
2032 case naclbitc::METADATA_BLOCK_ID: | 2077 case naclbitc::METADATA_BLOCK_ID: |
2033 if (ParseMetadata()) return true; | 2078 if (ParseMetadata()) { |
2079 DEBUG(dbgs() << "-> ParseFunctionBody\n"); | |
2080 return true; | |
2081 } | |
2034 break; | 2082 break; |
2035 } | 2083 } |
2036 continue; | 2084 continue; |
2037 | 2085 |
2038 case NaClBitstreamEntry::Record: | 2086 case NaClBitstreamEntry::Record: |
2039 // The interesting case. | 2087 // The interesting case. |
2040 break; | 2088 break; |
2041 } | 2089 } |
2042 | 2090 |
2043 // Read a record. | 2091 // Read a record. |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2855 FwdRef->eraseFromParent(); | 2903 FwdRef->eraseFromParent(); |
2856 } | 2904 } |
2857 | 2905 |
2858 BlockAddrFwdRefs.erase(BAFRI); | 2906 BlockAddrFwdRefs.erase(BAFRI); |
2859 } | 2907 } |
2860 | 2908 |
2861 // Trim the value list down to the size it was before we parsed this function. | 2909 // Trim the value list down to the size it was before we parsed this function. |
2862 ValueList.shrinkTo(ModuleValueListSize); | 2910 ValueList.shrinkTo(ModuleValueListSize); |
2863 MDValueList.shrinkTo(ModuleMDValueListSize); | 2911 MDValueList.shrinkTo(ModuleMDValueListSize); |
2864 std::vector<BasicBlock*>().swap(FunctionBBs); | 2912 std::vector<BasicBlock*>().swap(FunctionBBs); |
2913 DEBUG(dbgs() << "-> ParseFunctionBody\n"); | |
2865 return false; | 2914 return false; |
2866 } | 2915 } |
2867 | 2916 |
2868 /// FindFunctionInStream - Find the function body in the bitcode stream | 2917 /// FindFunctionInStream - Find the function body in the bitcode stream |
2869 bool NaClBitcodeReader::FindFunctionInStream(Function *F, | 2918 bool NaClBitcodeReader::FindFunctionInStream(Function *F, |
2870 DenseMap<Function*, uint64_t>::iterator DeferredFunctionInfoIterator) { | 2919 DenseMap<Function*, uint64_t>::iterator DeferredFunctionInfoIterator) { |
2871 while (DeferredFunctionInfoIterator->second == 0) { | 2920 while (DeferredFunctionInfoIterator->second == 0) { |
2872 if (Stream.AtEndOfStream()) | 2921 if (Stream.AtEndOfStream()) |
2873 return Error("Could not find Function in stream"); | 2922 return Error("Could not find Function in stream"); |
2874 // ParseModule will parse the next body in the stream and set its | 2923 // ParseModule will parse the next body in the stream and set its |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3115 if (M->MaterializeAllPermanently(ErrMsg)) { | 3164 if (M->MaterializeAllPermanently(ErrMsg)) { |
3116 delete M; | 3165 delete M; |
3117 return 0; | 3166 return 0; |
3118 } | 3167 } |
3119 | 3168 |
3120 // TODO: Restore the use-lists to the in-memory state when the bitcode was | 3169 // TODO: Restore the use-lists to the in-memory state when the bitcode was |
3121 // written. We must defer until the Module has been fully materialized. | 3170 // written. We must defer until the Module has been fully materialized. |
3122 | 3171 |
3123 return M; | 3172 return M; |
3124 } | 3173 } |
OLD | NEW |