@@ -42,35 +42,37 @@ std::string GetExecutablePath(const char *Argv0) {
42
42
return llvm::sys::fs::getMainExecutable (Argv0, MainAddr);
43
43
}
44
44
45
- static llvm::ExecutionEngine *createExecutionEngine (llvm::Module *M,
46
- std::string *ErrorStr) {
47
- llvm::EngineBuilder EB = llvm::EngineBuilder (M )
48
- .setUseMCJIT (true )
49
- .setEngineKind (llvm::EngineKind::Either)
50
- .setErrorStr (ErrorStr);
51
- return EB .create ();
45
+ static llvm::ExecutionEngine *
46
+ createExecutionEngine (std::unique_ptr<llvm::Module> M, std::string *ErrorStr) {
47
+ return llvm::EngineBuilder ( std::move (M) )
48
+ .setUseMCJIT (true )
49
+ .setEngineKind (llvm::EngineKind::Either)
50
+ .setErrorStr (ErrorStr)
51
+ .create ();
52
52
}
53
53
54
- static int Execute (llvm::Module * Mod, char * const *envp) {
54
+ static int Execute (std::unique_ptr< llvm::Module> Mod, char *const *envp) {
55
55
llvm::InitializeNativeTarget ();
56
56
llvm::InitializeNativeTargetAsmPrinter ();
57
57
58
+ llvm::Module &M = *Mod;
58
59
std::string Error;
59
- std::unique_ptr<llvm::ExecutionEngine> EE (createExecutionEngine (Mod, &Error));
60
+ std::unique_ptr<llvm::ExecutionEngine> EE (
61
+ createExecutionEngine (std::move (Mod), &Error));
60
62
if (!EE) {
61
63
llvm::errs () << " unable to make execution engine: " << Error << " \n " ;
62
64
return 255 ;
63
65
}
64
66
65
- llvm::Function *EntryFn = Mod-> getFunction (" main" );
67
+ llvm::Function *EntryFn = M. getFunction (" main" );
66
68
if (!EntryFn) {
67
69
llvm::errs () << " 'main' function not found in module.\n " ;
68
70
return 255 ;
69
71
}
70
72
71
73
// FIXME: Support passing arguments.
72
74
std::vector<std::string> Args;
73
- Args.push_back (Mod-> getModuleIdentifier ());
75
+ Args.push_back (M. getModuleIdentifier ());
74
76
75
77
EE->finalizeObject ();
76
78
return EE->runFunctionAsMain (EntryFn, Args, envp);
@@ -163,8 +165,8 @@ int main(int argc, const char **argv, char * const *envp) {
163
165
return 1 ;
164
166
165
167
int Res = 255 ;
166
- if (llvm::Module * Module = Act->takeModule ())
167
- Res = Execute (Module, envp);
168
+ if (std::unique_ptr< llvm::Module> & Module = Act->getModule ())
169
+ Res = Execute (std::move ( Module) , envp);
168
170
169
171
// Shutdown.
170
172
0 commit comments