aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/ir/IR.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/firrtl/ir/IR.scala')
-rw-r--r--src/main/scala/firrtl/ir/IR.scala9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/ir/IR.scala b/src/main/scala/firrtl/ir/IR.scala
index 275cbe51..023f53fd 100644
--- a/src/main/scala/firrtl/ir/IR.scala
+++ b/src/main/scala/firrtl/ir/IR.scala
@@ -297,6 +297,15 @@ case class UIntLiteral(value: BigInt, width: Width) extends Literal {
object UIntLiteral {
def minWidth(value: BigInt): Width = IntWidth(math.max(value.bitLength, 1))
def apply(value: BigInt): UIntLiteral = new UIntLiteral(value, minWidth(value))
+
+ /** Utility to construct UIntLiterals masked by the width
+ *
+ * This supports truncating negative values as well as values that are too wide for the width
+ */
+ def masked(value: BigInt, width: IntWidth): UIntLiteral = {
+ val mask = (BigInt(1) << width.width.toInt) - 1
+ UIntLiteral(value & mask, width)
+ }
}
case class SIntLiteral(value: BigInt, width: Width) extends Literal {
def tpe = SIntType(width)