brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · 3c5a1c0 Raw
93 lines · plain
1(*===-- llvm_executionengine.mli - LLVM OCaml Interface -------*- OCaml -*-===*2 *3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4 * See https://llvm.org/LICENSE.txt for license information.5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6 *7 *===----------------------------------------------------------------------===*)8 9(** JIT Interpreter.10 11    This interface provides an OCaml API for LLVM execution engine (JIT/12    interpreter), the classes in the [ExecutionEngine] library. *)13 14exception Error of string15 16(** [initialize ()] initializes the backend corresponding to the host.17    Returns [true] if initialization is successful; [false] indicates18    that there is no such backend or it is unable to emit object code19    via MCJIT. *)20val initialize : unit -> bool21 22(** An execution engine is either a JIT compiler or an interpreter, capable of23    directly loading an LLVM module and executing its functions without first24    invoking a static compiler and generating a native executable. *)25type llexecutionengine26 27(** MCJIT compiler options. See [llvm::TargetOptions]. *)28type llcompileroptions = {29  opt_level: int;30  code_model: Llvm_target.CodeModel.t;31  no_framepointer_elim: bool;32  enable_fast_isel: bool;33}34 35(** Default MCJIT compiler options:36    [{ opt_level = 0; code_model = CodeModel.JIT_default;37       no_framepointer_elim = false; enable_fast_isel = false }] *)38val default_compiler_options : llcompileroptions39 40(** [create m optlevel] creates a new MCJIT just-in-time compiler, taking41    ownership of the module [m] if successful with the desired optimization42    level [optlevel]. Raises [Error msg] if an error occurrs. The execution43    engine is not garbage collected and must be destroyed with [dispose ee].44 45    Run {!initialize} before using this function.46 47    See the function [llvm::EngineBuilder::create]. *)48val create : ?options:llcompileroptions -> Llvm.llmodule -> llexecutionengine49 50(** [dispose ee] releases the memory used by the execution engine and must be51    invoked to avoid memory leaks. *)52val dispose : llexecutionengine -> unit53 54(** [add_module m ee] adds the module [m] to the execution engine [ee]. *)55val add_module : Llvm.llmodule -> llexecutionengine -> unit56 57(** [remove_module m ee] removes the module [m] from the execution engine58    [ee]. Raises [Error msg] if an error occurs. *)59val remove_module : Llvm.llmodule -> llexecutionengine -> unit60 61(** [run_static_ctors ee] executes the static constructors of each module in62    the execution engine [ee]. *)63val run_static_ctors : llexecutionengine -> unit64 65(** [run_static_dtors ee] executes the static destructors of each module in66    the execution engine [ee]. *)67val run_static_dtors : llexecutionengine -> unit68 69(** [data_layout ee] is the data layout of the execution engine [ee]. *)70val data_layout : llexecutionengine -> Llvm_target.DataLayout.t71 72(** [add_global_mapping gv ptr ee] tells the execution engine [ee] that73    the global [gv] is at the specified location [ptr], which must outlive74    [gv] and [ee].75    All uses of [gv] in the compiled code will refer to [ptr]. *)76val add_global_mapping : Llvm.llvalue -> 'a Ctypes.ptr -> llexecutionengine -> unit77 78(** [get_global_value_address id typ ee] returns a pointer to the79    identifier [id] as type [typ], which will be a pointer type for a80    value, and which will be live as long as [id] and [ee]81    are. Caution: this function finalizes, i.e. forces code82    generation, all loaded modules.  Further modifications to the83    modules will not have any effect. *)84val get_global_value_address : string -> 'a Ctypes.typ -> llexecutionengine -> 'a85 86(** [get_function_address fn typ ee] returns a pointer to the function87    [fn] as type [typ], which will be a pointer type for a function88    (e.g. [(int -> int) typ]), and which will be live as long as [fn]89    and [ee] are. Caution: this function finalizes, i.e. forces code90    generation, all loaded modules.  Further modifications to the91    modules will not have any effect. *)92val get_function_address : string -> 'a Ctypes.typ -> llexecutionengine -> 'a93