Skip to content

Commit ef64c67

Browse files
authored
Fix boring taps of views of ExtModule ports (#5110)
1 parent 74c0d2d commit ef64c67

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

core/src/main/scala/chisel3/RawModule.scala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,7 @@ abstract class RawModule extends BaseModule {
193193
_component
194194
}
195195

196-
private[chisel3] def secretConnection(left: Data, _right: Data)(implicit si: SourceInfo): Unit = {
197-
val (right: Data, _) = chisel3.experimental.dataview
198-
.reifyIdentityView(_right)
199-
.getOrElse(
200-
throwException(s"BoringUtils currently only support identity views, ${_right} has multiple targets.")
201-
)
202-
196+
private[chisel3] def secretConnection(left: Data, right: Data)(implicit si: SourceInfo): Unit = {
203197
def computeConnection(left: Data, right: Data): Command = {
204198
(left.probeInfo.nonEmpty, right.probeInfo.nonEmpty) match {
205199
case (true, true) => ProbeDefine(si, left.lref, Node(right))

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import chisel3.probe.{Probe, RWProbe}
77
import chisel3.reflect.DataMirror
88
import chisel3.Data.ProbeInfo
99
import chisel3.experimental.{annotate, requireIsHardware, skipPrefix, BaseModule, SourceInfo}
10-
import chisel3.internal.{Builder, BuilderContextCache, NamedComponent, Namespace}
10+
import chisel3.experimental.dataview.reifyIdentityView
11+
import chisel3.internal.{throwException, Builder, BuilderContextCache, NamedComponent, Namespace}
1112
import chisel3.internal.binding.{BlockBinding, CrossModuleBinding, PortBinding, SecretPortBinding}
1213
import firrtl.transforms.{DontTouchAnnotation, NoDedupAnnotation}
1314
import chisel3.internal.firrtl.ir.Block
@@ -209,12 +210,18 @@ object BoringUtils {
209210
}
210211

211212
private def boreOrTap[A <: Data](
212-
source: A,
213+
_source: A,
213214
createProbe: Option[ProbeInfo] = None,
214215
isDrive: Boolean = false
215216
)(
216217
implicit si: SourceInfo
217218
): A = {
219+
val (source, _) =
220+
reifyIdentityView(_source)
221+
.getOrElse(
222+
throwException(s"BoringUtils currently only support identity views, ${_source} has multiple targets.")
223+
)
224+
218225
def parent(d: Data): BaseModule = d.topBinding.location.get
219226
def purePortTypeBase = if (createProbe.nonEmpty) Output(chiselTypeOf(source))
220227
else if (DataMirror.hasOuterFlip(source)) Flipped(chiselTypeOf(source))

src/test/scala-2/chiselTests/BoringUtilsTapSpec.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,34 @@ class BoringUtilsTapSpec extends AnyFlatSpec with Matchers with FileCheck {
358358
)
359359
}
360360

361+
it should "work for identity views of ExtModule ports" in {
362+
import chisel3.experimental.dataview._
363+
class Foo extends ExtModule {
364+
val out = IO(Output(Bool()))
365+
val view = out.viewAs[Bool]
366+
}
367+
class Top extends RawModule {
368+
val foo = Module(new Foo)
369+
val outProbe = IO(probe.Probe(Bool()))
370+
val out = IO(Bool())
371+
probe.define(outProbe, BoringUtils.tap(foo.view))
372+
out := BoringUtils.tapAndRead(foo.view)
373+
}
374+
ChiselStage
375+
.emitCHIRRTL(new Top, args = Array("--full-stacktrace"))
376+
.fileCheck()(
377+
"""|CHECK: extmodule Foo :
378+
|CHECK: output out : UInt<1>
379+
|CHECK: public module Top :
380+
|CHECK: output outProbe : Probe<UInt<1>>
381+
|CHECK: output out : UInt<1>
382+
|CHECK: inst foo of Foo
383+
|CHECK: define outProbe = probe(foo.out)
384+
|CHECK: connect out, foo.out
385+
|""".stripMargin
386+
)
387+
}
388+
361389
it should "NOT work [yet] for non-identity views" in {
362390
import chisel3.experimental.dataview._
363391
class MyBundle extends Bundle {

0 commit comments

Comments
 (0)