mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Fixed switch with constant value and fallthroughs
This commit is contained in:
parent
e1119d77a9
commit
d4d74ed37c
2 changed files with 32 additions and 16 deletions
|
@ -3744,7 +3744,7 @@ BeMCOperand BeMCContext::AllocVirtualReg(BeType* type, int refCount, bool mustBe
|
|||
|
||||
if (mDebugging)
|
||||
{
|
||||
if (mcOperand.mVRegIdx == 14)
|
||||
if (mcOperand.mVRegIdx == 6)
|
||||
{
|
||||
NOP;
|
||||
}
|
||||
|
@ -8610,6 +8610,17 @@ void BeMCContext::DoActualization()
|
|||
BF_ASSERT((!vregInfo->IsDirectRelTo()) || (vregInfo->mDbgVariable != NULL));
|
||||
|
||||
if (vregInfo->mIsExpr)
|
||||
{
|
||||
if (vregInfo->IsDirectRelToAny())
|
||||
{
|
||||
AllocInst(BeMCInstKind_Mov, BeMCOperand::FromVReg(vregIdx), vregInfo->mRelTo, instIdx++ + 1);
|
||||
|
||||
vregInfo->mIsExpr = false;
|
||||
vregInfo->mRelTo = BeMCOperand();
|
||||
vregInfo->mRelOffset = BeMCOperand();
|
||||
vregInfo->mRelOffsetScale = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a new reg with the expression, and then load the value into the old non-expressionized reg
|
||||
// This has the advantage of fixing any other references to this expr, too
|
||||
|
@ -8633,6 +8644,7 @@ void BeMCContext::DoActualization()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasMoreWork)
|
||||
break;
|
||||
|
|
|
@ -4311,6 +4311,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
|||
|
||||
auto startingLocalVarId = mCurMethodState->GetRootMethodState()->mCurLocalVarId;
|
||||
|
||||
bool prevHadFallthrough = false;
|
||||
|
||||
Dictionary<int64, _CaseState> handledCases;
|
||||
for (BfSwitchCase* switchCase : switchStmt->mSwitchCases)
|
||||
{
|
||||
|
@ -4596,7 +4598,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
|||
|
||||
auto prevInsertBlock = mBfIRBuilder->GetInsertBlock();
|
||||
|
||||
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true, !mayHaveMatch);
|
||||
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true, !mayHaveMatch && !prevHadFallthrough);
|
||||
|
||||
mBfIRBuilder->AddBlock(caseBlock);
|
||||
mBfIRBuilder->SetInsertPoint(caseBlock);
|
||||
|
@ -4678,6 +4680,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
|||
|
||||
mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
||||
|
||||
prevHadFallthrough = mCurMethodState->mDeferredLocalAssignData->mHadFallthrough;
|
||||
|
||||
blockIdx++;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue