1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-01-12 03:30:09 +00:00

Better removal of unused functions

This commit is contained in:
Karol Stasiak 2019-10-01 00:46:41 +02:00
parent d1058b6223
commit 1185b1c0bb

View File

@ -59,7 +59,7 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program
mem.banks(bank).readable(addr) = true mem.banks(bank).readable(addr) = true
value match { value match {
case NumericConstant(x, _) => case NumericConstant(x, _) =>
if (x > 0xff) log.error("Byte overflow") if (x > 0xff) log.error("Byte overflow: " + x.toHexString)
mem.banks(bank).output(addr) = x.toByte mem.banks(bank).output(addr) = x.toByte
case _ => case _ =>
bytesToWriteLater += ((bank, addr, value)) bytesToWriteLater += ((bank, addr, value))
@ -281,7 +281,7 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program
"__divmod_u16u8u16u8", "__mod_u16u8u16u8", "__div_u16u8u16u8", "__divmod_u16u8u16u8", "__mod_u16u8u16u8", "__div_u16u8u16u8",
"__divmod_u16u16u16u16", "__mod_u16u16u16u16", "__div_u16u16u16u16") ++ "__divmod_u16u16u16u16", "__mod_u16u16u16u16", "__div_u16u16u16u16") ++
compiledFunctions.keySet.filter(_.endsWith(".trampoline")) compiledFunctions.keySet.filter(_.endsWith(".trampoline"))
val unusedRuntimeObjects = objectsThatMayBeUnused.filterNot(name =>{ val unusedRuntimeObjects0 = objectsThatMayBeUnused.filterNot(name =>{
compiledFunctions.exists{ compiledFunctions.exists{
case (fname, compiled) => fname != name && (compiled match { case (fname, compiled) => fname != name && (compiled match {
case f:NormalCompiledFunction[_] => f.code.exists(_.refersTo(name)) case f:NormalCompiledFunction[_] => f.code.exists(_.refersTo(name))
@ -289,6 +289,14 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program
}) })
} }
}) })
val unusedRuntimeObjects = unusedRuntimeObjects0 ++ objectsThatMayBeUnused.filterNot(name =>{
compiledFunctions.exists{
case (fname, compiled) => fname != name && !unusedRuntimeObjects0(fname) && (compiled match {
case f:NormalCompiledFunction[_] => f.code.exists(_.refersTo(name))
case _ => false
})
}
})
env.allPreallocatables.filterNot(o => unusedRuntimeObjects(o.name)).foreach { env.allPreallocatables.filterNot(o => unusedRuntimeObjects(o.name)).foreach {
case thing@InitializedArray(name, Some(NumericConstant(address, _)), items, _, _, elementType, readOnly, _) => case thing@InitializedArray(name, Some(NumericConstant(address, _)), items, _, _, elementType, readOnly, _) =>