llvm.org GIT mirror llvm / dbc8849
remove support for reading llvm 2.9 .bc files. LLVM 3.1 is only compatible back to 3.0 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145164 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
10 changed file(s) with 5 addition(s) and 311 deletion(s). Raw diff Collapse all Expand all
2828
2929 // Module sub-block id's.
3030 PARAMATTR_BLOCK_ID,
31
32 /// TYPE_BLOCK_ID_OLD - This is the type descriptor block in LLVM 2.9 and
33 /// earlier, replaced with TYPE_BLOCK_ID2. FIXME: Remove in LLVM 3.1.
34 TYPE_BLOCK_ID_OLD,
31
32 UNUSED_ID1,
3533
3634 CONSTANTS_BLOCK_ID,
3735 FUNCTION_BLOCK_ID,
3836
39 /// TYPE_SYMTAB_BLOCK_ID_OLD - This type descriptor is from LLVM 2.9 and
40 /// earlier bitcode files. FIXME: Remove in LLVM 3.1
41 TYPE_SYMTAB_BLOCK_ID_OLD,
37 UNUSED_ID2,
4238
4339 VALUE_SYMTAB_BLOCK_ID,
4440 METADATA_BLOCK_ID,
9389 TYPE_CODE_POINTER = 8, // POINTER: [pointee type]
9490 TYPE_CODE_FUNCTION_OLD = 9, // FUNCTION: [vararg, attrid, retty, paramty x N]
9591
96 // FIXME: This is the encoding used for structs in LLVM 2.9 and earlier.
97 // REMOVE this in LLVM 3.1
98 TYPE_CODE_STRUCT_OLD = 10, // STRUCT: [ispacked, eltty x N]
92 // Code #10 is unused.
93
9994 TYPE_CODE_ARRAY = 11, // ARRAY: [numelts, eltty]
10095 TYPE_CODE_VECTOR = 12, // VECTOR: [numelts, eltty]
10196
400400 // If we have a forward reference, the only possible case is when it is to a
401401 // named struct. Just create a placeholder for now.
402402 return TypeList[ID] = StructType::create(Context);
403 }
404
405 /// FIXME: Remove in LLVM 3.1, only used by ParseOldTypeTable.
406 Type *BitcodeReader::getTypeByIDOrNull(unsigned ID) {
407 if (ID >= TypeList.size())
408 TypeList.resize(ID+1);
409
410 return TypeList[ID];
411403 }
412404
413405
743735 assert(ResultTy && "Didn't read a type?");
744736 assert(TypeList[NumRecords] == 0 && "Already read type?");
745737 TypeList[NumRecords++] = ResultTy;
746 }
747 }
748
749 // FIXME: Remove in LLVM 3.1
750 bool BitcodeReader::ParseOldTypeTable() {
751 if (Stream.EnterSubBlock(bitc::TYPE_BLOCK_ID_OLD))
752 return Error("Malformed block record");
753
754 if (!TypeList.empty())
755 return Error("Multiple TYPE_BLOCKs found!");
756
757
758 // While horrible, we have no good ordering of types in the bc file. Just
759 // iteratively parse types out of the bc file in multiple passes until we get
760 // them all. Do this by saving a cursor for the start of the type block.
761 BitstreamCursor StartOfTypeBlockCursor(Stream);
762
763 unsigned NumTypesRead = 0;
764
765 SmallVector Record;
766 RestartScan:
767 unsigned NextTypeID = 0;
768 bool ReadAnyTypes = false;
769
770 // Read all the records for this type table.
771 while (1) {
772 unsigned Code = Stream.ReadCode();
773 if (Code == bitc::END_BLOCK) {
774 if (NextTypeID != TypeList.size())
775 return Error("Invalid type forward reference in TYPE_BLOCK_ID_OLD");
776
777 // If we haven't read all of the types yet, iterate again.
778 if (NumTypesRead != TypeList.size()) {
779 // If we didn't successfully read any types in this pass, then we must
780 // have an unhandled forward reference.
781 if (!ReadAnyTypes)
782 return Error("Obsolete bitcode contains unhandled recursive type");
783
784 Stream = StartOfTypeBlockCursor;
785 goto RestartScan;
786 }
787
788 if (Stream.ReadBlockEnd())
789 return Error("Error at end of type table block");
790 return false;
791 }
792
793 if (Code == bitc::ENTER_SUBBLOCK) {
794 // No known subblocks, always skip them.
795 Stream.ReadSubBlockID();
796 if (Stream.SkipBlock())
797 return Error("Malformed block record");
798 continue;
799 }
800
801 if (Code == bitc::DEFINE_ABBREV) {
802 Stream.ReadAbbrevRecord();
803 continue;
804 }
805
806 // Read a record.
807 Record.clear();
808 Type *ResultTy = 0;
809 switch (Stream.ReadRecord(Code, Record)) {
810 default: return Error("unknown type in type table");
811 case bitc::TYPE_CODE_NUMENTRY: // TYPE_CODE_NUMENTRY: [numentries]
812 // TYPE_CODE_NUMENTRY contains a count of the number of types in the
813 // type list. This allows us to reserve space.
814 if (Record.size() < 1)
815 return Error("Invalid TYPE_CODE_NUMENTRY record");
816 TypeList.resize(Record[0]);
817 continue;
818 case bitc::TYPE_CODE_VOID: // VOID
819 ResultTy = Type::getVoidTy(Context);
820 break;
821 case bitc::TYPE_CODE_FLOAT: // FLOAT
822 ResultTy = Type::getFloatTy(Context);
823 break;
824 case bitc::TYPE_CODE_DOUBLE: // DOUBLE
825 ResultTy = Type::getDoubleTy(Context);
826 break;
827 case bitc::TYPE_CODE_X86_FP80: // X86_FP80
828 ResultTy = Type::getX86_FP80Ty(Context);
829 break;
830 case bitc::TYPE_CODE_FP128: // FP128
831 ResultTy = Type::getFP128Ty(Context);
832 break;
833 case bitc::TYPE_CODE_PPC_FP128: // PPC_FP128
834 ResultTy = Type::getPPC_FP128Ty(Context);
835 break;
836 case bitc::TYPE_CODE_LABEL: // LABEL
837 ResultTy = Type::getLabelTy(Context);
838 break;
839 case bitc::TYPE_CODE_METADATA: // METADATA
840 ResultTy = Type::getMetadataTy(Context);
841 break;
842 case bitc::TYPE_CODE_X86_MMX: // X86_MMX
843 ResultTy = Type::getX86_MMXTy(Context);
844 break;
845 case bitc::TYPE_CODE_INTEGER: // INTEGER: [width]
846 if (Record.size() < 1)
847 return Error("Invalid Integer type record");
848 ResultTy = IntegerType::get(Context, Record[0]);
849 break;
850 case bitc::TYPE_CODE_OPAQUE: // OPAQUE
851 if (NextTypeID < TypeList.size() && TypeList[NextTypeID] == 0)
852 ResultTy = StructType::create(Context);
853 break;
854 case bitc::TYPE_CODE_STRUCT_OLD: {// STRUCT_OLD
855 if (NextTypeID >= TypeList.size()) break;
856 // If we already read it, don't reprocess.
857 if (TypeList[NextTypeID] &&
858 !cast(TypeList[NextTypeID])->isOpaque())
859 break;
860
861 // Set a type.
862 if (TypeList[NextTypeID] == 0)
863 TypeList[NextTypeID] = StructType::create(Context);
864
865 std::vector EltTys;
866 for (unsigned i = 1, e = Record.size(); i != e; ++i) {
867 if (Type *Elt = getTypeByIDOrNull(Record[i]))
868 EltTys.push_back(Elt);
869 else
870 break;
871 }
872
873 if (EltTys.size() != Record.size()-1)
874 break; // Not all elements are ready.
875
876 cast(TypeList[NextTypeID])->setBody(EltTys, Record[0]);
877 ResultTy = TypeList[NextTypeID];
878 TypeList[NextTypeID] = 0;
879 break;
880 }
881 case bitc::TYPE_CODE_POINTER: { // POINTER: [pointee type] or
882 // [pointee type, address space]
883 if (Record.size() < 1)
884 return Error("Invalid POINTER type record");
885 unsigned AddressSpace = 0;
886 if (Record.size() == 2)
887 AddressSpace = Record[1];
888 if ((ResultTy = getTypeByIDOrNull(Record[0])))
889 ResultTy = PointerType::get(ResultTy, AddressSpace);
890 break;
891 }
892 case bitc::TYPE_CODE_FUNCTION_OLD: {
893 // FIXME: attrid is dead, remove it in LLVM 3.0
894 // FUNCTION: [vararg, attrid, retty, paramty x N]
895 if (Record.size() < 3)
896 return Error("Invalid FUNCTION type record");
897 std::vector ArgTys;
898 for (unsigned i = 3, e = Record.size(); i != e; ++i) {
899 if (Type *Elt = getTypeByIDOrNull(Record[i]))
900 ArgTys.push_back(Elt);
901 else
902 break;
903 }
904 if (ArgTys.size()+3 != Record.size())
905 break; // Something was null.
906 if ((ResultTy = getTypeByIDOrNull(Record[2])))
907 ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0]);
908 break;
909 }
910 case bitc::TYPE_CODE_FUNCTION: {
911 // FUNCTION: [vararg, retty, paramty x N]
912 if (Record.size() < 2)
913 return Error("Invalid FUNCTION type record");
914 std::vector ArgTys;
915 for (unsigned i = 2, e = Record.size(); i != e; ++i) {
916 if (Type *Elt = getTypeByIDOrNull(Record[i]))
917 ArgTys.push_back(Elt);
918 else
919 break;
920 }
921 if (ArgTys.size()+2 != Record.size())
922 break; // Something was null.
923 if ((ResultTy = getTypeByIDOrNull(Record[1])))
924 ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0]);
925 break;
926 }
927 case bitc::TYPE_CODE_ARRAY: // ARRAY: [numelts, eltty]
928 if (Record.size() < 2)
929 return Error("Invalid ARRAY type record");
930 if ((ResultTy = getTypeByIDOrNull(Record[1])))
931 ResultTy = ArrayType::get(ResultTy, Record[0]);
932 break;
933 case bitc::TYPE_CODE_VECTOR: // VECTOR: [numelts, eltty]
934 if (Record.size() < 2)
935 return Error("Invalid VECTOR type record");
936 if ((ResultTy = getTypeByIDOrNull(Record[1])))
937 ResultTy = VectorType::get(ResultTy, Record[0]);
938 break;
939 }
940
941 if (NextTypeID >= TypeList.size())
942 return Error("invalid TYPE table");
943
944 if (ResultTy && TypeList[NextTypeID] == 0) {
945 ++NumTypesRead;
946 ReadAnyTypes = true;
947
948 TypeList[NextTypeID] = ResultTy;
949 }
950
951 ++NextTypeID;
952 }
953 }
954
955
956 bool BitcodeReader::ParseOldTypeSymbolTable() {
957 if (Stream.EnterSubBlock(bitc::TYPE_SYMTAB_BLOCK_ID_OLD))
958 return Error("Malformed block record");
959
960 SmallVector Record;
961
962 // Read all the records for this type table.
963 std::string TypeName;
964 while (1) {
965 unsigned Code = Stream.ReadCode();
966 if (Code == bitc::END_BLOCK) {
967 if (Stream.ReadBlockEnd())
968 return Error("Error at end of type symbol table block");
969 return false;
970 }
971
972 if (Code == bitc::ENTER_SUBBLOCK) {
973 // No known subblocks, always skip them.
974 Stream.ReadSubBlockID();
975 if (Stream.SkipBlock())
976 return Error("Malformed block record");
977 continue;
978 }
979
980 if (Code == bitc::DEFINE_ABBREV) {
981 Stream.ReadAbbrevRecord();
982 continue;
983 }
984
985 // Read a record.
986 Record.clear();
987 switch (Stream.ReadRecord(Code, Record)) {
988 default: // Default behavior: unknown type.
989 break;
990 case bitc::TST_CODE_ENTRY: // TST_ENTRY: [typeid, namechar x N]
991 if (ConvertToString(Record, 1, TypeName))
992 return Error("Invalid TST_ENTRY record");
993 unsigned TypeID = Record[0];
994 if (TypeID >= TypeList.size())
995 return Error("Invalid Type ID in TST_ENTRY record");
996
997 // Only apply the type name to a struct type with no name.
998 if (StructType *STy = dyn_cast(TypeList[TypeID]))
999 if (!STy->isLiteral() && !STy->hasName())
1000 STy->setName(TypeName);
1001 TypeName.clear();
1002 break;
1003 }
1004738 }
1005739 }
1006740
16331367 break;
16341368 case bitc::TYPE_BLOCK_ID_NEW:
16351369 if (ParseTypeTable())
1636 return true;
1637 break;
1638 case bitc::TYPE_BLOCK_ID_OLD:
1639 if (ParseOldTypeTable())
1640 return true;
1641 break;
1642 case bitc::TYPE_SYMTAB_BLOCK_ID_OLD:
1643 if (ParseOldTypeSymbolTable())
16441370 return true;
16451371 break;
16461372 case bitc::VALUE_SYMTAB_BLOCK_ID:
210210 bool ParseTriple(std::string &Triple);
211211 private:
212212 Type *getTypeByID(unsigned ID);
213 Type *getTypeByIDOrNull(unsigned ID);
214213 Value *getFnValueByID(unsigned ID, Type *Ty) {
215214 if (Ty && Ty->isMetadataTy())
216215 return MDValueList.getValueFwdRef(ID);
258257 bool ParseModule();
259258 bool ParseAttributeBlock();
260259 bool ParseTypeTable();
261 bool ParseOldTypeTable(); // FIXME: Remove in LLVM 3.1
262260 bool ParseTypeTableBody();
263261
264 bool ParseOldTypeSymbolTable(); // FIXME: Remove in LLVM 3.1
265262 bool ParseValueSymbolTable();
266263 bool ParseConstants();
267264 bool RememberAndSkipFunctionBody();
+0
-4
test/Bitcode/AutoUpgradeGlobals.ll less more
None ; This isn't really an assembly file. It just runs test on bitcode to ensure
1 ; it is auto-upgraded.
2 ; RUN: llvm-dis < %s.bc | FileCheck %s
3 ; CHECK-NOT: {i32 @\\.llvm\\.eh}
test/Bitcode/AutoUpgradeGlobals.ll.bc less more
Binary diff not shown
+0
-5
test/Bitcode/fbench-llvm-2.9.ll less more
None ; This isn't really an assembly file. It just runs the test on the bitcode to
1 ; ensure bitcode file backward compatibility. No need for FileCheck as the
2 ; BitcodeReader will fail with an assert if broken. This test case was
3 ; generated using a clang binary, based on LLVM 2.9, downloaded from llvm.org.
4 ; RUN: llvm-dis < %s.bc > /dev/null
test/Bitcode/fbench-llvm-2.9.ll.bc less more
Binary diff not shown
+0
-5
test/Bitcode/spirit-llvm-2.9.ll less more
None ; This isn't really an assembly file. It just runs the test on the bitcode to
1 ; ensure bitcode file backward compatibility. No need for FileCheck as the
2 ; BitcodeReader will fail with an assert if broken. This test case was
3 ; generated using a clang binary, based on LLVM 2.9, downloaded from llvm.org.
4 ; RUN: llvm-dis < %s.bc > /dev/null
test/Bitcode/spirit-llvm-2.9.ll.bc less more
Binary diff not shown
101101 default: return 0;
102102 case bitc::MODULE_BLOCK_ID: return "MODULE_BLOCK";
103103 case bitc::PARAMATTR_BLOCK_ID: return "PARAMATTR_BLOCK";
104 case bitc::TYPE_BLOCK_ID_OLD: return "TYPE_BLOCK_ID_OLD";
105104 case bitc::TYPE_BLOCK_ID_NEW: return "TYPE_BLOCK_ID";
106105 case bitc::CONSTANTS_BLOCK_ID: return "CONSTANTS_BLOCK";
107106 case bitc::FUNCTION_BLOCK_ID: return "FUNCTION_BLOCK";
108 case bitc::TYPE_SYMTAB_BLOCK_ID_OLD: return "TYPE_SYMTAB_OLD";
109107 case bitc::VALUE_SYMTAB_BLOCK_ID: return "VALUE_SYMTAB";
110108 case bitc::METADATA_BLOCK_ID: return "METADATA_BLOCK";
111109 case bitc::METADATA_ATTACHMENT_ID: return "METADATA_ATTACHMENT_BLOCK";
162160 default: return 0;
163161 case bitc::PARAMATTR_CODE_ENTRY: return "ENTRY";
164162 }
165 case bitc::TYPE_BLOCK_ID_OLD:
166163 case bitc::TYPE_BLOCK_ID_NEW:
167164 switch (CodeID) {
168165 default: return 0;
174171 case bitc::TYPE_CODE_OPAQUE: return "OPAQUE";
175172 case bitc::TYPE_CODE_INTEGER: return "INTEGER";
176173 case bitc::TYPE_CODE_POINTER: return "POINTER";
177 case bitc::TYPE_CODE_FUNCTION_OLD: return "FUNCTION_OLD";
178 case bitc::TYPE_CODE_STRUCT_OLD: return "STRUCT_OLD";
179174 case bitc::TYPE_CODE_ARRAY: return "ARRAY";
180175 case bitc::TYPE_CODE_VECTOR: return "VECTOR";
181176 case bitc::TYPE_CODE_X86_FP80: return "X86_FP80";
247242 case bitc::FUNC_CODE_INST_CALL: return "INST_CALL";
248243 case bitc::FUNC_CODE_DEBUG_LOC: return "DEBUG_LOC";
249244 }
250 case bitc::TYPE_SYMTAB_BLOCK_ID_OLD:
251 switch (CodeID) {
252 default: return 0;
253 case bitc::TST_CODE_ENTRY: return "ENTRY";
254 }
255245 case bitc::VALUE_SYMTAB_BLOCK_ID:
256246 switch (CodeID) {
257247 default: return 0;