Chisel

References:

Scala

Based on Java Virtual Machine (JVM).

Scala – .class – JVM

Scala designed for Domain-Specific Language developers: can build your own language based on Scala.

Chisel

Type parameters

class or function definition can have type paramters, in order to define class/functions with arbitrary types.

e.g. the following defines a function myMux which accepts inputs of any type of tPath and fPath

def myMux [T <: Data ]( sel: Bool , tPath: T, fPath: T): T = {
val ret = WireDefault (fPath)
  when (sel) {
    ret := tPath
  } 
r et
}

The expression in the square brackets [T <: Data] defines a type parameter T that is Data or a subclass of Data . Data is the root of the Chisel type system.

// generators/chipyard/src/main/scala/HarnessBinders.scala

class HarnessBinder[T, S <: HasHarnessSignalReferences, U <: Data](composer: ((T, S, Seq[U]) => Unit) => (T, S, Seq[U]) => Unit)(implicit systemTag: ClassTag[T], harnessTag: ClassTag[S], portTag: ClassTag[U]) extends Config((site, here, up) => {
  case HarnessBinders => up(HarnessBinders, site) + (systemTag.runtimeClass.toString ->
      ((t: Any, th: HasHarnessSignalReferences, ports: Seq[Data]) => {
        val pts = ports.collect({case p: U => p})
        require (pts.length == ports.length, s"Port type mismatch between IOBinder and HarnessBinder: ${portTag}")
        val upfn = up(HarnessBinders, site)(systemTag.runtimeClass.toString)
        th match {
          case th: S =>
            t match {
              case system: T => composer(upfn)(system, th, pts)
              case _ =>
            }
          case _ =>
        }
      })
  )
})

More

Created Sep 21, 2022 // Last Updated Dec 16, 2022

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?