diff options
| author | Schuyler Eldridge | 2020-02-07 14:54:58 -0500 |
|---|---|---|
| committer | Schuyler Eldridge | 2020-02-10 12:57:50 -0500 |
| commit | 72427067ebb870d021b748d55fe09aa9761f6410 (patch) | |
| tree | 9c2453b313eba3510282d5b88362120edbda1752 /src | |
| parent | dc9709c55bfa9f2dc7ee9a400e141ce5deb7269c (diff) | |
Add Target utility referringModule
This adds a utility method, referringModule, to the Target object that
behaves like IsMember.pathlessTarget except that it returns the module
of an InstanceTarget. This is useful for situations where you want to
get at "the module" a target is pointing at, but you want behavior
to get an actual module from an instance.
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/annotations/Target.scala | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/annotations/Target.scala b/src/main/scala/firrtl/annotations/Target.scala index 1571f98e..c7cb98d2 100644 --- a/src/main/scala/firrtl/annotations/Target.scala +++ b/src/main/scala/firrtl/annotations/Target.scala @@ -185,6 +185,19 @@ object Target { } }.tryToComplete } + + /** Returns the module that a [[Target]] "refers" to. + * + * For a [[ModuleTarget]] or a [[ReferenceTarget]], this is simply the deepest module. For an [[InstanceTarget]] this + * is *the module of the instance*. + * + * @note This differs from [[InstanceTarget.pathlessTarget]] which refers to the module instantiating the instance. + */ + def referringModule(a: IsMember): ModuleTarget = a match { + case b: ModuleTarget => b + case b: InstanceTarget => b.ofModuleTarget + case b: ReferenceTarget => b.pathlessTarget.moduleTarget + } } /** Represents incomplete or non-standard [[Target]]s |
