forked from ucb-bar/riscv-sodor
-
Notifications
You must be signed in to change notification settings - Fork 21
Case Class
kshalle edited this page Apr 15, 2018
·
4 revisions
A case class
represents a special type of class in Scala that has the features:
- external access to the class parameters,
- eliminates the need to use
new
when instantiating the class - automatically creates an
unapply
method that supplies access to all of the class Parameters, - cannot be subclassed from.
It's often used to essentially create a data structure.
From RocketTiles.scala
line 15:
case class RocketTileParams(
core: RocketCoreParams = RocketCoreParams(),
icache: Option[ICacheParams] = Some(ICacheParams()),
dcache: Option[DCacheParams] = Some(DCacheParams()),
rocc: Seq[RoCCParams] = Nil,
btb: Option[BTBParams] = Some(BTBParams()),
dataScratchpadBytes: Int = 0) extends TileParams {
...
Which is used this way:
class RocketTile(val rocketParams: RocketTileParams, val hartid: Int)(implicit p: Parameters) extends BaseTile(rocketParams)(p)
...
val m = if (rocketParams.core.mulDiv.nonEmpty) "m" else ""
...