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 =
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.