Skip to content

Commit

Permalink
Allow BoringUtils to use existing port in a closed module (#4484) (#4486
Browse files Browse the repository at this point in the history
)

* fix case ordering when drilling connection

* add test

(cherry picked from commit 9d58f0d)

Co-authored-by: Trevor McKay <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mergify[bot] and tmckay-sifive authored Nov 26, 2024
1 parent 648366a commit a5df567
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/scala/chisel3/util/experimental/BoringUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ object BoringUtils {
}
def drill(source: A, path: Seq[BaseModule], connectionLocation: Seq[BaseModule], up: Boolean): A = {
path.zip(connectionLocation).foldLeft(source) {
case (rhs, (module, conLoc)) if (module.isFullyClosed) => boringError(module); DontCare.asInstanceOf[A]
case (rhs, (module, _)) if (up && module == path(0) && isPort(rhs)) => {
rhs
}
case (rhs, (module, conLoc)) if (module.isFullyClosed) => boringError(module); DontCare.asInstanceOf[A]
case (rhs, (module, conLoc)) =>
skipPrefix { // so `lcaSource` isn't in the name of the secret port
if (!up && createProbe.nonEmpty && createProbe.get.writable) {
Expand Down
40 changes: 40 additions & 0 deletions src/test/scala/chiselTests/BoringUtilsTapSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -826,4 +826,44 @@ class BoringUtilsTapSpec extends ChiselFlatSpec with ChiselRunners with Utils wi
val e = the[ChiselException] thrownBy circt.stage.ChiselStage.emitCHIRRTL(new Top)
e.getMessage should include("BoringUtils currently only support identity views")
}

it should "reuse existing port in a closed module" in {
class Foo extends Module {
val io = IO(Output(UInt(32.W)))
val ioProbe = IO(probe.RWProbe(UInt(32.W)))
probe.define(ioProbe, probe.RWProbeValue(io))
io := 0.U
}

class Bar extends Module {
val foo = Module(new Foo)
val ioNames = reflect.DataMirror.modulePorts(foo).map(_._1) // close foo
val io = IO(Output(UInt(32.W)))
io := foo.io
}

class Baz extends Module {
val bar = Module(new Bar)
val reProbe = Wire(probe.RWProbe(UInt(32.W)))
probe.define(reProbe, BoringUtils.rwTap(bar.foo.ioProbe))
probe.forceInitial(reProbe, 1.U)
}

val chirrtl = circt.stage.ChiselStage.emitCHIRRTL(new Baz)
matchesAndOmits(chirrtl)(
"module Foo :",
"output io : UInt<32>",
"output ioProbe : RWProbe<UInt<32>>",
"define ioProbe = rwprobe(io)",
"module Bar :",
"inst foo of Foo",
"output bore : RWProbe<UInt<32>>",
"define bore = foo.ioProbe",
"module Baz :",
"inst bar of Bar",
"wire reProbe : RWProbe<UInt<32>>",
"define reProbe = bar.bore",
"force_initial(reProbe, UInt<32>(0h1))"
)()
}
}

0 comments on commit a5df567

Please sign in to comment.