diff options
| author | Henry Cook | 2015-08-13 13:42:47 -0700 |
|---|---|---|
| committer | Henry Cook | 2015-08-13 13:42:47 -0700 |
| commit | a20354fd7b6f0e28a9b81cab09a0b9d2a4aa0244 (patch) | |
| tree | 5abb4a81670ca07a1902cf18635bdd52335c56b9 /src/main/scala/Chisel/Builder.scala | |
| parent | cd4f96021998f64874d1f59879b797e16d646116 (diff) | |
Cleanup DynamicContext
Diffstat (limited to 'src/main/scala/Chisel/Builder.scala')
| -rw-r--r-- | src/main/scala/Chisel/Builder.scala | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/main/scala/Chisel/Builder.scala b/src/main/scala/Chisel/Builder.scala index 9a469149..0d25b177 100644 --- a/src/main/scala/Chisel/Builder.scala +++ b/src/main/scala/Chisel/Builder.scala @@ -67,30 +67,14 @@ private class DynamicContext { val globalNamespace = new FIRRTLNamespace val globalRefMap = new RefMap val components = ArrayBuffer[Component]() - val currentModuleVar = new DynamicVariable[Option[Module]](None) - val currentParamsVar = new DynamicVariable[Parameters](Parameters.empty) + var currentModule: Option[Module] = None val parameterDump = new ParameterDump - - def getCurrentModule = currentModuleVar.value - def moduleScope[T](body: => T): T = { - currentModuleVar.withValue(getCurrentModule)(body) - } - def forceCurrentModule[T](m: Module) { // Used in Module constructor - currentModuleVar.value = Some(m) - } - def pushCommand(c: Command) { - currentModuleVar.value.foreach(_._commands += c) - } - - def getParams: Parameters = currentParamsVar.value - def paramsScope[T](p: Parameters)(body: => T): T = { - currentParamsVar.withValue(p)(body) - } } private object Builder { // All global mutable state must be referenced via dynamicContextVar!! private val dynamicContextVar = new DynamicVariable[Option[DynamicContext]](None) + private val currentParamsVar = new DynamicVariable[Parameters](Parameters.empty) def dynamicContext = dynamicContextVar.value.get def idGen = dynamicContext.idGen @@ -99,12 +83,19 @@ private object Builder { def components = dynamicContext.components def parameterDump = dynamicContext.parameterDump - def pushCommand(c: Command) = dynamicContext.pushCommand(c) + def pushCommand(c: Command) { + dynamicContext.currentModule.foreach(_._commands += c) + } def pushOp[T <: Data](cmd: DefPrim[T]) = { pushCommand(cmd) cmd.id } + def getParams: Parameters = currentParamsVar.value + def paramsScope[T](p: Parameters)(body: => T): T = { + currentParamsVar.withValue(p)(body) + } + def build[T <: Module](f: => T): Circuit = { dynamicContextVar.withValue(Some(new DynamicContext)) { val mod = f |
