summaryrefslogtreecommitdiff
path: root/AbstractModule.scala
blob: e179c684d29b327dac7d114bd9c86ea921ae83f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package chiselTests

import chisel3._
import chisel3.stage.ChiselStage
import chisel3.MetaConnect._

class AbstractModule[T <: Data](params: T) {
  val ioNode = IO(params)
}

object TypeArithmetic {
  implicit val f1: UInt => UInt => UInt = (a: UInt) => (b: UInt) => Mux(a > b, a, b)
  implicit val f2: SomeTypeContainer => Unit => SomeTypeContainer = (a: SomeTypeContainer) => (b: Unit) => a
}

case class SomeTypeContainer(w: Int) extends UInt(w.W)

class AbstractModuleContainer extends Module {
  val mod1 = new AbstractModule[UInt](Input(UInt(4.W)))
  val mod2 = new AbstractModule[UInt](Output(UInt(8.W)))
  val mod3 = new AbstractModule[SomeTypeContainer](Output(SomeTypeContainer(16)))

  import TypeArithmetic._
  val typeA = mod1.ioNode.makeConnection(mod2.ioNode)
  val typeB = mod2.ioNode.makeConnection(mod3.ioNode)
  // need to create versions of mods1-3 with these new type params
  // similar to log aggregation writer monad? but more like type aggregation
}

object main {
  def main(args: Array[String]): Unit = {
    println(chisel3.stage.ChiselStage.emitChirrtl(new AbstractModuleContainer))
  }
}