aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/annotations
diff options
context:
space:
mode:
authorAlbert Chen2019-02-22 15:30:27 -0800
committermergify[bot]2019-02-22 23:30:27 +0000
commit5608aa8f42c1d69b59bee158d14fc6cef9b19a47 (patch)
tree86b7bad9c5f164d12aba9f324bde223e7ff5e9f3 /src/main/scala/firrtl/annotations
parent0ace0218d3151df2d102463dd682128a88ae7be6 (diff)
Add Width Constraints with Annotations (#956)
* refactor InferWidths to allow for extra contraints, add InferWidthsWithAnnos * add test cases * add ResolvedAnnotationPaths trait to InferWidthsWithAnnos * remove println * cleanup tests * remove extraneous constraints * use foreachStmt instead of mapStmt * remove support for aggregates * fold InferWidthsWithAnnos into InferWidths * throw exception if ref not found, check for annos before AST walk
Diffstat (limited to 'src/main/scala/firrtl/annotations')
-rw-r--r--src/main/scala/firrtl/annotations/Target.scala21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/annotations/Target.scala b/src/main/scala/firrtl/annotations/Target.scala
index 8a9d68e8..0247b66c 100644
--- a/src/main/scala/firrtl/annotations/Target.scala
+++ b/src/main/scala/firrtl/annotations/Target.scala
@@ -3,7 +3,8 @@
package firrtl
package annotations
-import firrtl.ir.Expression
+import firrtl.ir.{Expression, Type}
+import firrtl.Utils.{sub_type, field_type}
import AnnotationUtils.{toExp, validComponentName, validModuleName}
import TargetToken._
@@ -553,6 +554,24 @@ case class ReferenceTarget(circuit: String,
/** @return The clock signal of this reference, must be to a [[firrtl.ir.DefRegister]] */
def clock: ReferenceTarget = ReferenceTarget(circuit, module, path, ref, component :+ Clock)
+ /** @param the type of this target's ref
+ * @return the type of the subcomponent specified by this target's component
+ */
+ def componentType(baseType: Type): Type = componentType(baseType, tokens)
+
+ private def componentType(baseType: Type, tokens: Seq[TargetToken]): Type = {
+ if (tokens.isEmpty) {
+ baseType
+ } else {
+ val headType = tokens.head match {
+ case Index(idx) => sub_type(baseType)
+ case Field(field) => field_type(baseType, field)
+ case _: Ref => baseType
+ }
+ componentType(headType, tokens.tail)
+ }
+ }
+
override def circuitOpt: Option[String] = Some(circuit)
override def moduleOpt: Option[String] = Some(module)