diff options
| author | Richard Lin | 2016-11-22 00:57:12 -0800 |
|---|---|---|
| committer | Andrew Waterman | 2016-11-22 00:57:12 -0800 |
| commit | 8cb4e0cc38e2bf1ec596ae000caaf8e49c47dc31 (patch) | |
| tree | bafb28474b557c456e12897ef7f6e0ace51535c4 /chiselFrontend | |
| parent | 3c31b9af6b1dc9abde701edb33d4be36c192bad2 (diff) | |
Disallow chained apply (#380)
Diffstat (limited to 'chiselFrontend')
3 files changed, 15 insertions, 11 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala index 8fdcb260..17354799 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala @@ -126,7 +126,7 @@ object Vec { if (n <= 1) 0.U else if (idx.width.known && idx.width.get <= w) idx else if (idx.width.known) idx(w-1,0) - else (idx | 0.U(w))(w-1,0) + else (idx | 0.U(w.W))(w-1,0) } } diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala index 354512e1..cab1a82e 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala @@ -478,7 +478,7 @@ sealed class UInt private[core] (width: Width, lit: Option[ULit] = None) final def unary_! () : Bool = macro SourceInfoTransform.noArg - def do_unary_! (implicit sourceInfo: SourceInfo) : Bool = this === 0.U(1) + def do_unary_! (implicit sourceInfo: SourceInfo) : Bool = this === 0.U(1.W) override def do_<< (that: Int)(implicit sourceInfo: SourceInfo): UInt = binop(sourceInfo, UInt(this.width + that), ShiftLeftOp, that) @@ -496,7 +496,7 @@ sealed class UInt private[core] (width: Width, lit: Option[ULit] = None) final def bitSet(off: UInt, dat: Bool): UInt = macro UIntTransform.bitset def do_bitSet(off: UInt, dat: Bool)(implicit sourceInfo: SourceInfo): UInt = { - val bit = 1.U(1) << off + val bit = 1.U(1.W) << off Mux(dat, this | bit, ~(~this | bit)) } diff --git a/chiselFrontend/src/main/scala/chisel3/core/package.scala b/chiselFrontend/src/main/scala/chisel3/core/package.scala index 77f35c23..1d5817ae 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/package.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/package.scala @@ -16,14 +16,18 @@ package chisel3 { * 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. + * + * Implementation note: the empty parameter list (like `U()`) is necessary to prevent + * interpreting calls that have a non-Width parameter as a chained apply, otherwise things like + * `0.asUInt(16)` (instead of `16.W`) compile without error and produce undesired results. */ implicit class fromBigIntToLiteral(val bigint: BigInt) { /** Int to UInt conversion, recommended style for constants. */ - def U: UInt = UInt.Lit(bigint, 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, 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, width) // scalastyle:ignore method.name @@ -33,10 +37,10 @@ package chisel3 { /** Int to UInt conversion, recommended style for variables. */ - def asUInt: UInt = UInt.Lit(bigint, Width()) + def asUInt(): UInt = UInt.Lit(bigint, Width()) /** Int to SInt conversion, recommended style for variables. */ - def asSInt: SInt = SInt.Lit(bigint, 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(bigint, width) @@ -51,14 +55,14 @@ 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 = 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(str), 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 = 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(str), width) @@ -88,11 +92,11 @@ package chisel3 { implicit class fromBooleanToLiteral(val boolean: Boolean) { /** Boolean to Bool conversion, recommended style for constants. */ - def B: Bool = Bool.Lit(boolean) // 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(boolean) + def asBool(): Bool = Bool.Lit(boolean) } implicit class fromDoubleToLiteral(val double: Double) { |
