aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala
diff options
context:
space:
mode:
authorCarlos Eduardo2021-03-09 15:49:37 -0300
committerGitHub2021-03-09 18:49:37 +0000
commitefdefde2a5fa13de8faa8c141f852391909225df (patch)
treef9b16501a688feedc8bcebff611148bc12f39de3 /src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala
parent8a4c156f401c8bfab5f2d595c32c20534f0722d7 (diff)
Create annotation to allow inline readmem in Verilog (#2107)
This PR adds a new annotation allowing inline loading for memory files in Verilog code.
Diffstat (limited to 'src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala')
-rw-r--r--src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala b/src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala
index 44656e0d..62dc96f4 100644
--- a/src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala
+++ b/src/main/scala/firrtl/annotations/MemoryInitAnnotation.scala
@@ -2,7 +2,14 @@
package firrtl.annotations
-import firrtl.{MemoryArrayInit, MemoryEmissionOption, MemoryInitValue, MemoryRandomInit, MemoryScalarInit}
+import firrtl.{
+ MemoryArrayInit,
+ MemoryEmissionOption,
+ MemoryFileInlineInit,
+ MemoryInitValue,
+ MemoryRandomInit,
+ MemoryScalarInit
+}
/**
* Represents the initial value of the annotated memory.
@@ -33,3 +40,15 @@ case class MemoryArrayInitAnnotation(target: ReferenceTarget, values: Seq[BigInt
override def initValue: MemoryInitValue = MemoryArrayInit(values)
override def isRandomInit: Boolean = false
}
+
+/** Initialize the `target` memory with inline readmem[hb] statement. */
+case class MemoryFileInlineAnnotation(
+ target: ReferenceTarget,
+ filename: String,
+ hexOrBinary: MemoryLoadFileType.FileType = MemoryLoadFileType.Hex)
+ extends MemoryInitAnnotation {
+ require(filename.trim.nonEmpty, "empty filename not allowed in MemoryFileInlineAnnotation")
+ override def duplicate(n: ReferenceTarget): Annotation = copy(n)
+ override def initValue: MemoryInitValue = MemoryFileInlineInit(filename, hexOrBinary)
+ override def isRandomInit: Boolean = false
+}