diff options
| author | Henry Cook | 2015-08-12 16:55:26 -0700 |
|---|---|---|
| committer | Henry Cook | 2015-08-12 17:14:26 -0700 |
| commit | 0514044266af6ab681b4887ba50d630b268726d7 (patch) | |
| tree | 761f7a9c4f8ee3eecd1e23d0a4f50022e0a83a56 /src | |
| parent | 4031fad8dda90a1c14149c3c378dbf9798b388d9 (diff) | |
params and paramsScope objects
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/Chisel/Core.scala | 12 | ||||
| -rw-r--r-- | src/main/scala/Chisel/Parameters.scala | 32 |
2 files changed, 29 insertions, 15 deletions
diff --git a/src/main/scala/Chisel/Core.scala b/src/main/scala/Chisel/Core.scala index efb5b8f8..f03919a1 100644 --- a/src/main/scala/Chisel/Core.scala +++ b/src/main/scala/Chisel/Core.scala @@ -58,12 +58,6 @@ private class DynamicContext { def paramsScope[T](p: Parameters)(body: => T): T = { currentParamsVar.withValue(p)(body) } - def paramsScope[T,S](mask: Map[S,Any])(body: => T): T = { - paramsScope(currentParamsVar.value.alter(mask))(body) - } - def paramsScope[T](mask: PartialFunction[Any,Any])(body: => T): T = { - paramsScope(currentParamsVar.value.alterPartial(mask))(body) - } } private object Builder { @@ -299,8 +293,6 @@ abstract class Data(dirArg: Direction) extends Id { if (_mod ne null) _mod.addNode(this) - def params = dynamicContext.getParams - def toType: Kind def dir: Direction = dirVar @@ -906,6 +898,7 @@ object Bundle { def apply[T <: Bundle](b: => T)(implicit p: Parameters): T = { dynamicContext.paramsScope(p.push){ b } } + //TODO @deprecated("Use Chisel.paramsScope object","08-01-2015") def apply[T <: Bundle](b: => T, f: PartialFunction[Any,Any]): T = { val q = dynamicContext.getParams.alterPartial(f) apply(b)(q) @@ -979,6 +972,7 @@ object Module { m }.connectImplicitIOs() } + //TODO @deprecated("Use Chisel.paramsScope object","08-01-2015") def apply[T <: Module](m: => T, f: PartialFunction[Any,Any]): T = { apply(m)(dynamicContext.getParams.alterPartial(f)) } @@ -999,8 +993,6 @@ abstract class Module(_clock: Clock = null, _reset: Bool = null) extends Id { val name = Builder.globalNamespace.name(getClass.getName.split('.').last) - def params = dynamicContext.getParams - def io: Bundle val clock = Clock(INPUT) val reset = Bool(INPUT) diff --git a/src/main/scala/Chisel/Parameters.scala b/src/main/scala/Chisel/Parameters.scala index 24cb04fb..d5b0a46f 100644 --- a/src/main/scala/Chisel/Parameters.scala +++ b/src/main/scala/Chisel/Parameters.scala @@ -67,8 +67,30 @@ import scala.collection.mutable // Convention: leading _'s on names means private to the outside world // but accessible to anything in this file. -abstract trait UsesParameters { - def params: Parameters +@deprecated("params is now globally available as Chisel.params object","08-01-2015") +abstract trait UsesParameters { } + +object params { + def apply[T](field:Any):T = Builder.dynamicContext.getParams.apply(field) + def apply[T](field:Field[T]):T = Builder.dynamicContext.getParams.apply(field) + // TODO: provide other mutators of Parameters? or @deprecate this and make + // Parameters private, only mutateable through paramsScope? + def alterPartial[T](mask: PartialFunction[Any,Any]): Parameters = { + Builder.dynamicContext.getParams.alterPartial(mask) + } + def constrain(gen:ViewSym=>Ex[Boolean]) = Builder.dynamicContext.getParams.constrain(gen) +} + +object paramsScope { + def apply[T](p: Parameters)(body: => T): T = { + Builder.dynamicContext.paramsScope(p)(body) + } + def apply[T,S](mask: Map[S,Any])(body: => T): T = { + apply(Builder.dynamicContext.getParams.alter(mask))(body) + } + def apply[T](mask: PartialFunction[Any,Any])(body: => T): T = { + apply(Builder.dynamicContext.getParams.alterPartial(mask))(body) + } } class ParameterUndefinedException(field:Any, cause:Throwable=null) @@ -79,6 +101,8 @@ class KnobUndefinedException(field:Any, cause:Throwable=null) // Knobs are top level free variables that go into the constraint solver. final case class Knob[T](name:Any) +// Fields are wrappers around particular a particular parameter's type +class Field[T] class ChiselConfig( val topDefinitions: World.TopDefs = { (a,b,c) => {throw new scala.MatchError(a)}}, @@ -124,6 +148,7 @@ class ChiselConfig( override def toString = this.getClass.getSimpleName } +// TODO eliminate this or move it to DynamicContext object Dump { def apply[T](key:Any,value:T):T = Builder.parameterDump.apply(key, value) def apply[T](knob:Knob[T]):Knob[T] = Builder.parameterDump.apply(knob) @@ -140,7 +165,6 @@ class ParameterDump { // objects given to the user in mask functions (site,here,up) abstract class View { - protected val deftSite: View // when views are queried without a specifying a site this is the default // use `this` view's behavior to query for a parameters value as if @@ -414,8 +438,6 @@ object Parameters { } } -class Field[T] - final class Parameters( private val _world: World, private val _look: _Lookup |
