Skip to content

Commit

Permalink
Support boring on original Module after .toInstance call (#4602)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4d162c4)
  • Loading branch information
jackkoenig authored and mergify[bot] committed Jan 9, 2025
1 parent 158d66b commit 54d9991
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ object Lookupable {
def getIoMap(hierarchy: Hierarchy[_]): Option[Map[Data, Data]] = {
hierarchy.underlying match {
case Clone(x: ModuleClone[_]) => Some(x.ioMap)
case Proto(x: BaseModule) => Some(x.getChiselPorts.map { case (_, data: Data) => data -> data }.toMap)
case Proto(x: BaseModule) => Some(x.getIOs.map { data => data -> data }.toMap)
case Clone(x: InstantiableClone[_]) => getIoMap(x._innerContext)
case Clone(x: InstanceClone[_]) => None
case other => {
Expand Down
29 changes: 29 additions & 0 deletions src/test/scala/chiselTests/BoringUtilsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,35 @@ class BoringUtilsSpec extends ChiselFlatSpec with ChiselRunners with Utils with
log should include("Can only bore into modules that are not fully closed")
}

it should "support boring on a Module even after .toInstance (and accessing a port)" in {
import chisel3.experimental.hierarchy._
@instantiable
class Bar extends RawModule {
@public val port = IO(Output(UInt(8.W)))
val a_wire = WireInit(UInt(1.W), DontCare)
}
class Foo extends RawModule {
val bar = Module(new Bar)
val bi = bar.toInstance
val x = BoringUtils.bore(bar.a_wire)
val p = bi.port // Previously, the lookup here would close the module due to reflecting on the IOs of bar
val y = BoringUtils.bore(bar.a_wire)
}

generateFirrtlAndFileCheck(new Foo)(
"""|CHECK-LABEL: module Bar :
|CHECK: output port : UInt<8>
|CHECK: output x_bore : UInt<1>
|CHECK: output y_bore : UInt<1>
|CHECK: connect x_bore, a_wire
|CHECK: connect y_bore, a_wire
|CHECK-LABEL: module Foo :
|CHECK: connect x, bar.x_bore
|CHECK: connect y, bar.y_bore
|""".stripMargin
)
}

it should "not create a new port when source is a port" in {
class Baz extends RawModule {
val a = IO(Output(Bool()))
Expand Down

0 comments on commit 54d9991

Please sign in to comment.