dpi_import_export
::=
// from Annex A.2.6
import "DPI" [ dpi_import_property ] [ c_identifier
= ] dpi_function_proto;
The following are examples of external declarations.
import "DPI" function void myInit();
//
from standard math library
import "DPI" pure function real sin(real);
//
from standard C library: memory management
import "DPI" function chandle malloc(int size); // standard C function
import "DPI" function void free(chandle ptr); // standard C function
//
abstract data structure: queue
import "DPI" function chandle newQueue(input
string name_of_queue);
//
Note the following import uses the same foreign function for
//
implementation as the prior import, but has different SystemVerilog name
// and
provides a default value for the argument.
import "DPI" newQueue=function chandle newAnonQueue(input
string s=null);
import "DPI" function chandle newElem(bit
[15:0]);
import "DPI" function void enqueue(chandle queue, chandle elem);
import "DPI" function chandle dequeue(chandle queue);
//
miscellanea
import "DPI" function bit [15:0] getStimulus();
import "DPI” context function void processTransaction(chandle elem,
output logic [64:1] arr [0:63]);
Function result types are restricted to small values.
The following SystemVerilog data types are allowed for imported function
results:
— void, byte, shortint, int, longint, real, shortreal, chandle, and string.
— packed bit arrays up to 32 bits and all types that
are eventually equivalent to packed bit arrays up to 32 bits.
The same restrictions apply for the result types of
exported functions.
dpi_import_export
::=
// from Annex A.2.6
| export "DPI" [ c_identifier = ] function
function_identifier;