Skip to content

Commit

Permalink
Move circuitVar from HasId to BaseModule (#4253)
Browse files Browse the repository at this point in the history
(cherry picked from commit 18d21fb)
  • Loading branch information
jackkoenig authored and mergify[bot] committed Jul 10, 2024
1 parent 2bc4859 commit e8926f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
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 @@ -421,6 +421,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 @@ -121,13 +121,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 @@ -350,9 +343,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

0 comments on commit e8926f1

Please sign in to comment.