Search code examples
system-verilogvpi

How to add a new key to a Systemverilog associative array using VPI


I'm trying to access Systemverilog associative array from C using VPI. I can write a value to an array element for a key using the following code if the key is already there.

index = vpi_handle_by_index(reg_array, 200); // 200 is an existing key
vpi_value.format = vpiIntVal;
vpi_value.value.integer = (PLI_INT32)array_var_val;
vpi_put_value(index, &vpi_value, NULL, vpiNoDelay);

vpi_handle_by_index() returns a NULL if a key doesn't exist already. My question is how can I add a new key to an associative array?

Similarly, I also want to push a value to a Systemverilog Queue using VPI. How can I implement push_back(val) method using VPI?


Solution

  • There is no way to modify the size of a dynamic array/queue through the VPI. The SystemVerilog VPI is missing many features that deal with dynamically allocated arrays.

    The VPI is mainly a tool interface that interacts with the existing design database. You should be using the DPI as a modeling/inter-language interface.