DEADSOFTWARE

implement Kernel.Call for CPfront using libffi
[cpc.git] / src / cpfront / 486 / Lib / Mod / FFI.cp
1 MODULE LibFFI ["ffi.h"];
3 IMPORT SYSTEM, types := PosixCtypes, sys_types := PosixCsys_types;
5 CONST
6 SIZEOF_ARG* = 4;
8 CONST (* abi *)
9 FIRST_ABI* = 0;
10 SYSV* = 1;
11 STDCALL_WIN32* = 2; (* FFI_STDCALL for win32 *)
12 THISCALL* = 3;
13 FASTCALL* = 4;
14 MS_CDECL_WIN32* = 5; (* FFI_MS_CDECL for win32 *)
15 STDCALL_GENERIC* = 5; (* FFI_STDCALL for ~win32 *)
16 PASCAL* = 6;
17 REGISTER* = 7;
18 LAST_ABI* = 7;
19 DEFAULT_ABI* = SYSV;
21 CONST (* status *)
22 OK* = 0; BAD_TYPEDEF* = 1; BAD_ABI* = 2;
24 CONST
25 TYPE_VOID* = 0;
26 TYPE_INT* = 1;
27 TYPE_FLOAT* = 2;
28 TYPE_DOUBLE* = 3;
29 TYPE_LONGDOUBLE* = 4;
30 TYPE_UINT8* = 5;
31 TYPE_SINT8* = 6;
32 TYPE_UINT16* = 7;
33 TYPE_SINT16* = 8;
34 TYPE_UINT32* = 9;
35 TYPE_SINT32* = 10;
36 TYPE_UINT64* = 11;
37 TYPE_SINT64* = 12;
38 TYPE_STRUCT* = 13;
39 TYPE_POINTER* = 14;
40 TYPE_COMPLEX* = 15;
41 TYPE_LAST* = TYPE_COMPLEX;
43 TYPE
44 abi* ["ffi_abi"] = types.int; (* !!! enum *)
45 status* ["ffi_status"] = types.int; (* !!! enum *)
47 (* Ptype* = POINTER [untagged] TO type;
48 PPtype* = POINTER [untagged] TO ARRAY [untagged] OF Ptype; *)
49 type* ["ffi_type"] = RECORD [untagged]
50 size*: sys_types.size_t;
51 alignment*: types.unsigned_short;
52 type*: types.unsigned_short;
53 elements*: POINTER [untagged] TO ARRAY [untagged] OF POINTER TO type;
54 END;
56 (* Pcif* = POINTER TO cif; *)
57 cif* ["ffi_cif"] = RECORD [untagged]
58 abi*: abi;
59 nargs*: types.unsigned;
60 arg_type*: POINTER [untagged] TO ARRAY [untagged] OF POINTER TO type;
61 rtype*: POINTER TO type;
62 bytes*: types.unsigned;
63 flags*: types.unsigned;
64 END;
66 VAR
67 type_void- ["ffi_type_void"]: type;
68 type_uint8- ["ffi_type_uint8"]: type;
69 type_sint8- ["ffi_type_sint8"]: type;
70 type_uint16- ["ffi_type_uint16"]: type;
71 type_sint16- ["ffi_type_sint16"]: type;
72 type_uint32- ["ffi_type_uint32"]: type;
73 type_sint32- ["ffi_type_sint32"]: type;
74 type_uint64- ["ffi_type_uint64"]: type;
75 type_sint64- ["ffi_type_sint64"]: type;
76 type_float- ["ffi_type_float"]: type;
77 type_double- ["ffi_type_double"]: type;
78 type_pointer- ["ffi_type_pointer"]: type;
79 type_longdouble- ["ffi_type_longdouble"]: type;
81 type_complex_single- ["ffi_type_complex_single"]: type;
82 type_complex_double- ["ffi_type_complex_double"]: type;
83 type_complex_longdouble- ["ffi_type_complex_longdouble"]: type;
85 PROCEDURE [ccall] prep_cif* ["ffi_prep_cif"] (VAR c: cif; a: abi; nargs: types.unsigned_int; rtype: POINTER TO type; atypes: POINTER [untagged] TO ARRAY [untagged] OF POINTER TO type): status;
86 PROCEDURE [ccall] prep_cif_var* ["ffi_prep_cif_var"] (VAR c: cif; a: abi; nfixedargs, ntotalargs: types.unsigned_int; rtype: POINTER TO type; atypes: POINTER [untagged] TO ARRAY [untagged] OF POINTER TO type): status;
87 PROCEDURE [ccall] call* ["ffi_call"] (VAR c: cif; fn, rvalue, avalue: SYSTEM.ADDRESS);
89 END LibFFI.