Skip to content

Commit

Permalink
cxxrtl: fix vcd writer scope handling
Browse files Browse the repository at this point in the history
The vcd writer incorrectly treated two scope vectors as the same, whenever
they have the same length of entries and the last item matches.
This is however not always true, for example consider a current_scope of
["top", "something0", "same"]
and a scope of
["top", "something1", "same"]
  • Loading branch information
rroohhh authored and whitequark committed Oct 12, 2024
1 parent a8f4bc2 commit 0f762f7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions backends/cxxrtl/runtime/cxxrtl/cxxrtl_vcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ class vcd_writer {

void emit_scope(const std::vector<std::string> &scope) {
assert(!streaming);
while (current_scope.size() > scope.size() ||
(current_scope.size() > 0 &&
current_scope[current_scope.size() - 1] != scope[current_scope.size() - 1])) {
size_t same_scope_count = 0;
while ((same_scope_count < current_scope.size()) &&
(same_scope_count < scope.size()) &&
(current_scope[same_scope_count] == scope[same_scope_count])) {
same_scope_count++;
}
while (current_scope.size() > same_scope_count) {
buffer += "$upscope $end\n";
current_scope.pop_back();
}
Expand Down

0 comments on commit 0f762f7

Please sign in to comment.