1
0

diplomacy: add LazyScope to post-hoc add children to a LazyModule

This commit is contained in:
Wesley W. Terpstra 2017-09-26 14:40:45 -07:00
parent a27e853101
commit a2b423d647

View File

@ -172,16 +172,43 @@ sealed trait LazyModuleImpLike extends BaseModule
}
}
abstract class LazyModuleImp(val wrapper: LazyModule) extends MultiIOModule with LazyModuleImpLike {
class LazyModuleImp(val wrapper: LazyModule) extends MultiIOModule with LazyModuleImpLike {
val (auto, dangles) = instantiate()
}
abstract class LazyRawModuleImp(val wrapper: LazyModule) extends RawModule with LazyModuleImpLike {
class LazyRawModuleImp(val wrapper: LazyModule) extends RawModule with LazyModuleImpLike {
val (auto, dangles) = withClockAndReset(Bool(false).asClock, Bool(true)) {
instantiate()
}
}
class SimpleLazyModule(implicit p: Parameters) extends LazyModule
{
lazy val module = new LazyModuleImp(this)
}
trait LazyScope
{
this: LazyModule =>
def apply[T](body: => T)(implicit p: Parameters) = {
require (!LazyModule.stack.exists(x => x eq this))
LazyModule.stack = this :: LazyModule.stack
val out = body
require (LazyModule.stack.head eq this)
LazyModule.stack = LazyModule.stack.tail
out
}
}
object LazyScope
{
def apply[T](name: String)(body: => T)(implicit p: Parameters) = {
val scope = LazyModule(new SimpleLazyModule with LazyScope)
scope.suggestName(name)
scope { body }
}
}
case class HalfEdge(serial: Int, index: Int)
case class Dangle(source: HalfEdge, sink: HalfEdge, flipped: Boolean, name: String, data: Data)