diff options
| author | Schuyler Eldridge | 2019-02-02 20:54:06 -0500 |
|---|---|---|
| committer | Schuyler Eldridge | 2019-04-25 16:24:15 -0400 |
| commit | 47fe781c4ace38dff7f31da7e78f772e131d689e (patch) | |
| tree | ec4b11c4a556d7a354efbe6dcc7be51fba44e2f9 /src/main/scala/firrtl/options | |
| parent | 254e7909f6c9d155f514664584f142566f0a6799 (diff) | |
OptionsView/Viewer typeclass canonicalizations
This switches the OptionsView/Viewer typeclass to use more canonical
approaches and helper methods. This uses a context bound instead of an
explicitly specified implicit argument. Additionally, this adds an
apply method to OptionsView to enable more canonical use of the
OptionsView typeclass.
With this, you can now do things like `Viewer[FirrtlOptions].view` in
addition to the old (and still available)
`Viewer.view[FirrtlOptions]`. Uses of the latter are updated to use
the former.
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src/main/scala/firrtl/options')
| -rw-r--r-- | src/main/scala/firrtl/options/OptionsView.scala | 9 | ||||
| -rw-r--r-- | src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/main/scala/firrtl/options/OptionsView.scala b/src/main/scala/firrtl/options/OptionsView.scala index 49417ded..4235b660 100644 --- a/src/main/scala/firrtl/options/OptionsView.scala +++ b/src/main/scala/firrtl/options/OptionsView.scala @@ -19,11 +19,16 @@ trait OptionsView[T] { /** A shim to manage multiple "views" of an [[firrtl.AnnotationSeq AnnotationSeq]] */ object Viewer { + /** Helper method to get at a given [[OptionsView]]. This enables access to [[OptionsView]] methods in a more canonical + * format, e.g., you can then do `Viewer[T].view`. + * @param a an implicit [[OptionsView]] + */ + def apply[T](implicit a: OptionsView[T]): OptionsView[T] = a + /** Convert annotations to options using an implicitly provided [[OptionsView]] * @param options some annotations - * @param optionsView a converter of options to the requested type * @tparam T the type to which the input [[firrtl.AnnotationSeq AnnotationSeq]] should be viewed as */ - def view[T](options: AnnotationSeq)(implicit optionsView: OptionsView[T]): T = optionsView.view(options) + def view[T: OptionsView](options: AnnotationSeq): T = Viewer[T].view(options) } diff --git a/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala b/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala index 66f40d3c..bb2a8cd6 100644 --- a/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala +++ b/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala @@ -15,7 +15,7 @@ class WriteOutputAnnotations extends Phase { /** Write the input [[AnnotationSeq]] to a fie. */ def transform(annotations: AnnotationSeq): AnnotationSeq = { - val sopts = Viewer.view[StageOptions](annotations) + val sopts = Viewer[StageOptions].view(annotations) val serializable = annotations.filter{ case _: Unserializable => false case _: DeletedAnnotation => sopts.writeDeleted |
