aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/passes/Uniquify.scala
diff options
context:
space:
mode:
authorJack Koenig2020-08-21 13:05:38 -0700
committerGitHub2020-08-21 13:05:38 -0700
commit266ac5fc32865d001409194f426b4126f5d9001b (patch)
tree882b568677ed3578023bc8987ac0b4ee601c5db3 /src/main/scala/firrtl/passes/Uniquify.scala
parent73868fc6e8110282ce545c296540d3ebbafadfeb (diff)
Deprecate Uniquify and move its useful utilities (#1856)
Diffstat (limited to 'src/main/scala/firrtl/passes/Uniquify.scala')
-rw-r--r--src/main/scala/firrtl/passes/Uniquify.scala75
1 files changed, 8 insertions, 67 deletions
diff --git a/src/main/scala/firrtl/passes/Uniquify.scala b/src/main/scala/firrtl/passes/Uniquify.scala
index bc48ebbc..57ef11fa 100644
--- a/src/main/scala/firrtl/passes/Uniquify.scala
+++ b/src/main/scala/firrtl/passes/Uniquify.scala
@@ -31,6 +31,7 @@ import MemPortUtils.memType
* there WOULD be collisions in references a[0] and a_0 so we still have
* to rename a
*/
+@deprecated("Uniquify is now part of LowerTypes", "FIRRTL 1.4.0")
object Uniquify extends Transform with DependencyAPIMigration {
override def prerequisites =
@@ -51,77 +52,17 @@ object Uniquify extends Transform with DependencyAPIMigration {
/** Appends delim to prefix until no collisions of prefix + elts in names We don't add an _ in the collision check
* because elts could be Seq("") In this case, we're just really checking if prefix itself collides
*/
- @tailrec
+ @deprecated("Use firrtl.Namespace.findValidPrefix", "FIRRTL 1.4.0")
def findValidPrefix(
prefix: String,
elts: Seq[String],
namespace: collection.mutable.HashSet[String]
- ): String = {
- elts.find(elt => namespace.contains(prefix + elt)) match {
- case Some(_) => findValidPrefix(prefix + "_", elts, namespace)
- case None => prefix
- }
- }
-
- /** Enumerates all possible names for a given type. For example:
- * {{{
- * foo : { bar : { a, b }[2], c }
- * => foo, foo bar, foo bar 0, foo bar 1, foo bar 0 a, foo bar 0 b, foo bar 1 a, foo bar 1 b, foo c
- * }}}
- */
- private[firrtl] def enumerateNames(tpe: Type): Seq[Seq[String]] = tpe match {
- case t: BundleType =>
- t.fields.flatMap { f =>
- (enumerateNames(f.tpe).map(f.name +: _)) ++ Seq(Seq(f.name))
- }
- case t: VectorType =>
- ((0 until t.size).map(i => Seq(i.toString))) ++
- ((0 until t.size).flatMap { i =>
- enumerateNames(t.tpe).map(i.toString +: _)
- })
- case _ => Seq()
- }
+ ): String = Namespace.findValidPrefix(prefix, elts, namespace)
/** Creates a Bundle Type from a Stmt */
- def stmtToType(s: Statement)(implicit sinfo: Info, mname: String): BundleType = {
- // Recursive helper
- def recStmtToType(s: Statement): Seq[Field] = s match {
- case sx: DefWire => Seq(Field(sx.name, Default, sx.tpe))
- case sx: DefRegister => Seq(Field(sx.name, Default, sx.tpe))
- case sx: WDefInstance => Seq(Field(sx.name, Default, sx.tpe))
- case sx: DefMemory =>
- sx.dataType match {
- case (_: UIntType | _: SIntType | _: FixedType) =>
- Seq(Field(sx.name, Default, memType(sx)))
- case tpe: BundleType =>
- val newFields = tpe.fields
- .map(f =>
- DefMemory(
- sx.info,
- f.name,
- f.tpe,
- sx.depth,
- sx.writeLatency,
- sx.readLatency,
- sx.readers,
- sx.writers,
- sx.readwriters
- )
- )
- .flatMap(recStmtToType)
- Seq(Field(sx.name, Default, BundleType(newFields)))
- case tpe: VectorType =>
- val newFields =
- (0 until tpe.size).map(i => sx.copy(name = i.toString, dataType = tpe.tpe)).flatMap(recStmtToType)
- Seq(Field(sx.name, Default, BundleType(newFields)))
- }
- case sx: DefNode => Seq(Field(sx.name, Default, sx.value.tpe))
- case sx: Conditionally => recStmtToType(sx.conseq) ++ recStmtToType(sx.alt)
- case sx: Block => (sx.stmts.map(recStmtToType)).flatten
- case sx => Seq()
- }
- BundleType(recStmtToType(s))
- }
+ @deprecated("Use firrtl.Utils.stmtToType", "FIRRTL 1.4.0")
+ def stmtToType(s: Statement)(implicit sinfo: Info, mname: String): BundleType =
+ Utils.stmtToType(s)
// Accepts a Type and an initial namespace
// Returns new Type with uniquified names
@@ -136,7 +77,7 @@ object Uniquify extends Transform with DependencyAPIMigration {
case tx: BundleType =>
// First add everything
val newFieldsAndElts = tx.fields.map { f =>
- val newName = findValidPrefix(f.name, Seq(""), namespace)
+ val newName = Namespace.findValidPrefix(f.name, Seq(""), namespace)
namespace += newName
Field(newName, f.flip, f.tpe)
}.map { f =>
@@ -146,7 +87,7 @@ object Uniquify extends Transform with DependencyAPIMigration {
val (tpe, eltsx) = recUniquifyNames(f.tpe, collection.mutable.HashSet())
// Need leading _ for findValidPrefix, it doesn't add _ for checks
val eltsNames: Seq[String] = eltsx.map(e => "_" + e)
- val prefix = findValidPrefix(f.name, eltsNames, namespace)
+ val prefix = Namespace.findValidPrefix(f.name, eltsNames, namespace)
// We added f.name in previous map, delete if we change it
if (prefix != f.name) {
namespace -= f.name