aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtlTests/WidthSpec.scala
diff options
context:
space:
mode:
authorJack Koenig2018-06-11 13:27:56 -0700
committerGitHub2018-06-11 13:27:56 -0700
commit535d8025412a64471d8cc9c315505a8e2cbddbe0 (patch)
tree4c52dd0a665192b55763fec2d3b47db23b561bad /src/test/scala/firrtlTests/WidthSpec.scala
parent9bd639acf58ad3a6c13b858d65845a95ddac1610 (diff)
Add utilities for UInt and SInt literals (#815)
Also minor cleanup to literal construction in Visitor
Diffstat (limited to 'src/test/scala/firrtlTests/WidthSpec.scala')
-rw-r--r--src/test/scala/firrtlTests/WidthSpec.scala24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/scala/firrtlTests/WidthSpec.scala b/src/test/scala/firrtlTests/WidthSpec.scala
index d1d02ee2..9ca965f6 100644
--- a/src/test/scala/firrtlTests/WidthSpec.scala
+++ b/src/test/scala/firrtlTests/WidthSpec.scala
@@ -22,6 +22,30 @@ class WidthSpec extends FirrtlFlatSpec {
}
}
+ case class LiteralWidthCheck(lit: BigInt, uIntWidth: Option[BigInt], sIntWidth: BigInt)
+ val litChecks = Seq(
+ LiteralWidthCheck(-4, None, 3),
+ LiteralWidthCheck(-3, None, 3),
+ LiteralWidthCheck(-2, None, 2),
+ LiteralWidthCheck(-1, None, 1),
+ LiteralWidthCheck(0, Some(1), 1), // TODO https://github.com/freechipsproject/firrtl/pull/530
+ LiteralWidthCheck(1, Some(1), 2),
+ LiteralWidthCheck(2, Some(2), 3),
+ LiteralWidthCheck(3, Some(2), 3),
+ LiteralWidthCheck(4, Some(3), 4)
+ )
+ for (LiteralWidthCheck(lit, uwo, sw) <- litChecks) {
+ import firrtl.ir.{UIntLiteral, SIntLiteral, IntWidth}
+ s"$lit" should s"have signed width $sw" in {
+ SIntLiteral(lit).width should equal (IntWidth(sw))
+ }
+ uwo.foreach { uw =>
+ it should s"have unsigned width $uw" in {
+ UIntLiteral(lit).width should equal (IntWidth(uw))
+ }
+ }
+ }
+
"Dshl by 20 bits" should "result in an error" in {
val passes = Seq(
ToWorkingIR,