diff options
| author | Kevin Laeufer | 2021-06-15 16:36:50 -0700 |
|---|---|---|
| committer | GitHub | 2021-06-15 23:36:50 +0000 |
| commit | 117054bb4cdc3c5abf34ba5c99f61bcd590871f0 (patch) | |
| tree | dde8b24ea3a744e058165f98e77639ca3283833f /src/main/scala/firrtl/annotations | |
| parent | 3ea95e720c8107a1c466b8cba1fc076bfbc296fa (diff) | |
make PresetRegAnnotation public (#2254)
* make PresetRegAnnotation public
this annotation is useful outside the firrtl compiler:
- to implement a pass that creates registers which
need to be initialized at the beginning of simulation
(e.g., for formal verification)
- to support preset registers in treadle
* add PresetRegAnnotation test and deal with annotation correctly in RemoveReset pass
Diffstat (limited to 'src/main/scala/firrtl/annotations')
| -rw-r--r-- | src/main/scala/firrtl/annotations/PresetAnnotations.scala | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/main/scala/firrtl/annotations/PresetAnnotations.scala b/src/main/scala/firrtl/annotations/PresetAnnotations.scala index 32f24f13..449679cc 100644 --- a/src/main/scala/firrtl/annotations/PresetAnnotations.scala +++ b/src/main/scala/firrtl/annotations/PresetAnnotations.scala @@ -17,15 +17,31 @@ case class PresetAnnotation(target: ReferenceTarget) /** * Transform the targeted asynchronously-reset Reg into a bitstream preset Reg - * Used internally to annotate all registers associated to an AsyncReset tree + * Thus you can use this annotation in order to initialize a register + * at the beginning of simulation or through the FPGA bit-stream to its `init` value. + * + * The register must fulfil the following requirements: + * - the reset signal is `UInt(0)` + * - the `init` value is a Literal * * @param target ReferenceTarget to a Reg */ -private[firrtl] case class PresetRegAnnotation( +case class PresetRegAnnotation( target: ReferenceTarget) extends SingleTargetAnnotation[ReferenceTarget] - with RegisterEmissionOption { + with RegisterEmissionOption + with firrtl.transforms.DontTouchAllTargets { def duplicate(n: ReferenceTarget) = this.copy(target = n) override def useInitAsPreset = true override def disableRandomization = true } + +object PresetRegAnnotation { + + /** Extracts the names of every preset reg in the design by module. */ + def collect(annotations: AnnotationSeq, main: String): Map[String, Set[String]] = + annotations.collect { + case a: PresetRegAnnotation if a.target.circuit == main => + a.target.module -> a.target.ref + }.groupBy(_._1).map { case (k, v) => k -> v.map(_._2).toSet } +} |
