aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/Compiler.scala
diff options
context:
space:
mode:
authorAdam Izraelevitz2017-02-23 13:28:49 -0800
committerAdam Izraelevitz2017-03-06 16:48:15 -0800
commitb5ef5b876d4f4ad4a17bc81362b2264970272d63 (patch)
treed25820fb2e8c47caef2afc9ea4fc4f302feb156b /src/main/scala/firrtl/Compiler.scala
parent2370185a9ba231fe0349091eb7f0926b61b15853 (diff)
Addresses #459. Rewords transform annotations API.
Now, any annotation not propagated by a transform is considered deleted. A new DeletedAnnotation is added in place of it.
Diffstat (limited to 'src/main/scala/firrtl/Compiler.scala')
-rw-r--r--src/main/scala/firrtl/Compiler.scala50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/main/scala/firrtl/Compiler.scala b/src/main/scala/firrtl/Compiler.scala
index d1ca6320..780f5eb0 100644
--- a/src/main/scala/firrtl/Compiler.scala
+++ b/src/main/scala/firrtl/Compiler.scala
@@ -14,7 +14,7 @@ import Utils.throwInternalError
* RenameMap maps old names to modified names. Generated by transformations
* that modify names
*/
-case class RenameMap(map: Map[Named, Seq[Named]])
+case class RenameMap(map: Map[Named, Seq[Named]] = Map[Named, Seq[Named]]())
/**
* Container of all annotations for a Firrtl compiler.
@@ -153,7 +153,7 @@ abstract class PassBasedTransform extends Transform with PassBased {
def execute(state: CircuitState): CircuitState = {
require(state.form <= inputForm,
s"[$name]: Input form must be lower or equal to $inputForm. Got ${state.form}")
- CircuitState(runPasses(state.circuit), outputForm)
+ CircuitState(runPasses(state.circuit), outputForm, state.annotations)
}
}
@@ -231,8 +231,7 @@ object CompilerUtils {
}
-trait Compiler {
- // Emitter is still somewhat special because we want to make sure it is run last
+trait Compiler extends LazyLogging {
def emitter: Emitter
/** The sequence of transforms this compiler will execute
@@ -314,28 +313,31 @@ trait Compiler {
val finalState = allTransforms.foldLeft(state) { (in, xform) =>
val result = Utils.time(s"***${xform.name}***") { xform.execute(in) }
- // Annotation propagation
- // TODO: This should be redone
- val inAnnotationMap = in.annotations getOrElse AnnotationMap(Seq.empty)
- val remappedAnnotations: Seq[Annotation] = result.renames match {
- case Some(RenameMap(rmap)) =>
- // For each key in the rename map (rmap), obtain the
- // corresponding annotations (in.annotationMap.get(from)). If any
- // annotations exist, for each annotation, create a sequence of
- // annotations with the names in rmap's value.
- for {
- (oldName, newNames) <- rmap.toSeq
- oldAnno <- inAnnotationMap.get(oldName)
- newAnno <- oldAnno.update(newNames)
- } yield newAnno
- case _ => inAnnotationMap.annotations
+ val newAnnotations = {
+ val inSet = in.annotations.getOrElse(AnnotationMap(Seq.empty)).annotations.toSet
+ val resSet = result.annotations.getOrElse(AnnotationMap(Seq.empty)).annotations.toSet
+ val deleted = (inSet -- resSet).map {
+ case DeletedAnnotation(xFormName, delAnno) => DeletedAnnotation(s"${xFormName}+${xform.name}", delAnno)
+ case anno => DeletedAnnotation(xform.name, anno)
+ }
+ val created = resSet -- inSet
+ val unchanged = resSet & inSet
+ (deleted ++ created ++ unchanged)
}
- val resultAnnotations: Seq[Annotation] = result.annotations match {
- case None => Nil
- case Some(p) => p.annotations
+
+ // For each annotation, rename all annotations.
+ val renames = result.renames.getOrElse(RenameMap()).map
+ val remappedAnnotations: Seq[Annotation] = for {
+ anno <- newAnnotations.toSeq
+ newAnno <- anno.update(renames.getOrElse(anno.target, Seq(anno.target)))
+ } yield newAnno
+ logger.debug(s"*** ${xform.name} ***")
+ logger.debug(s"Form: ${result.form}")
+ logger.debug(result.circuit.serialize)
+ remappedAnnotations.foreach { a =>
+ logger.debug(a.serialize)
}
- val newAnnotations = AnnotationMap(remappedAnnotations ++ resultAnnotations)
- CircuitState(result.circuit, result.form, Some(newAnnotations))
+ CircuitState(result.circuit, result.form, Some(AnnotationMap(remappedAnnotations)))
}
finalState
}