Handle case where block with fixed end branch is not taken.

This commit is contained in:
Jean-Philip Desjardins 2017-04-14 19:16:55 -04:00
parent 6d9a9b469e
commit 25e817802a

View file

@ -181,6 +181,7 @@ void CBasicBlock::Compile()
void CBasicBlock::CompileRange(CMipsJitter* jitter)
{
uint32 fixedEnd = m_end;
bool needsPcAdjust = false;
//Update block end because MipsAnalysis might not include an instruction
//in a delay slot when cutting a function into basic blocks
@ -190,6 +191,7 @@ void CBasicBlock::CompileRange(CMipsJitter* jitter)
if(branchType == MIPS_BRANCH_NORMAL)
{
fixedEnd += 4;
needsPcAdjust = true;
}
}
@ -202,6 +204,20 @@ void CBasicBlock::CompileRange(CMipsJitter* jitter)
//Sanity check
assert(jitter->IsStackEmpty());
}
//Adjust PC to make sure we don't execute the delay slot at the next block
if(needsPcAdjust)
{
jitter->PushCst(MIPS_INVALID_PC);
jitter->PushRel(offsetof(CMIPS, m_State.nDelayedJumpAddr));
jitter->BeginIf(Jitter::CONDITION_EQ);
{
jitter->PushCst(fixedEnd + 4);
jitter->PullRel(offsetof(CMIPS, m_State.nDelayedJumpAddr));
}
jitter->EndIf();
}
}
unsigned int CBasicBlock::Execute()