@@ -6,24 +6,29 @@ import scala.collection.immutable.ListMap
66
77import chisel3 .{Data , FixedIOBaseModule , Module , SourceInfoDoc }
88import chisel3 .experimental .{BaseModule , SourceInfo }
9+ import chisel3 .experimental .hierarchy .core .Lookupable
910import chisel3 .internal .{groupByIntoSeq , Builder }
1011import chisel3 .internal .binding .InstanceChoiceBinding
1112import chisel3 .internal .Builder .pushCommand
1213import chisel3 .internal .firrtl .ir .DefInstanceChoice
1314
1415object ModuleChoice extends ModuleChoiceObjIntf {
1516
16- protected def _applyImpl [T <: Data ](
17+ protected def _applyImpl [T ](
1718 default : => FixedIOBaseModule [T ],
1819 choices : Seq [(Case , () => FixedIOBaseModule [T ])]
1920 )(
2021 implicit sourceInfo : SourceInfo
2122 ): T = {
2223 val instDefaultModule = Module .evaluate(default)
24+ val lk : Lookupable [T ] = instDefaultModule._lookupable
25+
26+ val defaultLeaves = lk.in(instDefaultModule.io)
2327
2428 val choiceModules = choices.map { case (choice, module) =>
2529 val instModule = Module .evaluate(module())
26- if (! instModule.io.typeEquivalent(instDefaultModule.io)) {
30+ val choiceLeaves = lk.in(instModule.io)
31+ if (! defaultLeaves.zip(choiceLeaves).forall { case (a, b) => b.typeEquivalent(a) }) {
2732 Builder .error(" Error: choice module IO bundles are not type equivalent" )
2833 }
2934 Builder .options += choice
@@ -46,13 +51,14 @@ object ModuleChoice extends ModuleChoiceObjIntf {
4651 }
4752 val group = groupedChoices.head.name
4853
49- val binding = instDefaultModule.io.cloneTypeFull
50- binding.bind(InstanceChoiceBinding (Builder .forcedUserModule, Builder .currentBlock))
54+ val bindingLeaves = defaultLeaves.map(_.cloneTypeFull)
55+ bindingLeaves.foreach(_.bind(InstanceChoiceBinding (Builder .forcedUserModule, Builder .currentBlock)))
56+ val binding = lk.out(instDefaultModule.io, bindingLeaves.iterator)
5157
5258 pushCommand(
5359 DefInstanceChoice (
5460 sourceInfo,
55- binding ,
61+ bindingLeaves.head ,
5662 instDefaultModule,
5763 group,
5864 choiceModules.map { case (choice, instModule) =>
0 commit comments