Skip to content

Commit 671a3ec

Browse files
committed
Started experimenting with ORC support
1 parent e7612b0 commit 671a3ec

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/execution_engine.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,47 @@ macro_rules! impl_unsafe_fn {
516516
}
517517

518518
impl_unsafe_fn!(A, B, C, D, E, F, G, H, I, J, K, L, M);
519+
520+
#[cfg(all(feature = "experimental", not(any(feature = "llvm3-6", feature = "llvm3-7"))))]
521+
pub mod experimental {
522+
#[llvm_versions(3.8..=latest)]
523+
use llvm_sys::orc::{LLVMOrcCreateInstance, LLVMOrcDisposeInstance, LLVMOrcJITStackRef, LLVMOrcAddEagerlyCompiledIR, LLVMOrcAddLazilyCompiledIR};
524+
use crate::module::Module;
525+
use crate::targets::TargetMachine;
526+
use std::mem::MaybeUninit;
527+
528+
// TODO
529+
#[derive(Debug)]
530+
pub struct Orc(LLVMOrcJITStackRef);
531+
532+
impl Orc {
533+
pub fn create(target_machine: TargetMachine) -> Self {
534+
let stack_ref = unsafe {
535+
LLVMOrcCreateInstance(target_machine.target_machine)
536+
};
537+
538+
Orc(stack_ref)
539+
}
540+
541+
pub fn add_compiled_ir<'ctx>(&self, module: &Module<'ctx>, lazily: bool) -> Result<(), ()> {
542+
// let handle = MaybeUninit::uninit();
543+
// let _err = if lazily {
544+
// unsafe { LLVMOrcAddLazilyCompiledIR(self.0, handle.as_mut_ptr(), module.module.get(), sym_resolve, sym_resolve_ctx) }
545+
// } else {
546+
// unsafe { LLVMOrcAddEagerlyCompiledIR(self.0, handle.as_mut_ptr(), module.module.get(), sym_resolve, sym_resolve_ctx) }
547+
// };
548+
549+
Ok(())
550+
}
551+
}
552+
553+
impl Drop for Orc {
554+
fn drop(&mut self) {
555+
// REVIEW: This returns an LLVMErrorRef, not sure what we can do with it...
556+
// print to stderr maybe?
557+
unsafe {
558+
LLVMOrcDisposeInstance(self.0);
559+
}
560+
}
561+
}
562+
}

src/targets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ impl Target {
990990

991991
#[derive(Debug)]
992992
pub struct TargetMachine {
993-
target_machine: LLVMTargetMachineRef,
993+
pub(crate) target_machine: LLVMTargetMachineRef,
994994
}
995995

996996
impl TargetMachine {

0 commit comments

Comments
 (0)