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

BoringUtils: Fix tapAndRead to return same type even when not boring. #4084

Merged
merged 1 commit into from
May 23, 2024
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
6 changes: 6 additions & 0 deletions src/main/scala/chisel3/util/experimental/BoringUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ object BoringUtils {
}
if (parent(source) == thisModule) {
// No boring to do
if (createProbe.nonEmpty && !DataMirror.isFullyAligned(source)) {
// Create aligned wire if source isn't aligned. This ensures result has same type regardless of origin.
val bore = Wire(purePortTypeBase)
bore :#= source
return bore
}
return source
}

Expand Down
23 changes: 23 additions & 0 deletions src/test/scala/chiselTests/BoringUtilsTapSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,29 @@ class BoringUtilsTapSpec extends ChiselFlatSpec with ChiselRunners with Utils wi
val verilog = circt.stage.ChiselStage.emitSystemVerilog(new Foo)
}

it should "work with DecoupledIO locally" in {
import chisel3.util.{Decoupled, DecoupledIO}
class Foo extends RawModule {
val a = WireInit(DecoupledIO(Bool()), DontCare)
val b = BoringUtils.tapAndRead(a)
assert(chisel3.reflect.DataMirror.isFullyAligned(b), "tapAndRead should always return passive data")
}

val chirrtl = circt.stage.ChiselStage.emitCHIRRTL(new Foo, Array("--full-stacktrace"))

matchesAndOmits(chirrtl)(
"module Foo :",
"wire a : { flip ready : UInt<1>, valid : UInt<1>, bits : UInt<1>}",
"wire b : { ready : UInt<1>, valid : UInt<1>, bits : UInt<1>}",
"connect b.bits, a.bits",
"connect b.valid, a.valid",
"connect b.ready, a.ready"
)()

// Check that firtool also passes
val verilog = circt.stage.ChiselStage.emitSystemVerilog(new Foo)
}

it should "allow tapping a probe" in {
class Bar extends RawModule {
val a = IO(probe.Probe(Bool()))
Expand Down
Loading