aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/Compiler.scala
diff options
context:
space:
mode:
authorSchuyler Eldridge2020-04-22 19:55:32 -0400
committerGitHub2020-04-22 19:55:32 -0400
commit65360f886f9b92438d1b6fe609120b34ebb413cf (patch)
tree073ebe73d43e652af1f71a08d34cc30a421c4dbb /src/main/scala/firrtl/Compiler.scala
parent8653fd628f83c1bcb329dd37844ddfdb8f4cf206 (diff)
parent184d40095179a9f49dd21e73e2c02b998bac5c00 (diff)
Merge pull request #1534 from freechipsproject/deprecate-transform-2
Trait-base Dependency API Migration
Diffstat (limited to 'src/main/scala/firrtl/Compiler.scala')
-rw-r--r--src/main/scala/firrtl/Compiler.scala99
1 files changed, 50 insertions, 49 deletions
diff --git a/src/main/scala/firrtl/Compiler.scala b/src/main/scala/firrtl/Compiler.scala
index d0e853f5..f80825d4 100644
--- a/src/main/scala/firrtl/Compiler.scala
+++ b/src/main/scala/firrtl/Compiler.scala
@@ -13,7 +13,7 @@ import firrtl.ir.Circuit
import firrtl.Utils.throwInternalError
import firrtl.annotations.transforms.{EliminateTargetPaths, ResolvePaths}
import firrtl.options.{DependencyAPI, Dependency, PreservesAll, StageUtils, TransformLike}
-import firrtl.stage.transforms.CatchCustomTransformExceptions
+import firrtl.stage.Forms
/** Container of all annotations for a Firrtl compiler */
class AnnotationSeq private (private[firrtl] val underlying: List[Annotation]) {
@@ -89,6 +89,8 @@ object CircuitState {
def apply(circuit: Circuit, form: CircuitForm): CircuitState = apply(circuit, form, Seq())
def apply(circuit: Circuit, form: CircuitForm, annotations: AnnotationSeq): CircuitState =
new CircuitState(circuit, form, annotations, None)
+ def apply(circuit: Circuit, annotations: AnnotationSeq): CircuitState =
+ new CircuitState(circuit, UnknownForm, annotations, None)
}
/** Current form of the Firrtl Circuit
@@ -100,7 +102,9 @@ object CircuitState {
* strictly supersets of the "lower" forms. Thus, that any transform that
* operates on [[HighForm]] can also operate on [[MidForm]] or [[LowForm]]
*/
-@deprecated("CircuitForm will be removed in 1.3. Switch to Seq[TransformDependency] to specify dependencies.", "1.2")
+@deprecated(
+ "Mix-in the DependencyAPIMigration trait into your Transform and specify its Dependency API dependencies. See: https://bit.ly/2Voppre",
+ "FIRRTL 1.3")
sealed abstract class CircuitForm(private val value: Int) extends Ordered[CircuitForm] {
// Note that value is used only to allow comparisons
def compare(that: CircuitForm): Int = this.value - that.value
@@ -119,7 +123,9 @@ sealed abstract class CircuitForm(private val value: Int) extends Ordered[Circui
*
* See [[CDefMemory]] and [[CDefMPort]]
*/
-@deprecated("Form-based dependencies will be removed in 1.3. Please migrate to the new Dependency API.", "1.2")
+@deprecated(
+ "Mix-in the DependencyAPIMigration trait into your Transform and specify its Dependency API dependencies. See: https://bit.ly/2Voppre",
+ "FIRRTL 1.3")
final case object ChirrtlForm extends CircuitForm(value = 3) {
val outputSuffix: String = ".fir"
}
@@ -131,7 +137,9 @@ final case object ChirrtlForm extends CircuitForm(value = 3) {
*
* Also see [[firrtl.ir]]
*/
-@deprecated("Form-based dependencies will be removed in 1.3. Please migrate to the new Dependency API.", "1.2")
+@deprecated(
+ "Mix-in the DependencyAPIMigration trait into your Transform and specify its Dependency API dependencies. See: https://bit.ly/2Voppre",
+ "FIRRTL 1.3")
final case object HighForm extends CircuitForm(2) {
val outputSuffix: String = ".hi.fir"
}
@@ -143,7 +151,9 @@ final case object HighForm extends CircuitForm(2) {
* - All whens must be removed
* - There can only be a single connection to any element
*/
-@deprecated("Form-based dependencies will be removed in 1.3. Please migrate to the new Dependency API.", "1.2")
+@deprecated(
+ "Mix-in the DependencyAPIMigration trait into your Transform and specify its Dependency API dependencies. See: https://bit.ly/2Voppre",
+ "FIRRTL 1.3")
final case object MidForm extends CircuitForm(1) {
val outputSuffix: String = ".mid.fir"
}
@@ -154,7 +164,9 @@ final case object MidForm extends CircuitForm(1) {
* - All aggregate types (vector/bundle) must have been removed
* - All implicit truncations must be made explicit
*/
-@deprecated("Form-based dependencies will be removed in 1.3. Please migrate to the new Dependency API.", "1.2")
+@deprecated(
+ "Mix-in the DependencyAPIMigration trait into your Transform and specify its Dependency API dependencies. See: https://bit.ly/2Voppre",
+ "FIRRTL 1.3")
final case object LowForm extends CircuitForm(0) {
val outputSuffix: String = ".lo.fir"
}
@@ -170,7 +182,9 @@ final case object LowForm extends CircuitForm(0) {
* TODO(azidar): Replace with PreviousForm, which more explicitly encodes
* this requirement.
*/
-@deprecated("Form-based dependencies will be removed in 1.3. Please migrate to the new Dependency API.", "1.2")
+@deprecated(
+ "Mix-in the DependencyAPIMigration trait into your Transform and specify its Dependency API dependencies. See: https://bit.ly/2Voppre",
+ "FIRRTL 1.3")
final case object UnknownForm extends CircuitForm(-1) {
override def compare(that: CircuitForm): Int = { sys.error("Illegal to compare UnknownForm"); 0 }
@@ -183,16 +197,17 @@ trait Transform extends TransformLike[CircuitState] with DependencyAPI[Transform
/** A convenience function useful for debugging and error messages */
def name: String = this.getClass.getName
+
/** The [[firrtl.CircuitForm]] that this transform requires to operate on */
@deprecated(
- "InputForm/OutputForm will be removed in 1.3. Use DependencyAPI methods (prerequisites, dependents, invalidates)",
- "1.2")
+ "Use Dependency API methods for equivalent functionality. See: https://bit.ly/2Voppre",
+ "FIRRTL 1.3")
def inputForm: CircuitForm
/** The [[firrtl.CircuitForm]] that this transform outputs */
@deprecated(
- "InputForm/OutputForm will be removed in 1.3. Use DependencyAPI methods (prerequisites, dependents, invalidates)",
- "1.2")
+ "Use Dependency API methods for equivalent functionality. See: https://bit.ly/2Voppre",
+ "FIRRTL 1.3")
def outputForm: CircuitForm
/** Perform the transform, encode renaming with RenameMap, and can
@@ -207,7 +222,6 @@ trait Transform extends TransformLike[CircuitState] with DependencyAPI[Transform
def transform(state: CircuitState): CircuitState = execute(state)
import firrtl.{ChirrtlForm => C, HighForm => H, MidForm => M, LowForm => L, UnknownForm => U}
- import firrtl.stage.Forms
override def prerequisites: Seq[Dependency[Transform]] = inputForm match {
case C => Nil
@@ -387,6 +401,7 @@ trait Emitter extends Transform with PreservesAll[Transform] {
def outputSuffix: String
}
+@deprecated("This will be removed in 1.4", "FIRRTL 1.3")
object CompilerUtils extends LazyLogging {
/** Generates a sequence of [[Transform]]s to lower a Firrtl circuit
*
@@ -394,7 +409,9 @@ object CompilerUtils extends LazyLogging {
* @param outputForm [[CircuitForm]] to lower to
* @return Sequence of transforms that will lower if outputForm is lower than inputForm
*/
- @deprecated("Use a TransformManager requesting which transforms you want to run. This will be removed in 1.3.", "1.2")
+ @deprecated(
+ "Use a TransformManager requesting which transforms you want to run. This will be removed in 1.4.",
+ "FIRRTL 1.3")
def getLoweringTransforms(inputForm: CircuitForm, outputForm: CircuitForm): Seq[Transform] = {
// If outputForm is equal-to or higher than inputForm, nothing to lower
if (outputForm >= inputForm) {
@@ -444,7 +461,9 @@ object CompilerUtils extends LazyLogging {
* inputForm of a latter transforms is equal to or lower than the outputForm
* of the previous transform.
*/
- @deprecated("Use a TransformManager with custom targets. This will be removed in 1.3.", "1.2")
+ @deprecated(
+ "Use a TransformManager requesting which transforms you want to run. This will be removed in 1.4.",
+ "FIRRTL 1.3")
def mergeTransforms(lowering: Seq[Transform], custom: Seq[Transform]): Seq[Transform] = {
custom
.sortWith{
@@ -463,8 +482,10 @@ object CompilerUtils extends LazyLogging {
}
-@deprecated("Use a TransformManager requesting which transforms you want to run. This will be removed in 1.3.", "1.2")
-trait Compiler extends LazyLogging {
+@deprecated(
+ "Migrate to firrtl.stage.transforms.Compiler. This will be removed in 1.4.",
+ "FIRRTL 1.3")
+trait Compiler extends Transform with DependencyAPIMigration {
def emitter: Emitter
/** The sequence of transforms this compiler will execute
@@ -473,26 +494,17 @@ trait Compiler extends LazyLogging {
*/
def transforms: Seq[Transform]
+ final override def execute(state: CircuitState): CircuitState =
+ new stage.transforms.Compiler (
+ targets = (transforms :+ emitter).map(Dependency.fromTransform),
+ currentState = prerequisites,
+ knownObjects = (transforms :+ emitter).toSet
+ ).execute(state)
+
require(transforms.size >= 1,
s"Compiler transforms for '${this.getClass.getName}' must have at least ONE Transform! " +
"Use IdentityTransform if you need an identity/no-op transform.")
- // Similar to (input|output)Form on [[Transform]] but derived from this Compiler's transforms
- def inputForm: CircuitForm = transforms.head.inputForm
- def outputForm: CircuitForm = transforms.last.outputForm
-
- private def transformsLegal(xforms: Seq[Transform]): Boolean =
- if (xforms.size < 2) {
- true
- } else {
- xforms.sliding(2, 1)
- .map { case Seq(p, n) => n.inputForm >= p.outputForm }
- .reduce(_ && _)
- }
-
- assert(transformsLegal(transforms),
- "Illegal Compiler, each transform must be able to accept the output of the previous transform!")
-
/** Perform compilation
*
* @param state The Firrtl AST to compile
@@ -537,23 +549,12 @@ trait Compiler extends LazyLogging {
* @return result of compilation
*/
def compile(state: CircuitState, customTransforms: Seq[Transform]): CircuitState = {
- val allTransforms = CompilerUtils.mergeTransforms(transforms, customTransforms)
-
- val (timeMillis, finalState) = Utils.time {
- allTransforms.foldLeft(state) { (in, xform) =>
- try {
- xform.runTransform(in)
- } catch {
- // Wrap exceptions from custom transforms so they are reported as such
- case e: Exception if CatchCustomTransformExceptions.isCustomTransform(xform) =>
- throw CustomTransformException(e)
- }
- }
- }
-
- logger.warn(f"Total FIRRTL Compile Time: $timeMillis%.1f ms")
-
- finalState
+ val transformManager = new stage.transforms.Compiler (
+ targets = (emitter +: customTransforms ++: transforms).map(Dependency.fromTransform),
+ currentState = prerequisites,
+ knownObjects = (transforms :+ emitter).toSet
+ )
+ transformManager.transform(state)
}
}