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

Interop fixes and tests, fixing xplat struct passing issues

This commit is contained in:
Brian Fiete 2020-06-10 07:12:07 -07:00
parent 4cf6af53bd
commit 5da74382d4
31 changed files with 1569 additions and 239 deletions

View file

@ -71,6 +71,22 @@ BeStructType* BeContext::CreateStruct(const StringImpl& name)
return structType;
}
BeStructType* BeContext::CreateStruct(const SizedArrayImpl<BeType*>& types)
{
BeStructType** valuePtr = NULL;
if (mAnonymousStructMap.TryGetValueWith(types, &valuePtr))
return *valuePtr;
Array<BeType*> key;
for (auto type : types)
key.Add(type);
BeStructType* structType = CreateStruct("");
SetStructBody(structType, types, false);
mAnonymousStructMap.TryAdd(key, structType);
return structType;
}
BePointerType* BeContext::GetPointerTo(BeType* beType)
{
if (beType->mPointerType == NULL)

View file

@ -226,14 +226,16 @@ public:
//BumpAllocator mAlloc;
BeType* mPrimitiveTypes[BeTypeCode_COUNT];
OwnedVector<BeType> mTypes;
Dictionary<Array<BeType*>, BeStructType*> mAnonymousStructMap;
public:
void NotImpl();
public:
BeContext();
BeType* GetPrimitiveType(BeTypeCode typeCode);
BeType* GetPrimitiveType(BeTypeCode typeCode);
BeStructType* CreateStruct(const StringImpl& name);
BeStructType* CreateStruct(const SizedArrayImpl<BeType*>& types);
BePointerType* GetPointerTo(BeType* beType);
void SetStructBody(BeStructType* structType, const SizedArrayImpl<BeType*>& types, bool packed);
BeSizedArrayType* CreateSizedArrayType(BeType* type, int length);

View file

@ -963,6 +963,13 @@ void BeIRCodeGen::HandleNextCmd()
SetResult(curId, mBeContext->CreateStruct(typeName));
}
break;
case BfIRCmd_CreateAnonymousStruct:
{
CMD_PARAM(CmdParamVec<BeType*>, members);
BeStructType* structType = mBeContext->CreateStruct(members);
SetResult(curId, structType);
}
break;
case BfIRCmd_StructSetBody:
{
CMD_PARAM(BeType*, type);
@ -2143,7 +2150,8 @@ void BeIRCodeGen::HandleNextCmd()
{
if (attribute == BfIRAttribute_StructRet)
{
BF_ASSERT(argIdx == 1);
auto valType = callInst->mArgs[argIdx - 1].mValue->GetType();
BF_ASSERT(valType->IsPointer());
callInst->mArgs[argIdx - 1].mStructRet = true;
}
else if (attribute == BfIRAttribute_ZExt)
@ -2152,6 +2160,9 @@ void BeIRCodeGen::HandleNextCmd()
callInst->mArgs[argIdx - 1].mNoAlias = true;
else if (attribute == BfIRAttribute_NoCapture)
callInst->mArgs[argIdx - 1].mNoCapture = true;
else if (attribute == BfIRAttribute_ByVal)
{
}
else
BF_FATAL("Unhandled");
}
@ -2177,7 +2188,21 @@ void BeIRCodeGen::HandleNextCmd()
if (argIdx > 0)
{
if (attribute == BfIRAttribute_Dereferencable)
{
callInst->mArgs[argIdx - 1].mDereferenceableSize = arg;
if (auto func = BeValueDynCast<BeFunction>(callInst->mFunc))
{
BF_ASSERT(func->mParams[argIdx - 1].mDereferenceableSize == arg);
}
}
else if (attribute == BfIRAttribute_ByVal)
{
callInst->mArgs[argIdx - 1].mByRefSize = arg;
if (auto func = BeValueDynCast<BeFunction>(callInst->mFunc))
{
BF_ASSERT(func->mParams[argIdx - 1].mByValSize == arg);
}
}
else
BF_FATAL("Unhandled");
}
@ -2242,6 +2267,8 @@ void BeIRCodeGen::HandleNextCmd()
{
if (attribute == BfIRAttribute_Dereferencable)
func->mParams[argIdx - 1].mDereferenceableSize = arg;
else if (attribute == BfIRAttribute_ByVal)
func->mParams[argIdx - 1].mByValSize = arg;
else
BF_FATAL("Unhandled");
}

View file

@ -532,6 +532,7 @@ void BeFunction::HashContent(BeHashContext& hashCtx)
hashCtx.Mixin(param.mStructRet);
hashCtx.Mixin(param.mZExt);
hashCtx.Mixin(param.mDereferenceableSize);
hashCtx.Mixin(param.mByValSize);
}
if (mDbgFunction != NULL)
mDbgFunction->HashReference(hashCtx);

View file

@ -410,6 +410,7 @@ public:
bool mNoCapture;
bool mZExt;
int mDereferenceableSize;
int mByValSize;
BeFunctionParam()
{
@ -418,6 +419,7 @@ public:
mNoCapture = false;
mZExt = false;
mDereferenceableSize = -1;
mByValSize = -1;
}
};
@ -1207,6 +1209,7 @@ public:
{
BeValue* mValue;
int mDereferenceableSize;
int mByRefSize;
bool mStructRet;
bool mZExt;
bool mNoAlias;
@ -1219,6 +1222,7 @@ public:
mNoAlias = false;
mNoCapture = false;
mDereferenceableSize = -1;
mByRefSize = -1;
}
};
@ -1254,6 +1258,8 @@ public:
arg.mValue->HashReference(hashCtx);
hashCtx.Mixin(arg.mStructRet);
hashCtx.Mixin(arg.mZExt);
hashCtx.Mixin(arg.mDereferenceableSize);
hashCtx.Mixin(arg.mByRefSize);
}
hashCtx.Mixin(mCallingConv);
hashCtx.Mixin(mNoReturn);