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

@ -2088,7 +2088,7 @@ void CeBuilder::Build()
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);
@ -3607,6 +3607,18 @@ void CeBuilder::Build()
*((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)
{ {
Fail("No method definition available"); Fail("No method definition available");
@ -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));
} }
@ -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,11 +1275,14 @@ 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 Fail(const StringImpl& error);
bool HasFailed();
void Init(); void Init();
BeContext* GetBeContext(); BeContext* GetBeContext();
BeModule* GetBeModule(); BeModule* GetBeModule();