From 3ef63639284b2b56f415e1540c58d85d88c360db Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 30 Jan 2017 22:42:57 -0800 Subject: Make Module and Bundle properly use empty namespaces Fix default suggested name of Module instances (now based on desired name rather than actual assigned name). Remove parent/child relationship from Namespace. Previously, Module and Bundle namespaces were "children" of the Module definition namespace. This could lead to collisions that would give unexpected names for module instances or Bundle elements. In particular, otherwise identical modules that instantiate other identical modules in such a way that the instance cannot be named via reflection would not be deduplicated because the names of the instances would collide with the names of the modules in the Builder.globalNamespace. --- .../src/main/scala/chisel3/internal/Builder.scala | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'chiselFrontend/src/main/scala/chisel3/internal') diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala index 5d841941..d8202da6 100644 --- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala +++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala @@ -9,7 +9,7 @@ import chisel3._ import core._ import firrtl._ -private[chisel3] class Namespace(parent: Option[Namespace], keywords: Set[String]) { +private[chisel3] class Namespace(keywords: Set[String]) { private val names = collection.mutable.HashMap[String, Long]() for (keyword <- keywords) names(keyword) = 1 @@ -29,9 +29,7 @@ private[chisel3] class Namespace(parent: Option[Namespace], keywords: Set[String if (res.isEmpty || !legalStart(res.head)) s"_$res" else res } - def contains(elem: String): Boolean = { - names.contains(elem) || parent.map(_ contains elem).getOrElse(false) - } + def contains(elem: String): Boolean = names.contains(elem) def name(elem: String): String = { val sanitized = sanitize(elem) @@ -42,9 +40,11 @@ private[chisel3] class Namespace(parent: Option[Namespace], keywords: Set[String sanitized } } +} - def child(kws: Set[String]): Namespace = new Namespace(Some(this), kws) - def child: Namespace = child(Set()) +private[chisel3] object Namespace { + /** Constructs an empty Namespace */ + def empty: Namespace = new Namespace(Set.empty[String]) } private[chisel3] class IdGen { @@ -143,7 +143,7 @@ private[chisel3] trait HasId extends InstanceId { private[chisel3] class DynamicContext() { val idGen = new IdGen - val globalNamespace = new Namespace(None, Set()) + val globalNamespace = Namespace.empty val components = ArrayBuffer[Component]() val annotations = ArrayBuffer[ChiselAnnotation]() var currentModule: Option[Module] = None -- cgit v1.2.3