diplomacy: Allow LazyModuleImps to be based on RawModules or MultiIOModules
And add a MonitorBase class to be connect's return type.
This commit is contained in:
@ -4,6 +4,7 @@ package diplomacy
|
||||
|
||||
import Chisel._
|
||||
import config._
|
||||
import chisel3.experimental.{BaseModule, RawModule, MultiIOModule}
|
||||
import chisel3.internal.sourceinfo.{SourceInfo, SourceLine, UnlocatableSourceInfo}
|
||||
|
||||
abstract class LazyModule()(implicit val p: Parameters)
|
||||
@ -51,7 +52,7 @@ abstract class LazyModule()(implicit val p: Parameters)
|
||||
def name = valName.getOrElse(className)
|
||||
def line = sourceLine(info)
|
||||
|
||||
def module: LazyModuleImp
|
||||
def module: LazyModuleImpLike
|
||||
|
||||
protected[diplomacy] def instantiate() = {
|
||||
children.reverse.foreach { c =>
|
||||
@ -140,14 +141,23 @@ object LazyModule
|
||||
}
|
||||
}
|
||||
|
||||
abstract class LazyModuleImp(outer: LazyModule) extends Module
|
||||
trait LazyModuleImpLike extends BaseModule
|
||||
{
|
||||
val wrapper: LazyModule
|
||||
|
||||
// .module had better not be accessed while LazyModules are still being built!
|
||||
require (LazyModule.stack.isEmpty, s"${outer.name}.module was constructed before LazyModule() was run on ${LazyModule.stack.head.name}")
|
||||
require (LazyModule.stack.isEmpty, s"${wrapper.name}.module was constructed before LazyModule() was run on ${LazyModule.stack.head.name}")
|
||||
|
||||
override def desiredName = outer.moduleName
|
||||
suggestName(outer.instanceName)
|
||||
override def desiredName = wrapper.moduleName
|
||||
suggestName(wrapper.instanceName)
|
||||
|
||||
outer.instantiate()
|
||||
implicit val p = outer.p
|
||||
wrapper.instantiate()
|
||||
|
||||
implicit val p = wrapper.p
|
||||
}
|
||||
|
||||
abstract class LazyModuleImp(val wrapper: LazyModule) extends Module with LazyModuleImpLike
|
||||
|
||||
abstract class LazyMultiIOModuleImp(val wrapper: LazyModule) extends MultiIOModule with LazyModuleImpLike
|
||||
|
||||
abstract class LazyRawModuleImp(val wrapper: LazyModule) extends RawModule with LazyModuleImpLike
|
||||
|
11
src/main/scala/diplomacy/Monitor.scala
Normal file
11
src/main/scala/diplomacy/Monitor.scala
Normal file
@ -0,0 +1,11 @@
|
||||
// See LICENSE.SiFive for license details.
|
||||
|
||||
package diplomacy
|
||||
|
||||
import Chisel._
|
||||
import chisel3.internal.sourceinfo.{SourceInfo, SourceLine}
|
||||
import config._
|
||||
|
||||
abstract class MonitorBase(implicit sourceInfo: SourceInfo, p: Parameters) extends LazyModule()(p) {
|
||||
override val module: LazyModuleImp
|
||||
}
|
@ -18,7 +18,7 @@ trait InwardNodeImp[DI, UI, EI, BI <: Data]
|
||||
def bundleI(ei: EI): BI
|
||||
def colour: String
|
||||
def reverse: Boolean = false
|
||||
def connect(edges: () => Seq[EI], bundles: () => Seq[(BI, BI)])(implicit p: Parameters, sourceInfo: SourceInfo): (Option[LazyModule], () => Unit) = {
|
||||
def connect(edges: () => Seq[EI], bundles: () => Seq[(BI, BI)])(implicit p: Parameters, sourceInfo: SourceInfo): (Option[MonitorBase], () => Unit) = {
|
||||
(None, () => bundles().foreach { case (i, o) => i <> o })
|
||||
}
|
||||
|
||||
@ -78,11 +78,11 @@ case class NodeHandle[DI, UI, BI <: Data, DO, UO, BO <: Data]
|
||||
trait InwardNodeHandle[DI, UI, BI <: Data]
|
||||
{
|
||||
val inward: InwardNode[DI, UI, BI]
|
||||
def := (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[LazyModule] =
|
||||
def := (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[MonitorBase] =
|
||||
inward.:=(h)(p, sourceInfo)
|
||||
def :*= (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[LazyModule] =
|
||||
def :*= (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[MonitorBase] =
|
||||
inward.:*=(h)(p, sourceInfo)
|
||||
def :=* (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[LazyModule] =
|
||||
def :=* (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[MonitorBase] =
|
||||
inward.:=*(h)(p, sourceInfo)
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ abstract class MixedNode[DI, UI, EI, BI <: Data, DO, UO, EO, BO <: Data](
|
||||
lazy val bundleIn = wireI(flipI(HeterogeneousBag(edgesIn .map(inner.bundleI(_)))))
|
||||
|
||||
// connects the outward part of a node with the inward part of this node
|
||||
private def bind(h: OutwardNodeHandle[DI, UI, BI], binding: NodeBinding)(implicit p: Parameters, sourceInfo: SourceInfo): Option[LazyModule] = {
|
||||
private def bind(h: OutwardNodeHandle[DI, UI, BI], binding: NodeBinding)(implicit p: Parameters, sourceInfo: SourceInfo): Option[MonitorBase] = {
|
||||
val x = this // x := y
|
||||
val y = h.outward
|
||||
val info = sourceLine(sourceInfo, " at ", "")
|
||||
@ -263,9 +263,9 @@ abstract class MixedNode[DI, UI, EI, BI <: Data, DO, UO, EO, BO <: Data](
|
||||
out
|
||||
}
|
||||
|
||||
override def := (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[LazyModule] = bind(h, BIND_ONCE)
|
||||
override def :*= (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[LazyModule] = bind(h, BIND_STAR)
|
||||
override def :=* (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[LazyModule] = bind(h, BIND_QUERY)
|
||||
override def := (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[MonitorBase] = bind(h, BIND_ONCE)
|
||||
override def :*= (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[MonitorBase] = bind(h, BIND_STAR)
|
||||
override def :=* (h: OutwardNodeHandle[DI, UI, BI])(implicit p: Parameters, sourceInfo: SourceInfo): Option[MonitorBase] = bind(h, BIND_QUERY)
|
||||
|
||||
// meta-data for printing the node graph
|
||||
protected[diplomacy] def colour = inner.colour
|
||||
|
Reference in New Issue
Block a user