How can I fetch the dimensions of a vector port using the vpi PLI routines? For example, for the vector port declaration "output [2:1] out;", how can I get the left dimension as 2 and right dimension as 1? I tried using vpiRange property but it seems that vpiRange property is not supported for Ports. Thanks! Putting the code here for clarity.
vpiHandle lowconn = vpi_handle(vpiLowConn, portH);
int dim = 0;
int ldim[10];
int rdim[10];
vpiHandle range_itr = vpi_iterate(vpiRange, lowconn );
vpiHandle range;
while ((range = vpi_scan(range_itr))) {
ldim[dim] = vpi_get(vpiLeftRange, range);
rdim[dim] = vpi_get(vpiRightRange, range);
dim++;
}
int size = vpi_get(vpiSize, portH);
cout << endl << vpi_get_str(vpiName, portH) << " size = " << size << " LeftRange = " << vpi_get(vpiLeftRange, lowconn ) << " RightRange = " << vpi_get(vpiRightRange, lowconn );
for ( int i = 0; i < dim; i++ ) {
cout << vpi_get_str(vpiName, portH) << " = " << ldim[i] << ":" << rdim[i];
}
I am getting -1 from vpi_get(vpiLeft/RightRange) as well as in ldim and rdim. Is there anything erroneos with my code?
Your problem is that both vpiLeftRange and vpiRightRange return vpiHandle, not the value. When you instantiate a module. They could be constant expressions, or variable index expressions (for highcon). so, you can try to get values for them. Here is an example which works for vcs.
the verilog module looks like this:
c-code is here
here is the result
This should work for simple constant expressions with parameters and literals.