summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Koenig2018-11-21 14:08:32 -0800
committerJack Koenig2018-12-04 13:13:13 -0800
commit121635ed26c8a9852c827d6c0729515337604d08 (patch)
tree108b4ef217b89cd308ec27ec4e314b400fb369ad
parent277b3979912db443aef4e1aad741ac2b3c07f42f (diff)
Add asBools, deprecate toBools
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Bits.scala10
-rw-r--r--coreMacros/src/main/scala/chisel3/SourceInfoDoc.scala2
-rw-r--r--src/main/scala/chisel3/util/Bitwise.scala2
-rw-r--r--src/main/scala/chisel3/util/OneHot.scala2
-rw-r--r--src/test/scala/chiselTests/UIntOps.scala4
-rw-r--r--src/test/scala/cookbook/UInt2VecOfBool.scala4
-rw-r--r--src/test/scala/examples/VendingMachineGenerator.scala2
7 files changed, 17 insertions, 9 deletions
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]]
diff --git a/coreMacros/src/main/scala/chisel3/SourceInfoDoc.scala b/coreMacros/src/main/scala/chisel3/SourceInfoDoc.scala
index ad320d5d..2f14585e 100644
--- a/coreMacros/src/main/scala/chisel3/SourceInfoDoc.scala
+++ b/coreMacros/src/main/scala/chisel3/SourceInfoDoc.scala
@@ -16,7 +16,7 @@ package chisel3
*
* The equivalent public-facing methods do not have the `do_` prefix or have the same name. Use and look at the
* documentation for those. If you want left shift, use `<<`, not `do_<<`. If you want comversion to a [[Seq]] of
- * [[Bool]]s look at the `toBools` above, not the one below. Users can safely ignore every method in this group!
+ * [[Bool]]s look at the `asBools` above, not the one below. Users can safely ignore every method in this group!
* <br>
* <br>
*
diff --git a/src/main/scala/chisel3/util/Bitwise.scala b/src/main/scala/chisel3/util/Bitwise.scala
index 387fd109..dc10d36d 100644
--- a/src/main/scala/chisel3/util/Bitwise.scala
+++ b/src/main/scala/chisel3/util/Bitwise.scala
@@ -24,7 +24,7 @@ object FillInterleaved {
*
* Output data-equivalent to in(size(in)-1) (n times) ## ... ## in(1) (n times) ## in(0) (n times)
*/
- def apply(n: Int, in: UInt): UInt = apply(n, in.toBools)
+ def apply(n: Int, in: UInt): UInt = apply(n, in.asBools)
/** Creates n repetitions of each bit of x in order.
*
diff --git a/src/main/scala/chisel3/util/OneHot.scala b/src/main/scala/chisel3/util/OneHot.scala
index a6af0d99..3ffbdfe2 100644
--- a/src/main/scala/chisel3/util/OneHot.scala
+++ b/src/main/scala/chisel3/util/OneHot.scala
@@ -36,7 +36,7 @@ object OHToUInt {
*/
object PriorityEncoder {
def apply(in: Seq[Bool]): UInt = PriorityMux(in, (0 until in.size).map(_.asUInt))
- def apply(in: Bits): UInt = apply(in.toBools)
+ def apply(in: Bits): UInt = apply(in.asBools)
}
/** Returns the one hot encoding of the input UInt.
diff --git a/src/test/scala/chiselTests/UIntOps.scala b/src/test/scala/chiselTests/UIntOps.scala
index 4bd9706d..dc4a9d63 100644
--- a/src/test/scala/chiselTests/UIntOps.scala
+++ b/src/test/scala/chiselTests/UIntOps.scala
@@ -140,13 +140,13 @@ class UIntOpsSpec extends ChiselPropSpec with Matchers {
assertTesterPasses(new UIntLitExtractTester)
}
- property("toBools should support chained apply") {
+ property("asBools should support chained apply") {
elaborate(new Module {
val io = IO(new Bundle {
val in = Input(UInt(8.W))
val out = Output(Bool())
})
- io.out := io.in.toBools()(2)
+ io.out := io.in.asBools()(2)
})
}
}
diff --git a/src/test/scala/cookbook/UInt2VecOfBool.scala b/src/test/scala/cookbook/UInt2VecOfBool.scala
index f69c483a..10250ad5 100644
--- a/src/test/scala/cookbook/UInt2VecOfBool.scala
+++ b/src/test/scala/cookbook/UInt2VecOfBool.scala
@@ -6,13 +6,13 @@ import chisel3._
/* ### How do I create a Vec of Bools from a UInt?
*
- * Use the builtin function [[chisel3.core.Bits.toBools]] to create a Scala Seq of Bool,
+ * Use the builtin function [[chisel3.core.Bits.asBools]] to create a Scala Seq of Bool,
* then wrap the resulting Seq in Vec(...)
*/
class UInt2VecOfBool extends CookbookTester(1) {
// Example
val uint = 0xc.U
- val vec = VecInit(uint.toBools)
+ val vec = VecInit(uint.asBools)
printf(p"$vec") // Vec(0, 0, 1, 1)
// Test
diff --git a/src/test/scala/examples/VendingMachineGenerator.scala b/src/test/scala/examples/VendingMachineGenerator.scala
index c222ca07..48dabacd 100644
--- a/src/test/scala/examples/VendingMachineGenerator.scala
+++ b/src/test/scala/examples/VendingMachineGenerator.scala
@@ -93,7 +93,7 @@ class ParameterizedVendingMachineTester(
val (idx, done) = Counter(true.B, testLength + 1)
when (done) { stop(); stop() } // Two stops for Verilator
- dut.io.inputs := inputVec(idx).toBools
+ dut.io.inputs := inputVec(idx).asBools
assert(dut.io.dispense === expectedVec(idx))
}