summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala7
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Bits.scala19
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Data.scala13
-rw-r--r--src/main/scala/chisel3/package.scala8
-rw-r--r--src/main/scala/chisel3/util/BitPat.scala4
-rw-r--r--src/main/scala/chisel3/util/Decoupled.scala6
-rw-r--r--src/main/scala/chisel3/util/Valid.scala6
-rw-r--r--src/test/scala/chiselTests/GCD.scala14
-rw-r--r--src/test/scala/chiselTests/Module.scala2
-rw-r--r--src/test/scala/chiselTests/Risc.scala12
10 files changed, 64 insertions, 27 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
index 1b49e163..666d8283 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
@@ -179,8 +179,11 @@ sealed class Vec[T <: Data] private (gen: => T, val length: Int)
@deprecated("Use Vec.apply instead", "chisel3")
def write(idx: UInt, data: T): Unit = apply(idx).:=(data)(DeprecatedSourceInfo)
- override def cloneType: this.type =
- Vec(length, gen).asInstanceOf[this.type]
+ override def cloneType: this.type = {
+ val clone = Vec(length, gen).asInstanceOf[this.type]
+ clone.unBind()
+ clone
+ }
private[chisel3] def toType: String = s"${sample_element.toType}[$length]"
private[chisel3] lazy val flatten: IndexedSeq[Bits] =
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
index 1bdf66f1..e8aae578 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
@@ -51,7 +51,11 @@ sealed abstract class Bits(width: Width, override val litArg: Option[LitArg])
private[chisel3] def flatten: IndexedSeq[Bits] = IndexedSeq(this)
- def cloneType: this.type = cloneTypeWidth(width)
+ def cloneType: this.type = {
+ val clone = cloneTypeWidth(width)
+ clone.unBind()
+ clone
+ }
final def tail(n: Int): UInt = macro SourceInfoTransform.nArg
final def head(n: Int): UInt = macro SourceInfoTransform.nArg
@@ -514,12 +518,12 @@ sealed class UInt private[core] (width: Width, lit: Option[ULit] = None)
private[core] sealed trait UIntFactory {
/** Create a UInt type with inferred width. */
def apply(): UInt = apply(Width())
+ /** Create a UInt type or port with fixed width. */
+ def apply(width: Int): UInt = apply(Width(width))
/** Create a UInt port with specified width. */
def apply(width: Width): UInt = new UInt(width)
/** Create a UInt with a specified width - compatibility with Chisel2. */
- def apply(dummy: Option[Direction] = None, width: Int): UInt = apply(Width(width))
- /** Create a UInt literal with inferred width. */
- def apply(value: BigInt): UInt = apply(value, Width())
+ def apply(dummy: Direction, width: Int): UInt = apply(Width(width))
/** Create a UInt literal with fixed width. */
def apply(value: BigInt, width: Int): UInt = apply(value, Width(width))
/** Create a UInt literal with inferred width. */
@@ -733,7 +737,12 @@ object Bool {
/** Creates Bool literal.
*/
- def apply(x: Boolean): Bool = new Bool(Some(ULit(if (x) 1 else 0, Width(1))))
+ def apply(x: Boolean): Bool = {
+ val result = new Bool(Some(ULit(if (x) 1 else 0, Width(1))))
+ // Bind result to being an Literal
+ result.binding = LitBinding()
+ result
+ }
}
object Mux {
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
index 4cc66cb5..79119114 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
@@ -174,6 +174,13 @@ abstract class Data extends HasId {
*/
@deprecated("Use asBits, which makes the reinterpret cast more explicit and actually returns Bits", "chisel3")
def toBits(): UInt = SeqUtils.do_asUInt(this.flatten)(DeprecatedSourceInfo)
+
+ protected def unBind(): Unit = {
+ //TODO(twigg): Do recursively for better error messages
+ for(elem <- this.allElements) {
+ elem.binding = UnboundBinding(elem.binding.direction)
+ }
+ }
}
object Wire {
@@ -210,7 +217,11 @@ object Clock {
// TODO: Document this.
sealed class Clock extends Element(Width(1)) {
- def cloneType: this.type = Clock().asInstanceOf[this.type]
+ def cloneType: this.type = {
+ val clone = Clock().asInstanceOf[this.type]
+ clone.unBind()
+ clone
+ }
private[chisel3] override def flatten: IndexedSeq[Bits] = IndexedSeq()
private[chisel3] def cloneTypeWidth(width: Width): this.type = cloneType
private[chisel3] def toType = "Clock"
diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala
index 71ec0e92..86fce6a2 100644
--- a/src/main/scala/chisel3/package.scala
+++ b/src/main/scala/chisel3/package.scala
@@ -1,9 +1,10 @@
+// See LICENSE for license details.
+
package object chisel3 {
import scala.language.experimental.macros
import internal.firrtl.Width
import internal.sourceinfo.{SourceInfo, SourceInfoTransform}
-
import util.BitPat
@@ -87,6 +88,11 @@ package object chisel3 {
implicit class fromBigIntToLiteral(val x: BigInt) extends AnyVal {
def U: UInt = UInt(x, Width())
def S: SInt = SInt(x, Width())
+
+ def asUInt() = UInt(x, Width())
+ def asSInt() = SInt(x, Width())
+ def asUInt(width: Int) = UInt(x, width)
+ def asSInt(width: Int) = SInt(x, width)
}
implicit class fromStringToLiteral(val x: String) extends AnyVal {
def U: UInt = UInt(x)
diff --git a/src/main/scala/chisel3/util/BitPat.scala b/src/main/scala/chisel3/util/BitPat.scala
index 9eb5cf67..3ae192a2 100644
--- a/src/main/scala/chisel3/util/BitPat.scala
+++ b/src/main/scala/chisel3/util/BitPat.scala
@@ -75,7 +75,7 @@ object BitPat {
// TODO: Break out of Core? (this doesn't involve FIRRTL generation)
/** Bit patterns are literals with masks, used to represent values with don't
* cares. Equality comparisons will ignore don't care bits (for example,
- * BitPat(0b10?1) === UInt(0b1001) and UInt(0b1011)).
+ * BitPat(0b10?1) === 0b1001.asUInt and 0b1011.asUInt.
*/
sealed class BitPat(val value: BigInt, val mask: BigInt, width: Int) {
def getWidth: Int = width
@@ -83,7 +83,7 @@ sealed class BitPat(val value: BigInt, val mask: BigInt, width: Int) {
def =/= (that: UInt): Bool = macro SourceInfoTransform.thatArg
def != (that: UInt): Bool = macro SourceInfoTransform.thatArg
- def do_=== (that: UInt)(implicit sourceInfo: SourceInfo): Bool = UInt(value) === (that & UInt(mask))
+ def do_=== (that: UInt)(implicit sourceInfo: SourceInfo): Bool = value.asUInt === (that & mask.asUInt)
def do_=/= (that: UInt)(implicit sourceInfo: SourceInfo): Bool = !(this === that)
def do_!= (that: UInt)(implicit sourceInfo: SourceInfo): Bool = this =/= that
}
diff --git a/src/main/scala/chisel3/util/Decoupled.scala b/src/main/scala/chisel3/util/Decoupled.scala
index 4a6b72e9..fb1ee6b9 100644
--- a/src/main/scala/chisel3/util/Decoupled.scala
+++ b/src/main/scala/chisel3/util/Decoupled.scala
@@ -58,7 +58,11 @@ object DecoupledIO {
target.ready := Bool(false)
}
}
-// override def cloneType: this.type = { DeqIO(gen).asInstanceOf[this.type]; }
+// override def cloneType: this.type = {
+// val clone = DeqIO(gen).asInstanceOf[this.type]
+// clone.unBind()
+// clone
+// }
}
object EnqIO {
diff --git a/src/main/scala/chisel3/util/Valid.scala b/src/main/scala/chisel3/util/Valid.scala
index 4078a76a..5641f0f2 100644
--- a/src/main/scala/chisel3/util/Valid.scala
+++ b/src/main/scala/chisel3/util/Valid.scala
@@ -13,7 +13,11 @@ class Valid[+T <: Data](gen: T) extends Bundle
val valid = Output(Bool())
val bits = Output(gen.cloneType)
def fire(dummy: Int = 0): Bool = valid
- override def cloneType: this.type = Valid(gen).asInstanceOf[this.type]
+ override def cloneType: this.type = {
+ val clone = Valid(gen).asInstanceOf[this.type]
+ clone.unBind()
+ clone
+ }
}
/** Adds a valid protocol to any interface */
diff --git a/src/test/scala/chiselTests/GCD.scala b/src/test/scala/chiselTests/GCD.scala
index a8b907af..7c04ae00 100644
--- a/src/test/scala/chiselTests/GCD.scala
+++ b/src/test/scala/chiselTests/GCD.scala
@@ -21,18 +21,18 @@ class GCD extends Module {
.otherwise { y := y -% x }
when (io.e) { x := io.a; y := io.b }
io.z := x
- io.v := y === UInt(0)
+ io.v := y === 0.U
}
class GCDTester(a: Int, b: Int, z: Int) extends BasicTester {
val dut = Module(new GCD)
- val first = Reg(init=Bool(true))
- dut.io.a := UInt(a)
- dut.io.b := UInt(b)
+ val first = Reg(init=true.B)
+ dut.io.a := a.U
+ dut.io.b := b.U
dut.io.e := first
- when(first) { first := Bool(false) }
- when(dut.io.v) {
- assert(dut.io.z === UInt(z))
+ when(first) { first := false.B }
+ when(!first && dut.io.v) {
+ assert(dut.io.z === z.U)
stop()
}
}
diff --git a/src/test/scala/chiselTests/Module.scala b/src/test/scala/chiselTests/Module.scala
index f1608d5b..857aeda3 100644
--- a/src/test/scala/chiselTests/Module.scala
+++ b/src/test/scala/chiselTests/Module.scala
@@ -11,7 +11,7 @@ class SimpleIO extends Bundle {
class PlusOne extends Module {
val io = IO(new SimpleIO)
- io.out := io.in + UInt(1)
+ io.out := io.in + 1.asUInt
}
class ModuleVec(val n: Int) extends Module {
diff --git a/src/test/scala/chiselTests/Risc.scala b/src/test/scala/chiselTests/Risc.scala
index fafec95a..c110d37e 100644
--- a/src/test/scala/chiselTests/Risc.scala
+++ b/src/test/scala/chiselTests/Risc.scala
@@ -27,13 +27,13 @@ class Risc extends Module {
val rai = inst(15, 8)
val rbi = inst( 7, 0)
- val ra = Mux(rai === Bits(0), Bits(0), file(rai))
- val rb = Mux(rbi === Bits(0), Bits(0), file(rbi))
+ val ra = Mux(rai === 0.asUInt(), 0.asUInt(), file(rai))
+ val rb = Mux(rbi === 0.asUInt(), 0.asUInt(), file(rbi))
val rc = Wire(Bits(width = 32))
io.valid := Bool(false)
- io.out := Bits(0)
- rc := Bits(0)
+ io.out := 0.asUInt()
+ rc := 0.asUInt()
when (io.isWr) {
code(io.wrAddr) := io.wrData
@@ -45,12 +45,12 @@ class Risc extends Module {
is(imm_op) { rc := (rai << 8) | rbi }
}
io.out := rc
- when (rci === UInt(255)) {
+ when (rci === 255.asUInt()) {
io.valid := Bool(true)
} .otherwise {
file(rci) := rc
}
- pc := pc +% UInt(1)
+ pc := pc +% 1.asUInt()
}
}