-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add enum annotation definitions (#27)
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |