Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix aop.Select behavior for CloneModuleAsRecord (backport #1993) #1994

Merged
merged 2 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/main/scala/chisel3/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ package internal {
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
9 changes: 7 additions & 2 deletions 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 @@ -81,8 +82,12 @@ object Select {
def instances(module: BaseModule): Seq[BaseModule] = {
check(module)
module._component.get match {
case d: DefModule => d.commands.collect {
case i: DefInstance => i.id
case d: DefModule => d.commands.flatMap {
case i: DefInstance => i.id match {
case _: ModuleClone => None
case other => Some(other)
}
case _ => None
}
case other => Nil
}
Expand Down
26 changes: 26 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,31 @@ class SelectSpec extends ChiselFlatSpec {
assert(bbs.size == 1)
}

"CloneModuleAsRecord" should "NOT show up in Select aspects" 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
Select.collectDeep(top) { case x => x } should equal (Seq(top, top.inst0))
Select.getDeep(top)(x => Seq(x)) should equal (Seq(top, top.inst0))
Select.instances(top) should equal (Seq(top.inst0))
}

}