diff options
| author | Andrew Waterman | 2015-08-10 17:44:35 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2015-08-10 17:44:35 -0700 |
| commit | d4a4ee78a36783b5d8d90c4382b4332a70485244 (patch) | |
| tree | 1939558af67b99267d2fbe31716acc9a14aacd26 | |
| parent | d161470df3ba1e07b6926b37f06798ffa2dd3417 (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.
| -rw-r--r-- | src/main/scala/Chisel/Core.scala | 6 |
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 = { |
