Skip to content
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
2 changes: 1 addition & 1 deletion src/main/scala/chisel3/util/BitPat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object BitPat {
*/
def apply(x: UInt): BitPat = {
val len = if (x.isWidthKnown) x.getWidth else 0
apply("b" + x.litValue.toString(2).reverse.padTo(len, "0").reverse.mkString)
apply("b" + x.litOption.getOrElse(throw new ChiselException(s"$x is not a literal, BitPat.apply(x: UInt) only accept literal")).toString(2).reverse.padTo(len, "0").reverse.mkString)
}

implicit class fromUIntToBitPatComparable(x: UInt) extends SourceInfoDoc {
Expand Down
8 changes: 8 additions & 0 deletions src/test/scala/chiselTests/util/BitPatSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class BitPatSpec extends AnyFlatSpec with Matchers {
(BitPat.Y(4) ## BitPat.dontCare(3) ## BitPat.N(2)).toString should be (s"BitPat(1111???00)")
}

it should "throw when BitPat apply to a Hardware" in {
intercept[chisel3.internal.ChiselException]{
chisel3.stage.ChiselStage.emitChirrtl(new chisel3.Module {
BitPat(chisel3.Reg(chisel3.Bool()))
})
}
}

it should "index and return new BitPat" in {
val b = BitPat("b1001???")
b(0) should be(BitPat.dontCare(1))
Expand Down