diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index c26e6da50..9fa811e3f 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -376,7 +376,8 @@ extern vpiHandle vpip_make_int4(const char*name, int msb, int lsb, vvp_net_t*vec); extern vpiHandle vpip_make_var4(const char*name, int msb, int lsb, bool signed_flag, vvp_net_t*net); -extern vpiHandle vpip_make_net4(const char*name, int msb, int lsb, +extern vpiHandle vpip_make_net4(__vpiScope*scope, + const char*name, int msb, int lsb, bool signed_flag, vvp_net_t*node); /* @@ -543,7 +544,9 @@ struct __vpiRealVar : public __vpiHandle { }; extern __vpiScope* vpip_scope(__vpiRealVar*sig); -extern vpiHandle vpip_make_real_var(const char*name, vvp_net_t*net, bool is_wire); +extern vpiHandle vpip_make_real_var(const char*name, vvp_net_t*net); +extern vpiHandle vpip_make_real_net(__vpiScope*scope, + const char*name, vvp_net_t*net); class __vpiBaseVar : public __vpiHandle { diff --git a/vvp/vpi_real.cc b/vvp/vpi_real.cc index 54ad3caf6..e51ee3219 100644 --- a/vvp/vpi_real.cc +++ b/vvp/vpi_real.cc @@ -178,7 +178,8 @@ vpiHandle __vpiRealVar::vpi_handle(int code) vpiHandle __vpiRealVar::vpi_iterate(int code) { return real_var_iterate(code, this); } -vpiHandle vpip_make_real_var(const char*name, vvp_net_t*net, bool is_wire) +static vpiHandle vpip_make_real_(__vpiScope*scope, const char*name, + vvp_net_t*net, bool is_wire) { struct __vpiRealVar*obj = new __vpiRealVar; @@ -187,11 +188,22 @@ vpiHandle vpip_make_real_var(const char*name, vvp_net_t*net, bool is_wire) obj->is_wire = is_wire; obj->net = net; - obj->within.scope = vpip_peek_current_scope(); + obj->within.scope = scope; return obj; } +vpiHandle vpip_make_real_var(const char*name, vvp_net_t*net) +{ + return vpip_make_real_(vpip_peek_current_scope(), name, net, false); +} + +vpiHandle vpip_make_real_net(__vpiScope*scope, + const char*name, vvp_net_t*net) +{ + return vpip_make_real_(scope, name, net, true); +} + #ifdef CHECK_WITH_VALGRIND void real_delete(vpiHandle item) { diff --git a/vvp/vpi_signal.cc b/vvp/vpi_signal.cc index 9cac4c796..5e63e77af 100644 --- a/vvp/vpi_signal.cc +++ b/vvp/vpi_signal.cc @@ -132,9 +132,19 @@ char *generic_get_str(int code, vpiHandle ref, const char *name, const char *ind return res; } -static vpiHandle fill_in_net4(struct __vpiSignal*obj, - const char*name, int msb, int lsb, - bool signed_flag, vvp_net_t*node); +static vpiHandle fill_in_net4(struct __vpiSignal*obj, __vpiScope*scope, + const char*name, int msb, int lsb, + bool signed_flag, vvp_net_t*node); + +static vpiHandle fill_in_var4(struct __vpiSignal*obj, + const char*name, int msb, int lsb, + bool signed_flag, vvp_net_t*node) +{ + // Variable declarations are always resolved immediately, + // so we can assume they belong in the current scope. + return fill_in_net4(obj, vpip_peek_current_scope(), + name, msb, lsb, signed_flag, node); +} /* * The standard formatting/conversion routines. @@ -972,7 +982,7 @@ struct signal_longint : public __vpiSignal { vpiHandle vpip_make_int4(const char*name, int msb, int lsb, vvp_net_t*vec) { __vpiSignal*obj = new signal_integer; - return fill_in_net4(obj, name, msb, lsb, true, vec); + return fill_in_var4(obj, name, msb, lsb, true, vec); } /* @@ -1011,7 +1021,7 @@ vpiHandle vpip_make_int2(const char*name, int msb, int lsb, bool signed_flag, } } - return fill_in_net4(obj, name, msb, lsb, signed_flag, vec); + return fill_in_var4(obj, name, msb, lsb, signed_flag, vec); } /* @@ -1021,7 +1031,7 @@ vpiHandle vpip_make_var4(const char*name, int msb, int lsb, bool signed_flag, vvp_net_t*vec) { __vpiSignal*obj = new signal_reg; - return fill_in_net4(obj, name, msb, lsb, signed_flag, vec); + return fill_in_var4(obj, name, msb, lsb, signed_flag, vec); } #ifdef CHECK_WITH_VALGRIND @@ -1116,7 +1126,7 @@ void signal_pool_delete() * The name is the PLI name for the object. If it is an array it is * []. */ -static vpiHandle fill_in_net4(struct __vpiSignal*obj, +static vpiHandle fill_in_net4(struct __vpiSignal*obj, __vpiScope*scope, const char*name, int msb, int lsb, bool signed_flag, vvp_net_t*node) { @@ -1130,18 +1140,19 @@ static vpiHandle fill_in_net4(struct __vpiSignal*obj, // Place this object within a scope. If this object is // attached to an array, then this value will be replaced with // the handle to the parent. - obj->within.scope = vpip_peek_current_scope(); + obj->within.scope = scope; count_vpi_nets += 1; return obj; } -vpiHandle vpip_make_net4(const char*name, int msb, int lsb, +vpiHandle vpip_make_net4(__vpiScope*scope, + const char*name, int msb, int lsb, bool signed_flag, vvp_net_t*node) { struct __vpiSignal*obj = new signal_net; - return fill_in_net4(obj, name, msb, lsb, signed_flag, node); + return fill_in_net4(obj, scope, name, msb, lsb, signed_flag, node); } static int PV_get_base(struct __vpiPV*rfp) diff --git a/vvp/words.cc b/vvp/words.cc index 0a89f0b8d..fcafa939a 100644 --- a/vvp/words.cc +++ b/vvp/words.cc @@ -48,7 +48,7 @@ static void __compile_var_real(char*label, char*name, define_functor_symbol(label, net); - vpiHandle obj = vpip_make_real_var(name, net, false); + vpiHandle obj = vpip_make_real_var(name, net); compile_vpi_symbol(label, obj); if (name) { @@ -350,7 +350,7 @@ static void do_compile_net(vvp_net_t*node, vvp_array_t array, vpiHandle obj = 0; if (! local_flag) { /* Make the vpiHandle for the reg. */ - obj = vpip_make_net4(name, msb, lsb, signed_flag, node); + obj = vpip_make_net4(scope, name, msb, lsb, signed_flag, node); /* This attaches the label to the vpiHandle */ compile_vpi_symbol(my_label, obj); } @@ -481,7 +481,7 @@ static void __compile_real_net2(vvp_net_t*node, vvp_array_t array, vpiHandle obj = 0; if (!local_flag) { - obj = vpip_make_real_var(name, node, true); + obj = vpip_make_real_net(scope, name, node); compile_vpi_symbol(my_label, obj); } #ifdef CHECK_WITH_VALGRIND