diff options
Diffstat (limited to 'src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala')
| -rw-r--r-- | src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala b/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala index 5da00282..9018d494 100644 --- a/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala +++ b/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala @@ -8,30 +8,40 @@ import net.jcazevedo.moultingyaml._ object AnnotationYamlProtocol extends DefaultYamlProtocol { // bottom depends on top implicit object AnnotationYamlFormat extends YamlFormat[Annotation] { - def write(a: Annotation) = - YamlArray( - YamlString(a.targetString), - YamlString(a.transformClass), - YamlString(a.value)) + def write(a: Annotation) = YamlObject( + YamlString("targetString") -> YamlString(a.targetString), + YamlString("transformClass") -> YamlString(a.transformClass), + YamlString("value") -> YamlString(a.value) + ) - def read(value: YamlValue) = { - value.asYamlObject.getFields( - YamlString("targetString"), - YamlString("transformClass"), - YamlString("value")) match { - case Seq( - YamlString(targetString), - YamlString(transformClass), - YamlString(value)) => - new Annotation(toTarget(targetString), Class.forName(transformClass).asInstanceOf[Class[_ <: Transform]], value) - case _ => deserializationError("Color expected") + def read(yamlValue: YamlValue): Annotation = { + try { + yamlValue.asYamlObject.getFields( + YamlString("targetString"), + YamlString("transformClass"), + YamlString("value")) match { + case Seq(YamlString(targetString), YamlString(transformClass), YamlString(value)) => + Annotation( + toTarget(targetString), Class.forName(transformClass).asInstanceOf[Class[_ <: Transform]], value) + case _ => deserializationError("Annotation expected") + } + } + catch { + case annotationException: AnnotationException => + Utils.error( + s"Error: ${annotationException.getMessage} while parsing annotation from yaml\n${yamlValue.prettyPrint}") + case annotationException: FIRRTLException => + Utils.error( + s"Error: ${annotationException.getMessage} while parsing annotation from yaml\n${yamlValue.prettyPrint}") } } - def toTarget(string: String) = string.split('.').toSeq match { + def toTarget(string: String): Named = string.split("""\.""", -1).toSeq match { case Seq(c) => CircuitName(c) case Seq(c, m) => ModuleName(m, CircuitName(c)) - case Nil => error("BAD") - case s => ComponentName(s.drop(2).mkString("."), ModuleName(s(1), CircuitName(s(0)))) + case Nil => Utils.error("BAD") + case s => + val componentString = s.drop(2).mkString(".") + ComponentName(componentString, ModuleName(s.tail.head, CircuitName(s.head))) } } } |
