aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/Compiler.scala
diff options
context:
space:
mode:
authorAdam Izraelevitz2016-05-26 15:50:45 -0700
committerazidar2016-07-27 14:18:06 -0700
commit90aa6f5187834e4eefe71accd020ae35cec4d734 (patch)
treef041e029dad21155b7cd3a7b380c7999bceb3ef8 /src/main/scala/firrtl/Compiler.scala
parent07149ac70cd4e3b5d5cc33a19736d34fcb3e6478 (diff)
Reworked annotation system. Added tenacity and permissibility
Conflicts: src/main/scala/firrtl/Compiler.scala src/main/scala/firrtl/LoweringCompilers.scala src/main/scala/firrtl/passes/Inline.scala src/test/scala/firrtlTests/AnnotationTests.scala src/test/scala/firrtlTests/InlineInstancesTests.scala
Diffstat (limited to 'src/main/scala/firrtl/Compiler.scala')
-rw-r--r--src/main/scala/firrtl/Compiler.scala83
1 files changed, 34 insertions, 49 deletions
diff --git a/src/main/scala/firrtl/Compiler.scala b/src/main/scala/firrtl/Compiler.scala
index 49bf9395..4bc60c00 100644
--- a/src/main/scala/firrtl/Compiler.scala
+++ b/src/main/scala/firrtl/Compiler.scala
@@ -28,79 +28,64 @@ MODIFICATIONS.
package firrtl
import com.typesafe.scalalogging.LazyLogging
+import scala.collection.mutable
import java.io.Writer
+import Annotations._
-import firrtl.ir._
-import Utils._
-import firrtl.passes._
-
-
-// ===========================================
-// Annotations
-// -------------------------------------------
-case class AnnotationException(message: String) extends Exception(message)
-trait Named { def name: String }
-case class ModuleName(name: String) extends Named
-case class ComponentName(name: String, module: ModuleName) extends Named
-
-// - Associated with an arbitrary serializable annotation
-trait Annotation {
- def serialize: String
-}
-
-// - Used to identify which annotation is consumed by which pass
-trait CircuitAnnotationKind
-case object UnknownCAKind extends CircuitAnnotationKind
-
-// - A collection of annotations on a given circuit
-// - Call update to keep annotations synced with circuit after
-// a transformation modifies module or component names
-trait CircuitAnnotation {
- def kind: CircuitAnnotationKind
- def update (renames: RenameMap): CircuitAnnotation
-}
-
-// - A class that contains a map from old name to modified names
-// - Generated by transformations that modify names
-trait RenameMap { def map: Map[Named, Seq[Named]] }
-case class BasicRenameMap(map: Map[Named,Seq[Named]]) extends RenameMap
-
+import firrtl.ir.Circuit
+/**
+ * RenameMap maps old names to modified names. Generated by transformations
+ * that modify names
+ */
+case class RenameMap(map: Map[Named, Seq[Named]])
// ===========================================
// Transforms
// -------------------------------------------
case class TransformResult (
- circuit: Circuit,
- renames: Option[RenameMap] = None,
- annotation: Option[CircuitAnnotation] = None)
+ circuit: Circuit,
+ renames: Option[RenameMap] = None,
+ annotation: Option[AnnotationMap] = None)
// - Transforms a circuit
// - Can consume multiple CircuitAnnotation's
trait Transform {
- def execute (circuit: Circuit, annotations: Seq[CircuitAnnotation]): TransformResult
+ def execute (circuit: Circuit, annotationMap: AnnotationMap): TransformResult
}
+
// ===========================================
// Compilers
// -------------------------------------------
-case class CompilerResult (circuit: Circuit, annotations: Seq[CircuitAnnotation])
+case class CompilerResult (circuit: Circuit, annotationMap: AnnotationMap)
// - A sequence of transformations
// - Call compile to executes each transformation in sequence onto
// a given circuit.
-trait Compiler extends LazyLogging {
+trait Compiler {
def transforms(w: Writer): Seq[Transform]
- def compile(circuit: Circuit, annotations: Seq[CircuitAnnotation], writer: Writer): CompilerResult = {
- transforms(writer).foldLeft(CompilerResult(circuit,annotations))((in: CompilerResult, xform: Transform) => {
- val result = xform.execute(in.circuit,in.annotations)
- val in_remapped = result.renames match {
- case Some(renames) => in.annotations.map(_.update(renames))
- case None => in.annotations
+ def compile(circuit: Circuit, annotationMap: AnnotationMap, writer: Writer): CompilerResult = {
+ transforms(writer).foldLeft(CompilerResult(circuit,annotationMap))((in: CompilerResult, xform: Transform) => {
+ val result = xform.execute(in.circuit,in.annotationMap)
+ 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
+ tID2OldAnnos <- in.annotationMap.get(oldName).toSeq
+ oldAnno <- tID2OldAnnos.values
+ newAnno <- oldAnno.update(newNames)
+ } yield newAnno
+ }
+ case _ => in.annotationMap.annotations
}
- val full_annotations = in_remapped ++ result.annotation
- CompilerResult(result.circuit,full_annotations)
+ val full_annotations = new AnnotationMap((remappedAnnotations ++ result.annotation.getOrElse(new AnnotationMap(Seq.empty)).annotations).toSeq)
+ CompilerResult(result.circuit, full_annotations)
})
}
}