/// <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); }
private static void AddAndExecuteTestModule(LLVMOrcJITStackRef orcJit, LLVMContextRef context, LLVMTargetMachineRef machine, int expectedResult) { LLVMModuleRef module = CreateModule(context, machine, expectedResult); LLVMErrorRef err = LLVMOrcAddEagerlyCompiledIR(orcJit, out ulong jitHandle, module, SymbolResolver, IntPtr.Zero); Assert.IsTrue(err.IsInvalid); // ORC now owns the module, so it must never be released module.SetHandleAsInvalid(); LLVMOrcGetMangledSymbol(orcJit, out string mangledName, "main"); err = LibLLVMOrcGetSymbolAddress(orcJit, out ulong funcAddress, mangledName, false); Assert.IsTrue(err.IsInvalid); Assert.AreNotEqual(0ul, funcAddress); var callableMain = Marshal.GetDelegateForFunctionPointer <TestMain>(( IntPtr )funcAddress); Assert.AreEqual(expectedResult, callableMain( )); LLVMOrcRemoveModule(orcJit, jitHandle); }
/// <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); }