1 ! Copyright (C) 2009 Matthew Willis.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types alien.syntax assocs destructors
4 kernel llvm.core llvm.engine llvm.wrappers namespaces ;
12 : empty-engine ( -- engine )
13 "initial-module" <module> <provider> <engine> ;
16 jit new empty-engine >>ee H{ } clone >>mps ;
18 : (remove-functions) ( function -- )
19 thejit get ee>> value>> over LLVMFreeMachineCodeForFunction
20 LLVMGetNextFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
22 : remove-functions ( module -- )
23 ! free machine code for each function in module
24 LLVMGetFirstFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
26 : remove-provider ( provider -- )
27 thejit get ee>> value>> swap value>> f <void*> f <void*>
28 [ LLVMRemoveModuleProvider drop ] 2keep *void* [ llvm-throw ] when*
29 *void* module new swap >>value
30 [ value>> remove-functions ] with-disposal ;
32 : remove-module ( name -- )
33 dup thejit get mps>> at [
35 thejit get mps>> delete-at
38 : add-module ( module name -- )
39 [ <provider> ] dip [ remove-module ] keep
40 thejit get ee>> value>> pick
41 [ [ value>> LLVMAddModuleProvider ] [ t >>disposed drop ] bi ] with-disposal
42 thejit get mps>> set-at ;
44 : function-pointer ( name -- alien )
45 thejit get ee>> value>> dup
46 rot f <void*> [ LLVMFindFunction drop ] keep
47 *void* LLVMGetPointerToGlobal ;
49 thejit [ <jit> ] initialize