From 45a875cc200bdcf06235e2aae07c5c0685397e21 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Thu, 4 Jul 2024 14:38:03 -0700 Subject: [PATCH] Remove autoSeedVar, use Boolean to distinguish suggested or autoSeed --- core/src/main/scala/chisel3/Data.scala | 4 ++-- .../main/scala/chisel3/internal/Builder.scala | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/src/main/scala/chisel3/Data.scala b/core/src/main/scala/chisel3/Data.scala index a928d56c7d9..8d3b9e6af3c 100644 --- a/core/src/main/scala/chisel3/Data.scala +++ b/core/src/main/scala/chisel3/Data.scala @@ -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) } } diff --git a/core/src/main/scala/chisel3/internal/Builder.scala b/core/src/main/scala/chisel3/internal/Builder.scala index 5f38b2ee632..32893a023f7 100644 --- a/core/src/main/scala/chisel3/internal/Builder.scala +++ b/core/src/main/scala/chisel3/internal/Builder.scala @@ -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 @@ -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 } @@ -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 } @@ -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)