From d9c565d89895f6fab6a399f9f9dc2a43c2b640f3 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Tue, 21 Sep 2021 08:41:49 +0200 Subject: [PATCH] Fix local variables with linker sections --- oscar64/Disassembler.cpp | 2 +- oscar64/Emulator.cpp | 2 +- oscar64/InterCode.cpp | 12 +++++++---- oscar64/NativeCodeGenerator.cpp | 35 +++++++++++++++++++++------------ 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/oscar64/Disassembler.cpp b/oscar64/Disassembler.cpp index 85849d6..4092ac7 100644 --- a/oscar64/Disassembler.cpp +++ b/oscar64/Disassembler.cpp @@ -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) { 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++; if (i < proc->mTempOffset.Size()) sprintf_s(buffer, 10, "T%d + %d", i, tmp - (proc->mTempOffset[i] + BC_REG_TMP)); diff --git a/oscar64/Emulator.cpp b/oscar64/Emulator.cpp index d10d7d4..0c6def0 100644 --- a/oscar64/Emulator.cpp +++ b/oscar64/Emulator.cpp @@ -453,7 +453,7 @@ bool Emulator::EmulateInstruction(AsmInsType type, AsmInsMode mode, int addr, in int Emulator::Emulate(int startIP) { - int trace = 3; + int trace = 0; for (int i = 0; i < 0x10000; i++) mCycles[i] = 0; diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 2fdd18c..15d12e7 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -3213,11 +3213,15 @@ void InterCodeBasicBlock::CollectVariables(GrowingVariableArray& globalVars, Gro case IC_JSR: 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; - if (size > localVars[mInstructions[i]->mVarIndex]->mSize) - localVars[mInstructions[i]->mVarIndex]->mSize = size; + if (size > localVars[varIndex]->mSize) + localVars[varIndex]->mSize = size; if (mInstructions[i]->mCode == IC_CONSTANT) - localVars[mInstructions[i]->mVarIndex]->mAliased = true; + localVars[varIndex]->mAliased = true; } break; } @@ -3785,7 +3789,7 @@ void InterCodeProcedure::MapVariables(void) mLocalSize = 0; for (int i = 0; i < mLocalVars.Size(); i++) { - if (mLocalVars[i]->mUsed) + if (mLocalVars[i] && mLocalVars[i]->mUsed) { mLocalVars[i]->mOffset = mLocalSize; mLocalSize += mLocalVars[i]->mSize; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index a476b10..637a4d2 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -3919,11 +3919,12 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) { mIns[i].ValueForwarding(data); } - +#if 1 if (mFalseJump) { switch (mBranch) { +#if 1 case ASMIT_BCS: if (data.mRegs[CPU_REG_C].mImmediate) { @@ -3944,17 +3945,9 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) changed = true; } break; +#endif +#if 1 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) { mBranch = ASMIT_JMP; @@ -3964,11 +3957,22 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) changed = true; } 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: if (data.mRegs[CPU_REG_Z].mImmediate) { mBranch = ASMIT_JMP; - if (!(data.mRegs[CPU_REG_Z].mValue & 0x80)) + if ((data.mRegs[CPU_REG_Z].mValue & 0x80)) mTrueJump = mFalseJump; mFalseJump = nullptr; changed = true; @@ -3978,7 +3982,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) if (data.mRegs[CPU_REG_Z].mImmediate) { mBranch = ASMIT_JMP; - if (data.mRegs[CPU_REG_Z].mValue & 0x80) + if (!(data.mRegs[CPU_REG_Z].mValue & 0x80)) mTrueJump = mFalseJump; mFalseJump = nullptr; changed = true; @@ -3986,7 +3990,9 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) break; } } +#endif +#if 1 // move load store pairs up to initial store for (int i = 2; i + 2 < mIns.Size(); i++) @@ -3997,6 +4003,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) changed = true; } } +#endif bool progress = false; do { @@ -4022,6 +4029,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) 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) { mIns[i].mType = ASMIT_LDA; @@ -4137,6 +4145,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(void) mIns[i + 2].mAddress = mIns[i + 0].mAddress; } } +#endif } if (progress)