Skip to content

Commit

Permalink
Error when calling define targeting a child of a probe (#4175)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4de3581)

# Conflicts:
#	core/src/main/scala/chisel3/internal/package.scala
  • Loading branch information
jackkoenig authored and mergify[bot] committed Jun 14, 2024
1 parent 7ccb53e commit 4e12e77
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
38 changes: 38 additions & 0 deletions core/src/main/scala/chisel3/internal/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,44 @@ package object internal {
case leaf => leaf.probeInfo.nonEmpty
}

<<<<<<< HEAD
=======
private[chisel3] def requireCompatibleDestinationProbeColor(
dest: Data,
errorMessage: => String = ""
)(
implicit sourceInfo: SourceInfo
): Unit = {
val destLayer = dest.probeInfo match {
case Some(Data.ProbeInfo(_, Some(color))) =>
color
case _ => return
}
val enabledLayers = Builder.enabledLayers.view ++ Builder.layerStack.headOption
if (enabledLayers.exists(_.canWriteTo(destLayer))) {
return
}
Builder.error(errorMessage)
}

private[chisel3] def requireNotChildOfProbe(
probe: Data,
errorMessage: => String = ""
)(
implicit sourceInfo: SourceInfo
): Unit = {
probe.binding match {
case Some(ChildBinding(parent)) =>
if (parent.probeInfo.nonEmpty) {
val providedMsg = errorMessage // only evaluate by-name argument once
val msg = if (providedMsg.isEmpty) "Expected a root of a probe." else providedMsg
Builder.error(msg)
}
case _ => ()
}
}

>>>>>>> 4de35818c (Error when calling define targeting a child of a probe (#4175))
// TODO this exists in cats.Traverse, should we just use that?
private[chisel3] implicit class ListSyntax[A](xs: List[A]) {
def mapAccumulate[B, C](z: B)(f: (B, A) => (B, C)): (B, List[C]) = {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/chisel3/probe/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ package object probe extends SourceInfoDoc {
Builder.error("Cannot define a probe on a non-equivalent type.")
}
requireHasProbeTypeModifier(sink, "Expected sink to be a probe.")
requireNotChildOfProbe(sink, "Expected sink to be the root of a probe.")
requireHasProbeTypeModifier(probeExpr, "Expected source to be a probe expression.")
if (sink.probeInfo.get.writable) {
requireHasWritableProbeTypeModifier(
Expand Down
16 changes: 16 additions & 0 deletions src/test/scala/chiselTests/ProbeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,22 @@ class ProbeSpec extends ChiselFlatSpec with Utils {
exc.getMessage should include("Probe width unknown.")
}

it should "error trying to define a child of an Aggregate probe" in {
val exc = intercept[chisel3.ChiselException] {
ChiselStage.emitSystemVerilog(
new RawModule {
val in = IO(Input(UInt(16.W)))
val p = IO(Output(Probe(new Bundle {
val a = UInt(16.W)
})))
define(p.a, ProbeValue(in))
},
Array("--throw-on-first-error")
)
}
exc.getMessage should include("Expected sink to be the root of a probe.")
}

"Probe force/release reg example" should "work in simulator" in {
// Simple example forcing a register and checking basic behavior.

Expand Down

0 comments on commit 4e12e77

Please sign in to comment.