summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
7 files changed, 33 insertions, 19 deletions
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()
}
}