summaryrefslogtreecommitdiff
path: root/chiselFrontend
diff options
context:
space:
mode:
authorJack Koenig2016-12-05 11:28:04 -0800
committerGitHub2016-12-05 11:28:04 -0800
commita1e8ae80888b6b4d7bac057c6486b3442334cdc6 (patch)
treec8fd05fe6669fa436f5c8f98978afdd4d4730f31 /chiselFrontend
parenteba224e524b249207b47a3b378458c61c9b66e2c (diff)
Fix literal width (#389)
Fixes #388
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) {