summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/core
diff options
context:
space:
mode:
authorRichard Lin2016-11-21 13:25:03 -0800
committerGitHub2016-11-21 13:25:03 -0800
commitcd6eb41275381a4399a8a88c886110d276bb805c (patch)
treeee1a0d87a49903cd4d3a97fce200096452104615 /chiselFrontend/src/main/scala/chisel3/core
parent822160cc8e76e70643fb56707bb39f6f7526b6fd (diff)
parente8aea3f4153b58321784ac33734305207570ef75 (diff)
Merge pull request #369 from ucb-bar/rangemacro
Add ranging API
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Bits.scala17
1 files changed, 17 insertions, 0 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
index 4a09c70e..82b60a4c 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
@@ -563,6 +563,14 @@ private[core] sealed trait UIntFactory {
result.binding = LitBinding()
result
}
+ /** Create a UInt with the specified range */
+ def apply(range: Range): UInt = {
+ width(range.getWidth)
+ }
+ /** Create a UInt with the specified range */
+ def apply(range: (NumericBound[Int], NumericBound[Int])): UInt = {
+ apply(KnownUIntRange(range._1, range._2))
+ }
/** Create a UInt with a specified width - compatibility with Chisel2. */
// NOTE: This resolves UInt(width = 32)
@@ -728,6 +736,15 @@ object SInt {
/** Create an SInt literal with specified width. */
def apply(value: BigInt, width: Width): SInt = Lit(value, width)
+ /** Create a SInt with the specified range */
+ def apply(range: Range): SInt = {
+ width(range.getWidth)
+ }
+ /** Create a SInt with the specified range */
+ def apply(range: (NumericBound[Int], NumericBound[Int])): SInt = {
+ apply(KnownSIntRange(range._1, range._2))
+ }
+
def Lit(value: BigInt): SInt = Lit(value, Width())
def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width))
/** Create an SInt literal with specified width. */