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

Add DataMirror.getLayerColor #3765

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions core/src/main/scala/chisel3/reflect/DataMirror.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ object DataMirror {
*/
def hasProbeTypeModifier(x: Data): Boolean = x.probeInfo.nonEmpty

/** Return the optional layer color of a `Data`.
* @param x the `Data` to examine
* @return a `Some[Layer]` if the data has a layer color, `None` otherwise
*/
def getLayerColor(x: Data): Option[layer.Layer] = x.probeInfo match {
case None => None
case Some(Data.ProbeInfo(_, color)) => color
}

/** Get an early guess for the name of this [[Data]]
*
* '''Warning: it is not guaranteed that this name will end up in the output FIRRTL or Verilog.'''
Expand Down
21 changes: 21 additions & 0 deletions src/test/scala/chiselTests/reflect/DataMirrorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package chiselTests.reflect

import chisel3._
import chisel3.probe.Probe
import chisel3.reflect.DataMirror
import chiselTests.ChiselFlatSpec
import circt.stage.ChiselStage
Expand Down Expand Up @@ -178,4 +179,24 @@ class DataMirrorSpec extends ChiselFlatSpec {
assert(DataMirror.isFullyAligned(UInt(8.W)))
}

"getLayerColor" should "return a layer color if one exists" in {
object A extends layer.Layer(layer.Convention.Bind)
class Foo extends Bundle {
val a = Bool()
val b = Probe(Bool())
val c = Probe(Bool(), A)
}

val foo = new Foo

info("a non-probe returns None")
DataMirror.getLayerColor(foo.a) should be(None)

info("an uncolored probe returns None")
DataMirror.getLayerColor(foo.b) should be(None)

info("a probe colored with A returns Some(A)")
DataMirror.getLayerColor(foo.c) should be(Some(A))
}

}
Loading