This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 178
File Serialization of Annotations #1277
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3461fde
Transform, not run in LegalizeAndReduction test
seldridge ba58d7e
Use execute in FIRRTL testing infra (not run)
seldridge 2a80aa7
Add HowToSerialize Annotation mix-in
seldridge 9d4645d
Handle HowToSerialize in WriteOutputAnnotations
seldridge 4efe0c9
Test HowToSerialize in WriteOutputAnnotationsSpec
seldridge 71c27e3
[skip chisel tests] Migrate to HowToSerialize
seldridge 0a2d545
Deprecated firrtl.stage.phases.WriteEmitted
seldridge a128b50
Use streams in HowToSerialize
seldridge 0ca9d6d
Switch from Stream[Char] to Stream[Byte]
seldridge c10739c
Change howToSerialize method to Iterable
seldridge 9dc7a2e
Add Scaladoc to HowToSerialize trait
seldridge 69a7f98
Change HowToSerialize to CustomFileEmission
seldridge 74c1f10
Add default implementation of replacements
seldridge fa6999d
Avoid unnecessary 2x monad in CustomFileEmission
seldridge 67e9eec
Restrict CustomFileEmission filename API
seldridge abdb67c
Add file conflict behavior for CustomFileEmission
seldridge 019f8bf
Return relative path from getBuildFileName
seldridge 5cca338
Normalize paths in StageOptions.getBuildFile
seldridge c70c4f4
Refer to CustomFIleEmission in deprecation message
seldridge 59cc4a8
Simplify CustomFileEmission toBytes implementation
seldridge 5010149
Use toBytes, not getBytes, in CustomFileEmission
seldridge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -4,6 +4,9 @@ package firrtl.options | |
|
||
import firrtl.AnnotationSeq | ||
import firrtl.annotations.{Annotation, NoTargetAnnotation} | ||
import firrtl.options.Viewer.view | ||
|
||
import java.io.File | ||
|
||
import scopt.OptionParser | ||
|
||
|
@@ -14,6 +17,63 @@ sealed trait StageOption { this: Annotation => } | |
*/ | ||
trait Unserializable { this: Annotation => } | ||
|
||
/** Mix-in that lets an [[firrtl.annotations.Annotation Annotation]] serialize itself to a file separate from the output | ||
* annotation file. | ||
* | ||
* This can be used as a mechanism to serialize an [[firrtl.options.Unserializable Unserializable]] annotation or to | ||
* write ancillary collateral used by downstream tooling, e.g., a TCL script or an FPGA constraints file. Any | ||
* annotations using this mix-in will be serialized by the [[firrtl.options.phases.WriteOutputAnnotations | ||
* WriteOutputAnnotations]] phase. This is one of the last phases common to all [[firrtl.options.Stage Stages]] and | ||
* should not have to be called/included manually. | ||
* | ||
* Note: from the perspective of transforms generating annotations that mix-in this trait, the serialized files are not | ||
* expected to be available to downstream transforms. Communication of information between transforms must occur | ||
* through the annotations that will eventually be serialized to files. | ||
*/ | ||
trait CustomFileEmission { this: Annotation => | ||
|
||
/** Output filename where serialized content will be written | ||
* | ||
* The full annotation sequence is a parameter to allow for the location where this annotation will be serialized to | ||
* be a function of other annotations, e.g., if the location where information is written is controlled by a separate | ||
* file location annotation. | ||
* | ||
* @param annotations the annotation sequence at the time of emission | ||
*/ | ||
protected def baseFileName(annotations: AnnotationSeq): String | ||
Comment on lines
+35
to
+43
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. Just a thought, annotations that would serialize to the same filename could use this to disambiguate themselves. That is, they could see that others of the type exist and provide a disambiguation algorithm. |
||
|
||
/** Optional suffix of the output file */ | ||
protected def suffix: Option[String] | ||
|
||
/** A method that can convert this annotation to bytes that will be written to a file. | ||
* | ||
* If you only need to serialize a string, you can use the `getBytes` method: | ||
* {{{ | ||
* def getBytes: Iterable[Byte] = myString.getBytes | ||
* }}} | ||
*/ | ||
def getBytes: Iterable[Byte] | ||
|
||
/** Optionally, a sequence of annotations that will replace this annotation in the output annotation file. | ||
jackkoenig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* A non-empty implementation of this method is a mechanism for telling a downstream [[firrtl.options.Stage Stage]] | ||
* how to deserialize the information that was serialized to a separate file. For example, if a FIRRTL circuit is | ||
* serialized to a separate file, this method could include an input file annotation that a later stage can use to | ||
* read the serialized FIRRTL circuit back in. | ||
*/ | ||
def replacements(file: File): AnnotationSeq = Seq.empty | ||
jackkoenig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Method that returns the filename where this annotation will be serialized. | ||
* | ||
* @param annotations the annotations at the time of serialization | ||
*/ | ||
final def filename(annotations: AnnotationSeq): File = { | ||
val name = view[StageOptions](annotations).getBuildFileName(baseFileName(annotations), suffix) | ||
new File(name) | ||
} | ||
|
||
} | ||
|
||
/** Holds the name of the target directory | ||
* - set with `-td/--target-dir` | ||
* - if unset, a [[TargetDirAnnotation]] will be generated with the | ||
|
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't know why, but I didn't notice that this was just using the API here. Pretty slick :)