summaryrefslogtreecommitdiff
path: root/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala
diff options
context:
space:
mode:
authorAdam Izraelevitz2021-10-28 18:18:34 -0700
committerGitHub2021-10-29 01:18:34 +0000
commit0c43dadf60c1485be348115c20690990f0fea940 (patch)
treeb62086358a1d0d5587515a7d443bad7279647498 /macros/src/main/scala/chisel3/internal/InstantiableMacro.scala
parent84da5fdb528bbedc9a32c3e075bb3865994cd4aa (diff)
Exposing more APIs from D/I internals (#2220)
Exposing more internals of D/I, which are required for supporting D/I with more powerful Chisel libraries: - Exposing IsClone[_] - Exposing InstantiableClone[_] - Gated builders for Instance/Definition - Unsealing Lookupable, with protected accessors for proto and cloned
Diffstat (limited to 'macros/src/main/scala/chisel3/internal/InstantiableMacro.scala')
-rw-r--r--macros/src/main/scala/chisel3/internal/InstantiableMacro.scala19
1 files changed, 11 insertions, 8 deletions
diff --git a/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala b/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala
index f4ba2e6e..18c6c7aa 100644
--- a/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala
+++ b/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala
@@ -14,18 +14,21 @@ private[chisel3] object instantiableMacro {
def processBody(stats: Seq[Tree]): (Seq[Tree], Iterable[Tree]) = {
val extensions = scala.collection.mutable.ArrayBuffer.empty[Tree]
extensions += q"implicit val mg = new chisel3.internal.MacroGenerated{}"
+ // Note the triple `_` prefixing `module` is to avoid conflicts if a user marks a 'val module'
+ // with @public; in this case, the lookup code is ambiguous between the generated `def module`
+ // function and the argument to the generated implicit class.
val resultStats = stats.flatMap {
case x @ q"@public val $tpname: $tpe = $name" if tpname.toString() == name.toString() =>
- extensions += atPos(x.pos)(q"def $tpname = module._lookup(_.$tpname)")
+ extensions += atPos(x.pos)(q"def $tpname = ___module._lookup(_.$tpname)")
Nil
case x @ q"@public val $tpname: $tpe = $_" =>
- extensions += atPos(x.pos)(q"def $tpname = module._lookup(_.$tpname)")
+ extensions += atPos(x.pos)(q"def $tpname = ___module._lookup(_.$tpname)")
Seq(x)
case x @ q"@public val $tpname: $tpe" =>
- extensions += atPos(x.pos)(q"def $tpname = module._lookup(_.$tpname)")
+ extensions += atPos(x.pos)(q"def $tpname = ___module._lookup(_.$tpname)")
Seq(x)
case x @ q"@public lazy val $tpname: $tpe = $_" =>
- extensions += atPos(x.pos)(q"def $tpname = module._lookup(_.$tpname)")
+ extensions += atPos(x.pos)(q"def $tpname = ___module._lookup(_.$tpname)")
Seq(x)
case other =>
Seq(other)
@@ -44,8 +47,8 @@ private[chisel3] object instantiableMacro {
val (newStats, extensions) = processBody(stats)
val argTParams = tparams.map(_.name)
(q""" $mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents with chisel3.experimental.hierarchy.IsInstantiable { $self => ..$newStats } """,
- Seq(q"""implicit class $defname[..$tparams](module: chisel3.experimental.hierarchy.Definition[$tpname[..$argTParams]]) { ..$extensions }""",
- q"""implicit class $instname[..$tparams](module: chisel3.experimental.hierarchy.Instance[$tpname[..$argTParams]]) { ..$extensions } """),
+ Seq(q"""implicit class $defname[..$tparams](___module: chisel3.experimental.hierarchy.Definition[$tpname[..$argTParams]]) { ..$extensions }""",
+ q"""implicit class $instname[..$tparams](___module: chisel3.experimental.hierarchy.Instance[$tpname[..$argTParams]]) { ..$extensions } """),
tpname)
case q"$mods trait $tpname[..$tparams] extends { ..$earlydefns } with ..$parents { $self => ..$stats }" =>
val defname = TypeName(tpname + c.freshName())
@@ -53,8 +56,8 @@ private[chisel3] object instantiableMacro {
val (newStats, extensions) = processBody(stats)
val argTParams = tparams.map(_.name)
(q"$mods trait $tpname[..$tparams] extends { ..$earlydefns } with ..$parents with chisel3.experimental.hierarchy.IsInstantiable { $self => ..$newStats }",
- Seq(q"""implicit class $defname[..$tparams](module: chisel3.experimental.hierarchy.Definition[$tpname[..$argTParams]]) { ..$extensions }""",
- q"""implicit class $instname[..$tparams](module: chisel3.experimental.hierarchy.Instance[$tpname[..$argTParams]]) { ..$extensions } """),
+ Seq(q"""implicit class $defname[..$tparams](___module: chisel3.experimental.hierarchy.Definition[$tpname[..$argTParams]]) { ..$extensions }""",
+ q"""implicit class $instname[..$tparams](___module: chisel3.experimental.hierarchy.Instance[$tpname[..$argTParams]]) { ..$extensions } """),
tpname)
}
val newObj = objOpt match {