summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/scala/chisel3/util/BitPat.scala7
-rw-r--r--src/test/scala/chiselTests/util/BitPatSpec.scala17
2 files changed, 24 insertions, 0 deletions
diff --git a/src/main/scala/chisel3/util/BitPat.scala b/src/main/scala/chisel3/util/BitPat.scala
index 12a421a0..5a40d312 100644
--- a/src/main/scala/chisel3/util/BitPat.scala
+++ b/src/main/scala/chisel3/util/BitPat.scala
@@ -119,4 +119,11 @@ sealed class BitPat(val value: BigInt, val mask: BigInt, width: Int) extends Sou
!(this === that)
}
+ override def toString = {
+ "BitPat(" +
+ (0 until width).map(i =>
+ if (((mask >> i) & 1) == 1) if (((value >> i) & 1) == 1) "1" else "0" else "?"
+ ).reverse.reduce(_ + _) +
+ ")"
+ }
}
diff --git a/src/test/scala/chiselTests/util/BitPatSpec.scala b/src/test/scala/chiselTests/util/BitPatSpec.scala
new file mode 100644
index 00000000..a6c0acf7
--- /dev/null
+++ b/src/test/scala/chiselTests/util/BitPatSpec.scala
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package chiselTests.util
+
+import chisel3.util.BitPat
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+
+class BitPatSpec extends AnyFlatSpec with Matchers {
+ behavior of classOf[BitPat].toString
+
+ it should "convert a BitPat to readable form" in {
+ val testPattern = "0" * 32 + "1" * 32 + "?" * 32 + "?01" * 32
+ BitPat("b" + testPattern).toString should be (s"BitPat($testPattern)")
+ }
+}