-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b8d9c4
commit 7436555
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package yourpackage | ||
|
||
import firrtl._ | ||
import firrtl.annotations.NoTargetAnnotation | ||
import firrtl.ir._ | ||
import firrtl.stage.TransformManager.TransformDependency | ||
|
||
case class ModulePrefixAnnotation(prefix: String) extends NoTargetAnnotation | ||
|
||
class AddModulePrefix extends Transform with DependencyAPIMigration { | ||
|
||
override def prerequisites: Seq[TransformDependency] = firrtl.stage.Forms.ChirrtlForm | ||
|
||
override protected def execute(state: CircuitState): CircuitState = { | ||
val c = state.circuit | ||
|
||
val prefix = state.annotations.collectFirst { | ||
case ModulePrefixAnnotation(p) => p | ||
}.get | ||
|
||
def onStmt(s: Statement): Statement = s match { | ||
case DefInstance(info, name, module) => | ||
DefInstance(info, name, prefix + module) | ||
case other => | ||
other.mapStmt(onStmt) | ||
} | ||
|
||
def onModule(m: DefModule): DefModule = { | ||
val newMod = m.mapStmt(onStmt) | ||
newMod match { | ||
case Module(info, name, ports, body) => | ||
Module(info, prefix + name, ports, body) | ||
case other => | ||
other | ||
} | ||
} | ||
val newCircuit = c.mapModule(onModule) | ||
state.copy(newCircuit.copy(main = prefix + newCircuit.main)) | ||
} | ||
|
||
} |