From 8ea814e4b4ce7416188130647c87dea41401a5b6 Mon Sep 17 00:00:00 2001 From: Marlon James Date: Tue, 2 Jan 2024 15:57:34 -0800 Subject: [PATCH] Fix VPI parameter iteration (#4798) --- include/verilated_vpi.cpp | 15 ++++++++++++--- test_regress/t/t_vpi_package.cpp | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index dbccd8fc3..03ad2abe9 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -419,10 +419,19 @@ public: } if (m_onlyParams && !m_it->second.isParam()) continue; if (VL_UNLIKELY(m_topscopep)) { - if (const VerilatedVar* topvarp = m_topscopep->varFind(m_it->second.name())) - return ((new VerilatedVpioVar{topvarp, m_topscopep})->castVpiHandle()); + if (const VerilatedVar* topvarp = m_topscopep->varFind(m_it->second.name())) { + if (topvarp->isParam()) { + return ((new VerilatedVpioParam{topvarp, m_topscopep})->castVpiHandle()); + } else { + return ((new VerilatedVpioVar{topvarp, m_topscopep})->castVpiHandle()); + } + } + } + if (m_it->second.isParam()) { + return ((new VerilatedVpioParam{&(m_it->second), m_scopep})->castVpiHandle()); + } else { + return ((new VerilatedVpioVar{&(m_it->second), m_scopep})->castVpiHandle()); } - return ((new VerilatedVpioVar{&(m_it->second), m_scopep})->castVpiHandle()); } } }; diff --git a/test_regress/t/t_vpi_package.cpp b/test_regress/t/t_vpi_package.cpp index b171b3fbe..7d16c2283 100644 --- a/test_regress/t/t_vpi_package.cpp +++ b/test_regress/t/t_vpi_package.cpp @@ -75,7 +75,9 @@ int count_params(TestVpiHandle& handle, int expectedParams) { int params = 0; while (true) { TestVpiHandle handle = vpi_scan(it); - if (handle == NULL) break; + if (!handle) break; + const int vpi_type = vpi_get(vpiType, handle); + CHECK_RESULT(vpi_type, vpiParameter); params++; } it.freed();