From 0f762f75a610a246e7a48a5d2be1e2f5bc8c0d89 Mon Sep 17 00:00:00 2001 From: Robin Ole Heinemann Date: Fri, 11 Oct 2024 17:56:48 +0200 Subject: [PATCH] cxxrtl: fix vcd writer scope handling 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"] --- backends/cxxrtl/runtime/cxxrtl/cxxrtl_vcd.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backends/cxxrtl/runtime/cxxrtl/cxxrtl_vcd.h b/backends/cxxrtl/runtime/cxxrtl/cxxrtl_vcd.h index cb2ccf5fc..e4c9a6770 100644 --- a/backends/cxxrtl/runtime/cxxrtl/cxxrtl_vcd.h +++ b/backends/cxxrtl/runtime/cxxrtl/cxxrtl_vcd.h @@ -50,9 +50,13 @@ class vcd_writer { void emit_scope(const std::vector &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(); }