diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/scala/Chisel/BlackBox.scala | 34 | ||||
| -rw-r--r-- | src/main/scala/Chisel/Module.scala | 37 | ||||
| -rw-r--r-- | src/main/scala/Chisel/util/Decoupled.scala | 7 |
3 files changed, 59 insertions, 19 deletions
diff --git a/src/main/scala/Chisel/BlackBox.scala b/src/main/scala/Chisel/BlackBox.scala index ae0c59ba..48887271 100644 --- a/src/main/scala/Chisel/BlackBox.scala +++ b/src/main/scala/Chisel/BlackBox.scala @@ -2,6 +2,9 @@ package Chisel +import internal.Builder.pushCommand +import internal.firrtl.{ModuleIO, DefInvalid} + /** Defines a black box, which is a module that can be referenced from within * Chisel, but is not defined in the emitted Verilog. Useful for connecting * to RTL modules defined outside Chisel. @@ -12,10 +15,37 @@ package Chisel * }}} */ // REVIEW TODO: make Verilog parameters part of the constructor interface? -abstract class BlackBox(_clock: Clock = null, _reset: Bool = null) - extends Module(_clock = _clock, _reset = _reset) { +abstract class BlackBox extends Module { + // Don't bother taking override_clock|reset, clock/reset locked out anyway // TODO: actually implement this. def setVerilogParameters(s: String): Unit = {} // The body of a BlackBox is empty, the real logic happens in firrtl/Emitter.scala + // Bypass standard clock, reset, io port declaration by flattening io + // TODO(twigg): ? Really, overrides are bad, should extend BaseModule.... + override private[Chisel] def ports = io.elements.toSeq + + // Do not do reflective naming of internal signals, just name io + override private[Chisel] def setRefs(): this.type = { + for ((name, port) <- ports) { + port.setRef(ModuleIO(this, _namespace.name(name))) + } + io.setRef("") // don't io parts prepended with io_ + this + } + + // Don't setup clock, reset + // Cann't invalide io in one bunch, must invalidate each part separately + override private[Chisel] def setupInParent(): this.type = _parent match { + case Some(p) => { + // Just init instance inputs + for((_,port) <- ports) pushCommand(DefInvalid(port.ref)) + this + } + case None => this + } + + // Using null is horrible but these signals SHOULD NEVER be used: + override val clock = null + override val reset = null } diff --git a/src/main/scala/Chisel/Module.scala b/src/main/scala/Chisel/Module.scala index cfcf5a48..738863e3 100644 --- a/src/main/scala/Chisel/Module.scala +++ b/src/main/scala/Chisel/Module.scala @@ -25,8 +25,7 @@ object Module { val ports = m.computePorts Builder.components += Component(m, m.name, ports, m._commands) pushCommand(DefInstance(m, ports)) - pushCommand(DefInvalid(m.io.ref)) // init instance inputs - m.connectImplicitIOs() + m.setupInParent() } } @@ -36,8 +35,14 @@ object Module { * * @note Module instantiations must be wrapped in a Module() call. */ -abstract class Module(_clock: Clock = null, _reset: Bool = null) extends HasId { - private val _namespace = Builder.globalNamespace.child +abstract class Module( + override_clock: Option[Clock]=None, override_reset: Option[Bool]=None) +extends HasId { + def this(clock: Clock) = this(Some(clock), None) + def this(reset: Bool) = this(None, Some(reset)) + def this(clock: Clock, reset: Bool) = this(Some(clock), Some(reset)) + + private[Chisel] val _namespace = Builder.globalNamespace.child private[Chisel] val _commands = ArrayBuffer[Command]() private[Chisel] val _ids = ArrayBuffer[HasId]() dynamicContext.currentModule = Some(this) @@ -54,27 +59,29 @@ abstract class Module(_clock: Clock = null, _reset: Bool = null) extends HasId { private[Chisel] def addId(d: HasId) { _ids += d } - private def ports = (clock, "clk") :: (reset, "reset") :: (io, "io") :: Nil + private[Chisel] def ports: Seq[(String,Data)] = Vector( + ("clk", clock), ("reset", reset), ("io", io) + ) - private[Chisel] def computePorts = ports map { case (port, name) => + private[Chisel] def computePorts = for((name, port) <- ports) yield { val bundleDir = if (port.isFlip) INPUT else OUTPUT Port(port, if (port.dir == NO_DIR) bundleDir else port.dir) } - private def connectImplicitIOs(): this.type = _parent match { - case Some(p) => - clock := (if (_clock eq null) p.clock else _clock) - reset := (if (_reset eq null) p.reset else _reset) + private[Chisel] def setupInParent(): this.type = _parent match { + case Some(p) => { + pushCommand(DefInvalid(io.ref)) // init instance inputs + clock := override_clock.getOrElse(p.clock) + reset := override_reset.getOrElse(p.reset) this + } case None => this } - private def makeImplicitIOs(): Unit = ports map { case (port, name) => - } - - private def setRefs(): this.type = { - for ((port, name) <- ports) + private[Chisel] def setRefs(): this.type = { + for ((name, port) <- ports) { port.setRef(ModuleIO(this, _namespace.name(name))) + } // Suggest names to nodes using runtime reflection val valNames = HashSet[String](getClass.getDeclaredFields.map(_.getName):_*) diff --git a/src/main/scala/Chisel/util/Decoupled.scala b/src/main/scala/Chisel/util/Decoupled.scala index faee2a5f..6c7787f8 100644 --- a/src/main/scala/Chisel/util/Decoupled.scala +++ b/src/main/scala/Chisel/util/Decoupled.scala @@ -104,8 +104,11 @@ class QueueIO[T <: Data](gen: T, entries: Int) extends Bundle class Queue[T <: Data](gen: T, val entries: Int, pipe: Boolean = false, flow: Boolean = false, - _reset: Bool = null) extends Module(_reset=_reset) -{ + override_reset: Option[Bool] = None) +extends Module(override_reset=override_reset) { + def this(gen: T, entries: Int, pipe: Boolean, flow: Boolean, reset: Bool) = + this(gen, entries, pipe, flow, Some(reset)) + val io = new QueueIO(gen, entries) val ram = Mem(entries, gen) |
