// On Mingw and Cygwin, an external symbol named '__main' is called from the // generated 'main' function to allow static intialization. To avoid linking // problems with remote targets (because lli's remote target support does not // currently handle external linking) we add a secondary module which defines // an empty '__main' function. static void addCygMingExtraModule(ExecutionEngine &EE, LLVMContext &Context, StringRef TargetTripleStr) { IRBuilder<> Builder(Context); Triple TargetTriple(TargetTripleStr); // Create a new module. std::unique_ptr<Module> M = make_unique<Module>("CygMingHelper", Context); M->setTargetTriple(TargetTripleStr); // Create an empty function named "__main". Function *Result; if (TargetTriple.isArch64Bit()) { Result = Function::Create( TypeBuilder<int64_t(void), false>::get(Context), GlobalValue::ExternalLinkage, "__main", M.get()); } else { Result = Function::Create( TypeBuilder<int32_t(void), false>::get(Context), GlobalValue::ExternalLinkage, "__main", M.get()); } BasicBlock *BB = BasicBlock::Create(Context, "__main", Result); Builder.SetInsertPoint(BB); Value *ReturnVal; if (TargetTriple.isArch64Bit()) ReturnVal = ConstantInt::get(Context, APInt(64, 0)); else ReturnVal = ConstantInt::get(Context, APInt(32, 0)); Builder.CreateRet(ReturnVal); // Add this new module to the ExecutionEngine. EE.addModule(std::move(M)); }
void initEE(std::unique_ptr<Module> Owner) { string ErrStr; if (EE == NULL) { RTDyldMM = new SectionMemoryManager(); EE = EngineBuilder(std::move(Owner)) .setEngineKind(EngineKind::JIT) .setErrorStr(&ErrStr) .setVerifyModules(true) .setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager>(RTDyldMM)) .setOptLevel(CodeGenOpt::Default) .create(); } else EE->addModule(std::move(Owner)); if (ErrStr.length() != 0) cerr << "Create Engine Error" << endl << ErrStr << endl; EE->finalizeObject(); }
void initEE(std::unique_ptr<Module> Owner) { if (EE == NULL) EE = EngineBuilder(std::move(Owner)).create(); else EE->addModule(std::move(Owner)); }