Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

D/I suggestName #2414

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 8 additions & 2 deletions core/src/main/scala/chisel3/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,19 @@ package internal {
record.forceName(None, default = this.desiredName, namespace)
// Now take the Ref that forceName set and convert it to the correct Arg
val instName = record.getRef match {
case Ref(name) => name
case bad => throwException(s"Internal Error! Cloned-module Record $record has unexpected ref $bad")
case Ref(name) => name
case ModuleCloneIO(_, name) => namespace.name(name)
case bad => throwException(s"Internal Error! Cloned-module Record $record has unexpected ref $bad")
}
// Set both the record and the module to have the same instance name
record.setRef(ModuleCloneIO(getProto, instName), force = true) // force because we did .forceName first
this.setRef(Ref(instName))
}

def suggestName(name: String): Unit = {
_portsRecord.setRef(ModuleCloneIO(getProto, name)) // force because we did .forceName first
this.setRef(Ref(name))
}
}

/** Represents a module viewed from a different instance context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ object Instance extends SourceInfoDoc {
case Clone(x: IsClone[_] with BaseModule) => x.toAbsoluteTarget
}

def suggestName(name: String): Unit = {
i.getInnerDataContext.get.asInstanceOf[ModuleClone[T]].suggestName(name)
}
}

/** A constructs an [[Instance]] from a [[Definition]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,4 +1066,41 @@ class InstanceSpec extends ChiselFunSpec with Utils {
getFirrtlAndAnnos(new HasMultipleTypeParamsInside, Seq(aspect))
}
}
it("11.1 suggestName for Instances") {
class Top extends Module {
val definition = Definition(new AddOne)
val inst0 = Instance(definition)
inst0.suggestName("potato")
}
val (chirrtl, _) = getFirrtlAndAnnos(new Top)
chirrtl.serialize should include("inst potato of AddOne")
}
it("11.2 suggestName at instantiation") {
class Top extends Module {
val k = Instance(Definition(new AddOne)).suggestName("potato")
}
val (chirrtl, _) = getFirrtlAndAnnos(new Top)
chirrtl.serialize should include("inst potato of AddOne")
}
it("11.3 suggestName with sanitization") {
class Top extends Module {
val definition = Definition(new AddOne)
val inst0 = Instance(definition)
val inst1 = Instance(definition)
inst0.suggestName("potato")
inst1.suggestName("potato")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you show a test with two different things that are not the same Definition, Instance which also name conflict and successfully sanitize?

val inst0 = Module(new AddOne()).suggestName("potato")
val inst1 = Instance(definition).suggestName("potato")

}
val (chirrtl, _) = getFirrtlAndAnnos(new Top)
chirrtl.serialize should include("inst potato of AddOne")
chirrtl.serialize should include("inst potato_1 of AddOne")
}
it("11.4 suggestName with multi-def collision sanitization") {
class Top extends Module {
val inst0 = Module(new AddOne()).suggestName("potato")
val inst1 = Instance(Definition(new AddOne)).suggestName("potato")
}
val (chirrtl, _) = getFirrtlAndAnnos(new Top)
chirrtl.serialize should include("inst potato of AddOne")
chirrtl.serialize should include("inst potato_1 of AddOne_1")
}
}