Hi all, i’m trying to get array from cpp code to my sv code and get the error:
xmsim: *F,SIGUSR: Unix Signal SIGSEGV raised from user application code. Stack trace information is captured in file sigusrdump.out.
sv code:
function void nmu_sv_get_l_y_msb_array_by_index(int index);
int result[];
result = new [100];
nmu_cpp_get_l_y_msb_array_by_index(index,p_nmu_simulator,result);
endfunction : nmu_sv_get_l_y_msb_array_by_index
import from sv:
import "DPI-C" context function void nmu_cpp_get_l_y_msb_array_by_index(int index,chandle handle, output int result[]);
cpp code:
void nmu_cpp_get_l_y_msb_array_by_index(int index,void* handle ,svOpenArrayHandle result){
myclass* p_cpp_nmu = static_cast<myclass *>(handle);
uint32_t myArray[2]= {8,10};
svPutBitArrElemVecVal(result,myArray, 1); // fail in run time in this line
}
Your issue is the declaration of ‘result’ in the SV code. You are declaring ‘result’ as a dynamic array, where the DPI is expecting a static array. These data types are different and not compatible.
You want:
function void nmu_sv_get_l_y_msb_array_by_index(int index);
int result[100];
nmu_cpp_get_l_y_msb_array_by_index(index,p_nmu_simulator,result);
endfunction : nmu_sv_get_l_y_msb_array_by_index
import "DPI-C" function void nmu_cpp_get_l_y_msb_array_by_index(int index,chandle handle, output int result[]);
module test();
function void nmu_sv_get_l_y_msb_array_by_index(int index);
int result[100];
nmu_cpp_get_l_y_msb_array_by_index(index,null,result);
endfunction : nmu_sv_get_l_y_msb_array_by_index
initial begin
nmu_sv_get_l_y_msb_array_by_index(1);
end
endmodule