-
Notifications
You must be signed in to change notification settings - Fork 57
Initial ORCJIT Bindings #102
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
Conversation
/// - ctx: A void pointer pointing to a retained ORCJIT instance. | ||
/// - Returns: A callable address of a compiled function, or 0 if no such | ||
/// function was found. | ||
func orcjitSymbolResolver(symbol: UnsafePointer<Int8>?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this meant to be public
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it’s only used as a shim passed into the Orc bindings. It calls into the public symbol resolvers.
From a cursory glance, this is missing
|
return jit.resolver.address(of: String(cString: cString), in: jit) ?? 0 | ||
} | ||
|
||
public class ORCJIT { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be documented like mad (and at the top of this file).
|
||
private var sharedObjectBuffers = [LLVMSharedObjectBufferRef]() | ||
|
||
public enum Error: Swift.Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation here too.
/// The strategy that ORCJIT should use to compile a specific module. | ||
public enum CompilationStrategy { | ||
/// The IR will be compiled lazily, one function at a time. | ||
case lazy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JIT provides LLVMOrcCreateLazyCompileCallback
to be fired when it resolves symbols. We could wrap this and let the user pass us a block.
/// - Returns: `nil` if the symbol could not be found, otherwise the opaque | ||
/// address of a C function pointer that can be called to execute | ||
/// the compiled code. | ||
func address(of symbol: String, in jit: ORCJIT) -> UInt64? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we provide a public typealias for LLVMOrcTargetAddress
instead of using UInt64?
|
||
/// Runs a series of symbol resolvers in order, stopping when the first resolver | ||
/// finds a valid symbol. | ||
public struct CompoundSymbolResolver: SymbolResolver { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CodaFi should compound resolvers just...be the default? i.e. should ORCJIT always keep a chain of resolvers and run them, defaulting to the simple resolver?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, neat. Sure, sounds good. Then symbol resolution is a fold with ??.
Subsumed by #158 |
This patch provides an initial set of ORCJIT bindings. They're incomplete, and the ORC API will evolve past this in the near future.