summaryrefslogtreecommitdiff
path: root/src/main/scala/Chisel
diff options
context:
space:
mode:
authorAndrew Waterman2015-08-10 17:44:35 -0700
committerAndrew Waterman2015-08-10 17:44:35 -0700
commitd4a4ee78a36783b5d8d90c4382b4332a70485244 (patch)
tree1939558af67b99267d2fbe31716acc9a14aacd26 /src/main/scala/Chisel
parentd161470df3ba1e07b6926b37f06798ffa2dd3417 (diff)
Make Bits.toBool safe
It now fails if the width is unknown or is not equal to 1. We could consider relaxing this later, defining it as this.orR.
Diffstat (limited to 'src/main/scala/Chisel')
-rw-r--r--src/main/scala/Chisel/Core.scala6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/main/scala/Chisel/Core.scala b/src/main/scala/Chisel/Core.scala
index 4b8d2ca3..1ab84681 100644
--- a/src/main/scala/Chisel/Core.scala
+++ b/src/main/scala/Chisel/Core.scala
@@ -639,7 +639,11 @@ sealed abstract class Bits(dirArg: Direction, width: Width, override val litArg:
def asUInt(): UInt
final def toSInt(): SInt = asSInt
final def toUInt(): UInt = asUInt
- def toBool(): Bool = this(0)
+
+ def toBool(): Bool = width match {
+ case KnownWidth(1) => this(0)
+ case _ => throwException(s"can't covert UInt<$width> to Bool")
+ }
override def toBits = asUInt
override def fromBits(n: Bits): this.type = {