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.

(cherry picked from commit 7be47bb)
  • Loading branch information
mikeurbach authored and mergify[bot] committed Jan 30, 2024
1 parent fe98d41 commit d978f38
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 d978f38

Please sign in to comment.