aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/Utils.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/firrtl/Utils.scala')
-rw-r--r--src/main/scala/firrtl/Utils.scala11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala
index 3d0f19b8..a58b6997 100644
--- a/src/main/scala/firrtl/Utils.scala
+++ b/src/main/scala/firrtl/Utils.scala
@@ -51,7 +51,18 @@ object getWidth {
def apply(e: Expression): Width = apply(e.tpe)
}
+/**
+ * Helper object for computing the width of a firrtl type.
+ */
object bitWidth {
+
+ /**
+ * Compute the width of a firrtl type.
+ * For example, a Vec of 4 UInts of width 8 should have a width of 32.
+ *
+ * @param dt firrtl type
+ * @return Width of the given type
+ */
def apply(dt: Type): BigInt = widthOf(dt)
private def widthOf(dt: Type): BigInt = dt match {
case t: VectorType => t.size * bitWidth(t.tpe)