Skip to content

Commit

Permalink
Remove autoSeedVar, use Boolean to distinguish suggested or autoSeed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkoenig committed Jul 10, 2024
1 parent f62b790 commit be81766
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/chisel3/Data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ abstract class Data extends HasId with NamedComponent with SourceInfoDoc {
override def autoSeed(name: String): this.type = {
topBindingOpt match {
// Ports are special in that the autoSeed will keep the first name, not the last name
case Some(PortBinding(m)) if hasAutoSeed && Builder.currentModule.contains(m) => this
case _ => super.autoSeed(name)
case Some(PortBinding(m)) if hasSeed && Builder.currentModule.contains(m) => this
case _ => super.autoSeed(name)
}
}

Expand Down
20 changes: 10 additions & 10 deletions core/src/main/scala/chisel3/internal/Builder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,16 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
override def hashCode: Int = super.hashCode()
override def equals(that: Any): Boolean = super.equals(that)

// Contains suggested seed (user-decided seed)
// Did the user suggest a name? This overrides names suggested by the compiler plugin.
private var _nameIsSuggested: Boolean = false
// Contains name seed (either user suggested or generated by the plugin).
private var suggested_seedVar: String = null // using nullable var for better memory usage
private def suggested_seed: Option[String] = Option(suggested_seedVar)

// Contains the seed computed automatically by the compiler plugin
private var auto_seedVar: String = null // using nullable var for better memory usage
private def auto_seed: Option[String] = Option(auto_seedVar)

// Prefix for use in naming
// - Defaults to prefix at time when object is created
// - Overridden when [[suggestSeed]] or [[autoSeed]] is called
// - Note that suggestSeed does *not* prevent autoSeed from changing this
private var naming_prefix: Prefix = Builder.getPrefix

/** Takes the last seed suggested. Multiple calls to this function will take the last given seed, unless
Expand All @@ -163,7 +162,9 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
private[chisel3] def autoSeed(seed: String): this.type = forceAutoSeed(seed)
// Bypass the overridden behavior of autoSeed in [[Data]], apply autoSeed even to ports
private[chisel3] def forceAutoSeed(seed: String): this.type = {
auto_seedVar = seed
if (!_nameIsSuggested) {
suggested_seedVar = seed
}
naming_prefix = Builder.getPrefix
this
}
Expand All @@ -190,10 +191,11 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
* @return this object
*/
def suggestName(seed: => String): this.type = {
if (suggested_seed.isEmpty) {
if (!_nameIsSuggested) {
suggested_seedVar = seed
// Only set the prefix if a seed hasn't been suggested
naming_prefix = Builder.getPrefix
_nameIsSuggested = true
}
this
}
Expand All @@ -212,13 +214,11 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
*
* @return the current calculation of a name, if it exists
*/
private[chisel3] def seedOpt: Option[String] = suggested_seed.orElse(auto_seed)
private[chisel3] def seedOpt: Option[String] = suggested_seed

/** @return Whether either autoName or suggestName has been called */
def hasSeed: Boolean = seedOpt.isDefined

private[chisel3] def hasAutoSeed: Boolean = auto_seed.isDefined

// Uses a namespace to convert suggestion into a true name
// Will not do any naming if the reference already assigned.
// (e.g. tried to suggest a name to part of a Record)
Expand Down

0 comments on commit be81766

Please sign in to comment.