diff options
| author | Jack Koenig | 2018-02-28 17:40:53 -0800 |
|---|---|---|
| committer | GitHub | 2018-02-28 17:40:53 -0800 |
| commit | 46553432aaf65cff131e59081d57dabe16c2ab55 (patch) | |
| tree | 2a64125046b36808a5a89c18f98204394c27ccd8 /src/main | |
| parent | 97871178cb511063965f971b768f91c289c4776f (diff) | |
Refactor Annotations (#767)
* Generalize ChiselAnnotation
This allows us to delay creation of Annotations till elaboration is
complete. Also update all annotation-related code.
* Add RunFirrtlTransform
Use a Chisel-specific RunFirrtlTransform API to preserve behavior of old
ChiselAnnotation (now called ChiselLegacyAnnotation)
* Use unique test directories in ChiselRunners.compile
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/scala/chisel3/Driver.scala | 22 | ||||
| -rw-r--r-- | src/main/scala/chisel3/package.scala | 3 | ||||
| -rw-r--r-- | src/main/scala/chisel3/util/BlackBoxUtils.scala | 17 |
3 files changed, 27 insertions, 15 deletions
diff --git a/src/main/scala/chisel3/Driver.scala b/src/main/scala/chisel3/Driver.scala index dae921ab..25d25425 100644 --- a/src/main/scala/chisel3/Driver.scala +++ b/src/main/scala/chisel3/Driver.scala @@ -3,13 +3,14 @@ package chisel3 import chisel3.internal.firrtl.Emitter -import chisel3.experimental.RawModule +import chisel3.experimental.{RawModule, RunFirrtlTransform} import java.io._ import net.jcazevedo.moultingyaml._ import internal.firrtl._ import firrtl._ +import firrtl.annotations.{Annotation, JsonProtocol} import firrtl.util.{ BackendCompilationUtilities => FirrtlBackendCompilationUtilities } import _root_.firrtl.annotations.AnnotationYamlProtocol._ @@ -153,9 +154,10 @@ object Driver extends BackendCompilationUtilities { w.write(firrtlString) w.close() - val annotationFile = new File(optionsManager.getBuildFileName("anno")) + val annotationFile = new File(optionsManager.getBuildFileName("anno.json")) val af = new FileWriter(annotationFile) - af.write(circuit.annotations.toArray.toYaml.prettyPrint) + val firrtlAnnos = circuit.annotations.map(_.toFirrtl) + af.write(JsonProtocol.serialize(firrtlAnnos)) af.close() /** Find the set of transform classes associated with annotations then @@ -164,16 +166,16 @@ object Driver extends BackendCompilationUtilities { * transform being instantiated */ val transforms = circuit.annotations - .map(_.transform) - .distinct - .filterNot(_ == classOf[firrtl.Transform]) - .map { transformClass: Class[_ <: Transform] => - transformClass.newInstance() - } + .collect { case anno: RunFirrtlTransform => anno.transformClass } + .distinct + .filterNot(_ == classOf[firrtl.Transform]) + .map { transformClass: Class[_ <: Transform] => + transformClass.newInstance() + } /* This passes the firrtl source and annotations directly to firrtl */ optionsManager.firrtlOptions = optionsManager.firrtlOptions.copy( firrtlSource = Some(firrtlString), - annotations = optionsManager.firrtlOptions.annotations ++ circuit.annotations.toList, + annotations = optionsManager.firrtlOptions.annotations ++ firrtlAnnos, customTransforms = optionsManager.firrtlOptions.customTransforms ++ transforms.toList) val firrtlExecutionResult = if(chiselOptions.runFirrtlCompiler) { diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 973ad026..b3a9f54b 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -439,6 +439,9 @@ package object chisel3 { // scalastyle:ignore package.object.name type ChiselAnnotation = chisel3.core.ChiselAnnotation val ChiselAnnotation = chisel3.core.ChiselAnnotation + type RunFirrtlTransform = chisel3.core.RunFirrtlTransform + + val annotate = chisel3.core.annotate val DataMirror = chisel3.core.DataMirror val requireIsHardware = chisel3.core.requireIsHardware diff --git a/src/main/scala/chisel3/util/BlackBoxUtils.scala b/src/main/scala/chisel3/util/BlackBoxUtils.scala index fbcf4a59..fa62184a 100644 --- a/src/main/scala/chisel3/util/BlackBoxUtils.scala +++ b/src/main/scala/chisel3/util/BlackBoxUtils.scala @@ -3,14 +3,18 @@ package chisel3.util import chisel3._ -import chisel3.core.ChiselAnnotation -import firrtl.transforms.{BlackBoxInline, BlackBoxResource, BlackBoxSourceHelper} +import chisel3.experimental.{ChiselAnnotation, RunFirrtlTransform} +import firrtl.transforms.{BlackBoxResourceAnno, BlackBoxInlineAnno, BlackBoxSourceHelper} trait HasBlackBoxResource extends BlackBox { self: BlackBox => def setResource(blackBoxResource: String): Unit = { - annotate(ChiselAnnotation(self, classOf[BlackBoxSourceHelper], BlackBoxResource(blackBoxResource).serialize)) + val anno = new ChiselAnnotation with RunFirrtlTransform { + def toFirrtl = BlackBoxResourceAnno(self.toNamed, blackBoxResource) + def transformClass = classOf[BlackBoxSourceHelper] + } + chisel3.experimental.annotate(anno) } } @@ -18,7 +22,10 @@ trait HasBlackBoxInline extends BlackBox { self: BlackBox => def setInline(blackBoxName: String, blackBoxInline: String): Unit = { - annotate(ChiselAnnotation( - self, classOf[BlackBoxSourceHelper], BlackBoxInline(blackBoxName, blackBoxInline).serialize)) + val anno = new ChiselAnnotation with RunFirrtlTransform { + def toFirrtl = BlackBoxInlineAnno(self.toNamed, blackBoxName, blackBoxInline) + def transformClass = classOf[BlackBoxSourceHelper] + } + chisel3.experimental.annotate(anno) } } |
