From f11a0f03511c6380faec7f012eb1314007ca4823 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Wed, 19 Dec 2018 16:50:01 -0500 Subject: Add IdentityTransform This adds an identity transform that applies an identity function to some CircuitState, i.e., it just returns the original CircuitState. This is useful for transform generators that may, for edge cases, generate an empty transform sequence. Other classes (e.g., Compiler) have explicit or implicit requirements that a transform sequence is non-empty. Signed-off-by: Schuyler Eldridge --- .../scala/firrtl/transforms/IdentityTransform.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/scala/firrtl/transforms/IdentityTransform.scala (limited to 'src') diff --git a/src/main/scala/firrtl/transforms/IdentityTransform.scala b/src/main/scala/firrtl/transforms/IdentityTransform.scala new file mode 100644 index 00000000..a39ca4b7 --- /dev/null +++ b/src/main/scala/firrtl/transforms/IdentityTransform.scala @@ -0,0 +1,17 @@ +// See LICENSE for license details. + +package firrtl.transforms + +import firrtl.{CircuitForm, CircuitState, Transform} + +/** Transform that applies an identity function. This returns an unmodified [[CircuitState]]. + * @param form the input and output [[CircuitForm]] + */ +class IdentityTransform(form: CircuitForm) extends Transform { + + final override def inputForm: CircuitForm = form + final override def outputForm: CircuitForm = form + + final def execute(state: CircuitState): CircuitState = state + +} -- cgit v1.2.3 From 0cfd0eb27d2b92796c3173e5a34d8f4e954b2911 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Wed, 19 Dec 2018 16:51:58 -0500 Subject: Use IdentityTransform to construct NoneCompiler This changes the NoneCompiler to be a unary sequence consisting of an IdentityTransform. This fixes the inputForm and outputForm inherited methods that implicitly mandate a non-empty transform sequence. Signed-off-by: Schuyler Eldridge --- src/main/scala/firrtl/LoweringCompilers.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/scala/firrtl/LoweringCompilers.scala b/src/main/scala/firrtl/LoweringCompilers.scala index 350fd433..eab928c2 100644 --- a/src/main/scala/firrtl/LoweringCompilers.scala +++ b/src/main/scala/firrtl/LoweringCompilers.scala @@ -2,6 +2,8 @@ package firrtl +import firrtl.transforms.IdentityTransform + sealed abstract class CoreTransform extends SeqTransform /** This transforms "CHIRRTL", the chisel3 IR, to "Firrtl". Note the resulting @@ -132,7 +134,7 @@ import firrtl.transforms.BlackBoxSourceHelper */ class NoneCompiler extends Compiler { def emitter = new ChirrtlEmitter - def transforms: Seq[Transform] = Seq.empty + def transforms: Seq[Transform] = Seq(new IdentityTransform(ChirrtlForm)) } /** Emits input circuit -- cgit v1.2.3 From c727961ca6461d90858c4c66d8b01897293fc0ab Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Wed, 19 Dec 2018 16:48:10 -0500 Subject: Require transforms.size >= 1 for Compilers This adds a requirement that all Compilers must have at least one Transform. Without this, there is no way to determine the inputForm or outputForm of a given compiler as these are (rightly) defined in terms of the head/last transform. Signed-off-by: Schuyler Eldridge --- src/main/scala/firrtl/Compiler.scala | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/main/scala/firrtl/Compiler.scala b/src/main/scala/firrtl/Compiler.scala index 80ba42c4..87662800 100644 --- a/src/main/scala/firrtl/Compiler.scala +++ b/src/main/scala/firrtl/Compiler.scala @@ -373,6 +373,10 @@ trait Compiler extends LazyLogging { */ def transforms: Seq[Transform] + 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 -- cgit v1.2.3