summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/util/BitPat.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/chisel3/util/BitPat.scala')
-rw-r--r--src/main/scala/chisel3/util/BitPat.scala24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main/scala/chisel3/util/BitPat.scala b/src/main/scala/chisel3/util/BitPat.scala
index 6cba497e..b8a239d0 100644
--- a/src/main/scala/chisel3/util/BitPat.scala
+++ b/src/main/scala/chisel3/util/BitPat.scala
@@ -4,10 +4,10 @@ package chisel3.util
import scala.language.experimental.macros
import chisel3._
-import chisel3.core.CompileOptions
import chisel3.internal.chiselRuntimeDeprecated
import chisel3.internal.sourceinfo.{SourceInfo, SourceInfoTransform}
+
object BitPat {
/** Parses a bit pattern string into (bits, mask, width).
*
@@ -77,6 +77,28 @@ object BitPat {
val len = if (x.isWidthKnown) x.getWidth else 0
apply("b" + x.litValue.toString(2).reverse.padTo(len, "0").reverse.mkString)
}
+
+ implicit class fromUIntToBitPatComparable(x: UInt) extends SourceInfoDoc {
+ import internal.sourceinfo.{SourceInfo, SourceInfoTransform}
+
+ import scala.language.experimental.macros
+
+ final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg
+ final def =/= (that: BitPat): Bool = macro SourceInfoTransform.thatArg
+
+ /** @group SourceInfoTransformMacro */
+ def do_=== (that: BitPat) // scalastyle:ignore method.name
+ (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = that === x
+ /** @group SourceInfoTransformMacro */
+ def do_=/= (that: BitPat) // scalastyle:ignore method.name
+ (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = that =/= x
+
+ final def != (that: BitPat): Bool = macro SourceInfoTransform.thatArg
+ @chiselRuntimeDeprecated
+ @deprecated("Use '=/=', which avoids potential precedence problems", "chisel3")
+ def do_!= (that: BitPat) // scalastyle:ignore method.name
+ (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = that != x
+ }
}
/** Bit patterns are literals with masks, used to represent values with don't