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

Move circuitVar from HasId to BaseModule #4253

Merged
merged 1 commit into from
Jul 10, 2024
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
7 changes: 7 additions & 0 deletions core/src/main/scala/chisel3/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ package experimental {
abstract class BaseModule extends HasId with IsInstantiable {
_parent.foreach(_.addId(this))

// Set if the returned top-level module of a nested call to the Chisel Builder, see Definition.apply
private var _circuitVar: BaseModule = null // using nullable var for better memory usage
private[chisel3] def _circuit: Option[BaseModule] = Option(_circuitVar)
private[chisel3] def _circuit_=(target: Option[BaseModule]): Unit = {
_circuitVar = target.getOrElse(null)
}

// Protected so it can be overridden by the compiler plugin
protected def _sourceInfo: SourceInfo = UnlocatableSourceInfo

Expand Down
18 changes: 8 additions & 10 deletions core/src/main/scala/chisel3/internal/Builder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
_parentVar = target.getOrElse(null)
}

// Set if the returned top-level module of a nested call to the Chisel Builder, see Definition.apply
private var _circuitVar: BaseModule = null // using nullable var for better memory usage
private[chisel3] def _circuit: Option[BaseModule] = Option(_circuitVar)
private[chisel3] def _circuit_=(target: Option[BaseModule]): Unit = {
_circuitVar = target.getOrElse(null)
}

private[chisel3] val _id: Long = Builder.idGen.next

// TODO: remove this, but its removal seems to cause a nasty Scala compiler crash.
Expand Down Expand Up @@ -351,9 +344,14 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
}
def circuitName: String = _parent match {
case None =>
_circuit match {
case None => instanceName
case Some(o) => o.circuitName
// Only modules have circuits
this match {
case b: BaseModule =>
b._circuit match {
case Some(c) => c.circuitName
case None => instanceName
}
case _ => instanceName
}
case Some(ViewParent) => reifyParent.circuitName
case Some(p) => p.circuitName
Expand Down