From 9911b3467de2ebe92827ddc3288bd6db477cc636 Mon Sep 17 00:00:00 2001 From: Jim Lawson Date: Mon, 18 Mar 2019 15:20:51 -0700 Subject: Add serialization support for LoadMemoryFileType in LoadMemoryAnnotation (#1056) * Add serialization support for LoadMemoryFileType in LoadMemoryAnnotation Add custom LoadMemoryFileTypeSerializer. Add test to verify LoadMemoryAnnotation can be correctly serialized/deserialized. * Simplify and focus LoadMemoryAnnotation serialization/deserialization. Respond to comments on earlier implementations. * Add type FileType definition for current chisel3 code. --- .../firrtl/annotations/LoadMemoryAnnotation.scala | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala') diff --git a/src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala b/src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala index c5dae954..c52bf5f6 100644 --- a/src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala +++ b/src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala @@ -4,13 +4,25 @@ package firrtl.annotations import java.io.File -/** Enumeration of the two types of `readmem` statements available in Verilog. +import firrtl.FIRRTLException + +/** Representation of the two types of `readmem` statements available in Verilog. */ -object MemoryLoadFileType extends Enumeration { - type FileType = Value +sealed abstract class MemoryLoadFileType(val value: String) { + def serialize: String = value +} - val Hex: Value = Value("h") - val Binary: Value = Value("b") +object MemoryLoadFileType { + // purely for backwards compatibility with chisel3's ChiselLoadMemoryAnnotation + type FileType = MemoryLoadFileType + + case object Hex extends MemoryLoadFileType("h") + case object Binary extends MemoryLoadFileType("b") + def deserialize(s: String): MemoryLoadFileType = s match { + case "h" => MemoryLoadFileType.Hex + case "b" => MemoryLoadFileType.Binary + case _ => throw new FIRRTLException(s"Unrecognized MemoryLoadFileType: $s") + } } /** Firrtl implementation for load memory @@ -21,7 +33,7 @@ object MemoryLoadFileType extends Enumeration { case class LoadMemoryAnnotation( target: ComponentName, fileName: String, - hexOrBinary: MemoryLoadFileType.FileType = MemoryLoadFileType.Hex, + hexOrBinary: MemoryLoadFileType = MemoryLoadFileType.Hex, originalMemoryNameOpt: Option[String] = None ) extends SingleTargetAnnotation[Named] { -- cgit v1.2.3