@@ -102,7 +102,7 @@ pub mod jit {
102102 use back:: link:: llvm_err;
103103 use driver:: session:: Session ;
104104 use lib:: llvm:: llvm;
105- use lib:: llvm:: { ModuleRef , PassManagerRef , ContextRef } ;
105+ use lib:: llvm:: { ModuleRef , PassManagerRef } ;
106106 use metadata:: cstore;
107107
108108 use core:: cast;
@@ -125,7 +125,6 @@ pub mod jit {
125125
126126 pub fn exec ( sess : Session ,
127127 pm : PassManagerRef ,
128- c : ContextRef ,
129128 m : ModuleRef ,
130129 opt : c_int ,
131130 stacks : bool ) {
@@ -154,43 +153,26 @@ pub mod jit {
154153 } ) ;
155154 }
156155
157- // We custom-build a JIT execution engine via some rust wrappers
158- // first. This wrappers takes ownership of the module passed in.
159- let ee = llvm:: LLVMRustBuildJIT ( manager, pm, m, opt, stacks) ;
160- if ee. is_null ( ) {
161- llvm:: LLVMContextDispose ( c) ;
162- llvm_err ( sess, ~"Could not create the JIT ") ;
163- }
156+ // The execute function will return a void pointer
157+ // to the _rust_main function. We can do closure
158+ // magic here to turn it straight into a callable rust
159+ // closure. It will also cleanup the memory manager
160+ // for us.
164161
165- // Next, we need to get a handle on the _rust_main function by
166- // looking up it's corresponding ValueRef and then requesting that
167- // the execution engine compiles the function.
168- let fun = do str:: as_c_str ( "_rust_main" ) |entry| {
169- llvm:: LLVMGetNamedFunction ( m, entry)
170- } ;
171- if fun. is_null ( ) {
172- llvm:: LLVMDisposeExecutionEngine ( ee) ;
173- llvm:: LLVMContextDispose ( c) ;
174- llvm_err ( sess, ~"Could not find _rust_main in the JIT ") ;
175- }
162+ let entry = llvm:: LLVMRustExecuteJIT ( manager,
163+ pm, m, opt, stacks) ;
176164
177- // Finally, once we have the pointer to the code, we can do some
178- // closure magic here to turn it straight into a callable rust
179- // closure
180- let code = llvm:: LLVMGetPointerToGlobal ( ee, fun) ;
181- assert ! ( !code. is_null( ) ) ;
182- let closure = Closure {
183- code : code,
184- env : ptr:: null ( )
185- } ;
186- let func: & fn ( ) = cast:: transmute ( closure) ;
187- func ( ) ;
188-
189- // Sadly, there currently is no interface to re-use this execution
190- // engine, so it's disposed of here along with the context to
191- // prevent leaks.
192- llvm:: LLVMDisposeExecutionEngine ( ee) ;
193- llvm:: LLVMContextDispose ( c) ;
165+ if ptr:: is_null ( entry) {
166+ llvm_err ( sess, ~"Could not JIT ") ;
167+ } else {
168+ let closure = Closure {
169+ code : entry,
170+ env : ptr:: null ( )
171+ } ;
172+ let func: & fn ( ) = cast:: transmute ( closure) ;
173+
174+ func ( ) ;
175+ }
194176 }
195177 }
196178}
@@ -207,7 +189,6 @@ pub mod write {
207189 use driver:: session;
208190 use lib:: llvm:: llvm;
209191 use lib:: llvm:: { ModuleRef , mk_pass_manager, mk_target_data} ;
210- use lib:: llvm:: { ContextRef } ;
211192 use lib;
212193
213194 use back:: passes;
@@ -226,7 +207,6 @@ pub mod write {
226207 }
227208
228209 pub fn run_passes ( sess : Session ,
229- llcx : ContextRef ,
230210 llmod : ModuleRef ,
231211 output_type : output_type ,
232212 output : & Path ) {
@@ -301,7 +281,7 @@ pub mod write {
301281 // JIT execution takes ownership of the module,
302282 // so don't dispose and return.
303283
304- jit:: exec ( sess, pm. llpm , llcx , llmod, CodeGenOptLevel , true ) ;
284+ jit:: exec ( sess, pm. llpm , llmod, CodeGenOptLevel , true ) ;
305285
306286 if sess. time_llvm_passes ( ) {
307287 llvm:: LLVMRustPrintPassTimings ( ) ;
@@ -369,7 +349,6 @@ pub mod write {
369349 // Clean up and return
370350
371351 llvm:: LLVMDisposeModule ( llmod) ;
372- llvm:: LLVMContextDispose ( llcx) ;
373352 if sess. time_llvm_passes ( ) {
374353 llvm:: LLVMRustPrintPassTimings ( ) ;
375354 }
@@ -388,7 +367,6 @@ pub mod write {
388367 }
389368
390369 llvm:: LLVMDisposeModule ( llmod) ;
391- llvm:: LLVMContextDispose ( llcx) ;
392370 if sess. time_llvm_passes ( ) { llvm:: LLVMRustPrintPassTimings ( ) ; }
393371 }
394372 }
0 commit comments