Skip to content

Commit

Permalink
Changed P -> params. Added Alter and PF as convenience classes for ob…
Browse files Browse the repository at this point in the history
…taining partial functions for altering a child's parameters
  • Loading branch information
Adam Izraelevitz authored and Adam Izraelevitz committed Aug 2, 2014
1 parent 1f6f196 commit e600be3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/Bundle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object Bundle {
*/
class Bundle(view_arg: Seq[String] = null)(implicit _params:Option[Parameters] = None) extends Aggregate {
var view = view_arg;
val P = if(_params == None) {
val params = if(_params == None) {
if(Driver.parStack.isEmpty) Parameters.empty else Driver.parStack.top
} else _params.get
private var elementsCache: ArrayBuffer[(String, Data)] = null;
Expand Down
40 changes: 24 additions & 16 deletions src/main/scala/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,16 @@ import ChiselError._
import Module._

object Module {
def apply[T<:Module](c: =>T,fun:PartialFunction[Any,Any])(implicit _p:Option[Parameters] = None):T = {
val q = _p.getOrElse(params).alterPartial(fun)
Driver.modStackPushed = true
Driver.parStack.push(q)
val res = init(c)
Driver.parStack.pop
res
}
def apply[T<:Module](c: =>T)(implicit _p:Option[Parameters] = None):T = {
Driver.modStackPushed = true
def init(c: =>T):T = {
val res = c
pop()
for ((n, io) <- res.wires) {
if (io.dir == null)
ChiselErrors += new ChiselError(() => {"All IO's must be ports (dir set): " + io}, io.line)
// else if (io.width_ == -1)
// ChiselErrors += new ChiselError(() => {"All IO's must have width set: " + io}, io.line)
io.isIo = true
}
res
}
_p match {
case Some(q: Parameters) => {
Driver.parStack.push(q.push)
Expand All @@ -71,7 +67,19 @@ object Module {
}
}
}
private def P = if(Driver.parStack.isEmpty) Parameters.empty else Driver.parStack.top
private def init[T<:Module](c: =>T):T = {
val res = c
pop()
for ((n, io) <- res.wires) {
if (io.dir == null)
ChiselErrors += new ChiselError(() => {"All IO's must be ports (dir set): " + io}, io.line)
// else if (io.width_ == -1)
// ChiselErrors += new ChiselError(() => {"All IO's must have width set: " + io}, io.line)
io.isIo = true
}
res
}
private def params = if(Driver.parStack.isEmpty) Parameters.empty else Driver.parStack.top

/* *push* is done in the Module constructor because we don't have
a *this* pointer before then, yet we need to store it before the subclass
Expand All @@ -80,7 +88,7 @@ object Module {
private def push(c: Module) {
if (!Driver.modStackPushed) {
ChiselError.error(
c.getClass.getName + " was not properly wrapped into a Module() call.")
c.getClass.getName + " was not properly wrapped into a module() call.")
}
Driver.modStackPushed = false
Driver.compStack.push(c)
Expand Down Expand Up @@ -180,8 +188,8 @@ abstract class Module(var clock: Clock = null, private var _reset: Bool = null)
push(this)

//Parameter Stuff
def P = Module.P
P.path = this.getClass :: P.path
def params = Module.params
params.path = this.getClass :: params.path

var hasExplicitClock = !(clock == null)
var hasExplicitReset = !(_reset == null)
Expand Down
9 changes: 8 additions & 1 deletion src/main/scala/Parameters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ final case class Knob[T](name:Any)

abstract class ChiselConfig {
val top:World.TopDefs
val knobVal:Any=>Any
val knobVal:Any=>Any = {
case x if(false) => x
}
}

// objects given to the user in mask functions (site,here,up)
Expand Down Expand Up @@ -319,6 +321,11 @@ object Parameters {

class Field[T]

trait PF extends PartialFunction[Any,Any]
object Alter {
def apply(p:PartialFunction[Any,Any]) = p
}

final class Parameters(
private val _world: World,
private val _look: _Lookup
Expand Down

0 comments on commit e600be3

Please sign in to comment.