File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,10 @@ package llvm
1818#include <stdlib.h>
1919*/
2020import "C"
21- import "unsafe"
22- import "errors"
21+ import (
22+ "errors"
23+ "unsafe"
24+ )
2325
2426func LinkInMCJIT () { C .LLVMLinkInMCJIT () }
2527func 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+
113126func 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+
162181func (ee ExecutionEngine ) RecompileAndRelinkFunction (f Value ) unsafe.Pointer {
163182 return C .LLVMRecompileAndRelinkFunction (ee .C , f .C )
164183}
You can’t perform that action at this time.
0 commit comments