Skip to content

Commit

Permalink
fixup! Add Layer Coloring to Probe Types
Browse files Browse the repository at this point in the history
  • Loading branch information
seldridge committed Jan 24, 2024
1 parent 780d07f commit bb5d02c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
15 changes: 15 additions & 0 deletions core/src/main/scala/chisel3/internal/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ package object internal {
case leaf => leaf.probeInfo.nonEmpty
}

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
}
if (!Builder.layerStack.exists(_ == destLayer))
Builder.error(errorMessage)
}

// 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
5 changes: 5 additions & 0 deletions core/src/main/scala/chisel3/probe/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ package object probe extends SourceInfoDoc {
}
requireHasProbeTypeModifier(sink, "Expected sink to be a probe.")
requireHasProbeTypeModifier(probeExpr, "Expected source to be a probe expression.")
requireCompatibleDestinationProbeColor(
sink,
if (Builder.layerStack.head == layer.Layer.Root) s"Cannot define '$sink' from outside a layerblock"
else s"Cannot define '$sink' from a layerblock associated with layer ${Builder.layerStack.head.fullName}"
)
if (sink.probeInfo.get.writable) {
requireHasWritableProbeTypeModifier(
probeExpr,
Expand Down
18 changes: 2 additions & 16 deletions firrtl/src/main/scala/firrtl/ir/IR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -539,23 +539,9 @@ object GroundType {
}
abstract class AggregateType extends Type

@data class ProbeType(underlying: Type, @since("Chisel 7") color: Option[String] = None)
extends Type
with UseSerializer {
def copy(underlying: Type = underlying): ProbeType = ProbeType(underlying, color)
}
object ProbeType {
def unapply(a: ProbeType): Some[(Type)] = Some((a.underlying))
}
final case class ProbeType(underlying: Type, color: Option[String] = None) extends Type with UseSerializer

@data class RWProbeType(underlying: Type, @since("Chisel 7") color: Option[String] = None)
extends Type
with UseSerializer {
def copy(underlying: Type = underlying): RWProbeType = RWProbeType(underlying, color)
}
object RWProbeType {
def unapply(a: RWProbeType): Some[(Type)] = Some((a.underlying))
}
final case class RWProbeType(underlying: Type, color: Option[String] = None) extends Type with UseSerializer

case class ConstType(underlying: Type) extends Type with UseSerializer

Expand Down

0 comments on commit bb5d02c

Please sign in to comment.