diff options
| author | Albert Magyar | 2019-10-07 11:56:30 -0700 |
|---|---|---|
| committer | mergify[bot] | 2019-10-07 18:56:30 +0000 |
| commit | 357eba4c2b1549de70843899b4dae7d657757d50 (patch) | |
| tree | fcfb740f9dfda8e4e7bdd24984ae027e871f6e32 /src/main/scala/firrtl/annotations | |
| parent | 621c5689ff9b441465a9e6a1f4d92af739603293 (diff) | |
Absorb some instance analysis into InstanceGraph, use safer boxed Strings (#1186)
* Replace instance analysis code with InstanceGraph API calls
* Add convenience implicits for using TargetTokens as safe boxed strings
Diffstat (limited to 'src/main/scala/firrtl/annotations')
| -rw-r--r-- | src/main/scala/firrtl/annotations/TargetToken.scala | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/annotations/TargetToken.scala b/src/main/scala/firrtl/annotations/TargetToken.scala index 587f30eb..70b64271 100644 --- a/src/main/scala/firrtl/annotations/TargetToken.scala +++ b/src/main/scala/firrtl/annotations/TargetToken.scala @@ -2,6 +2,9 @@ package firrtl.annotations +import firrtl._ +import ir.{DefModule, DefInstance} + /** Building block to represent a [[Target]] of a FIRRTL component */ sealed trait TargetToken { def keyword: String @@ -32,6 +35,33 @@ case object TargetToken { case object Init extends TargetToken { override def keyword: String = "init"; val value = "" } case object Reset extends TargetToken { override def keyword: String = "reset"; val value = "" } + implicit class fromStringToTargetToken(s: String) { + def Instance: Instance = new TargetToken.Instance(s) + def OfModule: OfModule = new TargetToken.OfModule(s) + def Ref: Ref = new TargetToken.Ref(s) + def Field: Field = new TargetToken.Field(s) + } + + implicit class fromIntToTargetToken(i: Int) { + def Index: Index = new TargetToken.Index(i) + } + + implicit class fromDefModuleToTargetToken(m: DefModule) { + def OfModule: OfModule = new TargetToken.OfModule(m.name) + } + + implicit class fromDefInstanceToTargetToken(i: DefInstance) { + def Instance: Instance = new TargetToken.Instance(i.name) + def OfModule: OfModule = new TargetToken.OfModule(i.module) + def toTokens: (Instance, OfModule) = (new TargetToken.Instance(i.name), new TargetToken.OfModule(i.module)) + } + + implicit class fromWDefInstanceToTargetToken(wi: WDefInstance) { + def Instance: Instance = new TargetToken.Instance(wi.name) + def OfModule: OfModule = new TargetToken.OfModule(wi.module) + def toTokens: (Instance, OfModule) = (new TargetToken.Instance(wi.name), new TargetToken.OfModule(wi.module)) + } + val keyword2targettoken = Map( "inst" -> ((value: String) => Instance(value)), "of" -> ((value: String) => OfModule(value)), |
