Skip to content

Commit 6e0428d

Browse files
Implement Lookupable for Unit (#4497) (#4498)
(cherry picked from commit 48866a9) Co-authored-by: Jack Koenig <[email protected]>
1 parent a5df567 commit 6e0428d

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

+1
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,5 @@ object Lookupable {
543543
implicit val lookupString: SimpleLookupable[String] = new SimpleLookupable[String]()
544544
implicit val lookupBoolean: SimpleLookupable[Boolean] = new SimpleLookupable[Boolean]()
545545
implicit val lookupBigInt: SimpleLookupable[BigInt] = new SimpleLookupable[BigInt]()
546+
implicit val lookupUnit: SimpleLookupable[Unit] = new SimpleLookupable[Unit]()
546547
}

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

+7
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

+12
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,18 @@ class InstanceSpec extends ChiselFunSpec with Utils {
449449
MarkAnnotation("~Top|Top/i:HasHasTarget>sram_mem".rt, "x")
450450
)
451451
}
452+
it("(3.s): should work on Unit") {
453+
class Top extends Module {
454+
val i = Instance(Definition(new HasPublicUnit))
455+
i.x should be(())
456+
mark(i.y._1, "y_1")
457+
i.y._2 should be(())
458+
}
459+
val (_, annos) = getFirrtlAndAnnos(new Top)
460+
annos.collect { case c: MarkAnnotation => c } should contain(
461+
MarkAnnotation("~Top|Top/i:HasPublicUnit>y_1".rt, "y_1")
462+
)
463+
}
452464
}
453465
describe("(4) toInstance") {
454466
it("(4.a): should work on modules") {

0 commit comments

Comments
 (0)