Several IO interface constructors of the Sodor processor collection implements its own clone method. I looked into the usage of clone method in Scala but still cannot figure out why exactly that is done. (I could not find any explicit usage of these methods anywhere in the design)
Usage of clone method in Chisel IO interface constructors
272 views Asked by isururathnayaka At
1
Sodor is still currently still on Chisel 2.
clone
was renamed tocloneType
in Chisel 3 to distinguish it fromclone
in Java and Scala.cloneType
is generally required by Chisel in order to instantiate new instances of parameterizedBundles
. For example:Chisel often needs to create an instance of a given Bundle class from another instance of that class. Chisel uses Java reflection to do this. If there are no arguments to the constructor then it can just instantiate the object from the default constructor. However, it cannot determine the value of
width
from an instance of MyParameterizedBundle via reflection, so it cannot provide an appropriate parameter to the constructor. This is what thecloneType
function is for. It tells Chisel how to create a new instance of a Bundle from a given object.We hope to fix this wart in the future, but have not had the time to implement it. The most promising way is to automatically generate
cloneType
via Scala macro annotations.