diff options
| author | ducky | 2016-11-16 15:23:36 -0800 |
|---|---|---|
| committer | ducky | 2016-11-21 12:48:10 -0800 |
| commit | 876bc32feca6bd0a2aaec7019fd3d29675ce0255 (patch) | |
| tree | 9598426ff507c096340e37fcf9cd1e75f41e5318 /src | |
| parent | 2db9bc81015000b5ee4581dc57c0f339ae9f9329 (diff) | |
Fix open-open range specifier, remove dead code, restyle tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/chisel3/package.scala | 5 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/RangeSpec.scala | 58 |
2 files changed, 29 insertions, 34 deletions
diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 436534e1..b49f6dec 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -1,10 +1,9 @@ - // See LICENSE for license details. package object chisel3 { // scalastyle:ignore package.object.name import scala.language.experimental.macros - import internal.firrtl.Width + import internal.firrtl.{Width, NumericBound} import internal.sourceinfo.{SourceInfo, SourceInfoTransform} import util.BitPat @@ -12,8 +11,6 @@ package object chisel3 { // scalastyle:ignore package.object.name import chisel3.util._ import chisel3.internal.firrtl.Port - import chisel3.internal.firrtl.NumericBound - type Direction = chisel3.core.Direction val Input = chisel3.core.Input val Output = chisel3.core.Output diff --git a/src/test/scala/chiselTests/RangeSpec.scala b/src/test/scala/chiselTests/RangeSpec.scala index cbac4d4c..565d304d 100644 --- a/src/test/scala/chiselTests/RangeSpec.scala +++ b/src/test/scala/chiselTests/RangeSpec.scala @@ -8,40 +8,52 @@ import org.scalatest.{Matchers, FreeSpec} class RangeSpec extends FreeSpec with Matchers { "Ranges can be specified for UInt, SInt, and FixedPoint" - { + "invalid range specifiers should fail at compile time" in { + assertDoesNotCompile(""" range"" """) + assertDoesNotCompile(""" range"[]" """) + assertDoesNotCompile(""" range"0" """) + assertDoesNotCompile(""" range"[0]" """) + assertDoesNotCompile(""" range"[0, 1" """) + assertDoesNotCompile(""" range"0, 1]" """) + assertDoesNotCompile(""" range"[0, 1, 2]" """) + assertDoesNotCompile(""" range"[a]" """) + assertDoesNotCompile(""" range"[a, b]" """) + assertCompiles(""" range"[0, 1]" """) // syntax sanity check + } + "range macros should allow open and closed bounds" in { range"[-1, 1)" should be( (Closed(-1), Open(1)) ) - range"[-1, 1]" should be( (Closed(-1), Closed(1)) ) - range"(-1, 1]" should be( (Open(-1), Closed(1)) ) - range"(-1, 1)" should be( (Open(-1), Open(1)) ) } + + "range specifiers should be whitespace tolerant" in { + range"[-1,1)" should be( (Closed(-1), Open(1)) ) + range" [-1,1) " should be( (Closed(-1), Open(1)) ) + range" [ -1 , 1 ) " should be( (Closed(-1), Open(1)) ) + range" [ -1 , 1 ) " should be( (Closed(-1), Open(1)) ) + } + "range macros should work with interpolated variables" in { val a = 10 val b = -3 range"[$b, $a)" should be( (Closed(b), Open(a)) ) - range"[${a + b}, $a)" should be( (Closed(a + b), Open(a)) ) - range"[${-3 - 7}, ${-3 + a})" should be( (Closed(-10), Open(-3 + a)) ) } + "UInt should get the correct width from a range" in { UInt(range"[0, 8)").getWidth should be (3) - UInt(range"[0, 8]").getWidth should be (4) - UInt(range"[0, 0]").getWidth should be (1) } "SInt should get the correct width from a range" in { SInt(range"[0, 8)").getWidth should be (4) - SInt(range"[0, 8]").getWidth should be (5) - SInt(range"[-4, 4)").getWidth should be (3) - SInt(range"[0, 0]").getWidth should be (1) } @@ -49,53 +61,39 @@ class RangeSpec extends FreeSpec with Matchers { an [IllegalArgumentException] should be thrownBy { UInt(range"[1, 0]") } - an [IllegalArgumentException] should be thrownBy { UInt(range"[-1, 1]") } - an [IllegalArgumentException] should be thrownBy { UInt(range"(0,0]") } - an [IllegalArgumentException] should be thrownBy { UInt(range"[0,0)") } - an [IllegalArgumentException] should be thrownBy { UInt(range"(0,0)") } + an [IllegalArgumentException] should be thrownBy { + UInt(range"(0,1)") + } } "SInt should check that the range is valid" in { an [IllegalArgumentException] should be thrownBy { SInt(range"[1, 0]") } - an [IllegalArgumentException] should be thrownBy { SInt(range"(0,0]") } - an [IllegalArgumentException] should be thrownBy { SInt(range"[0,0)") } - an [IllegalArgumentException] should be thrownBy { SInt(range"(0,0)") } - } - - "Invalid range specifiers should fail at compile time" in { - assertDoesNotCompile(""" range"" """) - assertDoesNotCompile(""" range"[]" """) - assertDoesNotCompile(""" range"0" """) - assertDoesNotCompile(""" range"[0]" """) - assertDoesNotCompile(""" range"[0, 1" """) - assertDoesNotCompile(""" range"0, 1]" """) - assertDoesNotCompile(""" range"[0, 1, 2]" """) - assertDoesNotCompile(""" range"[a]" """) - assertDoesNotCompile(""" range"[a, b]" """) - assertCompiles(""" range"[0, 1]" """) // syntax sanity check + an [IllegalArgumentException] should be thrownBy { + SInt(range"(0,1)") + } } } } |
