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