2016-08-19 20:08:35 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
|
|
|
package uncore.tilelink2
|
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import scala.collection.mutable.ListBuffer
|
2016-08-31 19:37:30 +02:00
|
|
|
import chisel3.internal.sourceinfo.SourceInfo
|
2016-08-19 20:08:35 +02:00
|
|
|
|
2016-08-31 21:17:55 +02:00
|
|
|
// PI = PortInputParameters
|
|
|
|
// PO = PortOutputParameters
|
|
|
|
// EI = EdgeInput
|
|
|
|
// EO = EdgeOutput
|
2016-09-08 20:30:04 +02:00
|
|
|
abstract class NodeImp[PO, PI, EO, EI, B <: Data]
|
2016-08-31 21:17:55 +02:00
|
|
|
{
|
|
|
|
def edgeO(po: PO, pi: PI): EO
|
|
|
|
def edgeI(po: PO, pi: PI): EI
|
|
|
|
def bundleO(eo: Seq[EO]): Vec[B]
|
|
|
|
def bundleI(ei: Seq[EI]): Vec[B]
|
|
|
|
def connect(bo: B, eo: EO, bi: B, ei: EI)(implicit sourceInfo: SourceInfo): Unit
|
|
|
|
}
|
|
|
|
|
2016-09-08 23:41:08 +02:00
|
|
|
class RootNode
|
|
|
|
{
|
|
|
|
// You cannot create a Node outside a LazyModule!
|
|
|
|
require (!LazyModule.stack.isEmpty)
|
|
|
|
|
|
|
|
val lazyModule = LazyModule.stack.head
|
|
|
|
lazyModule.nodes = this :: lazyModule.nodes
|
|
|
|
}
|
|
|
|
|
2016-09-08 20:30:04 +02:00
|
|
|
class BaseNode[PO, PI, EO, EI, B <: Data](imp: NodeImp[PO, PI, EO, EI, B])(
|
2016-08-31 22:30:06 +02:00
|
|
|
private val oFn: Option[Seq[PO] => PO],
|
|
|
|
private val iFn: Option[Seq[PI] => PI],
|
|
|
|
private val numPO: Range.Inclusive,
|
2016-09-08 23:41:08 +02:00
|
|
|
private val numPI: Range.Inclusive) extends RootNode
|
2016-08-19 20:08:35 +02:00
|
|
|
{
|
|
|
|
// At least 0 ports must be supported
|
2016-08-31 22:30:06 +02:00
|
|
|
require (!numPO.isEmpty)
|
|
|
|
require (!numPI.isEmpty)
|
|
|
|
require (numPO.start >= 0)
|
|
|
|
require (numPI.start >= 0)
|
|
|
|
|
|
|
|
val noOs = numPO.size == 1 && numPO.contains(0)
|
|
|
|
val noIs = numPI.size == 1 && numPI.contains(0)
|
|
|
|
|
|
|
|
require (noOs || oFn.isDefined)
|
|
|
|
require (noIs || iFn.isDefined)
|
|
|
|
|
|
|
|
private val accPO = ListBuffer[BaseNode[PO, PI, EO, EI, B]]()
|
|
|
|
private val accPI = ListBuffer[BaseNode[PO, PI, EO, EI, B]]()
|
|
|
|
private var oRealized = false
|
|
|
|
private var iRealized = false
|
|
|
|
|
2016-09-08 23:41:08 +02:00
|
|
|
def name = lazyModule.name + "." + getClass.getName.split('.').last
|
|
|
|
private def reqO() = require(numPO.contains(accPO.size), s"${name} has ${accPO.size} outputs, expected ${numPO}${lazyModule.line}")
|
|
|
|
private def reqI() = require(numPI.contains(accPI.size), s"${name} has ${accPI.size} inputs, expected ${numPI}${lazyModule.line}")
|
|
|
|
|
|
|
|
private lazy val oPorts = { oRealized = true; reqO(); accPO.result() }
|
|
|
|
private lazy val iPorts = { iRealized = true; reqI(); accPI.result() }
|
2016-08-31 22:30:06 +02:00
|
|
|
private lazy val oParams : Option[PO] = oFn.map(_(iPorts.map(_.oParams.get)))
|
|
|
|
private lazy val iParams : Option[PI] = iFn.map(_(oPorts.map(_.iParams.get)))
|
|
|
|
|
|
|
|
lazy val edgesOut = oPorts.map { n => imp.edgeO(oParams.get, n.iParams.get) }
|
|
|
|
lazy val edgesIn = iPorts.map { n => imp.edgeI(n.oParams.get, iParams.get) }
|
|
|
|
|
2016-08-31 21:17:55 +02:00
|
|
|
lazy val bundleOut = imp.bundleO(edgesOut)
|
|
|
|
lazy val bundleIn = imp.bundleI(edgesIn)
|
2016-08-31 04:26:01 +02:00
|
|
|
|
|
|
|
def connectOut = bundleOut
|
|
|
|
def connectIn = bundleIn
|
2016-08-31 19:37:30 +02:00
|
|
|
|
2016-08-31 21:17:55 +02:00
|
|
|
// source.edge(sink)
|
|
|
|
protected[tilelink2] def edge(x: BaseNode[PO, PI, EO, EI, B])(implicit sourceInfo: SourceInfo) = {
|
2016-08-31 22:30:06 +02:00
|
|
|
require (!noOs)
|
|
|
|
require (!oRealized)
|
|
|
|
require (!x.noIs)
|
|
|
|
require (!x.iRealized)
|
|
|
|
val i = x.accPI.size
|
|
|
|
val o = accPO.size
|
|
|
|
accPO += x
|
|
|
|
x.accPI += this
|
2016-08-31 19:37:30 +02:00
|
|
|
() => {
|
2016-08-31 21:17:55 +02:00
|
|
|
imp.connect(connectOut(o), edgesOut(o), x.connectIn(i), x.edgesIn(i))
|
2016-08-31 19:37:30 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-19 20:08:35 +02:00
|
|
|
}
|
|
|
|
|
2016-09-08 20:30:04 +02:00
|
|
|
class IdentityNode[PO, PI, EO, EI, B <: Data](imp: NodeImp[PO, PI, EO, EI, B])
|
2016-08-31 22:30:06 +02:00
|
|
|
extends BaseNode(imp)(Some{case Seq(x) => x}, Some{case Seq(x) => x}, 1 to 1, 1 to 1)
|
2016-09-01 00:47:07 +02:00
|
|
|
|
2016-09-08 20:30:04 +02:00
|
|
|
class OutputNode[PO, PI, EO, EI, B <: Data](imp: NodeImp[PO, PI, EO, EI, B]) extends IdentityNode(imp)
|
2016-08-19 20:08:35 +02:00
|
|
|
{
|
2016-08-31 22:30:06 +02:00
|
|
|
override def connectOut = bundleOut
|
|
|
|
override def connectIn = bundleOut
|
2016-08-19 20:08:35 +02:00
|
|
|
}
|
|
|
|
|
2016-09-08 20:30:04 +02:00
|
|
|
class InputNode[PO, PI, EO, EI, B <: Data](imp: NodeImp[PO, PI, EO, EI, B]) extends IdentityNode(imp)
|
2016-08-31 04:26:01 +02:00
|
|
|
{
|
2016-08-31 22:30:06 +02:00
|
|
|
override def connectOut = bundleIn
|
|
|
|
override def connectIn = bundleIn
|
2016-08-31 04:26:01 +02:00
|
|
|
}
|
|
|
|
|
2016-09-08 20:30:04 +02:00
|
|
|
class SourceNode[PO, PI, EO, EI, B <: Data](imp: NodeImp[PO, PI, EO, EI, B])(po: PO, num: Range.Inclusive = 1 to 1)
|
2016-08-31 22:30:06 +02:00
|
|
|
extends BaseNode(imp)(Some{case Seq() => po}, None, num, 0 to 0)
|
2016-08-31 04:26:01 +02:00
|
|
|
{
|
2016-08-31 22:30:06 +02:00
|
|
|
require (num.end >= 1)
|
2016-08-31 04:26:01 +02:00
|
|
|
}
|
|
|
|
|
2016-09-08 20:30:04 +02:00
|
|
|
class SinkNode[PO, PI, EO, EI, B <: Data](imp: NodeImp[PO, PI, EO, EI, B])(pi: PI, num: Range.Inclusive = 1 to 1)
|
2016-08-31 22:30:06 +02:00
|
|
|
extends BaseNode(imp)(None, Some{case Seq() => pi}, 0 to 0, num)
|
2016-08-31 04:26:01 +02:00
|
|
|
{
|
2016-08-31 22:30:06 +02:00
|
|
|
require (num.end >= 1)
|
2016-08-31 04:26:01 +02:00
|
|
|
}
|
2016-08-19 20:08:35 +02:00
|
|
|
|
2016-09-08 20:30:04 +02:00
|
|
|
class InteriorNode[PO, PI, EO, EI, B <: Data](imp: NodeImp[PO, PI, EO, EI, B])
|
2016-08-31 22:30:06 +02:00
|
|
|
(oFn: Seq[PO] => PO, iFn: Seq[PI] => PI, numPO: Range.Inclusive, numPI: Range.Inclusive)
|
|
|
|
extends BaseNode(imp)(Some(oFn), Some(iFn), numPO, numPI)
|
2016-08-19 20:08:35 +02:00
|
|
|
{
|
2016-08-31 22:30:06 +02:00
|
|
|
require (numPO.end >= 1)
|
|
|
|
require (numPI.end >= 1)
|
2016-08-19 20:08:35 +02:00
|
|
|
}
|