From 1683c95e159006d40a8458d29ef266ca741752c7 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 25 Jul 2013 12:58:56 -0700 Subject: SI-7622 Clean Up Phase Assembly Let optimiser components and continuations plugin opt-out when required flags are not set. Wasted time on a whitespace error in check file, so let --debug dump the processed check file and its diff. --- .../plugin/scala/tools/selectivecps/CPSUtils.scala | 2 +- .../tools/selectivecps/SelectiveCPSPlugin.scala | 43 ++++++++++++---------- 2 files changed, 24 insertions(+), 21 deletions(-) (limited to 'src/continuations') diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala index 29480576ea..98d0695865 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala @@ -8,7 +8,7 @@ trait CPSUtils { val global: Global import global._ - var cpsEnabled = false + val cpsEnabled: Boolean val verbose: Boolean = System.getProperty("cpsVerbose", "false") == "true" def vprintln(x: =>Any): Unit = if (verbose) println(x) diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala index d3b02d74f4..a7e82e949b 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala @@ -11,41 +11,44 @@ class SelectiveCPSPlugin(val global: Global) extends Plugin { val name = "continuations" val description = "applies selective cps conversion" - val anfPhase = new {val global = SelectiveCPSPlugin.this.global } with SelectiveANFTransform() { + val pluginEnabled = options contains "enable" + + val anfPhase = new { + val global = SelectiveCPSPlugin.this.global + val cpsEnabled = pluginEnabled + override val enabled = cpsEnabled + } with SelectiveANFTransform { val runsAfter = List("pickler") } - val cpsPhase = new {val global = SelectiveCPSPlugin.this.global } with SelectiveCPSTransform() { + val cpsPhase = new { + val global = SelectiveCPSPlugin.this.global + val cpsEnabled = pluginEnabled + override val enabled = cpsEnabled + } with SelectiveCPSTransform { val runsAfter = List("selectiveanf") override val runsBefore = List("uncurry") } val components = List[PluginComponent](anfPhase, cpsPhase) - val checker = new { val global: SelectiveCPSPlugin.this.global.type = SelectiveCPSPlugin.this.global } with CPSAnnotationChecker + val checker = new { + val global: SelectiveCPSPlugin.this.global.type = SelectiveCPSPlugin.this.global + val cpsEnabled = pluginEnabled + } with CPSAnnotationChecker + + // TODO don't muck up global with unused checkers global.addAnnotationChecker(checker.checker) global.analyzer.addAnalyzerPlugin(checker.plugin) global.log("instantiated cps plugin: " + this) - def setEnabled(flag: Boolean) = { - checker.cpsEnabled = flag - anfPhase.cpsEnabled = flag - cpsPhase.cpsEnabled = flag - } - - // TODO: require -enabled command-line flag - - override def processOptions(options: List[String], error: String => Unit) = { - var enabled = false - for (option <- options) { - if (option == "enable") { - enabled = true - } else { - error("Option not understood: "+option) - } + override def init(options: List[String], error: String => Unit) = { + options foreach { + case "enable" => // in initializer + case arg => error(s"Bad argument: $arg") } - setEnabled(enabled) + pluginEnabled } override val optionsHelp: Option[String] = -- cgit v1.2.3