Fix local variables with linker sections

This commit is contained in:
drmortalwombat 2021-09-21 08:41:49 +02:00
parent 27d7baaac2
commit d9c565d898
4 changed files with 32 additions and 19 deletions

View File

@ -647,7 +647,7 @@ const char* NativeCodeDisassembler::TempName(uint8 tmp, char* buffer, InterCodeP
else if (proc && tmp >= BC_REG_TMP && tmp < BC_REG_TMP + proc->mTempSize) else if (proc && tmp >= BC_REG_TMP && tmp < BC_REG_TMP + proc->mTempSize)
{ {
int i = 0; int i = 0;
while (i < proc->mTempOffset.Size() && tmp >= proc->mTempOffset[i] + BC_REG_TMP && tmp < proc->mTempOffset[i] + proc->mTempSizes[i] + BC_REG_TMP) while (i < proc->mTempOffset.Size() && !(tmp >= proc->mTempOffset[i] + BC_REG_TMP && tmp < proc->mTempOffset[i] + proc->mTempSizes[i] + BC_REG_TMP))
i++; i++;
if (i < proc->mTempOffset.Size()) if (i < proc->mTempOffset.Size())
sprintf_s(buffer, 10, "T%d + %d", i, tmp - (proc->mTempOffset[i] + BC_REG_TMP)); sprintf_s(buffer, 10, "T%d + %d", i, tmp - (proc->mTempOffset[i] + BC_REG_TMP));

View File

@ -453,7 +453,7 @@ bool Emulator::EmulateInstruction(AsmInsType type, AsmInsMode mode, int addr, in
int Emulator::Emulate(int startIP) int Emulator::Emulate(int startIP)
{ {
int trace = 3; int trace = 0;
for (int i = 0; i < 0x10000; i++) for (int i = 0; i < 0x10000; i++)
mCycles[i] = 0; mCycles[i] = 0;

View File

@ -3213,11 +3213,15 @@ void InterCodeBasicBlock::CollectVariables(GrowingVariableArray& globalVars, Gro
case IC_JSR: case IC_JSR:
if (mInstructions[i]->mMemory == IM_LOCAL) if (mInstructions[i]->mMemory == IM_LOCAL)
{ {
int varIndex = mInstructions[i]->mVarIndex;
if (!localVars[varIndex])
localVars[varIndex] = new InterVariable;
int size = mInstructions[i]->mOperandSize + mInstructions[i]->mIntValue; int size = mInstructions[i]->mOperandSize + mInstructions[i]->mIntValue;
if (size > localVars[mInstructions[i]->mVarIndex]->mSize) if (size > localVars[varIndex]->mSize)
localVars[mInstructions[i]->mVarIndex]->mSize = size; localVars[varIndex]->mSize = size;
if (mInstructions[i]->mCode == IC_CONSTANT) if (mInstructions[i]->mCode == IC_CONSTANT)
localVars[mInstructions[i]->mVarIndex]->mAliased = true; localVars[varIndex]->mAliased = true;
} }
break; break;
} }
@ -3785,7 +3789,7 @@ void InterCodeProcedure::MapVariables(void)
mLocalSize = 0; mLocalSize = 0;
for (int i = 0; i < mLocalVars.Size(); i++) for (int i = 0; i < mLocalVars.Size(); i++)
{ {
if (mLocalVars[i]->mUsed) if (mLocalVars[i] && mLocalVars[i]->mUsed)
{ {
mLocalVars[i]->mOffset = mLocalSize; mLocalVars[i]->mOffset = mLocalSize;
mLocalSize += mLocalVars[i]->mSize; mLocalSize += mLocalVars[i]->mSize;

View File

@ -3919,11 +3919,12 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void)
{ {
mIns[i].ValueForwarding(data); mIns[i].ValueForwarding(data);
} }
#if 1
if (mFalseJump) if (mFalseJump)
{ {
switch (mBranch) switch (mBranch)
{ {
#if 1
case ASMIT_BCS: case ASMIT_BCS:
if (data.mRegs[CPU_REG_C].mImmediate) if (data.mRegs[CPU_REG_C].mImmediate)
{ {
@ -3944,17 +3945,9 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void)
changed = true; changed = true;
} }
break; break;
#endif
#if 1
case ASMIT_BNE: case ASMIT_BNE:
if (data.mRegs[CPU_REG_Z].mImmediate)
{
mBranch = ASMIT_JMP;
if (data.mRegs[CPU_REG_Z].mValue)
mTrueJump = mFalseJump;
mFalseJump = nullptr;
changed = true;
}
break;
case ASMIT_BEQ:
if (data.mRegs[CPU_REG_Z].mImmediate) if (data.mRegs[CPU_REG_Z].mImmediate)
{ {
mBranch = ASMIT_JMP; mBranch = ASMIT_JMP;
@ -3964,11 +3957,22 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void)
changed = true; changed = true;
} }
break; break;
case ASMIT_BEQ:
if (data.mRegs[CPU_REG_Z].mImmediate)
{
mBranch = ASMIT_JMP;
if (data.mRegs[CPU_REG_Z].mValue)
mTrueJump = mFalseJump;
mFalseJump = nullptr;
changed = true;
}
break;
#endif
case ASMIT_BPL: case ASMIT_BPL:
if (data.mRegs[CPU_REG_Z].mImmediate) if (data.mRegs[CPU_REG_Z].mImmediate)
{ {
mBranch = ASMIT_JMP; mBranch = ASMIT_JMP;
if (!(data.mRegs[CPU_REG_Z].mValue & 0x80)) if ((data.mRegs[CPU_REG_Z].mValue & 0x80))
mTrueJump = mFalseJump; mTrueJump = mFalseJump;
mFalseJump = nullptr; mFalseJump = nullptr;
changed = true; changed = true;
@ -3978,7 +3982,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void)
if (data.mRegs[CPU_REG_Z].mImmediate) if (data.mRegs[CPU_REG_Z].mImmediate)
{ {
mBranch = ASMIT_JMP; mBranch = ASMIT_JMP;
if (data.mRegs[CPU_REG_Z].mValue & 0x80) if (!(data.mRegs[CPU_REG_Z].mValue & 0x80))
mTrueJump = mFalseJump; mTrueJump = mFalseJump;
mFalseJump = nullptr; mFalseJump = nullptr;
changed = true; changed = true;
@ -3986,7 +3990,9 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void)
break; break;
} }
} }
#endif
#if 1
// move load store pairs up to initial store // move load store pairs up to initial store
for (int i = 2; i + 2 < mIns.Size(); i++) for (int i = 2; i + 2 < mIns.Size(); i++)
@ -3997,6 +4003,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void)
changed = true; changed = true;
} }
} }
#endif
bool progress = false; bool progress = false;
do { do {
@ -4022,6 +4029,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void)
for (int i = 0; i < mIns.Size(); i++) for (int i = 0; i < mIns.Size(); i++)
{ {
#if 1
if (mIns[i].mType == ASMIT_AND && mIns[i].mMode == ASMIM_IMMEDIATE && mIns[i].mAddress == 0) if (mIns[i].mType == ASMIT_AND && mIns[i].mMode == ASMIM_IMMEDIATE && mIns[i].mAddress == 0)
{ {
mIns[i].mType = ASMIT_LDA; mIns[i].mType = ASMIT_LDA;
@ -4137,6 +4145,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void)
mIns[i + 2].mAddress = mIns[i + 0].mAddress; mIns[i + 2].mAddress = mIns[i + 0].mAddress;
} }
} }
#endif
} }
if (progress) if (progress)