AsmWriter/Bitcode: MDDerivedType and MDCompositeType

llvm-svn: 229009
This commit is contained in:
Duncan P. N. Exon Smith
2015-02-13 01:20:38 +00:00
parent d6346e6f3e
commit 171d077ae4
9 changed files with 265 additions and 23 deletions

View File

@@ -1183,12 +1183,17 @@ std::error_code BitcodeReader::ParseMetadata() {
SmallVector<uint64_t, 64> Record;
auto getMD =
[&](unsigned ID) -> Metadata *{ return MDValueList.getValueFwdRef(ID); };
auto getMDOrNull = [&](unsigned ID) -> Metadata *{
if (ID)
return getMD(ID - 1);
return nullptr;
};
auto getMDString = [&](unsigned ID) -> MDString *{
// This requires that the ID is not really a forward reference. In
// particular, the MDString must already have been resolved.
if (ID)
return cast<MDString>(MDValueList.getValueFwdRef(ID - 1));
return nullptr;
return cast_or_null<MDString>(getMDOrNull(ID));
};
#define GET_OR_DISTINCT(CLASS, DISTINCT, ARGS) \
@@ -1382,6 +1387,36 @@ std::error_code BitcodeReader::ParseMetadata() {
NextMDValueNo++);
break;
}
case bitc::METADATA_DERIVED_TYPE: {
if (Record.size() != 12)
return Error("Invalid record");
MDValueList.AssignValue(
GET_OR_DISTINCT(MDDerivedType, Record[0],
(Context, Record[1], getMDString(Record[2]),
getMDOrNull(Record[3]), Record[4],
getMDOrNull(Record[5]), getMD(Record[6]), Record[7],
Record[8], Record[9], Record[10],
getMDOrNull(Record[11]))),
NextMDValueNo++);
break;
}
case bitc::METADATA_COMPOSITE_TYPE: {
if (Record.size() != 16)
return Error("Invalid record");
MDValueList.AssignValue(
GET_OR_DISTINCT(MDCompositeType, Record[0],
(Context, Record[1], getMDString(Record[2]),
getMDOrNull(Record[3]), Record[4],
getMDOrNull(Record[5]), getMDOrNull(Record[6]),
Record[7], Record[8], Record[9], Record[10],
getMDOrNull(Record[11]), Record[12],
getMDOrNull(Record[13]), getMDOrNull(Record[14]),
getMDString(Record[15]))),
NextMDValueNo++);
break;
}
case bitc::METADATA_FILE: {
if (Record.size() != 3)
return Error("Invalid record");