Skip to content

Commit

Permalink
Correctly output knob names into .knb output file
Browse files Browse the repository at this point in the history
Added a new member to ChiselConfig called topConstraints, which allows
the designer to add top level custom constraints to a configuration
class
  • Loading branch information
Adam Izraelevitz authored and Adam Izraelevitz committed Sep 2, 2014
1 parent 00d2469 commit 18e6012
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
5 changes: 3 additions & 2 deletions src/main/scala/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ object Driver extends FileSystemUtilities{
if (!Driver.chiselConfigMode.isEmpty && !Driver.chiselConfigClassName.isEmpty) {
val config = Class.forName(chiselConfigClassName.get).newInstance.asInstanceOf[ChiselConfig]
val world = if(Driver.chiselConfigMode.get == "collect") new Collector(config.top,config.knobVal) else new Instance(config.top,config.knobVal)
val p = Some(Parameters.root(world))
val c = execute(() => Module(gen())(p))
val p = Parameters.root(world)
config.topConstraints.foreach(c => p.constrain(c))
val c = execute(() => Module(gen())(Some(p)))
if(Driver.chiselConfigMode.get == "collect") {
val v = createOutputFile(Driver.chiselConfigClassName.get + ".knb")
v.write(world.getKnobs)
Expand Down
40 changes: 9 additions & 31 deletions src/main/scala/Parameters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Portions may be copyrighted by others, as may be noted in specific //
// copyright notices within specific files. //
// //
// AUTHOR: J. Bachan //
// AUTHOR: J. Bachan, A Izraelevitz, H Cook //
//////////////////////////////////////////////////////////////////////////

// Convention: leading _'s on names means private to the outside world
Expand Down Expand Up @@ -36,6 +36,7 @@ abstract class ChiselConfig {
val knobVal:Any=>Any = {
case x if(false) => x
}
val topConstraints:List[ViewSym=>Ex[Boolean]] = List( ex => ExLit[Boolean](true) )
}

// objects given to the user in mask functions (site,here,up)
Expand Down Expand Up @@ -119,6 +120,7 @@ abstract class World(
topDefs: World.TopDefs
) {

val _knobs = new mutable.HashSet[Any]
abstract class _View extends View {
val look: _Lookup
def path = look.path
Expand All @@ -134,7 +136,7 @@ abstract class World(
// evaluate an expression against this world
def _eval[T](e:Ex[T]):T = {
Ex.eval(e, {
case v:_VarKnob[_] => _knobValue(v.kname)
case v:_VarKnob[_] => {_knobs += v.kname; _knobValue(v.kname)}
case v:_VarLet[_] => _eval(v.expr.asInstanceOf[Ex[T]])
})
}
Expand Down Expand Up @@ -200,31 +202,10 @@ class Collector(

val _constraints = new mutable.HashSet[Ex[Boolean]]

def knobs():Set[Any] = {
val ks = new mutable.HashSet[Any]
for(c <- _constraints) {
for(e <- Ex.unfurl(c)) {
e match {
case ExVar(_VarKnob(k)) => ks += k
case _ => {}
}
}
}
ks.toSet
def knobs():List[Any] = {
_knobs.toList
}
def knobNames():Set[String] = {
val ks = new mutable.HashSet[String]
for(c <- _constraints) {
for(e <- Ex.unfurl(c)) {
e match {
case v:ExVar[_] => ks += v.toString
case _ => {}
}
}
}
ks.toSet
}


def constraints():List[Ex[Boolean]] = {
_constraints.toList
}
Expand Down Expand Up @@ -270,8 +251,8 @@ class Collector(

override def getConstraints:String = if(constraints.isEmpty) "" else constraints.map("( " + _.toString + " )").reduce(_ +"\n" + _) + "\n"

override def getKnobs:String = if(knobNames.isEmpty) "" else {
knobNames.reduce(_ + "\n" + _) + "\n"
override def getKnobs:String = if(knobs.isEmpty) "" else {
knobs.map(_.toString).reduce(_ + "\n" + _) + "\n"
}
}

Expand Down Expand Up @@ -383,9 +364,6 @@ final class Parameters(
def alter[T](mask:Map[T,Any]) =
_alter(Parameters.makeMask(mask.asInstanceOf[Map[Any,Any]]))

def alter(mask:PartialFunction[Any,Any]) =
_alter(Parameters.makeMask(mask))

def alterPartial(mask:PartialFunction[Any,Any]) =
_alter(Parameters.makeMask(mask))
}

0 comments on commit 18e6012

Please sign in to comment.