The SystemVerilog DPI supports only SystemVerilog data types, which are the data types that can cross the boundary between SystemVerilog and a foreign language in both the direction. On the other hand, the data types used in C code shall be C types. A value that is passed through the DPI is specified in SystemVerilog code as a value of SystemVerilog data type, while the same value is declared C code as a value of C data type. Therefore, a pair of matching type definitions is required to pass a value through DPI, the SystemVerilog definition and the C definition.
The following SystemVerilog types are the only permitted types for formal arguments of import and export tasks or functions:
void, byte, shortint, int, longint, real, shortreal, chandle, and string
Scalar values of type bit and logic
Packed arrays, structs, and unions composed of types bit and logic. Every packed type is eventually equivalent to a packed one-dimensional array. On the foreign language side of the DPI, all packed types are perceived as packed one-dimensional arrays regardless of their declaration in the SystemVerilog code.
Enumeration types interpreted as the type associated with that enumeration
Types constructed from the supported types with the help of the constructs: struct , union , Unpacked array , typedef
Mapping data types
Passing Logic Datatype
The DPI defines the canonical representation of packed 2-state (type svBitVecVal) and 4-state arrays (type svBitVecVal). svLogicVecVal is fully equivalent to type s_vpi_vecval, which is used to represent 4-state logic in VPI.
CODE:SV_file.sv program main;
logic a;
import "DPI" functionvoid show(logic a);
initialbegin a = 1'b0;
show(a);
a = 1'b1;
show(a);
a = 1'bX;
show(a);
a = 1'bZ;
show(a);
end endprogram
void show(svLogic a){
if(a == 0)
printf(" a is 0 \n");
elseif(a == 1)
printf(" a is 1 \n");
elseif(a == 2)
printf(" a is x \n");
elseif(a == 3)
printf(" a is z \n");