summaryrefslogtreecommitdiff
path: root/core/src/main/scala/chisel3/internal/Builder.scala
diff options
context:
space:
mode:
authorJack2022-11-11 06:53:04 +0000
committerJack2022-11-11 06:53:04 +0000
commit3ce953c81f06519351c48277e3474b5720ec07ff (patch)
treeac79dcb80d0528c2ae86ca21da4cf424715ab645 /core/src/main/scala/chisel3/internal/Builder.scala
parentadccde9998c91875e5490cff6d5822ffacc593ed (diff)
parentc8046636a25474be4c547c6fe9c6d742ea7b1d13 (diff)
Merge branch '3.5.x' into 3.5-release
Diffstat (limited to 'core/src/main/scala/chisel3/internal/Builder.scala')
-rw-r--r--core/src/main/scala/chisel3/internal/Builder.scala74
1 files changed, 55 insertions, 19 deletions
diff --git a/core/src/main/scala/chisel3/internal/Builder.scala b/core/src/main/scala/chisel3/internal/Builder.scala
index 61f94f8f..e3dfff09 100644
--- a/core/src/main/scala/chisel3/internal/Builder.scala
+++ b/core/src/main/scala/chisel3/internal/Builder.scala
@@ -88,10 +88,19 @@ trait InstanceId {
private[chisel3] trait HasId extends InstanceId {
private[chisel3] def _onModuleClose: Unit = {}
- private[chisel3] var _parent: Option[BaseModule] = Builder.currentModule
+ // using nullable var for better memory usage
+ private var _parentVar: BaseModule = Builder.currentModule.getOrElse(null)
+ private[chisel3] def _parent: Option[BaseModule] = Option(_parentVar)
+ private[chisel3] def _parent_=(target: Option[BaseModule]): Unit = {
+ _parentVar = target.getOrElse(null)
+ }
// Set if the returned top-level module of a nested call to the Chisel Builder, see Definition.apply
- private[chisel3] var _circuit: Option[BaseModule] = None
+ 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
@@ -100,10 +109,12 @@ private[chisel3] trait HasId extends InstanceId {
override def equals(that: Any): Boolean = super.equals(that)
// Contains suggested seed (user-decided seed)
- private var suggested_seed: Option[String] = None
+ 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_seed: Option[String] = None
+ 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
@@ -131,7 +142,7 @@ private[chisel3] trait HasId extends 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_seed = Some(seed)
+ auto_seedVar = seed
for (hook <- auto_postseed_hooks.reverse) { hook(seed) }
naming_prefix = Builder.getPrefix
this
@@ -159,9 +170,12 @@ private[chisel3] trait HasId extends InstanceId {
* @return this object
*/
def suggestName(seed: => String): this.type = {
- if (suggested_seed.isEmpty) suggested_seed = Some(seed)
- naming_prefix = Builder.getPrefix
- for (hook <- suggest_postseed_hooks.reverse) { hook(seed) }
+ if (suggested_seed.isEmpty) {
+ suggested_seedVar = seed
+ // Only set the prefix if a seed hasn't been suggested
+ naming_prefix = Builder.getPrefix
+ for (hook <- suggest_postseed_hooks.reverse) { hook(seed) }
+ }
this
}
@@ -171,7 +185,7 @@ private[chisel3] trait HasId extends InstanceId {
private[chisel3] def forceFinalName(seed: String): this.type = {
// This could be called with user prefixes, ignore them
noPrefix {
- suggested_seed = Some(seed)
+ suggested_seedVar = seed
this.suggestName(seed)
}
}
@@ -212,16 +226,21 @@ private[chisel3] trait HasId extends InstanceId {
naming_prefix = Nil
}
- private var _ref: Option[Arg] = None
+ private var _refVar: Arg = null // using nullable var for better memory usage
+ private def _ref: Option[Arg] = Option(_refVar)
private[chisel3] def setRef(imm: Arg): Unit = setRef(imm, false)
private[chisel3] def setRef(imm: Arg, force: Boolean): Unit = {
if (_ref.isEmpty || force) {
- _ref = Some(imm)
+ _refVar = imm
}
}
- private[chisel3] def setRef(parent: HasId, name: String): Unit = setRef(Slot(Node(parent), name))
- private[chisel3] def setRef(parent: HasId, index: Int): Unit = setRef(Index(Node(parent), ILit(index)))
- private[chisel3] def setRef(parent: HasId, index: UInt): Unit = setRef(Index(Node(parent), index.ref))
+ private[chisel3] def setRef(parent: HasId, name: String, opaque: Boolean = false): Unit = {
+ if (!opaque) setRef(Slot(Node(parent), name))
+ else setRef(OpaqueSlot(Node(parent)))
+ }
+
+ private[chisel3] def setRef(parent: HasId, index: Int): Unit = setRef(Index(Node(parent), ILit(index)))
+ private[chisel3] def setRef(parent: HasId, index: UInt): Unit = setRef(Index(Node(parent), index.ref))
private[chisel3] def getRef: Arg = _ref.get
private[chisel3] def getOptionRef: Option[Arg] = _ref
@@ -232,10 +251,21 @@ private[chisel3] trait HasId extends InstanceId {
// These accesses occur after Chisel elaboration so we cannot use the normal
// Builder.deprecated mechanism, we have to create our own one off ErrorLog and print the
// warning right away.
- val errors = new ErrorLog
+ // It's especially bad because --warnings-as-errors does not work with these warnings
+ val nameGuess = _computeName(None) match {
+ case Some(name) => s": '$name'"
+ case None => ""
+ }
+ val parentGuess = _parent match {
+ case Some(ViewParent) => s", in module '${reifyParent.pathName}'"
+ case Some(p) => s", in module '${p.pathName}'"
+ case None => ""
+ }
+ val errors = new ErrorLog(false)
val logger = new _root_.logger.Logger(this.getClass.getName)
- val msg = "Accessing the .instanceName or .toTarget of non-hardware Data is deprecated. " +
- "This will become an error in Chisel 3.6."
+ val msg =
+ "Accessing the .instanceName or .toTarget of non-hardware Data is deprecated" + nameGuess + parentGuess + ". " +
+ "This will become an error in Chisel 3.6."
errors.deprecated(msg, None)
errors.checkpoint(logger)
_computeName(None).get
@@ -364,7 +394,8 @@ private[chisel3] class ChiselContext() {
private[chisel3] class DynamicContext(
val annotationSeq: AnnotationSeq,
val throwOnFirstError: Boolean,
- val warnReflectiveNaming: Boolean) {
+ val warnReflectiveNaming: Boolean,
+ val warningsAsErrors: Boolean) {
val importDefinitionAnnos = annotationSeq.collect { case a: ImportDefinitionAnnotation[_] => a }
// Map holding the actual names of extModules
@@ -421,8 +452,9 @@ private[chisel3] class DynamicContext(
var whenStack: List[WhenContext] = Nil
var currentClock: Option[Clock] = None
var currentReset: Option[Reset] = None
- val errors = new ErrorLog
+ val errors = new ErrorLog(warningsAsErrors)
val namingStack = new NamingStack
+
// Used to indicate if this is the top-level module of full elaboration, or from a Definition
var inDefinition: Boolean = false
}
@@ -439,6 +471,9 @@ private[chisel3] object Builder extends LazyLogging {
dynamicContextVar.value.get
}
+ // Used to suppress warnings when casting from a UInt to an Enum
+ var suppressEnumCastWarning: Boolean = false
+
// Returns the current dynamic context
def captureContext(): DynamicContext = dynamicContext
// Sets the current dynamic contents
@@ -496,6 +531,7 @@ private[chisel3] object Builder extends LazyLogging {
def buildAggName(id: HasId): Option[String] = {
def getSubName(field: Data): Option[String] = field.getOptionRef.flatMap {
case Slot(_, field) => Some(field) // Record
+ case OpaqueSlot(_) => None // OpaqueSlots don't contribute to the name
case Index(_, ILit(n)) => Some(n.toString) // Vec static indexing
case Index(_, ULit(n, _)) => Some(n.toString) // Vec lit indexing
case Index(_, _: Node) => None // Vec dynamic indexing