mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 16:29:21 +00:00
variables init subroutine must never be optimized away (fixes primes example)
This commit is contained in:
parent
a86852874f
commit
560047adee
@ -1695,6 +1695,7 @@ class Subroutine(override val name: String,
|
||||
val isAsmSubroutine: Boolean,
|
||||
override var statements: MutableList<IStatement>,
|
||||
override val position: Position) : IStatement, INameScope {
|
||||
var keepAlways: Boolean = false
|
||||
override lateinit var parent: Node
|
||||
val calledBy = mutableSetOf<INameScope>()
|
||||
val calls = mutableSetOf<Subroutine>()
|
||||
|
@ -110,6 +110,7 @@ private class StatementReorderer(private val program: Program): IAstProcessor {
|
||||
val statements = varInits.map{it.value}.toMutableList()
|
||||
val varInitSub = Subroutine(initvarsSubName, emptyList(), emptyList(), emptyList(), emptyList(),
|
||||
emptySet(), null, false, statements, block.position)
|
||||
varInitSub.keepAlways = true
|
||||
varInitSub.linkParents(block)
|
||||
block.statements.add(varInitSub)
|
||||
|
||||
|
@ -7,9 +7,6 @@ import kotlin.math.floor
|
||||
|
||||
|
||||
/*
|
||||
TODO FIX THE OPTIMIZER: RESULTS IN WRONG CODE FOR THE primes.p8 EXAMPLE
|
||||
|
||||
|
||||
todo: subroutines with 1 or 2 byte args or 1 word arg can be converted to asm sub calling convention (args in registers)
|
||||
|
||||
todo: implement usage counters for variables (locals and heap), blocks. Remove if count is zero.
|
||||
@ -40,13 +37,15 @@ class StatementOptimizer(private val program: Program) : IAstProcessor {
|
||||
val entrypoint = program.entrypoint()
|
||||
program.modules.forEach {
|
||||
callgraph.forAllSubroutines(it) { sub ->
|
||||
if(sub !== entrypoint && (sub.calledBy.isEmpty() || (sub.containsNoCodeNorVars() && !sub.isAsmSubroutine)))
|
||||
if(sub !== entrypoint && !sub.keepAlways && (sub.calledBy.isEmpty() || (sub.containsNoCodeNorVars() && !sub.isAsmSubroutine)))
|
||||
removeSubroutines.add(sub)
|
||||
}
|
||||
}
|
||||
|
||||
if(removeSubroutines.isNotEmpty()) {
|
||||
removeSubroutines.forEach { it.definingScope().statements.remove(it) }
|
||||
removeSubroutines.forEach {
|
||||
it.definingScope().statements.remove(it)
|
||||
}
|
||||
}
|
||||
|
||||
val removeBlocks = mutableSetOf<Block>()
|
||||
|
@ -3,9 +3,6 @@
|
||||
|
||||
~ main {
|
||||
|
||||
; TODO FIX THE COMPILER OPTIMIZER ; RESULTS IN WRONG CODE FOR THIS PROGRAM
|
||||
|
||||
|
||||
ubyte[256] sieve
|
||||
ubyte candidate_prime = 2 ; is increased in the loop
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user