FFI work
parent
14f1f0aaae
commit
9ea2332a2b
|
@ -309,6 +309,7 @@ vectors words ;
|
||||||
"/library/compiler/amd64/assembler.factor"
|
"/library/compiler/amd64/assembler.factor"
|
||||||
"/library/compiler/amd64/architecture.factor"
|
"/library/compiler/amd64/architecture.factor"
|
||||||
"/library/compiler/x86/generator.factor"
|
"/library/compiler/x86/generator.factor"
|
||||||
|
"/library/compiler/amd64/generator.factor"
|
||||||
"/library/compiler/x86/slots.factor"
|
"/library/compiler/x86/slots.factor"
|
||||||
"/library/compiler/x86/stack.factor"
|
"/library/compiler/x86/stack.factor"
|
||||||
"/library/compiler/x86/fixnum.factor"
|
"/library/compiler/x86/fixnum.factor"
|
||||||
|
|
|
@ -1,31 +1,36 @@
|
||||||
! Copyright (C) 2005 Slava Pestov.
|
! Copyright (C) 2005, 2006 Slava Pestov.
|
||||||
! See http://factor.sf.net/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: compiler-backend
|
IN: compiler-backend
|
||||||
USING: alien assembler kernel math sequences ;
|
USING: alien arrays assembler kernel kernel-internals math
|
||||||
|
sequences ;
|
||||||
|
|
||||||
! GENERIC: store-insn ( offset reg-class -- )
|
GENERIC: store-insn ( offset reg-class -- )
|
||||||
!
|
|
||||||
! GENERIC: load-insn ( elt parameter reg-class -- )
|
GENERIC: load-insn ( elt parameter reg-class -- )
|
||||||
!
|
|
||||||
! M: int-regs store-insn drop >r 3 1 r> stack@ STW ;
|
: stack@ RCX RSP MOV RCX swap 2array ;
|
||||||
!
|
|
||||||
! M: int-regs load-insn drop 3 + 1 rot stack@ LWZ ;
|
M: int-regs store-insn
|
||||||
!
|
drop stack@ RAX MOV ;
|
||||||
! M: %unbox generate-node ( vop -- )
|
|
||||||
! drop
|
M: int-regs load-insn
|
||||||
! ! Call the unboxer
|
drop param-regs nth swap stack@ MOV ;
|
||||||
! 1 input f compile-c-call
|
|
||||||
! ! Store the return value on the C stack
|
M: %unbox generate-node ( vop -- )
|
||||||
! 0 input 2 input store-insn ;
|
drop
|
||||||
!
|
! Call the unboxer
|
||||||
! M: %parameter generate-node ( vop -- )
|
1 input f compile-c-call
|
||||||
! ! Move a value from the C stack into the fastcall register
|
! Store the return value on the C stack
|
||||||
! drop 0 input 1 input 2 input load-insn ;
|
0 input 2 input store-insn ;
|
||||||
!
|
|
||||||
! M: %box generate-node ( vop -- )
|
M: %parameter generate-node ( vop -- )
|
||||||
! drop
|
! Move a value from the C stack into the fastcall register
|
||||||
! ! Move return value of C function into input register
|
drop 0 input 1 input 2 input load-insn ;
|
||||||
! param-regs first RAX MOV
|
|
||||||
! 0 input f compile-c-call ;
|
M: %box generate-node ( vop -- )
|
||||||
!
|
drop
|
||||||
! M: %cleanup generate-node ( vop -- ) drop ;
|
! Move return value of C function into input register
|
||||||
|
param-regs first RAX MOV
|
||||||
|
0 input f compile-c-call ;
|
||||||
|
|
||||||
|
M: %cleanup generate-node ( vop -- ) drop ;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
! Copyright (C) 2005, 2006 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: compiler-backend
|
IN: compiler-backend
|
||||||
USING: alien arrays assembler compiler compiler-backend kernel
|
USING: alien arrays assembler compiler compiler-backend kernel
|
||||||
kernel-internals math sequences ;
|
kernel-internals math sequences ;
|
||||||
|
@ -44,10 +46,6 @@ M: float-regs fastcall-regs drop 0 ;
|
||||||
|
|
||||||
: prepare-division CQO ; inline
|
: prepare-division CQO ; inline
|
||||||
|
|
||||||
: compile-prologue RSP 8 SUB ; inline
|
|
||||||
|
|
||||||
: compile-epilogue RSP 8 ADD ; inline
|
|
||||||
|
|
||||||
: load-indirect ( dest literal -- )
|
: load-indirect ( dest literal -- )
|
||||||
#! We use RIP-relative addressing. The '3' is a hardcoded
|
#! We use RIP-relative addressing. The '3' is a hardcoded
|
||||||
#! instruction length.
|
#! instruction length.
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
! Copyright (C) 2006 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
IN: compiler-backend
|
||||||
|
USING: assembler kernel math namespaces ;
|
||||||
|
|
||||||
|
: stack-increment \ stack-reserve get 16 align 8 + ;
|
||||||
|
|
||||||
|
M: %prologue generate-node ( vop -- )
|
||||||
|
drop RSP stack-increment SUB ;
|
||||||
|
|
||||||
|
: compile-epilogue ( -- )
|
||||||
|
RSP stack-increment ADD ; inline
|
|
@ -5,8 +5,7 @@ USING: alien arrays assembler compiler inference kernel
|
||||||
kernel-internals lists math memory namespaces sequences words ;
|
kernel-internals lists math memory namespaces sequences words ;
|
||||||
|
|
||||||
! Not used on x86
|
! Not used on x86
|
||||||
M: %prologue generate-node ( vop -- )
|
M: %prologue generate-node ( vop -- ) drop ;
|
||||||
drop compile-prologue ;
|
|
||||||
|
|
||||||
: (%call)
|
: (%call)
|
||||||
label dup postpone-word
|
label dup postpone-word
|
||||||
|
|
|
@ -6,3 +6,9 @@ FUNCTION: void ffi_test_0 ; compiled
|
||||||
FUNCTION: int ffi_test_1 ; compiled
|
FUNCTION: int ffi_test_1 ; compiled
|
||||||
[ 3 ] [ ffi_test_1 ] unit-test
|
[ 3 ] [ ffi_test_1 ] unit-test
|
||||||
|
|
||||||
|
FUNCTION: int ffi_test_2 int x int y ; compiled
|
||||||
|
[ 5 ] [ 2 3 ffi_test_2 ] unit-test
|
||||||
|
|
||||||
|
FUNCTION: int ffi_test_3 int x int y int z int t ; compiled
|
||||||
|
[ 25 ] [ 2 3 4 5 ffi_test_3 ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -17,3 +17,9 @@ int ffi_test_2(int x, int y)
|
||||||
printf("ffi_test_2(%d,%d)\n",x,y);
|
printf("ffi_test_2(%d,%d)\n",x,y);
|
||||||
return x + y;
|
return x + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ffi_test_3(int x, int y, int z, int t)
|
||||||
|
{
|
||||||
|
printf("ffi_test_3(%d,%d,%d,%d)\n",x,y,z,t);
|
||||||
|
return x + y + z * t;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue