fix name check in inline asm

this no longer removes a subroutine that is otherwise only called from inlined asm.
This commit is contained in:
Irmen de Jong 2023-11-21 01:26:32 +01:00
parent af5ca2d0b8
commit 62d3f01948
4 changed files with 24 additions and 10 deletions

View File

@ -776,4 +776,20 @@ main {
""" """
compileText(VMTarget(), true, text, writeAssembly = false) shouldNotBe null compileText(VMTarget(), true, text, writeAssembly = false) shouldNotBe null
} }
test("sub only called by asm should not be optimized away") {
val src="""
main {
sub start() {
%asm{{
jsr p8_test
}}
}
sub test() {
cx16.r0++
}
}"""
compileText(Cx16Target(), true, src, writeAssembly = true) shouldNotBe null
}
}) })

View File

@ -163,7 +163,7 @@ class CallGraph(private val program: Program) : IAstVisitor {
return allIdentifiersAndTargets.filter { decl===it.value }.map{ it.key } return allIdentifiersAndTargets.filter { decl===it.value }.map{ it.key }
} }
private fun nameInAssemblyCode(name: String) = allAssemblyNodes.any { name in it.names } private fun nameInAssemblyCode(name: String) = allAssemblyNodes.any { "p8_$name" in it.names || name in it.names }
inline fun unused(label: Label) = false // just always output labels inline fun unused(label: Label) = false // just always output labels

View File

@ -4,8 +4,6 @@ TODO
- IRQ callback should return boolean to tell Prog8 to call the kernal ISR or not. - IRQ callback should return boolean to tell Prog8 to call the kernal ISR or not.
- Is there a way to tell prog8 not to optimize out a function that is only called from within %asm{{}}? like a @shared but for subs?
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 .... - [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
... ...

View File

@ -1,14 +1,14 @@
%import textio %import textio
%import floats
%zeropage basicsafe %zeropage basicsafe
main { main {
sub start() { sub start() {
float fl1 = 999.8877 %asm{{
float fl2 = sqrt(fl1) * fl1 + fl1*33.44 jsr p8_test
floats.print_f(fl2) }}
txt.nl() }
fl1=0
floats.print_f(fl1) sub test() {
cx16.r0++
} }
} }