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.scala8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/ir/IR.scala b/src/main/scala/firrtl/ir/IR.scala
index 3887f17d..fc741b28 100644
--- a/src/main/scala/firrtl/ir/IR.scala
+++ b/src/main/scala/firrtl/ir/IR.scala
@@ -161,6 +161,10 @@ case class UIntLiteral(value: BigInt, width: Width) extends Literal {
def mapType(f: Type => Type): Expression = this
def mapWidth(f: Width => Width): Expression = UIntLiteral(value, f(width))
}
+object UIntLiteral {
+ def minWidth(value: BigInt): Width = IntWidth(math.max(value.bitLength, 1))
+ def apply(value: BigInt): UIntLiteral = new UIntLiteral(value, minWidth(value))
+}
case class SIntLiteral(value: BigInt, width: Width) extends Literal {
def tpe = SIntType(width)
def serialize = s"""SInt${width.serialize}("h""" + value.toString(16)+ """")"""
@@ -168,6 +172,10 @@ case class SIntLiteral(value: BigInt, width: Width) extends Literal {
def mapType(f: Type => Type): Expression = this
def mapWidth(f: Width => Width): Expression = SIntLiteral(value, f(width))
}
+object SIntLiteral {
+ def minWidth(value: BigInt): Width = IntWidth(value.bitLength + 1)
+ def apply(value: BigInt): SIntLiteral = new SIntLiteral(value, minWidth(value))
+}
case class FixedLiteral(value: BigInt, width: Width, point: Width) extends Literal {
def tpe = FixedType(width, point)
def serialize = {