1
0

diplomacy: ValName captures val bindings for Nodes

This commit is contained in:
Wesley W. Terpstra
2017-09-11 19:31:44 -07:00
parent 5662d1de0b
commit 3656e975a1
3 changed files with 37 additions and 1 deletions

View 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."))
}
}