summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHappyQuark2020-09-10 04:18:08 +1000
committerGitHub2020-09-09 18:18:08 +0000
commit88265eec586046e6ec96b4615e5516be0f3d9e2c (patch)
tree0fa14c05b6bd5565c6bb7e122b51d2b130069165 /src
parent05ac57c160c58268c571b74d6f688b87ff4312b0 (diff)
Fix load memory from file to work with binary (#1583)
* fix loadMemoryFromFile to work with binary Passed in hexOrBinary parameter to ChiselLoadMemoryAnnotation * Added test for binary format support in loadMemoryFromFile * Added test for binary format support in loadMemoryFromFile
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/chisel3/util/experimental/LoadMemoryTransform.scala2
-rw-r--r--src/test/scala/chiselTests/LoadMemoryFromFileSpec.scala29
2 files changed, 30 insertions, 1 deletions
diff --git a/src/main/scala/chisel3/util/experimental/LoadMemoryTransform.scala b/src/main/scala/chisel3/util/experimental/LoadMemoryTransform.scala
index 92bfcde7..4beafa19 100644
--- a/src/main/scala/chisel3/util/experimental/LoadMemoryTransform.scala
+++ b/src/main/scala/chisel3/util/experimental/LoadMemoryTransform.scala
@@ -112,7 +112,7 @@ object loadMemoryFromFile {
fileName: String,
hexOrBinary: MemoryLoadFileType.FileType = MemoryLoadFileType.Hex
): Unit = {
- annotate(ChiselLoadMemoryAnnotation(memory, fileName))
+ annotate(ChiselLoadMemoryAnnotation(memory, fileName, hexOrBinary))
}
}
diff --git a/src/test/scala/chiselTests/LoadMemoryFromFileSpec.scala b/src/test/scala/chiselTests/LoadMemoryFromFileSpec.scala
index 529d90af..d151f24e 100644
--- a/src/test/scala/chiselTests/LoadMemoryFromFileSpec.scala
+++ b/src/test/scala/chiselTests/LoadMemoryFromFileSpec.scala
@@ -106,6 +106,19 @@ class HasComplexMemory(memoryDepth: Int) extends Module {
io.value := memory(io.address)
}
+class HasBinarySupport(memoryDepth: Int, memoryType: Data) extends Module {
+ val io = IO(new Bundle {
+ val address = Input(UInt(memoryType.getWidth.W))
+ val value = Output(memoryType)
+ })
+
+ val memory = Mem(memoryDepth, memoryType)
+
+ loadMemoryFromFile(memory, "./mem", MemoryLoadFileType.Binary)
+
+ io.value := memory(io.address)
+}
+
/**
* The following tests are a bit incomplete and check that the output verilog is properly constructed
@@ -176,4 +189,20 @@ class LoadMemoryFromFileSpec extends AnyFreeSpec with Matchers {
}
+ "Has binary format support" in {
+ val testDirName = "test_run_dir/binary_memory_load"
+
+ val result = (new ChiselStage).execute(
+ args = Array("-X", "verilog", "--target-dir", testDirName),
+ annotations = Seq(ChiselGeneratorAnnotation(() => new HasBinarySupport(memoryDepth = 8, memoryType = UInt(16.W))))
+ )
+
+ val dir = new File(testDirName)
+ val file = new File(dir, s"HasBinarySupport.HasBinarySupport.memory.v")
+ file.exists() should be (true)
+ val fileText = io.Source.fromFile(file).getLines().mkString("\n")
+ fileText should include (s"""$$readmemb("./mem", HasBinarySupport.memory);""")
+ file.delete()
+ }
+
}