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

Copy composites for interop calling conventions

This commit is contained in:
Brian Fiete 2022-02-04 10:29:23 -05:00
parent 904d2aae6c
commit bb49f819ad
3 changed files with 28 additions and 7 deletions

View file

@ -6368,7 +6368,7 @@ void BfExprEvaluator::SplatArgs(BfTypedValue value, SizedArrayImpl<BfIRValue>& i
checkTypeLambda(value);
}
void BfExprEvaluator::PushArg(BfTypedValue argVal, SizedArrayImpl<BfIRValue>& irArgs, bool disableSplat, bool disableLowering, bool isIntrinsic)
void BfExprEvaluator::PushArg(BfTypedValue argVal, SizedArrayImpl<BfIRValue>& irArgs, bool disableSplat, bool disableLowering, bool isIntrinsic, bool createCompositeCopy)
{
MakeBaseConcrete(argVal);
@ -6441,7 +6441,15 @@ void BfExprEvaluator::PushArg(BfTypedValue argVal, SizedArrayImpl<BfIRValue>& ir
return;
}
}
}
if ((createCompositeCopy) && (!argVal.IsTempAddr()))
{
// Non-Beef calling conventions require copies of composites
auto copyAddr = mModule->CreateAlloca(argVal.mType);
mModule->mBfIRBuilder->CreateStore(mModule->LoadValue(argVal).mValue, copyAddr);
argVal = BfTypedValue(copyAddr, argVal.mType, BfTypedValueKind_TempAddr);
}
}
else
argVal = mModule->LoadValue(argVal);
@ -7488,13 +7496,13 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
}
if (argValue)
{
{
if (isThis)
PushThis(targetSrc, argValue, methodInstance, irArgs);
else if (wantsSplat)
SplatArgs(argValue, irArgs);
SplatArgs(argValue, irArgs);
else
PushArg(argValue, irArgs, true, false, methodInstance->mIsIntrinsic);
PushArg(argValue, irArgs, true, false, methodInstance->mIsIntrinsic, methodInstance->mCallingConvention != BfCallingConvention_Unspecified);
}
paramIdx++;
}

View file

@ -456,7 +456,7 @@ public:
BfTypedValue CreateCall(BfMethodMatcher* methodMatcher, BfTypedValue target);
void MakeBaseConcrete(BfTypedValue& typedValue);
void SplatArgs(BfTypedValue value, SizedArrayImpl<BfIRValue>& irArgs);
void PushArg(BfTypedValue argVal, SizedArrayImpl<BfIRValue>& irArgs, bool disableSplat = false, bool disableLowering = false, bool isIntrinsic = false);
void PushArg(BfTypedValue argVal, SizedArrayImpl<BfIRValue>& irArgs, bool disableSplat = false, bool disableLowering = false, bool isIntrinsic = false, bool createCompositeCopy = false);
void PushThis(BfAstNode* targetSrc, BfTypedValue callTarget, BfMethodInstance* methodInstance, SizedArrayImpl<BfIRValue>& irArgs, bool skipMutCheck = false);
BfTypedValue MatchConstructor(BfAstNode* targetSrc, BfMethodBoundExpression* methodBoundExpr, BfTypedValue target, BfTypeInstance* targetType,
BfResolvedArgs& argValues, bool callCtorBodyOnly, bool allowAppendAlloc, BfTypedValue* appendIndexValue = NULL);

View file

@ -314,6 +314,12 @@ void BfGNUMangler::MangleTypeInst(MangleContext& mangleContext, StringImpl& name
typeVec.push_back(BfNodeDynCast<BfDirectTypeReference>(methodDef->mReturnTypeRef)->mType);
if (methodDef->mIsMutating)
name += "_mut_";
if (delegateInfo->mCallingConvention == BfCallingConvention_Cdecl)
name += "_cdecl_";
else if (delegateInfo->mCallingConvention == BfCallingConvention_Stdcall)
name += "_stdcall_";
else if (delegateInfo->mCallingConvention == BfCallingConvention_Fastcall)
name += "_fastcall_";
for (int paramIdx = 0; paramIdx < (int)methodDef->mParams.size(); paramIdx++)
{
name += "_";
@ -1227,7 +1233,7 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl&
BF_ASSERT(newNameSub.mTypeInst->mTypeDef->mMethods[0]->mName == "Invoke");
auto delegateInfo = newNameSub.mTypeInst->GetDelegateInfo();
auto methodDef = newNameSub.mTypeInst->mTypeDef->mMethods[0];
if (newNameSub.mTypeInst->IsDelegate())
name += "?$delegate";
@ -1235,6 +1241,13 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl&
name += "?$function";
if (methodDef->mIsMutating)
name += "_mut_";
if (delegateInfo->mCallingConvention == BfCallingConvention_Cdecl)
name += "_cdecl_";
else if (delegateInfo->mCallingConvention == BfCallingConvention_Stdcall)
name += "_stdcall_";
else if (delegateInfo->mCallingConvention == BfCallingConvention_Fastcall)
name += "_fastcall_";
SizedArray<BfType*, 8> typeVec;
typeVec.push_back(BfNodeDynCast<BfDirectTypeReference>(methodDef->mReturnTypeRef)->mType);