diff --git a/ci/test.sh b/ci/test.sh index 22202a5..366bcc3 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -17,6 +17,7 @@ fi ! ./vcddiff tests/counter.vcd tests/counter.change_reorder.no_diff.vcd | grep -q . ! ./vcddiff tests/counter.vcd tests/counter.var_reorder.no_diff.vcd | grep -q . ! ./vcddiff tests/counter.vcd tests/counter.identifier.no_diff.vcd | grep -q . +! ./vcddiff tests/counter.vcd tests/counter.scope_move.no_diff.vcd | grep -q . if [ "$FIFO_SUPPORTED" = "1" ]; then ! ./vcddiff <(cat tests/counter.vcd) <(cat tests/counter.vcd) | grep -q . fi diff --git a/tests/counter.scope_move.no_diff.vcd b/tests/counter.scope_move.no_diff.vcd new file mode 100644 index 0000000..e01d21d --- /dev/null +++ b/tests/counter.scope_move.no_diff.vcd @@ -0,0 +1,46 @@ +$date + Fri Nov 21 13:40:50 2025 +$end +$version + Some Simulator +$end +$timescale + 1ns +$end + +$scope module t $end +$scope module the_sub $end +$var integer 32 # cyc $end +$var integer 32 $ cyc_plus_one $end +$upscope $end +$var reg 1 ! clk $end +$var integer 32 " cyc $end + +$upscope $end + +$scope begin std $end +$upscope $end +$enddefinitions $end +#0 +$dumpvars +0! +b0 " +b0 # +b1 $ +$end +#10 +1! +b1 " +b1 # +b10 $ +#20 +0! +#30 +1! +b10 " +b10 # +b11 $ +#40 +0! +#50 +1! diff --git a/vcddiff.c b/vcddiff.c index bdb75c1..88f392a 100644 --- a/vcddiff.c +++ b/vcddiff.c @@ -399,6 +399,11 @@ static void variable(FILE* fp, char* file_name) { if (token[0] != '$') { int available = MAXSIG - 1 - strlen(signame); if (available > 0) { strncat(signame, token, available); } + get_token(fp, token); + if (token[0] != '$') { + printf("ERROR - missing $end for %s\n", signame); + exit(1); + } } add_signal(signame, ident, VERILOG_ID_TO_POS(ident), bits, type); @@ -447,22 +452,34 @@ static int get_vkeywrd(char* tstr) { return (EOF); } +static void make_curmod(int level) { + char sep[2]; + int i; + + sep[0] = '.'; + sep[1] = '\0'; + + strcpy(curmodG, scopesG[0]); + strcat(curmodG, sep); + + for (i = 1; i < level; i++) { + strcat(curmodG, scopesG[i]); + strcat(curmodG, sep); + } +} + /* process all the lines until $enddef is reached, determines all variable * names, seperated by a '.' between scopes, place the timescale number * and units, and return the file location to start processing diffs */ static long get_lines(FILE* fp, int* units, int* tnum, char* file_name) { - char sep[2]; int level; - int i; char* tok; //1+because of the line with "tok++", which would otherwise make the buffer //smaller than expected by get_token static char token[MAXTOKSIZE + 1]; - sep[0] = '.'; - sep[1] = '\0'; level = 0; *units = 1; *tnum = 1; @@ -483,6 +500,7 @@ static long get_lines(FILE* fp, int* units, int* tnum, char* file_name) { case V_UPSCOPE: if (level > 0) level--; + make_curmod(level); break; case V_SCOPE: @@ -491,18 +509,8 @@ static long get_lines(FILE* fp, int* units, int* tnum, char* file_name) { if (level < MAXSCOPES) { strcpy(scopesG[level], tok); - - strcpy(curmodG, scopesG[0]); - strcat(curmodG, sep); level++; - - if (level) { - for (i = 1; i < level; i++) { - strcat(curmodG, scopesG[i]); - strcat(curmodG, sep); - } - } - + make_curmod(level); } else { printf("*** ERROR-exceeded max scope levels %d\n", level); exit(0);