Skip to content

Commit

Permalink
Allow top-level RawModule
Browse files Browse the repository at this point in the history
  • Loading branch information
ducky64 committed Apr 13, 2017
1 parent 5ddceb4 commit aecb59b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/main/scala/chisel3/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package chisel3

import chisel3.internal.firrtl.Emitter
import chisel3.experimental.RawModule

import java.io._
import net.jcazevedo.moultingyaml._
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions src/test/scala/chiselTests/ChiselSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions src/test/scala/chiselTests/RawModuleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down

0 comments on commit aecb59b

Please sign in to comment.