Skip to content

Commit 5ab4b69

Browse files
Qi Zhouaykevl
authored andcommitted
add ExecutionEngine.NewJITCompiler()
add ExecutionEngine.GetFunctionAddress()
1 parent 12a422f commit 5ab4b69

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

executionengine.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ package llvm
1818
#include <stdlib.h>
1919
*/
2020
import "C"
21-
import "unsafe"
22-
import "errors"
21+
import (
22+
"errors"
23+
"unsafe"
24+
)
2325

2426
func LinkInMCJIT() { C.LLVMLinkInMCJIT() }
2527
func LinkInInterpreter() { C.LLVMLinkInInterpreter() }
@@ -110,6 +112,17 @@ func NewInterpreter(m Module) (ee ExecutionEngine, err error) {
110112
return
111113
}
112114

115+
func NewJITCompiler(m Module, optLevel int) (ee ExecutionEngine, err error) {
116+
var cmsg *C.char
117+
fail := C.LLVMCreateJITCompilerForModule(&ee.C, m.C, C.uint(optLevel), &cmsg)
118+
if fail != 0 {
119+
ee.C = nil
120+
err = errors.New(C.GoString(cmsg))
121+
C.LLVMDisposeMessage(cmsg)
122+
}
123+
return
124+
}
125+
113126
func NewMCJITCompilerOptions() MCJITCompilerOptions {
114127
var options C.struct_LLVMMCJITCompilerOptions
115128
C.LLVMInitializeMCJITCompilerOptions(&options, C.size_t(unsafe.Sizeof(C.struct_LLVMMCJITCompilerOptions{})))
@@ -159,6 +172,12 @@ func (ee ExecutionEngine) FindFunction(name string) (f Value) {
159172
return
160173
}
161174

175+
func (ee ExecutionEngine) GetFunctionAddress(name string) uint64 {
176+
cname := C.CString(name)
177+
defer C.free(unsafe.Pointer(cname))
178+
return uint64(C.LLVMGetFunctionAddress(ee.C, cname))
179+
}
180+
162181
func (ee ExecutionEngine) RecompileAndRelinkFunction(f Value) unsafe.Pointer {
163182
return C.LLVMRecompileAndRelinkFunction(ee.C, f.C)
164183
}

0 commit comments

Comments
 (0)