Skip to content

Commit

Permalink
Support isLit for Property types. (#3782)
Browse files Browse the repository at this point in the history
Since we override litOption to always be None, we need to override
isLit to check the Binding.
  • Loading branch information
mikeurbach authored Jan 30, 2024
1 parent d8991c5 commit 7be47bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/main/scala/chisel3/properties/Property.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ sealed trait Property[T] extends Element { self =>
}

override def litOption: Option[BigInt] = None

/** Return whether this Property is a literal.
*
* Since we override litOption to always be None, we need to override this method to check the Binding.
*/
override def isLit: Boolean = topBindingOpt match {
case Some(PropertyValueBinding) => true
case _ => false
}

def toPrintable: Printable = {
throwException(s"Properties do not support hardware printing" + this._errorContext)
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/scala/chiselTests/properties/PropertySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -607,4 +607,14 @@ class PropertySpec extends ChiselFlatSpec with MatchesAndOmits {
"propassign flatModule.prop.int, Integer(1)"
)()
}

it should "support isLit" in {
ChiselStage.emitCHIRRTL(new RawModule {
val port = IO(Input(Property[Int]()))
val lit = Property(1)

port.isLit shouldBe false
lit.isLit shouldBe true
})
}
}

0 comments on commit 7be47bb

Please sign in to comment.