summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/scala/Core.scala62
-rw-r--r--src/main/scala/Driver.scala1
-rw-r--r--src/main/scala/utils.scala18
3 files changed, 55 insertions, 26 deletions
diff --git a/src/main/scala/Core.scala b/src/main/scala/Core.scala
index 94352327..7145ccaa 100644
--- a/src/main/scala/Core.scala
+++ b/src/main/scala/Core.scala
@@ -56,7 +56,7 @@ object Builder {
else if (cmds.length == 1)
cmds(0)
else
- Begin(cmds.toArray)
+ Begin(cmds.toList)
}
def pushCommands =
commandz.push(new ArrayBuffer[Command]())
@@ -77,7 +77,8 @@ object Builder {
def legalizeName (name: String) = {
if (name == "mem" || name == "node" || name == "wire" ||
name == "reg" || name == "inst")
- genSym.next(name)
+ // genSym.next(name)
+ name + "__"
else
name
}
@@ -240,7 +241,7 @@ case class DefSeqMemory(val id: String, val kind: Kind, val size: Int) extends D
case class DefAccessor(val id: String, val source: Alias, val direction: Direction, val index: Arg) extends Definition;
case class DefInstance(val id: String, val module: String) extends Definition;
case class Conditionally(val prep: Command, val pred: Arg, val conseq: Command, var alt: Command) extends Command;
-case class Begin(val body: Array[Command]) extends Command();
+case class Begin(val body: List[Command]) extends Command();
case class Connect(val loc: Alias, val exp: Arg) extends Command;
case class BulkConnect(val loc1: Alias, val loc2: Alias) extends Command;
case class ConnectInit(val loc: Alias, val exp: Arg) extends Command;
@@ -304,6 +305,7 @@ abstract class Data(dirArg: Direction) extends Id {
def setDir(dir: Direction) {
isFlipVar = (dir == INPUT)
}
+ def init(dummy:Int = 0) = { }
def asInput: this.type = {
setDir(INPUT)
this
@@ -443,7 +445,7 @@ class SeqMem[T <: Data](t: T, n: Int) {
}
object Vec {
- def apply[T <: Data](gen: T, n: Int): Vec[T] =
+ def apply[T <: Data](gen: => T, n: Int): Vec[T] =
new Vec((0 until n).map(i => gen.cloneType))
def apply[T <: Data](elts: Iterable[T]): Vec[T] = {
val vec = new Vec[T](elts.map(e => elts.head.cloneType))
@@ -476,8 +478,12 @@ class Vec[T <: Data](elts: Iterable[T], dirArg: Direction = NO_DIR) extends Aggr
private val self = elts.toIndexedSeq
private val elt0 = elts.head
- for ((e, i) <- self zipWithIndex)
+ // println("BEGIN VEC NAMING")
+ for ((e, i) <- self zipWithIndex) {
+ // println(" NAME " + i + " -> " + cid)
setIndexForId(cid, e.cid, i)
+ }
+ // println("DONE VEC NAMING")
def <> (that: Iterable[T]): Unit =
this <> Vec(that).asInstanceOf[Data]
@@ -499,8 +505,10 @@ class Vec[T <: Data](elts: Iterable[T], dirArg: Direction = NO_DIR) extends Aggr
self.map(d => d.toPort).toArray
def toType: Kind =
VectorType(self.size, elt0.toType, isFlipVar)
- override def cloneType: this.type =
+ override def cloneType: this.type =
Vec(elt0.cloneType, self.size).asInstanceOf[this.type]
+ override def init(dummy:Int = 0) =
+ for (e <- self) e.init()
def inits (f: (Int, T, (Int, T, T) => Unit) => Unit) = {
var i = 0
def doInit (index: Int, elt: T, init: T) =
@@ -948,7 +956,8 @@ object Cat {
object Bundle {
val keywords = HashSet[String]("elements", "flip", "toString",
"flatten", "binding", "asInput", "asOutput", "unary_$tilde",
- "unary_$bang", "unary_$minus", "cloneType", "toUInt", "toBits",
+ "unary_$bang", "unary_$minus", "cloneType",
+ "toUInt", "toBits",
"toBool", "toSInt", "asDirectionless")
def apply[T <: Bundle](b: => T)(implicit p: Parameters): T = {
Driver.parStack.push(p.push)
@@ -963,7 +972,15 @@ object Bundle {
private def params = if(Driver.parStack.isEmpty) Parameters.empty else Driver.parStack.top
}
-class Bundle(dirArg: Direction = NO_DIR) extends Aggregate(dirArg) {
+trait BundleFinalizer extends DelayedInit {
+ def collectElts = { }
+ def delayedInit(body: => Unit) = {
+ body // evaluates the initialization code of C
+ collectElts
+ }
+}
+
+class Bundle(dirArg: Direction = NO_DIR) extends Aggregate(dirArg) with BundleFinalizer {
def toPorts: Array[Port] =
elements.map(_._2.toPort).toArray
def toType: BundleType =
@@ -974,31 +991,34 @@ class Bundle(dirArg: Direction = NO_DIR) extends Aggregate(dirArg) {
sortedElts.map(_.flatten).reduce(_ ++ _)
}
+ override def init(dummy:Int = 0) =
+ for ((s, e) <- elements) e.init()
lazy val elements: LinkedHashMap[String, Data] = {
- def isInterface(cls: Class[_], supcls: Class[_]): Boolean = {
- if (cls == supcls) true
- else if (cls == null || cls == Class.forName("java.lang.Object")) false
- else isInterface(cls.getSuperclass, supcls)
- }
-
val elts = LinkedHashMap[String, Data]()
- for (m <- getClass.getDeclaredMethods) {
+ // println("BEGIN BUNDLE NAMING " + cid)
+ for (m <- getClass.getMethods) {
val name = m.getName
+ // println("NAME = " + name)
+ val rtype = m.getReturnType
+ val isInterface = classOf[Data].isAssignableFrom(rtype)
if (m.getParameterTypes.isEmpty &&
!isStatic(m.getModifiers) &&
- isInterface(m.getReturnType, Class.forName("Chisel.Data")) &&
+ isInterface &&
!(Bundle.keywords contains name)) {
val obj = m.invoke(this)
obj match {
case data: Data =>
+ // println(" NAMING " + name + " -> " + cid)
setFieldForId(cid, data.cid, name)
elts(name) = data
case _ => ()
}
}
}
+ // println("DONE BUNDLE NAMING " + cid)
elts
}
+ override def collectElts = elements
override def cloneType : this.type = {
try {
@@ -1008,9 +1028,11 @@ class Bundle(dirArg: Direction = NO_DIR) extends Aggregate(dirArg) {
} catch {
case npe: java.lang.reflect.InvocationTargetException if npe.getCause.isInstanceOf[java.lang.NullPointerException] =>
// throwException("Parameterized Bundle " + this.getClass + " needs cloneType method. You are probably using an anonymous Bundle object that captures external state and hence is un-cloneTypeable", npe)
- error("BAD")
+ val s = "CLONE INVOKATION EXCEPTION " + this.getClass
+ error(s)
case e: java.lang.Exception =>
- error("BAD")
+ val s = "CLONE EXCEPTION " + this.getClass
+ error(s)
// throwException("Parameterized Bundle " + this.getClass + " needs cloneType method", e)
}
}
@@ -1157,6 +1179,8 @@ class Emitter {
parts.foldLeft("")((s, p) => if (s == "") p else s + sep + p)
def join0(parts: Array[String], sep: String) =
parts.foldLeft("")((s, p) => s + sep + p)
+ def join0(parts: List[String], sep: String) =
+ parts.foldLeft("")((s, p) => s + sep + p)
def newline =
"\n" + join((0 until indenting).map(x => " ").toArray, "")
def emitDir(e: Direction, isTop: Boolean): String =
@@ -1207,7 +1231,7 @@ class Emitter {
""
}
val suffix = if (!e.alt.isInstanceOf[EmptyCommand]) {
- newline + "else : " + newline + withIndent{ emit(e.alt) }
+ newline + "else : " + withIndent{ newline + emit(e.alt) }
} else {
""
}
diff --git a/src/main/scala/Driver.scala b/src/main/scala/Driver.scala
index 0b714b6f..c4a26221 100644
--- a/src/main/scala/Driver.scala
+++ b/src/main/scala/Driver.scala
@@ -148,6 +148,7 @@ object Driver extends FileSystemUtilities{
// setTopComponent(c)
if (!isTesting) {
val s = emitter.emit( c )
+ // println(c.components(0))
val filename = c.main + ".fir"
// println("FILENAME " + filename)
// println("S = " + s)
diff --git a/src/main/scala/utils.scala b/src/main/scala/utils.scala
index 8e6ce571..4135d92b 100644
--- a/src/main/scala/utils.scala
+++ b/src/main/scala/utils.scala
@@ -275,12 +275,12 @@ object Counter
}
}
-class ValidIO[+T <: Data](gen: T) extends Bundle
+class ValidIO[+T <: Data](gen2: T) extends Bundle
{
val valid = Bool(OUTPUT)
- val bits = gen.cloneType.asOutput
+ val bits = gen2.cloneType.asOutput
def fire(dummy: Int = 0): Bool = valid
- override def cloneType: this.type = new ValidIO(gen).asInstanceOf[this.type]
+ override def cloneType: this.type = new ValidIO(gen2).asInstanceOf[this.type]
}
/** Adds a valid protocol to any interface. The standard used is
@@ -310,16 +310,20 @@ object Decoupled {
class EnqIO[T <: Data](gen: T) extends DecoupledIO(gen)
{
def enq(dat: T): T = { valid := Bool(true); bits := dat; dat }
- valid := Bool(false);
- for (io <- bits.flatten)
- io := UInt(0)
+ override def init(dummy: Int = 0) = {
+ valid := Bool(false);
+ for (io <- bits.flatten)
+ io := UInt(0)
+ }
override def cloneType: this.type = { new EnqIO(gen).asInstanceOf[this.type]; }
}
class DeqIO[T <: Data](gen: T) extends DecoupledIO(gen)
{
flip()
- ready := Bool(false);
+ override def init(dummy: Int = 0) = {
+ ready := Bool(false)
+ }
def deq(b: Boolean = false): T = { ready := Bool(true); bits }
override def cloneType: this.type = { new DeqIO(gen).asInstanceOf[this.type]; }
}