diff --git a/lit/tests/CompilerPlugin/WithCompilerPlugin.sc b/lit/tests/CompilerPlugin/WithCompilerPlugin.sc new file mode 100644 index 00000000000..fda84c9c5fd --- /dev/null +++ b/lit/tests/CompilerPlugin/WithCompilerPlugin.sc @@ -0,0 +1,16 @@ +// RUN: scala-cli --server=false --java-home=%JAVAHOME --extra-jars=%RUNCLASSPATH --scala-version=%SCALAVERSION --scala-option="-Xplugin:%SCALAPLUGINJARS" --java-opt="--enable-native-access=ALL-UNNAMED --enable-preview -Djava.library.path=%JAVALIBRARYPATH" %s | FileCheck %s + +import chisel3._ +import circt.stage.ChiselStage +class FooBundle extends Bundle { + val foo = Input(UInt(3.W)) +} +// CHECK-LABEL: module FooModule +// CHECK: input clock : Clock +// CHECK: input reset : UInt<1> +class FooModule extends Module { + // CHECK: output io : { flip foo : UInt<3>} + val io = IO(new FooBundle) + // CHECK: skip +} +println(ChiselStage.emitCHIRRTL(new FooModule)) diff --git a/lit/tests/CompilerPlugin/WithoutCompilerPlugin.sc b/lit/tests/CompilerPlugin/WithoutCompilerPlugin.sc new file mode 100644 index 00000000000..44fbfde3888 --- /dev/null +++ b/lit/tests/CompilerPlugin/WithoutCompilerPlugin.sc @@ -0,0 +1,12 @@ +// RUN: not scala-cli --server=false --java-home=%JAVAHOME --extra-jars=%RUNCLASSPATH --scala-version=%SCALAVERSION --java-opt="--enable-native-access=ALL-UNNAMED --enable-preview -Djava.library.path=%JAVALIBRARYPATH" %s 2>&1 | FileCheck %s + +import chisel3._ +import circt.stage.ChiselStage +class FooBundle extends Bundle { + val foo = Input(UInt(3.W)) +} +class FooModule extends Module { + // CHECK: assertion failed: The Chisel compiler plugin is now required for compiling Chisel code. + val io = IO(new FooBundle) +} +println(ChiselStage.emitCHIRRTL(new FooModule)) diff --git a/lit/tests/lit.cfg.py b/lit/tests/lit.cfg.py new file mode 100644 index 00000000000..c4c4e23c34a --- /dev/null +++ b/lit/tests/lit.cfg.py @@ -0,0 +1,16 @@ +import platform +import lit.formats +from lit.llvm import llvm_config +from lit.llvm.subst import ToolSubst + +config.name = 'CHISEL' +config.test_format = lit.formats.ShTest(True) +config.suffixes = [".sc"] +config.substitutions = [ + ('%SCALAVERSION', config.scala_version), + ('%RUNCLASSPATH', ':'.join(config.run_classpath)), + ('%SCALAPLUGINJARS', ':'.join(config.scala_plugin_jars)), + ('%JAVAHOME', config.java_home), + ('%JAVALIBRARYPATH', ':'.join(config.java_library_path)) +] +config.test_source_root = os.path.dirname(__file__) diff --git a/lit/tests/lit.site.cfg.py.in b/lit/tests/lit.site.cfg.py.in new file mode 100644 index 00000000000..c08dbeb6ee2 --- /dev/null +++ b/lit/tests/lit.site.cfg.py.in @@ -0,0 +1,9 @@ +import sys +config.scala_version = "@SCALA_VERSION@" +config.run_classpath = "@RUN_CLASSPATH@".split(",") +config.scala_plugin_jars = "@SCALA_PLUGIN_JARS@".split(",") +config.java_home = "@JAVA_HOME@" +config.java_library_path = "@JAVA_LIBRARY_PATH@".split(",") +config.chisel_lit_dir = "@CHISEL_LIT_DIR@".split(",") +config.test_exec_root = os.path.dirname(__file__) +lit_config.load_config(config, "@CHISEL_LIT_DIR@/tests/lit.cfg.py") diff --git a/lit/utility/src/package.scala b/lit/utility/src/package.scala new file mode 100644 index 00000000000..03e63ea52bb --- /dev/null +++ b/lit/utility/src/package.scala @@ -0,0 +1,23 @@ +import chisel3._ + +package object utility { + object binding { + def streamString(module: => RawModule, stream: chisel3.internal.CIRCTConverter => geny.Writable): String = Seq( + new chisel3.stage.phases.Elaborate, + chisel3.internal.panama.Convert + ).foldLeft( + firrtl.AnnotationSeq(Seq(chisel3.stage.ChiselGeneratorAnnotation(() => module))) + ) { case (annos, phase) => phase.transform(annos) } + .collectFirst { + case chisel3.internal.panama.circt.PanamaCIRCTConverterAnnotation(converter) => + val string = new java.io.ByteArrayOutputStream + stream(converter).writeBytesTo(string) + new String(string.toByteArray) + } + .get + + def firrtlString(module: => RawModule): String = streamString(module, _.firrtlStream) + + def verilogString(module: => RawModule): String = streamString(module, _.verilogStream) + } +} \ No newline at end of file