diff options
Diffstat (limited to 'src/main/scala/firrtl/annotations')
| -rw-r--r-- | src/main/scala/firrtl/annotations/Annotation.scala | 15 | ||||
| -rw-r--r-- | src/main/scala/firrtl/annotations/AnnotationUtils.scala | 13 |
2 files changed, 28 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 + } +} diff --git a/src/main/scala/firrtl/annotations/AnnotationUtils.scala b/src/main/scala/firrtl/annotations/AnnotationUtils.scala index 6e6af81d..8f55c13e 100644 --- a/src/main/scala/firrtl/annotations/AnnotationUtils.scala +++ b/src/main/scala/firrtl/annotations/AnnotationUtils.scala @@ -3,9 +3,15 @@ package firrtl package annotations +import net.jcazevedo.moultingyaml._ +import firrtl.annotations.AnnotationYamlProtocol._ + import firrtl.ir._ object AnnotationUtils { + def toYaml(a: Annotation): String = a.toYaml.prettyPrint + def fromYaml(s: String): Annotation = s.parseYaml.convertTo[Annotation] + /** Returns true if a valid Module name */ val SerializedModuleName = """([a-zA-Z_][a-zA-Z_0-9~!@#$%^*\-+=?/]*)""".r def validModuleName(s: String): Boolean = s match { @@ -34,6 +40,13 @@ object AnnotationUtils { case None => Seq(s) } + def toNamed(s: String): Named = tokenize(s) match { + case Seq(n) => CircuitName(n) + case Seq(c, m) => ModuleName(m, CircuitName(c)) + case Seq(c, m) => ModuleName(m, CircuitName(c)) + case Seq(c, m, x) => ComponentName(x, ModuleName(m, CircuitName(c))) + } + /** Given a serialized component/subcomponent reference, subindex, subaccess, * or subfield, return the corresponding IR expression. * E.g. "foo.bar" becomes SubField(Reference("foo", UnknownType), "bar", UnknownType) |
