summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
diff options
context:
space:
mode:
authorJim Lawson2016-07-06 09:31:47 -0700
committerJim Lawson2016-07-18 15:49:45 -0700
commit12810b5efe6a8f872fbc1c63cdfb835ca354624f (patch)
tree1fe4d0666e28f15880bbaf164592bd2bba1eff7c /chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
parentc5f9ea3133ef363ff8944e17d94fea79767b6bed (diff)
Update Chisel -> chisel3 references.
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/internal/Builder.scala')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/Builder.scala54
1 files changed, 30 insertions, 24 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
index d0e28b7c..0e0a88cc 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
@@ -1,29 +1,35 @@
// See LICENSE for license details.
-package Chisel.internal
+package chisel3.internal
import scala.util.DynamicVariable
import scala.collection.mutable.{ArrayBuffer, HashMap}
-import Chisel._
-import Chisel.internal.firrtl._
+import chisel3._
+import core._
+import firrtl._
-private[Chisel] class Namespace(parent: Option[Namespace], keywords: Set[String]) {
- private var i = 0L
- private val names = collection.mutable.HashSet[String]()
+private[chisel3] class Namespace(parent: Option[Namespace], keywords: Set[String]) {
+ private val names = collection.mutable.HashMap[String, Long]()
+ for (keyword <- keywords)
+ names(keyword) = 1
- private def rename(n: String) = { i += 1; s"${n}_${i}" }
+ private def rename(n: String): String = {
+ val index = names.getOrElse(n, 1L)
+ val tryName = s"${n}_${index}"
+ names(n) = index + 1
+ if (this contains tryName) rename(n) else tryName
+ }
def contains(elem: String): Boolean = {
- keywords.contains(elem) || names.contains(elem) ||
- parent.map(_ contains elem).getOrElse(false)
+ names.contains(elem) || parent.map(_ contains elem).getOrElse(false)
}
def name(elem: String): String = {
if (this contains elem) {
name(rename(elem))
} else {
- names += elem
+ names(elem) = 1
elem
}
}
@@ -32,7 +38,7 @@ private[Chisel] class Namespace(parent: Option[Namespace], keywords: Set[String]
def child: Namespace = child(Set())
}
-private[Chisel] class IdGen {
+private[chisel3] class IdGen {
private var counter = -1L
def next: Long = {
counter += 1
@@ -40,12 +46,12 @@ private[Chisel] class IdGen {
}
}
-private[Chisel] trait HasId {
- private[Chisel] def _onModuleClose {} // scalastyle:ignore method.name
- private[Chisel] val _parent = Builder.dynamicContext.currentModule
+private[chisel3] trait HasId {
+ private[chisel3] def _onModuleClose {} // scalastyle:ignore method.name
+ private[chisel3] val _parent = Builder.dynamicContext.currentModule
_parent.foreach(_.addId(this))
- private[Chisel] val _id = Builder.idGen.next
+ private[chisel3] val _id = Builder.idGen.next
override def hashCode: Int = _id.toInt
override def equals(that: Any): Boolean = that match {
case x: HasId => _id == x._id
@@ -62,12 +68,12 @@ private[Chisel] trait HasId {
for(hook <- postname_hooks) { hook(name) }
this
}
- private[Chisel] def addPostnameHook(hook: String=>Unit): Unit = postname_hooks += hook
+ private[chisel3] def addPostnameHook(hook: String=>Unit): Unit = postname_hooks += hook
// 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 Bundle)
- private[Chisel] def forceName(default: =>String, namespace: Namespace): Unit =
+ private[chisel3] def forceName(default: =>String, namespace: Namespace): Unit =
if(_ref.isEmpty) {
val candidate_name = suggested_name.getOrElse(default)
val available_name = namespace.name(candidate_name)
@@ -75,14 +81,14 @@ private[Chisel] trait HasId {
}
private var _ref: Option[Arg] = None
- private[Chisel] def setRef(imm: Arg): Unit = _ref = Some(imm)
- private[Chisel] def setRef(parent: HasId, name: String): Unit = setRef(Slot(Node(parent), name))
- private[Chisel] def setRef(parent: HasId, index: Int): Unit = setRef(Index(Node(parent), ILit(index)))
- private[Chisel] def setRef(parent: HasId, index: UInt): Unit = setRef(Index(Node(parent), index.ref))
- private[Chisel] def getRef: Arg = _ref.get
+ private[chisel3] def setRef(imm: Arg): Unit = _ref = Some(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 getRef: Arg = _ref.get
}
-private[Chisel] class DynamicContext {
+private[chisel3] class DynamicContext {
val idGen = new IdGen
val globalNamespace = new Namespace(None, Set())
val components = ArrayBuffer[Component]()
@@ -90,7 +96,7 @@ private[Chisel] class DynamicContext {
val errors = new ErrorLog
}
-private[Chisel] object Builder {
+private[chisel3] object Builder {
// All global mutable state must be referenced via dynamicContextVar!!
private val dynamicContextVar = new DynamicVariable[Option[DynamicContext]](None)