Examples of Argument Passing
Imported function: passing integer from SystemVerilog to C
On the SystemVerilog side:
import "DPI" function integer my_C_func (integer my_arg);
...
result = my_c_func (some_arg);
On the C side:
int my_c_func(int);
int my_c_func(int i) {
...
}
Imported function: passing an input integer from SystemVerilog to C
On the SystemVerilog side:
import "DPI" function integer my_C_func (input integer my_arg);
...
result = my_c_func (some_arg);
On the C side:
int my_c_func(const int); // const => input
int my_c_func(const int i) {
...
}
Imported function: passing an output bit vector from SystemVerilog to C
On the SystemVerilog side:
import "DPI" function integer my_C_func (input integer my_inp_arg,
output bit [63:0] my_outp_arg);
...
result = my_c_func (some_arg);
On the C side:
int my_c_func(const int, svBitPackedArrRef);
// const => input and bit vector passed as handle
int my_c_func(const int i, svBitPackedArrRef j) {
...
}
Exported function: passing an array of int as output from C to SystemVerilog
On the SystemVerilog side:
export "DPI" function int my_SV_func;
function int my_SV_func(input int i, output j [7:0]);
begin
...
end
endfunction
On the C side:
extern int my_SV_func (int, int*);
...
// use it later on
int k, l, m;
...
k = my_SV_func (l, &m);
Previous: Passing arguments
| Next: C-side functions