aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/options/OptionsView.scala
diff options
context:
space:
mode:
authorSchuyler Eldridge2018-08-22 15:22:20 -0400
committerSchuyler Eldridge2018-11-07 13:24:23 -0500
commite0951fef346c4e3e2d19a57b396012e9800b69b6 (patch)
tree54bd309d7234de5d221aa569230c517f6b7b745c /src/main/scala/firrtl/options/OptionsView.scala
parentd04af59c233cec994087df3d0d3fff14e20ac04c (diff)
Add firrtl.options
This adds a new package, "firrtl.options", that provides a framework for working with options inside and outside FIRRTL. Small changes: - Make TerminateOnExit return the correct exit code - Deprecate mutable TerminateOnExit - Add immutable DoNotTermianteOnExit 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.scala27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/options/OptionsView.scala b/src/main/scala/firrtl/options/OptionsView.scala
new file mode 100644
index 00000000..dade5c56
--- /dev/null
+++ b/src/main/scala/firrtl/options/OptionsView.scala
@@ -0,0 +1,27 @@
+// See LICENSE for license details.
+
+package firrtl.options
+
+import firrtl.AnnotationSeq
+
+/** Type class defining a "view" of an [[AnnotationSeq]]
+ * @tparam T the type to which this viewer converts an [[AnnotationSeq]] to
+ */
+trait OptionsView[T] {
+
+ /** Convert an [[AnnotationSeq]] to some other type
+ * @param options some annotations
+ */
+ def view(options: AnnotationSeq): Option[T]
+}
+
+/** A shim to manage multiple "views" of an [[AnnotationSeq]] */
+object Viewer {
+
+ /** 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 [[AnnotationSeq]] should be viewed as
+ */
+ def view[T](options: AnnotationSeq)(implicit optionsView: OptionsView[T]): Option[T] = optionsView.view(options)
+}