diff options
| author | Adam Izraelevitz | 2021-10-13 12:01:52 -0700 |
|---|---|---|
| committer | GitHub | 2021-10-13 12:01:52 -0700 |
| commit | 8ed9940ed943d0b7f4248d26c598a95c62340f26 (patch) | |
| tree | eefcda35d6f431528ebb57129e192c4c7099d73d | |
| parent | ce8e42077d69e041dddb41843379a0fb4e5b4f23 (diff) | |
Support @public on unimplemented vals (#2182)
3 files changed, 25 insertions, 1 deletions
diff --git a/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala b/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala index 1d374198..15f69848 100644 --- a/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala +++ b/macros/src/main/scala/chisel3/internal/InstantiableMacro.scala @@ -21,10 +21,14 @@ private[chisel3] object instantiableMacro { case x @ q"@public val $tpname: $tpe = $_" => 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)") + Seq(x) case x @ q"@public lazy val $tpname: $tpe = $_" => extensions += atPos(x.pos)(q"def $tpname = module._lookup(_.$tpname)") Seq(x) - case other => Seq(other) + case other => + Seq(other) } (resultStats, extensions) } diff --git a/src/test/scala/chiselTests/experimental/hierarchy/DefinitionSpec.scala b/src/test/scala/chiselTests/experimental/hierarchy/DefinitionSpec.scala index 19261c36..4eb77c8a 100644 --- a/src/test/scala/chiselTests/experimental/hierarchy/DefinitionSpec.scala +++ b/src/test/scala/chiselTests/experimental/hierarchy/DefinitionSpec.scala @@ -258,6 +258,17 @@ class DefinitionSpec extends ChiselFunSpec with Utils { val (_, annos) = getFirrtlAndAnnos(new Top) annos should contain(MarkAnnotation("~Top|HasPublicConstructorArgs>x".rt, "10")) } + it("3.10: should work on unimplemented vals in abstract classes/traits") { + class Top() extends Module { + val i = Definition(new ConcreteHasBlah()) + def f(d: Definition[HasBlah]): Unit = { + mark(d, d.blah.toString) + } + f(i) + } + val (_, annos) = getFirrtlAndAnnos(new Top) + annos should contain(MarkAnnotation("~Top|ConcreteHasBlah".mt, "10")) + } } describe("4: toDefinition") { it("4.0: should work on modules") { diff --git a/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala b/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala index 23b8c9c0..94c0e551 100644 --- a/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala +++ b/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala @@ -183,4 +183,13 @@ object Examples { @public val out = IO(Output(UInt(3.W))) out := RegNext(in) } + @instantiable + abstract class HasBlah() extends Module { + @public val blah: Int + } + + @instantiable + class ConcreteHasBlah() extends HasBlah { + val blah = 10 + } } |
