From aecb59bb02a969708d1b7f88352d1d1a566cfdeb Mon Sep 17 00:00:00 2001 From: ducky Date: Thu, 30 Mar 2017 13:19:37 -0700 Subject: [PATCH] Allow top-level RawModule --- src/main/scala/chisel3/Driver.scala | 11 ++++++----- src/test/scala/chiselTests/ChiselSpec.scala | 7 ++++--- src/test/scala/chiselTests/RawModuleSpec.scala | 4 ++++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/scala/chisel3/Driver.scala b/src/main/scala/chisel3/Driver.scala index b2acc946509..8a2256dfb49 100644 --- a/src/main/scala/chisel3/Driver.scala +++ b/src/main/scala/chisel3/Driver.scala @@ -3,6 +3,7 @@ package chisel3 import chisel3.internal.firrtl.Emitter +import chisel3.experimental.RawModule import java.io._ import net.jcazevedo.moultingyaml._ @@ -88,11 +89,11 @@ object Driver extends BackendCompilationUtilities { * @param gen a function that creates a Module hierarchy * @return the resulting Chisel IR in the form of a Circuit (TODO: Should be FIRRTL IR) */ - def elaborate[T <: Module](gen: () => T): Circuit = internal.Builder.build(Module(gen())) + def elaborate[T <: RawModule](gen: () => T): Circuit = internal.Builder.build(Module(gen())) - def emit[T <: Module](gen: () => T): String = Emitter.emit(elaborate(gen)) + def emit[T <: RawModule](gen: () => T): String = Emitter.emit(elaborate(gen)) - def emit[T <: Module](ir: Circuit): String = Emitter.emit(ir) + def emit[T <: RawModule](ir: Circuit): String = Emitter.emit(ir) def dumpFirrtl(ir: Circuit, optName: Option[File]): File = { val f = optName.getOrElse(new File(ir.name + ".fir")) @@ -122,7 +123,7 @@ object Driver extends BackendCompilationUtilities { */ def execute( optionsManager: ExecutionOptionsManager with HasChiselExecutionOptions with HasFirrtlOptions, - dut: () => Module): ChiselExecutionResult = { + dut: () => RawModule): ChiselExecutionResult = { val circuit = elaborate(dut) // this little hack let's us set the topName with the circuit name if it has not been set from args @@ -173,7 +174,7 @@ object Driver extends BackendCompilationUtilities { * @param dut The device under test * @return An execution result with useful stuff, or failure with message */ - def execute(args: Array[String], dut: () => Module): ChiselExecutionResult = { + def execute(args: Array[String], dut: () => RawModule): ChiselExecutionResult = { val optionsManager = new ExecutionOptionsManager("chisel3") with HasChiselExecutionOptions with HasFirrtlOptions optionsManager.parse(args) match { diff --git a/src/test/scala/chiselTests/ChiselSpec.scala b/src/test/scala/chiselTests/ChiselSpec.scala index 584f134c37a..143a14950bf 100644 --- a/src/test/scala/chiselTests/ChiselSpec.scala +++ b/src/test/scala/chiselTests/ChiselSpec.scala @@ -7,6 +7,7 @@ import org.scalatest._ import org.scalatest.prop._ import org.scalacheck._ import chisel3._ +import chisel3.experimental.RawModule import chisel3.testers._ import firrtl.{ CommonOptions, @@ -27,21 +28,21 @@ trait ChiselRunners extends Assertions { def assertTesterFails(t: => BasicTester, additionalVResources: Seq[String] = Seq()): Unit = { assert(!runTester(t, additionalVResources)) } - def elaborate(t: => Module): Unit = Driver.elaborate(() => t) + def elaborate(t: => RawModule): Unit = Driver.elaborate(() => t) /** Given a generator, return the Firrtl that it generates. * * @param t Module generator * @return Firrtl representation as a String */ - def generateFirrtl(t: => Module): String = Driver.emit(() => t) + def generateFirrtl(t: => RawModule): String = Driver.emit(() => t) /** Compiles a Chisel Module to Verilog * NOTE: This uses the "test_run_dir" as the default directory for generated code. * @param t the generator for the module * @return the Verilog code as a string. */ - def compile(t: => Module): String = { + def compile(t: => RawModule): String = { val manager = new ExecutionOptionsManager("compile") with HasFirrtlOptions with HasChiselExecutionOptions { commonOptions = CommonOptions(targetDirName = "test_run_dir") diff --git a/src/test/scala/chiselTests/RawModuleSpec.scala b/src/test/scala/chiselTests/RawModuleSpec.scala index 66d9c89e5a0..180a1c0459c 100644 --- a/src/test/scala/chiselTests/RawModuleSpec.scala +++ b/src/test/scala/chiselTests/RawModuleSpec.scala @@ -51,6 +51,10 @@ class ImplicitModuleInRawModuleTester extends BasicTester { } class RawModuleSpec extends ChiselFlatSpec { + "RawModule" should "elaborate" in { + elaborate { new RawModuleWithImpliitModule } + } + "RawModule" should "work" in { assertTesterPasses({ new RawModuleTester }) }