diff options
| author | Jack Koenig | 2020-08-12 21:17:14 -0700 |
|---|---|---|
| committer | GitHub | 2020-08-13 04:17:14 +0000 |
| commit | 39f510a9081d09d94d56eb89ceb97a678993fda1 (patch) | |
| tree | 02dcadb37c768d5763f6eae87b84b5aeeead6df1 /src/main/scala/firrtl/annotations | |
| parent | e1d3a0c64a48b4c9999ad59f15922db7c155c361 (diff) | |
Remove LegacyAnnotation and [most] MoultingYaml (#1833)
* Remove LegacyAnnotation and MoultingYaml
It has been deprecated since 1.1
* Remove all uses of ConvertLegacyAnnotations
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'src/main/scala/firrtl/annotations')
3 files changed, 1 insertions, 175 deletions
diff --git a/src/main/scala/firrtl/annotations/Annotation.scala b/src/main/scala/firrtl/annotations/Annotation.scala index 3e58a0d7..a382f685 100644 --- a/src/main/scala/firrtl/annotations/Annotation.scala +++ b/src/main/scala/firrtl/annotations/Annotation.scala @@ -127,130 +127,7 @@ trait MultiTargetAnnotation extends Annotation { def flat(): AnnotationSeq = crossJoin(targets).map(r => duplicate(r.map(Seq(_)))) } -@deprecated("Just extend NoTargetAnnotation", "1.1") -trait SingleStringAnnotation extends NoTargetAnnotation { - def value: String -} - -object Annotation { - @deprecated("This returns a LegacyAnnotation, use an explicit Annotation type", "1.1") - def apply(target: Named, transform: Class[_ <: Transform], value: String): LegacyAnnotation = - new LegacyAnnotation(target, transform, value) - @deprecated("This uses LegacyAnnotation, use an explicit Annotation type", "1.1") - def unapply(a: LegacyAnnotation): Option[(Named, Class[_ <: Transform], String)] = - Some((a.target, a.transform, a.value)) -} - -// Constructor is private so that we can still construct these internally without deprecation -// warnings -final case class LegacyAnnotation private[firrtl] ( - target: Named, - transform: Class[_ <: Transform], - value: String) extends SingleTargetAnnotation[Named] { - val targetString: String = target.serialize - val transformClass: String = transform.getName - - def targets(named: Named): Boolean = named == target - def targets(transform: Class[_ <: Transform]): Boolean = transform == this.transform - - /** - * This serialize is basically a pretty printer, actual serialization is handled by - * AnnotationYamlProtocol - * @return a nicer string than the raw case class default - */ - override def serialize: String = { - s"Annotation(${target.serialize},${transform.getCanonicalName},$value)" - } - - def update(tos: Seq[Named]): Seq[Annotation] = { - check(target, tos, this) - propagate(target, tos, duplicate) - } - def propagate(from: Named, tos: Seq[Named], dup: Named=>Annotation): Seq[Annotation] = tos.map(dup(_)) - def check(from: Named, tos: Seq[Named], which: Annotation): Unit = {} - def duplicate(n: Named): LegacyAnnotation = new LegacyAnnotation(n, transform, value) -} - -// Private so that LegacyAnnotation can only be constructed via deprecated Annotation.apply -private[firrtl] object LegacyAnnotation { - // ***** Everything below here is to help people migrate off of old annotations ***** - def errorIllegalAnno(name: String): Annotation = - throw new Exception(s"Old-style annotations that look like $name are no longer supported") - - private val OldDeletedRegex = """(?s)DELETED by ([^\n]*)\n(.*)""".r - private val PinsRegex = "pins:(.*)".r - private val SourceRegex = "source (.+)".r - private val SinkRegex = "sink (.+)".r - - import firrtl.transforms._ - import firrtl.passes._ - import firrtl.passes.memlib._ - import firrtl.passes.wiring._ - import firrtl.passes.clocklist._ - - // Attempt to convert common Annotations and error on the rest of old-style build-in annotations - def convertLegacyAnno(anno: LegacyAnnotation): Annotation = anno match { - // All old-style Emitter annotations are illegal - case LegacyAnnotation(_,_,"emitCircuit") => errorIllegalAnno("EmitCircuitAnnotation") - case LegacyAnnotation(_,_,"emitAllModules") => errorIllegalAnno("EmitAllModulesAnnotation") - case LegacyAnnotation(_,_,value) if value.startsWith("emittedFirrtlCircuit") => - errorIllegalAnno("EmittedFirrtlCircuitAnnotation") - case LegacyAnnotation(_,_,value) if value.startsWith("emittedFirrtlModule") => - errorIllegalAnno("EmittedFirrtlModuleAnnotation") - case LegacyAnnotation(_,_,value) if value.startsWith("emittedVerilogCircuit") => - errorIllegalAnno("EmittedVerilogCircuitAnnotation") - case LegacyAnnotation(_,_,value) if value.startsWith("emittedVerilogModule") => - errorIllegalAnno("EmittedVerilogModuleAnnotation") - // People shouldn't be trying to pass deleted annotations to Firrtl - case LegacyAnnotation(_,_,OldDeletedRegex(_,_)) => errorIllegalAnno("DeletedAnnotation") - // Some annotations we'll try to support - case LegacyAnnotation(named, t, _) if t == classOf[InlineInstances] => InlineAnnotation(named) - case LegacyAnnotation(n: ModuleName, t, outputConfig) if t == classOf[ClockListTransform] => - ClockListAnnotation(n, outputConfig) - case LegacyAnnotation(CircuitName(_), transform, "") if transform == classOf[InferReadWrite] => - InferReadWriteAnnotation - case LegacyAnnotation(_,_,PinsRegex(pins)) => PinAnnotation(pins.split(" ")) - case LegacyAnnotation(_, t, value) if t == classOf[ReplSeqMem] => - val args = value.split(" ") - require(args.size == 2, "Something went wrong, stop using legacy ReplSeqMemAnnotation") - ReplSeqMemAnnotation(args(0), args(1)) - case LegacyAnnotation(c: ComponentName, transform, "nodedupmem!") - if transform == classOf[ResolveMemoryReference] => NoDedupMemAnnotation(c) - case LegacyAnnotation(m: ModuleName, transform, "nodedup!") - if transform == classOf[DedupModules] => NoDedupAnnotation(m) - case LegacyAnnotation(c: ComponentName, _, SourceRegex(pin)) => SourceAnnotation(c, pin) - case LegacyAnnotation(n, _, SinkRegex(pin)) => SinkAnnotation(n, pin) - case LegacyAnnotation(m: ModuleName, t, text) if t == classOf[BlackBoxSourceHelper] => - val nArgs = 3 - text.split("\n", nArgs).toList match { - case "resource" :: id :: _ => BlackBoxResourceAnno(m, id) - case "inline" :: name :: text :: _ => BlackBoxInlineAnno(m, name, text) - case "targetDir" :: targetDir :: _ => BlackBoxTargetDirAnno(targetDir) - case _ => errorIllegalAnno("BlackBoxSourceAnnotation") - } - case LegacyAnnotation(_, transform, "noDCE!") if transform == classOf[DeadCodeElimination] => - NoDCEAnnotation - case LegacyAnnotation(c: ComponentName, _, "DONTtouch!") => DontTouchAnnotation(c.toTarget) - case LegacyAnnotation(c: ModuleName, _, "optimizableExtModule!") => - OptimizableExtModuleAnnotation(c) - case other => other - } - def convertLegacyAnnos(annos: AnnotationSeq): AnnotationSeq = { - var warned: Boolean = false - annos.map { - case legacy: LegacyAnnotation => - val annox = convertLegacyAnno(legacy) - if (!warned && (annox ne legacy)) { - val msg = s"A LegacyAnnotation was automatically converted.\n" + (" "*9) + - "This functionality will soon be removed. Please migrate to new annotations." - StageUtils.dramaticWarning(msg) - warned = true - } - annox - case other => other - } - } -} +object Annotation case class DeletedAnnotation(xFormName: String, anno: Annotation) extends NoTargetAnnotation { override def serialize: String = s"""DELETED by $xFormName\n${anno.serialize}""" diff --git a/src/main/scala/firrtl/annotations/AnnotationUtils.scala b/src/main/scala/firrtl/annotations/AnnotationUtils.scala index 52b18400..58cc0097 100644 --- a/src/main/scala/firrtl/annotations/AnnotationUtils.scala +++ b/src/main/scala/firrtl/annotations/AnnotationUtils.scala @@ -5,10 +5,6 @@ package annotations import java.io.File - -import net.jcazevedo.moultingyaml._ -import firrtl.annotations.AnnotationYamlProtocol._ - import firrtl.ir._ case class InvalidAnnotationFileException(file: File, cause: FirrtlUserException = null) @@ -22,8 +18,6 @@ case class AnnotationClassNotFoundException(className: String) extends FirrtlUse ) object AnnotationUtils { - def toYaml(a: LegacyAnnotation): String = a.toYaml.prettyPrint - def fromYaml(s: String): LegacyAnnotation = s.parseYaml.convertTo[LegacyAnnotation] /** Returns true if a valid Module name */ val SerializedModuleName = """([a-zA-Z_][a-zA-Z_0-9~!@#$%^*\-+=?/]*)""".r diff --git a/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala b/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala deleted file mode 100644 index 4bb643b3..00000000 --- a/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala +++ /dev/null @@ -1,45 +0,0 @@ -// See LICENSE for license details. - -package firrtl -package annotations - -import net.jcazevedo.moultingyaml._ - -object AnnotationYamlProtocol extends DefaultYamlProtocol { - // bottom depends on top - implicit object AnnotationYamlFormat extends YamlFormat[LegacyAnnotation] { - def write(a: LegacyAnnotation) = YamlObject( - YamlString("targetString") -> YamlString(a.targetString), - YamlString("transformClass") -> YamlString(a.transformClass), - YamlString("value") -> YamlString(a.value) - ) - - def read(yamlValue: YamlValue): LegacyAnnotation = { - try { - yamlValue.asYamlObject.getFields( - YamlString("targetString"), - YamlString("transformClass"), - YamlString("value")) match { - case Seq(YamlString(targetString), YamlString(transformClass), YamlString(value)) => - LegacyAnnotation(toTarget(targetString), - Class.forName(transformClass).asInstanceOf[Class[_ <: Transform]], - value) - case _ => deserializationError("LegacyAnnotation expected") - } - } - catch { - case annotationException: AnnotationException => - Utils.error( - s"Error: ${annotationException.getMessage} while parsing annotation from yaml\n${yamlValue.prettyPrint}") - } - } - 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 => Utils.error("BAD") - case s => - val componentString = s.drop(2).mkString(".") - ComponentName(componentString, ModuleName(s.tail.head, CircuitName(s.head))) - } - } -} |
