summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/aop/injecting
diff options
context:
space:
mode:
authorJack Koenig2021-09-17 21:01:26 -0700
committerJack Koenig2021-09-17 21:01:26 -0700
commit5c8c19345e6711279594cf1f9ddab33623c8eba7 (patch)
treed9d6ced3934aa4a8be3dec19ddcefe50a7a93d5a /src/main/scala/chisel3/aop/injecting
parente63b9667d89768e0ec6dc8a9153335cb48a213a7 (diff)
parent958904cb2f2f65d02b2ab3ec6d9ec2e06d04e482 (diff)
Merge branch 'master' into 3.5-release
Diffstat (limited to 'src/main/scala/chisel3/aop/injecting')
-rw-r--r--src/main/scala/chisel3/aop/injecting/InjectingAspect.scala20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala b/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
index 39590b93..1a476f61 100644
--- a/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
+++ b/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
@@ -4,6 +4,7 @@ package chisel3.aop.injecting
import chisel3.{Module, ModuleAspect, RawModule, withClockAndReset}
import chisel3.aop._
+import chisel3.experimental.hierarchy.IsInstantiable
import chisel3.internal.{Builder, DynamicContext}
import chisel3.internal.firrtl.DefModule
import chisel3.stage.DesignAnnotation
@@ -54,13 +55,14 @@ abstract class InjectorAspect[T <: RawModule, M <: RawModule](
* @return
*/
final def toAnnotation(modules: Iterable[M], circuit: String, moduleNames: Seq[String]): AnnotationSeq = {
- val dynamicContext = new DynamicContext()
- // Add existing module names into the namespace. If injection logic instantiates new modules
- // which would share the same name, they will get uniquified accordingly
- moduleNames.foreach { n =>
- dynamicContext.globalNamespace.name(n)
- }
RunFirrtlTransformAnnotation(new InjectingTransform) +: modules.map { module =>
+ val dynamicContext = new DynamicContext(annotationsInAspect)
+ // Add existing module names into the namespace. If injection logic instantiates new modules
+ // which would share the same name, they will get uniquified accordingly
+ moduleNames.foreach { n =>
+ dynamicContext.globalNamespace.name(n)
+ }
+
val (chiselIR, _) = Builder.build(Module(new ModuleAspect(module) {
module match {
case x: Module => withClockAndReset(x.clock, x.reset) { injection(module) }
@@ -75,16 +77,20 @@ abstract class InjectorAspect[T <: RawModule, M <: RawModule](
val annotations = chiselIR.annotations.map(_.toFirrtl).filterNot{ a => a.isInstanceOf[DesignAnnotation[_]] }
+ /** Statements to be injected via aspect. */
val stmts = mutable.ArrayBuffer[ir.Statement]()
+ /** Modules to be injected via aspect. */
val modules = Aspect.getFirrtl(chiselIR.copy(components = comps)).modules.flatMap {
+ // for "container" modules, inject their statements
case m: firrtl.ir.Module if m.name == module.name =>
stmts += m.body
Nil
+ // for modules to be injected
case other: firrtl.ir.DefModule =>
Seq(other)
}
- InjectStatement(ModuleTarget(circuit, module.name), ir.Block(stmts), modules, annotations)
+ InjectStatement(ModuleTarget(circuit, module.name), ir.Block(stmts.toSeq), modules, annotations)
}.toSeq
}
}