@@ -102,7 +102,7 @@ pub mod jit {
102
102
use back:: link:: llvm_err;
103
103
use driver:: session:: Session ;
104
104
use lib:: llvm:: llvm;
105
- use lib:: llvm:: { ModuleRef , PassManagerRef , ContextRef } ;
105
+ use lib:: llvm:: { ModuleRef , PassManagerRef } ;
106
106
use metadata:: cstore;
107
107
108
108
use core:: cast;
@@ -125,7 +125,6 @@ pub mod jit {
125
125
126
126
pub fn exec ( sess : Session ,
127
127
pm : PassManagerRef ,
128
- c : ContextRef ,
129
128
m : ModuleRef ,
130
129
opt : c_int ,
131
130
stacks : bool ) {
@@ -154,43 +153,26 @@ pub mod jit {
154
153
} ) ;
155
154
}
156
155
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.
164
161
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) ;
176
164
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
+ }
194
176
}
195
177
}
196
178
}
@@ -207,7 +189,6 @@ pub mod write {
207
189
use driver:: session;
208
190
use lib:: llvm:: llvm;
209
191
use lib:: llvm:: { ModuleRef , mk_pass_manager, mk_target_data} ;
210
- use lib:: llvm:: { ContextRef } ;
211
192
use lib;
212
193
213
194
use back:: passes;
@@ -226,7 +207,6 @@ pub mod write {
226
207
}
227
208
228
209
pub fn run_passes ( sess : Session ,
229
- llcx : ContextRef ,
230
210
llmod : ModuleRef ,
231
211
output_type : output_type ,
232
212
output : & Path ) {
@@ -301,7 +281,7 @@ pub mod write {
301
281
// JIT execution takes ownership of the module,
302
282
// so don't dispose and return.
303
283
304
- jit:: exec ( sess, pm. llpm , llcx , llmod, CodeGenOptLevel , true ) ;
284
+ jit:: exec ( sess, pm. llpm , llmod, CodeGenOptLevel , true ) ;
305
285
306
286
if sess. time_llvm_passes ( ) {
307
287
llvm:: LLVMRustPrintPassTimings ( ) ;
@@ -369,7 +349,6 @@ pub mod write {
369
349
// Clean up and return
370
350
371
351
llvm:: LLVMDisposeModule ( llmod) ;
372
- llvm:: LLVMContextDispose ( llcx) ;
373
352
if sess. time_llvm_passes ( ) {
374
353
llvm:: LLVMRustPrintPassTimings ( ) ;
375
354
}
@@ -388,7 +367,6 @@ pub mod write {
388
367
}
389
368
390
369
llvm:: LLVMDisposeModule ( llmod) ;
391
- llvm:: LLVMContextDispose ( llcx) ;
392
370
if sess. time_llvm_passes ( ) { llvm:: LLVMRustPrintPassTimings ( ) ; }
393
371
}
394
372
}
0 commit comments