Support vpiScalarVal

This commit is contained in:
Wilson Snyder 2026-02-22 20:04:06 -05:00
parent 1e5a6901c8
commit 97fd6a5a13
2 changed files with 34 additions and 12 deletions

View File

@ -2555,6 +2555,15 @@ bool vl_check_format(const VerilatedVpioVarBase* vop, const p_vpi_value valuep,
case VLVT_REAL: return status;
default: status = false; // LCOV_EXCL_LINE
}
} else if (valuep->format == vpiScalarVal) {
switch (varp->vltype()) {
case VLVT_UINT8:
case VLVT_UINT16:
case VLVT_UINT32:
case VLVT_UINT64:
case VLVT_WDATA: return status;
default: status = false; // LCOV_EXCL_LINE
}
} else if (valuep->format == vpiSuppressVal) {
return status;
} else {
@ -2894,6 +2903,9 @@ void vl_vpi_get_value(const VerilatedVpioVarBase* vop, p_vpi_value valuep) {
else
valuep->value.real = *vop->varRealDatap();
return;
} else if (valuep->format == vpiScalarVal) {
valuep->value.scalar = get_word(vop, 32, 0) ? vpi1 : vpi0;
return;
} else if (valuep->format == vpiSuppressVal) {
return;
@ -3175,6 +3187,9 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_
*(valueVop->varRealDatap()) = valuep->value.real;
return object;
}
} else if (valuep->format == vpiScalarVal) {
vl_vpi_put_word(valueVop, (valuep->value.scalar == vpi1 ? 1 : 0), 1, 0);
return object;
}
VL_VPI_ERROR_(__FILE__, __LINE__, "%s: Unsupported format (%s) as requested for %s",
__func__, VerilatedVpiError::strFromVpiVal(valuep->format),

View File

@ -420,18 +420,25 @@ int _mon_check_var() {
}
// other unsigned types
constexpr struct {
const char* name;
PLI_INT32 exp_type;
} uint_vars[] = {
// uvm_hdl_polling.v requires single bits return vpiBitVar
{"bit1", vpiBitVar},
};
for (const auto& s : uint_vars) {
TestVpiHandle vh101 = VPI_HANDLE(s.name);
CHECK_RESULT_NZ(vh101);
d = vpi_get(vpiType, vh101);
CHECK_RESULT(d, s.exp_type);
{
TestVpiHandle vh999 = VPI_HANDLE("bit1");
CHECK_RESULT_NZ(vh999);
d = vpi_get(vpiType, vh999);
CHECK_RESULT(d, vpiBitVar); // Required by uvm_hdl_polling
for (PLI_INT32 i : {vpi0, vpi1, vpiX, vpiZ}) {
t_vpi_value value;
value.format = vpiScalarVal;
value.value.scalar = i;
vpi_put_value(vh999, &value, NULL, vpiNoDelay);
value.value.scalar = 9;
vpi_get_value(vh999, &value);
#ifdef VERILATOR // 2-state
const PLI_INT32 expv = (i == vpi1) ? vpi1 : vpi0;
#else
const PLI_INT32 expv = i;
#endif
TEST_CHECK_EQ(value.value.scalar, expv);
}
}
// other integer types