diff options
| author | azidar | 2016-08-04 15:15:00 -0700 |
|---|---|---|
| committer | azidar | 2016-08-04 15:16:37 -0700 |
| commit | 6aea3924fb48cbb4c1be217630c60be39b243ff1 (patch) | |
| tree | c9fc072f10598953f54405a3336e3079e394bfbb | |
| parent | 9b310a04c9c355c8a6f11da2e2f704fbce8f89bb (diff) | |
Addd check: bits, tail, head arg width
| -rw-r--r-- | src/main/scala/firrtl/passes/Checks.scala | 9 | ||||
| -rw-r--r-- | src/test/scala/firrtlTests/UnitTests.scala | 57 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/passes/Checks.scala b/src/main/scala/firrtl/passes/Checks.scala index 7350a8c1..8c94d737 100644 --- a/src/main/scala/firrtl/passes/Checks.scala +++ b/src/main/scala/firrtl/passes/Checks.scala @@ -690,6 +690,9 @@ object CheckWidths extends Pass { s"$info : [module $mname] Width too small for constant " + serialize(b) + ".") class NegWidthException(info:Info) extends PassException(s"${info}: [module ${mname}] Width cannot be negative or zero.") + class BitsWidthException(info: Info, hi: BigInt, width: BigInt) extends PassException(s"${info}: [module ${mname}] High bit $hi in bits operator is larger than input width $width.") + class HeadWidthException(info: Info, n: BigInt, width: BigInt) extends PassException(s"${info}: [module ${mname}] Parameter $n in head operator is larger than input width $width.") + class TailWidthException(info: Info, n: BigInt, width: BigInt) extends PassException(s"${info}: [module ${mname}] Parameter $n in tail operator is larger than input width $width.") def run (c:Circuit): Circuit = { val errors = new Errors() def check_width_m (m:DefModule) : Unit = { @@ -720,6 +723,12 @@ object CheckWidths extends Pass { } check_width_w(info)(e.width) } + case DoPrim(Bits, Seq(a), Seq(hi, lo), _) if(long_BANG(a.tpe) <= hi) => + errors.append(new BitsWidthException(info, hi, long_BANG(a.tpe))) + case DoPrim(Head, Seq(a), Seq(n), _) if(long_BANG(a.tpe) < n) => + errors.append(new HeadWidthException(info, n, long_BANG(a.tpe))) + case DoPrim(Tail, Seq(a), Seq(n), _) if(long_BANG(a.tpe) <= n) => + errors.append(new TailWidthException(info, n, long_BANG(a.tpe))) case (e:DoPrim) => false case (e) => false } diff --git a/src/test/scala/firrtlTests/UnitTests.scala b/src/test/scala/firrtlTests/UnitTests.scala index bc8db897..2d1bbdc1 100644 --- a/src/test/scala/firrtlTests/UnitTests.scala +++ b/src/test/scala/firrtlTests/UnitTests.scala @@ -232,4 +232,61 @@ class UnitTests extends FirrtlFlatSpec { ) executeTest(input, check, passes) } + + "Oversized bit select" should "throw an exception" in { + val passes = Seq( + ToWorkingIR, + ResolveKinds, + InferTypes, + ResolveGenders, + InferWidths, + CheckWidths) + val input = + """circuit Unit : + | module Unit : + | node x = bits(UInt(1), 100, 0)""".stripMargin + intercept[CheckWidths.BitsWidthException] { + passes.foldLeft(Parser.parse(input.split("\n").toIterator)) { + (c: Circuit, p: Pass) => p.run(c) + } + } + } + + "Oversized head select" should "throw an exception" in { + val passes = Seq( + ToWorkingIR, + ResolveKinds, + InferTypes, + ResolveGenders, + InferWidths, + CheckWidths) + val input = + """circuit Unit : + | module Unit : + | node x = head(UInt(1), 100)""".stripMargin + intercept[CheckWidths.HeadWidthException] { + passes.foldLeft(Parser.parse(input.split("\n").toIterator)) { + (c: Circuit, p: Pass) => p.run(c) + } + } + } + + "Oversized tail select" should "throw an exception" in { + val passes = Seq( + ToWorkingIR, + ResolveKinds, + InferTypes, + ResolveGenders, + InferWidths, + CheckWidths) + val input = + """circuit Unit : + | module Unit : + | node x = tail(UInt(1), 100)""".stripMargin + intercept[CheckWidths.TailWidthException] { + passes.foldLeft(Parser.parse(input.split("\n").toIterator)) { + (c: Circuit, p: Pass) => p.run(c) + } + } + } } |
