You've already forked linux-packaging-mono
Imported Upstream version 5.18.0.167
Former-commit-id: 289509151e0fee68a1b591a20c9f109c3c789d3a
This commit is contained in:
parent
e19d552987
commit
b084638f15
@ -1,6 +0,0 @@
|
||||
add_ocaml_library(llvm_executionengine
|
||||
OCAML llvm_executionengine
|
||||
OCAMLDEP llvm llvm_target
|
||||
C executionengine_ocaml
|
||||
LLVM executionengine mcjit native
|
||||
PKG ctypes)
|
@ -1,127 +0,0 @@
|
||||
/*===-- executionengine_ocaml.c - LLVM OCaml Glue ---------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|
||||
|* macros, since most of the parameters are not GC heap objects. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/ExecutionEngine.h"
|
||||
#include "llvm-c/Target.h"
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/custom.h"
|
||||
#include "caml/fail.h"
|
||||
#include "caml/memory.h"
|
||||
#include "caml/callback.h"
|
||||
|
||||
void llvm_raise(value Prototype, char *Message);
|
||||
|
||||
/* unit -> bool */
|
||||
CAMLprim value llvm_ee_initialize(value Unit) {
|
||||
LLVMLinkInMCJIT();
|
||||
|
||||
return Val_bool(!LLVMInitializeNativeTarget() &&
|
||||
!LLVMInitializeNativeAsmParser() &&
|
||||
!LLVMInitializeNativeAsmPrinter());
|
||||
}
|
||||
|
||||
/* llmodule -> llcompileroption -> ExecutionEngine.t */
|
||||
CAMLprim LLVMExecutionEngineRef llvm_ee_create(value OptRecordOpt, LLVMModuleRef M) {
|
||||
value OptRecord;
|
||||
LLVMExecutionEngineRef MCJIT;
|
||||
char *Error;
|
||||
struct LLVMMCJITCompilerOptions Options;
|
||||
|
||||
LLVMInitializeMCJITCompilerOptions(&Options, sizeof(Options));
|
||||
if (OptRecordOpt != Val_int(0)) {
|
||||
OptRecord = Field(OptRecordOpt, 0);
|
||||
Options.OptLevel = Int_val(Field(OptRecord, 0));
|
||||
Options.CodeModel = Int_val(Field(OptRecord, 1));
|
||||
Options.NoFramePointerElim = Int_val(Field(OptRecord, 2));
|
||||
Options.EnableFastISel = Int_val(Field(OptRecord, 3));
|
||||
Options.MCJMM = NULL;
|
||||
}
|
||||
|
||||
if (LLVMCreateMCJITCompilerForModule(&MCJIT, M, &Options,
|
||||
sizeof(Options), &Error))
|
||||
llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error);
|
||||
return MCJIT;
|
||||
}
|
||||
|
||||
/* ExecutionEngine.t -> unit */
|
||||
CAMLprim value llvm_ee_dispose(LLVMExecutionEngineRef EE) {
|
||||
LLVMDisposeExecutionEngine(EE);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* llmodule -> ExecutionEngine.t -> unit */
|
||||
CAMLprim value llvm_ee_add_module(LLVMModuleRef M, LLVMExecutionEngineRef EE) {
|
||||
LLVMAddModule(EE, M);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* llmodule -> ExecutionEngine.t -> llmodule */
|
||||
CAMLprim value llvm_ee_remove_module(LLVMModuleRef M, LLVMExecutionEngineRef EE) {
|
||||
LLVMModuleRef RemovedModule;
|
||||
char *Error;
|
||||
if (LLVMRemoveModule(EE, M, &RemovedModule, &Error))
|
||||
llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* ExecutionEngine.t -> unit */
|
||||
CAMLprim value llvm_ee_run_static_ctors(LLVMExecutionEngineRef EE) {
|
||||
LLVMRunStaticConstructors(EE);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* ExecutionEngine.t -> unit */
|
||||
CAMLprim value llvm_ee_run_static_dtors(LLVMExecutionEngineRef EE) {
|
||||
LLVMRunStaticDestructors(EE);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
extern value llvm_alloc_data_layout(LLVMTargetDataRef TargetData);
|
||||
|
||||
/* ExecutionEngine.t -> Llvm_target.DataLayout.t */
|
||||
CAMLprim value llvm_ee_get_data_layout(LLVMExecutionEngineRef EE) {
|
||||
value DataLayout;
|
||||
LLVMTargetDataRef OrigDataLayout;
|
||||
char* TargetDataCStr;
|
||||
|
||||
OrigDataLayout = LLVMGetExecutionEngineTargetData(EE);
|
||||
TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout);
|
||||
DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr));
|
||||
LLVMDisposeMessage(TargetDataCStr);
|
||||
|
||||
return DataLayout;
|
||||
}
|
||||
|
||||
/* Llvm.llvalue -> int64 -> llexecutionengine -> unit */
|
||||
CAMLprim value llvm_ee_add_global_mapping(LLVMValueRef Global, value Ptr,
|
||||
LLVMExecutionEngineRef EE) {
|
||||
LLVMAddGlobalMapping(EE, Global, (void*) (Int64_val(Ptr)));
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
CAMLprim value llvm_ee_get_global_value_address(value Name,
|
||||
LLVMExecutionEngineRef EE) {
|
||||
return caml_copy_int64((int64_t) LLVMGetGlobalValueAddress(EE, String_val(Name)));
|
||||
}
|
||||
|
||||
CAMLprim value llvm_ee_get_function_address(value Name,
|
||||
LLVMExecutionEngineRef EE) {
|
||||
return caml_copy_int64((int64_t) LLVMGetFunctionAddress(EE, String_val(Name)));
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
(*===-- llvm_executionengine.ml - LLVM OCaml Interface --------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
exception Error of string
|
||||
|
||||
let () = Callback.register_exception "Llvm_executionengine.Error" (Error "")
|
||||
|
||||
external initialize : unit -> bool
|
||||
= "llvm_ee_initialize"
|
||||
|
||||
type llexecutionengine
|
||||
|
||||
type llcompileroptions = {
|
||||
opt_level: int;
|
||||
code_model: Llvm_target.CodeModel.t;
|
||||
no_framepointer_elim: bool;
|
||||
enable_fast_isel: bool;
|
||||
}
|
||||
|
||||
let default_compiler_options = {
|
||||
opt_level = 0;
|
||||
code_model = Llvm_target.CodeModel.JITDefault;
|
||||
no_framepointer_elim = false;
|
||||
enable_fast_isel = false }
|
||||
|
||||
external create : ?options:llcompileroptions -> Llvm.llmodule -> llexecutionengine
|
||||
= "llvm_ee_create"
|
||||
external dispose : llexecutionengine -> unit
|
||||
= "llvm_ee_dispose"
|
||||
external add_module : Llvm.llmodule -> llexecutionengine -> unit
|
||||
= "llvm_ee_add_module"
|
||||
external remove_module : Llvm.llmodule -> llexecutionengine -> unit
|
||||
= "llvm_ee_remove_module"
|
||||
external run_static_ctors : llexecutionengine -> unit
|
||||
= "llvm_ee_run_static_ctors"
|
||||
external run_static_dtors : llexecutionengine -> unit
|
||||
= "llvm_ee_run_static_dtors"
|
||||
external data_layout : llexecutionengine -> Llvm_target.DataLayout.t
|
||||
= "llvm_ee_get_data_layout"
|
||||
external add_global_mapping_ : Llvm.llvalue -> nativeint -> llexecutionengine -> unit
|
||||
= "llvm_ee_add_global_mapping"
|
||||
external get_global_value_address_ : string -> llexecutionengine -> nativeint
|
||||
= "llvm_ee_get_global_value_address"
|
||||
external get_function_address_ : string -> llexecutionengine -> nativeint
|
||||
= "llvm_ee_get_function_address"
|
||||
|
||||
let add_global_mapping llval ptr ee =
|
||||
add_global_mapping_ llval (Ctypes.raw_address_of_ptr (Ctypes.to_voidp ptr)) ee
|
||||
|
||||
let get_global_value_address name typ ee =
|
||||
let vptr = get_global_value_address_ name ee in
|
||||
if Nativeint.to_int vptr <> 0 then
|
||||
let open Ctypes in !@ (coerce (ptr void) (ptr typ) (ptr_of_raw_address vptr))
|
||||
else
|
||||
raise (Error ("Value " ^ name ^ " not found"))
|
||||
|
||||
let get_function_address name typ ee =
|
||||
let fptr = get_function_address_ name ee in
|
||||
if Nativeint.to_int fptr <> 0 then
|
||||
let open Ctypes in coerce (ptr void) typ (ptr_of_raw_address fptr)
|
||||
else
|
||||
raise (Error ("Function " ^ name ^ " not found"))
|
||||
|
||||
(* The following are not bound. Patches are welcome.
|
||||
target_machine : llexecutionengine -> Llvm_target.TargetMachine.t
|
||||
*)
|
@ -1,93 +0,0 @@
|
||||
(*===-- llvm_executionengine.mli - LLVM OCaml Interface -------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** JIT Interpreter.
|
||||
|
||||
This interface provides an OCaml API for LLVM execution engine (JIT/
|
||||
interpreter), the classes in the [ExecutionEngine] library. *)
|
||||
|
||||
exception Error of string
|
||||
|
||||
(** [initialize ()] initializes the backend corresponding to the host.
|
||||
Returns [true] if initialization is successful; [false] indicates
|
||||
that there is no such backend or it is unable to emit object code
|
||||
via MCJIT. *)
|
||||
val initialize : unit -> bool
|
||||
|
||||
(** An execution engine is either a JIT compiler or an interpreter, capable of
|
||||
directly loading an LLVM module and executing its functions without first
|
||||
invoking a static compiler and generating a native executable. *)
|
||||
type llexecutionengine
|
||||
|
||||
(** MCJIT compiler options. See [llvm::TargetOptions]. *)
|
||||
type llcompileroptions = {
|
||||
opt_level: int;
|
||||
code_model: Llvm_target.CodeModel.t;
|
||||
no_framepointer_elim: bool;
|
||||
enable_fast_isel: bool;
|
||||
}
|
||||
|
||||
(** Default MCJIT compiler options:
|
||||
[{ opt_level = 0; code_model = CodeModel.JIT_default;
|
||||
no_framepointer_elim = false; enable_fast_isel = false }] *)
|
||||
val default_compiler_options : llcompileroptions
|
||||
|
||||
(** [create m optlevel] creates a new MCJIT just-in-time compiler, taking
|
||||
ownership of the module [m] if successful with the desired optimization
|
||||
level [optlevel]. Raises [Error msg] if an error occurrs. The execution
|
||||
engine is not garbage collected and must be destroyed with [dispose ee].
|
||||
|
||||
Run {!initialize} before using this function.
|
||||
|
||||
See the function [llvm::EngineBuilder::create]. *)
|
||||
val create : ?options:llcompileroptions -> Llvm.llmodule -> llexecutionengine
|
||||
|
||||
(** [dispose ee] releases the memory used by the execution engine and must be
|
||||
invoked to avoid memory leaks. *)
|
||||
val dispose : llexecutionengine -> unit
|
||||
|
||||
(** [add_module m ee] adds the module [m] to the execution engine [ee]. *)
|
||||
val add_module : Llvm.llmodule -> llexecutionengine -> unit
|
||||
|
||||
(** [remove_module m ee] removes the module [m] from the execution engine
|
||||
[ee]. Raises [Error msg] if an error occurs. *)
|
||||
val remove_module : Llvm.llmodule -> llexecutionengine -> unit
|
||||
|
||||
(** [run_static_ctors ee] executes the static constructors of each module in
|
||||
the execution engine [ee]. *)
|
||||
val run_static_ctors : llexecutionengine -> unit
|
||||
|
||||
(** [run_static_dtors ee] executes the static destructors of each module in
|
||||
the execution engine [ee]. *)
|
||||
val run_static_dtors : llexecutionengine -> unit
|
||||
|
||||
(** [data_layout ee] is the data layout of the execution engine [ee]. *)
|
||||
val data_layout : llexecutionengine -> Llvm_target.DataLayout.t
|
||||
|
||||
(** [add_global_mapping gv ptr ee] tells the execution engine [ee] that
|
||||
the global [gv] is at the specified location [ptr], which must outlive
|
||||
[gv] and [ee].
|
||||
All uses of [gv] in the compiled code will refer to [ptr]. *)
|
||||
val add_global_mapping : Llvm.llvalue -> 'a Ctypes.ptr -> llexecutionengine -> unit
|
||||
|
||||
(** [get_global_value_address id typ ee] returns a pointer to the
|
||||
identifier [id] as type [typ], which will be a pointer type for a
|
||||
value, and which will be live as long as [id] and [ee]
|
||||
are. Caution: this function finalizes, i.e. forces code
|
||||
generation, all loaded modules. Further modifications to the
|
||||
modules will not have any effect. *)
|
||||
val get_global_value_address : string -> 'a Ctypes.typ -> llexecutionengine -> 'a
|
||||
|
||||
(** [get_function_address fn typ ee] returns a pointer to the function
|
||||
[fn] as type [typ], which will be a pointer type for a function
|
||||
(e.g. [(int -> int) typ]), and which will be live as long as [fn]
|
||||
and [ee] are. Caution: this function finalizes, i.e. forces code
|
||||
generation, all loaded modules. Further modifications to the
|
||||
modules will not have any effect. *)
|
||||
val get_function_address : string -> 'a Ctypes.typ -> llexecutionengine -> 'a
|
Reference in New Issue
Block a user