summaryrefslogtreecommitdiff
path: root/chiselFrontend
diff options
context:
space:
mode:
authorJack Koenig2016-12-05 11:28:29 -0800
committerGitHub2016-12-05 11:28:29 -0800
commit207da69768dac464a719a7c712f6977371f7c5f4 (patch)
treed005ddb271bce815bcd1b45988196b954934e8da /chiselFrontend
parentd3ec37edd39799e8cf039e5caed915c00dff7eeb (diff)
parenta1e8ae80888b6b4d7bac057c6486b3442334cdc6 (diff)
Merge branch 'master' into exceptionfix
Diffstat (limited to 'chiselFrontend')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/package.scala18
1 files changed, 6 insertions, 12 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/package.scala b/chiselFrontend/src/main/scala/chisel3/core/package.scala
index 1d5817ae..87dca1f3 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/package.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/package.scala
@@ -55,14 +55,17 @@ package chisel3 {
implicit class fromStringToLiteral(val str: String) {
/** String to UInt parse, recommended style for constants.
*/
- def U(): UInt = UInt.Lit(parse(str), parsedWidth(str)) // scalastyle:ignore method.name
+ def U(): UInt = str.asUInt() // scalastyle:ignore method.name
/** String to UInt parse with specified width, recommended style for constants.
*/
- def U(width: Width): UInt = UInt.Lit(parse(str), width) // scalastyle:ignore method.name
+ def U(width: Width): UInt = str.asUInt(width) // scalastyle:ignore method.name
/** String to UInt parse, recommended style for variables.
*/
- def asUInt(): UInt = UInt.Lit(parse(str), parsedWidth(str))
+ def asUInt(): UInt = {
+ val bigInt = parse(str)
+ UInt.Lit(bigInt, Width(bigInt.bitLength max 1))
+ }
/** String to UInt parse with specified width, recommended style for variables.
*/
def asUInt(width: Width): UInt = UInt.Lit(parse(str), width)
@@ -78,15 +81,6 @@ package chisel3 {
}
BigInt(num.filterNot(_ == '_'), radix)
}
-
- protected def parsedWidth(n: String) =
- if (n(0) == 'b') {
- Width(n.length-1)
- } else if (n(0) == 'h') {
- Width((n.length-1) * 4)
- } else {
- Width()
- }
}
implicit class fromBooleanToLiteral(val boolean: Boolean) {