summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/RangeSpec.scala
diff options
context:
space:
mode:
authorChick Markley2019-10-18 19:44:08 -0700
committerAdam Izraelevitz2019-10-18 19:44:08 -0700
commit7b93b0f8c48e39cc9730cf9f91340cf733dadafe (patch)
tree3e9666c29d6c9901f221fed4728d05b9fd75067e /src/test/scala/chiselTests/RangeSpec.scala
parentfafd984a923591841917cd4c3a1f4c823dc485b4 (diff)
Interval Data Type Support for Chisel (#1210)
Plan to be released with 3.3. Breaks experimental Range API. Adds new Interval type and associated support. This commit adds the following: - Renamed Range to IntervalRange to avoid name collision with scala Range - Changed RangeTransform macro to Return an IntervalRange - Improved error messages on missing comma or decimal - Added notational support for binary point - Some formatting cleanup also - SIntFactory - Change to use IntervalRange API - UIntFactory - UInt from range has custom width computation - It does not need to deal with lowerbound extending bit requirements - Code to handle special case of range"[0,0]" to have a width of 1 - IR.scala - Removed Bound and other constraint code that was duplicating firrtl stuff - Added new RangeType - Added IntervalRange class and object - RangeSpec - modified just a bit to handle notational differences - previous range interpolator returned tuple now returns IntervalRange - Add IntervalType to emitter - Added IntervalSpec with many tests - Added ScalaIntervalSimulatorSpec which tests golden model for Interval - Added ScalaIntervalSimulator which is a golden model for Interval - This gold may not have been polished to a high sheen - Add IntervalLit cases to Converter - Add Interval PrimOps to IR - asInterval, wrap, squz, clip, setp, decp, incp - Add IntervalLit class to IR - Add Interval to MonoConnect - Add Interval Type to Bits (in experimental package) - add conversions to Interval from other types - Add Interval clone stuff to Data - Add Literal creation helpers to chisel3 package - these may move to experimental if I can figure that out
Diffstat (limited to 'src/test/scala/chiselTests/RangeSpec.scala')
-rw-r--r--src/test/scala/chiselTests/RangeSpec.scala98
1 files changed, 3 insertions, 95 deletions
diff --git a/src/test/scala/chiselTests/RangeSpec.scala b/src/test/scala/chiselTests/RangeSpec.scala
index e2313f34..e85a477d 100644
--- a/src/test/scala/chiselTests/RangeSpec.scala
+++ b/src/test/scala/chiselTests/RangeSpec.scala
@@ -4,101 +4,9 @@ package chiselTests
import chisel3._
import chisel3.experimental.ChiselRange
-
-import chisel3.internal.firrtl.{Open, Closed}
-import org.scalatest.{Matchers, FreeSpec}
+import chisel3.internal.firrtl._
+import firrtl.ir.{Closed, Open}
+import org.scalatest.{FreeSpec, Matchers}
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)) )
-
- def number(n: Int): Int = n
- range"[${number(1)}, ${number(3)})" should be( (Closed(1), Open(3)) )
- }
-
- "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)
- }
-
- "UInt should check that the range is valid" in {
- 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)")
- }
- an [IllegalArgumentException] should be thrownBy {
- SInt(range"(0,1)")
- }
- }
- }
}