diff options
| author | Schuyler Eldridge | 2019-11-02 02:01:56 -0400 |
|---|---|---|
| committer | Schuyler Eldridge | 2019-11-02 02:15:19 -0400 |
| commit | a69d79f25a363e2895e682cadd463466964fa889 (patch) | |
| tree | bf085d63d201ed8aa10568acd7c2c30b903a7b42 /chiselFrontend/src/main | |
| parent | 2e891a4e2a638a00cb836736c72eb87673dffba3 (diff) | |
Better anonymous and class-in-function desiredName
This changes the desired name of a Module to provide non-numeric
naming for anonymous Modules and Modules defined inside function
bodies.
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'chiselFrontend/src/main')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/Module.scala | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/Module.scala b/chiselFrontend/src/main/scala/chisel3/Module.scala index f88d637f..5642840f 100644 --- a/chiselFrontend/src/main/scala/chisel3/Module.scala +++ b/chiselFrontend/src/main/scala/chisel3/Module.scala @@ -218,10 +218,32 @@ package experimental { // // Chisel Internals // - /** Desired name of this module. Override this to give this module a custom, perhaps parametric, - * name. + + /** The desired name of this module (which will be used in generated FIRRTL IR or Verilog). + * + * The name of a module approximates the behavior of the Java Reflection [[`getSimpleName` method + * https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getSimpleName--]] with some modifications: + * + * - Anonymous modules will get an `"_Anon"` tag + * - Modules defined in functions will use their class name and not a numeric name + * + * @note If you want a custom or parametric name, override this method. */ - def desiredName: String = this.getClass.getName.split("\\.|\\$").last + def desiredName: String = { + /* The default module name is derived from the Java reflection derived class name. */ + val baseName = this.getClass.getName + + /* A sequence of string filters applied to the name */ + val filters: Seq[String => String] = Seq( + ((a: String) => raw"\$$+anon".r.replaceAllIn(a, "_Anon")) // Merge the "$$anon" name with previous name + ) + + filters + .foldLeft(baseName){ case (str, filter) => filter(str) } // 1. Apply filters to baseName + .split("\\.|\\$") // 2. Split string at '.' or '$' + .filterNot(_.forall(_.isDigit)) // 3. Drop purely numeric names + .last // 4. Use the last name + } /** Legalized name of this module. */ final lazy val name = try { |
