blob: 62ddf03ab77263095be296fd74cd4bc2130a3730 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// SPDX-License-Identifier: Apache-2.0
package firrtl
import firrtl.ir._
import Utils.trim
import firrtl.constraint.Constraint
object Implicits {
implicit def int2WInt(i: Int): WrappedInt = WrappedInt(BigInt(i))
implicit def bigint2WInt(i: BigInt): WrappedInt = WrappedInt(i)
implicit def constraint2bound(c: Constraint): Bound = c match {
case x: Bound => x
case x => CalcBound(x)
}
implicit def constraint2width(c: Constraint): Width = c match {
case Closed(x) if trim(x).isWhole => IntWidth(x.toBigInt)
case x => CalcWidth(x)
}
implicit def width2constraint(w: Width): Constraint = w match {
case CalcWidth(x: Constraint) => x
case IntWidth(x) => Closed(BigDecimal(x))
case UnknownWidth => UnknownBound
case v: Constraint => v
}
}
case class WrappedInt(value: BigInt) {
def U: Expression = UIntLiteral(value, IntWidth(Utils.getUIntWidth(value)))
def S: Expression = SIntLiteral(value, IntWidth(Utils.getSIntWidth(value)))
}
|