summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/aop
diff options
context:
space:
mode:
authorJack2022-01-12 04:27:19 +0000
committerJack2022-01-12 04:27:19 +0000
commit29df513e348cc809876893f650af8180f0190496 (patch)
tree06daaea954b4e5af7113f06e4bdbb78b33515cb3 /src/main/scala/chisel3/aop
parent5242ce90659decb9058ee75db56e5c188029fbf9 (diff)
parent747d16311bdf185d2e98e452b14cb5d8ccca004c (diff)
Merge branch 'master' into 3.5-release
Diffstat (limited to 'src/main/scala/chisel3/aop')
-rw-r--r--src/main/scala/chisel3/aop/AspectLibrary.scala24
-rw-r--r--src/main/scala/chisel3/aop/Select.scala318
-rw-r--r--src/main/scala/chisel3/aop/injecting/InjectStatement.scala7
-rw-r--r--src/main/scala/chisel3/aop/injecting/InjectingAspect.scala43
-rw-r--r--src/main/scala/chisel3/aop/injecting/InjectingTransform.scala4
-rw-r--r--src/main/scala/chisel3/aop/inspecting/InspectingAspect.scala1
6 files changed, 230 insertions, 167 deletions
diff --git a/src/main/scala/chisel3/aop/AspectLibrary.scala b/src/main/scala/chisel3/aop/AspectLibrary.scala
index 1a16b61f..04ac2384 100644
--- a/src/main/scala/chisel3/aop/AspectLibrary.scala
+++ b/src/main/scala/chisel3/aop/AspectLibrary.scala
@@ -8,7 +8,7 @@ import firrtl.options.{OptionsException, RegisteredLibrary, ShellOption}
/** Enables adding aspects to a design from the commandline, e.g.
* sbt> runMain chisel3.stage.ChiselMain --module <module> --with-aspect <aspect>
*/
-final class AspectLibrary() extends RegisteredLibrary {
+final class AspectLibrary() extends RegisteredLibrary {
val name = "AspectLibrary"
import scala.reflect.runtime.universe._
@@ -34,16 +34,20 @@ final class AspectLibrary() extends RegisteredLibrary {
throw new OptionsException(s"Unable to locate aspect '$aspectName'! (Did you misspell it?)", e)
case e: InstantiationException =>
throw new OptionsException(
- s"Unable to create instance of aspect '$aspectName'! (Does this class take parameters?)", e)
+ s"Unable to create instance of aspect '$aspectName'! (Does this class take parameters?)",
+ e
+ )
}
}
- val options = Seq(new ShellOption[String](
- longOption = "with-aspect",
- toAnnotationSeq = {
- case aspectName: String => Seq(apply(aspectName))
- },
- helpText = "The name/class of an aspect to compile with (must be a class/object without arguments!)",
- helpValueName = Some("<package>.<aspect>")
- ))
+ val options = Seq(
+ new ShellOption[String](
+ longOption = "with-aspect",
+ toAnnotationSeq = {
+ case aspectName: String => Seq(apply(aspectName))
+ },
+ helpText = "The name/class of an aspect to compile with (must be a class/object without arguments!)",
+ helpValueName = Some("<package>.<aspect>")
+ )
+ )
}
diff --git a/src/main/scala/chisel3/aop/Select.scala b/src/main/scala/chisel3/aop/Select.scala
index 8f5a2577..3a2a8931 100644
--- a/src/main/scala/chisel3/aop/Select.scala
+++ b/src/main/scala/chisel3/aop/Select.scala
@@ -47,17 +47,18 @@ object Select {
*/
def instancesIn(parent: Hierarchy[BaseModule]): Seq[Instance[BaseModule]] = {
check(parent)
- implicit val mg = new chisel3.internal.MacroGenerated{}
+ implicit val mg = new chisel3.internal.MacroGenerated {}
parent.proto._component.get match {
- case d: DefModule => d.commands.collect {
- case d: DefInstance =>
- d.id match {
- case p: chisel3.internal.BaseModule.IsClone[_] =>
- parent._lookup { x => new Instance(Clone(p)).asInstanceOf[Instance[BaseModule]] }
- case other: BaseModule =>
- parent._lookup { x => other }
- }
- }
+ case d: DefModule =>
+ d.commands.collect {
+ case d: DefInstance =>
+ d.id match {
+ case p: chisel3.internal.BaseModule.IsClone[_] =>
+ parent._lookup { x => new Instance(Clone(p)).asInstanceOf[Instance[BaseModule]] }
+ case other: BaseModule =>
+ parent._lookup { x => other }
+ }
+ }
case other => Nil
}
}
@@ -65,24 +66,27 @@ object Select {
/** Selects all Instances of instances/modules directly instantiated within given module, of provided type
*
* @note IMPORTANT: this function requires summoning a TypeTag[T], which will fail if T is an inner class.
+ * @note IMPORTANT: this function ignores type parameters. E.g. instancesOf[List[Int]] would return List[String].
+ *
* @param parent hierarchy which instantiates the returned Definitions
*/
- def instancesOf[T <: BaseModule : TypeTag](parent: Hierarchy[BaseModule]): Seq[Instance[T]] = {
+ def instancesOf[T <: BaseModule: TypeTag](parent: Hierarchy[BaseModule]): Seq[Instance[T]] = {
check(parent)
- implicit val mg = new chisel3.internal.MacroGenerated{}
+ implicit val mg = new chisel3.internal.MacroGenerated {}
parent.proto._component.get match {
- case d: DefModule => d.commands.flatMap {
- case d: DefInstance =>
- d.id match {
- case p: chisel3.internal.BaseModule.IsClone[_] =>
- val i = parent._lookup { x => new Instance(Clone(p)).asInstanceOf[Instance[BaseModule]] }
- if(i.isA[T]) Some(i.asInstanceOf[Instance[T]]) else None
- case other: BaseModule =>
- val i = parent._lookup { x => other }
- if(i.isA[T]) Some(i.asInstanceOf[Instance[T]]) else None
- }
- case other => None
- }
+ case d: DefModule =>
+ d.commands.flatMap {
+ case d: DefInstance =>
+ d.id match {
+ case p: chisel3.internal.BaseModule.IsClone[_] =>
+ val i = parent._lookup { x => new Instance(Clone(p)).asInstanceOf[Instance[BaseModule]] }
+ if (i.isA[T]) Some(i.asInstanceOf[Instance[T]]) else None
+ case other: BaseModule =>
+ val i = parent._lookup { x => other }
+ if (i.isA[T]) Some(i.asInstanceOf[Instance[T]]) else None
+ }
+ case other => None
+ }
case other => Nil
}
}
@@ -90,66 +94,73 @@ object Select {
/** Selects all Instances directly and indirectly instantiated within given root hierarchy, of provided type
*
* @note IMPORTANT: this function requires summoning a TypeTag[T], which will fail if T is an inner class.
+ * @note IMPORTANT: this function ignores type parameters. E.g. allInstancesOf[List[Int]] would return List[String].
+ *
* @param root top of the hierarchy to search for instances/modules of given type
*/
- def allInstancesOf[T <: BaseModule : TypeTag](root: Hierarchy[BaseModule]): Seq[Instance[T]] = {
- val soFar = if(root.isA[T]) Seq(root.toInstance.asInstanceOf[Instance[T]]) else Nil
+ def allInstancesOf[T <: BaseModule: TypeTag](root: Hierarchy[BaseModule]): Seq[Instance[T]] = {
+ val soFar = if (root.isA[T]) Seq(root.toInstance.asInstanceOf[Instance[T]]) else Nil
val allLocalInstances = instancesIn(root)
soFar ++ (allLocalInstances.flatMap(allInstancesOf[T]))
}
/** Selects the Definitions of all instances/modules directly instantiated within given module
- *
+ *
* @param parent
*/
def definitionsIn(parent: Hierarchy[BaseModule]): Seq[Definition[BaseModule]] = {
type DefType = Definition[BaseModule]
- implicit val mg = new chisel3.internal.MacroGenerated{}
+ implicit val mg = new chisel3.internal.MacroGenerated {}
check(parent)
val defs = parent.proto._component.get match {
- case d: DefModule => d.commands.collect {
- case i: DefInstance =>
- i.id match {
- case p: chisel3.internal.BaseModule.IsClone[_] =>
- parent._lookup { x => new Definition(Proto(p.getProto)).asInstanceOf[Definition[BaseModule]] }
- case other: BaseModule =>
- parent._lookup { x => other.toDefinition }
- }
- }
+ case d: DefModule =>
+ d.commands.collect {
+ case i: DefInstance =>
+ i.id match {
+ case p: chisel3.internal.BaseModule.IsClone[_] =>
+ parent._lookup { x => new Definition(Proto(p.getProto)).asInstanceOf[Definition[BaseModule]] }
+ case other: BaseModule =>
+ parent._lookup { x => other.toDefinition }
+ }
+ }
case other => Nil
}
- val (_, defList) = defs.foldLeft((Set.empty[DefType], List.empty[DefType])) { case ((set, list), definition: Definition[BaseModule]) =>
- if(set.contains(definition)) (set, list) else (set + definition, definition +: list)
+ val (_, defList) = defs.foldLeft((Set.empty[DefType], List.empty[DefType])) {
+ case ((set, list), definition: Definition[BaseModule]) =>
+ if (set.contains(definition)) (set, list) else (set + definition, definition +: list)
}
defList.reverse
}
-
/** Selects all Definitions of instances/modules directly instantiated within given module, of provided type
*
* @note IMPORTANT: this function requires summoning a TypeTag[T], which will fail if T is an inner class.
+ * @note IMPORTANT: this function ignores type parameters. E.g. definitionsOf[List[Int]] would return List[String].
+ *
* @param parent hierarchy which instantiates the returned Definitions
*/
- def definitionsOf[T <: BaseModule : TypeTag](parent: Hierarchy[BaseModule]): Seq[Definition[T]] = {
+ def definitionsOf[T <: BaseModule: TypeTag](parent: Hierarchy[BaseModule]): Seq[Definition[T]] = {
check(parent)
- implicit val mg = new chisel3.internal.MacroGenerated{}
+ implicit val mg = new chisel3.internal.MacroGenerated {}
type DefType = Definition[T]
val defs = parent.proto._component.get match {
- case d: DefModule => d.commands.flatMap {
- case d: DefInstance =>
- d.id match {
- case p: chisel3.internal.BaseModule.IsClone[_] =>
- val d = parent._lookup { x => new Definition(Clone(p)).asInstanceOf[Definition[BaseModule]] }
- if(d.isA[T]) Some(d.asInstanceOf[Definition[T]]) else None
- case other: BaseModule =>
- val d = parent._lookup { x => other.toDefinition }
- if(d.isA[T]) Some(d.asInstanceOf[Definition[T]]) else None
- }
- case other => None
- }
+ case d: DefModule =>
+ d.commands.flatMap {
+ case d: DefInstance =>
+ d.id match {
+ case p: chisel3.internal.BaseModule.IsClone[_] =>
+ val d = parent._lookup { x => new Definition(Clone(p)).asInstanceOf[Definition[BaseModule]] }
+ if (d.isA[T]) Some(d.asInstanceOf[Definition[T]]) else None
+ case other: BaseModule =>
+ val d = parent._lookup { x => other.toDefinition }
+ if (d.isA[T]) Some(d.asInstanceOf[Definition[T]]) else None
+ }
+ case other => None
+ }
}
- val (_, defList) = defs.foldLeft((Set.empty[DefType], List.empty[DefType])) { case ((set, list), definition: Definition[T]) =>
- if(set.contains(definition)) (set, list) else (set + definition, definition +: list)
+ val (_, defList) = defs.foldLeft((Set.empty[DefType], List.empty[DefType])) {
+ case ((set, list), definition: Definition[T]) =>
+ if (set.contains(definition)) (set, list) else (set + definition, definition +: list)
}
defList.reverse
}
@@ -158,16 +169,18 @@ object Select {
*
* @note IMPORTANT: this function requires summoning a TypeTag[T], which will fail if T is an inner class, i.e.
* a class defined within another class.
+ * @note IMPORTANT: this function ignores type parameters. E.g. allDefinitionsOf[List[Int]] would return List[String].
+ *
* @param root top of the hierarchy to search for definitions of given type
*/
- def allDefinitionsOf[T <: BaseModule : TypeTag](root: Hierarchy[BaseModule]): Seq[Definition[T]] = {
+ def allDefinitionsOf[T <: BaseModule: TypeTag](root: Hierarchy[BaseModule]): Seq[Definition[T]] = {
type DefType = Definition[T]
val allDefSet = mutable.HashSet[Definition[BaseModule]]()
val defSet = mutable.HashSet[DefType]()
val defList = mutable.ArrayBuffer[DefType]()
def rec(hier: Definition[BaseModule]): Unit = {
- if(hier.isA[T] && !defSet.contains(hier.asInstanceOf[DefType])) {
- defSet += hier.asInstanceOf[DefType]
+ if (hier.isA[T] && !defSet.contains(hier.asInstanceOf[DefType])) {
+ defSet += hier.asInstanceOf[DefType]
defList += hier.asInstanceOf[DefType]
}
allDefSet += hier
@@ -180,7 +193,6 @@ object Select {
defList.toList
}
-
/** Collects all components selected by collector within module and all children modules it instantiates
* directly or indirectly
* Accepts a collector function, rather than a collector partial function (see [[collectDeep]])
@@ -195,8 +207,8 @@ object Select {
def getDeep[T](module: BaseModule)(collector: BaseModule => Seq[T]): Seq[T] = {
check(module)
val myItems = collector(module)
- val deepChildrenItems = instances(module).flatMap {
- i => getDeep(i)(collector)
+ val deepChildrenItems = instances(module).flatMap { i =>
+ getDeep(i)(collector)
}
myItems ++ deepChildrenItems
}
@@ -215,8 +227,8 @@ object Select {
def collectDeep[T](module: BaseModule)(collector: PartialFunction[BaseModule, T]): Iterable[T] = {
check(module)
val myItems = collector.lift(module)
- val deepChildrenItems = instances(module).flatMap {
- i => collectDeep(i)(collector)
+ val deepChildrenItems = instances(module).flatMap { i =>
+ collectDeep(i)(collector)
}
myItems ++ deepChildrenItems
}
@@ -230,14 +242,19 @@ object Select {
def instances(module: BaseModule): Seq[BaseModule] = {
check(module)
module._component.get match {
- case d: DefModule => d.commands.flatMap {
- case i: DefInstance => i.id match {
- case m: ModuleClone[_] if !m._madeFromDefinition => None
- case _: PseudoModule => throw new Exception("instances, collectDeep, and getDeep are currently incompatible with Definition/Instance!")
- case other => Some(other)
+ case d: DefModule =>
+ d.commands.flatMap {
+ case i: DefInstance =>
+ i.id match {
+ case m: ModuleClone[_] if !m._madeFromDefinition => None
+ case _: PseudoModule =>
+ throw new Exception(
+ "instances, collectDeep, and getDeep are currently incompatible with Definition/Instance!"
+ )
+ case other => Some(other)
+ }
+ case _ => None
}
- case _ => None
- }
case other => Nil
}
}
@@ -248,12 +265,12 @@ object Select {
def registers(module: BaseModule): Seq[Data] = {
check(module)
module._component.get.asInstanceOf[DefModule].commands.collect {
- case r: DefReg => r.id
+ case r: DefReg => r.id
case r: DefRegInit => r.id
}
}
- /** Selects all ios directly contained within given module
+ /** Selects all ios on a given module
* @param module
*/
def ios(module: BaseModule): Seq[Data] = {
@@ -261,6 +278,15 @@ object Select {
module._component.get.asInstanceOf[DefModule].ports.map(_.id)
}
+ /** Selects all ios directly on a given Instance or Definition of a module
+ * @param parent the Definition or Instance to get the IOs of
+ */
+ def ios[T <: BaseModule](parent: Hierarchy[T]): Seq[Data] = {
+ check(parent)
+ implicit val mg = new chisel3.internal.MacroGenerated {}
+ parent._lookup { x => ios(parent.proto) }
+ }
+
/** Selects all SyncReadMems directly contained within given module
* @param module
*/
@@ -349,9 +375,14 @@ object Select {
*/
def attachedTo(module: BaseModule)(signal: Data): Set[Data] = {
check(module)
- module._component.get.asInstanceOf[DefModule].commands.collect {
- case Attach(_, seq) if seq.contains(signal) => seq
- }.flatMap { seq => seq.map(_.id.asInstanceOf[Data]) }.toSet
+ module._component.get
+ .asInstanceOf[DefModule]
+ .commands
+ .collect {
+ case Attach(_, seq) if seq.contains(signal) => seq
+ }
+ .flatMap { seq => seq.map(_.id.asInstanceOf[Data]) }
+ .toSet
}
/** Selects all connections to a signal or its parent signal(s) (if the signal is an element of an aggregate signal)
@@ -365,31 +396,42 @@ object Select {
check(module)
val sensitivitySignals = getIntermediateAndLeafs(signal).toSet
val predicatedConnects = mutable.ArrayBuffer[PredicatedConnect]()
- val isPort = module._component.get.asInstanceOf[DefModule].ports.flatMap{ p => getIntermediateAndLeafs(p.id) }.contains(signal)
+ val isPort = module._component.get
+ .asInstanceOf[DefModule]
+ .ports
+ .flatMap { p => getIntermediateAndLeafs(p.id) }
+ .contains(signal)
var prePredicates: Seq[Predicate] = Nil
var seenDef = isPort
- searchWhens(module, (cmd: Command, preds) => {
- cmd match {
- case cmd: DefinitionIR if cmd.id.isInstanceOf[Data] =>
- val x = getIntermediateAndLeafs(cmd.id.asInstanceOf[Data])
- if(x.contains(signal)) prePredicates = preds
- case Connect(_, loc@Node(d: Data), exp) =>
- val effected = getEffected(loc).toSet
- if(sensitivitySignals.intersect(effected).nonEmpty) {
- val expData = getData(exp)
- prePredicates.reverse.zip(preds.reverse).foreach(x => assert(x._1 == x._2, s"Prepredicates $x must match for signal $signal"))
- predicatedConnects += PredicatedConnect(preds.dropRight(prePredicates.size), d, expData, isBulk = false)
- }
- case BulkConnect(_, loc@Node(d: Data), exp) =>
- val effected = getEffected(loc).toSet
- if(sensitivitySignals.intersect(effected).nonEmpty) {
- val expData = getData(exp)
- prePredicates.reverse.zip(preds.reverse).foreach(x => assert(x._1 == x._2, s"Prepredicates $x must match for signal $signal"))
- predicatedConnects += PredicatedConnect(preds.dropRight(prePredicates.size), d, expData, isBulk = true)
- }
- case other =>
+ searchWhens(
+ module,
+ (cmd: Command, preds) => {
+ cmd match {
+ case cmd: DefinitionIR if cmd.id.isInstanceOf[Data] =>
+ val x = getIntermediateAndLeafs(cmd.id.asInstanceOf[Data])
+ if (x.contains(signal)) prePredicates = preds
+ case Connect(_, loc @ Node(d: Data), exp) =>
+ val effected = getEffected(loc).toSet
+ if (sensitivitySignals.intersect(effected).nonEmpty) {
+ val expData = getData(exp)
+ prePredicates.reverse
+ .zip(preds.reverse)
+ .foreach(x => assert(x._1 == x._2, s"Prepredicates $x must match for signal $signal"))
+ predicatedConnects += PredicatedConnect(preds.dropRight(prePredicates.size), d, expData, isBulk = false)
+ }
+ case BulkConnect(_, loc @ Node(d: Data), exp) =>
+ val effected = getEffected(loc).toSet
+ if (sensitivitySignals.intersect(effected).nonEmpty) {
+ val expData = getData(exp)
+ prePredicates.reverse
+ .zip(preds.reverse)
+ .foreach(x => assert(x._1 == x._2, s"Prepredicates $x must match for signal $signal"))
+ predicatedConnects += PredicatedConnect(preds.dropRight(prePredicates.size), d, expData, isBulk = true)
+ }
+ case other =>
+ }
}
- })
+ )
predicatedConnects.toSeq
}
@@ -397,14 +439,18 @@ object Select {
*
* @param module
*/
- def stops(module: BaseModule): Seq[Stop] = {
+ def stops(module: BaseModule): Seq[Stop] = {
val stops = mutable.ArrayBuffer[Stop]()
- searchWhens(module, (cmd: Command, preds: Seq[Predicate]) => {
- cmd match {
- case chisel3.internal.firrtl.Stop(_, _, clock, ret) => stops += Stop(preds, ret, getId(clock).asInstanceOf[Clock])
- case other =>
+ searchWhens(
+ module,
+ (cmd: Command, preds: Seq[Predicate]) => {
+ cmd match {
+ case chisel3.internal.firrtl.Stop(_, _, clock, ret) =>
+ stops += Stop(preds, ret, getId(clock).asInstanceOf[Clock])
+ case other =>
+ }
}
- })
+ )
stops.toSeq
}
@@ -414,12 +460,16 @@ object Select {
*/
def printfs(module: BaseModule): Seq[Printf] = {
val printfs = mutable.ArrayBuffer[Printf]()
- searchWhens(module, (cmd: Command, preds: Seq[Predicate]) => {
- cmd match {
- case chisel3.internal.firrtl.Printf(id, _, clock, pable) => printfs += Printf(id, preds, pable, getId(clock).asInstanceOf[Clock])
- case other =>
+ searchWhens(
+ module,
+ (cmd: Command, preds: Seq[Predicate]) => {
+ cmd match {
+ case chisel3.internal.firrtl.Printf(id, _, clock, pable) =>
+ printfs += Printf(id, preds, pable, getId(clock).asInstanceOf[Clock])
+ case other =>
+ }
}
- })
+ )
printfs.toSeq
}
@@ -433,15 +483,15 @@ object Select {
// Given a loc, return all subcomponents of id that could be assigned to in connect
private def getEffected(a: Arg): Seq[Data] = a match {
case Node(id: Data) => getIntermediateAndLeafs(id)
- case Slot(imm, name) => Seq(imm.id.asInstanceOf[Record].elements(name))
+ case Slot(imm, name) => Seq(imm.id.asInstanceOf[Record].elements(name))
case Index(imm, value) => getEffected(imm)
}
// Given an arg, return the corresponding id. Don't use on a loc of a connect.
private def getId(a: Arg): HasId = a match {
case Node(id) => id
- case l: ULit => l.num.U(l.w)
- case l: SLit => l.num.S(l.w)
+ case l: ULit => l.num.U(l.w)
+ case l: SLit => l.num.S(l.w)
case l: FPLit => FixedPoint(l.num, l.w, l.binaryPoint)
case other =>
sys.error(s"Something went horribly wrong! I was expecting ${other} to be a lit or a node!")
@@ -461,9 +511,10 @@ object Select {
str.splitAt(str.indexOf('>'))._2.drop(1)
}
} catch {
- case e: ChiselException => i.getOptionRef.get match {
- case l: LitArg => l.num.intValue.toString
- }
+ case e: ChiselException =>
+ i.getOptionRef.get match {
+ case l: LitArg => l.num.intValue.toString
+ }
}
// Collects when predicates as it searches through a module, then applying processCommand to non-when related commands
@@ -472,21 +523,22 @@ object Select {
module._component.get.asInstanceOf[DefModule].commands.foldLeft((Seq.empty[Predicate], Option.empty[Predicate])) {
(blah, cmd) =>
(blah, cmd) match {
- case ((preds, o), cmd) => cmd match {
- case WhenBegin(_, Node(pred: Bool)) => (When(pred) +: preds, None)
- case WhenBegin(_, l: LitArg) if l.num == BigInt(1) => (When(true.B) +: preds, None)
- case WhenBegin(_, l: LitArg) if l.num == BigInt(0) => (When(false.B) +: preds, None)
- case other: WhenBegin =>
- sys.error(s"Something went horribly wrong! I was expecting ${other.pred} to be a lit or a bool!")
- case _: WhenEnd => (preds.tail, Some(preds.head))
- case AltBegin(_) if o.isDefined => (o.get.not +: preds, o)
- case _: AltBegin =>
- sys.error(s"Something went horribly wrong! I was expecting ${o} to be nonEmpty!")
- case OtherwiseEnd(_, _) => (preds.tail, None)
- case other =>
- processCommand(cmd, preds)
- (preds, o)
- }
+ case ((preds, o), cmd) =>
+ cmd match {
+ case WhenBegin(_, Node(pred: Bool)) => (When(pred) +: preds, None)
+ case WhenBegin(_, l: LitArg) if l.num == BigInt(1) => (When(true.B) +: preds, None)
+ case WhenBegin(_, l: LitArg) if l.num == BigInt(0) => (When(false.B) +: preds, None)
+ case other: WhenBegin =>
+ sys.error(s"Something went horribly wrong! I was expecting ${other.pred} to be a lit or a bool!")
+ case _: WhenEnd => (preds.tail, Some(preds.head))
+ case AltBegin(_) if o.isDefined => (o.get.not +: preds, o)
+ case _: AltBegin =>
+ sys.error(s"Something went horribly wrong! I was expecting ${o} to be nonEmpty!")
+ case OtherwiseEnd(_, _) => (preds.tail, None)
+ case other =>
+ processCommand(cmd, preds)
+ (preds, o)
+ }
}
}
}
@@ -507,7 +559,7 @@ object Select {
* @param bool the when predicate
*/
case class When(bool: Bool) extends Predicate {
- def not: WhenNot = WhenNot(bool)
+ def not: WhenNot = WhenNot(bool)
def serialize: String = s"${getName(bool)}"
}
@@ -516,7 +568,7 @@ object Select {
* @param bool the when predicate corresponding to this otherwise predicate
*/
case class WhenNot(bool: Bool) extends Predicate {
- def not: When = When(bool)
+ def not: When = When(bool)
def serialize: String = s"!${getName(bool)}"
}
@@ -532,7 +584,7 @@ object Select {
case class PredicatedConnect(preds: Seq[Predicate], loc: Data, exp: Data, isBulk: Boolean) extends Serializeable {
def serialize: String = {
val moduleTarget = loc.toTarget.moduleTarget.serialize
- s"$moduleTarget: when(${preds.map(_.serialize).mkString(" & ")}): ${getName(loc)} ${if(isBulk) "<>" else ":="} ${getName(exp)}"
+ s"$moduleTarget: when(${preds.map(_.serialize).mkString(" & ")}): ${getName(loc)} ${if (isBulk) "<>" else ":="} ${getName(exp)}"
}
}
diff --git a/src/main/scala/chisel3/aop/injecting/InjectStatement.scala b/src/main/scala/chisel3/aop/injecting/InjectStatement.scala
index 92e24ba1..dbe1fd7b 100644
--- a/src/main/scala/chisel3/aop/injecting/InjectStatement.scala
+++ b/src/main/scala/chisel3/aop/injecting/InjectStatement.scala
@@ -15,7 +15,12 @@ import firrtl.annotations.{Annotation, ModuleTarget, NoTargetAnnotation, SingleT
* @param modules Additional modules that may be instantiated by s
* @param annotations Additional annotations that should be passed down compiler
*/
-case class InjectStatement(module: ModuleTarget, s: firrtl.ir.Statement, modules: Seq[firrtl.ir.DefModule], annotations: Seq[Annotation]) extends SingleTargetAnnotation[ModuleTarget] {
+case class InjectStatement(
+ module: ModuleTarget,
+ s: firrtl.ir.Statement,
+ modules: Seq[firrtl.ir.DefModule],
+ annotations: Seq[Annotation])
+ extends SingleTargetAnnotation[ModuleTarget] {
val target: ModuleTarget = module
override def duplicate(n: ModuleTarget): Annotation = this.copy(module = n)
}
diff --git a/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala b/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
index dc7e6487..abe208cf 100644
--- a/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
+++ b/src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
@@ -2,9 +2,8 @@
package chisel3.aop.injecting
-import chisel3.{Module, ModuleAspect, RawModule, withClockAndReset}
+import chisel3.{withClockAndReset, Module, ModuleAspect, RawModule}
import chisel3.aop._
-import chisel3.experimental.hierarchy.IsInstantiable
import chisel3.internal.{Builder, DynamicContext}
import chisel3.internal.firrtl.DefModule
import chisel3.stage.DesignAnnotation
@@ -23,12 +22,12 @@ import scala.collection.mutable
* @tparam M Type of root module (join point)
*/
case class InjectingAspect[T <: RawModule, M <: RawModule](
- selectRoots: T => Iterable[M],
- injection: M => Unit
-) extends InjectorAspect[T, M](
- selectRoots,
- injection
-)
+ selectRoots: T => Iterable[M],
+ injection: M => Unit)
+ extends InjectorAspect[T, M](
+ selectRoots,
+ injection
+ )
/** Extend to inject Chisel code into a module of type M
*
@@ -39,11 +38,12 @@ case class InjectingAspect[T <: RawModule, M <: RawModule](
* @tparam M Type of root module (join point)
*/
abstract class InjectorAspect[T <: RawModule, M <: RawModule](
- selectRoots: T => Iterable[M],
- injection: M => Unit
-) extends Aspect[T] {
+ selectRoots: T => Iterable[M],
+ injection: M => Unit)
+ extends Aspect[T] {
final def toAnnotation(top: T): AnnotationSeq = {
- val moduleNames = Select.allDefinitionsOf[chisel3.experimental.BaseModule](top.toDefinition).map{i => i.toTarget.module }.toSeq
+ val moduleNames =
+ Select.allDefinitionsOf[chisel3.experimental.BaseModule](top.toDefinition).map { i => i.toTarget.module }.toSeq
toAnnotation(selectRoots(top), top.name, moduleNames)
}
@@ -63,22 +63,26 @@ abstract class InjectorAspect[T <: RawModule, M <: RawModule](
dynamicContext.globalNamespace.name(n)
}
- val (chiselIR, _) = Builder.build(Module(new ModuleAspect(module) {
- module match {
- case x: Module => withClockAndReset(x.clock, x.reset) { injection(module) }
- case x: RawModule => injection(module)
- }
- }), dynamicContext)
+ val (chiselIR, _) = Builder.build(
+ Module(new ModuleAspect(module) {
+ module match {
+ case x: Module => withClockAndReset(x.clock, x.reset) { injection(module) }
+ case x: RawModule => injection(module)
+ }
+ }),
+ dynamicContext
+ )
val comps = chiselIR.components.map {
case x: DefModule if x.name == module.name => x.copy(id = module)
case other => other
}
- val annotations = chiselIR.annotations.map(_.toFirrtl).filterNot{ a => a.isInstanceOf[DesignAnnotation[_]] }
+ val annotations = chiselIR.annotations.map(_.toFirrtl).filterNot { a => a.isInstanceOf[DesignAnnotation[_]] }
/** Statements to be injected via aspect. */
val stmts = mutable.ArrayBuffer[ir.Statement]()
+
/** Modules to be injected via aspect. */
val modules = Aspect.getFirrtl(chiselIR.copy(components = comps)).modules.flatMap {
// for "container" modules, inject their statements
@@ -94,4 +98,3 @@ abstract class InjectorAspect[T <: RawModule, M <: RawModule](
}.toSeq
}
}
-
diff --git a/src/main/scala/chisel3/aop/injecting/InjectingTransform.scala b/src/main/scala/chisel3/aop/injecting/InjectingTransform.scala
index cc5601b1..8a0b6ecb 100644
--- a/src/main/scala/chisel3/aop/injecting/InjectingTransform.scala
+++ b/src/main/scala/chisel3/aop/injecting/InjectingTransform.scala
@@ -2,7 +2,7 @@
package chisel3.aop.injecting
-import firrtl.{ChirrtlForm, CircuitForm, CircuitState, Transform, ir}
+import firrtl.{ir, ChirrtlForm, CircuitForm, CircuitState, Transform}
import scala.collection.mutable
@@ -11,7 +11,7 @@ import scala.collection.mutable
* Implemented with Chisel Aspects and the [[chisel3.aop.injecting]] library
*/
class InjectingTransform extends Transform {
- override def inputForm: CircuitForm = ChirrtlForm
+ override def inputForm: CircuitForm = ChirrtlForm
override def outputForm: CircuitForm = ChirrtlForm
override def execute(state: CircuitState): CircuitState = {
diff --git a/src/main/scala/chisel3/aop/inspecting/InspectingAspect.scala b/src/main/scala/chisel3/aop/inspecting/InspectingAspect.scala
index a9752426..1340f253 100644
--- a/src/main/scala/chisel3/aop/inspecting/InspectingAspect.scala
+++ b/src/main/scala/chisel3/aop/inspecting/InspectingAspect.scala
@@ -13,7 +13,6 @@ import firrtl.AnnotationSeq
*/
case class InspectingAspect[T <: RawModule](inspect: T => Unit) extends InspectorAspect[T](inspect)
-
/** Extend to make custom inspections of an elaborated design and printing out results
*
* @param inspect Given top-level design, print things and return nothing