diff --git a/ivtest/gold/br1003a.gold b/ivtest/gold/br1003a.gold index 12fc0c554..14a349d65 100644 --- a/ivtest/gold/br1003a.gold +++ b/ivtest/gold/br1003a.gold @@ -1,5 +1,5 @@ Time scale of (top) is 1ns / 1ps Time scale of (top) is 1ns / 1ps -Time scale of ($unit) is 100ps / 10ps +Time scale of ($unit::) is 100ps / 10ps 50 5 PASSED diff --git a/ivtest/gold/br1003b.gold b/ivtest/gold/br1003b.gold index 12fc0c554..14a349d65 100644 --- a/ivtest/gold/br1003b.gold +++ b/ivtest/gold/br1003b.gold @@ -1,5 +1,5 @@ Time scale of (top) is 1ns / 1ps Time scale of (top) is 1ns / 1ps -Time scale of ($unit) is 100ps / 10ps +Time scale of ($unit::) is 100ps / 10ps 50 5 PASSED diff --git a/ivtest/gold/br1003c.gold b/ivtest/gold/br1003c.gold index 12fc0c554..14a349d65 100644 --- a/ivtest/gold/br1003c.gold +++ b/ivtest/gold/br1003c.gold @@ -1,5 +1,5 @@ Time scale of (top) is 1ns / 1ps Time scale of (top) is 1ns / 1ps -Time scale of ($unit) is 100ps / 10ps +Time scale of ($unit::) is 100ps / 10ps 50 5 PASSED diff --git a/ivtest/gold/br1003d.gold b/ivtest/gold/br1003d.gold index 4b6e070f0..83be02b3e 100644 --- a/ivtest/gold/br1003d.gold +++ b/ivtest/gold/br1003d.gold @@ -1,5 +1,5 @@ Time scale of (top) is 1ns / 1ps Time scale of (top) is 1ns / 1ps -Time scale of (testpackage) is 100ps / 10ps +Time scale of (testpackage::) is 100ps / 10ps 50 5 PASSED diff --git a/ivtest/gold/pr1963962-fsv.gold b/ivtest/gold/pr1963962-fsv.gold index 47d9fb2e2..83f169c86 100644 --- a/ivtest/gold/pr1963962-fsv.gold +++ b/ivtest/gold/pr1963962-fsv.gold @@ -1,2 +1,2 @@ VCD info: dumpfile work/dumptest.vcd opened for output. -VCD warning: $dumpvars: Package ($unit) is not dumpable with VCD. +VCD warning: $dumpvars: Package ($unit::) is not dumpable with VCD. diff --git a/ivtest/vpi/br_gh1037.c b/ivtest/vpi/br_gh1037.c new file mode 100644 index 000000000..982ac03ef --- /dev/null +++ b/ivtest/vpi/br_gh1037.c @@ -0,0 +1,54 @@ +# include +# include +# include + +static PLI_INT32 check_items_calltf(PLI_BYTE8 *xx) +{ + (void)xx; /* Parameter is not used. */ + vpiHandle th, ih; + + // Get the top level instances. + th = vpi_iterate(vpiInstance, NULL); + while((ih = vpi_scan(th))) { + vpiHandle vh; + vpi_printf("Found an item named %s ", vpi_get_str(vpiFullName, ih)); + vpi_printf("of type %s\n", vpi_get_str(vpiType, ih)); + vh = vpi_iterate(vpiVariables, ih); + if (vh != 0) { + vpiHandle vi; + while((vi = vpi_scan(vh))) { + s_vpi_value value; + char*str_val; + value.format = vpiDecStrVal; + vpi_get_value(vi, &value); + str_val = strdup(value.value.str); + vpi_printf(" - Has a variable named %s ", vpi_get_str(vpiFullName, vi)); + vpi_printf("of type %s and a value of %s\n", vpi_get_str(vpiType, vi), str_val); + free(str_val); + } + } + } + vpi_printf("All done with items\n"); + return 0; +} + +static void check_items_register(void) +{ + s_vpi_systf_data tf_data; + + tf_data.type = vpiSysTask; + tf_data.tfname = "$check_items"; + tf_data.calltf = check_items_calltf; + tf_data.compiletf = 0; + tf_data.sizetf = 0; + vpi_register_systf(&tf_data); +} + +/* + * This is a table of register functions. This table is the external + * symbol that the simulator looks for when loading this .vpi module. + */ +void (*vlog_startup_routines[])(void) = { + check_items_register, + 0 +}; diff --git a/ivtest/vpi/br_gh1037.v b/ivtest/vpi/br_gh1037.v new file mode 100644 index 000000000..c812544e6 --- /dev/null +++ b/ivtest/vpi/br_gh1037.v @@ -0,0 +1,13 @@ +int top_var = 1; + +module top; + int val = 2; + initial begin + #1; + $check_items(); + end +endmodule + +package top; + int val = 3; +endpackage diff --git a/ivtest/vpi_gold/br_gh1037.gold b/ivtest/vpi_gold/br_gh1037.gold new file mode 100644 index 000000000..539280814 --- /dev/null +++ b/ivtest/vpi_gold/br_gh1037.gold @@ -0,0 +1,9 @@ +Compiling vpi/br_gh1037.c... +Making br_gh1037.vpi from br_gh1037.o... +Found an item named $unit:: of type vpiPackage + - Has a variable named $unit::top_var of type vpiIntVar and a value of 1 +Found an item named top:: of type vpiPackage + - Has a variable named top::val of type vpiIntVar and a value of 3 +Found an item named top of type vpiModule + - Has a variable named top.val of type vpiIntVar and a value of 2 +All done with items diff --git a/ivtest/vpi_regress.list b/ivtest/vpi_regress.list index bbbe858fe..240261b84 100644 --- a/ivtest/vpi_regress.list +++ b/ivtest/vpi_regress.list @@ -70,6 +70,7 @@ br_gh235 normal,-g2009 br_gh235.c br_gh235.gold br_gh308 normal br_gh308.c br_gh308.gold br_gh317 normal br_gh317.c br_gh317.gold br_gh496 normal,-g2009 br_gh496.c br_gh496.gold +br_gh1037 normal,-g2009 br_gh1037.c br_gh1037.gold br_ml20191013 normal br_ml20191013.c br_ml20191013.gold by_index normal by_index.c by_index.gold by_name normal by_name.c by_name.log diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index a30786ebb..57bea521a 100644 --- a/vvp/vpi_scope.cc +++ b/vvp/vpi_scope.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2023 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -180,10 +180,15 @@ static void construct_scope_fullname(__vpiScope*ref, char*buf) { if (ref->scope) { construct_scope_fullname(ref->scope, buf); - strcat(buf, "."); + // Add a "." separator, unless this is for a package + if (ref->scope->get_type_code() != vpiPackage) { + strcat(buf, "."); + } } strcat(buf, ref->scope_name()); + // For a package, add a "::" to the end + if (ref->get_type_code() == vpiPackage) strcat(buf, "::"); } static const char* scope_get_type(int code) diff --git a/vvp/vpi_signal.cc b/vvp/vpi_signal.cc index 6ed41455f..59fee8647 100644 --- a/vvp/vpi_signal.cc +++ b/vvp/vpi_signal.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2022 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2023 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -104,9 +104,13 @@ char *generic_get_str(int code, vpiHandle ref, const char *name, const char *ind { size_t len = strlen(name) + 1; /* include space for null termination */ char *bn = NULL; + bool is_bn_a_pkg = false; if (code == vpiFullName) { bn = strdup(vpi_get_str(code,ref)); - len += strlen(bn) + 1; /* include space for "." separator */ + size_t bn_len = strlen(bn); + is_bn_a_pkg = bn[bn_len-1] == ':' && bn[bn_len-2] == ':'; + len += bn_len; + if (! is_bn_a_pkg) len += 1; // include space for "." separator } if (index != NULL) len += strlen(index) + 2; /* include space for brackets */ @@ -120,7 +124,8 @@ char *generic_get_str(int code, vpiHandle ref, const char *name, const char *ind /* if this works, I can make it more efficient later */ if (bn != NULL) { strcat(res, bn); - strcat(res, "."); + // A package already has the "::" separator in the name + if (! is_bn_a_pkg) strcat(res, "."); free(bn); } strcat(res, name);