]> gitweb.factorcode.org Git - factor.git/blob - extra/llvm/jit/jit.factor
Remove usages of <void*> and *void*
[factor.git] / extra / llvm / jit / jit.factor
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 ;
5
6 IN: llvm.jit
7
8 TUPLE: jit ee mps ;
9
10 : empty-engine ( -- engine )
11     "initial-module" <module> <provider> <engine> ;
12
13 : <jit> ( -- jit )
14     jit new empty-engine >>ee H{ } clone >>mps ;
15
16 : current-jit ( -- jit )
17     \ current-jit global [ drop <jit> ] cache ;
18
19 : (remove-functions) ( function -- )
20     current-jit ee>> value>> over LLVMFreeMachineCodeForFunction
21     LLVMGetNextFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
22
23 : remove-functions ( module -- )
24     ! free machine code for each function in module
25     LLVMGetFirstFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
26
27 : remove-provider ( provider -- )
28     current-jit ee>> value>> swap value>> f void* <ref> f void* <ref>
29     [ LLVMRemoveModuleProvider drop ] 2keep void* deref [ llvm-throw ] when*
30     void* deref module new swap >>value
31     [ value>> remove-functions ] with-disposal ;
32
33 : remove-module ( name -- )
34     dup current-jit mps>> at [
35         remove-provider
36         current-jit mps>> delete-at
37     ] [ drop ] if* ;
38
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 ;
44
45 : function-pointer ( name -- alien )
46     current-jit ee>> value>> dup
47     rot f void* <ref> [ LLVMFindFunction drop ] keep
48     void* deref LLVMGetPointerToGlobal ;