I have a integer parameter array like:
parameter integer PAR_ARR [3:0] = '{ 12, 34, 56, 78 }
I want to read the values of the parameter array through VPI.
Here is what I've observed:
vpi_get(vpiType, par_handle)
returns vpiParameter
vpi_get_str(vpiDecompile, vpi_handle(vpiTypespec,par_handle))
returns integer array [3:0]
vpi_get_str(vpiType, vpi_handle(vpiTypespec,par_handle))
returns vpiArrayTypespec
vpi_get_str(vpiType, vpi_handle(vpiElemTypespec,vpi_handle(vpiTypespec,par_handle)))
returns vpiIntegerTypespec
So I am assuming this needs to be iterated over to get the individual integer values
s_vpi_value val = {vpiDecStrVal};
vpiHandle arrayIterator = vpi_iterate(vpiIntegerVar, par_handle);
if( arrayIterator != NULL ) {
vpiHandle item = NULL;
while( NULL != ( item = vpi_scan( arrayIterator ) ) ) {
vpi_get_value(item, &val);
vpi_printf("item type: %s = %s\n", vpi_get_str(vpiType, item), val.value.str);
vpi_free_object( item );
}
}
However arrayIterator returns NULL and I never enter the while loop. This same method seems to work on reg arrays but not on parameter arrays.
What am I be doing wrong here? Or does VPI not support iterating over parameter arrays? If so, is there any alternative to access the parameter value via VPI?
verilog/system verilog standard does not provide a vpi way to access members of parameter arrays. The only way I am aware of is to get data for every array element separately. Here is an example:
#include "vpi_user.h"
void dumpArray() {
vpiHandle module = vpi_handle_by_name("test", 0);
char name[16];
for (int i = 0; i < 4; i++) {
strcpy(name, "PAR_ARR[");
char num[16];
sprintf(num, "%d", i);
strcat(name, num);
strcat(name, "]");
vpiHandle pHandle = vpi_handle_by_name(name, module);
s_vpi_value value = {vpiIntVal};
vpi_get_value(pHandle, &value);
vpi_printf("%s: %d\n", name, value.value.integer);
}
}
module test;
parameter integer PAR_ARR [3:0] = '{ 12, 34, 56, 78 };
import "DPI-C" function void dumpArray();
initial begin
for (int i = 0; i < 4; i++)
$display("[%0d] --> %0d", i, PAR_ARR[i]);
dumpArray();
end
endmodule // test