1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-07 19:18:19 +02:00

Improved ce handling of failed irCodeGen, const null ptr handling

This commit is contained in:
Brian Fiete 2025-05-27 11:52:34 +02:00
parent 2f66bcafcc
commit e82f9ce3ee
3 changed files with 57 additions and 12 deletions

View file

@ -149,11 +149,22 @@ int ChunkedDataBuffer::GetReadPos()
} }
void ChunkedDataBuffer::SetReadPos(int pos) void ChunkedDataBuffer::SetReadPos(int pos)
{ {
mReadPoolIdx = pos / ALLOC_SIZE; mReadPoolIdx = pos / ALLOC_SIZE;
mReadCurAlloc = mPools[mReadPoolIdx]; if (mReadPoolIdx < mPools.mSize)
mReadCurPtr = mReadCurAlloc + pos % ALLOC_SIZE; {
mReadNextAlloc = mReadCurPtr + ALLOC_SIZE; mReadCurAlloc = mPools[mReadPoolIdx];
mReadCurPtr = mReadCurAlloc + pos % ALLOC_SIZE;
mReadNextAlloc = mReadCurPtr + ALLOC_SIZE;
}
else
{
// Place at end of last pool
mReadPoolIdx = mPools.mSize - 1;
mReadCurAlloc = mPools[mReadPoolIdx];
mReadCurPtr = mReadCurAlloc + ALLOC_SIZE;
mReadNextAlloc = mReadCurPtr;
}
} }
void ChunkedDataBuffer::NextReadPool() void ChunkedDataBuffer::NextReadPool()

View file

@ -2079,16 +2079,16 @@ void CeBuilder::Build()
SetAndRestoreValue<CeDbgState*> prevDbgState; SetAndRestoreValue<CeDbgState*> prevDbgState;
if (mCeMachine->mDebugger != NULL) if (mCeMachine->mDebugger != NULL)
prevDbgState.Init(mCeMachine->mDebugger->mCurDbgState, NULL); prevDbgState.Init(mCeMachine->mDebugger->mCurDbgState, NULL);
auto irCodeGen = mCeMachine->mCeModule->mBfIRBuilder->mBeIRCodeGen; auto irCodeGen = mCeMachine->mCeModule->mBfIRBuilder->mBeIRCodeGen;
auto irBuilder = mCeMachine->mCeModule->mBfIRBuilder; auto irBuilder = mCeMachine->mCeModule->mBfIRBuilder;
auto beModule = irCodeGen->mBeModule; auto beModule = irCodeGen->mBeModule;
mCeFunction->mFailed = true; mCeFunction->mFailed = true;
auto methodInstance = mCeFunction->mMethodInstance; auto methodInstance = mCeFunction->mMethodInstance;
if (methodInstance != NULL) if ((methodInstance != NULL) && (!mCeMachine->HasFailed()))
{ {
BfMethodInstance dupMethodInstance; BfMethodInstance dupMethodInstance;
dupMethodInstance.CopyFrom(methodInstance); dupMethodInstance.CopyFrom(methodInstance);
@ -3605,6 +3605,18 @@ void CeBuilder::Build()
{ {
auto& ceBlock = mBlocks[jumpEntry.mBlockIdx]; auto& ceBlock = mBlocks[jumpEntry.mBlockIdx];
*((int32*)(&mCeFunction->mCode[0] + jumpEntry.mEmitPos)) = ceBlock.mEmitOfs - jumpEntry.mEmitPos - 4; *((int32*)(&mCeFunction->mCode[0] + jumpEntry.mEmitPos)) = ceBlock.mEmitOfs - jumpEntry.mEmitPos - 4;
}
if (irCodeGen->mFailed)
{
mCeMachine->Fail(StrFormat("IRCodeGen Failed: %s", irCodeGen->mErrorMsg.c_str()));
irCodeGen->mFailed = false;
}
if (mCeMachine->HasFailed())
{
Fail("ConstEval machine failed");
return;
} }
if (mCeFunction->mCode.size() == 0) if (mCeFunction->mCode.size() == 0)
@ -3616,7 +3628,7 @@ void CeBuilder::Build()
if (mCeFunction->mGenError.IsEmpty()) if (mCeFunction->mGenError.IsEmpty())
mCeFunction->mFailed = false; mCeFunction->mFailed = false;
mCeFunction->mFrameSize = mFrameSize; mCeFunction->mFrameSize = mFrameSize;
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -5103,7 +5115,8 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
if (bfType->IsPointer()) if (bfType->IsPointer())
{ {
if ((mCurEvalFlags & CeEvalFlags_IgnoreConstEncodeFailure) == 0) addr_ce addr = *(addr_ce*)(ptr);
if ((addr != 0) && ((mCurEvalFlags & CeEvalFlags_IgnoreConstEncodeFailure) == 0))
Fail(StrFormat("Pointer type '%s' return value not allowed", module->TypeToString(bfType).c_str())); Fail(StrFormat("Pointer type '%s' return value not allowed", module->TypeToString(bfType).c_str()));
return irBuilder->CreateConstNull(irBuilder->MapType(bfType)); return irBuilder->CreateConstNull(irBuilder->MapType(bfType));
} }
@ -5209,7 +5222,7 @@ BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfI
} }
BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray<BfIRValue>& args, CeEvalFlags flags, BfType* expectingType) BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray<BfIRValue>& args, CeEvalFlags flags, BfType* expectingType)
{ {
// DISABLED // DISABLED
//return BfTypedValue(); //return BfTypedValue();
@ -5275,6 +5288,12 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod
} }
} }
if (mCeMachine->HasFailed())
{
Fail("ConstEval machine failed");
return BfTypedValue();
}
int thisArgIdx = -1; int thisArgIdx = -1;
int appendAllocIdx = -1; int appendAllocIdx = -1;
bool hasAggData = false; bool hasAggData = false;
@ -9604,6 +9623,17 @@ CeMachine::~CeMachine()
} }
} }
void CeMachine::Fail(const StringImpl& error)
{
if (mFailString.IsEmpty())
mFailString = error;
}
bool CeMachine::HasFailed()
{
return !mFailString.IsEmpty();
}
void CeMachine::Init() void CeMachine::Init()
{ {
BF_ASSERT(mCeModule == NULL); BF_ASSERT(mCeModule == NULL);
@ -9650,6 +9680,7 @@ void CeMachine::CompileStarted()
mRevision++; mRevision++;
mMethodBindRevision++; mMethodBindRevision++;
mDbgWantBreak = false; mDbgWantBreak = false;
mFailString.Clear();
if (mCeModule != NULL) if (mCeModule != NULL)
{ {
delete mCeModule; delete mCeModule;

View file

@ -1275,12 +1275,15 @@ public:
bool mDbgPaused; bool mDbgPaused;
bool mSpecialCheck; bool mSpecialCheck;
bool mDbgWantBreak; bool mDbgWantBreak;
String mFailString;
public: public:
CeMachine(BfCompiler* compiler); CeMachine(BfCompiler* compiler);
~CeMachine(); ~CeMachine();
void Init(); void Fail(const StringImpl& error);
bool HasFailed();
void Init();
BeContext* GetBeContext(); BeContext* GetBeContext();
BeModule* GetBeModule(); BeModule* GetBeModule();