Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Use toBytes, not getBytes, in CustomFileEmission
Browse files Browse the repository at this point in the history
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
  • Loading branch information
seldridge committed Aug 11, 2020
1 parent 59cc4a8 commit 5010149
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/firrtl/Emitter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ sealed trait EmittedAnnotation[T <: EmittedComponent] extends NoTargetAnnotation
}
sealed trait EmittedCircuitAnnotation[T <: EmittedCircuit] extends EmittedAnnotation[T] {

override def toBytes = Some(value.value.getBytes)
override def getBytes = value.value.getBytes

}
sealed trait EmittedModuleAnnotation[T <: EmittedModule] extends EmittedAnnotation[T] {

override def toBytes = Some(value.value.getBytes)
override def getBytes = value.value.getBytes

}

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/firrtl/options/StageAnnotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ trait CustomFileEmission { this: Annotation =>
*
* If you only need to serialize a string, you can use the `getBytes` method:
* {{{
* def toBytes: Option[Iterable[Byte]] = Some(myString.getBytes)
* def getBytes: Iterable[Byte] = myString.getBytes
* }}}
*/
def toBytes: Option[Iterable[Byte]]
def getBytes: Iterable[Byte]

/** Optionally, a sequence of annotations that will replace this annotation in the output annotation file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class WriteOutputAnnotations extends Phase {
val filename = a.filename(annotations)
val canonical = filename.getCanonicalPath()

(a.toBytes, filesWritten.get(canonical)) match {
case (Some(x), None) =>
filesWritten.get(canonical) match {
case None =>
val w = new BufferedWriter(new FileWriter(filename))
x.foreach( w.write(_) )
a.getBytes.foreach( w.write(_) )
w.close()
filesWritten(canonical) = a
case (Some(_), Some(first)) =>
case Some(first) =>
val msg =
s"""|Multiple CustomFileEmission annotations would be serialized to the same file, '$canonical'
| - first writer:
Expand All @@ -53,7 +53,6 @@ class WriteOutputAnnotations extends Phase {
| trimmed serialization: ${a.serialize.take(80)}
|""".stripMargin
throw new PhaseException(msg)
case (None, _) =>
}
a.replacements(filename)
case a => Some(a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private object WriteOutputAnnotationsSpec {

override protected def suffix: Option[String] = Some(".Emission")

override def toBytes: Option[Iterable[Byte]] = Some(value.getBytes)
override def getBytes: Iterable[Byte] = value.getBytes

override def replacements(file: File): AnnotationSeq = Seq(Replacement(file.toString))

Expand Down

0 comments on commit 5010149

Please sign in to comment.