I am a new learner of Chisel. What is the purpose of Cloning in Chisel? I saw somewhere written, "it creates a shallow copy". Why do we need it? Here are examples. Could you please elaborate it.
1)
  class Valid[+T <: Data](gen: T) extends Bundle
    {
    val valid = Output(Bool())
    val bits = Output(gen.chiselCloneType)//?????
    def fire(): Bool = valid
    override def cloneType: this.type = Valid(gen).asInstanceOf[this.type]
    }
    /** Adds a valid protocol to any interface */
    object Valid {
    def apply[T <: Data](gen: T): Valid[T] = new Valid(gen)
    }
2)
class Packet(n: Int, w: Int) extends Bundle {
val address = UInt(Log2Up(n).W)
val payload = UInt(w.W)
override def cloneType: this.type =
new Packet(n, w).asInstanceOf[this.type]
}
Why cloneType is Override. Is it like an apply method in Scala or it just only updates the cloneType method in Bundle.
Thanks
 
    