Skip to content

Commit

Permalink
DRY out the RocketConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryz123 committed Jun 30, 2024
1 parent 53bf263 commit 50559ea
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 412 deletions.
43 changes: 42 additions & 1 deletion src/main/scala/subsystem/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import freechips.rocketchip.resources.{
DTSModel, DTSCompat, DTSTimebase, BigIntHexContext
}
import freechips.rocketchip.tile.{
MaxHartIdBits, RocketTileParams
MaxHartIdBits, RocketTileParams, BuildRoCC, AccumulatorExample, OpcodeSet, TranslatorExample, CharacterCountExample, BlackBoxExample
}
import freechips.rocketchip.util.ClockGateModelFile
import scala.reflect.ClassTag
Expand Down Expand Up @@ -143,6 +143,47 @@ class WithBufferlessBroadcastHub extends Config((site, here, up) => {
case BroadcastKey => up(BroadcastKey, site).copy(bufferless = true)
})

class TileAttachConfig[T <: CanAttachTile](f: T => T, locationOpt: Option[HierarchicalLocation])(implicit tag: ClassTag[T])
extends Config((site, here, up) => locationOpt match {
case Some(loc) => {
case TilesLocated(`loc`) => up(TilesLocated(loc)) map {
case tp: T => f(tp)
case t => t
}
}
case None => {
case TilesLocated(loc) => up(TilesLocated(loc)) map {
case tp: T => f(tp)
case t => t
}
}
}) {
// The default constructor applies the modification to all locations
def this(f: T => T)(implicit tag: ClassTag[T]) = this(f, None)
// The atLocation method applies the modification to only the provided location
def atLocation(loc: HierarchicalLocation) = new TileAttachConfig(f, Some(loc))
}

class WithRoccExample extends Config((site, here, up) => {
case BuildRoCC => List(
(p: Parameters) => {
val accumulator = LazyModule(new AccumulatorExample(OpcodeSet.custom0, n = 4)(p))
accumulator
},
(p: Parameters) => {
val translator = LazyModule(new TranslatorExample(OpcodeSet.custom1)(p))
translator
},
(p: Parameters) => {
val counter = LazyModule(new CharacterCountExample(OpcodeSet.custom2)(p))
counter
},
(p: Parameters) => {
val blackbox = LazyModule(new BlackBoxExample(OpcodeSet.custom3, "RoccBlackBox")(p))
blackbox
})
})

/**
* WARNING!!! IGNORE AT YOUR OWN PERIL!!!
*
Expand Down
Loading

0 comments on commit 50559ea

Please sign in to comment.