Support vpi_handle_by_name with $root..

This commit is contained in:
Wilson Snyder 2025-07-28 18:03:21 -04:00
parent 833c31b031
commit 2ff6ee9613
2 changed files with 5 additions and 1 deletions

View File

@ -2059,7 +2059,10 @@ vpiHandle vpi_handle_by_name(PLI_BYTE8* namep, vpiHandle scope) {
const VerilatedScope* scopep;
const VerilatedVpioScope* const voScopep = VerilatedVpioScope::castp(scope);
std::string scopeAndName = namep;
if (voScopep) {
if (0 == std::strncmp(namep, "$root.", std::strlen("$root."))) {
namep += std::strlen("$root.");
scopeAndName = namep;
} else if (voScopep) {
const bool scopeIsPackage = VerilatedVpioPackage::castp(scope) != nullptr;
scopeAndName = std::string{voScopep->fullname()} + (scopeIsPackage ? "" : ".") + namep;
namep = const_cast<PLI_BYTE8*>(scopeAndName.c_str());

View File

@ -120,6 +120,7 @@ int mon_check() {
CHECK_RESULT_Z(check_handle(const_cast<PLI_BYTE8*>("someOtherInt"), tHandle))
CHECK_RESULT_Z(check_handle(const_cast<PLI_BYTE8*>("t.someOtherInt"), NULL))
CHECK_RESULT_Z(check_handle(const_cast<PLI_BYTE8*>("$root.t.someOtherInt"), NULL))
CHECK_RESULT_Z(check_handle(const_cast<PLI_BYTE8*>("someString"), tHandle))
CHECK_RESULT_Z(check_handle(const_cast<PLI_BYTE8*>("t.someString"), NULL))
CHECK_RESULT_Z(check_handle(const_cast<PLI_BYTE8*>("someInt"), pkgHandle))