mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Fixed append alloc issues, static init block fix
This commit is contained in:
parent
3b1f1634ac
commit
4a00830adf
3 changed files with 51 additions and 35 deletions
|
@ -792,7 +792,10 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef
|
|||
else if (typeRefName == "Inline")
|
||||
methodDef->mAlwaysInline = true;
|
||||
else if (typeRefName == "AllowAppend")
|
||||
{
|
||||
methodDef->mHasAppend = true;
|
||||
methodDef->mIsNoSplat = true;
|
||||
}
|
||||
else if (typeRefName == "Checked")
|
||||
methodDef->mCheckedKind = BfCheckedKind_Checked;
|
||||
else if (typeRefName == "Unchecked")
|
||||
|
@ -1866,6 +1869,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
|
|||
methodDef->mProtection = BfProtection_Public;
|
||||
methodDef->mMethodType = BfMethodType_CtorCalcAppend;
|
||||
methodDef->mIsMutating = method->mIsMutating;
|
||||
methodDef->mIsNoSplat = true;
|
||||
|
||||
methodDef->mMethodDeclaration = method->mMethodDeclaration;
|
||||
methodDef->mReturnTypeRef = mSystem->mDirectIntTypeRef;
|
||||
|
|
|
@ -411,6 +411,8 @@ public:
|
|||
|
||||
void EmitAppendAlign(int align, int sizeMultiple = 0)
|
||||
{
|
||||
BF_ASSERT(align > 0);
|
||||
|
||||
if (mIsFirstConstPass)
|
||||
mModule->mCurMethodInstance->mAppendAllocAlign = BF_MAX((int)mModule->mCurMethodInstance->mAppendAllocAlign, align);
|
||||
|
||||
|
@ -426,6 +428,8 @@ public:
|
|||
mCurAppendAlign = sizeMultiple % align;
|
||||
}
|
||||
|
||||
BF_ASSERT(mCurAppendAlign > 0);
|
||||
|
||||
if (mConstAccum)
|
||||
{
|
||||
auto constant = mModule->mBfIRBuilder->GetConstant(mConstAccum.mValue);
|
||||
|
@ -614,6 +618,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
mModule->PopulateType(resultType);
|
||||
|
||||
if (isRawArrayAlloc)
|
||||
{
|
||||
curAlign = resultType->mAlign;
|
||||
|
@ -13129,10 +13135,6 @@ void BfModule::SetupMethodIdHash(BfMethodInstance* methodInstance)
|
|||
}
|
||||
|
||||
methodInstance->mIdHash = (int64)hashCtx.Finish64();
|
||||
if (methodInstance->mIdHash == 0x3400000029LL)
|
||||
{
|
||||
NOP;
|
||||
}
|
||||
}
|
||||
|
||||
BfIRValue BfModule::GetInterfaceSlotNum(BfTypeInstance* ifaceType)
|
||||
|
@ -14730,7 +14732,7 @@ BfTypedValue BfModule::TryConstCalcAppend(BfMethodInstance* methodInst, SizedArr
|
|||
return BfTypedValue();
|
||||
|
||||
// Do we need to iterate in order to resolve mAppendAllocAlign?
|
||||
bool isFirstRun = methodInst->mAppendAllocAlign < 0;
|
||||
bool isFirstRun = methodInst->mEndingAppendAllocAlign < 0;
|
||||
bool wasAllConst = true;
|
||||
|
||||
int argIdx = 0;
|
||||
|
@ -15080,9 +15082,14 @@ void BfModule::CreateStaticCtor()
|
|||
continue;
|
||||
}
|
||||
GetFieldInitializerValue(fieldInst, NULL, NULL, NULL, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
auto _CheckInitBlock = [&](BfAstNode* node)
|
||||
{
|
||||
};
|
||||
|
||||
EmitInitBlocks(_CheckInitBlock);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -15565,11 +15572,6 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func
|
|||
if ((methodInstance->HasThis()) && (!methodDef->mHasExplicitThis))
|
||||
paramIdx = -1;
|
||||
|
||||
if (methodInstance->mMethodDef->mName == "Invoke@GetFFIType$wPb")
|
||||
{
|
||||
NOP;
|
||||
}
|
||||
|
||||
int argCount = methodInstance->GetIRFunctionParamCount(this);
|
||||
|
||||
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)
|
||||
{
|
||||
auto methodInstance = mCurMethodInstance;
|
||||
|
@ -16012,29 +16045,7 @@ void BfModule::EmitCtorBody(bool& skipBody)
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
initBodies.Insert(0, initMethodDef->mBody);
|
||||
}
|
||||
|
||||
for (auto body : initBodies)
|
||||
{
|
||||
_CheckInitBlock(body);
|
||||
VisitEmbeddedStatement(body);
|
||||
}
|
||||
EmitInitBlocks(_CheckInitBlock);
|
||||
|
||||
if (hadInlineInitBlock)
|
||||
{
|
||||
|
|
|
@ -1820,6 +1820,7 @@ public:
|
|||
void CreateDllImportMethod();
|
||||
BfIRCallingConv GetIRCallingConvention(BfMethodInstance* methodInstance);
|
||||
void SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined);
|
||||
void EmitInitBlocks(const std::function<void(BfAstNode*)>& initBlockCallback);
|
||||
void EmitCtorBody(bool& skipBody);
|
||||
void EmitDtorBody();
|
||||
void EmitEnumToStringBody();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue