diff --git a/src/main/scala/millfork/CompilationOptions.scala b/src/main/scala/millfork/CompilationOptions.scala index 6e94b850..564da98d 100644 --- a/src/main/scala/millfork/CompilationOptions.scala +++ b/src/main/scala/millfork/CompilationOptions.scala @@ -75,7 +75,7 @@ object CompilationFlag extends Enumeration { // compilation options: EmitIllegals, EmitCmosOpcodes, DecimalMode, ReadOnlyArrays, PreventJmpIndirectBug, // optimization options: - DetailedFlowAnalysis, DangerousOptimizations, InlineFunctions, + DetailedFlowAnalysis, DangerousOptimizations, InlineFunctions, OptimizeForSize, OptimizeForSpeed, // memory allocation options VariableOverlap, CompactReturnDispatchParams, // runtime check options diff --git a/src/main/scala/millfork/Main.scala b/src/main/scala/millfork/Main.scala index b4683a7f..79cabc44 100644 --- a/src/main/scala/millfork/Main.scala +++ b/src/main/scala/millfork/Main.scala @@ -225,7 +225,15 @@ object Main { } flag("--inline").action { c => c.changeFlag(CompilationFlag.InlineFunctions, true) - }.description("Inline functions automatically (experimental).") + }.description("Inline functions automatically.") + flag("-Of", "--fast").action { c => + c.changeFlag(CompilationFlag.OptimizeForSize, false) + c.changeFlag(CompilationFlag.OptimizeForSpeed, true) + }.description("Optimize for speed (experimental).") + flag("-Os", "--size").action { c => + c.changeFlag(CompilationFlag.OptimizeForSize, true) + c.changeFlag(CompilationFlag.OptimizeForSpeed, false) + }.description("Optimize for size (experimental).") flag("--detailed-flow").action { c => c.changeFlag(CompilationFlag.DetailedFlowAnalysis, true) }.description("Use detailed flow analysis (experimental).") diff --git a/src/main/scala/millfork/output/Assembler.scala b/src/main/scala/millfork/output/Assembler.scala index 75b95792..d466c671 100644 --- a/src/main/scala/millfork/output/Assembler.scala +++ b/src/main/scala/millfork/output/Assembler.scala @@ -145,7 +145,11 @@ class Assembler(private val program: Program, private val rootEnv: Environment) val assembly = mutable.ArrayBuffer[String]() val potentiallyInlineable: Map[String, Int] = - InliningCalculator.getPotentiallyInlineableFunctions(program, options.flags(CompilationFlag.InlineFunctions)) + InliningCalculator.getPotentiallyInlineableFunctions( + program, + options.flags(CompilationFlag.InlineFunctions), + if (options.flags(CompilationFlag.OptimizeForSpeed)) 1.3 else 1.0, + if (options.flags(CompilationFlag.OptimizeForSpeed)) 8.0 else 1.2) var inlinedFunctions = Map[String, List[AssemblyLine]]() val compiledFunctions = mutable.Map[String, List[AssemblyLine]]() diff --git a/src/main/scala/millfork/output/InliningCalculator.scala b/src/main/scala/millfork/output/InliningCalculator.scala index a7ebe86d..cd12ad79 100644 --- a/src/main/scala/millfork/output/InliningCalculator.scala +++ b/src/main/scala/millfork/output/InliningCalculator.scala @@ -16,8 +16,8 @@ object InliningCalculator { def getPotentiallyInlineableFunctions(program: Program, inlineByDefault: Boolean, - aggressivenessForNormal: Double = 1.0, - aggressivenessForRecommended: Double = 1.2): Map[String, Int] = { + aggressivenessForNormal: Double, + aggressivenessForRecommended: Double): Map[String, Int] = { val callCount = mutable.Map[String, Int]().withDefaultValue(0) val allFunctions = mutable.Set[String]() val badFunctions = mutable.Set[String]()