Internals: Refactor VPI case statement. No functional change intended

This commit is contained in:
Wilson Snyder 2026-03-27 21:51:34 -04:00
parent 8d109e85d0
commit 82c817d425
1 changed files with 45 additions and 34 deletions

View File

@ -2773,73 +2773,78 @@ void vpi_put_delays(vpiHandle /*object*/, p_vpi_delay /*delay_p*/) { VL_VPI_UNIM
// value processing // value processing
bool vl_check_format(const VerilatedVpioVarBase* vop, const p_vpi_value valuep, bool isGetValue) { bool vl_check_format(const VerilatedVpioVarBase* vop, const p_vpi_value valuep, bool isGetValue) {
const VerilatedVar* varp = vop->varp(); const VerilatedVar* varp = vop->varp();
bool status = true; switch (valuep->format) {
if ((valuep->format == vpiVectorVal) || (valuep->format == vpiBinStrVal) case vpiVectorVal: // FALLTHRU
|| (valuep->format == vpiOctStrVal) || (valuep->format == vpiHexStrVal)) { case vpiBinStrVal: // FALLTHRU
case vpiOctStrVal: // FALLTHRU
case vpiHexStrVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_UINT8: case VLVT_UINT8:
case VLVT_UINT16: case VLVT_UINT16:
case VLVT_UINT32: case VLVT_UINT32:
case VLVT_UINT64: case VLVT_UINT64:
case VLVT_WDATA: return status; case VLVT_WDATA: return true;
default: status = false; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
} else if (valuep->format == vpiDecStrVal) { break;
case vpiDecStrVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_UINT8: case VLVT_UINT8:
case VLVT_UINT16: case VLVT_UINT16:
case VLVT_UINT32: case VLVT_UINT32:
case VLVT_UINT64: return status; case VLVT_UINT64: return true;
default: status = false; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
} else if (valuep->format == vpiStringVal) { break;
case vpiStringVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_UINT8: case VLVT_UINT8:
case VLVT_UINT16: case VLVT_UINT16:
case VLVT_UINT32: case VLVT_UINT32:
case VLVT_UINT64: case VLVT_UINT64:
case VLVT_WDATA: return status; case VLVT_WDATA: return true;
case VLVT_STRING: case VLVT_STRING:
// string parameter values can't be changed // string parameter values can't be changed
if (isGetValue || !varp->isParam()) { if (isGetValue || !varp->isParam()) {
return status; return true;
} else { } else {
status = false;
break; break;
} }
default: status = false; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
} else if (valuep->format == vpiIntVal) { break;
case vpiIntVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_UINT8: case VLVT_UINT8:
case VLVT_UINT16: case VLVT_UINT16:
case VLVT_UINT32: case VLVT_UINT32:
case VLVT_UINT64: case VLVT_UINT64:
case VLVT_WDATA: return status; case VLVT_WDATA: return true;
default: status = false; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
} else if (valuep->format == vpiRealVal) { break;
case vpiRealVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_REAL: return status; case VLVT_REAL: return true;
default: status = false; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
} else if (valuep->format == vpiScalarVal) { break;
case vpiScalarVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_UINT8: case VLVT_UINT8:
case VLVT_UINT16: case VLVT_UINT16:
case VLVT_UINT32: case VLVT_UINT32:
case VLVT_UINT64: case VLVT_UINT64:
case VLVT_WDATA: return status; case VLVT_WDATA: return true;
default: status = false; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
} else if (valuep->format == vpiSuppressVal) { break;
return status; case vpiSuppressVal: return true;
} else { default: break;
status = false;
} }
VL_VPI_ERROR_(__FILE__, __LINE__, "%s: Unsupported format (%s) for '%s'", __func__, VL_VPI_ERROR_(__FILE__, __LINE__, "%s: Unsupported format (%s) for '%s'", __func__,
VerilatedVpiError::strFromVpiVal(valuep->format), vop->fullname()); VerilatedVpiError::strFromVpiVal(valuep->format), vop->fullname());
return status; return false;
} }
// Get a VPI format that can be used to fully represent a signal of the given type // Get a VPI format that can be used to fully represent a signal of the given type
@ -3520,7 +3525,8 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_
bool vl_check_array_format(const VerilatedVar* varp, const p_vpi_arrayvalue arrayvalue_p, bool vl_check_array_format(const VerilatedVar* varp, const p_vpi_arrayvalue arrayvalue_p,
const char* fullname) { const char* fullname) {
if (arrayvalue_p->format == vpiVectorVal) { switch (arrayvalue_p->format) {
case vpiVectorVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_UINT8: case VLVT_UINT8:
case VLVT_UINT16: case VLVT_UINT16:
@ -3529,15 +3535,17 @@ bool vl_check_array_format(const VerilatedVar* varp, const p_vpi_arrayvalue arra
case VLVT_WDATA: return true; case VLVT_WDATA: return true;
default:; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
} else if (arrayvalue_p->format == vpiIntVal) { break;
case vpiIntVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_UINT8: case VLVT_UINT8:
case VLVT_UINT16: case VLVT_UINT16:
case VLVT_UINT32: return true; case VLVT_UINT32: return true;
default:; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
} else if ((arrayvalue_p->format == vpiRawTwoStateVal) break;
|| (arrayvalue_p->format == vpiRawFourStateVal)) { case vpiRawTwoStateVal:
case vpiRawFourStateVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_UINT8: case VLVT_UINT8:
case VLVT_UINT16: case VLVT_UINT16:
@ -3546,13 +3554,15 @@ bool vl_check_array_format(const VerilatedVar* varp, const p_vpi_arrayvalue arra
case VLVT_WDATA: return true; case VLVT_WDATA: return true;
default:; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
} else if (arrayvalue_p->format == vpiShortIntVal) { break;
case vpiShortIntVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_UINT8: case VLVT_UINT8:
case VLVT_UINT16: return true; case VLVT_UINT16: return true;
default:; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
} else if (arrayvalue_p->format == vpiLongIntVal) { break;
case vpiLongIntVal:
switch (varp->vltype()) { switch (varp->vltype()) {
case VLVT_UINT8: case VLVT_UINT8:
case VLVT_UINT16: case VLVT_UINT16:
@ -3560,11 +3570,12 @@ bool vl_check_array_format(const VerilatedVar* varp, const p_vpi_arrayvalue arra
case VLVT_UINT64: return true; case VLVT_UINT64: return true;
default:; // LCOV_EXCL_LINE default:; // LCOV_EXCL_LINE
} }
break;
default:;
} }
VL_VPI_ERROR_(__FILE__, __LINE__, "%s: Unsupported format (%s) as requested for '%s'", VL_VPI_ERROR_(__FILE__, __LINE__, "%s: Unsupported format (%s) as requested for '%s'",
__func__, VerilatedVpiError::strFromVpiVal(arrayvalue_p->format), fullname); __func__, VerilatedVpiError::strFromVpiVal(arrayvalue_p->format), fullname);
return false; return false;
} }