summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAndrew Waterman2015-08-13 14:59:26 -0700
committerAndrew Waterman2015-08-13 15:00:33 -0700
commit02adb3e2fb40f555e317eb63d0927c082c0d0099 (patch)
treead6eec40031196bd5a06f815bb89dfdc51d5b62d /src/main
parent5096af220f54c63a2a7cd2da96aaab2b9ca0f633 (diff)
Check validity of bit extract ranges
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/Chisel/Core.scala16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/main/scala/Chisel/Core.scala b/src/main/scala/Chisel/Core.scala
index 063dbc98..d257044b 100644
--- a/src/main/scala/Chisel/Core.scala
+++ b/src/main/scala/Chisel/Core.scala
@@ -340,21 +340,25 @@ sealed abstract class Bits(dirArg: Direction, width: Width, override val litArg:
override def <> (that: Data): Unit = this := that
- final def apply(x: BigInt): Bool =
+ final def apply(x: BigInt): Bool = {
+ if (x < 0)
+ ChiselError.error(s"Negative bit indices are illegal (got $x)")
if (isLit()) Bool((litValue() >> x.toInt) & 1)
else pushOp(DefPrim(Bool(), BitSelectOp, this.ref, ILit(x)))
+ }
final def apply(x: Int): Bool =
apply(BigInt(x))
final def apply(x: UInt): Bool =
(this >> x)(0)
- final def apply(x: BigInt, y: BigInt): UInt = {
- val w = (x - y + 1).toInt
- if (isLit()) UInt((litValue >> y.toInt) & ((BigInt(1) << w) - 1), w)
+ final def apply(x: Int, y: Int): UInt = {
+ if (x < y || y < 0)
+ ChiselError.error(s"Invalid bit range ($x,$y)")
+ val w = x - y + 1
+ if (isLit()) UInt((litValue >> y) & ((BigInt(1) << w) - 1), w)
else pushOp(DefPrim(UInt(width = w), BitsExtractOp, this.ref, ILit(x), ILit(y)))
}
- final def apply(x: Int, y: Int): UInt =
- apply(BigInt(x), BigInt(y))
+ final def apply(x: BigInt, y: BigInt): UInt = apply(x.toInt, y.toInt)
private[Chisel] def unop[T <: Data](dest: T, op: PrimOp): T =
pushOp(DefPrim(dest, op, this.ref))