aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala
diff options
context:
space:
mode:
authorJared Barocsi2021-07-14 13:10:15 -0700
committerGitHub2021-07-14 13:10:15 -0700
commit4081d9f45a30d9f9e5711563b828f34257d4c19d (patch)
tree5e9e47ff023d816cea66f10b44d5ecb23fd314b6 /src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala
parent87ab555023760e7fe6f517c5776975bbc93ebe8c (diff)
Fix memory annotation deduplication (#2286)
* Add transform to deduplicate memory annotations * Add annotation deduplication to Dedup stage * ResolveAnnotationPaths and EliminateTargetPaths now invalidate the dedup annotations transform * Verilog emitter now throws exception when memory annotations fail to dedup Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala')
-rw-r--r--src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala b/src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala
index 1e81301d..e87066fb 100644
--- a/src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala
+++ b/src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala
@@ -8,7 +8,8 @@ import firrtl.{
MemoryFileInlineInit,
MemoryInitValue,
MemoryRandomInit,
- MemoryScalarInit
+ MemoryScalarInit,
+ Utils
}
/**
@@ -25,6 +26,9 @@ case class MemoryRandomInitAnnotation(target: ReferenceTarget) extends MemoryIni
override def duplicate(n: ReferenceTarget): Annotation = copy(n)
override def initValue: MemoryInitValue = MemoryRandomInit
override def isRandomInit: Boolean = true
+ override private[firrtl] def dedup: Option[(Any, Annotation, ReferenceTarget)] = Some(
+ ((target.pathlessTarget, Nil), copy(target = target.pathlessTarget), target)
+ )
}
/** Initialize all entries of the `target` memory with the scalar `value`. */
@@ -32,6 +36,9 @@ case class MemoryScalarInitAnnotation(target: ReferenceTarget, value: BigInt) ex
override def duplicate(n: ReferenceTarget): Annotation = copy(n)
override def initValue: MemoryInitValue = MemoryScalarInit(value)
override def isRandomInit: Boolean = false
+ override private[firrtl] def dedup: Option[(Any, Annotation, ReferenceTarget)] = Some(
+ ((target.pathlessTarget, value), copy(target = target.pathlessTarget), target)
+ )
}
/** Initialize the `target` memory with the array of `values` which must be the same size as the memory depth. */
@@ -39,6 +46,9 @@ case class MemoryArrayInitAnnotation(target: ReferenceTarget, values: Seq[BigInt
override def duplicate(n: ReferenceTarget): Annotation = copy(n)
override def initValue: MemoryInitValue = MemoryArrayInit(values)
override def isRandomInit: Boolean = false
+ override private[firrtl] def dedup: Option[(Any, Annotation, ReferenceTarget)] = Some(
+ ((target.pathlessTarget, values), copy(target = target.pathlessTarget), target)
+ )
}
/** Initialize the `target` memory with inline readmem[hb] statement. */
@@ -51,6 +61,9 @@ case class MemoryFileInlineAnnotation(
override def duplicate(n: ReferenceTarget): Annotation = copy(n)
override def initValue: MemoryInitValue = MemoryFileInlineInit(filename, hexOrBinary)
override def isRandomInit: Boolean = false
+ override private[firrtl] def dedup: Option[(Any, Annotation, ReferenceTarget)] = Some(
+ ((target.pathlessTarget, filename), copy(target = target.pathlessTarget), target)
+ )
}
/** Initializes the memory inside the `ifndef SYNTHESIS` block (default) */