From 277b3979912db443aef4e1aad741ac2b3c07f42f Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Wed, 21 Nov 2018 12:53:54 -0800 Subject: Make toBools support chained apply The expanded version substituted in by the macro was misspelled, renamed from toBools -> do_toBools as expected by the macro --- chiselFrontend/src/main/scala/chisel3/core/Bits.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chiselFrontend') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala index 9356a91c..ffde7c87 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala @@ -364,7 +364,7 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi final def toBools(): Seq[Bool] = macro SourceInfoTransform.noArg /** @group SourceInfoTransformMacro */ - def toBools(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Seq[Bool] = + def do_toBools(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Seq[Bool] = Seq.tabulate(this.getWidth)(i => this(i)) /** Reinterpret this $coll as a [[SInt]] -- cgit v1.2.3 From 121635ed26c8a9852c827d6c0729515337604d08 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Wed, 21 Nov 2018 14:08:32 -0800 Subject: Add asBools, deprecate toBools --- chiselFrontend/src/main/scala/chisel3/core/Bits.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'chiselFrontend') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala index ffde7c87..b7c303f0 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala @@ -364,7 +364,15 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi final def toBools(): Seq[Bool] = macro SourceInfoTransform.noArg /** @group SourceInfoTransformMacro */ - def do_toBools(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Seq[Bool] = + @chiselRuntimeDeprecated + @deprecated("Use asBools instead", "3.2") + def do_toBools(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Seq[Bool] = do_asBools + + /** Returns the contents of this wire as a [[scala.collection.Seq]] of [[Bool]]. */ + final def asBools(): Seq[Bool] = macro SourceInfoTransform.noArg + + /** @group SourceInfoTransformMacro */ + def do_asBools(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Seq[Bool] = Seq.tabulate(this.getWidth)(i => this(i)) /** Reinterpret this $coll as a [[SInt]] -- cgit v1.2.3 From 3db21bd8e5a32c29efa55494d180dac4d22589e5 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Wed, 21 Nov 2018 15:34:42 -0800 Subject: Add asBool, deprecate toBool --- chiselFrontend/src/main/scala/chisel3/core/Assert.scala | 4 ++-- chiselFrontend/src/main/scala/chisel3/core/Bits.scala | 17 +++++++++++++++-- chiselFrontend/src/main/scala/chisel3/core/Printf.scala | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) (limited to 'chiselFrontend') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Assert.scala b/chiselFrontend/src/main/scala/chisel3/core/Assert.scala index 92f602c4..77db3692 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Assert.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Assert.scala @@ -53,7 +53,7 @@ object assert { // scalastyle:ignore object.name def apply_impl_do(cond: Bool, line: String, message: Option[String], data: Bits*)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions) { val escLine = line.replaceAll("%", "%%") - when (!(cond || Module.reset.toBool)) { + when (!(cond || Module.reset.asBool)) { val fmt = message match { case Some(msg) => s"Assertion failed: $msg\n at $escLine\n" @@ -80,7 +80,7 @@ object assert { // scalastyle:ignore object.name object stop { // scalastyle:ignore object.name /** Terminate execution with a failure code. */ def apply(code: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Unit = { - when (!Module.reset.toBool) { + when (!Module.reset.asBool) { pushCommand(Stop(sourceInfo, Builder.forcedClock.ref, code)) } } diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala index b7c303f0..7e98cf04 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala @@ -78,6 +78,15 @@ abstract class Element extends Data { */ private[chisel3] sealed trait ToBoolable extends Element { + /** Casts this $coll to a [[Bool]] + * + * @note The width must be known and equal to 1 + */ + final def asBool(): Bool = macro SourceInfoWhiteboxTransform.noArg + + /** @group SourceInfoTransformMacro */ + def do_asBool(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool + /** Casts this $coll to a [[Bool]] * * @note The width must be known and equal to 1 @@ -420,13 +429,17 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi do_asUInt } - final def do_toBool(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = { + final def do_asBool(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = { width match { case KnownWidth(1) => this(0) - case _ => throwException(s"can't covert UInt<$width> to Bool") + case _ => throwException(s"can't covert ${this.getClass.getSimpleName}$width to Bool") } } + @chiselRuntimeDeprecated + @deprecated("Use asBool instead", "3.2") + final def do_toBool(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = do_asBool + /** Concatenation operator * * @param that a hardware component diff --git a/chiselFrontend/src/main/scala/chisel3/core/Printf.scala b/chiselFrontend/src/main/scala/chisel3/core/Printf.scala index bfab57d8..53b62bc8 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Printf.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Printf.scala @@ -86,7 +86,7 @@ object printf { // scalastyle:ignore object.name * @param pable [[Printable]] to print */ def apply(pable: Printable)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Unit = { - when (!Module.reset.toBool) { + when (!Module.reset.asBool) { printfWithoutReset(pable) } } -- cgit v1.2.3