From ddb7278760029be9d960ba8bf2b06ac8a8aac767 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Mon, 15 Aug 2016 22:48:14 -0700 Subject: Make "def width" a private API; expose isWidthKnown instead (#257) * Make "def width" a private API; expose isWidthKnown instead Resolves #256. Since width was used to determine whether getWidth would succeed, I added def isWidthKnown: Boolean but another option would be to expose something like def widthOption: Option[Int] ...thoughts? * Document getWidth/isWidthKnown * Add widthOption for more idiomatic Scala manipulation of widths --- src/main/scala/chisel3/util/BitPat.scala | 2 +- src/main/scala/chisel3/util/Bitwise.scala | 2 +- src/test/scala/chiselTests/Reg.scala | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/scala/chisel3/util/BitPat.scala b/src/main/scala/chisel3/util/BitPat.scala index d476f957..26106080 100644 --- a/src/main/scala/chisel3/util/BitPat.scala +++ b/src/main/scala/chisel3/util/BitPat.scala @@ -68,7 +68,7 @@ object BitPat { */ def apply(x: UInt): BitPat = { require(x.isLit) - val len = if (x.width.known) x.getWidth else 0 + val len = if (x.isWidthKnown) x.getWidth else 0 apply("b" + x.litValue.toString(2).reverse.padTo(len, "0").reverse.mkString) } } diff --git a/src/main/scala/chisel3/util/Bitwise.scala b/src/main/scala/chisel3/util/Bitwise.scala index 3134d043..6451ab14 100644 --- a/src/main/scala/chisel3/util/Bitwise.scala +++ b/src/main/scala/chisel3/util/Bitwise.scala @@ -29,7 +29,7 @@ object Fill { n match { case 0 => UInt(width=0) case 1 => x - case _ if x.width.known && x.getWidth == 1 => + case _ if x.isWidthKnown && x.getWidth == 1 => Mux(x.toBool, UInt((BigInt(1) << n) - 1, n), UInt(0, n)) case _ if n > 1 => val p2 = Array.ofDim[UInt](log2Up(n + 1)) diff --git a/src/test/scala/chiselTests/Reg.scala b/src/test/scala/chiselTests/Reg.scala index fc2cbf9d..a92d5ebf 100644 --- a/src/test/scala/chiselTests/Reg.scala +++ b/src/test/scala/chiselTests/Reg.scala @@ -16,7 +16,7 @@ class RegSpec extends ChiselFlatSpec { "A Reg" should "be of the same type and width as outType, if specified" in { class RegOutTypeWidthTester extends BasicTester { val reg = Reg(t=UInt(width=2), next=UInt(width=3), init=UInt(20)) - reg.width.get should be (2) + reg.getWidth should be (2) } elaborate{ new RegOutTypeWidthTester } } @@ -24,11 +24,11 @@ class RegSpec extends ChiselFlatSpec { "A Reg" should "be of unknown width if outType is not specified and width is not forced" in { class RegUnknownWidthTester extends BasicTester { val reg1 = Reg(next=UInt(width=3), init=UInt(20)) - reg1.width.known should be (false) + reg1.isWidthKnown should be (false) val reg2 = Reg(init=UInt(20)) - reg2.width.known should be (false) + reg2.isWidthKnown should be (false) val reg3 = Reg(next=UInt(width=3), init=UInt(width=5)) - reg3.width.known should be (false) + reg3.isWidthKnown should be (false) } elaborate { new RegUnknownWidthTester } } @@ -36,7 +36,7 @@ class RegSpec extends ChiselFlatSpec { "A Reg" should "be of width of init if outType and next are missing and init is a literal of forced width" in { class RegForcedWidthTester extends BasicTester { val reg2 = Reg(init=UInt(20, width=7)) - reg2.width.get should be (7) + reg2.getWidth should be (7) } elaborate{ new RegForcedWidthTester } } -- cgit v1.2.3