2016-08-19 20:08:35 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
|
|
|
package uncore.tilelink2
|
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import scala.collection.mutable.ListBuffer
|
|
|
|
import chisel3.internal.sourceinfo.SourceInfo
|
|
|
|
|
2016-08-31 19:25:46 +02:00
|
|
|
abstract class LazyModule
|
2016-08-19 20:08:35 +02:00
|
|
|
{
|
2016-08-31 19:37:30 +02:00
|
|
|
private val bindings = ListBuffer[() => Unit]()
|
2016-08-19 20:08:35 +02:00
|
|
|
|
2016-08-31 19:43:34 +02:00
|
|
|
// Use as: connect(source -> sink, source2 -> sink2, ...)
|
2016-08-31 21:17:55 +02:00
|
|
|
def connect[PO, PI, EO, EI, B <: Bundle](edges: (BaseNode[PO, PI, EO, EI, B], BaseNode[PO, PI, EO, EI, B])*)(implicit sourceInfo: SourceInfo) = {
|
2016-08-31 19:43:34 +02:00
|
|
|
edges.foreach { case (source, sink) =>
|
2016-08-31 21:17:55 +02:00
|
|
|
bindings += (source edge sink)
|
2016-08-31 19:43:34 +02:00
|
|
|
}
|
2016-08-19 20:08:35 +02:00
|
|
|
}
|
|
|
|
|
2016-08-31 19:25:46 +02:00
|
|
|
def module: LazyModuleImp
|
2016-08-19 20:08:35 +02:00
|
|
|
|
|
|
|
protected[tilelink2] def instantiate() = {
|
2016-08-31 19:25:46 +02:00
|
|
|
// Find all LazyModule members of self
|
2016-08-19 20:08:35 +02:00
|
|
|
for (m <- getClass.getMethods) {
|
|
|
|
if (m.getParameterTypes.isEmpty &&
|
|
|
|
!java.lang.reflect.Modifier.isStatic(m.getModifiers) &&
|
|
|
|
!(m.getName contains '$') &&
|
2016-08-31 19:25:46 +02:00
|
|
|
classOf[LazyModule].isAssignableFrom(m.getReturnType)) {
|
2016-08-19 20:08:35 +02:00
|
|
|
// ... and force their lazy module members to exist
|
2016-08-31 19:25:46 +02:00
|
|
|
m.invoke(this).asInstanceOf[LazyModule].module
|
2016-08-19 20:08:35 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-31 19:37:30 +02:00
|
|
|
bindings.foreach { f => f () }
|
2016-08-19 20:08:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 19:25:46 +02:00
|
|
|
abstract class LazyModuleImp(outer: LazyModule) extends Module
|
2016-08-30 02:53:31 +02:00
|
|
|
{
|
2016-08-31 19:25:46 +02:00
|
|
|
override def desiredName = outer.getClass.getName.split('.').last
|
|
|
|
outer.instantiate()
|
2016-08-19 20:08:35 +02:00
|
|
|
}
|