Skip to content

Commit

Permalink
add enum annotation definitions (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Sep 6, 2023
1 parent 6c72ca6 commit 6f14ed8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/main/scala/firrtl2/annotations/EnumAnnotations.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: Apache-2.0

package firrtl2.annotations

/** An annotation for strong enum instances that are ''not'' inside of Vecs
*
* @param target the enum instance being annotated
* @param enumTypeName the name of the enum's type (e.g. ''"mypackage.MyEnum"'')
*/
case class EnumComponentAnnotation(target: Named, enumTypeName: String) extends SingleTargetAnnotation[Named] {
def duplicate(n: Named): EnumComponentAnnotation = this.copy(target = n)
}

/** An annotation for Vecs of strong enums.
*
* The ''fields'' parameter deserves special attention, since it may be difficult to understand. Suppose you create a the following Vec:
*
* {{{
* VecInit(new Bundle {
* val e = MyEnum()
* val b = new Bundle {
* val inner_e = MyEnum()
* }
* val v = Vec(3, MyEnum())
* }
* }}}
*
* Then, the ''fields'' parameter will be: ''Seq(Seq("e"), Seq("b", "inner_e"), Seq("v"))''. Note that for any Vec that doesn't contain Bundles, this field will simply be an empty Seq.
*
* @param target the Vec being annotated
* @param typeName the name of the enum's type (e.g. ''"mypackage.MyEnum"'')
* @param fields a list of all chains of elements leading from the Vec instance to its inner enum fields.
*/
case class EnumVecAnnotation(target: Named, typeName: String, fields: Seq[Seq[String]])
extends SingleTargetAnnotation[Named] {
def duplicate(n: Named): EnumVecAnnotation = this.copy(target = n)
}

/** An annotation for enum types (rather than enum ''instances'').
*
* @param typeName the name of the enum's type (e.g. ''"mypackage.MyEnum"'')
* @param definition a map describing which integer values correspond to which enum names
*/
case class EnumDefAnnotation(typeName: String, definition: Map[String, BigInt]) extends NoTargetAnnotation

0 comments on commit 6f14ed8

Please sign in to comment.