Skip to content

add new functions #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions executionengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package llvm
#include <stdlib.h>
*/
import "C"
import "unsafe"
import "errors"
import (
"errors"
"unsafe"
)

func LinkInMCJIT() { C.LLVMLinkInMCJIT() }
func LinkInInterpreter() { C.LLVMLinkInInterpreter() }
Expand Down Expand Up @@ -110,6 +112,17 @@ func NewInterpreter(m Module) (ee ExecutionEngine, err error) {
return
}

func NewJITCompiler(m Module, optLevel int) (ee ExecutionEngine, err error) {
var cmsg *C.char
fail := C.LLVMCreateJITCompilerForModule(&ee.C, m.C, C.uint(optLevel), &cmsg)
if fail != 0 {
ee.C = nil
err = errors.New(C.GoString(cmsg))
C.LLVMDisposeMessage(cmsg)
}
return
}

func NewMCJITCompilerOptions() MCJITCompilerOptions {
var options C.struct_LLVMMCJITCompilerOptions
C.LLVMInitializeMCJITCompilerOptions(&options, C.size_t(unsafe.Sizeof(C.struct_LLVMMCJITCompilerOptions{})))
Expand Down Expand Up @@ -159,6 +172,12 @@ func (ee ExecutionEngine) FindFunction(name string) (f Value) {
return
}

func (ee ExecutionEngine) GetFunctionAddress(name string) uint64 {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return uint64(C.LLVMGetFunctionAddress(ee.C, cname))
}

func (ee ExecutionEngine) RecompileAndRelinkFunction(f Value) unsafe.Pointer {
return C.LLVMRecompileAndRelinkFunction(ee.C, f.C)
}
Expand Down
Loading