diff options
| author | ducky | 2016-11-16 18:54:44 -0800 |
|---|---|---|
| committer | ducky | 2016-11-21 13:31:12 -0800 |
| commit | 9e32a39bda3fba11e6b0990e6ad5e7e17b5d8364 (patch) | |
| tree | 7153cd0aae8e6a614b8ba9079dbdb07f0e6a778b /src | |
| parent | e0b277a40693476247a68e7c52672b547d7ceb17 (diff) | |
Refactor SInt WIP
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/chisel3/compatibility.scala | 39 | ||||
| -rw-r--r-- | src/main/scala/chisel3/package.scala | 40 |
2 files changed, 69 insertions, 10 deletions
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 |
