mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-13 23:25:06 +00:00
Add support for a union type in LLVM IR. Patch by Talin!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96011 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -585,6 +585,13 @@ bool BitcodeReader::ParseTypeTable() {
|
||||
ResultTy = StructType::get(Context, EltTys, Record[0]);
|
||||
break;
|
||||
}
|
||||
case bitc::TYPE_CODE_UNION: { // UNION: [eltty x N]
|
||||
SmallVector<const Type*, 8> EltTys;
|
||||
for (unsigned i = 0, e = Record.size(); i != e; ++i)
|
||||
EltTys.push_back(getTypeByID(Record[i], true));
|
||||
ResultTy = UnionType::get(&EltTys[0], EltTys.size());
|
||||
break;
|
||||
}
|
||||
case bitc::TYPE_CODE_ARRAY: // ARRAY: [numelts, eltty]
|
||||
if (Record.size() < 2)
|
||||
return Error("Invalid ARRAY type record");
|
||||
|
@@ -181,6 +181,14 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) {
|
||||
Log2_32_Ceil(VE.getTypes().size()+1)));
|
||||
unsigned StructAbbrev = Stream.EmitAbbrev(Abbv);
|
||||
|
||||
// Abbrev for TYPE_CODE_UNION.
|
||||
Abbv = new BitCodeAbbrev();
|
||||
Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_UNION));
|
||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
|
||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
|
||||
Log2_32_Ceil(VE.getTypes().size()+1)));
|
||||
unsigned UnionAbbrev = Stream.EmitAbbrev(Abbv);
|
||||
|
||||
// Abbrev for TYPE_CODE_ARRAY.
|
||||
Abbv = new BitCodeAbbrev();
|
||||
Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_ARRAY));
|
||||
@@ -250,6 +258,17 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) {
|
||||
AbbrevToUse = StructAbbrev;
|
||||
break;
|
||||
}
|
||||
case Type::UnionTyID: {
|
||||
const UnionType *UT = cast<UnionType>(T);
|
||||
// UNION: [eltty x N]
|
||||
Code = bitc::TYPE_CODE_UNION;
|
||||
// Output all of the element types.
|
||||
for (UnionType::element_iterator I = UT->element_begin(),
|
||||
E = UT->element_end(); I != E; ++I)
|
||||
TypeVals.push_back(VE.getTypeID(*I));
|
||||
AbbrevToUse = UnionAbbrev;
|
||||
break;
|
||||
}
|
||||
case Type::ArrayTyID: {
|
||||
const ArrayType *AT = cast<ArrayType>(T);
|
||||
// ARRAY: [numelts, eltty]
|
||||
@@ -789,7 +808,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
|
||||
else if (isCStr7)
|
||||
AbbrevToUse = CString7Abbrev;
|
||||
} else if (isa<ConstantArray>(C) || isa<ConstantStruct>(V) ||
|
||||
isa<ConstantVector>(V)) {
|
||||
isa<ConstantUnion>(C) || isa<ConstantVector>(V)) {
|
||||
Code = bitc::CST_CODE_AGGREGATE;
|
||||
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
|
||||
Record.push_back(VE.getValueID(C->getOperand(i)));
|
||||
|
Reference in New Issue
Block a user