diff options
| author | Aditya Naik | 2024-07-24 02:05:26 -0700 |
|---|---|---|
| committer | Aditya Naik | 2024-07-24 02:05:26 -0700 |
| commit | b058bdcf8c142641aacd92f9938fb350a90e0762 (patch) | |
| tree | b02c9c0deab87191de9868db0fbaba873156a438 /core/src/main/scala/chisel3/Module.scala | |
| parent | f998a07cc51d62db7f66be059d2a69d54a43e0b1 (diff) | |
Working on Module.scala
Diffstat (limited to 'core/src/main/scala/chisel3/Module.scala')
| -rw-r--r-- | core/src/main/scala/chisel3/Module.scala | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/core/src/main/scala/chisel3/Module.scala b/core/src/main/scala/chisel3/Module.scala index 727a1320..18749afa 100644 --- a/core/src/main/scala/chisel3/Module.scala +++ b/core/src/main/scala/chisel3/Module.scala @@ -3,7 +3,7 @@ package chisel3 import scala.collection.immutable.ListMap -import scala.collection.mutable.{ArrayBuffer, HashMap} +import scala.collection.mutable.{ArrayBuffer, HashMap, LinkedHashSet} import chisel3.internal._ import chisel3.internal.Builder._ @@ -22,6 +22,34 @@ object Module { * @return the input module `m` with Chisel metadata properly set */ def apply[T <: BaseModule](bc: => T): T = { + // Instantiate the module definition. + val module = evaluate[T](bc) + + // Handle connections at enclosing scope + // We use _component because Modules that don't generate them may still have one + if (Builder.currentModule.isDefined && module._component.isDefined) { + // Class only uses the Definition API, and is not allowed here. + module match { + case _: Class[_] => throwException("Module() cannot be called on a Class. Please use Definition().") + case _ => () + } + + val component = module._component.get + component match { + case DefClass(_, name, _, _) => + Builder.referenceUserContainer match { + case rm: RawModule => rm.addCommand(DefObject(module, name)) + } + case _ => pushCommand(DefInstance(module, component.ports)) + } + module.initializeInParent() + } + + module + } + + /** Build a module definition */ + private[chisel3] def evaluate[T <: BaseModule](bc: => T): T = { if (Builder.readyForModuleConstr) { throwException( "Error: Called Module() twice without instantiating a Module." |
