How to do a vector of modules?

后端 未结 1 1276
一整个雨季
一整个雨季 2021-01-02 23:36

I want to instantiate a one dimensional array of element, and element extends Module. How would I do this? If I say my best guess, which is:

val elements =         


        
相关标签:
1条回答
  • 2021-01-03 00:11

    Edit: I'm adding what I think is a better way to generate a vector of modules:

    val my_args = Seq(1,2,3,4)
    val exe_units = for (i <- 0 until num_units) yield
    {
       val exe_unit = Module(new AluExeUnit(args = my_args(i)))
       // any wiring or other logic can go here
       exe_unit
    }
    

    Notice that this method allows you to individually tailor each unit differently, and returns a Seq() of Chisel modules. It will generate better looking hardware too.

    But if you really need to be able to dynamically index into your array of Modules, you can pull out a Vec() of the IOs like this:

    val exe_units_io = Vec(exe_units.map(_.io))
    

    (This is the old suggestion, which I think is less good).

    You can create a Vec of Modules as follows:

    val vec_of_elements = Vec.fill(n) {Module(new MyElement(my_args)).io }
    

    But notice, a Vec can really only be either of Wires or of Registers, so we've really just created a Vec of the IO Wires, which just so happen to create the Modules we care about in the process.

    0 讨论(0)
提交回复
热议问题