chipsalliance / chipsalliance/chisel

loadMemoryFromFile() should place readmemh() inline for better compatibility

Open
#1,293 18 comments 2 reactions 1 assignee Claimed by @chick View on GitHub
Dominant language
Scala
Stars
4.8k
Forks
658
Avg merge
18h 59m
Merged PRs (30d)
14

Description

`loadMemoryFromFile()` creates a separate file and uses a SV bind statement. A simple example:

```
import chisel3._
import chisel3.util.experimental.loadMemoryFromFile

class Foo(val bits: Int, val size: Int, filename: String) extends Module {
val io = IO(new Bundle {
val nia = Input(UInt(bits.W))
val insn = Output(UInt(32.W))
})

val memory = Mem(size, UInt(32.W))
io.insn := memory(io.nia >> 2);
loadMemoryFromFile(memory, filename)
}

object FooObj extends App {
chisel3.Driver.execute(Array[String](), () => new Foo(32, 1024, "insns.hex"))
}
```

```
# cat Foo.Foo.memory.v
module BindsTo_0_Foo(
input clock,
input reset,
input [31:0] io_nia,
output [31:0] io_insn
);

initial begin
$readmemh("insns.hex", Foo.memory);
end
endmodule

bind Foo BindsTo_0_Foo BindsTo_0_Foo_Inst(.*);
```

Yosys doesn't like this, and likely there are other tools that don't either. Is there any reason we don't just place it inline?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.