From ca7fd00eefa7c7037992919775bfff118cff623c Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Thu, 30 May 2024 08:52:25 -0700 Subject: [PATCH] Add test for FlatIO port ordering (#4113) (cherry picked from commit c3c997939b448b75b6db5cc684aba885ea2affa6) --- .../chiselTests/experimental/FlatIOSpec.scala | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/test/scala/chiselTests/experimental/FlatIOSpec.scala b/src/test/scala/chiselTests/experimental/FlatIOSpec.scala index ae38e17bb36..13e309e5a9b 100644 --- a/src/test/scala/chiselTests/experimental/FlatIOSpec.scala +++ b/src/test/scala/chiselTests/experimental/FlatIOSpec.scala @@ -6,9 +6,12 @@ import chisel3._ import chisel3.util.Valid import circt.stage.ChiselStage.emitCHIRRTL import chisel3.experimental.Analog -import chiselTests.ChiselFlatSpec +import chiselTests.{ChiselFlatSpec, MatchesAndOmits} +import chisel3.reflect.DataMirror +import scala.collection.immutable.SeqMap +import circt.stage.ChiselStage -class FlatIOSpec extends ChiselFlatSpec { +class FlatIOSpec extends ChiselFlatSpec with MatchesAndOmits { behavior.of("FlatIO") it should "create ports without a prefix" in { @@ -36,7 +39,7 @@ class FlatIOSpec extends ChiselFlatSpec { chirrtl should include("connect out.valid, valid") } - it should "dynamically indexing Vecs inside of FlatIOs" in { + it should "support dynamically indexing Vecs inside of FlatIOs" in { class MyModule extends RawModule { val io = FlatIO(new Bundle { val addr = Input(UInt(2.W)) @@ -76,4 +79,44 @@ class FlatIOSpec extends ChiselFlatSpec { chirrtl should include("output a : UInt<1>") chirrtl should include("output b : UInt<2>[2]") } + + it should "maintain port order for Bundles" in { + class MyBundle extends Bundle { + val foo = Bool() + val bar = Bool() + } + class MyModule extends Module { + val io = IO(Input(new MyBundle)) + } + class MyFlatIOModule extends Module { + val io = FlatIO(Input(new MyBundle)) + } + + matchesAndOmits( + ChiselStage.emitSystemVerilog(new MyModule) + )("io_foo,")("io_bar,") + + matchesAndOmits( + ChiselStage.emitSystemVerilog(new MyFlatIOModule) + )("foo,")("bar,") + } + + it should "maintain port order for Records" in { + class MyRecord extends Record { + val elements = SeqMap("foo" -> Bool(), "bar" -> Bool()) + } + class MyModule extends Module { + val io = IO(Input(new MyRecord)) + } + class MyFlatIOModule extends Module { + val io = FlatIO(Input(new MyRecord)) + } + matchesAndOmits( + ChiselStage.emitSystemVerilog(new MyModule) + )("io_bar,")("io_foo,") + matchesAndOmits( + ChiselStage.emitSystemVerilog(new MyFlatIOModule) + )("bar,")("foo,") + } + }