mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Enabled union encoding support
This commit is contained in:
parent
e79b8ca9df
commit
26bd41d8ca
1 changed files with 35 additions and 30 deletions
|
@ -3610,10 +3610,7 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
|
|||
if (bfType->IsTypeInstance())
|
||||
{
|
||||
auto typeInst = bfType->ToTypeInstance();
|
||||
|
||||
if (typeInst->mIsUnion)
|
||||
return BfIRValue();
|
||||
|
||||
|
||||
uint8* instData = ptr;
|
||||
// if ((typeInst->IsObject()) && (!isBaseType))
|
||||
// {
|
||||
|
@ -3745,35 +3742,43 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
|
|||
fieldVals.Add(result);
|
||||
}
|
||||
|
||||
for (int fieldIdx = 0; fieldIdx < typeInst->mFieldInstances.size(); fieldIdx++)
|
||||
if (typeInst->mIsUnion)
|
||||
{
|
||||
auto& fieldInstance = typeInst->mFieldInstances[fieldIdx];
|
||||
if (fieldInstance.mDataOffset < 0)
|
||||
continue;
|
||||
|
||||
if ((fieldInstance.mDataOffset == 0) && (typeInst == mCeMachine->mCompiler->mContext->mBfObjectType))
|
||||
auto unionInnerType = typeInst->GetUnionInnerType();
|
||||
fieldVals.Add(CreateConstant(module, ptr, unionInnerType, outType));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int fieldIdx = 0; fieldIdx < typeInst->mFieldInstances.size(); fieldIdx++)
|
||||
{
|
||||
auto vdataPtr = module->GetClassVDataPtr(typeInst);
|
||||
if (fieldInstance.mResolvedType->IsInteger())
|
||||
fieldVals.Add(irBuilder->CreatePtrToInt(vdataPtr, ((BfPrimitiveType*)fieldInstance.mResolvedType)->mTypeDef->mTypeCode));
|
||||
auto& fieldInstance = typeInst->mFieldInstances[fieldIdx];
|
||||
if (fieldInstance.mDataOffset < 0)
|
||||
continue;
|
||||
|
||||
if ((fieldInstance.mDataOffset == 0) && (typeInst == mCeMachine->mCompiler->mContext->mBfObjectType))
|
||||
{
|
||||
auto vdataPtr = module->GetClassVDataPtr(typeInst);
|
||||
if (fieldInstance.mResolvedType->IsInteger())
|
||||
fieldVals.Add(irBuilder->CreatePtrToInt(vdataPtr, ((BfPrimitiveType*)fieldInstance.mResolvedType)->mTypeDef->mTypeCode));
|
||||
else
|
||||
fieldVals.Add(vdataPtr);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto result = CreateConstant(module, instData + fieldInstance.mDataOffset, fieldInstance.mResolvedType);
|
||||
if (!result)
|
||||
return BfIRValue();
|
||||
|
||||
if (fieldInstance.mDataIdx == fieldVals.mSize)
|
||||
{
|
||||
fieldVals.Add(result);
|
||||
}
|
||||
else
|
||||
fieldVals.Add(vdataPtr);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto result = CreateConstant(module, instData + fieldInstance.mDataOffset, fieldInstance.mResolvedType);
|
||||
if (!result)
|
||||
return BfIRValue();
|
||||
|
||||
if (fieldInstance.mDataIdx == fieldVals.mSize)
|
||||
{
|
||||
fieldVals.Add(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (fieldInstance.mDataIdx >= fieldVals.mSize)
|
||||
fieldVals.Add(BfIRValue());
|
||||
fieldVals[fieldInstance.mDataIdx] = result;
|
||||
{
|
||||
while (fieldInstance.mDataIdx >= fieldVals.mSize)
|
||||
fieldVals.Add(BfIRValue());
|
||||
fieldVals[fieldInstance.mDataIdx] = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue