2015-10-28 10:40:04 +08:00
|
|
|
/*===----------- llvm-c/OrcBindings.h - Orc Lib C Iface ---------*- C++ -*-===*\
|
|
|
|
|* *|
|
2019-01-19 16:50:56 +08:00
|
|
|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
|
|
|
|* Exceptions. *|
|
|
|
|
|* See https://llvm.org/LICENSE.txt for license information. *|
|
|
|
|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
2015-10-28 10:40:04 +08:00
|
|
|
|* *|
|
|
|
|
|*===----------------------------------------------------------------------===*|
|
|
|
|
|* *|
|
|
|
|
|* This header declares the C interface to libLLVMOrcJIT.a, which implements *|
|
|
|
|
|* JIT compilation of LLVM IR. *|
|
|
|
|
|* *|
|
|
|
|
|* Many exotic languages can interoperate with C code but have a harder time *|
|
|
|
|
|* with C++ due to name mangling. So in addition to C, this interface enables *|
|
|
|
|
|* tools written in such languages. *|
|
|
|
|
|* *|
|
|
|
|
|* Note: This interface is experimental. It is *NOT* stable, and may be *|
|
|
|
|
|* changed without warning. *|
|
|
|
|
|* *|
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
|
|
|
#ifndef LLVM_C_ORCBINDINGS_H
|
|
|
|
#define LLVM_C_ORCBINDINGS_H
|
|
|
|
|
2018-09-23 10:09:18 +08:00
|
|
|
#include "llvm-c/Error.h"
|
2015-10-28 10:40:04 +08:00
|
|
|
#include "llvm-c/Object.h"
|
|
|
|
#include "llvm-c/TargetMachine.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
|
2018-02-09 10:30:40 +08:00
|
|
|
typedef uint64_t LLVMOrcModuleHandle;
|
2015-10-28 10:40:04 +08:00
|
|
|
typedef uint64_t LLVMOrcTargetAddress;
|
2016-04-26 05:21:20 +08:00
|
|
|
typedef uint64_t (*LLVMOrcSymbolResolverFn)(const char *Name, void *LookupCtx);
|
2015-10-30 11:20:21 +08:00
|
|
|
typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
|
|
|
|
void *CallbackCtx);
|
2015-10-28 10:40:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an ORC JIT stack.
|
|
|
|
*
|
|
|
|
* The client owns the resulting stack, and must call OrcDisposeInstance(...)
|
|
|
|
* to destroy it and free its memory. The JIT stack will take ownership of the
|
|
|
|
* TargetMachine, which will be destroyed when the stack is destroyed. The
|
|
|
|
* client should not attempt to dispose of the Target Machine, or it will result
|
|
|
|
* in a double-free.
|
|
|
|
*/
|
2015-11-04 00:40:37 +08:00
|
|
|
LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM);
|
2015-10-28 10:40:04 +08:00
|
|
|
|
2016-04-26 03:56:45 +08:00
|
|
|
/**
|
|
|
|
* Get the error message for the most recent error (if any).
|
|
|
|
*
|
|
|
|
* This message is owned by the ORC JIT Stack and will be freed when the stack
|
|
|
|
* is disposed of by LLVMOrcDisposeInstance.
|
|
|
|
*/
|
|
|
|
const char *LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack);
|
|
|
|
|
2015-10-28 10:40:04 +08:00
|
|
|
/**
|
|
|
|
* Mangle the given symbol.
|
|
|
|
* Memory will be allocated for MangledSymbol to hold the result. The client
|
|
|
|
*/
|
|
|
|
void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledSymbol,
|
|
|
|
const char *Symbol);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispose of a mangled symbol.
|
|
|
|
*/
|
|
|
|
void LLVMOrcDisposeMangledSymbol(char *MangledSymbol);
|
|
|
|
|
2015-10-30 11:20:21 +08:00
|
|
|
/**
|
|
|
|
* Create a lazy compile callback.
|
|
|
|
*/
|
2018-09-23 10:09:18 +08:00
|
|
|
LLVMErrorRef LLVMOrcCreateLazyCompileCallback(
|
|
|
|
LLVMOrcJITStackRef JITStack, LLVMOrcTargetAddress *RetAddr,
|
|
|
|
LLVMOrcLazyCompileCallbackFn Callback, void *CallbackCtx);
|
2015-10-30 11:20:21 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a named indirect call stub.
|
|
|
|
*/
|
2018-09-23 10:09:18 +08:00
|
|
|
LLVMErrorRef LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
|
|
|
|
const char *StubName,
|
|
|
|
LLVMOrcTargetAddress InitAddr);
|
2015-10-30 11:20:21 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the pointer for the given indirect stub.
|
|
|
|
*/
|
2018-09-23 10:09:18 +08:00
|
|
|
LLVMErrorRef LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
|
|
|
|
const char *StubName,
|
|
|
|
LLVMOrcTargetAddress NewAddr);
|
2015-10-30 11:20:21 +08:00
|
|
|
|
2015-10-28 10:40:04 +08:00
|
|
|
/**
|
|
|
|
* Add module to be eagerly compiled.
|
|
|
|
*/
|
2018-09-23 10:09:18 +08:00
|
|
|
LLVMErrorRef LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
|
|
|
|
LLVMOrcModuleHandle *RetHandle,
|
|
|
|
LLVMModuleRef Mod,
|
|
|
|
LLVMOrcSymbolResolverFn SymbolResolver,
|
|
|
|
void *SymbolResolverCtx);
|
2015-10-28 10:40:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add module to be lazily compiled one function at a time.
|
|
|
|
*/
|
2018-09-23 10:09:18 +08:00
|
|
|
LLVMErrorRef LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
|
|
|
|
LLVMOrcModuleHandle *RetHandle,
|
|
|
|
LLVMModuleRef Mod,
|
|
|
|
LLVMOrcSymbolResolverFn SymbolResolver,
|
|
|
|
void *SymbolResolverCtx);
|
2015-10-28 10:40:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an object file.
|
2017-09-17 11:25:03 +08:00
|
|
|
*
|
|
|
|
* This method takes ownership of the given memory buffer and attempts to add
|
|
|
|
* it to the JIT as an object file.
|
|
|
|
* Clients should *not* dispose of the 'Obj' argument: the JIT will manage it
|
|
|
|
* from this call onwards.
|
2015-10-28 10:40:04 +08:00
|
|
|
*/
|
2018-09-23 10:09:18 +08:00
|
|
|
LLVMErrorRef LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
|
|
|
|
LLVMOrcModuleHandle *RetHandle,
|
|
|
|
LLVMMemoryBufferRef Obj,
|
|
|
|
LLVMOrcSymbolResolverFn SymbolResolver,
|
|
|
|
void *SymbolResolverCtx);
|
2015-10-28 10:40:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a module set from the JIT.
|
|
|
|
*
|
|
|
|
* This works for all modules that can be added via OrcAdd*, including object
|
|
|
|
* files.
|
|
|
|
*/
|
2018-09-23 10:09:18 +08:00
|
|
|
LLVMErrorRef LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack,
|
|
|
|
LLVMOrcModuleHandle H);
|
2015-10-28 10:40:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get symbol address from JIT instance.
|
|
|
|
*/
|
2018-09-23 10:09:18 +08:00
|
|
|
LLVMErrorRef LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
|
|
|
|
LLVMOrcTargetAddress *RetAddr,
|
|
|
|
const char *SymbolName);
|
2015-10-28 10:40:04 +08:00
|
|
|
|
2018-05-25 02:44:34 +08:00
|
|
|
/**
|
|
|
|
* Get symbol address from JIT instance, searching only the specified
|
|
|
|
* handle.
|
|
|
|
*/
|
2018-09-23 10:09:18 +08:00
|
|
|
LLVMErrorRef LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
|
|
|
|
LLVMOrcTargetAddress *RetAddr,
|
|
|
|
LLVMOrcModuleHandle H,
|
|
|
|
const char *SymbolName);
|
2018-05-25 02:44:34 +08:00
|
|
|
|
2015-10-28 10:40:04 +08:00
|
|
|
/**
|
|
|
|
* Dispose of an ORC JIT stack.
|
|
|
|
*/
|
2018-09-23 10:09:18 +08:00
|
|
|
LLVMErrorRef LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
|
2015-10-28 10:40:04 +08:00
|
|
|
|
2018-05-25 05:32:52 +08:00
|
|
|
/**
|
|
|
|
* Register a JIT Event Listener.
|
|
|
|
*
|
|
|
|
* A NULL listener is ignored.
|
|
|
|
*/
|
|
|
|
void LLVMOrcRegisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventListenerRef L);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unegister a JIT Event Listener.
|
|
|
|
*
|
|
|
|
* A NULL listener is ignored.
|
|
|
|
*/
|
|
|
|
void LLVMOrcUnregisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventListenerRef L);
|
|
|
|
|
2015-10-28 10:40:04 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* extern "C" */
|
|
|
|
|
|
|
|
#endif /* LLVM_C_ORCBINDINGS_H */
|