1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fixed append alloc issues, static init block fix

This commit is contained in:
Brian Fiete 2020-12-26 11:41:31 -08:00
parent 3b1f1634ac
commit 4a00830adf
3 changed files with 51 additions and 35 deletions

View file

@ -792,7 +792,10 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef
else if (typeRefName == "Inline") else if (typeRefName == "Inline")
methodDef->mAlwaysInline = true; methodDef->mAlwaysInline = true;
else if (typeRefName == "AllowAppend") else if (typeRefName == "AllowAppend")
{
methodDef->mHasAppend = true; methodDef->mHasAppend = true;
methodDef->mIsNoSplat = true;
}
else if (typeRefName == "Checked") else if (typeRefName == "Checked")
methodDef->mCheckedKind = BfCheckedKind_Checked; methodDef->mCheckedKind = BfCheckedKind_Checked;
else if (typeRefName == "Unchecked") else if (typeRefName == "Unchecked")
@ -1866,6 +1869,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
methodDef->mProtection = BfProtection_Public; methodDef->mProtection = BfProtection_Public;
methodDef->mMethodType = BfMethodType_CtorCalcAppend; methodDef->mMethodType = BfMethodType_CtorCalcAppend;
methodDef->mIsMutating = method->mIsMutating; methodDef->mIsMutating = method->mIsMutating;
methodDef->mIsNoSplat = true;
methodDef->mMethodDeclaration = method->mMethodDeclaration; methodDef->mMethodDeclaration = method->mMethodDeclaration;
methodDef->mReturnTypeRef = mSystem->mDirectIntTypeRef; methodDef->mReturnTypeRef = mSystem->mDirectIntTypeRef;

View file

