blob: 2e43d3c96402a5ef40da9ec1c34f57cb04fe7580 (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import chisel3._
import chisel3.stage.ChiselStage
object TypeArithmetic {
implicit val f1: SomeTypeContainer => SomeTypeContainer => SomeTypeContainer = (a: SomeTypeContainer) => (b: SomeTypeContainer) => new SomeTypeContainer(a.i+b.i)
implicit val f2: SomeTypeContainer => Int => SomeTypeContainer = (a: SomeTypeContainer) => (b: Int) => new SomeTypeContainer(b+a.i)
implicit val f3: SomeTypeContainer => UInt => SomeTypeContainer = (a: SomeTypeContainer) => (b: UInt) => {
val litval: Int = 1
new SomeTypeContainer(litval.toInt+a.i)
}
// Dynamically create an IO
// implicit val f4: UInt => UInt => (() => Any) = (a: UInt) => (b: UInt) => (() => Wire(a))
implicit val f5 = (new Op[UInt, UInt, () => UInt]((a: UInt) => (b: UInt) => (() => IO(a)))).f
}
case class SomeTypeContainer(i: Int)
object AbstractModuleStandalone {
class SomeModule extends Module
def main(args: Array[String]): Unit = {
val foo: Int = 1
val bar: SomeTypeContainer = SomeTypeContainer(2)
val baz: UInt = UInt(1.W)
val afoo = AbstractInterface[UInt](Input(UInt(4.W)))
val abar = AbstractInterface[UInt](Output(UInt(8.W)))
val abaz = AbstractInterface[SomeTypeContainer](SomeTypeContainer(16))
import MetaConnect._
import TypeArithmetic._
val barfoobarbar = bar makeConnection foo makeConnection bar makeConnection bar
val barbazfoo = bar makeConnection baz makeConnection foo
val abazafoo = abaz makeConnection afoo
val afooabar = afoo makeConnection abar
val topIface = Seq(abazafoo, afooabar)
def topBody(iface: Seq[AbstractInterface[_]]): () => Module = {
val k = () => new SomeModule {
iface.foreach { x => x.params match {
case some: UInt => x.params.asInstanceOf[UInt] := 19.U
case _ =>
}}
}
k
}
println(ChiselStage.emitFirrtl({
(new AbstractModule(Seq(abazafoo, afooabar))(topBody)).comp()
}))
}
}
|