JIT
public final class JIT
A JIT is a Just-In-Time compiler that will compile and execute LLVM IR
that has been generated in a Module. It can execute arbitrary functions
and return the value the function generated, allowing you to write
interactive programs that will run as soon as they are compiled.
-
Creates a Just In Time compiler that will compile the code in the provided
Moduleto the architecture of the providedTargetMachine, and execute it.Throws
JITErrorDeclaration
Swift
public init(module: Module, machine: TargetMachine) throwsParameters
moduleThe module containing code you wish to execute
machineThe target machine which you’re compiling for
-
Runs the specified function with the provided arguments by compiling it to machine code for the target architecture used to initialize this JIT.
Parameters
functionThe function you wish to execute
argsThe arguments you wish to pass to the function
Return Value
The LLVM value that the function returned
-
Retrieves a pointer to the function compiled by this JIT. - parameter name: The name of the function you wish to look up. - returns: A pointer to the result of compiling the specified function. - note: You will have to
unsafeBitCastthis pointer to the appropriate@convention(c)function type to be able to run it from Swift.typealias FnPtr = @convention(c) () -> Double let fnAddr = jit.addressOfFunction(name: "test") let fn = unsafeBitCast(fnAddr, to: FnPtr.self)Declaration
Swift
public func addressOfFunction(name: String) -> OpaquePointer?Parameters
nameThe name of the function you wish to look up.
Return Value
A pointer to the result of compiling the specified function.
-
Adds the provided module, and all top-level declarations into this JIT. - parameter module: The module you wish to add.
Declaration
Swift
public func addModule(_ module: Module)Parameters
moduleThe module you wish to add.
-
Removes the provided module, and all top-level declarations, from this JIT.
Declaration
Swift
public func removeModule(_ module: Module) throws -
Runs the specified function as if it were the
mainfunction in an executable. It takes an array of argument strings and passes them into the function asargcandargv.Declaration
Swift
public func runFunctionAsMain(_ function: Function, args: [String]) -> IntParameters
functionThe
mainfunction you wish to executeargsThe string arguments you wish to pass to the function
Return Value
The numerical exit code returned by the function
JIT Class Reference