aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/annotations/Annotation.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/firrtl/annotations/Annotation.scala')
-rw-r--r--src/main/scala/firrtl/annotations/Annotation.scala15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/annotations/Annotation.scala b/src/main/scala/firrtl/annotations/Annotation.scala
index 2e361833..9efc6e9b 100644
--- a/src/main/scala/firrtl/annotations/Annotation.scala
+++ b/src/main/scala/firrtl/annotations/Annotation.scala
@@ -3,6 +3,9 @@
package firrtl
package annotations
+import net.jcazevedo.moultingyaml._
+import firrtl.annotations.AnnotationYamlProtocol._
+
case class AnnotationException(message: String) extends Exception(message)
final case class Annotation(target: Named, transform: Class[_ <: Transform], value: String) {
@@ -26,3 +29,15 @@ final case class Annotation(target: Named, transform: Class[_ <: Transform], val
def check(from: Named, tos: Seq[Named], which: Annotation): Unit = {}
def duplicate(n: Named) = Annotation(n, transform, value)
}
+
+object DeletedAnnotation {
+ def apply(xFormName: String, anno: Annotation): Annotation =
+ Annotation(anno.target, classOf[Transform], s"""DELETED by $xFormName\n${AnnotationUtils.toYaml(anno)}""")
+
+ private val deletedRegex = """(?s)DELETED by ([^\n]*)\n(.*)""".r
+ def unapply(a: Annotation): Option[Tuple2[String, Annotation]] = a match {
+ case Annotation(named, t, deletedRegex(xFormName, annoString)) if t == classOf[Transform] =>
+ Some((xFormName, AnnotationUtils.fromYaml(annoString)))
+ case _ => None
+ }
+}