Search code examples
system-verilogvpi

How to check if a Systemverilog associative array has a key using VPI


I'm trying to access Systemverilog associative array from C using VPI. I can access the array element for a key using the following code if I provide an existing key.

index = vpi_handle_by_index(reg_array, 200); // 200 is a valid key
vpi_value.format = vpiIntVal;
vpi_get_value(index, &vpi_value);

But this code generates an ERROR message if key is not valid (non-existing). How can I check if a key exists in the array without generating an ERROR message?


Solution

  • The VPI provides no mechanism to see if a key exists. You can only iterate over all array elements and collect the keys using vpi_handle (vpiIndex, var_select_handle) on each element and stop when you get a match.