-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add safer Chisel annotation API, deprecate old ones #4643
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,12 @@ | |
|
||
package chisel3.experimental | ||
|
||
import scala.annotation.nowarn | ||
import chisel3._ | ||
import firrtl.annotations._ | ||
|
||
// Rather than refactoring the annotation work here, we should just remove ChiselEnum annotations | ||
@nowarn("msg=Avoid custom annotations") | ||
object EnumAnnotations { | ||
|
||
/** An annotation for strong enum instances that are ''not'' inside of Vecs | ||
|
@@ -16,6 +19,10 @@ object EnumAnnotations { | |
def duplicate(n: Named): EnumComponentAnnotation = this.copy(target = n) | ||
} | ||
|
||
@deprecated( | ||
"Avoid custom annotations. If you must use annotations, new annotate.apply method that takes Data", | ||
"Chisel 7.0" | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong deprecation message, just deprecate the annotation. |
||
) | ||
case class EnumComponentChiselAnnotation(target: InstanceId, enumTypeName: String) extends ChiselAnnotation { | ||
def toFirrtl: EnumComponentAnnotation = EnumComponentAnnotation(target.toNamed, enumTypeName) | ||
} | ||
|
@@ -45,6 +52,10 @@ object EnumAnnotations { | |
def duplicate(n: Named): EnumVecAnnotation = this.copy(target = n) | ||
} | ||
|
||
@deprecated( | ||
"Avoid custom annotations. If you must use annotations, new annotate.apply method that takes Data", | ||
"Chisel 7.0" | ||
) | ||
case class EnumVecChiselAnnotation(target: InstanceId, typeName: String, fields: Seq[Seq[String]]) | ||
extends ChiselAnnotation { | ||
override def toFirrtl: EnumVecAnnotation = EnumVecAnnotation(target.toNamed, typeName, fields) | ||
|
@@ -57,6 +68,10 @@ object EnumAnnotations { | |
*/ | ||
case class EnumDefAnnotation(typeName: String, definition: Map[String, BigInt]) extends NoTargetAnnotation | ||
|
||
@deprecated( | ||
"Avoid custom annotations. If you must use annotations, new annotate.apply method that takes Data", | ||
"Chisel 7.0" | ||
) | ||
case class EnumDefChiselAnnotation(typeName: String, definition: Map[String, BigInt]) extends ChiselAnnotation { | ||
override def toFirrtl: Annotation = EnumDefAnnotation(typeName, definition) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -568,50 +568,16 @@ private[chisel3] object ir { | |
case class DefClass(id: Class, name: String, ports: Seq[Port], block: Block) extends Component | ||
|
||
case class Circuit( | ||
name: String, | ||
components: Seq[Component], | ||
annotations: Seq[ChiselAnnotation], | ||
renames: RenameMap, | ||
newAnnotations: Seq[ChiselMultiAnnotation], | ||
typeAliases: Seq[DefTypeAlias], | ||
layers: Seq[Layer], | ||
options: Seq[DefOption] | ||
name: String, | ||
components: Seq[Component], | ||
annotations: Seq[() => Seq[Annotation]], | ||
renames: RenameMap, | ||
typeAliases: Seq[DefTypeAlias], | ||
layers: Seq[Layer], | ||
options: Seq[DefOption] | ||
) { | ||
|
||
def this( | ||
name: String, | ||
components: Seq[Component], | ||
annotations: Seq[ChiselAnnotation], | ||
renames: RenameMap, | ||
typeAliases: Seq[DefTypeAlias], | ||
layers: Seq[Layer], | ||
options: Seq[DefOption] | ||
) = | ||
this(name, components, annotations, renames, Seq.empty, typeAliases, layers, options) | ||
|
||
def firrtlAnnotations: Iterable[Annotation] = | ||
annotations.flatMap(_.toFirrtl.update(renames)) ++ newAnnotations.flatMap( | ||
_.toFirrtl.flatMap(_.update(renames)) | ||
) | ||
} | ||
|
||
object Circuit | ||
extends scala.runtime.AbstractFunction7[String, Seq[Component], Seq[ChiselAnnotation], RenameMap, Seq[ | ||
DefTypeAlias | ||
], Seq[Layer], Seq[DefOption], Circuit] { | ||
def unapply(c: Circuit): Option[(String, Seq[Component], Seq[ChiselAnnotation], RenameMap, Seq[DefTypeAlias])] = { | ||
Some((c.name, c.components, c.annotations, c.renames, c.typeAliases)) | ||
} | ||
|
||
def apply( | ||
name: String, | ||
components: Seq[Component], | ||
annotations: Seq[ChiselAnnotation], | ||
Comment on lines
-598
to
-609
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of this was left over from previous needs to maintain binary compatibility. These APIs are all package private now so we can just delete them. |
||
renames: RenameMap, | ||
typeAliases: Seq[DefTypeAlias] = Seq.empty, | ||
layers: Seq[Layer] = Seq.empty, | ||
options: Seq[DefOption] = Seq.empty | ||
): Circuit = | ||
new Circuit(name, components, annotations, renames, typeAliases, layers, options) | ||
annotations.flatMap(_().flatMap(_.update(renames))) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to do this which directly passes the
targets
to the annotation construction function directly?For this to work, an
Annotation
(or a subclass of) would need to have a constructor that can build it from anInstanceId
(or aData
).I'm primarily worried about there being no check of the connection between the
targets
and themkAnnos
function as a user could put in incorrect targets or ignore them entirely to get the old, legacy behavior.Can you think of a way to untangle this?