aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtlTests/PassTests.scala
diff options
context:
space:
mode:
authorAdam Izraelevitz2016-05-02 14:59:51 -0700
committerjackkoenig2016-05-12 22:42:06 -0700
commitf07baed2bc46e107250c317f290af48747a98322 (patch)
treea63c5d2477eabccab85dc6780f289fc24cbcad5c /src/test/scala/firrtlTests/PassTests.scala
parent0ee659e85c7fe46c2678a49866ef1eca8f4a2c65 (diff)
Restructured Compiler to use Transforms. Added an InlineInstance pass.
Transforms are new unit of modularity within the compiler.
Diffstat (limited to 'src/test/scala/firrtlTests/PassTests.scala')
-rw-r--r--src/test/scala/firrtlTests/PassTests.scala82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/test/scala/firrtlTests/PassTests.scala b/src/test/scala/firrtlTests/PassTests.scala
new file mode 100644
index 00000000..38ecc7c3
--- /dev/null
+++ b/src/test/scala/firrtlTests/PassTests.scala
@@ -0,0 +1,82 @@
+package firrtlTests
+
+import com.typesafe.scalalogging.LazyLogging
+import java.io.{StringWriter,Writer}
+import org.scalatest.{FlatSpec, Matchers}
+import org.scalatest.junit.JUnitRunner
+import firrtl.{Parser,Circuit,FIRRTLEmitter}
+import firrtl.Parser.IgnoreInfo
+import firrtl.passes.{Pass, PassExceptions}
+import firrtl.{
+ Transform,
+ CircuitAnnotation,
+ TransformResult,
+ SimpleRun,
+ Chisel3ToHighFirrtl,
+ IRToWorkingIR,
+ ResolveAndCheck,
+ HighFirrtlToMiddleFirrtl,
+ MiddleFirrtlToLowFirrtl,
+ EmitFirrtl,
+ Compiler
+}
+
+
+// An example methodology for testing Firrtl Passes
+// Spec class should extend this class
+abstract class SimpleTransformSpec extends FlatSpec with Matchers with Compiler with LazyLogging {
+ // Utility function
+ def parse(s: String): Circuit = Parser.parse(s.split("\n").toIterator, infoMode = IgnoreInfo)
+
+ // Executes the test. Call in tests.
+ def execute(writer: Writer, annotations: Seq[CircuitAnnotation], input: String, check: String) = {
+ compile(parse(input), annotations, writer)
+ logger.debug(writer.toString)
+ logger.debug(check)
+ (parse(writer.toString)) should be (parse(check))
+ }
+ // Executes the test, should throw an error
+ def failingexecute(writer: Writer, annotations: Seq[CircuitAnnotation], input: String) = {
+ intercept[PassExceptions] {
+ compile(parse(input), annotations, writer)
+ }
+ }
+}
+
+trait LowTransformSpec extends SimpleTransformSpec {
+ def transform: Transform
+ def transforms (writer: Writer) = Seq(
+ new Chisel3ToHighFirrtl(),
+ new IRToWorkingIR(),
+ new ResolveAndCheck(),
+ new HighFirrtlToMiddleFirrtl(),
+ new MiddleFirrtlToLowFirrtl(),
+ new ResolveAndCheck(),
+ transform,
+ new EmitFirrtl(writer)
+ )
+}
+
+trait MiddleTransformSpec extends SimpleTransformSpec {
+ def transform: Transform
+ def transforms (writer: Writer) = Seq(
+ new Chisel3ToHighFirrtl(),
+ new IRToWorkingIR(),
+ new ResolveAndCheck(),
+ new HighFirrtlToMiddleFirrtl(),
+ new ResolveAndCheck(),
+ transform,
+ new EmitFirrtl(writer)
+ )
+}
+
+trait HighTransformSpec extends SimpleTransformSpec {
+ def transform: Transform
+ def transforms (writer: Writer) = Seq(
+ new Chisel3ToHighFirrtl(),
+ new IRToWorkingIR(),
+ new ResolveAndCheck(),
+ transform,
+ new EmitFirrtl(writer)
+ )
+}