MonoEERef mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, FunctionEmittedCb *emitted_cb, ExceptionTableCb *exception_cb, DlSymCb *dlsym_cb, LLVMExecutionEngineRef *ee) { alloc_code_mem_cb = alloc_cb; InitializeNativeTarget (); InitializeNativeTargetAsmPrinter(); EnableMonoEH = true; MonoEHFrameSymbol = "mono_eh_frame"; EngineBuilder EB; #if defined(TARGET_AMD64) || defined(TARGET_X86) std::vector<std::string> attrs; // FIXME: Autodetect this attrs.push_back("sse3"); attrs.push_back("sse4.1"); EB.setMAttrs (attrs); #endif auto TM = EB.selectTarget (); assert (TM); jit = new MonoLLVMJIT (TM); return NULL; }
int llvm::runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms, const std::vector<std::string> &Args) { // Add the program's symbols into the JIT's search space. if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) { errs() << "Error loading program symbols.\n"; return 1; } // Grab a target machine and try to build a factory function for the // target-specific Orc callback manager. EngineBuilder EB; EB.setOptLevel(getOptLevel()); auto TM = std::unique_ptr<TargetMachine>(EB.selectTarget()); Triple T(TM->getTargetTriple()); auto CompileCallbackMgr = orc::createLocalCompileCallbackManager(T, 0); // If we couldn't build the factory function then there must not be a callback // manager for this target. Bail out. if (!CompileCallbackMgr) { errs() << "No callback manager available for target '" << TM->getTargetTriple().str() << "'.\n"; return 1; } auto IndirectStubsMgrBuilder = orc::createLocalIndirectStubsManagerBuilder(T); // If we couldn't build a stubs-manager-builder for this target then bail out. if (!IndirectStubsMgrBuilder) { errs() << "No indirect stubs manager available for target '" << TM->getTargetTriple().str() << "'.\n"; return 1; } // Everything looks good. Build the JIT. OrcLazyJIT J(std::move(TM), std::move(CompileCallbackMgr), std::move(IndirectStubsMgrBuilder), OrcInlineStubs); // Add the module, look up main and run it. for (auto &M : Ms) cantFail(J.addModule(std::shared_ptr<Module>(std::move(M)))); if (auto MainSym = J.findSymbol("main")) { typedef int (*MainFnPtr)(int, const char*[]); std::vector<const char *> ArgV; for (auto &Arg : Args) ArgV.push_back(Arg.c_str()); auto Main = fromTargetAddress<MainFnPtr>(cantFail(MainSym.getAddress())); return Main(ArgV.size(), (const char**)ArgV.data()); } else if (auto Err = MainSym.takeError()) logAllUnhandledErrors(std::move(Err), llvm::errs(), ""); else errs() << "Could not find main function.\n"; return 1; }
int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) { // Add the program's symbols into the JIT's search space. if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) { errs() << "Error loading program symbols.\n"; return 1; } // Grab a target machine and try to build a factory function for the // target-specific Orc callback manager. EngineBuilder EB; EB.setOptLevel(getOptLevel()); auto TM = std::unique_ptr<TargetMachine>(EB.selectTarget()); auto &Context = getGlobalContext(); auto CallbackMgrBuilder = OrcLazyJIT::createCallbackMgrBuilder(Triple(TM->getTargetTriple())); // If we couldn't build the factory function then there must not be a callback // manager for this target. Bail out. if (!CallbackMgrBuilder) { errs() << "No callback manager available for target '" << TM->getTargetTriple().str() << "'.\n"; return 1; } auto IndirectStubsMgrBuilder = OrcLazyJIT::createIndirectStubsMgrBuilder(Triple(TM->getTargetTriple())); // If we couldn't build a stubs-manager-builder for this target then bail out. if (!IndirectStubsMgrBuilder) { errs() << "No indirect stubs manager available for target '" << TM->getTargetTriple().str() << "'.\n"; return 1; } // Everything looks good. Build the JIT. OrcLazyJIT J(std::move(TM), Context, CallbackMgrBuilder, std::move(IndirectStubsMgrBuilder), OrcInlineStubs); // Add the module, look up main and run it. auto MainHandle = J.addModule(std::move(M)); auto MainSym = J.findSymbolIn(MainHandle, "main"); if (!MainSym) { errs() << "Could not find main function.\n"; return 1; } typedef int (*MainFnPtr)(int, char*[]); auto Main = fromTargetAddress<MainFnPtr>(MainSym.getAddress()); return Main(ArgC, ArgV); }