Skip to content

Commit

Permalink
Migrate nullary funcs to parameterless versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jared-barocsi committed Sep 16, 2021
1 parent bfb77d4 commit ef4f8a0
Show file tree
Hide file tree
Showing 19 changed files with 172 additions and 92 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/chisel3/Aggregate.scala
Expand Up @@ -53,7 +53,7 @@ sealed abstract class Aggregate extends Data {
override def litOption: Option[BigInt] = {
// Shift the accumulated value by our width and add in our component, masked by our width.
def shiftAdd(accumulator: Option[BigInt], elt: Data): Option[BigInt] = {
(accumulator, elt.litOption()) match {
(accumulator, elt.litOption) match {
case (Some(accumulator), Some(eltLit)) =>
val width = elt.width.get
val masked = ((BigInt(1) << width) - 1) & eltLit // also handles the negative case with two's complement
Expand Down
92 changes: 67 additions & 25 deletions core/src/main/scala/chisel3/Bits.scala
Expand Up @@ -25,7 +25,9 @@ private[chisel3] sealed trait ToBoolable extends Element {
*
* @note The width must be known and equal to 1
*/
final def asBool(): Bool = macro SourceInfoWhiteboxTransform.noArg
final def asBool: Bool = macro SourceInfoWhiteboxTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def asBool(dummy: Int*): Bool = macro SourceInfoWhiteboxTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_asBool(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool
Expand Down Expand Up @@ -222,7 +224,9 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi
* @return this $coll with each bit inverted
* @group Bitwise
*/
final def unary_~ (): Bits = macro SourceInfoWhiteboxTransform.noArg
final def unary_~ : Bits = macro SourceInfoWhiteboxTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def unary_~(dummy: Int*): Bits = macro SourceInfoWhiteboxTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_unary_~ (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bits
Expand Down Expand Up @@ -304,10 +308,14 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi
def do_>> (that: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bits

/** Returns the contents of this wire as a [[scala.collection.Seq]] of [[Bool]]. */
final def toBools(): Seq[Bool] = macro SourceInfoTransform.noArg
final def toBools: Seq[Bool] = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def toBools(dummy: Int*): Seq[Bool] = macro SourceInfoWhiteboxTransform.noArgDummy

/** Returns the contents of this wire as a [[scala.collection.Seq]] of [[Bool]]. */
final def asBools(): Seq[Bool] = macro SourceInfoTransform.noArg
final def asBools: Seq[Bool] = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def asBools(dummy: Int*): Seq[Bool] = macro SourceInfoWhiteboxTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_asBools(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Seq[Bool] =
Expand All @@ -318,7 +326,9 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi
* @note The arithmetic value is not preserved if the most-significant bit is set. For example, a [[UInt]] of
* width 3 and value 7 (0b111) would become an [[SInt]] of width 3 and value -1.
*/
final def asSInt(): SInt = macro SourceInfoTransform.noArg
final def asSInt: SInt = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def asSInt(dummy: Int*): SInt = macro SourceInfoWhiteboxTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_asSInt(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt
Expand Down Expand Up @@ -410,15 +420,19 @@ sealed class UInt private[chisel3] (width: Width) extends Bits(width) with Num[U
* $constantWidth
* @group Arithmetic
*/
final def unary_- (): UInt = macro SourceInfoTransform.noArg
final def unary_- : UInt = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def unary_-(dummy: Int*): UInt = macro SourceInfoTransform.noArgDummy

/** Unary negation (constant width)
*
* @return a $coll equal to zero minus this $coll shifted right by one.
* $constantWidth
* @group Arithmetic
*/
final def unary_-% (): UInt = macro SourceInfoTransform.noArg
final def unary_-% : UInt = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def unary_%(dummy: Int*): UInt = macro SourceInfoTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_unary_- (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions) : UInt = 0.U - this
Expand Down Expand Up @@ -522,7 +536,7 @@ sealed class UInt private[chisel3] (width: Width) extends Bits(width) with Num[U
*/
final def ^ (that: UInt): UInt = macro SourceInfoTransform.thatArg

// override def abs: UInt = macro SourceInfoTransform.noArg
// override def abs: UInt = macro SourceInfoTransform.noArgDummy
def do_abs(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt = this

/** @group SourceInfoTransformMacro */
Expand All @@ -545,21 +559,27 @@ sealed class UInt private[chisel3] (width: Width) extends Bits(width) with Num[U
* @return a hardware [[Bool]] resulting from every bit of this $coll or'd together
* @group Bitwise
*/
final def orR(): Bool = macro SourceInfoTransform.noArg
final def orR: Bool = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def orR(dummy: Int*): Bool = macro SourceInfoTransform.noArgDummy

/** And reduction operator
*
* @return a hardware [[Bool]] resulting from every bit of this $coll and'd together
* @group Bitwise
*/
final def andR(): Bool = macro SourceInfoTransform.noArg
final def andR: Bool = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def andR(dummy: Int*): Bool = macro SourceInfoTransform.noArgDummy

/** Exclusive or (xor) reduction operator
*
* @return a hardware [[Bool]] resulting from every bit of this $coll xor'd together
* @group Bitwise
*/
final def xorR(): Bool = macro SourceInfoTransform.noArg
final def xorR: Bool = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def xorR(dummy: Int*): Bool = macro SourceInfoTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_orR(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = redop(sourceInfo, OrReduceOp)
Expand Down Expand Up @@ -599,7 +619,9 @@ sealed class UInt private[chisel3] (width: Width) extends Bits(width) with Num[U
* @return a hardware [[Bool]] asserted if this $coll equals zero
* @group Bitwise
*/
final def unary_! () : Bool = macro SourceInfoTransform.noArg
final def unary_! : Bool = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def unary_! (dummy: Int*): Bool = macro SourceInfoTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_unary_! (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions) : Bool = this === 0.U(1.W)
Expand Down Expand Up @@ -639,7 +661,10 @@ sealed class UInt private[chisel3] (width: Width) extends Bits(width) with Num[U
* @return an [[SInt]] equal to this $coll with an additional zero in its most significant bit
* @note The width of the returned [[SInt]] is `width of this` + `1`.
*/
final def zext(): SInt = macro SourceInfoTransform.noArg
final def zext: SInt = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def zext(dummy: Int*): SInt = macro SourceInfoTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_zext(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt =
pushOp(DefPrim(sourceInfo, SInt(width + 1), ConvertOp, ref))
Expand Down Expand Up @@ -716,15 +741,19 @@ sealed class SInt private[chisel3] (width: Width) extends Bits(width) with Num[S
* $constantWidth
* @group Arithmetic
*/
final def unary_- (): SInt = macro SourceInfoTransform.noArg
final def unary_- : SInt = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def unary_-(dummy: Int*): SInt = macro SourceInfoTransform.noArgDummy

/** Unary negation (constant width)
*
* @return a hardware $coll equal to zero minus `this` shifted right by one
* $constantWidth
* @group Arithmetic
*/
final def unary_-% (): SInt = macro SourceInfoTransform.noArg
final def unary_-% : SInt = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def unary_-%(dummy: Int*): SInt = macro SourceInfoTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def unary_- (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt = 0.S - this
Expand Down Expand Up @@ -755,7 +784,7 @@ sealed class SInt private[chisel3] (width: Width) extends Bits(width) with Num[S
final def * (that: UInt): SInt = macro SourceInfoTransform.thatArg
/** @group SourceInfoTransformMacro */
def do_* (that: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt = {
val thatToSInt = that.zext()
val thatToSInt = that.zext
val result = binop(sourceInfo, SInt(this.width + thatToSInt.width), TimesOp, thatToSInt)
result.tail(1).asSInt
}
Expand Down Expand Up @@ -876,10 +905,10 @@ sealed class SInt private[chisel3] (width: Width) extends Bits(width) with Num[S
/** @group SourceInfoTransformMacro */
def do_=== (that: SInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = compop(sourceInfo, EqualOp, that)

// final def abs(): UInt = macro SourceInfoTransform.noArg
// final def abs(): UInt = macro SourceInfoTransform.noArgDummy

def do_abs(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt = {
Mux(this < 0.S, (-this), this)
Mux(this < 0.S, (this.unary_-(sourceInfo, compileOptions)), this)
}

override def do_<< (that: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt =
Expand Down Expand Up @@ -938,7 +967,9 @@ sealed class SInt private[chisel3] (width: Width) extends Bits(width) with Num[S

sealed trait Reset extends Element with ToBoolable {
/** Casts this $coll to an [[AsyncReset]] */
final def asAsyncReset(): AsyncReset = macro SourceInfoWhiteboxTransform.noArg
final def asAsyncReset: AsyncReset = macro SourceInfoWhiteboxTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def asAsyncReset(dummy: Int*): AsyncReset = macro SourceInfoTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_asAsyncReset(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): AsyncReset
Expand Down Expand Up @@ -1134,7 +1165,9 @@ sealed class Bool() extends UInt(1.W) with Reset {
def do_&& (that: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = this & that

/** Reinterprets this $coll as a clock */
def asClock(): Clock = macro SourceInfoTransform.noArg
def asClock: Clock = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
def asClock(dummy: Int*): Clock = macro SourceInfoTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_asClock(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Clock = pushOp(DefPrim(sourceInfo, Clock(), AsClockOp, ref))
Expand Down Expand Up @@ -1230,15 +1263,19 @@ package experimental {
* $expandingWidth
* @group Arithmetic
*/
final def unary_- (): FixedPoint = macro SourceInfoTransform.noArg
final def unary_- : FixedPoint = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def unary_-(dummy: Int*): FixedPoint = macro SourceInfoTransform.noArgDummy

/** Unary negation (constant width)
*
* @return a hardware $coll equal to zero minus `this` shifted right by one
* $constantWidth
* @group Arithmetic
*/
final def unary_-% (): FixedPoint = macro SourceInfoTransform.noArg
final def unary_-% : FixedPoint = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def unary_-%(dummy: Int*): FixedPoint = macro SourceInfoTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def unary_- (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): FixedPoint = FixedPoint.fromBigInt(0) - this
Expand Down Expand Up @@ -1673,8 +1710,13 @@ package experimental {
}
}

final def unary_-(): Interval = macro SourceInfoTransform.noArg
final def unary_-%(): Interval = macro SourceInfoTransform.noArg
final def unary_- : Interval = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def unary_-(dummy: Int*): Interval = macro SourceInfoTransform.noArgDummy

final def unary_-% : Interval = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def unary_-%(dummy: Int*): Interval = macro SourceInfoTransform.noArgDummy

def unary_-(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Interval = {
Interval.Zero - this
Expand Down Expand Up @@ -1789,7 +1831,7 @@ package experimental {
def do_=/= (that: Interval)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = compop(sourceInfo, NotEqualOp, that)
def do_=== (that: Interval)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = compop(sourceInfo, EqualOp, that)

// final def abs(): UInt = macro SourceInfoTransform.noArg
// final def abs(): UInt = macro SourceInfoTransform.noArgDummy

def do_abs(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Interval = {
Mux(this < Interval.Zero, (Interval.Zero - this), this)
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/scala/chisel3/Clock.scala
Expand Up @@ -32,8 +32,10 @@ sealed class Clock(private[chisel3] val width: Width = Width(1)) extends Element
def toPrintable: Printable = PString("CLOCK")

/** Returns the contents of the clock wire as a [[Bool]]. */
final def asBool(): Bool = macro SourceInfoTransform.noArg
def do_asBool(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = this.asUInt().asBool()
final def asBool: Bool = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def asBool(dummy: Int*): Bool = macro SourceInfoTransform.noArgDummy
def do_asBool(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = this.asUInt.asBool

override def do_asUInt(implicit sourceInfo: SourceInfo, connectCompileOptions: CompileOptions): UInt = pushOp(DefPrim(sourceInfo, UInt(this.width), AsUIntOp, ref))
private[chisel3] override def connectFromBits(that: Bits)(implicit sourceInfo: SourceInfo,
Expand Down
21 changes: 15 additions & 6 deletions core/src/main/scala/chisel3/Data.scala
Expand Up @@ -564,18 +564,25 @@ abstract class Data extends HasId with NamedComponent with SourceInfoDoc {
}
}

def isLit(): Boolean = litOption.isDefined
def isLit: Boolean = litOption.isDefined
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
def isLit(dummy: Int = 0): Boolean = isLit


/**
* If this is a literal that is representable as bits, returns the value as a BigInt.
* If not a literal, or not representable as bits (for example, is or contains Analog), returns None.
*/
def litOption(): Option[BigInt]
def litOption: Option[BigInt]
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
def litOption(dummy: Int = 0): Option[BigInt] = litOption

/**
* Returns the literal value if this is a literal that is representable as bits, otherwise crashes.
*/
def litValue(): BigInt = litOption.get
def litValue: BigInt = litOption.get
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
def litValue(dummy: Int = 0): BigInt = litValue

/** Returns the width, in bits, if currently known. */
final def getWidth: Int =
Expand All @@ -598,7 +605,7 @@ abstract class Data extends HasId with NamedComponent with SourceInfoDoc {
/** @group SourceInfoTransformMacro */
def do_asTypeOf[T <: Data](that: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
val thatCloned = Wire(that.cloneTypeFull)
thatCloned.connectFromBits(this.asUInt())
thatCloned.connectFromBits(this.asUInt)
thatCloned
}

Expand All @@ -614,7 +621,9 @@ abstract class Data extends HasId with NamedComponent with SourceInfoDoc {
* @note Aggregates are recursively packed with the first element appearing
* in the least-significant bits of the result.
*/
final def asUInt(): UInt = macro SourceInfoTransform.noArg
final def asUInt: UInt = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def asUInt(dummy: Int*): UInt = macro SourceInfoTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_asUInt(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt
Expand All @@ -634,7 +643,7 @@ trait WireFactory {
val x = t.cloneTypeFull

// Bind each element of x to being a Wire
x.bind(WireBinding(Builder.forcedUserModule, Builder.currentWhen()))
x.bind(WireBinding(Builder.forcedUserModule, Builder.currentWhen))

pushCommand(DefWire(sourceInfo, x))
if (!compileOptions.explicitInvalidate) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/chisel3/Mem.scala
Expand Up @@ -130,7 +130,7 @@ sealed abstract class MemBase[T <: Data](val t: T, val length: BigInt) extends H
t.cloneTypeFull, Node(this), dir, i.ref, Builder.forcedClock.ref)
).id
// Bind each element of port to being a MemoryPort
port.bind(MemoryPortBinding(Builder.forcedUserModule, Builder.currentWhen()))
port.bind(MemoryPortBinding(Builder.forcedUserModule, Builder.currentWhen))
port
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/chisel3/Module.scala
Expand Up @@ -39,7 +39,7 @@ object Module extends SourceInfoDoc {

// Save then clear clock and reset to prevent leaking scope, must be set again in the Module
val (saveClock, saveReset) = (Builder.currentClock, Builder.currentReset)
val savePrefix = Builder.getPrefix()
val savePrefix = Builder.getPrefix
Builder.clearPrefix()
Builder.currentClock = None
Builder.currentReset = None
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/chisel3/Num.scala
Expand Up @@ -148,7 +148,9 @@ trait Num[T <: Data] {
* $unchangedWidth
* @group Arithmetic
*/
final def abs(): T = macro SourceInfoTransform.noArg
final def abs: T = macro SourceInfoTransform.noArg
@deprecated("Calling a nullary function with an empty argument list will be removed by official release", "chisel3")
final def abs(dummy: Int*): T = macro SourceInfoTransform.noArgDummy

/** @group SourceInfoTransformMacro */
def do_abs(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T
Expand Down

0 comments on commit ef4f8a0

Please sign in to comment.