aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/options/OptionsView.scala
diff options
context:
space:
mode:
authorSchuyler Eldridge2019-02-02 20:54:06 -0500
committerSchuyler Eldridge2019-04-25 16:24:15 -0400
commit47fe781c4ace38dff7f31da7e78f772e131d689e (patch)
treeec4b11c4a556d7a354efbe6dcc7be51fba44e2f9 /src/main/scala/firrtl/options/OptionsView.scala
parent254e7909f6c9d155f514664584f142566f0a6799 (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/OptionsView.scala')
-rw-r--r--src/main/scala/firrtl/options/OptionsView.scala9
1 files changed, 7 insertions, 2 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)
}