Skip to content

Commit

Permalink
Factor buildName into reusable function
Browse files Browse the repository at this point in the history
The new function is chisel3.internal.buildName.
  • Loading branch information
jackkoenig committed Jun 6, 2022
1 parent cadaf33 commit 370ca8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
14 changes: 14 additions & 0 deletions core/src/main/scala/chisel3/RawModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ package object internal {
/** Marker trait for modules that are not true modules */
private[chisel3] trait PseudoModule extends BaseModule

/** Creates a name String from a prefix and a seed
* @param prefix The prefix associated with the seed (must be in correct order, *not* reversed)
* @param seed The seed for computing the name (if available)
*/
def buildName(seed: String, prefix: Prefix): String = {
val builder = new StringBuilder()
prefix.foreach { p =>
builder ++= p
builder += '_'
}
builder ++= seed
builder.toString
}

// Private reflective version of "val io" to maintain Chisel.Module semantics without having
// io as a virtual method. See https://github.com/freechipsproject/chisel3/pull/1550 for more
// information about the removal of "val io"
Expand Down
16 changes: 0 additions & 16 deletions core/src/main/scala/chisel3/internal/Builder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,6 @@ private[chisel3] trait HasId extends InstanceId {
* @return the name, if it can be computed
*/
private[chisel3] def _computeName(defaultPrefix: Option[String], defaultSeed: Option[String]): Option[String] = {

/** Computes a name of this signal, given the seed and prefix
* @param seed
* @param prefix
* @return
*/
def buildName(seed: String, prefix: Prefix): String = {
val builder = new StringBuilder()
prefix.foreach { p =>
builder ++= p
builder += '_'
}
builder ++= seed
builder.toString
}

if (hasSeed) {
Some(buildName(seedOpt.get, naming_prefix.reverse))
} else {
Expand Down

0 comments on commit 370ca8a

Please sign in to comment.