override def clone =

108 views
Skip to first unread message

Stephan

unread,
Feb 22, 2015, 9:16:44 AM2/22/15
to chisel...@googlegroups.com
Hi All,

Can anyone explain the need of the clone methode often seen in Bundle definitions and provide a minimalistic example that truely relies on that definition. Thanks in advance.

Regards,
Stephan

Jonathan Bachrach

unread,
Feb 26, 2015, 7:52:58 AM2/26/15
to chisel...@googlegroups.com
cloning is the way that types are copied allowing even wires to provide their type as input to things like ValidIO:

class ValidIO[+T <: Data](gen: T) extends Bundle {
  val valid = Bool(OUTPUT)
  val bits = gen.clone.asOutput
  def fire(dummy: Int = 0): Bool = valid
  override def clone: this.type = new ValidIO(gen).asInstanceOf[this.type]
}

usage:

  new ValidIO(UInt(width = 8))

the main place where you need to provide a clone method is when a bundle class definition depends on its parameters for creation.  it's pretty easy to do if you just copy and paste the template from above.  the template includes the this.type return type and the coercion to this.type using asInstanceOf.


--
You received this message because you are subscribed to the Google Groups "chisel-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chisel-users...@googlegroups.com.
To post to this group, send email to chisel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chisel-users/93655336-57eb-42f6-a0a7-98475cd791c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Schoeberl

unread,
Feb 27, 2015, 4:26:07 AM2/27/15
to chisel...@googlegroups.com
Thanks for providing this small example. Would be good if this (and other tips) could be collected either in the tutorial or in getting started.

Cheers,
Martin
> To view this discussion on the web visit https://groups.google.com/d/msgid/chisel-users/CALZ%3D%2Byb0nfMMWqHqfSvZM0dBy%3DTWyy2ox-s8MFZnJVnha-s5Cw%40mail.gmail.com.

Stephan

unread,
Feb 27, 2015, 5:00:10 AM2/27/15
to chisel...@googlegroups.com
Thanks from my side also!

- Stephan
Reply all
Reply to author
Forward
0 new messages