33package chiselTests
44
55import chisel3 ._
6- import chisel3 .experimental .OpaqueType
6+ import chisel3 .experimental .{ OpaqueType , SourceInfo }
77import chisel3 .reflect .DataMirror
88import chisel3 .simulator .scalatest .ChiselSim
99import chisel3 .simulator .stimulus .RunUntilFinished
10+ import chisel3 .testing .scalatest .FileCheck
1011import chisel3 .util .{Counter , Queue }
1112import circt .stage .ChiselStage
1213import org .scalatest .flatspec .AnyFlatSpec
@@ -113,7 +114,7 @@ object RecordSpec {
113114 }
114115}
115116
116- class RecordSpec extends AnyFlatSpec with Matchers with ChiselSim {
117+ class RecordSpec extends AnyFlatSpec with Matchers with ChiselSim with FileCheck {
117118 import RecordSpec ._
118119
119120 behavior.of(" Records" )
@@ -127,11 +128,12 @@ class RecordSpec extends AnyFlatSpec with Matchers with ChiselSim {
127128 }
128129
129130 they should " emit FIRRTL bulk connects when possible" in {
130- val chirrtl = ChiselStage .emitCHIRRTL(
131- gen = new ConnectionTestModule (fooBarType, fooBarType)
131+ val chirrtl = ChiselStage .emitCHIRRTL(new ConnectionTestModule (fooBarType, fooBarType))
132+ chirrtl.fileCheck()(
133+ """ | CHECK: connect io.outMono, io.inMono
134+ | CHECK: connect io.outBi, io.inBi
135+ |""" .stripMargin
132136 )
133- chirrtl should include(" connect io.outMono, io.inMono @" )
134- chirrtl should include(" connect io.outBi, io.inBi @" )
135137 }
136138
137139 they should " not allow aliased fields" in {
@@ -170,10 +172,40 @@ class RecordSpec extends AnyFlatSpec with Matchers with ChiselSim {
170172 class MyRecord extends Record {
171173 lazy val elements = VectorMap (" sanitize me" -> UInt (8 .W ))
172174 }
173- val chirrtl = ChiselStage .emitCHIRRTL(new RawModule {
174- val out = IO (Output (new MyRecord ))
175- })
176- chirrtl should include(" output out : { sanitizeme : UInt<8>}" )
175+ ChiselStage
176+ .emitCHIRRTL(new RawModule {
177+ val out = IO (Output (new MyRecord ))
178+ })
179+ .fileCheck()(
180+ """ |CHECK: output out : { sanitizeme : UInt<8>}
181+ |""" .stripMargin
182+ )
183+ }
184+
185+ // This is not a great API but it enables the external FixedPoint library
186+ they should " support overriding _fromUInt" in {
187+ class MyRecord extends Record {
188+ val foo = UInt (8 .W )
189+ val elements = SeqMap (" foo" -> foo)
190+ override protected def _fromUInt (that : UInt )(implicit sourceInfo : SourceInfo ): Data = {
191+ val _w = Wire (this .cloneType)
192+ _w.foo := that ^ 0x55 .U (8 .W )
193+ _w
194+ }
195+ }
196+ ChiselStage
197+ .emitCHIRRTL(new RawModule {
198+ val in = IO (Input (UInt (8 .W )))
199+ val out = IO (Output (new MyRecord ))
200+ out := in.asTypeOf(new MyRecord )
201+ })
202+ .fileCheck()(
203+ """ |CHECK: wire [[wire:.*]] : { foo : UInt<8>}
204+ |CHECK: node [[node:.*]] = xor(in, UInt<8>(0h55))
205+ |CHECK: connect [[wire]].foo, [[node]]
206+ |CHECK: connect out, [[wire]]
207+ |""" .stripMargin
208+ )
177209 }
178210
179211 " Bulk connect on Record" should " check that the fields match" in {
0 commit comments