mirror of https://github.com/YosysHQ/yosys.git
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.
This commit is contained in:
parent
9043632dcc
commit
06c0338f2c
|
@ -1166,8 +1166,7 @@ struct CxxrtlWorker {
|
||||||
});
|
});
|
||||||
|
|
||||||
dump_attrs(memory);
|
dump_attrs(memory);
|
||||||
f << indent << (writable_memories[memory] ? "" : "const ")
|
f << indent << "memory<" << memory->width << "> " << mangle(memory)
|
||||||
<< "memory<" << memory->width << "> " << mangle(memory)
|
|
||||||
<< " { " << memory->size << "u";
|
<< " { " << memory->size << "u";
|
||||||
if (init_cells.empty()) {
|
if (init_cells.empty()) {
|
||||||
f << " };\n";
|
f << " };\n";
|
||||||
|
|
|
@ -604,12 +604,15 @@ struct memory {
|
||||||
auto _ = {std::move(std::begin(init.data), std::end(init.data), data.begin() + init.offset)...};
|
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());
|
assert(index < data.size());
|
||||||
return data[index];
|
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());
|
assert(index < data.size());
|
||||||
return data[index];
|
return data[index];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue