no need for intermediary returnvalue var for prefix expressions

This commit is contained in:
Irmen de Jong 2021-12-16 21:00:38 +01:00
parent 77c2b2b326
commit 1462c57d0c
4 changed files with 19 additions and 32 deletions

View File

@ -312,22 +312,21 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
is IdentifierReference -> { is IdentifierReference -> {
val sourceName = asmgen.asmVariableName(value) val sourceName = asmgen.asmVariableName(value)
asmgen.out(""" asmgen.out("""
pha pha
clc clc
lda $sourceName lda $sourceName
beq + beq +
sec sec
+ pla + pla""")
""")
} }
else -> { else -> {
asmgen.assignExpressionToRegister(value, RegisterOrPair.A) asmgen.assignExpressionToRegister(value, RegisterOrPair.A)
asmgen.out(""" asmgen.out("""
beq + beq +
sec sec
bcs ++ bcs ++
+ clc + clc
+""") +""")
} }
} }
} else throw AssemblyError("can only use Carry as status flag parameter") } else throw AssemblyError("can only use Carry as status flag parameter")

View File

@ -1824,18 +1824,18 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
cmp #0 cmp #0
beq + beq +
lda #1 lda #1
+ eor #1""") + eor #1""")
RegisterOrPair.X -> asmgen.out(""" RegisterOrPair.X -> asmgen.out("""
txa txa
beq + beq +
lda #1 lda #1
+ eor #1 + eor #1
tax""") tax""")
RegisterOrPair.Y -> asmgen.out(""" RegisterOrPair.Y -> asmgen.out("""
tya tya
beq + beq +
lda #1 lda #1
+ eor #1 + eor #1
tay""") tay""")
else -> throw AssemblyError("invalid reg dt for byte not") else -> throw AssemblyError("invalid reg dt for byte not")
} }

View File

@ -466,21 +466,13 @@ class StatementOptimizer(private val program: Program,
return null return null
} }
when(returnStmt.value) { if(returnStmt.value is BinaryExpression) {
is PrefixExpression -> { val mod = returnViaIntermediaryVar(returnStmt.value!!)
val mod = returnViaIntermediaryVar(returnStmt.value!!) if(mod!=null)
if(mod!=null) return mod
return mod
}
is BinaryExpression -> {
val mod = returnViaIntermediaryVar(returnStmt.value!!)
if(mod!=null)
return mod
}
else -> {}
} }
return super.after(returnStmt, parent) return noModifications
} }
private fun hasBreak(scope: IStatementContainer): Boolean { private fun hasBreak(scope: IStatementContainer): Boolean {

View File

@ -3,10 +3,6 @@ TODO
For next compiler release (7.6) For next compiler release (7.6)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
why does the following use a intermediate return value and not just A?
sub pushing_start() -> ubyte {
return joy_info & 16
}
... ...