diff options
| author | Jim Lawson | 2016-08-16 11:08:32 -0700 |
|---|---|---|
| committer | Jim Lawson | 2016-08-16 11:08:32 -0700 |
| commit | a264157a47f56216cebf2d98c1c8118c344dad5f (patch) | |
| tree | 1724fe2900ce336822e73f9cae8280b8474f62ab /chiselFrontend/src/main/scala | |
| parent | 4ab2aa0e9209000fb0ba1299ac18db2e033f708f (diff) | |
| parent | ddb7278760029be9d960ba8bf2b06ac8a8aac767 (diff) | |
Merge branch 'master' into sdtwigg_connectwrap_renamechisel3
Diffstat (limited to 'chiselFrontend/src/main/scala')
3 files changed, 16 insertions, 9 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala index 459a3b67..12ae7e6b 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala @@ -15,8 +15,8 @@ import chisel3.internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, VecTransfo * of) other Data objects. */ sealed abstract class Aggregate extends Data { - private[chisel3] def cloneTypeWidth(width: Width): this.type = cloneType - private[chisel3] def width: Width = flatten.map(_.width).reduce(_ + _) + private[core] def cloneTypeWidth(width: Width): this.type = cloneType + private[core] def width: Width = flatten.map(_.width).reduce(_ + _) } object Vec { @@ -388,5 +388,6 @@ class Bundle extends Aggregate { } private[core] object Bundle { - val keywords = List("flip", "asInput", "asOutput", "cloneType", "toBits", "chiselCloneType") + val keywords = List("flip", "asInput", "asOutput", "cloneType", "toBits", + "widthOption", "chiselCloneType") } diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala index 7a3962a0..c2621251 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala @@ -385,7 +385,7 @@ abstract trait Num[T <: Data] { sealed class UInt private[core] (width: Width, lit: Option[ULit] = None) extends Bits(width, lit) with Num[UInt] { - private[chisel3] override def cloneTypeWidth(w: Width): this.type = + private[core] override def cloneTypeWidth(w: Width): this.type = new UInt(w).asInstanceOf[this.type] private[chisel3] def toType = s"UInt$width" @@ -577,7 +577,7 @@ object UInt extends UIntFactory sealed class SInt private (width: Width, lit: Option[SLit] = None) extends Bits(width, lit) with Num[SInt] { - private[chisel3] override def cloneTypeWidth(w: Width): this.type = + private[core] override def cloneTypeWidth(w: Width): this.type = new SInt(w).asInstanceOf[this.type] private[chisel3] def toType = s"SInt$width" @@ -721,7 +721,7 @@ object SInt { /** A data type for booleans, defined as a single bit indicating true or false. */ sealed class Bool(lit: Option[ULit] = None) extends UInt(Width(1), lit) { - private[chisel3] override def cloneTypeWidth(w: Width): this.type = { + private[core] override def cloneTypeWidth(w: Width): this.type = { require(!w.known || w.get == 1) new Bool().asInstanceOf[this.type] } diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala index 9115d1ba..bf68773f 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala @@ -117,8 +117,9 @@ abstract class Data extends HasId { } private[chisel3] def lref: Node = Node(this) private[chisel3] def ref: Arg = if (isLit) litArg.get else lref - private[chisel3] def cloneTypeWidth(width: Width): this.type + private[core] def cloneTypeWidth(width: Width): this.type private[chisel3] def toType: String + private[core] def width: Width def cloneType: this.type def chiselCloneType: this.type = { @@ -136,8 +137,13 @@ abstract class Data extends HasId { def litValue(): BigInt = litArg.get.num def isLit(): Boolean = litArg.isDefined - private[core] def width: Width + /** Returns the width, in bits, if currently known. + * @throws java.util.NoSuchElementException if the width is not known. */ final def getWidth: Int = width.get + /** Returns whether the width is currently known. */ + final def isWidthKnown: Boolean = width.known + /** Returns Some(width) if the width is known, else None. */ + final def widthOption: Option[Int] = if (isWidthKnown) Some(getWidth) else None // While this being in the Data API doesn't really make sense (should be in // Aggregate, right?) this is because of an implementation limitation: @@ -241,7 +247,7 @@ object Clock { sealed class Clock extends Element(Width(1)) { def cloneType: this.type = Clock().asInstanceOf[this.type] private[chisel3] override def flatten: IndexedSeq[Bits] = IndexedSeq() - private[chisel3] def cloneTypeWidth(width: Width): this.type = cloneType + private[core] def cloneTypeWidth(width: Width): this.type = cloneType private[chisel3] def toType = "Clock" override def connect (that: Data)(implicit sourceInfo: SourceInfo): Unit = that match { |
