From: Ketmar Dark Date: Tue, 26 Sep 2017 08:52:48 +0000 (+0300) Subject: some fixes to LibJIT bindings X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=0987bc582bf46d6b6540e036efeae52b9ba8d8c1;p=d2df-sdl.git some fixes to LibJIT bindings --- diff --git a/src/lib/libjit/libjit.pas b/src/lib/libjit/libjit.pas index 2939893..1310c8e 100644 --- a/src/lib/libjit/libjit.pas +++ b/src/lib/libjit/libjit.pas @@ -34,13 +34,14 @@ interface const {$IFDEF MSWINDOWS} - LIBJIT_LIBNAME = 'libjit.dll'; - {$DEFINE libraryLibJITDecl := cdecl} - {$DEFINE libraryLibJITImp := cdecl; external LIBJIT_LIBNAME} + //{$LINKLIB libjit.dll.a} + LIBJIT_LIBNAME = 'libjit-0.dll'; + {$DEFINE libraryLibJITDecl := cdecl} + {$DEFINE libraryLibJITImp := cdecl; external LIBJIT_LIBNAME} {$ELSE} - LIBJIT_LIBNAME = 'jit'; - {$DEFINE libraryLibJITDecl := cdecl} - {$DEFINE libraryLibJITImp := cdecl; external LIBJIT_LIBNAME} + LIBJIT_LIBNAME = 'jit'; + {$DEFINE libraryLibJITDecl := cdecl} + {$DEFINE libraryLibJITImp := cdecl; external LIBJIT_LIBNAME} {$ENDIF} diff --git a/src/lib/libjit/libjit_types.pas b/src/lib/libjit/libjit_types.pas index f6d997d..9c05368 100644 --- a/src/lib/libjit/libjit_types.pas +++ b/src/lib/libjit/libjit_types.pas @@ -35,6 +35,8 @@ interface uses libjit; +//LIBJIT_LIBNAME = 'libjit.dll'; +{$IF not DEFINED(MSWINDOWS)} (*const*) var jit_opcodes: packed array [0..JIT_OP_NUM_OPCODES-1] of jit_opcode_info_t; cvar; external LIBJIT_LIBNAME; (* @@ -76,8 +78,129 @@ uses (*const*) var jit_type_sys_double: jit_type_t; cvar; external LIBJIT_LIBNAME; (*const*) var jit_type_sys_long_double: jit_type_t; cvar; external LIBJIT_LIBNAME; +{$ELSE} +function jit_type_void (): jit_type_t; +function jit_type_sbyte (): jit_type_t; +function jit_type_ubyte (): jit_type_t; +function jit_type_short (): jit_type_t; +function jit_type_ushort (): jit_type_t; +function jit_type_int (): jit_type_t; +function jit_type_uint (): jit_type_t; +function jit_type_nint (): jit_type_t; +function jit_type_nuint (): jit_type_t; +function jit_type_long (): jit_type_t; +function jit_type_ulong (): jit_type_t; +function jit_type_float32 (): jit_type_t; +function jit_type_float64 (): jit_type_t; +function jit_type_nfloat (): jit_type_t; +function jit_type_void_ptr (): jit_type_t; + +function jit_type_sys_bool (): jit_type_t; +function jit_type_sys_char (): jit_type_t; +function jit_type_sys_schar (): jit_type_t; +function jit_type_sys_uchar (): jit_type_t; +function jit_type_sys_short (): jit_type_t; +function jit_type_sys_ushort (): jit_type_t; +function jit_type_sys_int (): jit_type_t; +function jit_type_sys_uint (): jit_type_t; +function jit_type_sys_long (): jit_type_t; +function jit_type_sys_ulong (): jit_type_t; +function jit_type_sys_longlong (): jit_type_t; +function jit_type_sys_ulonglong (): jit_type_t; +function jit_type_sys_float (): jit_type_t; +function jit_type_sys_double (): jit_type_t; +function jit_type_sys_long_double (): jit_type_t; +{$ENDIF} + implementation +{$IF DEFINED(MSWINDOWS)} +uses + Windows, SysUtils; + +var + libjitH: HModule = 0; + + +function libjitImport (const name: AnsiString): Pointer; +begin + if (libjitH = 0) then + begin + libjitH := LoadLibrary(LIBJIT_LIBNAME); + if (libjitH = 0) then raise Exception.Create('cannot load '+LIBJIT_LIBNAME); + end; + result := GetProcAddress(libjitH, PAnsiChar(name)); + if (result = nil) then raise Exception.Create('cannot load '''+name+''' from '+LIBJIT_LIBNAME); +end; + + +var + imp_jit_type_void: Pointer = nil; + imp_jit_type_sbyte: Pointer = nil; + imp_jit_type_ubyte: Pointer = nil; + imp_jit_type_short: Pointer = nil; + imp_jit_type_ushort: Pointer = nil; + imp_jit_type_int: Pointer = nil; + imp_jit_type_uint: Pointer = nil; + imp_jit_type_nint: Pointer = nil; + imp_jit_type_nuint: Pointer = nil; + imp_jit_type_long: Pointer = nil; + imp_jit_type_ulong: Pointer = nil; + imp_jit_type_float32: Pointer = nil; + imp_jit_type_float64: Pointer = nil; + imp_jit_type_nfloat: Pointer = nil; + imp_jit_type_void_ptr: Pointer = nil; + + imp_jit_type_sys_bool: Pointer = nil; + imp_jit_type_sys_char: Pointer = nil; + imp_jit_type_sys_schar: Pointer = nil; + imp_jit_type_sys_uchar: Pointer = nil; + imp_jit_type_sys_short: Pointer = nil; + imp_jit_type_sys_ushort: Pointer = nil; + imp_jit_type_sys_int: Pointer = nil; + imp_jit_type_sys_uint: Pointer = nil; + imp_jit_type_sys_long: Pointer = nil; + imp_jit_type_sys_ulong: Pointer = nil; + imp_jit_type_sys_longlong: Pointer = nil; + imp_jit_type_sys_ulonglong: Pointer = nil; + imp_jit_type_sys_float: Pointer = nil; + imp_jit_type_sys_double: Pointer = nil; + imp_jit_type_sys_long_double: Pointer = nil; + + +function jit_type_void (): jit_type_t; begin if (imp_jit_type_void = nil) then imp_jit_type_void := jit_type_t(libjitImport('jit_type_void')); result := imp_jit_type_void; end; +function jit_type_sbyte (): jit_type_t; begin if (imp_jit_type_sbyte = nil) then imp_jit_type_sbyte := jit_type_t(libjitImport('jit_type_sbyte')); result := imp_jit_type_sbyte; end; +function jit_type_ubyte (): jit_type_t; begin if (imp_jit_type_ubyte = nil) then imp_jit_type_ubyte := jit_type_t(libjitImport('jit_type_ubyte')); result := imp_jit_type_ubyte; end; +function jit_type_short (): jit_type_t; begin if (imp_jit_type_short = nil) then imp_jit_type_short := jit_type_t(libjitImport('jit_type_short')); result := imp_jit_type_short; end; +function jit_type_ushort (): jit_type_t; begin if (imp_jit_type_ushort = nil) then imp_jit_type_ushort := jit_type_t(libjitImport('jit_type_ushort')); result := imp_jit_type_ushort; end; +function jit_type_int (): jit_type_t; begin if (imp_jit_type_int = nil) then imp_jit_type_int := jit_type_t(libjitImport('jit_type_int')); result := imp_jit_type_int; end; +function jit_type_uint (): jit_type_t; begin if (imp_jit_type_uint = nil) then imp_jit_type_uint := jit_type_t(libjitImport('jit_type_uint')); result := imp_jit_type_uint; end; +function jit_type_nint (): jit_type_t; begin if (imp_jit_type_nint = nil) then imp_jit_type_nint := jit_type_t(libjitImport('jit_type_nint')); result := imp_jit_type_nint; end; +function jit_type_nuint (): jit_type_t; begin if (imp_jit_type_nuint = nil) then imp_jit_type_nuint := jit_type_t(libjitImport('jit_type_nuint')); result := imp_jit_type_nuint; end; +function jit_type_long (): jit_type_t; begin if (imp_jit_type_long = nil) then imp_jit_type_long := jit_type_t(libjitImport('jit_type_long')); result := imp_jit_type_long; end; +function jit_type_ulong (): jit_type_t; begin if (imp_jit_type_ulong = nil) then imp_jit_type_ulong := jit_type_t(libjitImport('jit_type_ulong')); result := imp_jit_type_ulong; end; +function jit_type_float32 (): jit_type_t; begin if (imp_jit_type_float32 = nil) then imp_jit_type_float32 := jit_type_t(libjitImport('jit_type_float32')); result := imp_jit_type_float32; end; +function jit_type_float64 (): jit_type_t; begin if (imp_jit_type_float64 = nil) then imp_jit_type_float64 := jit_type_t(libjitImport('jit_type_float64')); result := imp_jit_type_float64; end; +function jit_type_nfloat (): jit_type_t; begin if (imp_jit_type_nfloat = nil) then imp_jit_type_nfloat := jit_type_t(libjitImport('jit_type_nfloat')); result := imp_jit_type_nfloat; end; +function jit_type_void_ptr (): jit_type_t; begin if (imp_jit_type_void_ptr = nil) then imp_jit_type_void_ptr := jit_type_t(libjitImport('jit_type_void_ptr')); result := imp_jit_type_void_ptr; end; + +function jit_type_sys_bool (): jit_type_t; begin if (imp_jit_type_sys_bool = nil) then imp_jit_type_sys_bool := jit_type_t(libjitImport('jit_type_sys_bool')); result := imp_jit_type_sys_bool; end; +function jit_type_sys_char (): jit_type_t; begin if (imp_jit_type_sys_char = nil) then imp_jit_type_sys_char := jit_type_t(libjitImport('jit_type_sys_char')); result := imp_jit_type_sys_char; end; +function jit_type_sys_schar (): jit_type_t; begin if (imp_jit_type_sys_schar = nil) then imp_jit_type_sys_schar := jit_type_t(libjitImport('jit_type_sys_schar')); result := imp_jit_type_sys_schar; end; +function jit_type_sys_uchar (): jit_type_t; begin if (imp_jit_type_sys_uchar = nil) then imp_jit_type_sys_uchar := jit_type_t(libjitImport('jit_type_sys_uchar')); result := imp_jit_type_sys_uchar; end; +function jit_type_sys_short (): jit_type_t; begin if (imp_jit_type_sys_short = nil) then imp_jit_type_sys_short := jit_type_t(libjitImport('jit_type_sys_short')); result := imp_jit_type_sys_short; end; +function jit_type_sys_ushort (): jit_type_t; begin if (imp_jit_type_sys_ushort = nil) then imp_jit_type_sys_ushort := jit_type_t(libjitImport('jit_type_sys_ushort')); result := imp_jit_type_sys_ushort; end; +function jit_type_sys_int (): jit_type_t; begin if (imp_jit_type_sys_int = nil) then imp_jit_type_sys_int := jit_type_t(libjitImport('jit_type_sys_int')); result := imp_jit_type_sys_int; end; +function jit_type_sys_uint (): jit_type_t; begin if (imp_jit_type_sys_uint = nil) then imp_jit_type_sys_uint := jit_type_t(libjitImport('jit_type_sys_uint')); result := imp_jit_type_sys_uint; end; +function jit_type_sys_long (): jit_type_t; begin if (imp_jit_type_sys_long = nil) then imp_jit_type_sys_long := jit_type_t(libjitImport('jit_type_sys_long')); result := imp_jit_type_sys_long; end; +function jit_type_sys_ulong (): jit_type_t; begin if (imp_jit_type_sys_ulong = nil) then imp_jit_type_sys_ulong := jit_type_t(libjitImport('jit_type_sys_ulong')); result := imp_jit_type_sys_ulong; end; +function jit_type_sys_longlong (): jit_type_t; begin if (imp_jit_type_sys_longlong = nil) then imp_jit_type_sys_longlong := jit_type_t(libjitImport('jit_type_sys_longlong')); result := imp_jit_type_sys_longlong; end; +function jit_type_sys_ulonglong (): jit_type_t; begin if (imp_jit_type_sys_ulonglong = nil) then imp_jit_type_sys_ulonglong := jit_type_t(libjitImport('jit_type_sys_ulonglong')); result := imp_jit_type_sys_ulonglong; end; +function jit_type_sys_float (): jit_type_t; begin if (imp_jit_type_sys_float = nil) then imp_jit_type_sys_float := jit_type_t(libjitImport('jit_type_sys_float')); result := imp_jit_type_sys_float; end; +function jit_type_sys_double (): jit_type_t; begin if (imp_jit_type_sys_double = nil) then imp_jit_type_sys_double := jit_type_t(libjitImport('jit_type_sys_double')); result := imp_jit_type_sys_double; end; +function jit_type_sys_long_double (): jit_type_t; begin if (imp_jit_type_sys_long_double = nil) then imp_jit_type_sys_long_double := jit_type_t(libjitImport('jit_type_sys_long_double')); result := imp_jit_type_sys_long_double; end; +{$ENDIF} + end. diff --git a/src/lib/libjit/t1.dpr b/src/lib/libjit/t1.dpr index 95696b4..c0e13cb 100644 --- a/src/lib/libjit/t1.dpr +++ b/src/lib/libjit/t1.dpr @@ -36,7 +36,6 @@ var res: jit_int; begin if (jit_type_int = nil) then raise Exception.Create('fuuuuu (0)'); - //if (PPointer(jit_type_int)^ = nil) then raise Exception.Create('fuuuuu (1)'); (* Create a context to hold the JIT's primary state *) writeln('creating context...');