Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support boring on original Module after .toInstance call #4602

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,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 @@ -377,6 +377,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