aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/Compiler.scala
diff options
context:
space:
mode:
authorDonggyu2016-09-15 11:01:30 -0700
committerGitHub2016-09-15 11:01:30 -0700
commit30ae710af4b8882fa1cab449cc9cff08686a6c70 (patch)
treef0f26ef08024f58503e53d82ca710d8facb77f78 /src/main/scala/firrtl/Compiler.scala
parent92c31ab4ff941289b6f5c79a06f00907bb32c638 (diff)
parent10648a3bffa1f863f787e7a602e63b851b1b9d86 (diff)
Merge pull request #302 from ucb-bar/fix_more_styles
Style Fixes for Compiler, LoweringCompiler, WIR
Diffstat (limited to 'src/main/scala/firrtl/Compiler.scala')
-rw-r--r--src/main/scala/firrtl/Compiler.scala54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/main/scala/firrtl/Compiler.scala b/src/main/scala/firrtl/Compiler.scala
index 4bc60c00..f566544e 100644
--- a/src/main/scala/firrtl/Compiler.scala
+++ b/src/main/scala/firrtl/Compiler.scala
@@ -43,7 +43,7 @@ case class RenameMap(map: Map[Named, Seq[Named]])
// Transforms
// -------------------------------------------
-case class TransformResult (
+case class TransformResult(
circuit: Circuit,
renames: Option[RenameMap] = None,
annotation: Option[AnnotationMap] = None)
@@ -51,7 +51,7 @@ case class TransformResult (
// - Transforms a circuit
// - Can consume multiple CircuitAnnotation's
trait Transform {
- def execute (circuit: Circuit, annotationMap: AnnotationMap): TransformResult
+ def execute(circuit: Circuit, annotationMap: AnnotationMap): TransformResult
}
@@ -59,34 +59,36 @@ trait Transform {
// Compilers
// -------------------------------------------
-case class CompilerResult (circuit: Circuit, annotationMap: AnnotationMap)
+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 {
- def transforms(w: Writer): Seq[Transform]
- 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 = new AnnotationMap((remappedAnnotations ++ result.annotation.getOrElse(new AnnotationMap(Seq.empty)).annotations).toSeq)
- CompilerResult(result.circuit, full_annotations)
- })
- }
+ def transforms(w: Writer): Seq[Transform]
+ def compile(circuit: Circuit, annotationMap: AnnotationMap, writer: Writer): CompilerResult =
+ (transforms(writer) foldLeft CompilerResult(circuit, annotationMap)){ (in, xform) =>
+ 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 resultAnnotations: Seq[Annotation] = result.annotation match {
+ case None => Nil
+ case Some(p) => p.annotations
+ }
+ CompilerResult(result.circuit,
+ new AnnotationMap(remappedAnnotations ++ resultAnnotations))
+ }
}