blob: 01d2a4d4c1013fc2031eb9c1b1b0524c3cb0fdd5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// SPDX-License-Identifier: Apache-2.0
package firrtl.options
import firrtl.AnnotationSeq
/** Type class defining a "view" of an [[firrtl.AnnotationSeq AnnotationSeq]]
* @tparam T the type to which this viewer converts an [[firrtl.AnnotationSeq AnnotationSeq]] to
*/
trait OptionsView[T] {
/** Convert an [[firrtl.AnnotationSeq AnnotationSeq]] to some other type
* @param options some annotations
*/
def view(options: AnnotationSeq): 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
* @tparam T the type to which the input [[firrtl.AnnotationSeq AnnotationSeq]] should be viewed as
*/
def view[T: OptionsView](options: AnnotationSeq): T = Viewer[T].view(options)
}
|