summaryrefslogtreecommitdiff
path: root/plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala')
-rw-r--r--plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala36
1 files changed, 34 insertions, 2 deletions
diff --git a/plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala b/plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala
index 2282059f..eadb76b6 100644
--- a/plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala
+++ b/plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala
@@ -6,14 +6,40 @@ import scala.tools.nsc
import nsc.Global
import nsc.plugins.{Plugin, PluginComponent}
import scala.reflect.internal.util.NoPosition
+import scala.collection.mutable
-private[plugin] case class ChiselPluginArguments() {
+private[plugin] case class ChiselPluginArguments(val skipFiles: mutable.HashSet[String] = mutable.HashSet.empty) {
def useBundlePluginOpt = "useBundlePlugin"
def useBundlePluginFullOpt = s"-P:${ChiselPlugin.name}:$useBundlePluginOpt"
+
+ // Annoying because this shouldn't be used by users
+ def skipFilePluginOpt = "INTERNALskipFile:"
+ def skipFilePluginFullOpt = s"-P:${ChiselPlugin.name}:$skipFilePluginOpt"
}
object ChiselPlugin {
val name = "chiselplugin"
+
+ // Also logs why the compoennt was not run
+ private[plugin] def runComponent(global: Global, arguments: ChiselPluginArguments)(unit: global.CompilationUnit): Boolean = {
+ // This plugin doesn't work on Scala 2.11 nor Scala 3. Rather than complicate the sbt build flow,
+ // instead we just check the version and if its an early Scala version, the plugin does nothing
+ val scalaVersion = scala.util.Properties.versionNumberString.split('.')
+ val scalaVersionOk = scalaVersion(0).toInt == 2 && scalaVersion(1).toInt >= 12
+ val skipFile = arguments.skipFiles(unit.source.file.path)
+ if (scalaVersionOk && !skipFile) {
+ true
+ } else {
+ val reason = if (!scalaVersionOk) {
+ s"invalid Scala version '${scala.util.Properties.versionNumberString}'"
+ } else {
+ s"file skipped via '${arguments.skipFilePluginFullOpt}'"
+ }
+ // Enable this with scalacOption '-Ylog:chiselbundlephase'
+ global.log(s"Skipping BundleComponent on account of $reason.")
+ false
+ }
+ }
}
// The plugin to be run by the Scala compiler during compilation of Chisel code
@@ -22,7 +48,7 @@ class ChiselPlugin(val global: Global) extends Plugin {
val description = "Plugin for Chisel 3 Hardware Description Language"
private val arguments = ChiselPluginArguments()
val components: List[PluginComponent] = List[PluginComponent](
- new ChiselComponent(global),
+ new ChiselComponent(global, arguments),
new BundleComponent(global, arguments)
)
@@ -31,6 +57,12 @@ class ChiselPlugin(val global: Global) extends Plugin {
if (option == arguments.useBundlePluginOpt) {
val msg = s"'${arguments.useBundlePluginFullOpt}' is now default behavior, you can stop using the scalacOption."
global.reporter.warning(NoPosition, msg)
+ } else if (option.startsWith(arguments.skipFilePluginOpt)) {
+ val filename = option.stripPrefix(arguments.skipFilePluginOpt)
+ arguments.skipFiles += filename
+ // Be annoying and warn because users are not supposed to use this
+ val msg = s"Option -P:${ChiselPlugin.name}:$option should only be used for internal chisel3 compiler purposes!"
+ global.reporter.warning(NoPosition, msg)
} else {
error(s"Option not understood: '$option'")
}