From 889a4f94be9872f6b86be567a339560f58c15be5 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Tue, 29 Sep 2020 22:49:15 +0200 Subject: [PATCH] All things mentioned in segment layouts should be considered used. --- src/main/scala/millfork/node/opt/UnusedFunctions.scala | 3 ++- src/main/scala/millfork/node/opt/UnusedGlobalVariables.scala | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/scala/millfork/node/opt/UnusedFunctions.scala b/src/main/scala/millfork/node/opt/UnusedFunctions.scala index 981a6c14..dcd893e0 100644 --- a/src/main/scala/millfork/node/opt/UnusedFunctions.scala +++ b/src/main/scala/millfork/node/opt/UnusedFunctions.scala @@ -65,8 +65,9 @@ object UnusedFunctions extends NodeOptimization { case _ => None }.toMap val panicRequired = options.flags(CompilationFlag.CheckIndexOutOfBounds) + val entrypointNames = options.platform.bankLayouts.values.flatten.toSet + "main" val allNormalFunctions = nodes.flatMap { - case v: FunctionDeclarationStatement => if (v.address.isDefined && v.statements.isDefined || v.interrupt || v.name == "main" || panicRequired && v.name == "_panic") Nil else List(v.name) + case v: FunctionDeclarationStatement => if (v.address.isDefined && v.statements.isDefined || v.interrupt || entrypointNames(v.name) || panicRequired && v.name == "_panic") Nil else List(v.name) case _ => Nil }.toSet var allCalledFunctions = resolveAliases(aliases, getAllCalledFunctions(nodes).toSet) diff --git a/src/main/scala/millfork/node/opt/UnusedGlobalVariables.scala b/src/main/scala/millfork/node/opt/UnusedGlobalVariables.scala index 270fcfdf..eb2aa6c0 100644 --- a/src/main/scala/millfork/node/opt/UnusedGlobalVariables.scala +++ b/src/main/scala/millfork/node/opt/UnusedGlobalVariables.scala @@ -15,8 +15,9 @@ object UnusedGlobalVariables extends NodeOptimization { case AliasDefinitionStatement(source, target, _) => Some(source -> target) case _ => None }.toMap + val entrypointNames = options.platform.bankLayouts.values.flatten.toSet val allNonvolatileGlobalVariables = nodes.flatMap { - case v: VariableDeclarationStatement => if (v.address.isDefined || v.volatile || v.constant) Nil else List(v.name) + case v: VariableDeclarationStatement => if (v.address.isDefined || v.volatile || v.constant || entrypointNames(v.name)) Nil else List(v.name) case v: ArrayDeclarationStatement => if (v.address.isDefined) Nil else List(v.name) case _ => Nil }.toSet