Skip to content

Commit

Permalink
Make Instance.suggestName more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkoenig committed Jan 10, 2024
1 parent f834fca commit 33ba8cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.language.experimental.macros
import chisel3._
import chisel3.experimental.hierarchy.{InstantiableClone, ModuleClone}
import chisel3.internal.{throwException, Builder}
import chisel3.experimental.{BaseModule, ExtModule, SourceInfo}
import chisel3.experimental.{BaseModule, ExtModule, SourceInfo, UnlocatableSourceInfo}
import chisel3.internal.sourceinfo.InstanceTransform
import chisel3.internal.firrtl.{Component, DefBlackBox, DefClass, DefIntrinsicModule, DefModule, Port}
import firrtl.annotations.IsModule
Expand Down Expand Up @@ -94,8 +94,10 @@ object Instance extends SourceInfoDoc {
case _ => throw new InternalErrorException("Match error: i.underlying=${i.underlying}")
}

def suggestName(name: String): Unit = {
i.getInnerDataContext.get.asInstanceOf[ModuleClone[T]].suggestName(name)
def suggestName(name: String): Unit = i.underlying match {
case Clone(m: BaseModule) => m.suggestName(name)
case Proto(m) => m.suggestName(name)
case x => Builder.exception(s"Cannot call .suggestName on $x")(UnlocatableSourceInfo)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1218,10 +1218,13 @@ class InstanceSpec extends ChiselFunSpec with Utils {
class Top extends Module {
val definition = Definition(new AddOne)
val inst0 = Instance(definition)
val inst1 = Module(new AddOne).toInstance
inst0.suggestName("potato")
inst1.suggestName("potato")
}
val chirrtl = emitCHIRRTL(new Top)
chirrtl should include("inst potato of AddOne")
chirrtl should include("inst potato_1 of AddOne_1")
}
it("11.2 suggestName at instantiation") {
class Top extends Module {
Expand Down

0 comments on commit 33ba8cf

Please sign in to comment.