From 15a8d3818a1b185051b260ffc82da1fb4a60a45e Mon Sep 17 00:00:00 2001 From: ducky Date: Wed, 16 Nov 2016 18:31:24 -0800 Subject: Break out deprecated literal constructors, refactor all the things! --- src/main/scala/chisel3/compatibility.scala | 88 ++++++++++++++++-------------- 1 file changed, 46 insertions(+), 42 deletions(-) (limited to 'src/main/scala/chisel3/compatibility.scala') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index d0d2ddb4..7157b4d4 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -6,6 +6,7 @@ package object Chisel { // scalastyle:ignore package.object.name implicit val defaultCompileOptions = chisel3.core.ExplicitCompileOptions.NotStrict type Direction = chisel3.core.Direction + val INPUT = chisel3.core.Direction.Input val OUTPUT = chisel3.core.Direction.Output val NODIR = chisel3.core.Direction.Unspecified @@ -38,12 +39,51 @@ package object Chisel { // scalastyle:ignore package.object.name val assert = chisel3.core.assert val stop = chisel3.core.stop + trait UIntFactory extends chisel3.core.UIntFactory { + import chisel3.internal.firrtl.Width + + /** Create a UInt with a specified width */ + def width(width: Int): UInt = apply(Width(width)) + + /** Create a UInt literal with inferred width. */ + def apply(n: String): UInt = Lit(n) + /** Create a UInt literal with fixed width. */ + def apply(n: String, width: Int): UInt = Lit(parse(n), width) + + /** Create a UInt literal with specified width. */ + def apply(value: BigInt, width: Width): UInt = Lit(value, width) + + /** Create a UInt literal with fixed width. */ + def apply(value: BigInt, width: Int): UInt = Lit(value, Width(width)) + + /** Create a UInt with a specified width - compatibility with Chisel2. */ + // NOTE: This resolves UInt(width = 32) + def apply(dir: Option[Direction] = None, width: Int): UInt = apply(Width(width)) + /** Create a UInt literal with inferred width.- compatibility with Chisel2. */ + def apply(value: BigInt): UInt = apply(value, Width()) + /** Create a UInt with a specified direction and width - compatibility with Chisel2. */ + def apply(dir: Direction, width: Int): UInt = apply(dir, Width(width)) + /** Create a UInt with a specified direction, but unspecified width - compatibility with Chisel2. */ + def apply(dir: Direction): UInt = apply(dir, Width()) + def apply(dir: Direction, wWidth: Width): UInt = { + 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 + } + } + + /** Create a UInt port with specified width. */ + def width(width: Width): UInt = apply(width) + } + type Element = chisel3.core.Element type Bits = chisel3.core.Bits - val Bits = chisel3.core.Bits + object Bits extends UIntFactory type Num[T <: Data] = chisel3.core.Num[T] type UInt = chisel3.core.UInt - val UInt = chisel3.core.UInt + object UInt extends UIntFactory type SInt = chisel3.core.SInt val SInt = chisel3.core.SInt type Bool = chisel3.core.Bool @@ -68,46 +108,10 @@ package object Chisel { // scalastyle:ignore package.object.name val when = chisel3.core.when type WhenContext = chisel3.core.WhenContext - import chisel3.internal.firrtl.Width - /** - * These implicit classes allow one to convert scala.Int|scala.BigInt to - * Chisel.UInt|Chisel.SInt by calling .asUInt|.asSInt on them, respectively. - * The versions .asUInt(width)|.asSInt(width) are also available to explicitly - * mark a width for the new literal. - * - * Also provides .asBool to scala.Boolean and .asUInt to String - * - * Note that, for stylistic reasons, one should avoid extracting immediately - * after this call using apply, ie. 0.asUInt(1)(0) due to potential for - * confusion (the 1 is a bit length and the 0 is a bit extraction position). - * Prefer storing the result and then extracting from it. - */ - implicit class fromIntToLiteral(val x: Int) extends AnyVal { - def U: UInt = UInt(BigInt(x), Width()) // scalastyle:ignore method.name - def S: SInt = SInt(BigInt(x), Width()) // scalastyle:ignore method.name - - def asUInt(): UInt = UInt(x, Width()) - def asSInt(): SInt = SInt(x, Width()) - def asUInt(width: Int): UInt = UInt(x, width) - def asSInt(width: Int): SInt = SInt(x, width) - } - - implicit class fromBigIntToLiteral(val x: BigInt) extends AnyVal { - def U: UInt = UInt(x, Width()) // scalastyle:ignore method.name - def S: SInt = SInt(x, Width()) // scalastyle:ignore method.name - - def asUInt(): UInt = UInt(x, Width()) - def asSInt(): SInt = SInt(x, Width()) - def asUInt(width: Int): UInt = UInt(x, width) - def asSInt(width: Int): SInt = SInt(x, width) - } - implicit class fromStringToLiteral(val x: String) extends AnyVal { - def U: UInt = UInt(x) // scalastyle:ignore method.name - } - implicit class fromBooleanToLiteral(val x: Boolean) extends AnyVal { - def B: Bool = Bool(x) // scalastyle:ignore method.name - } - + implicit class fromtIntToLiteral(override val x: Int) extends chisel3.core.fromIntToLiteral(x) + implicit class fromBigIntToLiteral(override val x: BigInt) extends chisel3.core.fromBigIntToLiteral(x) + implicit class fromStringToLiteral(override val x: String) extends chisel3.core.fromStringToLiteral(x) + implicit class fromBooleanToLiteral(override val x: Boolean) extends chisel3.core.fromBooleanToLiteral(x) type BackendCompilationUtilities = chisel3.BackendCompilationUtilities val Driver = chisel3.Driver -- cgit v1.2.3 From e0b277a40693476247a68e7c52672b547d7ceb17 Mon Sep 17 00:00:00 2001 From: ducky Date: Wed, 16 Nov 2016 18:47:36 -0800 Subject: Deprecate things, split more things --- src/main/scala/chisel3/compatibility.scala | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/main/scala/chisel3/compatibility.scala') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index 7157b4d4..ac0caa45 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -42,13 +42,12 @@ package object Chisel { // scalastyle:ignore package.object.name trait UIntFactory extends chisel3.core.UIntFactory { import chisel3.internal.firrtl.Width - /** Create a UInt with a specified width */ - def width(width: Int): UInt = apply(Width(width)) - /** Create a UInt literal with inferred width. */ - def apply(n: String): UInt = Lit(n) + def apply(n: String): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n), + chisel3.core.fromStringToLiteral.parsedWidth(n)) /** Create a UInt literal with fixed width. */ - def apply(n: String, width: Int): UInt = Lit(parse(n), width) + def apply(n: String, width: Int): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n), + Width(width)) /** Create a UInt literal with specified width. */ def apply(value: BigInt, width: Width): UInt = Lit(value, width) @@ -74,6 +73,9 @@ package object Chisel { // scalastyle:ignore package.object.name } } + /** Create a UInt with a specified width */ + def width(width: Int): UInt = apply(Width(width)) + /** Create a UInt port with specified width. */ def width(width: Width): UInt = apply(width) } -- cgit v1.2.3 From 9e32a39bda3fba11e6b0990e6ad5e7e17b5d8364 Mon Sep 17 00:00:00 2001 From: ducky Date: Wed, 16 Nov 2016 18:54:44 -0800 Subject: Refactor SInt WIP --- src/main/scala/chisel3/compatibility.scala | 39 +++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/main/scala/chisel3/compatibility.scala') 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 -- cgit v1.2.3 From b0cc0c93a80aec5bed54cfb11923636c09b7e180 Mon Sep 17 00:00:00 2001 From: ducky Date: Thu, 17 Nov 2016 11:21:59 -0800 Subject: SInt conversion finished, everything builds again --- src/main/scala/chisel3/compatibility.scala | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/scala/chisel3/compatibility.scala') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index 69d02f9c..a9365ac3 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -147,6 +147,7 @@ package object Chisel { // scalastyle:ignore package.object.name implicit class fromBigIntToLiteral(override val x: BigInt) extends chisel3.core.fromBigIntToLiteral(x) implicit class fromStringToLiteral(override val x: String) extends chisel3.core.fromStringToLiteral(x) implicit class fromBooleanToLiteral(override val x: Boolean) extends chisel3.core.fromBooleanToLiteral(x) + implicit class fromIntToWidth(override val x: Int) extends chisel3.core.fromIntToWidth(x) type BackendCompilationUtilities = chisel3.BackendCompilationUtilities val Driver = chisel3.Driver -- cgit v1.2.3 From cd904da0aa0e96ba679906a3ee5dbdc068eace48 Mon Sep 17 00:00:00 2001 From: ducky Date: Thu, 17 Nov 2016 11:33:20 -0800 Subject: Restyle Bool constructors, move compatibility deprecations into compatibility package object --- src/main/scala/chisel3/compatibility.scala | 48 +++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'src/main/scala/chisel3/compatibility.scala') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index a9365ac3..9d0e266b 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -113,6 +113,22 @@ package object Chisel { // scalastyle:ignore package.object.name } } + trait BoolFactory extends chisel3.core.BoolFactory { + /** Creates Bool literal. + */ + def apply(x: Boolean): Bool = Lit(x) + + /** Create a UInt with a specified direction and width - compatibility with Chisel2. */ + def apply(dir: Direction): Bool = { + val result = apply() + 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 @@ -122,7 +138,7 @@ package object Chisel { // scalastyle:ignore package.object.name type SInt = chisel3.core.SInt object SInt extends SIntFactory type Bool = chisel3.core.Bool - val Bool = chisel3.core.Bool + object Bool extends BoolFactory val Mux = chisel3.core.Mux type BlackBox = chisel3.core.BlackBox @@ -152,9 +168,33 @@ package object Chisel { // scalastyle:ignore package.object.name type BackendCompilationUtilities = chisel3.BackendCompilationUtilities val Driver = chisel3.Driver val ImplicitConversions = chisel3.util.ImplicitConversions - val chiselMain = chisel3.compatibility.chiselMain - val throwException = chisel3.compatibility.throwException - val debug = chisel3.compatibility.debug + + object chiselMain { + import java.io.File + + def apply[T <: Module](args: Array[String], gen: () => T): Unit = + Predef.assert(false, "No more chiselMain in Chisel3") + + def run[T <: Module] (args: Array[String], gen: () => T): Unit = { + val circuit = Driver.elaborate(gen) + Driver.parseArgs(args) + val output_file = new File(Driver.targetDir + "/" + circuit.name + ".fir") + Driver.dumpFirrtl(circuit, Option(output_file)) + } + } + + @deprecated("debug doesn't do anything in Chisel3 as no pruning happens in the frontend", "chisel3") + object debug { // scalastyle:ignore object.name + def apply (arg: Data): Data = arg + } + + @throws(classOf[Exception]) + object throwException { + def apply(s: String, t: Throwable = null) = { + val xcpt = new Exception(s, t) + throw xcpt + } + } object testers { // scalastyle:ignore object.name type BasicTester = chisel3.testers.BasicTester -- cgit v1.2.3 From 54d3f8dc054e55dfbd01d1aa034169a3dabe89f2 Mon Sep 17 00:00:00 2001 From: ducky Date: Thu, 17 Nov 2016 13:01:03 -0800 Subject: Restyle a lot of test code, mainly with regex --- src/main/scala/chisel3/compatibility.scala | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/main/scala/chisel3/compatibility.scala') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index 9d0e266b..625628dd 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -41,6 +41,8 @@ package object Chisel { // scalastyle:ignore package.object.name val assert = chisel3.core.assert val stop = chisel3.core.stop + /** This contains literal constructor factory methods that are deprecated as of Chisel3. + */ trait UIntFactory extends chisel3.core.UIntFactory { /** Create a UInt literal with inferred width. */ def apply(n: String): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n), @@ -80,6 +82,8 @@ package object Chisel { // scalastyle:ignore package.object.name def width(width: Width): UInt = apply(width) } + /** This contains literal constructor factory methods that are deprecated as of Chisel3. + */ trait SIntFactory extends chisel3.core.SIntFactory { /** Create a SInt type or port with fixed width. */ def width(width: Int): SInt = apply(Width(width)) @@ -113,6 +117,8 @@ package object Chisel { // scalastyle:ignore package.object.name } } + /** This contains literal constructor factory methods that are deprecated as of Chisel3. + */ trait BoolFactory extends chisel3.core.BoolFactory { /** Creates Bool literal. */ -- cgit v1.2.3 From d89b54acc5a41dcc7498d97af314e58f6cd891c8 Mon Sep 17 00:00:00 2001 From: ducky Date: Thu, 17 Nov 2016 13:31:23 -0800 Subject: Refactor some code --- src/main/scala/chisel3/compatibility.scala | 47 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'src/main/scala/chisel3/compatibility.scala') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index 625628dd..fbe37f50 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -45,29 +45,28 @@ package object Chisel { // scalastyle:ignore package.object.name */ trait UIntFactory extends chisel3.core.UIntFactory { /** Create a UInt literal with inferred width. */ - def apply(n: String): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n), - chisel3.core.fromStringToLiteral.parsedWidth(n)) + def apply(n: String): UInt = n.asUInt /** Create a UInt literal with fixed width. */ - def apply(n: String, width: Int): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n), - Width(width)) + def apply(n: String, width: Int): UInt = n.asUInt(width.W) /** Create a UInt literal with specified width. */ - def apply(value: BigInt, width: Width): UInt = Lit(value, width) + def apply(value: BigInt, width: Width): UInt = value.asUInt(width) /** Create a UInt literal with fixed width. */ - def apply(value: BigInt, width: Int): UInt = Lit(value, Width(width)) + def apply(value: BigInt, width: Int): UInt = value.asUInt(width.W) /** Create a UInt with a specified width - compatibility with Chisel2. */ // NOTE: This resolves UInt(width = 32) - def apply(dir: Option[Direction] = None, width: Int): UInt = apply(Width(width)) + def apply(dir: Option[Direction] = None, width: Int): UInt = apply(width.W) /** Create a UInt literal with inferred width.- compatibility with Chisel2. */ - def apply(value: BigInt): UInt = apply(value, Width()) + def apply(value: BigInt): UInt = value.asUInt + /** Create a UInt with a specified direction and width - compatibility with Chisel2. */ - def apply(dir: Direction, width: Int): UInt = apply(dir, Width(width)) + def apply(dir: Direction, width: Int): UInt = apply(dir, width.W) /** Create a UInt with a specified direction, but unspecified width - compatibility with Chisel2. */ def apply(dir: Direction): UInt = apply(dir, Width()) - def apply(dir: Direction, wWidth: Width): UInt = { - val result = apply(wWidth) + def apply(dir: Direction, width: Width): UInt = { + val result = apply(width) dir match { case chisel3.core.Direction.Input => chisel3.core.Input(result) case chisel3.core.Direction.Output => chisel3.core.Output(result) @@ -76,7 +75,7 @@ package object Chisel { // scalastyle:ignore package.object.name } /** Create a UInt with a specified width */ - def width(width: Int): UInt = apply(Width(width)) + def width(width: Int): UInt = apply(width.W) /** Create a UInt port with specified width. */ def width(width: Width): UInt = apply(width) @@ -86,29 +85,29 @@ package object Chisel { // scalastyle:ignore package.object.name */ trait SIntFactory extends chisel3.core.SIntFactory { /** Create a SInt type or port with fixed width. */ - def width(width: Int): SInt = apply(Width(width)) + def width(width: Int): SInt = apply(width.W) /** 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) + def apply(value: BigInt): SInt = value.S /** Create an SInt literal with fixed width. */ - def apply(value: BigInt, width: Int): SInt = Lit(value, width) + def apply(value: BigInt, width: Int): SInt = value.S(width.W) /** Create an SInt literal with specified width. */ - def apply(value: BigInt, width: Width): SInt = Lit(value, width) + def apply(value: BigInt, width: Width): SInt = value.S(width) - def Lit(value: BigInt): SInt = Lit(value, Width()) - def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width)) + def Lit(value: BigInt): SInt = value.S + def Lit(value: BigInt, width: Int): SInt = value.S(width.W) /** Create a SInt with a specified width - compatibility with Chisel2. */ - def apply(dir: Option[Direction] = None, width: Int): SInt = apply(Width(width)) + def apply(dir: Option[Direction] = None, width: Int): SInt = apply(width.W) /** Create a SInt with a specified direction and width - compatibility with Chisel2. */ - def apply(dir: Direction, width: Int): SInt = apply(dir, Width(width)) + def apply(dir: Direction, width: Int): SInt = apply(dir, width.W) /** 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) + def apply(dir: Direction, width: Width): SInt = { + val result = apply(width) dir match { case chisel3.core.Direction.Input => chisel3.core.Input(result) case chisel3.core.Direction.Output => chisel3.core.Output(result) @@ -122,7 +121,7 @@ package object Chisel { // scalastyle:ignore package.object.name trait BoolFactory extends chisel3.core.BoolFactory { /** Creates Bool literal. */ - def apply(x: Boolean): Bool = Lit(x) + def apply(x: Boolean): Bool = x.B /** Create a UInt with a specified direction and width - compatibility with Chisel2. */ def apply(dir: Direction): Bool = { @@ -175,6 +174,7 @@ package object Chisel { // scalastyle:ignore package.object.name val Driver = chisel3.Driver val ImplicitConversions = chisel3.util.ImplicitConversions + // Deprecated as of Chisel3 object chiselMain { import java.io.File @@ -194,6 +194,7 @@ package object Chisel { // scalastyle:ignore package.object.name def apply (arg: Data): Data = arg } + // Deprecated as of Chsiel3 @throws(classOf[Exception]) object throwException { def apply(s: String, t: Throwable = null) = { -- cgit v1.2.3 From ebe7a0fb5774ec4bec919f9d3acd987d084d91b4 Mon Sep 17 00:00:00 2001 From: ducky Date: Thu, 17 Nov 2016 13:50:50 -0800 Subject: better style --- src/main/scala/chisel3/compatibility.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/main/scala/chisel3/compatibility.scala') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index fbe37f50..ff627c1e 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -90,15 +90,15 @@ package object Chisel { // scalastyle:ignore package.object.name def width(width: Width): SInt = apply(width) /** Create an SInt literal with inferred width. */ - def apply(value: BigInt): SInt = value.S + def apply(value: BigInt): SInt = value.asSInt /** Create an SInt literal with fixed width. */ - def apply(value: BigInt, width: Int): SInt = value.S(width.W) + def apply(value: BigInt, width: Int): SInt = value.asSInt(width.W) /** Create an SInt literal with specified width. */ - def apply(value: BigInt, width: Width): SInt = value.S(width) + def apply(value: BigInt, width: Width): SInt = value.asSInt(width) - def Lit(value: BigInt): SInt = value.S - def Lit(value: BigInt, width: Int): SInt = value.S(width.W) + def Lit(value: BigInt): SInt = value.asSInt + def Lit(value: BigInt, width: Int): SInt = value.asSInt(width.W) /** Create a SInt with a specified width - compatibility with Chisel2. */ def apply(dir: Option[Direction] = None, width: Int): SInt = apply(width.W) -- cgit v1.2.3 From 81e5d00d18a5ba9ae33c10219a270148002fc672 Mon Sep 17 00:00:00 2001 From: ducky Date: Fri, 18 Nov 2016 13:36:03 -0800 Subject: Deboilerplate the implicit conversions, add support for long.U --- src/main/scala/chisel3/compatibility.scala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/main/scala/chisel3/compatibility.scala') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index ff627c1e..51176d9d 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -164,11 +164,12 @@ package object Chisel { // scalastyle:ignore package.object.name val when = chisel3.core.when type WhenContext = chisel3.core.WhenContext - implicit class fromtIntToLiteral(override val x: Int) extends chisel3.core.fromIntToLiteral(x) - implicit class fromBigIntToLiteral(override val x: BigInt) extends chisel3.core.fromBigIntToLiteral(x) - implicit class fromStringToLiteral(override val x: String) extends chisel3.core.fromStringToLiteral(x) - implicit class fromBooleanToLiteral(override val x: Boolean) extends chisel3.core.fromBooleanToLiteral(x) - implicit class fromIntToWidth(override val x: Int) extends chisel3.core.fromIntToWidth(x) + implicit class fromBigIntToLiteral(val x: BigInt) extends chisel3.core.fromBigIntToLiteral(x) + implicit class fromtIntToLiteral(val x: Int) extends chisel3.core.fromIntToLiteral(x) + implicit class fromtLongToLiteral(val x: Long) extends chisel3.core.fromLongToLiteral(x) + implicit class fromStringToLiteral(val x: String) extends chisel3.core.fromStringToLiteral(x) + implicit class fromBooleanToLiteral(val x: Boolean) extends chisel3.core.fromBooleanToLiteral(x) + implicit class fromIntToWidth(val x: Int) extends chisel3.core.fromIntToWidth(x) type BackendCompilationUtilities = chisel3.BackendCompilationUtilities val Driver = chisel3.Driver -- cgit v1.2.3 From edb19a0559686a471141c74438f677c1e217a298 Mon Sep 17 00:00:00 2001 From: Richard Lin Date: Wed, 23 Nov 2016 16:01:50 -0800 Subject: Simplify Enum API (#385) Get rid of some cruft exposed in #373 This also allows Bits.fromtInt(...) to be removed. Yay! All old APIs (with some new restrictions, rocket still works fine) are preserved without deprecation in Chisel._, aside from the non-compile-time-checkable Map[] enum constructor which probably should have been deprecated during chisel2. The Map[] enums have been removed from chisel3._ without deprecation. The new restriction is that nodeType (legacy API) may only be of UInt type with unspecified width. Note that Bits() creates a UInt, and if you can't control the enum values, it makes little sense to specify a bitwidth.--- src/main/scala/chisel3/compatibility.scala | 57 +++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'src/main/scala/chisel3/compatibility.scala') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index 51176d9d..4ffd0b86 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -250,7 +250,62 @@ package object Chisel { // scalastyle:ignore package.object.name type Queue[T <: Data] = chisel3.util.Queue[T] val Queue = chisel3.util.Queue - val Enum = chisel3.util.Enum + object Enum extends chisel3.util.Enum { + /** Returns n unique values of the specified type. Can be used with unpacking to define enums. + * + * nodeType must be of UInt type (note that Bits() creates a UInt) with unspecified width. + * + * @example {{{ + * val state_on :: state_off :: Nil = Enum(UInt(), 2) + * val current_state = UInt() + * switch (current_state) { + * is (state_on) { + * ... + * } + * if (state_off) { + * ... + * } + * } + * }}} + */ + def apply[T <: Bits](nodeType: T, n: Int): List[T] = { + require(nodeType.isInstanceOf[UInt], "Only UInt supported for enums") + require(!nodeType.widthKnown, "Bit width may no longer be specified for enums") + apply(n).asInstanceOf[List[T]] + } + + /** An old Enum API that returns a map of symbols to UInts. + * + * Unlike the new list-based Enum, which can be unpacked into vals that the compiler + * understands and can check, map accesses can't be compile-time checked and typos may not be + * caught until runtime. + * + * Despite being deprecated, this is not to be removed from the compatibility layer API. + * Deprecation is only to nag users to do something safer. + */ + @deprecated("Use list-based Enum", "not soon enough") + def apply[T <: Bits](nodeType: T, l: Symbol *): Map[Symbol, T] = { + require(nodeType.isInstanceOf[UInt], "Only UInt supported for enums") + require(!nodeType.widthKnown, "Bit width may no longer be specified for enums") + (l zip createValues(l.length)).toMap.asInstanceOf[Map[Symbol, T]] + } + + /** An old Enum API that returns a map of symbols to UInts. + * + * Unlike the new list-based Enum, which can be unpacked into vals that the compiler + * understands and can check, map accesses can't be compile-time checked and typos may not be + * caught until runtime. + * + * Despite being deprecated, this is not to be removed from the compatibility layer API. + * Deprecation is only to nag users to do something safer. + */ + @deprecated("Use list-based Enum", "not soon enough") + def apply[T <: Bits](nodeType: T, l: List[Symbol]): Map[Symbol, T] = { + require(nodeType.isInstanceOf[UInt], "Only UInt supported for enums") + require(!nodeType.widthKnown, "Bit width may no longer be specified for enums") + (l zip createValues(l.length)).toMap.asInstanceOf[Map[Symbol, T]] + } + } val LFSR16 = chisel3.util.LFSR16 -- cgit v1.2.3 From 7680363982b02f53e9f76f5d5e242e44f17da6f7 Mon Sep 17 00:00:00 2001 From: Richard Lin Date: Tue, 29 Nov 2016 16:37:13 -0800 Subject: Add feature warnings to build, fix feature warnings, fix some documentation (#387) --- src/main/scala/chisel3/compatibility.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/scala/chisel3/compatibility.scala') diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index 4ffd0b86..613385af 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -120,7 +120,7 @@ package object Chisel { // scalastyle:ignore package.object.name */ trait BoolFactory extends chisel3.core.BoolFactory { /** Creates Bool literal. - */ + */ def apply(x: Boolean): Bool = x.B /** Create a UInt with a specified direction and width - compatibility with Chisel2. */ -- cgit v1.2.3