diff options
| author | Chick Markley | 2019-12-11 14:17:24 -0800 |
|---|---|---|
| committer | GitHub | 2019-12-11 14:17:24 -0800 |
| commit | 954cc41e1349d0df6d2250d6270590340cd36e82 (patch) | |
| tree | fb7eb67a0344db258530d1359ef470781093ea92 | |
| parent | 69ae14b485c67834ad3c9c518ef080cf75ce9b1d (diff) | |
| parent | 7c7b6f28adfdc2eeb223aaa8cbb904ae90bf36fe (diff) | |
Merge pull request #1274 from freechipsproject/interval-fix-1
Bug fixes to support code for Interval
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala | 5 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/IntervalRangeSpec.scala | 17 |
2 files changed, 20 insertions, 2 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala b/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala index bc662ddb..e76a8d60 100644 --- a/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala +++ b/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala @@ -9,6 +9,7 @@ import chisel3.experimental._ import _root_.firrtl.{ir => firrtlir} import _root_.firrtl.PrimOps +import scala.collection.immutable.NumericRange import scala.math.BigDecimal.RoundingMode // scalastyle:off number.of.types @@ -432,7 +433,7 @@ sealed class IntervalRange( val getHighestPossibleValue: Option[BigDecimal] = { increment match { case Some(inc) => - lower match { + upper match { case firrtlir.Closed(n) => Some(n) case firrtlir.Open(n) => Some(n - inc) case _ => None @@ -446,7 +447,7 @@ sealed class IntervalRange( * Mostly to be used for testing * @return */ - def getPossibleValues: Seq[BigDecimal] = { + def getPossibleValues: NumericRange[BigDecimal] = { (getLowestPossibleValue, getHighestPossibleValue, increment) match { case (Some(low), Some(high), Some(inc)) => (low to high by inc) case (_, _, None) => diff --git a/src/test/scala/chiselTests/IntervalRangeSpec.scala b/src/test/scala/chiselTests/IntervalRangeSpec.scala index c152e72d..f1daa228 100644 --- a/src/test/scala/chiselTests/IntervalRangeSpec.scala +++ b/src/test/scala/chiselTests/IntervalRangeSpec.scala @@ -216,6 +216,23 @@ class IntervalRangeSpec extends FreeSpec with Matchers { checkRange(range"[-7.875,7.875].3".setPrecision(1.BP), C(-8.0), C(7.5), 1.BP) } } + + "get possible values should return all values from high to low" in { + var range = range"[0,4]" + range.getLowestPossibleValue should be (Some(0)) + range.getHighestPossibleValue should be (Some(4)) + range.getPossibleValues should be (Seq(0, 1, 2, 3, 4)) + + range = range"(0,4)" + range.getLowestPossibleValue should be (Some(1)) + range.getHighestPossibleValue should be (Some(3)) + range.getPossibleValues should be (Seq(1, 2, 3)) + + range = range"(-1,4).1" + range.getLowestPossibleValue should be (Some(-0.5)) + range.getHighestPossibleValue should be (Some(3.5)) + range.getPossibleValues should be (Seq(-0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5)) + } } } |
