0

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?

user2756376
  • 117
  • 9
  • The LRM says the `vpi_handle_by_index` shall return `null` if a valid handle cannot be gotten from the given index. Have you tested for `index == null` on an index you know doesnt exist? Associative arrays in SV do allow for reads from nonexisting entries, so it might just return that, though. – Unn Aug 08 '18 at 17:36
  • @Unn, the behavior of accessing an associative array may not be the same from the VPI. – dave_59 Aug 08 '18 at 17:55
  • Yes, it returns a NULL so that I can check but it generates an ERROR message, which I want to avoid. – user2756376 Aug 08 '18 at 18:21

1 Answers1

1

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.

dave_59
  • 39,096
  • 3
  • 24
  • 63
  • Thanks, Dave. That is exactly what I suspected. And, it matches the behavior from Systemverilog. It is inconvenient that you cannot check if a key is actually exists or not when you are accessing the array from other language. I thought about iterating over the array but I was hoping I didn't need to resort to such brute force solution ... – user2756376 Aug 08 '18 at 18:23