summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/core
diff options
context:
space:
mode:
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/ChiselAnnotation.scala30
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Module.scala6
2 files changed, 35 insertions, 1 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/ChiselAnnotation.scala b/chiselFrontend/src/main/scala/chisel3/core/ChiselAnnotation.scala
new file mode 100644
index 00000000..73573bb1
--- /dev/null
+++ b/chiselFrontend/src/main/scala/chisel3/core/ChiselAnnotation.scala
@@ -0,0 +1,30 @@
+// See LICENSE for license details.
+
+package chisel3.core
+
+import chisel3.internal.InstanceId
+import firrtl.Transform
+import firrtl.annotations.{Annotation, CircuitName, ComponentName, ModuleName}
+
+/**
+ * This is a stand-in for the firrtl.Annotations.Annotation because at the time this annotation
+ * is created the component cannot be resolved, into a targetString. Resolution can only
+ * happen after the circuit is elaborated
+ * @param component A chisel thingy to be annotated, could be module, wire, reg, etc.
+ * @param transformClass A fully-qualified class name of the transformation pass
+ * @param value A string value to be used by the transformation pass
+ */
+case class ChiselAnnotation(component: InstanceId, transformClass: Class[_ <: Transform], value: String) {
+ def toFirrtl: Annotation = {
+ val circuitName = CircuitName(component.pathName.split("""\.""").head)
+ component match {
+ case m: Module =>
+ Annotation(
+ ModuleName(m.name, circuitName), transformClass, value)
+ case _ =>
+ Annotation(
+ ComponentName(
+ component.instanceName, ModuleName(component.parentModName, circuitName)), transformClass, value)
+ }
+ }
+}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
index bd406529..76a3b240 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
@@ -14,7 +14,7 @@ object Module {
/** A wrapper method that all Module instantiations must be wrapped in
* (necessary to help Chisel track internal state).
*
- * @param m the Module being created
+ * @param bc the Module being created
*
* @return the input module `m` with Chisel metadata properly set
*/
@@ -85,6 +85,10 @@ extends HasId {
iodef
}
+ def annotate(annotation: ChiselAnnotation): Unit = {
+ Builder.annotations += annotation
+ }
+
private[core] var ioDefined: Boolean = false
/**