summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorducky2016-11-16 18:54:44 -0800
committerducky2016-11-21 13:31:12 -0800
commit9e32a39bda3fba11e6b0990e6ad5e7e17b5d8364 (patch)
tree7153cd0aae8e6a614b8ba9079dbdb07f0e6a778b
parente0b277a40693476247a68e7c52672b547d7ceb17 (diff)
Refactor SInt WIP
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Bits.scala36
-rw-r--r--src/main/scala/chisel3/compatibility.scala39
-rw-r--r--src/main/scala/chisel3/package.scala40
3 files changed, 73 insertions, 42 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
index 70da27fc..7e467b88 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
@@ -555,7 +555,7 @@ trait UIntFactory {
object UInt extends UIntFactory
object Bits extends UIntFactory
-sealed class SInt private (width: Width, lit: Option[SLit] = None)
+sealed class SInt private[core] (width: Width, lit: Option[SLit] = None)
extends Bits(width, lit) with Num[SInt] {
private[core] override def cloneTypeWidth(w: Width): this.type =
@@ -659,37 +659,23 @@ sealed class SInt private (width: Width, lit: Option[SLit] = None)
}
}
-object SInt {
+trait SIntFactory {
/** Create an SInt type with inferred width. */
def apply(): SInt = apply(Width())
/** Create a SInt type or port with fixed width. */
def apply(width: Width): SInt = new SInt(width)
- /** Create a SInt type or port with fixed width. */
- def width(width: Int): SInt = apply(Width(width))
- /** Create an SInt type with specified width. */
- def width(width: Width): SInt = new SInt(width)
-
- /** Create an SInt literal with inferred width. */
- def apply(value: BigInt): SInt = Lit(value)
- /** Create an SInt literal with fixed width. */
- def apply(value: BigInt, width: Int): SInt = Lit(value, width)
-
- /** 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)
+ apply(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. */
- def Lit(value: BigInt, width: Width): SInt = {
+ protected def Lit(value: BigInt, width: Width): SInt = {
val lit = SLit(value, width)
val result = new SInt(lit.width, Some(lit))
@@ -697,20 +683,6 @@ object SInt {
result.binding = LitBinding()
result
}
- /** Create a SInt with a specified width - compatibility with Chisel2. */
- def apply(dir: Option[Direction] = None, width: Int): SInt = apply(Width(width))
- /** Create a SInt with a specified direction and width - compatibility with Chisel2. */
- def apply(dir: Direction, width: Int): SInt = apply(dir, Width(width))
- /** Create a SInt with a specified direction, but unspecified width - compatibility with Chisel2. */
- def apply(dir: Direction): SInt = apply(dir, Width())
- def apply(dir: Direction, wWidth: Width): SInt = {
- val result = apply(wWidth)
- dir match {
- case Direction.Input => Input(result)
- case Direction.Output => Output(result)
- case Direction.Unspecified => result
- }
- }
}
// REVIEW TODO: Why does this extend UInt and not Bits? Does defining airth
diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala
index ac0caa45..69d02f9c 100644
--- a/src/main/scala/chisel3/compatibility.scala
+++ b/src/main/scala/chisel3/compatibility.scala
@@ -4,6 +4,8 @@
// moving to the more standard package naming convention chisel3 (lowercase c).
package object Chisel { // scalastyle:ignore package.object.name
+ import chisel3.internal.firrtl.Width
+
implicit val defaultCompileOptions = chisel3.core.ExplicitCompileOptions.NotStrict
type Direction = chisel3.core.Direction
@@ -40,8 +42,6 @@ package object Chisel { // scalastyle:ignore package.object.name
val stop = chisel3.core.stop
trait UIntFactory extends chisel3.core.UIntFactory {
- import chisel3.internal.firrtl.Width
-
/** Create a UInt literal with inferred width. */
def apply(n: String): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n),
chisel3.core.fromStringToLiteral.parsedWidth(n))
@@ -80,6 +80,39 @@ package object Chisel { // scalastyle:ignore package.object.name
def width(width: Width): UInt = apply(width)
}
+ trait SIntFactory extends chisel3.core.SIntFactory {
+ /** Create a SInt type or port with fixed width. */
+ def width(width: Int): SInt = apply(Width(width))
+ /** Create an SInt type with specified width. */
+ def width(width: Width): SInt = apply(width)
+
+ /** Create an SInt literal with inferred width. */
+ def apply(value: BigInt): SInt = Lit(value)
+ /** Create an SInt literal with fixed width. */
+ def apply(value: BigInt, width: Int): SInt = Lit(value, width)
+
+ /** Create an SInt literal with specified width. */
+ def apply(value: BigInt, width: Width): SInt = Lit(value, width)
+
+ def Lit(value: BigInt): SInt = Lit(value, Width())
+ def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width))
+
+ /** Create a SInt with a specified width - compatibility with Chisel2. */
+ def apply(dir: Option[Direction] = None, width: Int): SInt = apply(Width(width))
+ /** Create a SInt with a specified direction and width - compatibility with Chisel2. */
+ def apply(dir: Direction, width: Int): SInt = apply(dir, Width(width))
+ /** Create a SInt with a specified direction, but unspecified width - compatibility with Chisel2. */
+ def apply(dir: Direction): SInt = apply(dir, Width())
+ def apply(dir: Direction, wWidth: Width): SInt = {
+ val result = apply(wWidth)
+ dir match {
+ case chisel3.core.Direction.Input => chisel3.core.Input(result)
+ case chisel3.core.Direction.Output => chisel3.core.Output(result)
+ case chisel3.core.Direction.Unspecified => result
+ }
+ }
+ }
+
type Element = chisel3.core.Element
type Bits = chisel3.core.Bits
object Bits extends UIntFactory
@@ -87,7 +120,7 @@ package object Chisel { // scalastyle:ignore package.object.name
type UInt = chisel3.core.UInt
object UInt extends UIntFactory
type SInt = chisel3.core.SInt
- val SInt = chisel3.core.SInt
+ object SInt extends SIntFactory
type Bool = chisel3.core.Bool
val Bool = chisel3.core.Bool
val Mux = chisel3.core.Mux
diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala
index 84a4779e..1161a1ca 100644
--- a/src/main/scala/chisel3/package.scala
+++ b/src/main/scala/chisel3/package.scala
@@ -38,20 +38,20 @@ package object chisel3 { // scalastyle:ignore package.object.name
def apply(n: String): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n),
chisel3.core.fromStringToLiteral.parsedWidth(n))
/** Create a UInt literal with fixed width. */
- @deprecated("chisel3, will be removed by end of 2016, use n.U(width: Width)")
+ @deprecated("chisel3, will be removed by end of 2016, use n.U(width.W)")
def apply(n: String, width: Int): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n),
Width(width))
/** Create a UInt literal with specified width. */
- @deprecated("chisel3, will be removed by end of 2016, use value.U(width: Width)")
+ @deprecated("chisel3, will be removed by end of 2016, use value.U(width)")
def apply(value: BigInt, width: Width): UInt = Lit(value, width)
/** Create a UInt literal with fixed width. */
- @deprecated("chisel3, will be removed by end of 2016, use value.U(width: Width)")
+ @deprecated("chisel3, will be removed by end of 2016, use value.U(width.W)")
def apply(value: BigInt, width: Int): UInt = Lit(value, Width(width))
/** Create a UInt with a specified width - compatibility with Chisel2. */
- @deprecated("chisel3, will be removed by end of 2016, use UInt(width: Width)")
+ @deprecated("chisel3, will be removed by end of 2016, use UInt(width.W)")
def apply(dir: Option[Direction] = None, width: Int): UInt = apply(Width(width))
/** Create a UInt literal with inferred width.- compatibility with Chisel2. */
@@ -59,20 +59,46 @@ package object chisel3 { // scalastyle:ignore package.object.name
def apply(value: BigInt): UInt = apply(value, Width())
/** Create a UInt with a specified width */
- @deprecated("chisel3, will be removed by end of 2016, use UInt(width: Width)")
+ @deprecated("chisel3, will be removed by end of 2016, use UInt(width.W)")
def width(width: Int): UInt = apply(Width(width))
/** Create a UInt port with specified width. */
- @deprecated("chisel3, will be removed by end of 2016, use UInt(width: Width)")
+ @deprecated("chisel3, will be removed by end of 2016, use UInt(width)")
def width(width: Width): UInt = apply(width)
}
+ trait SIntFactory extends chisel3.core.SIntFactory {
+ /** Create a SInt type or port with fixed width. */
+ @deprecated("chisel3, will be removed by end of 2016, use SInt(width.W)")
+ def width(width: Int): SInt = apply(Width(width))
+ /** Create an SInt type with specified width. */
+ @deprecated("chisel3, will be removed by end of 2016, use SInt(width)")
+ def width(width: Width): SInt = apply(width)
+
+ /** Create an SInt literal with inferred width. */
+ @deprecated("chisel3, will be removed by end of 2016, use value.S")
+ def apply(value: BigInt): SInt = Lit(value)
+ /** Create an SInt literal with fixed width. */
+ @deprecated("chisel3, will be removed by end of 2016, use value.S(width.W)")
+ def apply(value: BigInt, width: Int): SInt = Lit(value, width)
+
+ /** Create an SInt literal with specified width. */
+ @deprecated("chisel3, will be removed by end of 2016, use value.S(width)")
+ def apply(value: BigInt, width: Width): SInt = Lit(value, width)
+
+ @deprecated("chisel3, will be removed by end of 2016, use value.S")
+ def Lit(value: BigInt): SInt = Lit(value, Width())
+
+ @deprecated("chisel3, will be removed by end of 2016, use value.S(width)")
+ def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width))
+ }
+
object Bits extends UIntFactory
type Num[T <: Data] = chisel3.core.Num[T]
type UInt = chisel3.core.UInt
object UInt extends UIntFactory
type SInt = chisel3.core.SInt
- val SInt = chisel3.core.SInt
+ object SInt extends SIntFactory
type FixedPoint = chisel3.core.FixedPoint
val FixedPoint = chisel3.core.FixedPoint
type Bool = chisel3.core.Bool