44import chisel3 ._
55
66import org .scalatest ._
7+ import chiseltest ._
8+ import chiseltest .simulator .SimulatorDebugAnnotation
9+ import chiseltest .simulator .VerilatorFlags
10+ import org .scalatest .flatspec .AnyFlatSpec
711
812import chisel3 ._
913import chisel3 .util ._
@@ -13,6 +17,7 @@ import scopt.OParser
1317import System .err
1418import scopt .RenderingMode
1519import scala .collection .immutable .SeqMap
20+ import java .nio .file .Paths
1621
1722object Routes extends Enumeration {
1823 type Routes = Value
@@ -44,14 +49,15 @@ class BusesVec(singleElementWidth: Int, width: Int, height: Int)
4449 def asSeq : Seq [Vec [UInt ]] = routes.map(_._2).toSeq
4550}
4651
52+ class MockArrayBundle (width : Int , height : Int , singleElementWidth : Int ) extends Bundle {
53+ val ins = Input (new BusesVec (singleElementWidth, width, height))
54+ val outs = Output (new BusesVec (singleElementWidth, width, height))
55+ val lsbs = Output (Vec (width * height, Bool ()))
56+ }
57+
4758class MockArray (width : Int , height : Int , singleElementWidth : Int )
4859 extends Module {
49- val io = IO (new Bundle {
50- val ins = Input (new BusesVec (singleElementWidth, width, height))
51- val outs = Output (new BusesVec (singleElementWidth, width, height))
52-
53- val lsbs = Output (Vec (width * height, Bool ()))
54- })
60+ val io = IO (new MockArrayBundle (width, height, singleElementWidth))
5561
5662 class Element extends Module {
5763 val io =
@@ -147,49 +153,118 @@ case class ArrayConfig(
147153 remainingArgs : Seq [String ] = Seq .empty
148154)
149155
150- object GenerateMockArray extends App {
156+ class MockArrayPostSynthesis (width: Int , height: Int , singleElementWidth: Int )
157+ extends BlackBox with HasBlackBoxPath {
158+ override def desiredName = " MockArray"
159+ val io = IO (new Bundle {
160+ val clock = Input (Clock ())
161+ val reset = Input (Bool ())
162+ val io = new MockArrayBundle (width, height, singleElementWidth)
163+ })
164+ val platformDir = sys.env.getOrElse(" PLATFORM_DIR" , " defaultPath" ) + " /verilog/stdcell/"
165+ (Seq (" asap7sc7p5t_AO_RVT_TT_201020.v" ,
166+ " dff.v" ,
167+ " asap7sc7p5t_SIMPLE_RVT_TT_201020.v" ,
168+ " asap7sc7p5t_INVBUF_RVT_TT_201020.v" ,
169+ " empty.v" ).map(p=> Paths .get(platformDir + p)) ++
170+ Seq (
171+ " MockArrayFinal.v" ,
172+ " MockArrayElementFinal.v" ).map(p=> Paths .get(" post/" + p)))
173+ .foreach(p=> addPath(p.toAbsolutePath().toString()))
174+ }
151175
152- val builder = OParser .builder[ArrayConfig ]
153- val parser = {
154- import builder ._
155- OParser .sequence(
156- programName(" my-program" ),
157- opt[Int ]('w' , " width" )
158- .required()
159- .valueName(" Array width" )
160- .action((width, c) => c.copy(width = width))
161- .text(" input file is required" ),
162- opt[Int ]('h' , " height" )
163- .required()
164- .valueName(" height" )
165- .action((height, c) => c.copy(height = height))
166- .text(" Array height" ),
167- opt[Int ]('d' , " dataWidth" )
168- .required()
169- .valueName(" dataWidth" )
170- .action((dataWidth, c) => c.copy(dataWidth = dataWidth))
171- .text(" data path width" )
172- )
176+ class MockArrayTestbench (width: Int , height: Int , singleElementWidth: Int ) extends Module {
177+ val io = IO (new MockArrayBundle (width, height, singleElementWidth))
178+ val postSynthesis = Module (new MockArrayPostSynthesis (width, height, singleElementWidth))
179+ postSynthesis.io.io <> io
180+ postSynthesis.io.reset := reset.asBool
181+ postSynthesis.io.clock := clock
182+ }
183+
184+
185+ class MockArrayTest (width: Int , height: Int , singleElementWidth: Int ) extends AnyFlatSpec with ChiselScalatestTester {
186+ behavior of " MockArray"
187+
188+ it should " Wiggle some wires" in {
189+ // find full path foo.v in scala/src/resources
190+ test(new MockArrayTestbench (width, height, singleElementWidth)).
191+ withAnnotations(Seq (WriteVcdAnnotation ,
192+ VerilatorBackendAnnotation ,
193+ SimulatorDebugAnnotation ,
194+ // DD flip flops use UDP Tables, unsupported by Verilator
195+ VerilatorFlags (Seq ())
196+ )) { dut =>
197+ for (j <- 0 until 5 ) {
198+ dut.io.ins.routes.foreach { case (route, vec) =>
199+ vec.zipWithIndex.foreach { case (wire, i) =>
200+ wire.poke((i+ j).U )
201+ dut.clock.step(1 )
202+ }
203+ }
204+ }
205+ }
173206 }
207+ }
208+
209+
210+ object parse {
211+ def apply (args: Array [String ]) : (ArrayConfig , Array [String ]) = {
212+ val builder = OParser .builder[ArrayConfig ]
213+ val parser = {
214+ import builder ._
215+ OParser .sequence(
216+ programName(" my-program" ),
217+ opt[Int ]('w' , " width" )
218+ .required()
219+ .valueName(" Array width" )
220+ .action((width, c) => c.copy(width = width))
221+ .text(" input file is required" ),
222+ opt[Int ]('h' , " height" )
223+ .required()
224+ .valueName(" height" )
225+ .action((height, c) => c.copy(height = height))
226+ .text(" Array height" ),
227+ opt[Int ]('d' , " dataWidth" )
228+ .required()
229+ .valueName(" dataWidth" )
230+ .action((dataWidth, c) => c.copy(dataWidth = dataWidth))
231+ .text(" data path width" )
232+ )
233+ }
234+
235+ val (configArgs, afterDelimiter) = args.span(_ != " --" )
236+ val chiselArgs = afterDelimiter.drop(1 )
174237
175- val (configArgs, afterDelimiter) = args.span(_ != " --" )
176- val chiselArgs = afterDelimiter.drop(1 )
177-
178- OParser .parse(parser, configArgs, ArrayConfig ()) match {
179- case Some (c) =>
180- new ChiselStage ()
181- .execute(
182- chiselArgs,
183- Seq (
184- ChiselGeneratorAnnotation (() =>
185- new MockArray (c.width, c.height, c.dataWidth)
186- )
187- )
188- )
189238
190- case _ =>
191- // arguments are invalid
192- OParser .usage(parser, RenderingMode .TwoColumns )
193- sys.exit(1 )
239+
240+ OParser .parse(parser, configArgs, ArrayConfig ()) match {
241+ case Some (c) =>
242+ return (c, chiselArgs)
243+
244+ case _ =>
245+ // arguments are invalid
246+ OParser .usage(parser, RenderingMode .TwoColumns )
247+ sys.exit(1 )
248+ }
194249 }
250+
251+ }
252+
253+ object GenerateMockArray extends App {
254+ val (c, chiselArgs) = parse(args)
255+
256+ new ChiselStage ()
257+ .execute(
258+ chiselArgs,
259+ Seq (
260+ ChiselGeneratorAnnotation (() =>
261+ new MockArray (c.width, c.height, c.dataWidth)
262+ )
263+ )
264+ )
265+ }
266+
267+ object SimulatePostSynthesis extends App {
268+ val (c, chiselArgs) = parse(args)
269+ new MockArrayTest (c.width, c.height, c.dataWidth).execute()
195270}
0 commit comments