mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Fixed append alignment with unaligned stomp allocator
This commit is contained in:
parent
ce64d43b6a
commit
b2b964489e
3 changed files with 18 additions and 13 deletions
|
@ -5,13 +5,13 @@ namespace System
|
||||||
{
|
{
|
||||||
interface IRawAllocator
|
interface IRawAllocator
|
||||||
{
|
{
|
||||||
void* Alloc(int size, int align);
|
void* Alloc(int size, int align) mut;
|
||||||
void Free(void* ptr);
|
void Free(void* ptr) mut;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ITypedAllocator : IRawAllocator
|
interface ITypedAllocator : IRawAllocator
|
||||||
{
|
{
|
||||||
void* AllocTyped(Type type, int size, int align);
|
void* AllocTyped(Type type, int size, int align) mut;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StdAllocator : IRawAllocator
|
struct StdAllocator : IRawAllocator
|
||||||
|
|
|
@ -9094,6 +9094,13 @@ void BfModule::InitTypeInst(BfTypedValue typedValue, BfScopeData* scopeData, boo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BfModule::IsAllocatorAligned()
|
||||||
|
{
|
||||||
|
if (mCompiler->mOptions.mMallocLinkName == "StompAlloc")
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
BfIRValue BfModule::AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTarget, BfType* type, BfIRValue sizeValue, BfIRValue alignValue, BfAllocFlags allocFlags/*, bool zeroMemory, bool defaultToMalloc*/)
|
BfIRValue BfModule::AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTarget, BfType* type, BfIRValue sizeValue, BfIRValue alignValue, BfAllocFlags allocFlags/*, bool zeroMemory, bool defaultToMalloc*/)
|
||||||
{
|
{
|
||||||
BfIRValue result;
|
BfIRValue result;
|
||||||
|
@ -10010,19 +10017,17 @@ void BfModule::ValidateAllocation(BfType* type, BfAstNode* refNode)
|
||||||
Fail(StrFormat("Unable to allocate opaque type '%s'", TypeToString(type).c_str()), refNode);
|
Fail(StrFormat("Unable to allocate opaque type '%s'", TypeToString(type).c_str()), refNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfModule::EmitAlign(BfIRValue& appendCurIdx, int align)
|
|
||||||
{
|
|
||||||
appendCurIdx = mBfIRBuilder->CreateAdd(appendCurIdx, GetConstValue(align - 1));
|
|
||||||
appendCurIdx = mBfIRBuilder->CreateAnd(appendCurIdx, GetConstValue(~(align - 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void BfModule::EmitAppendAlign(int align, int sizeMultiple)
|
void BfModule::EmitAppendAlign(int align, int sizeMultiple)
|
||||||
{
|
{
|
||||||
if (sizeMultiple == 0)
|
if (sizeMultiple == 0)
|
||||||
sizeMultiple = align;
|
sizeMultiple = align;
|
||||||
if ((mCurMethodState->mCurAppendAlign != 0) && (mCurMethodState->mCurAppendAlign % align != 0))
|
if ((mCurMethodState->mCurAppendAlign != 0) && (mCurMethodState->mCurAppendAlign % align != 0))
|
||||||
{
|
{
|
||||||
if (mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor)
|
if (!IsAllocatorAligned())
|
||||||
|
{
|
||||||
|
// Don't align
|
||||||
|
}
|
||||||
|
else if (mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor)
|
||||||
{
|
{
|
||||||
auto localVar = mCurMethodState->GetRootMethodState()->mLocals[1];
|
auto localVar = mCurMethodState->GetRootMethodState()->mLocals[1];
|
||||||
BF_ASSERT(localVar->mName == "appendIdx");
|
BF_ASSERT(localVar->mName == "appendIdx");
|
||||||
|
|
|
@ -1707,13 +1707,13 @@ public:
|
||||||
void AssertErrorState();
|
void AssertErrorState();
|
||||||
void AssertParseErrorState();
|
void AssertParseErrorState();
|
||||||
void InitTypeInst(BfTypedValue typedValue, BfScopeData* scope, bool zeroMemory, BfIRValue dataSize);
|
void InitTypeInst(BfTypedValue typedValue, BfScopeData* scope, bool zeroMemory, BfIRValue dataSize);
|
||||||
|
bool IsAllocatorAligned();
|
||||||
BfIRValue AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTarget, BfType* type, BfIRValue sizeValue, BfIRValue alignValue, BfAllocFlags allocFlags/*bool zeroMemory, bool defaultToMalloc*/);
|
BfIRValue AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTarget, BfType* type, BfIRValue sizeValue, BfIRValue alignValue, BfAllocFlags allocFlags/*bool zeroMemory, bool defaultToMalloc*/);
|
||||||
BfIRValue GetMarkFuncPtr(BfType* type);
|
BfIRValue GetMarkFuncPtr(BfType* type);
|
||||||
BfIRValue GetDbgRawAllocData(BfType* type);
|
BfIRValue GetDbgRawAllocData(BfType* type);
|
||||||
BfIRValue AllocFromType(BfType* type, const BfAllocTarget& allocTarget, BfIRValue appendSizeValue = BfIRValue(), BfIRValue arraySize = BfIRValue(), int arrayDim = 0, /*bool isRawArrayAlloc = false, bool zeroMemory = true*/BfAllocFlags allocFlags = BfAllocFlags_ZeroMemory, int alignOverride = -1);
|
BfIRValue AllocFromType(BfType* type, const BfAllocTarget& allocTarget, BfIRValue appendSizeValue = BfIRValue(), BfIRValue arraySize = BfIRValue(), int arrayDim = 0, /*bool isRawArrayAlloc = false, bool zeroMemory = true*/BfAllocFlags allocFlags = BfAllocFlags_ZeroMemory, int alignOverride = -1);
|
||||||
void ValidateAllocation(BfType* type, BfAstNode* refNode);
|
void ValidateAllocation(BfType* type, BfAstNode* refNode);
|
||||||
bool IsOptimized();
|
bool IsOptimized();
|
||||||
void EmitAlign(BfIRValue& appendCurIdx, int align);
|
|
||||||
void EmitAppendAlign(int align, int sizeMultiple = 0);
|
void EmitAppendAlign(int align, int sizeMultiple = 0);
|
||||||
BfIRValue AppendAllocFromType(BfType* type, BfIRValue appendSizeValue = BfIRValue(), int appendAllocAlign = 0, BfIRValue arraySize = BfIRValue(), int arrayDim = 0, bool isRawArrayAlloc = false, bool zeroMemory = true);
|
BfIRValue AppendAllocFromType(BfType* type, BfIRValue appendSizeValue = BfIRValue(), int appendAllocAlign = 0, BfIRValue arraySize = BfIRValue(), int arrayDim = 0, bool isRawArrayAlloc = false, bool zeroMemory = true);
|
||||||
bool IsTargetingBeefBackend();
|
bool IsTargetingBeefBackend();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue