Search code examples
chiseldigital-logic

Chisel3 REPL Vec assignment into module only works after eval


If we run the following Chisel3 code

class Controller extends Module {

  val io = IO(new Bundle {
  })
  val sff = Module(new SFF)

  val frame: Vec[UInt] = Reg(Vec(ProcedureSpaceSize, Integer32Bit))
  for(i <- 0 until ProcedureSpaceSize)
    frame(i) := 99.U

  sff.io.inputDataVector := frame
}

class SFF extends Module {

  val io = IO(new Bundle {
    val inputDataVector: Vec[UInt] = Input(Vec(ProcedureSpaceSize, Integer32Bit))
  })

}

in REPL debug mode. First do

reset;step

peek sff.io_inputDataVector_0;peek sff.io_inputDataVector_1;peek sff.io_inputDataVector_2

The REPL returns

Error: exception Error: getValue(sff.io_inputDataVector_0) returns value not found
Error: exception Error: getValue(sff.io_inputDataVector_1) returns value not found
Error: exception Error: getValue(sff.io_inputDataVector_2) returns value not found

Then do

eval sff.io_inputDataVector_0

which will be a success, yielding

...
resolve dependencies
  evaluate     sff.io_inputDataVector_0 <= frame_0
  evaluated    sff.io_inputDataVector_0 <= 99.U<32>

Then perform the above peek again

peek sff.io_inputDataVector_0;peek sff.io_inputDataVector_1;peek sff.io_inputDataVector_2;

This time, it returns

peek sff.io_inputDataVector_0  99
peek sff.io_inputDataVector_1  99
peek sff.io_inputDataVector_2  99

which is more expected.

Why does the REPL act in this way? Or was there something I missed? Thanks!

*chisel-iotesters is in version 1.4.2, and chiseltest is in version 0.2.2. Both should be the newest version.


Solution

  • The firrtl interpreter REPL does not necessarily compute or store values that on a branch of a mux that is not used. This can lead to problems noted above like

    Error: exception Error: getValue(sff.io_inputDataVector_0) returns value not found.

    eval can be used to force unused branches to be evaluated anyway. The REPL is an experimental feature that has not had a lot of use.

    treadle is the more modern chisel scala-based simulator. It is better supported and faster than the interpreter. It has a REPL of its own, but does not have an executeFirrtlRepl equivalent.

    It must be run from the command line via the ./treadle.sh script in the root directory. One can also run sbt assembly to create a much faster launching jar that is placed in utils/bin. This REPL also has not been used a lot but I am interested on feedback that will make it better and easier to use.