/// <inheritdoc/> public ulong AddLazyCompiledModule(BitcodeModule bitcodeModule, LLVMOrcSymbolResolverFn resolver) { LLVMModuleRef moduleHandle = bitcodeModule.Detach( ); var wrappedResolver = new WrappedNativeCallback <LLVMOrcSymbolResolverFn>(resolver); var err = LLVMOrcAddLazilyCompiledIR(JitStackHandle, out ulong retHandle, moduleHandle, wrappedResolver, IntPtr.Zero); moduleHandle.SetHandleAsInvalid( ); if (!err.IsInvalid) { throw new LlvmException(err.ToString( )); } // keep resolver delegate alive as native code needs to call it after this function exits SymbolResolvers.Add(retHandle, wrappedResolver); return(retHandle); }
/// <summary>Add a module to the engine</summary> /// <param name="module">The module to add to the engine</param> /// <remarks> /// <note type="warning"> /// The input <paramref name="module"/> is disconnected from the underlying LLVM /// module as the module is considered fully owned by the engine. Thus, upon return /// the <see cref="BitcodeModule.IsDisposed"/> property is <see langword="true"/> /// </note> /// </remarks> /// <returns>Handle for the module in the engine</returns> public int AddModule(BitcodeModule module) { int handle = System.Threading.Interlocked.Increment(ref NextHandleValue) - 1; lock ( OwnedModules ) { OwnedModules.Add(handle, module.ModuleHandle); } if (handle == 0) { CreateEngine(module); } LLVMAddModule(EngineHandle, module.ModuleHandle); module.Detach( ); return(handle); }
/// <inheritdoc/> public ulong AddEagerlyCompiledModule(BitcodeModule bitcodeModule, LLVMOrcSymbolResolverFn resolver) { bitcodeModule.ValidateNotNull(nameof(bitcodeModule)); resolver.ValidateNotNull(nameof(resolver)); // detach the module before providing to JIT as JIT takes ownership LLVMModuleRef moduleHandle = bitcodeModule.Detach( ); var wrappedResolver = new WrappedNativeCallback <LLVMOrcSymbolResolverFn>(resolver); var err = LLVMOrcAddEagerlyCompiledIR(JitStackHandle, out ulong retHandle, moduleHandle, wrappedResolver, IntPtr.Zero); moduleHandle.SetHandleAsInvalid( ); if (!err.IsInvalid) { throw new LlvmException(err.ToString( )); } // keep resolver delegate alive as native code needs to call it after this function exits SymbolResolvers.Add(retHandle, wrappedResolver); return(retHandle); }