From 5608aa8f42c1d69b59bee158d14fc6cef9b19a47 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Fri, 22 Feb 2019 15:30:27 -0800 Subject: 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 --- src/main/scala/firrtl/annotations/Target.scala | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/main/scala/firrtl/annotations') 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) -- cgit v1.2.3