forked from OSchip/llvm-project
parent
2a8a2795ee
commit
a296664479
clang
|
@ -42,27 +42,29 @@ std::string GetExecutablePath(const char *Argv0) {
|
|||
return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
|
||||
}
|
||||
|
||||
static llvm::ExecutionEngine *createExecutionEngine(llvm::Module *M,
|
||||
std::string *ErrorStr) {
|
||||
llvm::EngineBuilder EB = llvm::EngineBuilder(M)
|
||||
.setUseMCJIT(true)
|
||||
.setEngineKind(llvm::EngineKind::Either)
|
||||
.setErrorStr(ErrorStr);
|
||||
return EB.create();
|
||||
static llvm::ExecutionEngine *
|
||||
createExecutionEngine(std::unique_ptr<llvm::Module> M, std::string *ErrorStr) {
|
||||
return llvm::EngineBuilder(std::move(M))
|
||||
.setUseMCJIT(true)
|
||||
.setEngineKind(llvm::EngineKind::Either)
|
||||
.setErrorStr(ErrorStr)
|
||||
.create();
|
||||
}
|
||||
|
||||
static int Execute(llvm::Module *Mod, char * const *envp) {
|
||||
static int Execute(std::unique_ptr<llvm::Module> Mod, char *const *envp) {
|
||||
llvm::InitializeNativeTarget();
|
||||
llvm::InitializeNativeTargetAsmPrinter();
|
||||
|
||||
llvm::Module &M = *Mod;
|
||||
std::string Error;
|
||||
std::unique_ptr<llvm::ExecutionEngine> EE(createExecutionEngine(Mod, &Error));
|
||||
std::unique_ptr<llvm::ExecutionEngine> EE(
|
||||
createExecutionEngine(std::move(Mod), &Error));
|
||||
if (!EE) {
|
||||
llvm::errs() << "unable to make execution engine: " << Error << "\n";
|
||||
return 255;
|
||||
}
|
||||
|
||||
llvm::Function *EntryFn = Mod->getFunction("main");
|
||||
llvm::Function *EntryFn = M.getFunction("main");
|
||||
if (!EntryFn) {
|
||||
llvm::errs() << "'main' function not found in module.\n";
|
||||
return 255;
|
||||
|
@ -70,7 +72,7 @@ static int Execute(llvm::Module *Mod, char * const *envp) {
|
|||
|
||||
// FIXME: Support passing arguments.
|
||||
std::vector<std::string> Args;
|
||||
Args.push_back(Mod->getModuleIdentifier());
|
||||
Args.push_back(M.getModuleIdentifier());
|
||||
|
||||
EE->finalizeObject();
|
||||
return EE->runFunctionAsMain(EntryFn, Args, envp);
|
||||
|
@ -163,8 +165,8 @@ int main(int argc, const char **argv, char * const *envp) {
|
|||
return 1;
|
||||
|
||||
int Res = 255;
|
||||
if (llvm::Module *Module = Act->takeModule())
|
||||
Res = Execute(Module, envp);
|
||||
if (std::unique_ptr<llvm::Module> &Module = Act->getModule())
|
||||
Res = Execute(std::move(Module), envp);
|
||||
|
||||
// Shutdown.
|
||||
|
||||
|
|
|
@ -52,9 +52,9 @@ public:
|
|||
/// the action will load it from the specified file.
|
||||
void setLinkModule(llvm::Module *Mod) { LinkModule = Mod; }
|
||||
|
||||
/// takeModule - Take the generated LLVM module, for use after the action has
|
||||
/// been run. The result may be null on failure.
|
||||
llvm::Module *takeModule();
|
||||
/// Take the generated LLVM module, for use after the action has been run.
|
||||
/// The result may be null on failure.
|
||||
std::unique_ptr<llvm::Module> &getModule() { return TheModule; }
|
||||
|
||||
/// Take the LLVM context used by this action.
|
||||
llvm::LLVMContext *takeLLVMContext();
|
||||
|
|
|
@ -579,8 +579,6 @@ void CodeGenAction::EndSourceFileAction() {
|
|||
TheModule.reset(BEConsumer->takeModule());
|
||||
}
|
||||
|
||||
llvm::Module *CodeGenAction::takeModule() { return TheModule.release(); }
|
||||
|
||||
llvm::LLVMContext *CodeGenAction::takeLLVMContext() {
|
||||
OwnsVMContext = false;
|
||||
return VMContext;
|
||||
|
|
Loading…
Reference in New Issue