diff options
| author | Andrew Waterman | 2019-01-11 15:05:28 -0800 |
|---|---|---|
| committer | edwardcwang | 2019-01-11 15:37:29 -0800 |
| commit | fe2f9e6a82dd222d5aecf2fcbc6880768346a4e1 (patch) | |
| tree | 49a1126c918ebc69854de5654a6e8ce43585761b /chiselFrontend | |
| parent | 1b2828f1c7fedc8c77e312509f68b59eb3041f5e (diff) | |
Move nameRecursively into Builder so it can be used elsewhere
Diffstat (limited to 'chiselFrontend')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Module.scala | 18 | ||||
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/internal/Builder.scala | 15 |
2 files changed, 16 insertions, 17 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala index 3bdc86d6..8a1a5c8a 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala @@ -225,22 +225,6 @@ abstract class BaseModule extends HasId { } } - /** Recursively suggests names to supported "container" classes - * Arbitrary nestings of supported classes are allowed so long as the - * innermost element is of type HasId - * (Note: Map is Iterable[Tuple2[_,_]] and thus excluded) - */ - def nameRecursively(prefix: String, nameMe: Any): Unit = - nameMe match { - case (id: HasId) => name(id, prefix) - case Some(elt) => nameRecursively(prefix, elt) - case (iter: Iterable[_]) if iter.hasDefiniteSize => - for ((elt, i) <- iter.zipWithIndex) { - nameRecursively(s"${prefix}_${i}", elt) - } - case _ => // Do nothing - } - /** Scala generates names like chisel3$util$Queue$$ram for private vals * This extracts the part after $$ for names like this and leaves names * without $$ unchanged @@ -248,7 +232,7 @@ abstract class BaseModule extends HasId { def cleanName(name: String): String = name.split("""\$\$""").lastOption.getOrElse(name) for (m <- getPublicFields(rootClass)) { - nameRecursively(cleanName(m.getName), m.invoke(this)) + Builder.nameRecursively(cleanName(m.getName), m.invoke(this), name) } names diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala index ce4e1e88..0938ea9e 100644 --- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala +++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala @@ -294,6 +294,21 @@ private[chisel3] object Builder { lastStack } + /** Recursively suggests names to supported "container" classes + * Arbitrary nestings of supported classes are allowed so long as the + * innermost element is of type HasId + * (Note: Map is Iterable[Tuple2[_,_]] and thus excluded) + */ + def nameRecursively(prefix: String, nameMe: Any, namer: (HasId, String) => Unit): Unit = nameMe match { + case (id: HasId) => namer(id, prefix) + case Some(elt) => nameRecursively(prefix, elt, namer) + case (iter: Iterable[_]) if iter.hasDefiniteSize => + for ((elt, i) <- iter.zipWithIndex) { + nameRecursively(s"${prefix}_${i}", elt, namer) + } + case _ => // Do nothing + } + def errors: ErrorLog = dynamicContext.errors def error(m: => String): Unit = if (dynamicContextVar.value.isDefined) errors.error(m) def warning(m: => String): Unit = if (dynamicContextVar.value.isDefined) errors.warning(m) |
