summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAndrew Waterman2015-08-20 23:26:04 -0700
committerAndrew Waterman2015-08-26 15:21:45 -0700
commit834dd38ea1bc6c6ac5453d8e73893910a5dcc968 (patch)
treedfc4c56ff4f5a861b01233e89ae2450e4c4c6c97 /src/main
parentd2e3c20eff2f8098a9b5b96bc81d5e32e202b69e (diff)
Simplify I/O zero-initialization
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/Chisel/Core.scala6
-rw-r--r--src/main/scala/Chisel/Emitter.scala14
2 files changed, 7 insertions, 13 deletions
diff --git a/src/main/scala/Chisel/Core.scala b/src/main/scala/Chisel/Core.scala
index 60b22830..8495a5d4 100644
--- a/src/main/scala/Chisel/Core.scala
+++ b/src/main/scala/Chisel/Core.scala
@@ -781,10 +781,16 @@ object Module {
paramsScope(currParams) {
val parent = dynamicContext.currentModule
val m = bc.setRefs()
+ // init module outputs
+ m._commands prependAll (for (p <- m.io.flatten; if p.dir == OUTPUT)
+ yield Connect(p.lref, p.fromInt(0).ref))
dynamicContext.currentModule = parent
val ports = m.computePorts
Builder.components += Component(m, m.name, ports, m._commands)
pushCommand(DefInstance(m, ports))
+ // init instance inputs
+ for (p <- m.io.flatten; if p.dir == INPUT)
+ p := p.fromInt(0)
m
}.connectImplicitIOs()
}
diff --git a/src/main/scala/Chisel/Emitter.scala b/src/main/scala/Chisel/Emitter.scala
index d384a536..fd271aa4 100644
--- a/src/main/scala/Chisel/Emitter.scala
+++ b/src/main/scala/Chisel/Emitter.scala
@@ -19,11 +19,7 @@ private class Emitter(circuit: Circuit) {
case e: ConnectInit => s"onreset ${e.loc.fullName(ctx)} := ${e.exp.fullName(ctx)}"
case e: DefInstance => {
val modName = moduleMap.getOrElse(e.id.name, e.id.name)
- val res = new StringBuilder(s"inst ${e.name} of $modName")
- res ++= newline
- for (p <- e.ports; x <- initPort(p, INPUT, ctx))
- res ++= newline + x
- res.toString
+ s"inst ${e.name} of $modName"
}
case w: WhenBegin =>
@@ -36,20 +32,12 @@ private class Emitter(circuit: Circuit) {
unindent()
"skip"
}
- private def initPort(p: Data, dir: Direction, ctx: Component) = {
- for (x <- p.flatten; if x.dir == dir)
- yield s"${x.getRef.fullName(ctx)} := ${x.makeLit(0).name}"
- }
-
private def emitBody(m: Component) = {
val me = new StringBuilder
withIndent {
for (p <- m.ports)
me ++= newline + emitPort(p)
me ++= newline
- for (p <- m.ports; x <- initPort(p, OUTPUT, m))
- me ++= newline + x
- me ++= newline
for (cmd <- m.commands)
me ++= newline + emit(cmd, m)
me ++= newline