]> gitweb.factorcode.org Git - factor.git/blob - work/llvm/llvm-tests.factor
Initial work on llvm bindings, with test
[factor.git] / work / llvm / llvm-tests.factor
1 USING: accessors alien compiler.units kernel
2 llvm tools.test words llvm.core ;
3
4 IN: scratchpad
5
6 : add-abi ( x y -- x+y ) ! to be filled in by llvm
7     drop ;
8
9 : llvm-add ( x y -- x+y )
10     "test" <module> [
11         {
12             { [ 32 LLVMIntType ] "add" }
13             { [ 32 LLVMIntType ] "x" }
14             { [ 32 LLVMIntType ] "y" }
15         } <function> [
16             "entry" <builder> [
17                 builder value>> "x" get-param "y" get-param "sum" LLVMBuildAdd
18                 builder value>> swap LLVMBuildRet drop
19             ] with-builder
20         ] with-function
21         
22         <engine>
23     ] with-module
24     
25     [
26         "add" find-function global>pointer
27         [ "int" { "int" "int" } "cdecl" alien-indirect ] curry \ add-abi swap
28         (( x y -- x+y )) [ define-declared ] with-compilation-unit
29         add-abi ! call our new word
30     ] with-engine ; inline
31
32 [ 7 ] [ 3 4 llvm-add ] unit-test