Skip to content

Commit 9d58f0d

Browse files
Allow BoringUtils to use existing port in a closed module (#4484)
* fix case ordering when drilling connection * add test
1 parent a7a68e5 commit 9d58f0d

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/main/scala/chisel3/util/experimental/BoringUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ object BoringUtils {
257257
}
258258
def drill(source: A, path: Seq[BaseModule], connectionLocation: Seq[BaseModule], up: Boolean): A = {
259259
path.zip(connectionLocation).foldLeft(source) {
260-
case (rhs, (module, conLoc)) if (module.isFullyClosed) => boringError(module); DontCare.asInstanceOf[A]
261260
case (rhs, (module, _)) if ((up || isDriveDone(rhs)) && module == path(0) && isPort(rhs)) => {
262261
rhs
263262
}
263+
case (rhs, (module, conLoc)) if (module.isFullyClosed) => boringError(module); DontCare.asInstanceOf[A]
264264
case (rhs, (module, conLoc)) =>
265265
skipPrefix { // so `lcaSource` isn't in the name of the secret port
266266
if (!up && createProbe.nonEmpty && createProbe.get.writable) {

src/test/scala/chiselTests/BoringUtilsTapSpec.scala

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,4 +922,44 @@ class BoringUtilsTapSpec extends ChiselFlatSpec with ChiselRunners with Utils wi
922922
val e = the[ChiselException] thrownBy circt.stage.ChiselStage.emitCHIRRTL(new Top)
923923
e.getMessage should include("BoringUtils currently only support identity views")
924924
}
925+
926+
it should "reuse existing port in a closed module" in {
927+
class Foo extends Module {
928+
val io = IO(Output(UInt(32.W)))
929+
val ioProbe = IO(probe.RWProbe(UInt(32.W)))
930+
probe.define(ioProbe, probe.RWProbeValue(io))
931+
io := 0.U
932+
}
933+
934+
class Bar extends Module {
935+
val foo = Module(new Foo)
936+
val ioNames = reflect.DataMirror.modulePorts(foo).map(_._1) // close foo
937+
val io = IO(Output(UInt(32.W)))
938+
io := foo.io
939+
}
940+
941+
class Baz extends Module {
942+
val bar = Module(new Bar)
943+
val reProbe = Wire(probe.RWProbe(UInt(32.W)))
944+
probe.define(reProbe, BoringUtils.rwTap(bar.foo.ioProbe))
945+
probe.forceInitial(reProbe, 1.U)
946+
}
947+
948+
val chirrtl = circt.stage.ChiselStage.emitCHIRRTL(new Baz)
949+
matchesAndOmits(chirrtl)(
950+
"module Foo :",
951+
"output io : UInt<32>",
952+
"output ioProbe : RWProbe<UInt<32>>",
953+
"define ioProbe = rwprobe(io)",
954+
"module Bar :",
955+
"inst foo of Foo",
956+
"output bore : RWProbe<UInt<32>>",
957+
"define bore = foo.ioProbe",
958+
"module Baz :",
959+
"inst bar of Bar",
960+
"wire reProbe : RWProbe<UInt<32>>",
961+
"define reProbe = bar.bore",
962+
"force_initial(reProbe, UInt<32>(0h1))"
963+
)()
964+
}
925965
}

0 commit comments

Comments
 (0)