From d4a4ee78a36783b5d8d90c4382b4332a70485244 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Mon, 10 Aug 2015 17:44:35 -0700 Subject: 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. --- src/main/scala/Chisel/Core.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') 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 = { -- cgit v1.2.3