summaryrefslogtreecommitdiff
path: root/plugin/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/src/main')
-rw-r--r--plugin/src/main/scala/chisel3/internal/plugin/ChiselComponent.scala33
1 files changed, 27 insertions, 6 deletions
diff --git a/plugin/src/main/scala/chisel3/internal/plugin/ChiselComponent.scala b/plugin/src/main/scala/chisel3/internal/plugin/ChiselComponent.scala
index b3bbdbe4..dd9f24fb 100644
--- a/plugin/src/main/scala/chisel3/internal/plugin/ChiselComponent.scala
+++ b/plugin/src/main/scala/chisel3/internal/plugin/ChiselComponent.scala
@@ -82,9 +82,17 @@ class ChiselComponent(val global: Global, arguments: ChiselPluginArguments)
// 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")
+ 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
@@ -171,25 +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 (shouldMatchNamedComp(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=$prefix)(f=$newRHS)"
- val named = q"chisel3.internal.plugin.autoNameRecursively($str)($prefixed)"
+
+ 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)"