Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp

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

Powered by Google App Engine
This is Rietveld 408576698