mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Fixes to "valueless" crepr structs
This commit is contained in:
parent
eb41a9c1de
commit
5c11c2271e
4 changed files with 29 additions and 5 deletions
|
@ -3784,6 +3784,13 @@ void BfIRBuilder::CreateTypeDefinition_Data(BfModule* populateModule, BfTypeInst
|
||||||
SizedArray<BfIRType, 256> irFieldTypes;
|
SizedArray<BfIRType, 256> irFieldTypes;
|
||||||
if ((!typeInstance->IsTypedPrimitive()) && (typeInstance->mBaseType != NULL))
|
if ((!typeInstance->IsTypedPrimitive()) && (typeInstance->mBaseType != NULL))
|
||||||
{
|
{
|
||||||
|
if (typeInstance->mBaseType->IsValuelessCReprType())
|
||||||
|
{
|
||||||
|
// Fake an empty type to avoid having a one-byte base type
|
||||||
|
auto valueTypeType = mModule->ResolveTypeDef(mModule->mCompiler->mValueTypeTypeDef);
|
||||||
|
irFieldTypes.push_back(MapType(valueTypeType, BfIRPopulateType_Eventually_Full));
|
||||||
|
}
|
||||||
|
else
|
||||||
irFieldTypes.push_back(MapTypeInst(typeInstance->mBaseType, BfIRPopulateType_Eventually_Full));
|
irFieldTypes.push_back(MapTypeInst(typeInstance->mBaseType, BfIRPopulateType_Eventually_Full));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2880,6 +2880,20 @@ bool BfTypeInstance::IsValuelessCReprType()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BfTypeInstance* BfTypeInstance::GetBaseType(bool remapValuelessCRepr)
|
||||||
|
{
|
||||||
|
if (!remapValuelessCRepr)
|
||||||
|
return mBaseType;
|
||||||
|
auto checkType = mBaseType;
|
||||||
|
while (checkType != NULL)
|
||||||
|
{
|
||||||
|
if (!checkType->IsValuelessCReprType())
|
||||||
|
break;
|
||||||
|
checkType = checkType->mBaseType;
|
||||||
|
}
|
||||||
|
return checkType;
|
||||||
|
}
|
||||||
|
|
||||||
bool BfTypeInstance::IsIRFuncUsed(BfIRFunction func)
|
bool BfTypeInstance::IsIRFuncUsed(BfIRFunction func)
|
||||||
{
|
{
|
||||||
for (auto& group : mMethodInstanceGroups)
|
for (auto& group : mMethodInstanceGroups)
|
||||||
|
|
|
@ -2176,6 +2176,7 @@ public:
|
||||||
virtual bool CanBeValuelessType() override { return (mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum); }
|
virtual bool CanBeValuelessType() override { return (mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum); }
|
||||||
virtual bool IsValuelessType() override;
|
virtual bool IsValuelessType() override;
|
||||||
virtual bool IsValuelessCReprType();
|
virtual bool IsValuelessCReprType();
|
||||||
|
virtual BfTypeInstance* GetBaseType(bool remapValuelessCRepr = false);
|
||||||
virtual bool HasPackingHoles() override { return mHasPackingHoles; }
|
virtual bool HasPackingHoles() override { return mHasPackingHoles; }
|
||||||
virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef) override;
|
virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef) override;
|
||||||
virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProject* curProject) override;
|
virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProject* curProject) override;
|
||||||
|
|
|
@ -4492,10 +4492,11 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta
|
||||||
auto typeInst = type->ToTypeInstance();
|
auto typeInst = type->ToTypeInstance();
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
if (typeInst->mBaseType != NULL)
|
auto baseType = typeInst->GetBaseType(true);
|
||||||
|
if (baseType != NULL)
|
||||||
{
|
{
|
||||||
auto baseConstant = module->mBfIRBuilder->GetConstant(aggConstant->mValues[0]);
|
auto baseConstant = module->mBfIRBuilder->GetConstant(aggConstant->mValues[0]);
|
||||||
if (!WriteConstant(module, addr, baseConstant, typeInst->mBaseType))
|
if (!WriteConstant(module, addr, baseConstant, baseType))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5034,9 +5035,10 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
|
||||||
return irBuilder->CreateConstNull(irBuilder->MapType(typeInst));
|
return irBuilder->CreateConstNull(irBuilder->MapType(typeInst));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeInst->mBaseType != NULL)
|
auto baseType = typeInst->GetBaseType(true);
|
||||||
|
if (baseType != NULL)
|
||||||
{
|
{
|
||||||
auto result = CreateConstant(module, instData, typeInst->mBaseType);
|
auto result = CreateConstant(module, instData, baseType);
|
||||||
if (!result)
|
if (!result)
|
||||||
return BfIRValue();
|
return BfIRValue();
|
||||||
fieldVals.Add(result);
|
fieldVals.Add(result);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue