Disclaimer: The following question is going to be in the Chisel-2 semantics as our codebase is still in the transition phase.
I am trying to implement a script in Scala/Chisel which will read some configuration data from a text file and assign it to an appropriate bundle.
Imagine the bundle to be something like:
class b1 extends Bundle{
e1 = UInt(width=x)
e2 = UInt(width=y)
e3 = new b2 // b2 is another bundle with elements f1,f2
}
And the text file can have the configuration data in the following manner:
b1.e2 = 2
b1.e1 = 3
b1.e3.f1 = 5
b1.e3.f2 = 6
I am planning to read the file line-by-line and use regular expressions to first find the corresponding bundle and then the element inside the bundle to assign the value to.
For this purpose, I need some sort of a map of the bundle (b1 and b2 in this case). Once I identify which bundle it is then I further need to identify which element do I have to assign the value to.
So, my questions are:
Is there a way to obtain such a map for the bundles in Chisel?
And, has anyone tried doing anything similar to what I am trying to achieve?
Bundles have a field elements
that returns ListMap[String, Data]
where the keys are the names of the fields and the values are the Chisel
Data
elements. You can use this map not only to inspect what the fields of the Bundle are, but to connect to some of them, eg.
b1.elements("e3").elements("f1") := 5.U