Skip to content

Commit 48866a9

Browse files
authored
Implement Lookupable for Unit (#4497)
1 parent abf74af commit 48866a9

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

core/src/main/scala/chisel3/experimental/hierarchy/core/Lookupable.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,4 +552,5 @@ object Lookupable {
552552
implicit val lookupString: SimpleLookupable[String] = new SimpleLookupable[String]()
553553
implicit val lookupBoolean: SimpleLookupable[Boolean] = new SimpleLookupable[Boolean]()
554554
implicit val lookupBigInt: SimpleLookupable[BigInt] = new SimpleLookupable[BigInt]()
555+
implicit val lookupUnit: SimpleLookupable[Unit] = new SimpleLookupable[Unit]()
555556
}

src/test/scala/chiselTests/experimental/hierarchy/Examples.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,11 @@ object Examples {
369369
out := copy.out
370370

371371
}
372+
373+
@instantiable
374+
class HasPublicUnit extends Module {
375+
@public val x: Unit = ()
376+
// Should also work in type-parameterized lookupable things
377+
@public val y: (Data, Unit) = (Wire(UInt(3.W)), ())
378+
}
372379
}

src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,18 @@ class InstanceSpec extends ChiselFunSpec with Utils {
474474
MarkAnnotation("~Top|Top/i:HasHasTarget>sram_sram".rt, "x")
475475
)
476476
}
477+
it("(3.s): should work on Unit") {
478+
class Top extends Module {
479+
val i = Instance(Definition(new HasPublicUnit))
480+
i.x should be(())
481+
mark(i.y._1, "y_1")
482+
i.y._2 should be(())
483+
}
484+
val (_, annos) = getFirrtlAndAnnos(new Top)
485+
annos.collect { case c: MarkAnnotation => c } should contain(
486+
MarkAnnotation("~Top|Top/i:HasPublicUnit>y_1".rt, "y_1")
487+
)
488+
}
477489
}
478490
describe("(4) toInstance") {
479491
it("(4.a): should work on modules") {

0 commit comments

Comments
 (0)