summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/internal
diff options
context:
space:
mode:
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/internal')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/Builder.scala43
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/CompileOptions.scala33
2 files changed, 66 insertions, 10 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
index 2dec78bb..0376e067 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
@@ -67,11 +67,11 @@ trait InstanceId {
}
private[chisel3] trait HasId extends InstanceId {
- private[chisel3] def _onModuleClose {} // scalastyle:ignore method.name
- private[chisel3] val _parent = Builder.dynamicContext.currentModule
+ private[chisel3] def _onModuleClose: Unit = {} // scalastyle:ignore method.name
+ private[chisel3] val _parent: Option[Module] = Builder.currentModule
_parent.foreach(_.addId(this))
- private[chisel3] val _id = Builder.idGen.next
+ private[chisel3] val _id: Long = Builder.idGen.next
override def hashCode: Int = _id.toInt
override def equals(that: Any): Boolean = that match {
case x: HasId => _id == x._id
@@ -129,35 +129,58 @@ private[chisel3] trait HasId extends InstanceId {
}
}
-private[chisel3] class DynamicContext {
+private[chisel3] class DynamicContext(moduleCompileOptions: Option[ExplicitCompileOptions] = None) {
val idGen = new IdGen
val globalNamespace = new Namespace(None, Set())
val components = ArrayBuffer[Component]()
var currentModule: Option[Module] = None
val errors = new ErrorLog
+ val compileOptions = moduleCompileOptions match {
+ case Some(options: ExplicitCompileOptions) => options
+ case None => chisel3.NotStrict.CompileOptions
+ }
}
private[chisel3] object Builder {
// All global mutable state must be referenced via dynamicContextVar!!
private val dynamicContextVar = new DynamicVariable[Option[DynamicContext]](None)
+ private def dynamicContext: DynamicContext =
+ dynamicContextVar.value.getOrElse(new DynamicContext)
- def dynamicContext: DynamicContext =
- dynamicContextVar.value getOrElse (new DynamicContext)
def idGen: IdGen = dynamicContext.idGen
def globalNamespace: Namespace = dynamicContext.globalNamespace
def components: ArrayBuffer[Component] = dynamicContext.components
+ def compileOptions = dynamicContext.compileOptions
+ def currentModule: Option[Module] = dynamicContext.currentModule
+ def currentModule_=(target: Option[Module]): Unit = {
+ dynamicContext.currentModule = target
+ }
+ def forcedModule: Module = currentModule match {
+ case Some(module) => module
+ case None => throw new Exception(
+ "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).
+ )
+ }
+
+ // 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 = {
- dynamicContext.currentModule.foreach(_._commands += c)
+ forcedModule._commands += c
c
}
- def pushOp[T <: Data](cmd: DefPrim[T]): T = pushCommand(cmd).id
+ 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")
+ pushCommand(cmd).id
+ }
def errors: ErrorLog = dynamicContext.errors
def error(m: => String): Unit = errors.error(m)
- def build[T <: Module](f: => T): Circuit = {
- dynamicContextVar.withValue(Some(new DynamicContext)) {
+ def build[T <: Module](f: => T, moduleCompileOptions: Option[ExplicitCompileOptions] = None): Circuit = {
+ dynamicContextVar.withValue(Some(new DynamicContext(moduleCompileOptions))) {
errors.info("Elaborating design...")
val mod = f
mod.forceName(mod.name, globalNamespace)
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/CompileOptions.scala b/chiselFrontend/src/main/scala/chisel3/internal/CompileOptions.scala
new file mode 100644
index 00000000..2890f6dc
--- /dev/null
+++ b/chiselFrontend/src/main/scala/chisel3/internal/CompileOptions.scala
@@ -0,0 +1,33 @@
+// See LICENSE for license details.
+
+package chisel3.internal
+
+trait CompileOptions {
+ // Should Bundle connections require a strict match of fields.
+ // If true and the same fields aren't present in both source and sink, a MissingFieldException,
+ // MissingLeftFieldException, or MissingRightFieldException will be thrown.
+ val connectFieldsMustMatch: Boolean
+ val declaredTypeMustBeUnbound: Boolean
+ val requireIOWrap: Boolean
+ val dontTryConnectionsSwapped: Boolean
+ val dontAssumeDirectionality: Boolean
+}
+
+trait ExplicitCompileOptions extends CompileOptions
+
+///** Initialize compilation options from a string map.
+// *
+// * @param optionsMap the map from "option" to "value"
+// */
+//class CompileOptions(optionsMap: Map[String, String]) {
+// // The default for settings related to "strictness".
+// val strictDefault: String = optionsMap.getOrElse("strict", "false")
+// // Should Bundle connections require a strict match of fields.
+// // If true and the same fields aren't present in both source and sink, a MissingFieldException,
+// // MissingLeftFieldException, or MissingRightFieldException will be thrown.
+// val connectFieldsMustMatch: Boolean = optionsMap.getOrElse("connectFieldsMustMatch", strictDefault).toBoolean
+// val declaredTypeMustBeUnbound: Boolean = optionsMap.getOrElse("declaredTypeMustBeUnbound", strictDefault).toBoolean
+// val requireIOWrap: Boolean = optionsMap.getOrElse("requireIOWrap", strictDefault).toBoolean
+// val dontTryConnectionsSwapped: Boolean = optionsMap.getOrElse("dontTryConnectionsSwapped", strictDefault).toBoolean
+// val dontAssumeDirectionality: Boolean = optionsMap.getOrElse("dontAssumeDirectionality", strictDefault).toBoolean
+//}