From 0816a57032ef4db0d3fc2a92d1b09cc8e1fc7d8f Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 30 Jul 2023 14:50:02 +0200 Subject: [PATCH] never add rts to inline asmsubs and always inline them regardless of optimization setting otherwise they can't specify a sequence of assembly instructions that should be inserted in-place, such as those that manipulate the cpu stack. for instance cx16.irqsafe_set_irqd() / cx16.irqsafe_clear_irqd() --- .../src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt | 4 ++-- codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt | 4 +--- .../src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt | 2 +- docs/source/todo.rst | 2 -- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt index 39e0191b3..1051b6497 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt @@ -63,8 +63,8 @@ internal class FunctionCallAsmGen(private val program: PtProgram, private val as if(sub is PtAsmSub) { argumentsViaRegisters(sub, call) - if (sub.inline && asmgen.options.optimize) { - // inline the subroutine. + if (sub.inline) { + // inline the subroutine. (regardless of optimization settings!) // we do this by copying the subroutine's statements at the call site. // NOTE: *if* there is a return statement, it will be the only one, and the very last statement of the subroutine // (this condition has been enforced by an ast check earlier) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt index 812aec809..aa9d38028 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt @@ -271,9 +271,7 @@ internal class ProgramAndVarsGen( internal fun translateAsmSubroutine(sub: PtAsmSub) { if(sub.inline) { - if(options.optimize) { - return - } + return // subroutine gets inlined at call site. } asmgen.out("") diff --git a/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt b/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt index e2a06d0d3..e4344ebe4 100644 --- a/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt +++ b/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt @@ -150,7 +150,7 @@ internal class BeforeAsmAstChanger(val program: Program, } } - if (!subroutine.inline || !options.optimize) { + if (!subroutine.inline) { if (subroutine.isAsmSubroutine && subroutine.asmAddress==null && !subroutine.hasRtsInAsm()) { // make sure the NOT INLINED asm subroutine actually has a rts at the end // (non-asm routines get a Return statement as needed, above) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index fff5915f8..e38dc43c6 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,8 +1,6 @@ TODO ==== -- compiling Rockrunner with -noopt crashes the program soon after startup - - IR: reduce the number of branch instructions such as BEQ, BEQR, etc (gradually), replace with CMP(I) + status branch instruction - IR: reduce amount of CMP/CMPI after instructions that set the status bits correctly (LOADs? INC? etc), but only after setting the status bits is verified!