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()
This commit is contained in:
Irmen de Jong 2023-07-30 14:50:02 +02:00
parent b89ad4b328
commit 0816a57032
4 changed files with 4 additions and 8 deletions

View File

@ -63,8 +63,8 @@ internal class FunctionCallAsmGen(private val program: PtProgram, private val as
if(sub is PtAsmSub) { if(sub is PtAsmSub) {
argumentsViaRegisters(sub, call) argumentsViaRegisters(sub, call)
if (sub.inline && asmgen.options.optimize) { if (sub.inline) {
// inline the subroutine. // inline the subroutine. (regardless of optimization settings!)
// we do this by copying the subroutine's statements at the call site. // 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 // 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) // (this condition has been enforced by an ast check earlier)

View File

@ -271,9 +271,7 @@ internal class ProgramAndVarsGen(
internal fun translateAsmSubroutine(sub: PtAsmSub) { internal fun translateAsmSubroutine(sub: PtAsmSub) {
if(sub.inline) { if(sub.inline) {
if(options.optimize) { return // subroutine gets inlined at call site.
return
}
} }
asmgen.out("") asmgen.out("")

View File

@ -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()) { if (subroutine.isAsmSubroutine && subroutine.asmAddress==null && !subroutine.hasRtsInAsm()) {
// make sure the NOT INLINED asm subroutine actually has a rts at the end // make sure the NOT INLINED asm subroutine actually has a rts at the end
// (non-asm routines get a Return statement as needed, above) // (non-asm routines get a Return statement as needed, above)

View File

@ -1,8 +1,6 @@
TODO 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 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! - 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!