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 ;
10 : empty-engine ( -- engine )
11 "initial-module" <module> <provider> <engine> ;
14 jit new empty-engine >>ee H{ } clone >>mps ;
16 : current-jit ( -- jit )
17 \ current-jit global [ drop <jit> ] cache ;
19 : (remove-functions) ( function -- )
20 current-jit ee>> value>> over LLVMFreeMachineCodeForFunction
21 LLVMGetNextFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
23 : remove-functions ( module -- )
24 ! free machine code for each function in module
25 LLVMGetFirstFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
27 : remove-provider ( provider -- )
28 current-jit ee>> value>> swap value>> f <void*> f <void*>
29 [ LLVMRemoveModuleProvider drop ] 2keep *void* [ llvm-throw ] when*
30 *void* module new swap >>value
31 [ value>> remove-functions ] with-disposal ;
33 : remove-module ( name -- )
34 dup current-jit mps>> at [
36 current-jit mps>> delete-at
39 : add-module ( module name -- )
40 [ <provider> ] dip [ remove-module ] keep
41 current-jit ee>> value>> pick
42 [ [ value>> LLVMAddModuleProvider ] [ t >>disposed drop ] bi ] with-disposal
43 current-jit mps>> set-at ;
45 : function-pointer ( name -- alien )
46 current-jit ee>> value>> dup
47 rot f <void*> [ LLVMFindFunction drop ] keep
48 *void* LLVMGetPointerToGlobal ;