3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-12 20:18:20 +00:00

cxxrtl: track aliases in VCD writer.

This commit changes the VCD writer such that for all signals that
share `debug_item.curr`, it would only emit a single VCD identifier,
and sample the value once.

Commit 9b39c6f7 added redundancy to debug information by including
alias wires, and increased the size of VCD files proportionally; this
commit eliminates the redundancy from VCD files so that their size
is the same as before.
This commit is contained in:
whitequark 2020-06-08 16:36:26 +00:00
parent 9b39c6f744
commit d5c07e5b6f

View file

@ -34,6 +34,7 @@ class vcd_writer {
std::vector<std::string> current_scope; std::vector<std::string> current_scope;
std::vector<variable> variables; std::vector<variable> variables;
std::vector<chunk_t> cache; std::vector<chunk_t> cache;
std::map<chunk_t*, size_t> aliases;
bool streaming = false; bool streaming = false;
void emit_timescale(unsigned number, const std::string &unit) { void emit_timescale(unsigned number, const std::string &unit) {
@ -103,10 +104,16 @@ class vcd_writer {
buffer += '\n'; buffer += '\n';
} }
void append_variable(size_t width, chunk_t *curr) { const variable &register_variable(size_t width, chunk_t *curr) {
const size_t chunks = (width + (sizeof(chunk_t) * 8 - 1)) / (sizeof(chunk_t) * 8); if (aliases.count(curr)) {
variables.emplace_back(variable { variables.size(), width, curr, cache.size() }); return variables[aliases[curr]];
cache.insert(cache.end(), &curr[0], &curr[chunks]); } else {
const size_t chunks = (width + (sizeof(chunk_t) * 8 - 1)) / (sizeof(chunk_t) * 8);
aliases[curr] = variables.size();
variables.emplace_back(variable { variables.size(), width, curr, cache.size() });
cache.insert(cache.end(), &curr[0], &curr[chunks]);
return variables.back();
}
} }
bool test_variable(const variable &var) { bool test_variable(const variable &var) {
@ -151,20 +158,17 @@ public:
switch (item.type) { switch (item.type) {
// Not the best naming but oh well... // Not the best naming but oh well...
case debug_item::VALUE: case debug_item::VALUE:
append_variable(item.width, item.curr); emit_var(register_variable(item.width, item.curr), "wire", name);
emit_var(variables.back(), "wire", name);
break; break;
case debug_item::WIRE: case debug_item::WIRE:
append_variable(item.width, item.curr); emit_var(register_variable(item.width, item.curr), "reg", name);
emit_var(variables.back(), "reg", name);
break; break;
case debug_item::MEMORY: { case debug_item::MEMORY: {
const size_t stride = (item.width + (sizeof(chunk_t) * 8 - 1)) / (sizeof(chunk_t) * 8); const size_t stride = (item.width + (sizeof(chunk_t) * 8 - 1)) / (sizeof(chunk_t) * 8);
for (size_t index = 0; index < item.depth; index++) { for (size_t index = 0; index < item.depth; index++) {
chunk_t *nth_curr = &item.curr[stride * index]; chunk_t *nth_curr = &item.curr[stride * index];
std::string nth_name = name + '[' + std::to_string(index) + ']'; std::string nth_name = name + '[' + std::to_string(index) + ']';
append_variable(item.width, nth_curr); emit_var(register_variable(item.width, nth_curr), "reg", nth_name);
emit_var(variables.back(), "reg", nth_name);
} }
break; break;
} }