1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Const sized array lookup fix

This commit is contained in:
Brian Fiete 2020-05-25 13:39:25 -07:00
parent c43212c38a
commit 8c2d65ca78

View file

@ -14992,11 +14992,25 @@ void BeMCContext::Generate(BeFunction* function)
break;
}
auto aggType = GetType(mcAgg);
BF_ASSERT(aggType->IsStruct());
BeStructType* structType = (BeStructType*)aggType;
auto& structMember = structType->mMembers[castedInst->mIdx];
int byteOffset = 0;
BeType* memberType = NULL;
if (aggType->IsSizedArray())
{
auto sizedArray = (BeSizedArrayType*)aggType;
memberType = sizedArray->mElementType;
byteOffset = BF_ALIGN(memberType->mSize, memberType->mAlign) * castedInst->mIdx;
}
else
{
BF_ASSERT(aggType->IsStruct());
BeStructType* structType = (BeStructType*)aggType;
auto& structMember = structType->mMembers[castedInst->mIdx];
byteOffset = structMember.mByteOffset;
memberType = structMember.mType;
}
if (mcAgg.mKind == BeMCOperandKind_VReg)
mcAgg.mKind = BeMCOperandKind_VRegAddr;
@ -15004,8 +15018,8 @@ void BeMCContext::Generate(BeFunction* function)
mcAgg.mKind = BeMCOperandKind_VReg;
else
NotImpl();
auto memberPtrType = mModule->mContext->GetPointerTo(structMember.mType);
result = AllocRelativeVirtualReg(memberPtrType, mcAgg, BeMCOperand::FromImmediate(structMember.mByteOffset), 1);
auto memberPtrType = mModule->mContext->GetPointerTo(memberType);
result = AllocRelativeVirtualReg(memberPtrType, mcAgg, BeMCOperand::FromImmediate(byteOffset), 1);
result.mKind = BeMCOperandKind_VRegLoad;
CreateDefineVReg(result);
}