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

Support isProperty query in DataMirror. (backport #3783) #3790

Merged
merged 2 commits into from
Jan 30, 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
10 changes: 10 additions & 0 deletions core/src/main/scala/chisel3/reflect/DataMirror.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import chisel3._
import chisel3.internal._
import chisel3.internal.firrtl.ir._
import chisel3.experimental.{requireIsHardware, BaseModule, SourceInfo}
import chisel3.properties.Property
import scala.reflect.ClassTag

object DataMirror {
Expand Down Expand Up @@ -51,6 +52,15 @@ object DataMirror {
*/
def isReg(x: Data): Boolean = hasBinding[RegBinding](x)

/** Check if a given `Data` is a Property
* @param x the `Data` to check
* @return `true` if x is a Property, `false` otherwise
*/
def isProperty(x: Data): Boolean = x match {
case _: Property[_] => true
case _ => false
}

/** Check if a given `Data` is a Probe
* @param x the `Data` to check
* @return `true` if x is a Probe, `false` otherwise
Expand Down
11 changes: 11 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.properties.Property
import chisel3.reflect.DataMirror
import chiselTests.ChiselFlatSpec
import circt.stage.ChiselStage
Expand Down Expand Up @@ -124,6 +125,16 @@ class DataMirrorSpec extends ChiselFlatSpec {
an[ExpectedHardwareException] should be thrownBy DataMirror.queryNameGuess(UInt(8.W))
}

it should "support querying if a Data is a Property" in {
ChiselStage.emitCHIRRTL(new RawModule {
val notProperty = IO(Input(Bool()))
val property = IO(Input(Property[Int]()))

DataMirror.isProperty(notProperty) shouldBe false
DataMirror.isProperty(property) shouldBe true
})
}

"chiselTypeClone" should "preserve Scala type information" in {
class MyModule extends Module {
val in = IO(Input(UInt(8.W)))
Expand Down
Loading