diplomacy: ValName captures val bindings for Nodes
This commit is contained in:
parent
5662d1de0b
commit
3656e975a1
22
macros/src/main/scala/ValName.scala
Normal file
22
macros/src/main/scala/ValName.scala
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// See LICENSE.SiFive for license details.
|
||||||
|
|
||||||
|
package freechips.rocketchip.macros
|
||||||
|
|
||||||
|
import scala.language.experimental.macros
|
||||||
|
import scala.reflect.macros.blackbox.Context
|
||||||
|
|
||||||
|
case class ValNameImpl(name: String)
|
||||||
|
|
||||||
|
object ValNameImpl
|
||||||
|
{
|
||||||
|
implicit def materialize: ValNameImpl = macro detail
|
||||||
|
def detail(c: Context): c.Expr[ValNameImpl] = {
|
||||||
|
import c.universe._
|
||||||
|
def allOwners(s: c.Symbol): Seq[c.Symbol] =
|
||||||
|
if (s == `NoSymbol`) Nil else s +: allOwners(s.owner)
|
||||||
|
val terms = allOwners(c.internal.enclosingOwner).filter(_.isTerm).map(_.asTerm)
|
||||||
|
terms.filter(_.isVal).map(_.name.toString).find(_(0) != '$').map { s =>
|
||||||
|
c.Expr[ValNameImpl] { q"_root_.freechips.rocketchip.macros.ValNameImpl(${s})" }
|
||||||
|
}.getOrElse(c.abort(c.enclosingPosition, "Not a valid application."))
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,8 @@ object BuildSettings extends Build {
|
|||||||
|
|
||||||
lazy val chisel = project in file("chisel3")
|
lazy val chisel = project in file("chisel3")
|
||||||
lazy val hardfloat = project.dependsOn(chisel)
|
lazy val hardfloat = project.dependsOn(chisel)
|
||||||
lazy val rocketchip = (project in file(".")).settings(chipSettings).dependsOn(chisel, hardfloat)
|
lazy val macros = project in file("macros")
|
||||||
|
lazy val rocketchip = (project in file(".")).settings(chipSettings).dependsOn(chisel, hardfloat, macros)
|
||||||
|
|
||||||
lazy val addons = settingKey[Seq[String]]("list of addons used for this build")
|
lazy val addons = settingKey[Seq[String]]("list of addons used for this build")
|
||||||
lazy val make = inputKey[Unit]("trigger backend-specific makefile command")
|
lazy val make = inputKey[Unit]("trigger backend-specific makefile command")
|
||||||
|
13
src/main/scala/diplomacy/ValName.scala
Normal file
13
src/main/scala/diplomacy/ValName.scala
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// See LICENSE.SiFive for license details.
|
||||||
|
|
||||||
|
package freechips.rocketchip.diplomacy
|
||||||
|
|
||||||
|
import scala.language.experimental.macros
|
||||||
|
import freechips.rocketchip.macros.ValNameImpl
|
||||||
|
|
||||||
|
case class ValName(name: String)
|
||||||
|
|
||||||
|
object ValName
|
||||||
|
{
|
||||||
|
implicit def materialize(implicit x: ValNameImpl): ValName = ValName(x.name)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user