summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorJack2022-07-30 22:41:15 +0000
committerJack2022-07-30 22:41:15 +0000
commit4cd44fa4dab370fcc5c20bcacc1fa0ee02327252 (patch)
tree05730be260feca0d2a870c4bb88325d36631a8fc /plugin
parentfe9635ef21bad233945617a24ab16cfa4055f2d1 (diff)
parentbced77045c8fc5db37e40b159c49220929e15d46 (diff)
Merge branch '3.5.x' into 3.5-release
Diffstat (limited to 'plugin')
-rw-r--r--plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala6
-rw-r--r--plugin/src/main/scala/chisel3/internal/plugin/ChiselComponent.scala47
2 files changed, 42 insertions, 11 deletions
diff --git a/plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala b/plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala
index e3ec0a04..eca3b158 100644
--- a/plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala
+++ b/plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala
@@ -84,6 +84,8 @@ private[plugin] class BundleComponent(val global: Global, arguments: ChiselPlugi
def isNullaryMethodNamed(name: String, defdef: DefDef): Boolean =
defdef.name.decodedName.toString == name && defdef.tparams.isEmpty && defdef.vparamss.isEmpty
+ def isVarArgs(sym: Symbol): Boolean = definitions.isRepeatedParamType(sym.tpe)
+
def getConstructorAndParams(body: List[Tree]): (Option[DefDef], Seq[Symbol]) = {
val paramAccessors = mutable.ListBuffer[Symbol]()
var primaryConstructor: Option[DefDef] = None
@@ -134,7 +136,9 @@ private[plugin] class BundleComponent(val global: Global, arguments: ChiselPlugi
// Make this.<ref>
val select = gen.mkAttributedSelect(thiz.asInstanceOf[Tree], p)
// Clone any Data parameters to avoid field aliasing, need full clone to include direction
- if (isData(vp.symbol)) cloneTypeFull(select.asInstanceOf[Tree]) else select
+ val cloned = if (isData(vp.symbol)) cloneTypeFull(select.asInstanceOf[Tree]) else select
+ // Need to splat varargs
+ if (isVarArgs(vp.symbol)) q"$cloned: _*" else cloned
})
val tparamList = bundle.tparams.map { t => Ident(t.symbol) }
diff --git a/plugin/src/main/scala/chisel3/internal/plugin/ChiselComponent.scala b/plugin/src/main/scala/chisel3/internal/plugin/ChiselComponent.scala
index eced652b..dd9f24fb 100644
--- a/plugin/src/main/scala/chisel3/internal/plugin/ChiselComponent.scala
+++ b/plugin/src/main/scala/chisel3/internal/plugin/ChiselComponent.scala
@@ -78,10 +78,21 @@ class ChiselComponent(val global: Global, arguments: ChiselPluginArguments)
}
}
- private val shouldMatchData: Type => Boolean = shouldMatchGen(tq"chisel3.Data")
- private val shouldMatchDataOrMem: Type => Boolean = shouldMatchGen(tq"chisel3.Data", tq"chisel3.MemBase[_]")
- private val shouldMatchModule: Type => Boolean = shouldMatchGen(tq"chisel3.experimental.BaseModule")
- private val shouldMatchInstance: Type => Boolean = shouldMatchGen(tq"chisel3.experimental.hierarchy.Instance[_]")
+ private val shouldMatchData: Type => Boolean = shouldMatchGen(tq"chisel3.Data")
+ // Checking for all chisel3.internal.NamedComponents, but since it is internal, we instead have
+ // to match the public subtypes
+ private val shouldMatchNamedComp: Type => Boolean =
+ shouldMatchGen(
+ tq"chisel3.Data",
+ tq"chisel3.MemBase[_]",
+ tq"chisel3.VerificationStatement"
+ )
+ private val shouldMatchModule: Type => Boolean = shouldMatchGen(tq"chisel3.experimental.BaseModule")
+ private val shouldMatchInstance: Type => Boolean = shouldMatchGen(tq"chisel3.experimental.hierarchy.Instance[_]")
+ private val shouldMatchChiselPrefixed: Type => Boolean =
+ shouldMatchGen(
+ tq"chisel3.experimental.AffectsChiselPrefix"
+ )
// Given a type tree, infer the type and return it
private def inferType(t: Tree): Type = localTyper.typed(t, nsc.Mode.TYPEmode).tpe
@@ -168,22 +179,38 @@ class ChiselComponent(val global: Global, arguments: ChiselPluginArguments)
// Check if a subtree is a candidate
case dd @ ValDef(mods, name, tpt, rhs) if okVal(dd) =>
val tpe = inferType(tpt)
+ val isData = shouldMatchData(tpe)
+ val isNamedComp = isData || shouldMatchNamedComp(tpe)
+ val isPrefixed = isNamedComp || shouldMatchChiselPrefixed(tpe)
+
// If a Data and in a Bundle, just get the name but not a prefix
- if (shouldMatchData(tpe) && inBundle(dd)) {
+ if (isData && inBundle(dd)) {
val str = stringFromTermName(name)
val newRHS = transform(rhs) // chisel3.internal.plugin.autoNameRecursively
val named = q"chisel3.internal.plugin.autoNameRecursively($str)($newRHS)"
treeCopy.ValDef(dd, mods, name, tpt, localTyper.typed(named))
}
// If a Data or a Memory, get the name and a prefix
- else if (shouldMatchDataOrMem(tpe)) {
+ else if (isData || isPrefixed) {
val str = stringFromTermName(name)
+ // Starting with '_' signifies a temporary, we ignore it for prefixing because we don't
+ // want double "__" in names when the user is just specifying a temporary
+ val prefix = if (str.head == '_') str.tail else str
val newRHS = transform(rhs)
- val prefixed = q"chisel3.experimental.prefix.apply[$tpt](name=$str)(f=$newRHS)"
- val named = q"chisel3.internal.plugin.autoNameRecursively($str)($prefixed)"
+ val prefixed = q"chisel3.experimental.prefix.apply[$tpt](name=$prefix)(f=$newRHS)"
+
+ val named =
+ if (isNamedComp) {
+ // Only name named components (not things that are merely prefixed)
+ q"chisel3.internal.plugin.autoNameRecursively($str)($prefixed)"
+ } else {
+ prefixed
+ }
+
treeCopy.ValDef(dd, mods, name, tpt, localTyper.typed(named))
- // If an instance, just get a name but no prefix
- } else if (shouldMatchModule(tpe)) {
+ }
+ // If an instance, just get a name but no prefix
+ else if (shouldMatchModule(tpe)) {
val str = stringFromTermName(name)
val newRHS = transform(rhs)
val named = q"chisel3.internal.plugin.autoNameRecursively($str)($newRHS)"