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

Commit

Permalink
Use streams in HowToSerialize
Browse files Browse the repository at this point in the history
This converts the HowToSerialize trait to use a Stream[Char] when
defining how an annotation should be serialized.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
  • Loading branch information
seldridge committed Dec 23, 2019
1 parent 72c021d commit d9bb111
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 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 @@ -106,7 +106,7 @@ sealed trait EmittedAnnotation[T <: EmittedComponent] extends NoTargetAnnotation
}
sealed trait EmittedCircuitAnnotation[T <: EmittedCircuit] extends EmittedAnnotation[T] {

override def howToSerialize: Option[String] = Some(value.value)
override def howToSerialize: Option[Stream[Char]] = Some(new StringBuilder(value.value).toStream)

override def filename(annotations: AnnotationSeq): File = {
val sopts = view[StageOptions](annotations)
Expand All @@ -117,7 +117,7 @@ sealed trait EmittedCircuitAnnotation[T <: EmittedCircuit] extends EmittedAnnota
}
sealed trait EmittedModuleAnnotation[T <: EmittedModule] extends EmittedAnnotation[T] {

override def howToSerialize: Option[String] = Some(value.value)
override def howToSerialize: Option[Stream[Char]] = Some(new StringBuilder(value.value).toStream)

override def howToResume(file: File): Option[AnnotationSeq] = None

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/firrtl/options/StageAnnotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ trait HowToSerialize { this: Annotation =>

protected def suffix: Option[String]

def howToSerialize: Option[String]
def howToSerialize: Option[Stream[Char]]

def howToResume(file: File): Option[AnnotationSeq]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import firrtl.AnnotationSeq
import firrtl.annotations.{DeletedAnnotation, JsonProtocol}
import firrtl.options.{HowToSerialize, Phase, StageOptions, Unserializable, Viewer}

import java.io.PrintWriter
import java.io.{BufferedWriter, FileWriter, PrintWriter}

/** [[firrtl.options.Phase Phase]] that writes an [[AnnotationSeq]] to a file. A file is written if and only if a
* [[StageOptions]] view has a non-empty [[StageOptions.annotationFileOut annotationFileOut]].
Expand All @@ -22,9 +22,9 @@ class WriteOutputAnnotations extends Phase {
case a: HowToSerialize =>
val filename = a.filename(annotations)
a.howToSerialize.map { str =>
val pw = new PrintWriter(filename)
pw.write(str)
pw.close()
val w = new BufferedWriter(new FileWriter(filename))
str.foreach( w.write(_) )
w.close()
}
a.howToResume(filename) match {
case Some(a) => a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private object WriteOutputAnnotationsSpec {

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

override def howToSerialize: Option[String] = Some(value)
override def howToSerialize: Option[Stream[Char]] = Some(new StringBuilder(value).toStream)

override def howToResume(file: File): Option[AnnotationSeq] = Some(Seq(HowToFindMe(file.toString)))

Expand Down

0 comments on commit d9bb111

Please sign in to comment.