summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/core
diff options
context:
space:
mode:
authorJim Lawson2016-07-21 17:12:06 -0700
committerJim Lawson2016-07-21 17:12:06 -0700
commit7c9043859994b32bb07d2fce4ae61a7a3362a1b3 (patch)
tree0f307e975393adf246e59aae0cc1b626e4ab4c7c /chiselFrontend/src/main/scala/chisel3/core
parentd269818bdd4f2b71abebfaba9d7f8c9b4d488688 (diff)
Introduce chiselCloneType to distinguish from cloneType.
Still fails one test - DirectionSpec in Direction.scala
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala18
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Bits.scala6
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Data.scala24
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Mem.scala6
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Reg.scala4
5 files changed, 25 insertions, 33 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
index a80dfec8..7707d906 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
@@ -24,10 +24,10 @@ object Vec {
*
* @note elements are NOT assigned by default and have no value
*/
- def apply[T <: Data](n: Int, gen: T): Vec[T] = new Vec(gen.cloneType, n)
+ def apply[T <: Data](n: Int, gen: T): Vec[T] = new Vec(gen, n)
@deprecated("Vec argument order should be size, t; this will be removed by the official release", "chisel3")
- def apply[T <: Data](gen: T, n: Int): Vec[T] = new Vec(gen.cloneType, n)
+ def apply[T <: Data](gen: T, n: Int): Vec[T] = new Vec(gen, n)
/** Creates a new [[Vec]] composed of elements of the input Seq of [[Data]]
* nodes.
@@ -104,12 +104,12 @@ object Vec {
* @note Vecs, unlike classes in Scala's collection library, are propagated
* intact to FIRRTL as a vector type, which may make debugging easier
*/
-sealed class Vec[T <: Data] private (gen: => T, val length: Int)
+sealed class Vec[T <: Data] private (gen: T, val length: Int)
extends Aggregate with VecLike[T] {
// Note: the constructor takes a gen() function instead of a Seq to enforce
// that all elements must be the same and because it makes FIRRTL generation
// simpler.
- private val self = IndexedSeq.fill(length)(gen)
+ private val self: Seq[T] = Vector.fill(length)(gen.chiselCloneType)
/**
* sample_element 'tracks' all changes to the elements of self.
@@ -118,7 +118,7 @@ sealed class Vec[T <: Data] private (gen: => T, val length: Int)
*
* Needed specifically for the case when the Vec is length 0.
*/
- private[core] val sample_element: T = gen
+ private[core] val sample_element: T = gen.chiselCloneType
// allElements current includes sample_element
// This is somewhat weird although I think the best course of action here is
@@ -157,7 +157,7 @@ sealed class Vec[T <: Data] private (gen: => T, val length: Int)
*/
def apply(idx: UInt): T = {
Binding.checkSynthesizable(idx ,s"'idx' ($idx)")
- val port = sample_element.cloneType
+ val port = sample_element.chiselCloneType
port.setRef(this, idx) //TODO(twigg): This is a bit too magical
// Bind each element of port to being whatever the base type is
@@ -180,9 +180,7 @@ sealed class Vec[T <: Data] private (gen: => T, val length: Int)
def write(idx: UInt, data: T): Unit = apply(idx).:=(data)(DeprecatedSourceInfo)
override def cloneType: this.type = {
- val clone = Vec(length, gen).asInstanceOf[this.type]
- clone.unBind()
- clone
+ Vec(length, gen).asInstanceOf[this.type]
}
private[chisel3] def toType: String = s"${sample_element.toType}[$length]"
@@ -390,5 +388,5 @@ class Bundle extends Aggregate {
}
private[core] object Bundle {
- val keywords = List("flip", "asInput", "asOutput", "cloneType", "toBits")
+ val keywords = List("flip", "asInput", "asOutput", "cloneType", "toBits", "chiselCloneType")
}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
index ee0acd86..07c113fd 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
@@ -51,11 +51,7 @@ sealed abstract class Bits(width: Width, override val litArg: Option[LitArg])
private[chisel3] def flatten: IndexedSeq[Bits] = IndexedSeq(this)
- def cloneType: this.type = {
- val clone = cloneTypeWidth(width)
- clone.unBind()
- clone
- }
+ def cloneType: this.type = cloneTypeWidth(width)
final def tail(n: Int): UInt = macro SourceInfoTransform.nArg
final def head(n: Int): UInt = macro SourceInfoTransform.nArg
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
index 79119114..fee5c01c 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
@@ -120,6 +120,15 @@ abstract class Data extends HasId {
private[chisel3] def toType: String
def cloneType: this.type
+ def chiselCloneType: this.type = {
+ // Call the user-supplied cloneType method
+ val clone = this.cloneType
+ //TODO(twigg): Do recursively for better error messages
+ for((clone_elem, source_elem) <- clone.allElements zip this.allElements) {
+ clone_elem.binding = UnboundBinding(source_elem.binding.direction)
+ }
+ clone
+ }
final def := (that: Data)(implicit sourceInfo: SourceInfo): Unit = this connect that
final def <> (that: Data)(implicit sourceInfo: SourceInfo): Unit = this bulkConnect that
def litArg(): Option[LitArg] = None
@@ -154,7 +163,7 @@ abstract class Data extends HasId {
def do_fromBits(that: Bits)(implicit sourceInfo: SourceInfo): this.type = {
var i = 0
- val wire = Wire(this.cloneType)
+ val wire = Wire(this.chiselCloneType)
val bits =
if (that.width.known && that.width.get >= wire.width.get) {
that
@@ -174,13 +183,6 @@ 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 {
@@ -217,11 +219,7 @@ object Clock {
// TODO: Document this.
sealed class Clock extends Element(Width(1)) {
- def cloneType: this.type = {
- val clone = Clock().asInstanceOf[this.type]
- clone.unBind()
- clone
- }
+ def cloneType: this.type = Clock().asInstanceOf[this.type]
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/chiselFrontend/src/main/scala/chisel3/core/Mem.scala b/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
index a4e6bee3..fd0897a2 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
@@ -20,7 +20,7 @@ object Mem {
*/
def apply[T <: Data](size: Int, t: T): Mem[T] = macro MemTransform.apply[T]
def do_apply[T <: Data](size: Int, t: T)(implicit sourceInfo: SourceInfo): Mem[T] = {
- val mt = t.cloneType
+ val mt = t.chiselCloneType
Binding.bind(mt, NoDirectionBinder, "Error: fresh t")
// TODO(twigg): Remove need for this Binding
@@ -86,7 +86,7 @@ sealed abstract class MemBase[T <: Data](t: T, val length: Int) extends HasId wi
val port = pushCommand(
DefMemPort(sourceInfo,
- t.cloneType, Node(this), dir, idx.ref, Node(idx._parent.get.clock))
+ t.chiselCloneType, Node(this), dir, idx.ref, Node(idx._parent.get.clock))
).id
// Bind each element of port to being a MemoryPort
Binding.bind(port, MemoryPortBinder(Builder.forcedModule), "Error: Fresh t")
@@ -117,7 +117,7 @@ object SeqMem {
def apply[T <: Data](size: Int, t: T): SeqMem[T] = macro MemTransform.apply[T]
def do_apply[T <: Data](size: Int, t: T)(implicit sourceInfo: SourceInfo): SeqMem[T] = {
- val mt = t.cloneType
+ val mt = t.chiselCloneType
Binding.bind(mt, NoDirectionBinder, "Error: fresh t")
// TODO(twigg): Remove need for this Binding
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Reg.scala b/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
index e0607520..c1693531 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
@@ -12,13 +12,13 @@ object Reg {
init: T = null): T = {
if (t ne null) {
Binding.checkUnbound(t, s"t ($t) must be unbound Type. Try using cloneType?")
- t.cloneType
+ t.chiselCloneType
} else if (next ne null) {
next.cloneTypeWidth(Width())
} else if (init ne null) {
init.litArg match {
// For e.g. Reg(init=UInt(0, k)), fix the Reg's width to k
- case Some(lit) if lit.forcedWidth => init.cloneType
+ case Some(lit) if lit.forcedWidth => init.chiselCloneType
case _ => init.cloneTypeWidth(Width())
}
} else {