diff options
| author | Jack Koenig | 2018-06-11 13:27:56 -0700 |
|---|---|---|
| committer | GitHub | 2018-06-11 13:27:56 -0700 |
| commit | 535d8025412a64471d8cc9c315505a8e2cbddbe0 (patch) | |
| tree | 4c52dd0a665192b55763fec2d3b47db23b561bad /src/main/scala/firrtl/ir | |
| parent | 9bd639acf58ad3a6c13b858d65845a95ddac1610 (diff) | |
Add utilities for UInt and SInt literals (#815)
Also minor cleanup to literal construction in Visitor
Diffstat (limited to 'src/main/scala/firrtl/ir')
| -rw-r--r-- | src/main/scala/firrtl/ir/IR.scala | 8 |
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 = { |
