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

@ -151,9 +151,20 @@ int ChunkedDataBuffer::GetReadPos()
void ChunkedDataBuffer::SetReadPos(int pos)
{
mReadPoolIdx = pos / ALLOC_SIZE;
mReadCurAlloc = mPools[mReadPoolIdx];
mReadCurPtr = mReadCurAlloc + pos % ALLOC_SIZE;
mReadNextAlloc = mReadCurPtr + ALLOC_SIZE;
if (mReadPoolIdx < mPools.mSize)
{
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()

View file

@ -2088,7 +2088,7 @@ void CeBuilder::Build()
auto methodInstance = mCeFunction->mMethodInstance;
if (methodInstance != NULL)
if ((methodInstance != NULL) && (!mCeMachine->HasFailed()))
{
BfMethodInstance dupMethodInstance;
dupMethodInstance.CopyFrom(methodInstance);
@ -3607,6 +3607,18 @@ void CeBuilder::Build()
*((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)
{
Fail("No method definition available");
@ -5103,7 +5115,8 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
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()));
return irBuilder->CreateConstNull(irBuilder->MapType(bfType));
}
@ -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 appendAllocIdx = -1;
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()
{
BF_ASSERT(mCeModule == NULL);
@ -9650,6 +9680,7 @@ void CeMachine::CompileStarted()
mRevision++;
mMethodBindRevision++;
mDbgWantBreak = false;
mFailString.Clear();
if (mCeModule != NULL)
{
delete mCeModule;

View file

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