1 USING: accessors alien.c-types alien.syntax assocs destructors
2 kernel llvm.core llvm.engine llvm.wrappers namespaces ;
10 : empty-engine ( -- engine )
11 "initial-module" <module> <provider> <engine> ;
14 jit new empty-engine >>ee H{ } clone >>mps ;
16 : (remove-functions) ( function -- )
17 thejit get ee>> value>> over LLVMFreeMachineCodeForFunction
18 LLVMGetNextFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
20 : remove-functions ( module -- )
21 ! free machine code for each function in module
22 LLVMGetFirstFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
24 : remove-provider ( provider -- )
25 thejit get ee>> value>> swap value>> f <void*> f <void*>
26 [ LLVMRemoveModuleProvider drop ] 2keep *void* [ llvm-throw ] when*
27 *void* module new swap >>value
28 [ value>> remove-functions ] with-disposal ;
30 : remove-module ( name -- )
31 dup thejit get mps>> at [
33 thejit get mps>> delete-at
36 : add-module ( module name -- )
37 [ <provider> ] dip [ remove-module ] keep
38 thejit get ee>> value>> pick
39 [ [ value>> LLVMAddModuleProvider ] [ t >>disposed drop ] bi ] with-disposal
40 thejit get mps>> set-at ;
42 : function-pointer ( name -- alien )
43 thejit get ee>> value>> dup
44 rot f <void*> [ LLVMFindFunction drop ] keep
45 *void* LLVMGetPointerToGlobal ;
47 thejit [ <jit> ] initialize