summaryrefslogtreecommitdiff
path: root/src/main/scala
diff options
context:
space:
mode:
authorJiuyang Liu2021-02-27 05:01:10 +0800
committerGitHub2021-02-26 13:01:10 -0800
commit923ccbde1353e37f0948d3c5d94b49965dc6d950 (patch)
tree0565112847c8aef6cf8aaf2562a3e97ead026d24 /src/main/scala
parentc2ba4098d0a2f7ca056ea198d68b1d3bfaf40f3b (diff)
Expose AnnotationSeq to Module. (#1731)
Diffstat (limited to 'src/main/scala')
-rw-r--r--src/main/scala/chisel3/aop/injecting/InjectingAspect.scala2
-rw-r--r--src/main/scala/chisel3/stage/ChiselAnnotations.scala6
-rw-r--r--src/main/scala/chisel3/stage/phases/AspectPhase.scala2
-rw-r--r--src/main/scala/chisel3/stage/phases/Elaborate.scala15
-rw-r--r--src/main/scala/chisel3/util/experimental/getAnnotations.scala9
5 files changed, 19 insertions, 15 deletions
diff --git a/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala b/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
index 39590b93..170bfbad 100644
--- a/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
+++ b/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
@@ -54,7 +54,7 @@ abstract class InjectorAspect[T <: RawModule, M <: RawModule](
* @return
*/
final def toAnnotation(modules: Iterable[M], circuit: String, moduleNames: Seq[String]): AnnotationSeq = {
- val dynamicContext = new DynamicContext()
+ 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 =>
diff --git a/src/main/scala/chisel3/stage/ChiselAnnotations.scala b/src/main/scala/chisel3/stage/ChiselAnnotations.scala
index 04246fc5..b071c60f 100644
--- a/src/main/scala/chisel3/stage/ChiselAnnotations.scala
+++ b/src/main/scala/chisel3/stage/ChiselAnnotations.scala
@@ -56,11 +56,7 @@ case class ChiselGeneratorAnnotation(gen: () => RawModule) extends NoTargetAnnot
/** Run elaboration on the Chisel module generator function stored by this [[firrtl.annotations.Annotation]]
*/
- def elaborate: AnnotationSeq = {
- val (circuit, dut) = Builder.build(Module(gen()))
- Seq(ChiselCircuitAnnotation(circuit), DesignAnnotation(dut))
- }
-
+ def elaborate: AnnotationSeq = (new chisel3.stage.phases.Elaborate).transform(Seq(this))
}
object ChiselGeneratorAnnotation extends HasShellOptions {
diff --git a/src/main/scala/chisel3/stage/phases/AspectPhase.scala b/src/main/scala/chisel3/stage/phases/AspectPhase.scala
index 1a27b8fa..72965861 100644
--- a/src/main/scala/chisel3/stage/phases/AspectPhase.scala
+++ b/src/main/scala/chisel3/stage/phases/AspectPhase.scala
@@ -29,7 +29,7 @@ class AspectPhase extends Phase {
case other => Seq(other)
}
if(dut.isDefined) {
- val newAnnotations = aspects.flatMap { _.resolveAspect(dut.get) }
+ val newAnnotations = aspects.flatMap { _.resolveAspect(dut.get, remainingAnnotations) }
remainingAnnotations ++ newAnnotations
} else annotations
}
diff --git a/src/main/scala/chisel3/stage/phases/Elaborate.scala b/src/main/scala/chisel3/stage/phases/Elaborate.scala
index df39b66b..e8f2623e 100644
--- a/src/main/scala/chisel3/stage/phases/Elaborate.scala
+++ b/src/main/scala/chisel3/stage/phases/Elaborate.scala
@@ -2,15 +2,13 @@
package chisel3.stage.phases
-import java.io.{PrintWriter, StringWriter}
-
-import chisel3.ChiselException
-import chisel3.internal.ErrorLog
+import chisel3.Module
import chisel3.internal.ExceptionHelpers.ThrowableHelpers
-import chisel3.stage.{ChiselGeneratorAnnotation, ChiselOptions}
+import chisel3.internal.{Builder, DynamicContext}
+import chisel3.stage.{ChiselCircuitAnnotation, ChiselGeneratorAnnotation, ChiselOptions, DesignAnnotation}
import firrtl.AnnotationSeq
+import firrtl.options.Phase
import firrtl.options.Viewer.view
-import firrtl.options.{OptionsException, Phase}
/** Elaborate all [[chisel3.stage.ChiselGeneratorAnnotation]]s into [[chisel3.stage.ChiselCircuitAnnotation]]s.
*/
@@ -22,8 +20,9 @@ class Elaborate extends Phase {
override def invalidates(a: Phase) = false
def transform(annotations: AnnotationSeq): AnnotationSeq = annotations.flatMap {
- case a: ChiselGeneratorAnnotation => try {
- a.elaborate
+ case ChiselGeneratorAnnotation(gen) => try {
+ val (circuit, dut) = Builder.build(Module(gen()), new DynamicContext(annotations))
+ Seq(ChiselCircuitAnnotation(circuit), DesignAnnotation(dut))
} catch {
/* if any throwable comes back and we're in "stack trace trimming" mode, then print an error and trim the stack trace
*/
diff --git a/src/main/scala/chisel3/util/experimental/getAnnotations.scala b/src/main/scala/chisel3/util/experimental/getAnnotations.scala
new file mode 100644
index 00000000..dc9b75ee
--- /dev/null
+++ b/src/main/scala/chisel3/util/experimental/getAnnotations.scala
@@ -0,0 +1,9 @@
+package chisel3.util.experimental
+
+import chisel3.internal.Builder
+import firrtl.AnnotationSeq
+
+object getAnnotations {
+ /** Returns the global Annotations */
+ def apply(): AnnotationSeq = Builder.annotationSeq
+}