diff options
author | whitequark <whitequark@whitequark.org> | 2020-04-16 16:45:02 +0000 |
---|---|---|
committer | whitequark <whitequark@whitequark.org> | 2020-04-16 16:45:54 +0000 |
commit | 06c0338f2c19ca50675f3928de7fa19b05d304c4 (patch) | |
tree | 0951897313ff14307d407dee6b7c5a0c7eab86c4 /backends/cxxrtl | |
parent | 9043632dcc9b4ab198e03ffbdb8ba232b047ef28 (diff) | |
download | yosys-06c0338f2c19ca50675f3928de7fa19b05d304c4.tar.gz yosys-06c0338f2c19ca50675f3928de7fa19b05d304c4.tar.bz2 yosys-06c0338f2c19ca50675f3928de7fa19b05d304c4.zip |
cxxrtl: make ROMs writable, document memory::operator[].
There is no practical benefit from using `const memory` for ROMs;
it uses an std::vector internally, which prevents contemporary
compilers from constant-propagating ROM contents. (It is not clear
whether they are permitted to do so.)
However, there is a major benefit from using non-const `memory` for
ROMs, which is the ability to dynamically fill the ROM for each
individual simulation.
Diffstat (limited to 'backends/cxxrtl')
-rw-r--r-- | backends/cxxrtl/cxxrtl.cc | 3 | ||||
-rw-r--r-- | backends/cxxrtl/cxxrtl.h | 7 |
2 files changed, 6 insertions, 4 deletions
diff --git a/backends/cxxrtl/cxxrtl.cc b/backends/cxxrtl/cxxrtl.cc index 8f7f9d7a3..e4fa430f3 100644 --- a/backends/cxxrtl/cxxrtl.cc +++ b/backends/cxxrtl/cxxrtl.cc @@ -1166,8 +1166,7 @@ struct CxxrtlWorker { }); dump_attrs(memory); - f << indent << (writable_memories[memory] ? "" : "const ") - << "memory<" << memory->width << "> " << mangle(memory) + f << indent << "memory<" << memory->width << "> " << mangle(memory) << " { " << memory->size << "u"; if (init_cells.empty()) { f << " };\n"; diff --git a/backends/cxxrtl/cxxrtl.h b/backends/cxxrtl/cxxrtl.h index 593c31c28..fd390db79 100644 --- a/backends/cxxrtl/cxxrtl.h +++ b/backends/cxxrtl/cxxrtl.h @@ -604,12 +604,15 @@ struct memory { auto _ = {std::move(std::begin(init.data), std::end(init.data), data.begin() + init.offset)...}; } - value<Width> &operator [](size_t index) { + // An operator for direct memory reads. May be used at any time during the simulation. + const value<Width> &operator [](size_t index) const { assert(index < data.size()); return data[index]; } - const value<Width> &operator [](size_t index) const { + // An operator for direct memory writes. May only be used before the simulation is started. If used + // after the simulation is started, the design may malfunction. + value<Width> &operator [](size_t index) { assert(index < data.size()); return data[index]; } |