Skip to content

Commit 4cc4ab8

Browse files
authored
[firrtl] Drop Circuit from Target/Named (#4862)
Remove the circuit from both `Target` and `Named`. For the latter, this means that `CircuitName` is deleted. Carry this to its logical conclusion. The only parts that do require a change: 1. The RenameMap wants to know if a path is renamed to something "absolute". It does this check by looking to see if a module name matches the circuit name. (Note: this check is incorrect because it assumes that a circuit has a single root. However, this has not been the case since D/I was implemented.) Work around this by adding a "circuit name" parameter to the RenameMap so that this check can still be done. Note: large code paths within the rename map that are checking for module or instance path renames should be completely unreachable. The only user of the RenameMap at this point in-tree is `DataView` and this is not going to do renames involving paths. 2. The LayerControl API needs to know what the circuit name is since this is part of its ABI. Previously, the circuit name was known because of a, now deleted, method on `RawModule`. Change this to use the module name itself when determining the ABI setting (file name or macro name). This should always be correct because the method to generate the ABI setting because ChiselSim is always given some top module that it wants to simulate. This may be problematic for multi-rooted circuits like inline directed tests. 3. Users of the Trace API do not have a trivial access to the circuit name, i.e., the top module. However, if you are a user of this, you should know what your top name is without relying on the returned `CompleteTarget`. See the `TraceSpec` for an example of this. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent 6e56a7c commit 4cc4ab8

33 files changed

+470
-660
lines changed

core/src/main/scala/chisel3/Module.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ package experimental {
692692
*
693693
* @note Should not be called until circuit elaboration is complete
694694
*/
695-
final def toNamed: ModuleName = ModuleTarget(this.circuitName, this.name).toNamed
695+
final def toNamed: ModuleName = ModuleTarget(this.name).toNamed
696696

697697
/** Returns a FIRRTL ModuleTarget that references this object
698698
*
@@ -703,7 +703,7 @@ package experimental {
703703
throwException(s"Internal Error! It's not legal to call .toTarget on an InstanceClone. $m")
704704
case m: experimental.hierarchy.DefinitionClone[_] =>
705705
throwException(s"Internal Error! It's not legal to call .toTarget on an DefinitionClone. $m")
706-
case _ => ModuleTarget(this.circuitName, this.name)
706+
case _ => ModuleTarget(this.name)
707707
}
708708

709709
/** Returns the real target of a Module which may be an [[InstanceTarget]]
@@ -724,7 +724,7 @@ package experimental {
724724
m._parent.get.getTarget.instOf(instanceName, name)
725725
// Without this, we get the wrong CircuitName for the Definition
726726
case m: experimental.hierarchy.DefinitionClone[_] if m._circuit.nonEmpty =>
727-
ModuleTarget(this._circuit.get.circuitName, this.name)
727+
ModuleTarget(this.name)
728728
case _ => this.toTarget
729729
}
730730

@@ -813,7 +813,6 @@ package experimental {
813813
else {
814814
val thisAbsolute = this.toAbsoluteTarget
815815
val rootAbsolute = root.get.toAbsoluteTarget
816-
if (thisAbsolute.circuit != thisAbsolute.circuit) fail()
817816
recurse(thisAbsolute, rootAbsolute)
818817
}
819818
}

core/src/main/scala/chisel3/internal/Builder.scala

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import chisel3.internal.binding._
1212
import chisel3.internal.firrtl.ir._
1313
import chisel3.internal.firrtl.Converter
1414
import chisel3.internal.naming._
15-
import _root_.firrtl.annotations.{Annotation, CircuitName, ComponentName, IsMember, ModuleName, Named, ReferenceTarget}
15+
import _root_.firrtl.annotations.{Annotation, ComponentName, IsMember, ModuleName, Named, ReferenceTarget}
1616
import _root_.firrtl.annotations.AnnotationUtils.validComponentName
1717
import _root_.firrtl.{annoSeqToSeq, AnnotationSeq}
1818
import _root_.firrtl.renamemap.MutableRenameMap
@@ -344,20 +344,6 @@ private[chisel3] trait HasId extends chisel3.InstanceId {
344344
case Some(p) => p.name
345345
case None => throwException(s"$instanceName doesn't have a parent")
346346
}
347-
def circuitName: String = _parent match {
348-
case None =>
349-
// Only modules have circuits
350-
this match {
351-
case b: BaseModule =>
352-
b._circuit match {
353-
case Some(c) => c.circuitName
354-
case None => instanceName
355-
}
356-
case _ => instanceName
357-
}
358-
case Some(ViewParent) => reifyParent.circuitName
359-
case Some(p) => p.circuitName
360-
}
361347
}
362348

363349
/** Holds the implementation of toNamed for Data and MemBase */
@@ -368,7 +354,7 @@ private[chisel3] trait NamedComponent extends HasId {
368354
*/
369355
final def toNamed: ComponentName = {
370356
assertValidTarget()
371-
ComponentName(this.instanceName, ModuleName(this.parentModName, CircuitName(this.circuitName)))
357+
ComponentName(this.instanceName, ModuleName(this.parentModName))
372358
}
373359

374360
/** Returns a FIRRTL ReferenceTarget that references this object
@@ -953,8 +939,8 @@ private[chisel3] object Builder extends LazyLogging {
953939
// Builds a RenameMap for all Views that do not correspond to a single Data
954940
// These Data give a fake ReferenceTarget for .toTarget and .toReferenceTarget that the returned
955941
// RenameMap can split into the constituent parts
956-
private[chisel3] def makeViewRenameMap: MutableRenameMap = {
957-
val renames = MutableRenameMap()
942+
private[chisel3] def makeViewRenameMap(circuitName: String): MutableRenameMap = {
943+
val renames = MutableRenameMap(circuitName)
958944
for (view <- unnamedViews if !view.isLit) { // Aggregates can be literals too!
959945
reifySingleTarget(view) match {
960946
// If the target reifies to a single target, we don't need to rename.
@@ -1131,7 +1117,7 @@ private[chisel3] object Builder extends LazyLogging {
11311117
components.last.name,
11321118
components.toSeq,
11331119
annotations.toSeq,
1134-
makeViewRenameMap,
1120+
makeViewRenameMap(circuitName = components.last.name),
11351121
typeAliases,
11361122
layerAdjacencyList(layer.Layer.Root).map(foldLayers).toSeq,
11371123
optionDefs

core/src/main/scala/chisel3/internal/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ package object internal {
109109
// the Converter
110110
// Note that this is not overriding .toAbsoluteTarget, that is a final def in BaseModule that delegates
111111
// to this method
112-
private[chisel3] val absoluteTarget: IsModule = ModuleTarget(this.circuitName, "_$$AbsoluteView$$_")
112+
private[chisel3] val absoluteTarget: IsModule = ModuleTarget("_$$AbsoluteView$$_")
113113

114114
// This module is not instantiable
115115
override private[chisel3] def generateComponent(): Option[Component] = None

0 commit comments

Comments
 (0)