int run(unique_ptr<Module> module, Chars_const fnName, const vector<string> args) { check(module, "no module"); Function* entryFn = module->getFunction(fnName); check(entryFn, "Source file does not contain a function of the given name"); // Use an EngineBuilder to configure and construct an MCJIT ExecutionEngine. #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 EngineBuilder builder(module.release()); builder.setUseMCJIT(true); #else const EngineBuilder builder(move(module)); const SectionMemoryManager mm; builder.setMCJITMemoryManager(&mm); #endif string errorStr; builder.setErrorStr(&errorStr); builder.setEngineKind(EngineKind::JIT); builder.setOptLevel(CodeGenOpt::None); ExecutionEngine* engine = builder.create(); // Call 'finalizeObject' to notify the JIT that we're ready to execute the jitted code, // then run the static constructors. engine->finalizeObject(); engine->runStaticConstructorsDestructors(false); // Pass the args to the jitted function, and capture the result. const int result = engine->runFunctionAsMain(entryFn, args, nullptr); engine->runStaticConstructorsDestructors(true); // Run the static destructors. return result; }