mirror of
https://github.com/verilator/verilator.git
synced 2025-01-01 04:07:34 +00:00
Add vpiConstType
support to vpi_get_str()
(#4797)
This commit is contained in:
parent
e430ea13f4
commit
0195fe9dfd
@ -855,6 +855,7 @@ public:
|
||||
static const char* strFromVpiMethod(PLI_INT32 vpiVal) VL_PURE;
|
||||
static const char* strFromVpiCallbackReason(PLI_INT32 vpiVal) VL_PURE;
|
||||
static const char* strFromVpiProp(PLI_INT32 vpiVal) VL_PURE;
|
||||
static const char* strFromVpiConstType(PLI_INT32 vpiVal) VL_PURE;
|
||||
};
|
||||
|
||||
//======================================================================
|
||||
@ -1372,6 +1373,23 @@ const char* VerilatedVpiError::strFromVpiProp(PLI_INT32 vpiVal) VL_PURE {
|
||||
if (vpiVal == vpiUndefined) return "vpiUndefined";
|
||||
return names[(vpiVal <= vpiIsProtected) ? vpiVal : 0];
|
||||
}
|
||||
const char* VerilatedVpiError::strFromVpiConstType(PLI_INT32 constType) VL_PURE {
|
||||
// clang-format off
|
||||
static const char* const names[] = {
|
||||
"*undefined*",
|
||||
"vpiDecConst",
|
||||
"vpiRealConst",
|
||||
"vpiBinaryConst",
|
||||
"vpiOctConst",
|
||||
"vpiHexConst",
|
||||
"vpiStringConst",
|
||||
"vpiIntConst",
|
||||
"vpiTimeConst",
|
||||
};
|
||||
// clang-format on
|
||||
if (VL_UNCOVERABLE(constType < 0)) return names[0];
|
||||
return names[(constType <= vpiTimeConst) ? constType : 0];
|
||||
}
|
||||
|
||||
#define SELF_CHECK_RESULT_CSTR(got, exp) \
|
||||
if (0 != std::strcmp((got), (exp))) { \
|
||||
@ -1643,6 +1661,15 @@ void VerilatedVpiError::selfTest() VL_MT_UNSAFE_ONE {
|
||||
SELF_CHECK_ENUM_STR(strFromVpiProp, vpiOffset);
|
||||
SELF_CHECK_ENUM_STR(strFromVpiProp, vpiStop);
|
||||
SELF_CHECK_ENUM_STR(strFromVpiProp, vpiIsProtected);
|
||||
|
||||
SELF_CHECK_ENUM_STR(strFromVpiConstType, vpiDecConst);
|
||||
SELF_CHECK_ENUM_STR(strFromVpiConstType, vpiRealConst);
|
||||
SELF_CHECK_ENUM_STR(strFromVpiConstType, vpiBinaryConst);
|
||||
SELF_CHECK_ENUM_STR(strFromVpiConstType, vpiOctConst);
|
||||
SELF_CHECK_ENUM_STR(strFromVpiConstType, vpiHexConst);
|
||||
SELF_CHECK_ENUM_STR(strFromVpiConstType, vpiStringConst);
|
||||
SELF_CHECK_ENUM_STR(strFromVpiConstType, vpiIntConst);
|
||||
SELF_CHECK_ENUM_STR(strFromVpiConstType, vpiTimeConst);
|
||||
}
|
||||
|
||||
#undef SELF_CHECK_ENUM_STR
|
||||
@ -2047,6 +2074,11 @@ PLI_BYTE8* vpi_get_str(PLI_INT32 property, vpiHandle object) {
|
||||
case vpiType: {
|
||||
return const_cast<PLI_BYTE8*>(VerilatedVpiError::strFromVpiObjType(vop->type()));
|
||||
}
|
||||
case vpiConstType: {
|
||||
const PLI_INT32 constType = vpi_get(vpiConstType, object);
|
||||
VL_VPI_ERROR_RESET_();
|
||||
return const_cast<PLI_BYTE8*>(VerilatedVpiError::strFromVpiConstType(constType));
|
||||
}
|
||||
default:
|
||||
VL_VPI_WARNING_(__FILE__, __LINE__, "%s: Unsupported type %s, nothing will be returned",
|
||||
__func__, VerilatedVpiError::strFromVpiProp(property));
|
||||
|
@ -77,22 +77,30 @@ int mon_check() {
|
||||
CHECK_RESULT_NZ(intHandle)
|
||||
PLI_INT32 intConstType = vpi_get(vpiConstType, intHandle);
|
||||
CHECK_RESULT(intConstType, vpiDecConst)
|
||||
const char* intConstTypeStr = vpi_get_str(vpiConstType, intHandle);
|
||||
CHECK_RESULT_CSTR(intConstTypeStr, "vpiDecConst")
|
||||
|
||||
TestVpiHandle realHandle = vpi_handle_by_name((PLI_BYTE8*)"t.realParam", NULL);
|
||||
CHECK_RESULT_NZ(realHandle)
|
||||
PLI_INT32 realConstType = vpi_get(vpiConstType, realHandle);
|
||||
CHECK_RESULT(realConstType, vpiRealConst)
|
||||
const char* realConstTypeStr = vpi_get_str(vpiConstType, realHandle);
|
||||
CHECK_RESULT_CSTR(realConstTypeStr, "vpiRealConst")
|
||||
|
||||
TestVpiHandle strHandle = vpi_handle_by_name((PLI_BYTE8*)"t.strParam", NULL);
|
||||
CHECK_RESULT_NZ(strHandle)
|
||||
PLI_INT32 strConstType = vpi_get(vpiConstType, strHandle);
|
||||
CHECK_RESULT(strConstType, vpiStringConst)
|
||||
const char* strConstTypeStr = vpi_get_str(vpiConstType, strHandle);
|
||||
CHECK_RESULT_CSTR(strConstTypeStr, "vpiStringConst")
|
||||
|
||||
TestVpiHandle sigHandle = vpi_handle_by_name((PLI_BYTE8*)"t.signal", NULL);
|
||||
CHECK_RESULT_NZ(sigHandle)
|
||||
PLI_INT32 sigConstType = vpi_get(vpiConstType, sigHandle);
|
||||
// t.signal is not constant
|
||||
CHECK_RESULT(sigConstType, vpiUndefined)
|
||||
const char* sigConstTypeStr = vpi_get_str(vpiConstType, sigHandle);
|
||||
CHECK_RESULT_CSTR(sigConstTypeStr, "*undefined*")
|
||||
TestVpiHandle leftHandle = vpi_handle(vpiLeftRange, sigHandle);
|
||||
CHECK_RESULT_NZ(leftHandle)
|
||||
PLI_INT32 leftConstType = vpi_get(vpiConstType, leftHandle);
|
||||
|
Loading…
Reference in New Issue
Block a user