1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-28 11:51:09 +00:00

replace jmp to rts with rts in double jump elimination pass

This commit is contained in:
Travis Fisher 2019-04-01 18:14:18 -04:00
parent 0fa2ec584e
commit 7784f174b7

View File

@ -40,9 +40,13 @@ public class Pass5DoubleJumpElimination extends Pass5AsmOptimization {
if(currentLabel != null) {
AsmInstruction asmInstruction = (AsmInstruction) line;
AsmInstructionType jmpType = AsmInstructionSet.getInstructionType("jmp", AsmAddressingMode.ABS, false);
AsmInstructionType rtsType = AsmInstructionSet.getInstructionType("rts", AsmAddressingMode.NON, false);
if(asmInstruction.getType().equals(jmpType)) {
immediateJumps.put(currentScope + "::" + currentLabel, asmInstruction.getParameter());
}
if(asmInstruction.getType().equals(rtsType)) {
immediateJumps.put(currentScope + "::" + currentLabel, "rts");
}
}
currentLabel = null;
} else {
@ -62,7 +66,12 @@ public class Pass5DoubleJumpElimination extends Pass5AsmOptimization {
AsmInstruction asmInstruction = (AsmInstruction) line;
if(asmInstruction.getType().isJump()) {
String immediateJmpTarget = immediateJumps.get(currentScope + "::" + asmInstruction.getParameter());
if(immediateJmpTarget != null && !immediateJmpTarget.equals(asmInstruction.getParameter())) {
if (immediateJmpTarget == "rts" && asmInstruction.getType().getMnemnonic()=="jmp") {
getLog().append("Replacing jump to rts with rts in " + asmInstruction.toString());
AsmInstructionType rtsType = AsmInstructionSet.getInstructionType("rts", AsmAddressingMode.NON, false);
asmInstruction.setType(rtsType);
optimized = true;
} else if(immediateJmpTarget != null && immediateJmpTarget != "rts" && !immediateJmpTarget.equals(asmInstruction.getParameter())) {
getLog().append("Skipping double jump to " + immediateJmpTarget + " in " + asmInstruction.toString());
asmInstruction.setParameter(immediateJmpTarget);
optimized = true;