@ -411,6 +411,8 @@ public:
void EmitAppendAlign(int align, int sizeMultiple = 0) void EmitAppendAlign(int align, int sizeMultiple = 0)
{ {
BF_ASSERT(align > 0);
if (mIsFirstConstPass) if (mIsFirstConstPass)
mModule->mCurMethodInstance->mAppendAllocAlign = BF_MAX((int)mModule->mCurMethodInstance->mAppendAllocAlign, align); mModule->mCurMethodInstance->mAppendAllocAlign = BF_MAX((int)mModule->mCurMethodInstance->mAppendAllocAlign, align);
@ -426,6 +428,8 @@ public:
mCurAppendAlign = sizeMultiple % align; mCurAppendAlign = sizeMultiple % align;
} }
BF_ASSERT(mCurAppendAlign > 0);
if (mConstAccum) if (mConstAccum)
{ {
auto constant = mModule->mBfIRBuilder->GetConstant(mConstAccum.mValue); auto constant = mModule->mBfIRBuilder->GetConstant(mConstAccum.mValue);
@ -614,6 +618,8 @@ public:
} }
} }
mModule->PopulateType(resultType);
if (isRawArrayAlloc) if (isRawArrayAlloc)
{ {
curAlign = resultType->mAlign; curAlign = resultType->mAlign;
@ -13129,10 +13135,6 @@ void BfModule::SetupMethodIdHash(BfMethodInstance* methodInstance)
} }
methodInstance->mIdHash = (int64)hashCtx.Finish64(); methodInstance->mIdHash = (int64)hashCtx.Finish64();
if (methodInstance->mIdHash == 0x3400000029LL)
{
NOP;
}
} }
BfIRValue BfModule::GetInterfaceSlotNum(BfTypeInstance* ifaceType) BfIRValue BfModule::GetInterfaceSlotNum(BfTypeInstance* ifaceType)
@ -14730,7 +14732,7 @@ BfTypedValue BfModule::TryConstCalcAppend(BfMethodInstance* methodInst, SizedArr
return BfTypedValue(); return BfTypedValue();
// Do we need to iterate in order to resolve mAppendAllocAlign? // Do we need to iterate in order to resolve mAppendAllocAlign?
bool isFirstRun = methodInst->mAppendAllocAlign < 0; bool isFirstRun = methodInst->mEndingAppendAllocAlign < 0;
bool wasAllConst = true; bool wasAllConst = true;
int argIdx = 0; int argIdx = 0;
@ -15079,10 +15081,15 @@ void BfModule::CreateStaticCtor()
{ {
continue; continue;
} }
GetFieldInitializerValue(fieldInst, NULL, NULL, NULL, true); GetFieldInitializerValue(fieldInst, NULL, NULL, NULL, true);
} }
} }
auto _CheckInitBlock = [&](BfAstNode* node)
{
};
EmitInitBlocks(_CheckInitBlock);
} }
else else
{ {
@ -15565,11 +15572,6 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func
if ((methodInstance->HasThis()) && (!methodDef->mHasExplicitThis)) if ((methodInstance->HasThis()) && (!methodDef->mHasExplicitThis))
paramIdx = -1; paramIdx = -1;
if (methodInstance->mMethodDef->mName == "Invoke@GetFFIType$wPb")
{
NOP;
}
int argCount = methodInstance->GetIRFunctionParamCount(this); int argCount = methodInstance->GetIRFunctionParamCount(this);
while (argIdx < argCount) while (argIdx < argCount)
@ -15753,6 +15755,37 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func
} }
} }
void BfModule::EmitInitBlocks(const std::function<void(BfAstNode*)>& initBlockCallback)
{
auto methodDef = mCurMethodInstance->mMethodDef;
mCurTypeInstance->mTypeDef->PopulateMemberSets();
BfMemberSetEntry* entry = NULL;
BfMethodDef* initMethodDef = NULL;
mCurTypeInstance->mTypeDef->mMethodSet.TryGetWith(String("__BfInit"), &entry);
if (entry != NULL)
initMethodDef = (BfMethodDef*)entry->mMemberDef;
SizedArray<BfAstNode*, 8> initBodies;
for (; initMethodDef != NULL; initMethodDef = initMethodDef->mNextWithSameName)
{
if (initMethodDef->mDeclaringType != methodDef->mDeclaringType)
continue;
if (initMethodDef->mMethodType != BfMethodType_Init)
continue;
if (initMethodDef->mIsStatic != methodDef->mIsStatic)
continue;
initBodies.Insert(0, initMethodDef->mBody);
}
for (auto body : initBodies)
{
initBlockCallback(body);
VisitEmbeddedStatement(body);
}
}
void BfModule::EmitCtorBody(bool& skipBody) void BfModule::EmitCtorBody(bool& skipBody)
{ {
auto methodInstance = mCurMethodInstance; auto methodInstance = mCurMethodInstance;
@ -16012,29 +16045,7 @@ void BfModule::EmitCtorBody(bool& skipBody)
} }
} }
mCurTypeInstance->mTypeDef->PopulateMemberSets(); EmitInitBlocks(_CheckInitBlock);
BfMemberSetEntry* entry = NULL;
BfMethodDef* initMethodDef = NULL;
mCurTypeInstance->mTypeDef->mMethodSet.TryGetWith(String("__BfInit"), &entry);
if (entry != NULL)
initMethodDef = (BfMethodDef*)entry->mMemberDef;
SizedArray<BfAstNode*, 8> initBodies;
for (; initMethodDef != NULL; initMethodDef = initMethodDef->mNextWithSameName)
{
if (initMethodDef->mDeclaringType != methodDef->mDeclaringType)
continue;
if (initMethodDef->mMethodType != BfMethodType_Init)
continue;
initBodies.Insert(0, initMethodDef->mBody);
}
for (auto body : initBodies)
{
_CheckInitBlock(body);
VisitEmbeddedStatement(body);
}
if (hadInlineInitBlock) if (hadInlineInitBlock)
{ {

View file

@ -1820,6 +1820,7 @@ public:
void CreateDllImportMethod(); void CreateDllImportMethod();
BfIRCallingConv GetIRCallingConvention(BfMethodInstance* methodInstance); BfIRCallingConv GetIRCallingConvention(BfMethodInstance* methodInstance);
void SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined); void SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined);
void EmitInitBlocks(const std::function<void(BfAstNode*)>& initBlockCallback);
void EmitCtorBody(bool& skipBody); void EmitCtorBody(bool& skipBody);
void EmitDtorBody(); void EmitDtorBody();
void EmitEnumToStringBody(); void EmitEnumToStringBody();