From 840446c5530de472d103fceb15c56d4310de755b Mon Sep 17 00:00:00 2001 From: Diego Roux Date: Thu, 26 Sep 2024 01:18:26 -0600 Subject: [PATCH] vpi_get_value_array: added vpiRawTwoStateVal support. Signed-off-by: Diego Roux --- include/verilated_vpi.cpp | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index 0beaa842a..7b474a751 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -2866,6 +2866,65 @@ void vl_get_value_array(vpiHandle object, p_vpi_arrayvalue arrayvalue_p, } } + return; + } else if (arrayvalue_p->format == vpiRawTwoStateVal) { + PLI_BYTE8 *value_ptr; + + if (arrayvalue_p->flags & vpiUserAllocFlag) { + value_ptr = arrayvalue_p->value.rawvals; + } else { + int ngroups; + + switch (varp->vltype()) { + case VLVT_UINT8: + ngroups = 1; break; + case VLVT_UINT16: + ngroups = 2; break; + case VLVT_UINT32: + ngroups = 4; break; + case VLVT_UINT64: + ngroups = 8; break; + default: + ngroups = 0; break; + } + + value_ptr = (PLI_BYTE8*)malloc(ngroups * num); + arrayvalue_p->value.rawvals = value_ptr; + } + + if (varp->vltype() == VLVT_UINT8) { + CData *ptr = reinterpret_cast(vop->varDatap()); + + for (int i = 0; i < num; i++) { + value_ptr[i] = ptr[index++]; + index = index % size; + } + } else if (varp->vltype() == VLVT_UINT16) { + SData *ptr = reinterpret_cast(vop->varDatap()); + SData *rawvals = reinterpret_cast(value_ptr); + + for (int i = 0; i < num; i++) { + rawvals[i] = ptr[index++]; + index = index % size; + } + } else if (varp->vltype() == VLVT_UINT32) { + IData *ptr = reinterpret_cast(vop->varDatap()); + IData *rawvals = reinterpret_cast(value_ptr); + + for (int i = 0; i < num; i++) { + rawvals[i] = ptr[index++]; + index = index % size; + } + } else if (varp->vltype() == VLVT_UINT64) { + QData *ptr = reinterpret_cast(vop->varDatap()); + QData *rawvals = reinterpret_cast(value_ptr); + + for (int i = 0; i < num; i++) { + rawvals[i] = ptr[index++]; + index = index % size; + } + } + return; } @@ -2898,6 +2957,18 @@ void vpi_get_value_array(vpiHandle object, p_vpi_arrayvalue arrayvalue_p, __func__, vop->fullname(), varp->dims()); } + switch (varp->vltype()) { + case VLVT_UINT8: + case VLVT_UINT16: + case VLVT_UINT32: + case VLVT_UINT64: + case VLVT_REAL: + break; + default: + VL_VPI_ERROR_(__FILE__, __LINE__, "%s: Unsupported type (%u) as requested for %s", __func__, + varp->vltype(), vop->fullname()); + } + vl_get_value_array(object, arrayvalue_p, index_p, num); }