2017-09-12 04:31:44 +02:00
|
|
|
// 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 =>
|
2017-09-26 02:47:40 +02:00
|
|
|
val trim = s.replaceAll("\\s", "")
|
|
|
|
c.Expr[ValNameImpl] { q"_root_.freechips.rocketchip.macros.ValNameImpl(${trim})" }
|
2017-09-12 04:31:44 +02:00
|
|
|
}.getOrElse(c.abort(c.enclosingPosition, "Not a valid application."))
|
|
|
|
}
|
|
|
|
}
|