11// See LICENSE for license details.
22package chisel3 .iotesters
33
4- import scala .collection .mutable .HashMap
5- import scala .util .Random
6- import java .io .{File , FileWriter , IOException , PrintStream , Writer }
4+ import java .io .{File , FileWriter , IOException , Writer }
75import java .nio .file .{FileAlreadyExistsException , Files , Paths }
86import java .nio .file .StandardCopyOption .REPLACE_EXISTING
97
108import chisel3 .{ChiselExecutionFailure , ChiselExecutionSuccess }
9+ import firrtl .{ChirrtlForm , CircuitState , Transform }
1110import firrtl .annotations .CircuitName
1211import firrtl .transforms .{BlackBoxSourceHelper , BlackBoxTargetDir }
1312
@@ -27,11 +26,10 @@ object copyVpiFiles {
2726 Files .createFile(vpiCppFilePath)
2827 Files .createFile(vpiTabFilePath)
2928 } catch {
30- case x : FileAlreadyExistsException =>
29+ case _ : FileAlreadyExistsException =>
3130 System .out.format(" " )
32- case x : IOException => {
31+ case x : IOException =>
3332 System .err.format(" createFile error: %s%n" , x)
34- }
3533 }
3634
3735 Files .copy(getClass.getResourceAsStream(" /sim_api.h" ), simApiHFilePath, REPLACE_EXISTING )
@@ -70,10 +68,10 @@ object genVCSVerilogHarness {
7068 writer write " reg [1023:0] vpdfile = 0;\n "
7169
7270 writer write " \n /*** DUT instantiation ***/\n "
73- writer write s " ${ dutName} ${ dutName} ( \n "
71+ writer write s " $dutName $ dutName( \n "
7472 writer write " .clock(clock),\n "
7573 writer write " .reset(reset),\n "
76- writer write ((inputs ++ outputs).unzip._2 map (name => s " . ${ name} ( ${name}_delay) " ) mkString " ,\n " )
74+ writer write ((inputs ++ outputs).unzip._2 map (name => s " . $name( ${name}_delay) " ) mkString " ,\n " )
7775 writer write " );\n\n "
7876
7977 writer write " initial begin\n "
@@ -112,7 +110,7 @@ object genVCSVerilogHarness {
112110 writer write " $vcdplusflush;\n "
113111 writer write " end\n\n "
114112 writer write " endmodule\n "
115- writer.close
113+ writer.close()
116114 }
117115}
118116
@@ -130,24 +128,31 @@ private[iotesters] object setupVCSBackend {
130128
131129 val chirrtl = firrtl.Parser .parse(emitted)
132130 val dut = getTopModule(circuit).asInstanceOf [T ]
133- val nodes = getChiselNodes(circuit)
134- val annotations = firrtl.AnnotationMap (optionsManager.firrtlOptions.annotations ++ List (
131+
132+ /*
133+ The following block adds an annotation that tells the black box helper where the
134+ current build directory is, so that it can copy verilog resource files into the right place
135+ */
136+ val annotationMap = firrtl.AnnotationMap (optionsManager.firrtlOptions.annotations ++ List (
135137 firrtl.annotations.Annotation (
136138 CircuitName (circuit.name),
137139 classOf [BlackBoxSourceHelper ],
138140 BlackBoxTargetDir (optionsManager.targetDirName).serialize
139141 )
140142 ))
141143
144+ val transforms = optionsManager.firrtlOptions.customTransforms
145+
142146 // Generate Verilog
143147 val verilogFile = new File (dir, s " ${circuit.name}.v " )
144148 val verilogWriter = new FileWriter (verilogFile)
145- val verilogCompiler = new firrtl.VerilogCompiler
146- verilogCompiler.compile(
147- firrtl.CircuitState (chirrtl, firrtl.ChirrtlForm , Some (annotations)),
148- verilogWriter,
149- optionsManager.firrtlOptions.customTransforms
149+
150+ val compileResult = (new firrtl.VerilogCompiler ).compileAndEmit(
151+ CircuitState (chirrtl, ChirrtlForm , Some (annotationMap)),
152+ customTransforms = transforms
150153 )
154+ val compiledStuff = compileResult.getEmittedCircuit
155+ verilogWriter.write(compiledStuff.value)
151156 verilogWriter.close()
152157
153158 // Generate Harness
@@ -160,8 +165,9 @@ private[iotesters] object setupVCSBackend {
160165
161166 val command = if (optionsManager.testerOptions.testCmd.nonEmpty) {
162167 optionsManager.testerOptions.testCmd
163- } else {
164- Seq (new File (dir, circuit.name).toString)
168+ }
169+ else {
170+ Seq (new File (dir, s " V ${circuit.name}" ).toString)
165171 }
166172
167173 (dut, new VCSBackend (dut, command))
0 commit comments