summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel/package.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/chisel/package.scala')
-rw-r--r--src/main/scala/chisel/package.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/scala/chisel/package.scala b/src/main/scala/chisel/package.scala
new file mode 100644
index 00000000..1abbc74f
--- /dev/null
+++ b/src/main/scala/chisel/package.scala
@@ -0,0 +1,31 @@
+package object chisel {
+ import scala.language.experimental.macros
+
+ import internal.firrtl.Width
+ import internal.sourceinfo.{SourceInfo, SourceInfoTransform}
+
+ implicit class fromBigIntToLiteral(val x: BigInt) extends AnyVal {
+ def U: UInt = UInt(x, Width())
+ def S: SInt = SInt(x, Width())
+ }
+ implicit class fromIntToLiteral(val x: Int) extends AnyVal {
+ def U: UInt = UInt(BigInt(x), Width())
+ def S: SInt = SInt(BigInt(x), Width())
+ }
+ implicit class fromStringToLiteral(val x: String) extends AnyVal {
+ def U: UInt = UInt(x)
+ }
+ implicit class fromBooleanToLiteral(val x: Boolean) extends AnyVal {
+ def B: Bool = Bool(x)
+ }
+
+ implicit class fromUIntToBitPatComparable(val x: UInt) extends AnyVal {
+ final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg
+ final def != (that: BitPat): Bool = macro SourceInfoTransform.thatArg
+ final def =/= (that: BitPat): Bool = macro SourceInfoTransform.thatArg
+
+ def do_=== (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that === x
+ def do_!= (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that != x
+ def do_=/= (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that =/= x
+ }
+}