summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
diff options
context:
space:
mode:
authorRichard Lin2017-04-13 22:59:00 -0700
committerGitHub2017-04-13 22:59:00 -0700
commite07248b8f6022fafdb84f5d1c0ebe3fc90a5475a (patch)
treef2bb938fd35651b4fc7b88cbcd20e163cc75dd2e /chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
parent97902cdc53eec52aa0cd806b8cb49a0e3f2fb769 (diff)
Module Hierarchy Refactor (#469)
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/internal/Builder.scala')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/Builder.scala26
1 files changed, 15 insertions, 11 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
index e0cbf302..73556750 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
@@ -70,7 +70,7 @@ trait InstanceId {
private[chisel3] trait HasId extends InstanceId {
private[chisel3] def _onModuleClose: Unit = {} // scalastyle:ignore method.name
- private[chisel3] val _parent: Option[Module] = Builder.currentModule
+ private[chisel3] val _parent: Option[BaseModule] = Builder.currentModule
_parent.foreach(_.addId(this))
private[chisel3] val _id: Long = Builder.idGen.next
@@ -148,7 +148,7 @@ private[chisel3] class DynamicContext() {
val globalNamespace = Namespace.empty
val components = ArrayBuffer[Component]()
val annotations = ArrayBuffer[ChiselAnnotation]()
- var currentModule: Option[Module] = None
+ var currentModule: Option[BaseModule] = None
// Set by object Module.apply before calling class Module constructor
// Used to distinguish between no Module() wrapping, multiple wrappings, and rewrapping
var readyForModuleConstr: Boolean = false
@@ -170,17 +170,24 @@ private[chisel3] object Builder {
def annotations: ArrayBuffer[ChiselAnnotation] = dynamicContext.annotations
def namingStack: internal.naming.NamingStack = dynamicContext.namingStack
- def currentModule: Option[Module] = dynamicContext.currentModule
- def currentModule_=(target: Option[Module]): Unit = {
+ def currentModule: Option[BaseModule] = dynamicContext.currentModule
+ def currentModule_=(target: Option[BaseModule]): Unit = {
dynamicContext.currentModule = target
}
- def forcedModule: Module = currentModule match {
+ def forcedModule: BaseModule = currentModule match {
case Some(module) => module
case None => throwException(
"Error: Not in a Module. Likely cause: Missed Module() wrap or bare chisel API call."
// A bare api call is, e.g. calling Wire() from the scala console).
)
}
+ def forcedUserModule: UserModule = currentModule match {
+ case Some(module: UserModule) => module
+ case _ => throwException(
+ "Error: Not in a UserModule. Likely cause: Missed Module() wrap, bare chisel API call, or attempting to construct hardware inside a BlackBox."
+ // A bare api call is, e.g. calling Wire() from the scala console).
+ )
+ }
def readyForModuleConstr: Boolean = dynamicContext.readyForModuleConstr
def readyForModuleConstr_=(target: Boolean): Unit = {
dynamicContext.readyForModuleConstr = target
@@ -203,15 +210,12 @@ private[chisel3] object Builder {
// TODO(twigg): Ideally, binding checks and new bindings would all occur here
// However, rest of frontend can't support this yet.
def pushCommand[T <: Command](c: T): T = {
- forcedModule match {
- case _: BlackBox => throwException("Cannot add hardware to a BlackBox")
- case m => m._commands += c
- }
+ forcedUserModule.addCommand(c)
c
}
def pushOp[T <: Data](cmd: DefPrim[T]): T = {
// Bind each element of the returned Data to being a Op
- Binding.bind(cmd.id, OpBinder(forcedModule), "Error: During op creation, fresh result")
+ Binding.bind(cmd.id, OpBinder(forcedUserModule), "Error: During op creation, fresh result")
pushCommand(cmd).id
}
@@ -230,7 +234,7 @@ private[chisel3] object Builder {
throwException(m)
}
- def build[T <: Module](f: => T): Circuit = {
+ def build[T <: UserModule](f: => T): Circuit = {
dynamicContextVar.withValue(Some(new DynamicContext())) {
errors.info("Elaborating design...")
val mod = f