Skip to content

Commit

Permalink
Restore aop.Select behavior for CloneModuleAsRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkoenig committed Jun 29, 2021
1 parent 8724cd5 commit 0531cb5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/src/main/scala/chisel3/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,14 @@ package internal {

object BaseModule {
// Private internal class to serve as a _parent for Data in cloned ports
private[chisel3] class ModuleClone(_proto: BaseModule) extends BaseModule {
private[chisel3] class ModuleClone(private[chisel3] val _proto: BaseModule) extends BaseModule {
// ClonePorts that hold the bound ports for this module
// Used for setting the refs of both this module and the Record
private[BaseModule] var _portsRecord: Record = _
// Don't generate a component, but point to the one for the cloned Module
private[chisel3] def generateComponent(): Option[Component] = {
require(!_closed, "Can't generate module more than once")
_closed = true
_component = _proto._component
None
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/scala/chisel3/aop/Select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import chisel3._
import chisel3.experimental.{BaseModule, FixedPoint}
import chisel3.internal.HasId
import chisel3.internal.firrtl._
import chisel3.internal.BaseModule.ModuleClone
import firrtl.annotations.ReferenceTarget

import scala.collection.mutable
Expand Down Expand Up @@ -82,7 +83,10 @@ object Select {
check(module)
module._component.get match {
case d: DefModule => d.commands.collect {
case i: DefInstance => i.id
case i: DefInstance => i.id match {
case clone: ModuleClone => clone._proto
case other => other
}
}
case other => Nil
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/scala/chiselTests/aop/SelectSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,30 @@ class SelectSpec extends ChiselFlatSpec {
assert(bbs.size == 1)
}

"CloneModuleAsRecord" should "show up in Select aspects as duplicates" in {
import chisel3.experimental.CloneModuleAsRecord
class Child extends RawModule {
val in = IO(Input(UInt(8.W)))
val out = IO(Output(UInt(8.W)))
out := in
}
class Top extends MultiIOModule {
val in = IO(Input(UInt(8.W)))
val out = IO(Output(UInt(8.W)))
val inst0 = Module(new Child)
val inst1 = CloneModuleAsRecord(inst0)
inst0.in := in
inst1("in") := inst0.out
out := inst1("out")
}
val top = ChiselGeneratorAnnotation(() => {
new Top()
}).elaborate
.collectFirst { case DesignAnnotation(design: Top) => design }
.get
val mods = Select.collectDeep(top) { case mod => mod }
mods should equal (Seq(top, top.inst0, top.inst0))
}

}

0 comments on commit 0531cb5

Please # to comment.