From a713fdaf5214770dad7d3631bd1d500fd1f623bf Mon Sep 17 00:00:00 2001 From: Raffaele Meloni Date: Thu, 11 Jul 2024 20:48:00 +0200 Subject: [PATCH] Add circuit test with ChiselEnums --- .../TywavesAnnotationCircuits.scala | 46 +++++++++++++++++++ .../TypeAnnotationDataTypesSpec.scala | 11 +++++ 2 files changed, 57 insertions(+) diff --git a/src/test/scala/circtTests/tywavesTests/TywavesAnnotationCircuits.scala b/src/test/scala/circtTests/tywavesTests/TywavesAnnotationCircuits.scala index 58757ee1389..f5b38744b0a 100644 --- a/src/test/scala/circtTests/tywavesTests/TywavesAnnotationCircuits.scala +++ b/src/test/scala/circtTests/tywavesTests/TywavesAnnotationCircuits.scala @@ -313,6 +313,52 @@ object TywavesAnnotationCircuits { } } + + // Test enumeration + class TopCircuitChiselEnum extends RawModule { + object MyEnum extends ChiselEnum { + val A, B, C = Value + } + + object MyEnum2 extends ChiselEnum { + val D, E, F = Value + } + + object ScopeEnum { + object MyEnum2 extends ChiselEnum { + val D, E = Value + } + } + + val inputEnum = IO(Input(MyEnum())) + + val io = IO(Input(new Bundle { + val a = MyEnum() + val b = MyEnum2() + val c = Bool() + })) + + // So the enumVecAnnotation will have fields + val i = IO(Input(new Bundle { + val e = MyEnum() + val b = new Bundle { + val inner_e = ScopeEnum.MyEnum2() + val NOENUM = Bool() + val inner_ee = MyEnum() + val inner_b = new Bundle { + val inner_inner_e = MyEnum() + val inner_NOENUM = Bool() + val inner_ee = MyEnum2() + } + val v = Vec(3, MyEnum()) + } + val v = Vec(3, MyEnum()) + })) + + val vBundle = VecInit(i) + val v = IO(Input(Vec(3, MyEnum()))) + val vv = IO(Input(Vec(2, Vec(2, MyEnum())))) + } } object MemCircuits { diff --git a/src/test/scala/circtTests/tywavesTests/dataTypesTests/TypeAnnotationDataTypesSpec.scala b/src/test/scala/circtTests/tywavesTests/dataTypesTests/TypeAnnotationDataTypesSpec.scala index b6171f2f746..f6f520b1e3b 100644 --- a/src/test/scala/circtTests/tywavesTests/dataTypesTests/TypeAnnotationDataTypesSpec.scala +++ b/src/test/scala/circtTests/tywavesTests/dataTypesTests/TypeAnnotationDataTypesSpec.scala @@ -222,4 +222,15 @@ class TypeAnnotationDataTypesSpec extends AnyFunSpec with Matchers with chiselTe // format: on } } + + describe("Chisel enum Annotations") { + val targetDir = os.pwd / "test_run_dir" / "TywavesAnnotationSpec" / "Enum Values Annotations" + val args: Array[String] = Array("--target", "chirrtl", "--target-dir", targetDir.toString) + // format: off + it("should annotate chiselEnum") { + // ChiselEnums are already annotated, so simply emit a .fir file for firtool tests + new ChiselStage(true).execute(args, Seq(ChiselGeneratorAnnotation(() => new TopCircuitChiselEnum))) + // format: on + } + } }