mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-11 12:29:46 +00:00
If a function has one small parameter, pass it via the accumulator
This commit is contained in:
parent
3d47c51804
commit
bc21e5befc
@ -169,6 +169,8 @@ object ReverseFlowAnalyzer {
|
||||
result = result.copy(x = Important, y = Important)
|
||||
case _ =>
|
||||
})
|
||||
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 1 =>
|
||||
result = result.copy(a = Important)
|
||||
case _ =>
|
||||
}
|
||||
if (ZeropageRegisterOptimizations.functionsThatUsePseudoregisterAsInput(fun.name)) {
|
||||
|
@ -35,6 +35,8 @@ object SingleAssignmentVariableOptimization extends AssemblyOptimization[Assembl
|
||||
|
||||
override def optimize(f: NormalFunction, code: List[AssemblyLine], options: CompilationOptions): List[AssemblyLine] = {
|
||||
val paramVariables = f.params match {
|
||||
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 1 =>
|
||||
Set[String]()
|
||||
case NormalParamSignature(ps) =>
|
||||
ps.map(_.name).toSet
|
||||
case _ =>
|
||||
|
@ -105,6 +105,8 @@ object VariableToRegisterOptimization extends AssemblyOptimization[AssemblyLine]
|
||||
|
||||
override def optimize(f: NormalFunction, code: List[AssemblyLine], options: CompilationOptions): List[AssemblyLine] = {
|
||||
val paramVariables = f.params match {
|
||||
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 1 =>
|
||||
Set[String]()
|
||||
case NormalParamSignature(ps) =>
|
||||
ps.map(_.name).toSet
|
||||
case _ =>
|
||||
|
@ -23,6 +23,11 @@ object MosCompiler extends AbstractCompiler[AssemblyLine] {
|
||||
ctx.env.nameCheck(ctx.function.code)
|
||||
val chunk = MosStatementCompiler.compile(ctx, ctx.function.code)
|
||||
|
||||
val storeParamsFromRegisters = ctx.function.params match {
|
||||
case NormalParamSignature(List(param@MemoryVariable(_, typ, _))) if typ.size == 1 =>
|
||||
List(AssemblyLine.absolute(STA, param))
|
||||
case _ => Nil
|
||||
}
|
||||
val phReg =
|
||||
if (ctx.options.flag(CompilationFlag.ZeropagePseudoregister)) {
|
||||
val reg = ctx.env.get[VariableInMemory]("__reg")
|
||||
@ -34,7 +39,7 @@ object MosCompiler extends AbstractCompiler[AssemblyLine] {
|
||||
)
|
||||
} else Nil
|
||||
|
||||
val prefix = (if (ctx.function.interrupt) {
|
||||
val prefix = storeParamsFromRegisters ++ (if (ctx.function.interrupt) {
|
||||
|
||||
if (ctx.options.flag(CompilationFlag.EmitNative65816Opcodes)) {
|
||||
if (ctx.options.flag(CompilationFlag.ZeropagePseudoregister)) {
|
||||
|
@ -1067,6 +1067,8 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
|
||||
case _ => Nil
|
||||
}
|
||||
secondViaMemory ++ thirdViaRegisters :+ AssemblyLine.absoluteOrLongAbsolute(JSR, function, ctx.options)
|
||||
case NormalParamSignature(List(MemoryVariable(_, typ, _))) if typ.size == 1 =>
|
||||
compile(ctx, params.head, Some(b -> RegisterVariable(MosRegister.A, b)), BranchSpec.None) ++ List(AssemblyLine.absoluteOrLongAbsolute(JSR, function, ctx.options))
|
||||
case NormalParamSignature(paramVars) =>
|
||||
params.zip(paramVars).flatMap {
|
||||
case (paramExpr, paramVar) =>
|
||||
|
Loading…
x
Reference in New Issue
Block a user