From 53245eb1e231f883b874e29490bed602093a68d8 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Tue, 6 Mar 2018 01:01:22 +0100 Subject: [PATCH] Single threaded mode --- src/main/scala/millfork/CompilationOptions.scala | 2 ++ src/main/scala/millfork/Main.scala | 4 ++++ src/main/scala/millfork/assembly/opt/SuperOptimizer.scala | 3 ++- .../assembly/opt/VariableToRegisterOptimization.scala | 2 +- src/main/scala/millfork/parser/SourceLoadingQueue.scala | 6 +++++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/scala/millfork/CompilationOptions.scala b/src/main/scala/millfork/CompilationOptions.scala index 4fcb6a6b..9d833453 100644 --- a/src/main/scala/millfork/CompilationOptions.scala +++ b/src/main/scala/millfork/CompilationOptions.scala @@ -126,6 +126,8 @@ object CompilationFlag extends Enumeration { VariableOverlap, CompactReturnDispatchParams, // runtime check options CheckIndexOutOfBounds, + // special options + SingleThreaded, // warning options ExtraComparisonWarnings, RorWarning, diff --git a/src/main/scala/millfork/Main.scala b/src/main/scala/millfork/Main.scala index d8bd0aaa..d3259f8f 100644 --- a/src/main/scala/millfork/Main.scala +++ b/src/main/scala/millfork/Main.scala @@ -301,6 +301,10 @@ object Main { fluff("", "Other options:", "") + flag("--single-threaded").action(c => + c.changeFlag(CompilationFlag.SingleThreaded, true) + ).description("Run the compiler in a single thread.") + flag("--help").action(c => { printHelp(20).foreach(println(_)) assumeStatus(CliStatus.Quit) diff --git a/src/main/scala/millfork/assembly/opt/SuperOptimizer.scala b/src/main/scala/millfork/assembly/opt/SuperOptimizer.scala index ebcf2298..83510f3e 100644 --- a/src/main/scala/millfork/assembly/opt/SuperOptimizer.scala +++ b/src/main/scala/millfork/assembly/opt/SuperOptimizer.scala @@ -52,7 +52,8 @@ object SuperOptimizer extends AssemblyOptimization { while(queue.nonEmpty) { val (optsSoFar, codeSoFar) = queue.dequeue() var isLeaf = true - allOptimizers.par.foreach { o => + (if (options.flag(CompilationFlag.SingleThreaded)) allOptimizers + else allOptimizers.par).foreach { o => val optimized = o.optimize(m, codeSoFar, options) val view = viewCode(optimized) seenSoFar.synchronized{ diff --git a/src/main/scala/millfork/assembly/opt/VariableToRegisterOptimization.scala b/src/main/scala/millfork/assembly/opt/VariableToRegisterOptimization.scala index e4e957a7..4b81dadd 100644 --- a/src/main/scala/millfork/assembly/opt/VariableToRegisterOptimization.scala +++ b/src/main/scala/millfork/assembly/opt/VariableToRegisterOptimization.scala @@ -194,7 +194,7 @@ object VariableToRegisterOptimization extends AssemblyOptimization { val aCandidateSets = NonOverlappingIntervals.apply[(String, Range, Int)](aCandidates, _._2.start, _._2.end) val variants = for { - vx <- xCandidateSets.par + vx <- if (options.flag(CompilationFlag.SingleThreaded)) xCandidateSets else xCandidateSets.par nx = vx.map(_._1) vy <- yCandidateSets diff --git a/src/main/scala/millfork/parser/SourceLoadingQueue.scala b/src/main/scala/millfork/parser/SourceLoadingQueue.scala index 9d98168d..0b72b385 100644 --- a/src/main/scala/millfork/parser/SourceLoadingQueue.scala +++ b/src/main/scala/millfork/parser/SourceLoadingQueue.scala @@ -30,7 +30,11 @@ class SourceLoadingQueue(val initialFilenames: List[String], val includePath: Li moduleQueue.enqueue(() => parseModule("zp_reg", includePath, Left(None), options)) } while (moduleQueue.nonEmpty) { - moduleQueue.dequeueAll(_ => true).par.foreach(_()) + if (options.flag(CompilationFlag.SingleThreaded)) { + moduleQueue.dequeueAll(_ => true).foreach(_()) + } else { + moduleQueue.dequeueAll(_ => true).par.foreach(_()) + } } ErrorReporting.assertNoErrors("Parse failed") parsedModules.values.reduce(_ + _)