diff options
| author | Adam Izraelevitz | 2018-10-24 20:40:27 -0700 |
|---|---|---|
| committer | GitHub | 2018-10-24 20:40:27 -0700 |
| commit | 7e2f787e125227dc389d5cf1d09717748ecfed2e (patch) | |
| tree | 2c654726a5c9850440792cf673e91ed01e0bdfe4 /src/main/scala/firrtl/annotations/AnnotationUtils.scala | |
| parent | f2c50e11c0e1ff3ed7b8ca3ae3d2d3b16f157453 (diff) | |
Instance Annotations (#865)
Added Target, which now supports Instance Annotations. See #865 for details.
Diffstat (limited to 'src/main/scala/firrtl/annotations/AnnotationUtils.scala')
| -rw-r--r-- | src/main/scala/firrtl/annotations/AnnotationUtils.scala | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/annotations/AnnotationUtils.scala b/src/main/scala/firrtl/annotations/AnnotationUtils.scala index 517cea26..ba9220f7 100644 --- a/src/main/scala/firrtl/annotations/AnnotationUtils.scala +++ b/src/main/scala/firrtl/annotations/AnnotationUtils.scala @@ -64,13 +64,29 @@ object AnnotationUtils { case Array(c, m, x) => ComponentName(x, ModuleName(m, CircuitName(c))) } + /** Converts a serialized FIRRTL component into a sequence of target tokens + * @param s + * @return + */ + def toSubComponents(s: String): Seq[TargetToken] = { + import TargetToken._ + def exp2subcomp(e: ir.Expression): Seq[TargetToken] = e match { + case ir.Reference(name, _) => Seq(Ref(name)) + case ir.SubField(expr, name, _) => exp2subcomp(expr) :+ Field(name) + case ir.SubIndex(expr, idx, _) => exp2subcomp(expr) :+ Index(idx) + case ir.SubAccess(expr, idx, _) => Utils.throwInternalError(s"For string $s, cannot convert a subaccess $e into a Target") + } + exp2subcomp(toExp(s)) + } + + /** 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) */ def toExp(s: String): Expression = { def parse(tokens: Seq[String]): Expression = { - val DecPattern = """([1-9]\d*)""".r + val DecPattern = """(\d+)""".r def findClose(tokens: Seq[String], index: Int, nOpen: Int): Seq[String] = { if(index >= tokens.size) { Utils.error("Cannot find closing bracket ]") |
