From 822160cc8e76e70643fb56707bb39f6f7526b6fd Mon Sep 17 00:00:00 2001 From: jackkoenig Date: Thu, 22 Sep 2016 22:38:33 -0700 Subject: Add support for parameterized BlackBoxes Also restrict black boxes to not allow hardware inside of them since it was being silently dropped anyway. Resolves #289 --- src/main/scala/chisel3/package.scala | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index e0364868..3cdda971 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -179,4 +179,28 @@ package object chisel3 { // scalastyle:ignore package.object.name } def getModulePorts(m: Module): Seq[Port] = m.getPorts def getFirrtlDirection(d: Data): Direction = chisel3.core.Data.getFirrtlDirection(d) + + /** Package for experimental features, which may have their API changed, be removed, etc. + * + * Because its contents won't necessarily have the same level of stability and support as + * non-experimental, you must explicitly import this package to use its contents. + */ + object experimental { + type Param = chisel3.core.Param + type IntParam = chisel3.core.IntParam + val IntParam = chisel3.core.IntParam + type DoubleParam = chisel3.core.DoubleParam + val DoubleParam = chisel3.core.DoubleParam + type StringParam = chisel3.core.StringParam + val StringParam = chisel3.core.StringParam + type RawParam = chisel3.core.RawParam + val RawParam = chisel3.core.RawParam + + // Implicit conversions for BlackBox Parameters + implicit def fromIntToIntParam(x: Int): IntParam = IntParam(BigInt(x)) + implicit def fromLongToIntParam(x: Long): IntParam = IntParam(BigInt(x)) + implicit def fromBigIntToIntParam(x: BigInt): IntParam = IntParam(x) + implicit def fromDoubleToDoubleParam(x: Double): DoubleParam = DoubleParam(x) + implicit def fromStringToStringParam(x: String): StringParam = StringParam(x) + } } -- cgit v1.2.3 From 22406a589c4a3f8de42a9f5c988201f474c11282 Mon Sep 17 00:00:00 2001 From: chick Date: Wed, 9 Nov 2016 16:23:52 -0800 Subject: simple test that range interpolator works with UInt factory method --- src/main/scala/chisel3/package.scala | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 3cdda971..436534e1 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -1,3 +1,4 @@ + // See LICENSE for license details. package object chisel3 { // scalastyle:ignore package.object.name @@ -11,6 +12,8 @@ package object chisel3 { // scalastyle:ignore package.object.name import chisel3.util._ import chisel3.internal.firrtl.Port + import chisel3.internal.firrtl.NumericBound + type Direction = chisel3.core.Direction val Input = chisel3.core.Input val Output = chisel3.core.Output @@ -156,6 +159,10 @@ package object chisel3 { // scalastyle:ignore package.object.name def F(binaryPoint: Int): FixedPoint = FixedPoint.fromDouble(x, binaryPoint = binaryPoint) } + implicit class ChiselRange(val sc: StringContext) extends AnyVal { + def range(args: Any*): (NumericBound[Int], NumericBound[Int]) = macro chisel3.internal.RangeTransform.apply + } + implicit class fromUIntToBitPatComparable(val x: UInt) extends AnyVal { final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg @deprecated("Use '=/=', which avoids potential precedence problems", "chisel3") -- cgit v1.2.3 From 876bc32feca6bd0a2aaec7019fd3d29675ce0255 Mon Sep 17 00:00:00 2001 From: ducky Date: Wed, 16 Nov 2016 15:23:36 -0800 Subject: Fix open-open range specifier, remove dead code, restyle tests --- src/main/scala/chisel3/package.scala | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 436534e1..b49f6dec 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -1,10 +1,9 @@ - // See LICENSE for license details. package object chisel3 { // scalastyle:ignore package.object.name import scala.language.experimental.macros - import internal.firrtl.Width + import internal.firrtl.{Width, NumericBound} import internal.sourceinfo.{SourceInfo, SourceInfoTransform} import util.BitPat @@ -12,8 +11,6 @@ package object chisel3 { // scalastyle:ignore package.object.name import chisel3.util._ import chisel3.internal.firrtl.Port - import chisel3.internal.firrtl.NumericBound - type Direction = chisel3.core.Direction val Input = chisel3.core.Input val Output = chisel3.core.Output -- cgit v1.2.3 From e8aea3f4153b58321784ac33734305207570ef75 Mon Sep 17 00:00:00 2001 From: ducky Date: Wed, 16 Nov 2016 17:51:56 -0800 Subject: Move ChiselRange to experimental --- src/main/scala/chisel3/package.scala | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index b49f6dec..29aa6528 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -156,10 +156,6 @@ package object chisel3 { // scalastyle:ignore package.object.name def F(binaryPoint: Int): FixedPoint = FixedPoint.fromDouble(x, binaryPoint = binaryPoint) } - implicit class ChiselRange(val sc: StringContext) extends AnyVal { - def range(args: Any*): (NumericBound[Int], NumericBound[Int]) = macro chisel3.internal.RangeTransform.apply - } - implicit class fromUIntToBitPatComparable(val x: UInt) extends AnyVal { final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg @deprecated("Use '=/=', which avoids potential precedence problems", "chisel3") @@ -206,5 +202,17 @@ package object chisel3 { // scalastyle:ignore package.object.name implicit def fromBigIntToIntParam(x: BigInt): IntParam = IntParam(x) implicit def fromDoubleToDoubleParam(x: Double): DoubleParam = DoubleParam(x) implicit def fromStringToStringParam(x: String): StringParam = StringParam(x) + + implicit class ChiselRange(val sc: StringContext) extends AnyVal { + /** Specifies a range using mathematical range notation. Variables can be interpolated using + * standard string interpolation syntax. + * @example {{{ + * UInt(range"[0, 2)") + * UInt(range"[0, $myInt)") + * UInt(range"[0, ${myInt + 2})") + * }}} + */ + def range(args: Any*): (NumericBound[Int], NumericBound[Int]) = macro chisel3.internal.RangeTransform.apply + } } } -- cgit v1.2.3 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/package.scala | 88 ++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 43 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 29aa6528..07dcdaca 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -31,10 +31,48 @@ package object chisel3 { // scalastyle:ignore package.object.name type Element = chisel3.core.Element type Bits = chisel3.core.Bits - val Bits = chisel3.core.Bits + + trait UIntFactory extends chisel3.core.UIntFactory { + /** 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 => Input(result) + case chisel3.core.Direction.Output => Output(result) + case chisel3.core.Direction.Unspecified => result + } + } + + /** Create a UInt port with specified width. */ + def width(width: Width): UInt = apply(width) + } + + 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 FixedPoint = chisel3.core.FixedPoint @@ -113,48 +151,12 @@ package object chisel3 { // scalastyle:ignore package.object.name implicit def string2Printable(str: String): Printable = PString(str) - /** - * 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 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 fromDoubleToLiteral(override val x: Double) extends chisel3.core.fromDoubleToLiteral(x) - 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 fromDoubleToLiteral(val x: Double) extends AnyVal { - def F(binaryPoint: Int): FixedPoint = FixedPoint.fromDouble(x, binaryPoint = binaryPoint) - } implicit class fromUIntToBitPatComparable(val x: UInt) extends AnyVal { final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg -- 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/package.scala | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 07dcdaca..84a4779e 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -33,39 +33,37 @@ package object chisel3 { // scalastyle:ignore package.object.name type Bits = chisel3.core.Bits trait UIntFactory extends chisel3.core.UIntFactory { - /** 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) + @deprecated("chisel3, will be removed by end of 2016, use n.U") + 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) + @deprecated("chisel3, will be removed by end of 2016, use n.U(width: Width)") + 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)") 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)") 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) + @deprecated("chisel3, will be removed by end of 2016, use UInt(width: Width)") def apply(dir: Option[Direction] = None, width: Int): UInt = apply(Width(width)) + /** Create a UInt literal with inferred width.- compatibility with Chisel2. */ + @deprecated("chisel3, will be removed by end of 2016, use value.U") 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 => Input(result) - case chisel3.core.Direction.Output => Output(result) - case chisel3.core.Direction.Unspecified => result - } - } + + /** Create a UInt with a specified width */ + @deprecated("chisel3, will be removed by end of 2016, use UInt(width: Width)") + 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)") 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/package.scala | 40 +++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') 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 -- 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/package.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 1161a1ca..1a100480 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -180,7 +180,7 @@ package object chisel3 { // scalastyle:ignore package.object.name 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 fromDoubleToLiteral(override val x: Double) extends chisel3.core.fromDoubleToLiteral(x) - + implicit class fromIntToWidth(override val x: Int) extends chisel3.core.fromIntToWidth(x) implicit class fromUIntToBitPatComparable(val x: UInt) extends AnyVal { final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg -- 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/package.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 1a100480..8ac76867 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -93,6 +93,13 @@ package object chisel3 { // scalastyle:ignore package.object.name def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width)) } + trait BoolFactory extends chisel3.core.BoolFactory { + /** Creates Bool literal. + */ + @deprecated("chisel3, will be removed by end of 2016, use x.B") + def apply(x: Boolean): Bool = Lit(x) + } + object Bits extends UIntFactory type Num[T <: Data] = chisel3.core.Num[T] type UInt = chisel3.core.UInt @@ -102,7 +109,7 @@ package object chisel3 { // scalastyle:ignore package.object.name type FixedPoint = chisel3.core.FixedPoint val FixedPoint = chisel3.core.FixedPoint type Bool = chisel3.core.Bool - val Bool = chisel3.core.Bool + object Bool extends BoolFactory val Mux = chisel3.core.Mux type BlackBox = chisel3.core.BlackBox -- 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/package.scala | 50 ++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 8ac76867..8b5b8a46 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -32,71 +32,89 @@ package object chisel3 { // scalastyle:ignore package.object.name type Element = chisel3.core.Element type Bits = chisel3.core.Bits + /** This contains literal constructor factory methods that are deprecated as of Chisel3. + * These will be removed very soon. It's recommended you move your code soon. + * + * Some recommended regex replacements: + * (note: these are not guaranteed to handle all edge cases! check all replacements!) + * Bool((true|false)) => $1.B + * UInt\(width\s*=\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => UInt($1.W) + * (UInt|SInt|Bits).width\((\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => $1($2.W) + * (U|S)Int\((-?\d+|0[xX][0-9a-fA-F]+)\) => $2.$1 + * UInt\((\d+|0[xX][0-9a-fA-F]+),\s*(?:width)?\s*=\s*(\d+)\) => $1.U($2.W) + * (UInt|SInt)\(([_a-zA-Z][_0-9a-zA-Z]*)\) => $2.as$1 + */ trait UIntFactory extends chisel3.core.UIntFactory { /** Create a UInt literal with inferred width. */ - @deprecated("chisel3, will be removed by end of 2016, use n.U") + @deprecated("use n.U", "chisel3, will be removed by end of 2016") 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.W)") + @deprecated("use n.U(width.W)", "chisel3, will be removed by end of 2016") 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)") + @deprecated("use value.U(width)", "chisel3, will be removed by end of 2016") 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.W)") + @deprecated("use value.U(width.W)", "chisel3, will be removed by end of 2016") 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.W)") + @deprecated("use UInt(width.W)", "chisel3, will be removed by end of 2016") def apply(dir: Option[Direction] = None, width: Int): UInt = apply(Width(width)) /** Create a UInt literal with inferred width.- compatibility with Chisel2. */ - @deprecated("chisel3, will be removed by end of 2016, use value.U") + @deprecated("use value.U", "chisel3, will be removed by end of 2016") 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.W)") + @deprecated("use UInt(width.W)", "chisel3, will be removed by end of 2016") 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)") + @deprecated("use UInt(width)", "chisel3, will be removed by end of 2016") def width(width: Width): UInt = apply(width) } + /** This contains literal constructor factory methods that are deprecated as of Chisel3. + * These will be removed very soon. It's recommended you move your code soon. + */ 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)") + @deprecated("use SInt(width.W)", "chisel3, will be removed by end of 2016") 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)") + @deprecated("use SInt(width)", "chisel3, will be removed by end of 2016") 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") + @deprecated("use value.S", "chisel3, will be removed by end of 2016") 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)") + @deprecated("use value.S(width.W)", "chisel3, will be removed by end of 2016") 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)") + @deprecated("use value.S(width)", "chisel3, will be removed by end of 2016") def apply(value: BigInt, width: Width): SInt = Lit(value, width) - @deprecated("chisel3, will be removed by end of 2016, use value.S") + @deprecated("use value.S", "chisel3, will be removed by end of 2016") def Lit(value: BigInt): SInt = Lit(value, Width()) - @deprecated("chisel3, will be removed by end of 2016, use value.S(width)") + @deprecated("use value.S(width)", "chisel3, will be removed by end of 2016") def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width)) } + /** This contains literal constructor factory methods that are deprecated as of Chisel3. + * These will be removed very soon. It's recommended you move your code soon. + */ trait BoolFactory extends chisel3.core.BoolFactory { /** Creates Bool literal. */ - @deprecated("chisel3, will be removed by end of 2016, use x.B") + @deprecated("use x.B", "chisel3, will be removed by end of 2016") def apply(x: Boolean): Bool = Lit(x) } -- cgit v1.2.3 From 73906fcc796b259c81d5df7733968b77fbb81ba8 Mon Sep 17 00:00:00 2001 From: ducky Date: Thu, 17 Nov 2016 13:06:57 -0800 Subject: All remaining automatable regex re-styles --- src/main/scala/chisel3/package.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 8b5b8a46..5b02be34 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -41,8 +41,9 @@ package object chisel3 { // scalastyle:ignore package.object.name * UInt\(width\s*=\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => UInt($1.W) * (UInt|SInt|Bits).width\((\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => $1($2.W) * (U|S)Int\((-?\d+|0[xX][0-9a-fA-F]+)\) => $2.$1 - * UInt\((\d+|0[xX][0-9a-fA-F]+),\s*(?:width)?\s*=\s*(\d+)\) => $1.U($2.W) - * (UInt|SInt)\(([_a-zA-Z][_0-9a-zA-Z]*)\) => $2.as$1 + * UInt\((\d+|0[xX][0-9a-fA-F]+),\s*(?:width\s*=)?\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => $1.U($2.W) + * (UInt|SInt|Bool)\(([_a-zA-Z][_0-9a-zA-Z]*)\) => $2.as$1 + * (UInt|SInt)\(([_a-zA-Z][_0-9a-zA-Z]*),\s*(?:width\s*=)?\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => $2.as$1($3.W) */ trait UIntFactory extends chisel3.core.UIntFactory { /** Create a UInt literal with inferred width. */ -- 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/package.scala | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 5b02be34..326f8d7c 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -33,7 +33,7 @@ package object chisel3 { // scalastyle:ignore package.object.name type Bits = chisel3.core.Bits /** This contains literal constructor factory methods that are deprecated as of Chisel3. - * These will be removed very soon. It's recommended you move your code soon. + * These will be removed very soon. It's recommended you port your code ASAP. * * Some recommended regex replacements: * (note: these are not guaranteed to handle all edge cases! check all replacements!) @@ -48,32 +48,30 @@ package object chisel3 { // scalastyle:ignore package.object.name trait UIntFactory extends chisel3.core.UIntFactory { /** Create a UInt literal with inferred width. */ @deprecated("use n.U", "chisel3, will be removed by end of 2016") - 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. */ @deprecated("use n.U(width.W)", "chisel3, will be removed by end of 2016") - 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. */ @deprecated("use value.U(width)", "chisel3, will be removed by end of 2016") - 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. */ @deprecated("use value.U(width.W)", "chisel3, will be removed by end of 2016") - 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. */ @deprecated("use UInt(width.W)", "chisel3, will be removed by end of 2016") - 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. */ @deprecated("use value.U", "chisel3, will be removed by end of 2016") - def apply(value: BigInt): UInt = apply(value, Width()) + def apply(value: BigInt): UInt = value.asUInt /** Create a UInt with a specified width */ @deprecated("use UInt(width.W)", "chisel3, will be removed by end of 2016") - def width(width: Int): UInt = apply(Width(width)) + def width(width: Int): UInt = apply(width.W) /** Create a UInt port with specified width. */ @deprecated("use UInt(width)", "chisel3, will be removed by end of 2016") @@ -86,27 +84,27 @@ package object chisel3 { // scalastyle:ignore package.object.name trait SIntFactory extends chisel3.core.SIntFactory { /** Create a SInt type or port with fixed width. */ @deprecated("use SInt(width.W)", "chisel3, will be removed by end of 2016") - def width(width: Int): SInt = apply(Width(width)) + def width(width: Int): SInt = apply(width.W) /** Create an SInt type with specified width. */ @deprecated("use SInt(width)", "chisel3, will be removed by end of 2016") def width(width: Width): SInt = apply(width) /** Create an SInt literal with inferred width. */ @deprecated("use value.S", "chisel3, will be removed by end of 2016") - def apply(value: BigInt): SInt = Lit(value) + def apply(value: BigInt): SInt = value.asSInt /** Create an SInt literal with fixed width. */ @deprecated("use value.S(width.W)", "chisel3, will be removed by end of 2016") - def apply(value: BigInt, width: Int): SInt = Lit(value, width) + def apply(value: BigInt, width: Int): SInt = value.asSInt(width.W) /** Create an SInt literal with specified width. */ @deprecated("use value.S(width)", "chisel3, will be removed by end of 2016") - def apply(value: BigInt, width: Width): SInt = Lit(value, width) + def apply(value: BigInt, width: Width): SInt = value.asSInt(width) @deprecated("use value.S", "chisel3, will be removed by end of 2016") - def Lit(value: BigInt): SInt = Lit(value, Width()) + def Lit(value: BigInt): SInt = value.asSInt @deprecated("use value.S(width)", "chisel3, will be removed by end of 2016") - def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width)) + def Lit(value: BigInt, width: Int): SInt = value.asSInt(width.W) } /** This contains literal constructor factory methods that are deprecated as of Chisel3. @@ -116,7 +114,7 @@ package object chisel3 { // scalastyle:ignore package.object.name /** Creates Bool literal. */ @deprecated("use x.B", "chisel3, will be removed by end of 2016") - def apply(x: Boolean): Bool = Lit(x) + def apply(x: Boolean): Bool = x.B } object Bits extends UIntFactory -- cgit v1.2.3 From a2b97f8dc9c261ae4dc39ea4e11feed7723e22dd Mon Sep 17 00:00:00 2001 From: ducky Date: Thu, 17 Nov 2016 13:36:16 -0800 Subject: Restyle UInt->BitPatComparable --- src/main/scala/chisel3/package.scala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 326f8d7c..7b07d964 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -1,10 +1,8 @@ // See LICENSE for license details. package object chisel3 { // scalastyle:ignore package.object.name - import scala.language.experimental.macros + import internal.firrtl.Width - import internal.firrtl.{Width, NumericBound} - import internal.sourceinfo.{SourceInfo, SourceInfoTransform} import util.BitPat import chisel3.core.{Binding, FlippedBinder} @@ -206,7 +204,10 @@ package object chisel3 { // scalastyle:ignore package.object.name implicit class fromDoubleToLiteral(override val x: Double) extends chisel3.core.fromDoubleToLiteral(x) implicit class fromIntToWidth(override val x: Int) extends chisel3.core.fromIntToWidth(x) - implicit class fromUIntToBitPatComparable(val x: UInt) extends AnyVal { + implicit class fromUIntToBitPatComparable(val x: UInt) { + import scala.language.experimental.macros + import internal.sourceinfo.{SourceInfo, SourceInfoTransform} + final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg @deprecated("Use '=/=', which avoids potential precedence problems", "chisel3") final def != (that: BitPat): Bool = macro SourceInfoTransform.thatArg @@ -254,6 +255,9 @@ package object chisel3 { // scalastyle:ignore package.object.name implicit def fromStringToStringParam(x: String): StringParam = StringParam(x) implicit class ChiselRange(val sc: StringContext) extends AnyVal { + import scala.language.experimental.macros + import internal.firrtl.NumericBound + /** Specifies a range using mathematical range notation. Variables can be interpolated using * standard string interpolation syntax. * @example {{{ -- cgit v1.2.3 From b50dbf2e17053d601213855642c117f429204fb8 Mon Sep 17 00:00:00 2001 From: ducky Date: Thu, 17 Nov 2016 14:40:31 -0800 Subject: Stop confusing scaladoc --- src/main/scala/chisel3/package.scala | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 7b07d964..50cb3dbe 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -30,18 +30,25 @@ package object chisel3 { // scalastyle:ignore package.object.name type Element = chisel3.core.Element type Bits = chisel3.core.Bits + // Some possible regex replacements for the literal specifier deprecation: + // (note: these are not guaranteed to handle all edge cases! check all replacements!) + // Bool((true|false)) + // => $1.B + // UInt\(width\s*=\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) + // => UInt($1.W) + // (UInt|SInt|Bits).width\((\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) + // => $1($2.W) + // (U|S)Int\((-?\d+|0[xX][0-9a-fA-F]+)\) + // => $2.$1 + // UInt\((\d+|0[xX][0-9a-fA-F]+),\s*(?:width\s*=)?\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) + // => $1.U($2.W) + // (UInt|SInt|Bool)\(([_a-zA-Z][_0-9a-zA-Z]*)\) + // => $2.as$1 + // (UInt|SInt)\(([_a-zA-Z][_0-9a-zA-Z]*),\s*(?:width\s*=)?\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) + // => $2.as$1($3.W) + /** This contains literal constructor factory methods that are deprecated as of Chisel3. * These will be removed very soon. It's recommended you port your code ASAP. - * - * Some recommended regex replacements: - * (note: these are not guaranteed to handle all edge cases! check all replacements!) - * Bool((true|false)) => $1.B - * UInt\(width\s*=\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => UInt($1.W) - * (UInt|SInt|Bits).width\((\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => $1($2.W) - * (U|S)Int\((-?\d+|0[xX][0-9a-fA-F]+)\) => $2.$1 - * UInt\((\d+|0[xX][0-9a-fA-F]+),\s*(?:width\s*=)?\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => $1.U($2.W) - * (UInt|SInt|Bool)\(([_a-zA-Z][_0-9a-zA-Z]*)\) => $2.as$1 - * (UInt|SInt)\(([_a-zA-Z][_0-9a-zA-Z]*),\s*(?:width\s*=)?\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => $2.as$1($3.W) */ trait UIntFactory extends chisel3.core.UIntFactory { /** Create a UInt literal with inferred width. */ -- cgit v1.2.3 From 75da1093142b57a58d61fe5e57181041bc59146d Mon Sep 17 00:00:00 2001 From: ducky Date: Thu, 17 Nov 2016 15:37:20 -0800 Subject: Fix regex example --- src/main/scala/chisel3/package.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 50cb3dbe..44d1f6c1 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -32,7 +32,7 @@ package object chisel3 { // scalastyle:ignore package.object.name // Some possible regex replacements for the literal specifier deprecation: // (note: these are not guaranteed to handle all edge cases! check all replacements!) - // Bool((true|false)) + // Bool\((true|false)\) // => $1.B // UInt\(width\s*=\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) // => UInt($1.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/package.scala | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 44d1f6c1..449f4ea5 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -204,12 +204,13 @@ package object chisel3 { // scalastyle:ignore package.object.name implicit def string2Printable(str: String): Printable = PString(str) - 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 fromDoubleToLiteral(override val x: Double) extends chisel3.core.fromDoubleToLiteral(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 fromDoubleToLiteral(val x: Double) extends chisel3.core.fromDoubleToLiteral(x) + implicit class fromIntToWidth(val x: Int) extends chisel3.core.fromIntToWidth(x) implicit class fromUIntToBitPatComparable(val x: UInt) { import scala.language.experimental.macros -- 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/package.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/main/scala/chisel3/package.scala') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 449f4ea5..e4e64b89 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -1,6 +1,8 @@ // See LICENSE for license details. package object chisel3 { // scalastyle:ignore package.object.name + import scala.language.implicitConversions + import internal.firrtl.Width import util.BitPat @@ -267,11 +269,11 @@ package object chisel3 { // scalastyle:ignore package.object.name import internal.firrtl.NumericBound /** Specifies a range using mathematical range notation. Variables can be interpolated using - * standard string interpolation syntax. + * standard string interpolation syntax. * @example {{{ * UInt(range"[0, 2)") - * UInt(range"[0, $myInt)") - * UInt(range"[0, ${myInt + 2})") + * UInt(range"[0, \$myInt)") + * UInt(range"[0, \${myInt + 2})") * }}} */ def range(args: Any*): (NumericBound[Int], NumericBound[Int]) = macro chisel3.internal.RangeTransform.apply -- cgit v1.2.3