summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala3
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Module.scala22
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/Builder.scala44
-rw-r--r--src/main/scala/chisel3/Driver.scala2
-rw-r--r--src/main/scala/chisel3/internal/firrtl/Emitter.scala16
5 files changed, 54 insertions, 33 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
index de64cb3d..82c6097f 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
@@ -374,4 +374,5 @@ class Bundle extends Aggregate(NO_DIR) {
private[core] object Bundle {
val keywords = List("flip", "asInput", "asOutput", "cloneType", "toBits",
- "widthOption", "signalName", "signalPathName", "signalParent", "signalComponent")
+ "widthOption", "signalName", "signalPathName", "signalParent", "signalComponent")
+}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
index 4f25515b..eb48a14d 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
@@ -31,7 +31,9 @@ object Module {
m._commands.prepend(DefInvalid(childSourceInfo, m.io.ref)) // init module outputs
dynamicContext.currentModule = parent
val ports = m.computePorts
- Builder.components += Component(m, m.name, ports, m._commands)
+ val component = Component(m, m.name, ports, m._commands)
+ m._component = Some(component)
+ Builder.components += component
pushCommand(DefInstance(sourceInfo, m, ports))
m.setupInParent(childSourceInfo)
}
@@ -63,8 +65,24 @@ extends HasId {
/** Legalized name of this module. */
final val name = Builder.globalNamespace.name(desiredName)
+ /** FIRRTL Module name */
+ private var _modName: Option[String] = None
+ private[chisel3] def setModName(name: String) = _modName = Some(name)
+ def modName = _modName match {
+ case Some(name) => name
+ case None => throwException("modName should be called after circuit elaboration")
+ }
+
+ /** Keep component for signal names */
+ private[chisel3] var _component: Option[Component] = None
+
+
/** Signal name (for simulation). */
- override def signalName(component: Component) = name
+ override def signalName =
+ if (_parent == None) name else _component match {
+ case None => getRef.name
+ case Some(c) => getRef fullName c
+ }
/** IO for this Module. At the Scala level (pre-FIRRTL transformations),
* connections in and out of a Module may only go through `io` elements.
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
index 21f32483..bf78c410 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
@@ -59,29 +59,18 @@ private[chisel3] class IdGen {
* currently, the node's name, the full path name, and references to its parent Module and component.
* These are only valid once the design has been elaborated, and should not be used during its construction.
*/
-trait SignalID {
- def signalName(component: Component): String
- def signalPathName(component: Component, separator: String = "."): String
- def signalParent: Module
- def signalComponent: Option[Component]
+trait SignalId {
+ def signalName: String
+ def pathName: String
+ def parentPathName: String
+ def parentModName: String
}
-private[chisel3] trait HasId extends SignalID {
+private[chisel3] trait HasId extends SignalId {
private[chisel3] def _onModuleClose {} // scalastyle:ignore method.name
private[chisel3] val _parent = Builder.dynamicContext.currentModule
_parent.foreach(_.addId(this))
- // Implementation of public methods.
- override def signalParent = _parent.get
- override def signalName(component: Component) = _ref.get.fullName(component)
- override def signalPathName(component: Component, separator: String = "_"): String = {
- _parent match {
- case Some(p) => p.signalPathName(component, separator) + separator + signalName(component)
- case None => signalName(component)
- }
- }
- override def signalComponent: Option[Component] = None
-
private[chisel3] val _id = Builder.idGen.next
override def hashCode: Int = _id.toInt
override def equals(that: Any): Boolean = that match {
@@ -117,6 +106,27 @@ private[chisel3] trait HasId extends SignalID {
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
+
+ // Implementation of public methods.
+ def signalName = _parent match {
+ case Some(p) => p._component match {
+ case Some(c) => getRef fullName c
+ case None => throwException("signalName/pathName should be called after circuit elaboration")
+ }
+ case None => throwException("this cannot happen")
+ }
+ def pathName = _parent match {
+ case None => signalName
+ case Some(p) => s"${p.pathName}.$signalName"
+ }
+ def parentPathName = _parent match {
+ case Some(p) => p.pathName
+ case None => throwException(s"$signalName doesn't have a parent")
+ }
+ def parentModName = _parent match {
+ case Some(p) => p.modName
+ case None => throwException(s"$signalName doesn't have a parent")
+ }
}
private[chisel3] class DynamicContext {
diff --git a/src/main/scala/chisel3/Driver.scala b/src/main/scala/chisel3/Driver.scala
index 0979314f..5aeeef99 100644
--- a/src/main/scala/chisel3/Driver.scala
+++ b/src/main/scala/chisel3/Driver.scala
@@ -112,6 +112,8 @@ object Driver extends BackendCompilationUtilities {
def emit[T <: Module](gen: () => T): String = Emitter.emit(elaborate(gen))
+ def emit[T <: Module](ir: Circuit): String = Emitter.emit(ir)
+
def dumpFirrtl(ir: Circuit, optName: Option[File]): File = {
val f = optName.getOrElse(new File(ir.name + ".fir"))
val w = new FileWriter(f)
diff --git a/src/main/scala/chisel3/internal/firrtl/Emitter.scala b/src/main/scala/chisel3/internal/firrtl/Emitter.scala
index 31856541..79f86ae9 100644
--- a/src/main/scala/chisel3/internal/firrtl/Emitter.scala
+++ b/src/main/scala/chisel3/internal/firrtl/Emitter.scala
@@ -27,11 +27,7 @@ private class Emitter(circuit: Circuit) {
case e: Stop => s"stop(${e.clk.fullName(ctx)}, UInt<1>(1), ${e.ret})"
case e: Printf => s"""printf(${e.clk.fullName(ctx)}, UInt<1>(1), "${e.format}"${e.ids.map(_.fullName(ctx)).fold(""){_ + ", " + _}})"""
case e: DefInvalid => s"${e.arg.fullName(ctx)} is invalid"
- case e: DefInstance => {
- val modName = moduleMap.get(e.id.name).get
- s"inst ${e.name} of $modName"
- }
-
+ case e: DefInstance => s"inst ${e.name} of ${e.id.modName}"
case w: WhenBegin =>
indent()
s"when ${w.pred.fullName(ctx)} :"
@@ -47,8 +43,6 @@ private class Emitter(circuit: Circuit) {
// Map of Module FIRRTL definition to FIRRTL name, if it has been emitted already.
private val defnMap = collection.mutable.HashMap[(String, String), Component]()
- // Map of Component name to FIRRTL id.
- private val moduleMap = collection.mutable.HashMap[String, String]()
/** Generates the FIRRTL module declaration.
*/
@@ -89,15 +83,11 @@ private class Emitter(circuit: Circuit) {
defnMap get (m.id.desiredName, defn) match {
case Some(duplicate) =>
- moduleMap(m.name) = duplicate.name
+ m.id setModName duplicate.name
""
case None =>
- require(!(moduleMap contains m.name),
- "emitting module with same name but different contents")
-
- moduleMap(m.name) = m.name
defnMap((m.id.desiredName, defn)) = m
-
+ m.id setModName m.id.name
moduleDecl(m) + defn
}
}