diff options
| author | Schuyler Eldridge | 2020-04-22 19:55:32 -0400 |
|---|---|---|
| committer | GitHub | 2020-04-22 19:55:32 -0400 |
| commit | 65360f886f9b92438d1b6fe609120b34ebb413cf (patch) | |
| tree | 073ebe73d43e652af1f71a08d34cc30a421c4dbb /src/main/scala/firrtl/options | |
| parent | 8653fd628f83c1bcb329dd37844ddfdb8f4cf206 (diff) | |
| parent | 184d40095179a9f49dd21e73e2c02b998bac5c00 (diff) | |
Merge pull request #1534 from freechipsproject/deprecate-transform-2
Trait-base Dependency API Migration
Diffstat (limited to 'src/main/scala/firrtl/options')
8 files changed, 44 insertions, 19 deletions
diff --git a/src/main/scala/firrtl/options/DependencyManager.scala b/src/main/scala/firrtl/options/DependencyManager.scala index 4880ab8f..537f87bd 100644 --- a/src/main/scala/firrtl/options/DependencyManager.scala +++ b/src/main/scala/firrtl/options/DependencyManager.scala @@ -20,9 +20,11 @@ case class DependencyManagerException(message: String, cause: Throwable = null) trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends TransformLike[A] with DependencyAPI[B] { import DependencyManagerUtils.CharSet - override lazy val prerequisites = currentState + override def prerequisites = currentState - override lazy val dependents = Seq.empty + override def dependents = Seq.empty + + override def optionalPrerequisites = Seq.empty override def invalidates(a: B): Boolean = (_currentState &~ _targets)(oToD(a)) @@ -114,7 +116,7 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends val edges = bfs( start = _targets &~ _currentState, blacklist = _currentState, - extractor = (p: B) => new LinkedHashSet[Dependency[B]]() ++ p.prerequisites &~ _currentState) + extractor = (p: B) => p._prerequisites &~ _currentState) DiGraph(edges) } @@ -123,7 +125,7 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends */ private lazy val dependentsGraph: DiGraph[B] = { val v = new LinkedHashSet() ++ prerequisiteGraph.getVertices - DiGraph(new LinkedHashMap() ++ v.map(vv => vv -> (v & (vv.dependents.toSet).map(dToO)))).reverse + DiGraph(new LinkedHashMap() ++ v.map(vv => vv -> (v & (vv._dependents).map(dToO)))).reverse } /** A directed graph of *optional* prerequisites. Each optional prerequisite is promoted to a full prerequisite if the @@ -131,7 +133,7 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends */ private lazy val optionalPrerequisitesGraph: DiGraph[B] = { val v = new LinkedHashSet() ++ prerequisiteGraph.getVertices - DiGraph(new LinkedHashMap() ++ v.map(vv => vv -> (v & (vv.optionalPrerequisites.toSet).map(dToO)))) + DiGraph(new LinkedHashMap() ++ v.map(vv => vv -> (v & (vv._optionalPrerequisites).map(dToO)))) } /** A directed graph consisting of prerequisites derived from ALL targets. This is necessary for defining targets for @@ -208,7 +210,7 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends /* [todo] Seq is inefficient here, but Array has ClassTag problems. Use something else? */ val (s, l) = sorted.foldLeft((_currentState, Seq[B]())){ case ((state, out), in) => /* The prerequisites are both prerequisites AND dependents. */ - val prereqs = new LinkedHashSet() ++ in.prerequisites ++ + val prereqs = in._prerequisites ++ dependencyGraph.getEdges(in).toSeq.map(oToD) ++ otherDependents.getEdges(in).toSeq.map(oToD) val preprocessing: Option[B] = { diff --git a/src/main/scala/firrtl/options/Phase.scala b/src/main/scala/firrtl/options/Phase.scala index 0e534ec8..847a4cf2 100644 --- a/src/main/scala/firrtl/options/Phase.scala +++ b/src/main/scala/firrtl/options/Phase.scala @@ -79,6 +79,29 @@ trait TransformLike[A] extends LazyLogging { } +/** Mix-in that makes a [[firrtl.options.TransformLike TransformLike]] guaranteed to be an identity function on some + * type. + * @tparam A the transformed type + */ +trait IdentityLike[A] { this: TransformLike[A] => + + /** The internal operation of this transform which, in order for this to be an identity function, must return nothing. + * @param a an input object + * @return nothing + */ + protected def internalTransform(a: A): Unit = Unit + + /** This method will execute `internalTransform` and then return the original input object + * @param a an input object + * @return the input object + */ + final override def transform(a: A): A = { + internalTransform(a) + a + } + +} + /** Mixin that defines dependencies between [[firrtl.options.TransformLike TransformLike]]s (hereafter referred to as * "transforms") * @@ -107,7 +130,7 @@ trait DependencyAPI[A <: DependencyAPI[A]] { this: TransformLike[_] => * $seqNote */ def optionalPrerequisites: Seq[Dependency[A]] = Seq.empty - private[options] lazy val _optionalPrerquisites: LinkedHashSet[Dependency[A]] = + private[options] lazy val _optionalPrerequisites: LinkedHashSet[Dependency[A]] = new LinkedHashSet() ++ optionalPrerequisites.toSet /** All transforms that must run ''after'' this transform diff --git a/src/main/scala/firrtl/options/phases/AddDefaults.scala b/src/main/scala/firrtl/options/phases/AddDefaults.scala index a327d930..034c502f 100644 --- a/src/main/scala/firrtl/options/phases/AddDefaults.scala +++ b/src/main/scala/firrtl/options/phases/AddDefaults.scala @@ -12,9 +12,9 @@ import firrtl.options.{Dependency, Phase, PreservesAll, TargetDirAnnotation} */ class AddDefaults extends Phase with PreservesAll[Phase] { - override val prerequisites = Seq(Dependency[GetIncludes], Dependency[ConvertLegacyAnnotations]) + override def prerequisites = Seq(Dependency[GetIncludes], Dependency[ConvertLegacyAnnotations]) - override val dependents = Seq.empty + override def dependents = Seq.empty def transform(annotations: AnnotationSeq): AnnotationSeq = { val td = annotations.collectFirst{ case a: TargetDirAnnotation => a}.isEmpty diff --git a/src/main/scala/firrtl/options/phases/Checks.scala b/src/main/scala/firrtl/options/phases/Checks.scala index 659247c9..69cbc7ed 100644 --- a/src/main/scala/firrtl/options/phases/Checks.scala +++ b/src/main/scala/firrtl/options/phases/Checks.scala @@ -12,9 +12,9 @@ import firrtl.options.Dependency */ class Checks extends Phase with PreservesAll[Phase] { - override val prerequisites = Seq(Dependency[GetIncludes], Dependency[ConvertLegacyAnnotations], Dependency[AddDefaults]) + override def prerequisites = Seq(Dependency[GetIncludes], Dependency[ConvertLegacyAnnotations], Dependency[AddDefaults]) - override val dependents = Seq.empty + override def dependents = Seq.empty /** Validate an [[AnnotationSeq]] for [[StageOptions]] * @throws OptionsException if annotations are invalid diff --git a/src/main/scala/firrtl/options/phases/ConvertLegacyAnnotations.scala b/src/main/scala/firrtl/options/phases/ConvertLegacyAnnotations.scala index a8e86a77..7611f66f 100644 --- a/src/main/scala/firrtl/options/phases/ConvertLegacyAnnotations.scala +++ b/src/main/scala/firrtl/options/phases/ConvertLegacyAnnotations.scala @@ -9,9 +9,9 @@ import firrtl.options.{Dependency, Phase, PreservesAll} /** Convert any [[firrtl.annotations.LegacyAnnotation LegacyAnnotation]]s to non-legacy variants */ class ConvertLegacyAnnotations extends Phase with PreservesAll[Phase] { - override val prerequisites = Seq(Dependency[GetIncludes]) + override def prerequisites = Seq(Dependency[GetIncludes]) - override val dependents = Seq.empty + override def dependents = Seq.empty def transform(annotations: AnnotationSeq): AnnotationSeq = LegacyAnnotation.convertLegacyAnnos(annotations) diff --git a/src/main/scala/firrtl/options/phases/DeletedWrapper.scala b/src/main/scala/firrtl/options/phases/DeletedWrapper.scala index 5374aa66..4a112172 100644 --- a/src/main/scala/firrtl/options/phases/DeletedWrapper.scala +++ b/src/main/scala/firrtl/options/phases/DeletedWrapper.scala @@ -15,9 +15,9 @@ import scala.collection.mutable class DeletedWrapper(p: Phase) extends Phase with Translator[AnnotationSeq, (AnnotationSeq, AnnotationSeq)] with PreservesAll[Phase] { - override val prerequisites = Seq.empty + override def prerequisites = Seq.empty - override val dependents = Seq.empty + override def dependents = Seq.empty override lazy val name: String = p.name diff --git a/src/main/scala/firrtl/options/phases/GetIncludes.scala b/src/main/scala/firrtl/options/phases/GetIncludes.scala index f6c02543..3b26795f 100644 --- a/src/main/scala/firrtl/options/phases/GetIncludes.scala +++ b/src/main/scala/firrtl/options/phases/GetIncludes.scala @@ -18,9 +18,9 @@ import scala.util.{Try, Failure} /** Recursively expand all [[InputAnnotationFileAnnotation]]s in an [[AnnotationSeq]] */ class GetIncludes extends Phase with PreservesAll[Phase] { - override val prerequisites = Seq.empty + override def prerequisites = Seq.empty - override val dependents = Seq.empty + override def dependents = Seq.empty /** Read all [[annotations.Annotation]] from a file in JSON or YAML format * @param filename a JSON or YAML file of [[annotations.Annotation]] diff --git a/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala b/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala index 4a638393..79769a81 100644 --- a/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala +++ b/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala @@ -14,13 +14,13 @@ import java.io.PrintWriter */ class WriteOutputAnnotations extends Phase with PreservesAll[Phase] { - override val prerequisites = + override def prerequisites = Seq( Dependency[GetIncludes], Dependency[ConvertLegacyAnnotations], Dependency[AddDefaults], Dependency[Checks] ) - override val dependents = Seq.empty + override def dependents = Seq.empty /** Write the input [[AnnotationSeq]] to a fie. */ def transform(annotations: AnnotationSeq): AnnotationSeq = { |
