diff options
| author | Richard Lin | 2017-04-13 22:59:00 -0700 |
|---|---|---|
| committer | GitHub | 2017-04-13 22:59:00 -0700 |
| commit | e07248b8f6022fafdb84f5d1c0ebe3fc90a5475a (patch) | |
| tree | f2bb938fd35651b4fc7b88cbcd20e163cc75dd2e /src/main/scala/chisel3 | |
| parent | 97902cdc53eec52aa0cd806b8cb49a0e3f2fb769 (diff) | |
Module Hierarchy Refactor (#469)
Diffstat (limited to 'src/main/scala/chisel3')
| -rw-r--r-- | src/main/scala/chisel3/Driver.scala | 11 | ||||
| -rw-r--r-- | src/main/scala/chisel3/compatibility.scala | 33 | ||||
| -rw-r--r-- | src/main/scala/chisel3/internal/firrtl/Emitter.scala | 4 | ||||
| -rw-r--r-- | src/main/scala/chisel3/package.scala | 7 | ||||
| -rw-r--r-- | src/main/scala/chisel3/util/BlackBoxUtils.scala | 4 |
5 files changed, 46 insertions, 13 deletions
diff --git a/src/main/scala/chisel3/Driver.scala b/src/main/scala/chisel3/Driver.scala index b2acc946..8a2256df 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/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index 40fbe9bf..778d2c13 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -152,16 +152,43 @@ package object Chisel { // scalastyle:ignore package.object.name object Bool extends BoolFactory val Mux = chisel3.core.Mux - type BlackBox = chisel3.core.BlackBox - + import chisel3.core.Param + abstract class BlackBox(params: Map[String, Param] = Map.empty[String, Param]) extends chisel3.core.BlackBox(params) { + // This class auto-wraps the BlackBox with IO(...), allowing legacy code (where IO(...) wasn't + // required) to build. + override def _autoWrapPorts() = { + if (!_ioPortBound()) { + IO(io) + } + } + } val Mem = chisel3.core.Mem type MemBase[T <: Data] = chisel3.core.MemBase[T] type Mem[T <: Data] = chisel3.core.Mem[T] val SeqMem = chisel3.core.SyncReadMem type SeqMem[T <: Data] = chisel3.core.SyncReadMem[T] + import chisel3.core.CompileOptions + abstract class CompatibilityModule( + override_clock: Option[Clock]=None, override_reset: Option[Bool]=None) + (implicit moduleCompileOptions: CompileOptions) + extends chisel3.core.LegacyModule(override_clock, override_reset) { + // This class auto-wraps the Module IO with IO(...), allowing legacy code (where IO(...) wasn't + // required) to build. + // Also provides the clock / reset constructors, which were used before withClock happened. + + def this(_clock: Clock)(implicit moduleCompileOptions: CompileOptions) = this(Option(_clock), None)(moduleCompileOptions) + def this(_reset: Bool)(implicit moduleCompileOptions: CompileOptions) = this(None, Option(_reset))(moduleCompileOptions) + def this(_clock: Clock, _reset: Bool)(implicit moduleCompileOptions: CompileOptions) = this(Option(_clock), Option(_reset))(moduleCompileOptions) + + override def _autoWrapPorts() = { + if (!_ioPortBound()) { + IO(io) + } + } + } val Module = chisel3.core.Module - type Module = chisel3.core.Module + type Module = CompatibilityModule val printf = chisel3.core.printf diff --git a/src/main/scala/chisel3/internal/firrtl/Emitter.scala b/src/main/scala/chisel3/internal/firrtl/Emitter.scala index eb00e333..16b39e35 100644 --- a/src/main/scala/chisel3/internal/firrtl/Emitter.scala +++ b/src/main/scala/chisel3/internal/firrtl/Emitter.scala @@ -57,8 +57,8 @@ private class Emitter(circuit: Circuit) { /** Generates the FIRRTL module declaration. */ private def moduleDecl(m: Component): String = m.id match { - case _: BlackBox => newline + s"extmodule ${m.name} : " - case _: Module => newline + s"module ${m.name} : " + case _: chisel3.core.BaseBlackBox => newline + s"extmodule ${m.name} : " + case _: chisel3.core.UserModule => newline + s"module ${m.name} : " } /** Generates the FIRRTL module definition. diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 191b636e..a7ccc43b 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -151,7 +151,7 @@ package object chisel3 { // scalastyle:ignore package.object.name type SyncReadMem[T <: Data] = chisel3.core.SyncReadMem[T] val Module = chisel3.core.Module - type Module = chisel3.core.Module + type Module = chisel3.core.LegacyModule val printf = chisel3.core.printf @@ -310,6 +310,11 @@ package object chisel3 { // scalastyle:ignore package.object.name val withClock = chisel3.core.withClock val withReset = chisel3.core.withReset + type BaseModule = chisel3.core.BaseModule + type MultiIOModule = chisel3.core.ImplicitModule + type RawModule = chisel3.core.UserModule + type ExtModule = chisel3.core.ExtModule + // Implicit conversions for BlackBox Parameters implicit def fromIntToIntParam(x: Int): IntParam = IntParam(BigInt(x)) implicit def fromLongToIntParam(x: Long): IntParam = IntParam(BigInt(x)) diff --git a/src/main/scala/chisel3/util/BlackBoxUtils.scala b/src/main/scala/chisel3/util/BlackBoxUtils.scala index 084d58f9..fbcf4a59 100644 --- a/src/main/scala/chisel3/util/BlackBoxUtils.scala +++ b/src/main/scala/chisel3/util/BlackBoxUtils.scala @@ -7,7 +7,7 @@ import chisel3.core.ChiselAnnotation import firrtl.transforms.{BlackBoxInline, BlackBoxResource, BlackBoxSourceHelper} trait HasBlackBoxResource extends BlackBox { - self: Module => + self: BlackBox => def setResource(blackBoxResource: String): Unit = { annotate(ChiselAnnotation(self, classOf[BlackBoxSourceHelper], BlackBoxResource(blackBoxResource).serialize)) @@ -15,7 +15,7 @@ trait HasBlackBoxResource extends BlackBox { } trait HasBlackBoxInline extends BlackBox { - self: Module => + self: BlackBox => def setInline(blackBoxName: String, blackBoxInline: String): Unit = { annotate(ChiselAnnotation( |
