Skip to content

Commit

Permalink
Use BufferedCustomFileEmission in CircuitSerializationAnnotation
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkoenig committed Aug 23, 2021
1 parent 62b8c1b commit 9eda63c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/main/scala/chisel3/stage/ChiselAnnotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package chisel3.stage

import firrtl.annotations.{Annotation, NoTargetAnnotation}
import firrtl.options.{CustomFileEmission, HasShellOptions, OptionsException, ShellOption, StageOptions, Unserializable}
import firrtl.options.{BufferedCustomFileEmission, CustomFileEmission, HasShellOptions, OptionsException, ShellOption, StageOptions, Unserializable}
import firrtl.options.Viewer.view
import chisel3.{ChiselException, Module}
import chisel3.RawModule
Expand Down Expand Up @@ -123,7 +123,7 @@ import CircuitSerializationAnnotation._
*/
case class CircuitSerializationAnnotation(circuit: Circuit, filename: String, format: Format)
extends NoTargetAnnotation
with CustomFileEmission {
with BufferedCustomFileEmission {
/* Caching the hashCode for a large circuit is necessary due to repeated queries.
* Not caching the hashCode will cause severe performance degredations for large [[Circuit]]s.
*/
Expand All @@ -133,17 +133,16 @@ case class CircuitSerializationAnnotation(circuit: Circuit, filename: String, fo

protected def suffix: Option[String] = Some(format.extension)

override def getBytes: Iterable[Byte] = format match {
override def getBytesBuffered: Iterable[Array[Byte]] = format match {
case FirrtlFileFormat =>
OldEmitter.emitLazily(circuit)
.map(_.getBytes)
.flatten
// TODO Use lazy Iterables so that we don't have to materialize full intermediate data structures
case ProtoBufFileFormat =>
val ostream = new java.io.ByteArrayOutputStream
val modules = circuit.components.map(m => () => chisel3.internal.firrtl.Converter.convert(m))
firrtl.proto.ToProto.writeToStreamFast(ostream, firrtl.ir.NoInfo, modules, circuit.name)
ostream.toByteArray
List(ostream.toByteArray)
}
}

Expand Down

0 comments on commit 9eda63c

Please sign in to comment.