summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorducky2016-11-18 13:36:03 -0800
committerducky2016-11-21 13:32:47 -0800
commit81e5d00d18a5ba9ae33c10219a270148002fc672 (patch)
tree56652eaa478d5dfd8cddfbe2795c0123d39d230d
parent70161db5b6ae88b4ba1edfd8032e6ed381734dab (diff)
Deboilerplate the implicit conversions, add support for long.U
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/package.scala71
-rw-r--r--src/main/scala/chisel3/compatibility.scala11
-rw-r--r--src/main/scala/chisel3/package.scala13
-rw-r--r--src/test/scala/chiselTests/BlackBox.scala2
4 files changed, 37 insertions, 60 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/package.scala b/chiselFrontend/src/main/scala/chisel3/core/package.scala
index 7c11d446..77f35c23 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/package.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/package.scala
@@ -17,76 +17,51 @@ package chisel3 {
* 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) {
+ implicit class fromBigIntToLiteral(val bigint: BigInt) {
/** Int to UInt conversion, recommended style for constants.
*/
- def U: UInt = UInt.Lit(BigInt(x), Width()) // scalastyle:ignore method.name
+ def U: UInt = UInt.Lit(bigint, Width()) // scalastyle:ignore method.name
/** Int to SInt conversion, recommended style for constants.
*/
- def S: SInt = SInt.Lit(BigInt(x), Width()) // scalastyle:ignore method.name
+ def S: SInt = SInt.Lit(bigint, Width()) // scalastyle:ignore method.name
/** Int to UInt conversion with specified width, recommended style for constants.
*/
- def U(width: Width): UInt = UInt.Lit(BigInt(x), width) // scalastyle:ignore method.name
+ def U(width: Width): UInt = UInt.Lit(bigint, width) // scalastyle:ignore method.name
/** Int to SInt conversion with specified width, recommended style for constants.
*/
- def S(width: Width): SInt = SInt.Lit(BigInt(x), width) // scalastyle:ignore method.name
+ def S(width: Width): SInt = SInt.Lit(bigint, width) // scalastyle:ignore method.name
/** Int to UInt conversion, recommended style for variables.
*/
- def asUInt: UInt = UInt.Lit(x, Width())
+ def asUInt: UInt = UInt.Lit(bigint, Width())
/** Int to SInt conversion, recommended style for variables.
*/
- def asSInt: SInt = SInt.Lit(x, Width())
+ def asSInt: SInt = SInt.Lit(bigint, Width())
/** Int to UInt conversion with specified width, recommended style for variables.
*/
- def asUInt(width: Width): UInt = UInt.Lit(x, width)
+ def asUInt(width: Width): UInt = UInt.Lit(bigint, width)
/** Int to SInt conversion with specified width, recommended style for variables.
*/
- def asSInt(width: Width): SInt = SInt.Lit(x, width)
+ def asSInt(width: Width): SInt = SInt.Lit(bigint, width)
}
- implicit class fromBigIntToLiteral(val x: BigInt) {
- /** Int to UInt conversion, recommended style for constants.
- */
- def U: UInt = UInt.Lit(x, Width()) // scalastyle:ignore method.name
- /** Int to SInt conversion, recommended style for constants.
- */
- def S: SInt = SInt.Lit(x, Width()) // scalastyle:ignore method.name
- /** Int to UInt conversion with specified width, recommended style for constants.
- */
- def U(width: Width): UInt = UInt.Lit(x, width) // scalastyle:ignore method.name
- /** Int to SInt conversion with specified width, recommended style for constants.
- */
- def S(width: Width): SInt = SInt.Lit(x, width) // scalastyle:ignore method.name
-
- /** Int to UInt conversion, recommended style for variables.
- */
- def asUInt: UInt = UInt.Lit(x, Width())
- /** Int to SInt conversion, recommended style for variables.
- */
- def asSInt: SInt = SInt.Lit(x, Width())
- /** Int to UInt conversion with specified width, recommended style for variables.
- */
- def asUInt(width: Width): UInt = UInt.Lit(x, width)
- /** Int to SInt conversion with specified width, recommended style for variables.
- */
- def asSInt(width: Width): SInt = SInt.Lit(x, width)
- }
+ implicit class fromIntToLiteral(val int: Int) extends fromBigIntToLiteral(int)
+ implicit class fromLongToLiteral(val long: Long) extends fromBigIntToLiteral(long)
- implicit class fromStringToLiteral(val x: String) {
+ implicit class fromStringToLiteral(val str: String) {
/** String to UInt parse, recommended style for constants.
*/
- def U: UInt = UInt.Lit(parse(x), parsedWidth(x)) // scalastyle:ignore method.name
+ def U: UInt = UInt.Lit(parse(str), parsedWidth(str)) // scalastyle:ignore method.name
/** String to UInt parse with specified width, recommended style for constants.
*/
- def U(width: Width): UInt = UInt.Lit(parse(x), width) // scalastyle:ignore method.name
+ def U(width: Width): UInt = UInt.Lit(parse(str), width) // scalastyle:ignore method.name
/** String to UInt parse, recommended style for variables.
*/
- def asUInt: UInt = UInt.Lit(parse(x), parsedWidth(x))
+ def asUInt: UInt = UInt.Lit(parse(str), parsedWidth(str))
/** String to UInt parse with specified width, recommended style for variables.
*/
- def asUInt(width: Width): UInt = UInt.Lit(parse(x), width)
+ def asUInt(width: Width): UInt = UInt.Lit(parse(str), width)
protected def parse(n: String) = {
val (base, num) = n.splitAt(1)
@@ -110,22 +85,22 @@ package chisel3 {
}
}
- implicit class fromBooleanToLiteral(val x: Boolean) {
+ implicit class fromBooleanToLiteral(val boolean: Boolean) {
/** Boolean to Bool conversion, recommended style for constants.
*/
- def B: Bool = Bool.Lit(x) // scalastyle:ignore method.name
+ def B: Bool = Bool.Lit(boolean) // scalastyle:ignore method.name
/** Boolean to Bool conversion, recommended style for variables.
*/
- def asBool: Bool = Bool.Lit(x)
+ def asBool: Bool = Bool.Lit(boolean)
}
- implicit class fromDoubleToLiteral(val x: Double) {
- def F(binaryPoint: Int): FixedPoint = FixedPoint.fromDouble(x, binaryPoint = binaryPoint)
+ implicit class fromDoubleToLiteral(val double: Double) {
+ def F(binaryPoint: Int): FixedPoint = FixedPoint.fromDouble(double, binaryPoint = binaryPoint)
}
- implicit class fromIntToWidth(val x: Int) {
- def W: Width = Width(x) // scalastyle:ignore method.name
+ implicit class fromIntToWidth(val int: Int) {
+ def W: Width = Width(int) // scalastyle:ignore method.name
}
}
}
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
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
diff --git a/src/test/scala/chiselTests/BlackBox.scala b/src/test/scala/chiselTests/BlackBox.scala
index 7fcba766..d42cd791 100644
--- a/src/test/scala/chiselTests/BlackBox.scala
+++ b/src/test/scala/chiselTests/BlackBox.scala
@@ -127,7 +127,7 @@ class BlackBoxWithParamsTester extends BasicTester {
assert(blackBoxFour.io.out === 4.U)
assert(blackBoxStringParamOne.io.out === 1.U)
assert(blackBoxStringParamTwo.io.out === 2.U)
- assert(blackBoxRealParamOne.io.out === BigInt(0x3ff0000000000000L).U)
+ assert(blackBoxRealParamOne.io.out === 0x3ff0000000000000L.U)
assert(blackBoxRealParamNeg.io.out === BigInt("bff0000000000000", 16).U)
assert(blackBoxTypeParamBit.io.out === 1.U)
assert(blackBoxTypeParamWord.io.out === "hdeadbeef".U(32.W))