Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions tests/counter.scope_move.no_diff.vcd
Original file line number Diff line number Diff line change
@@ -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!
38 changes: 23 additions & 15 deletions vcddiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand All @@ -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);
Expand Down