@@ -61,23 +61,28 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! {
61
61
62
62
pub fn WriteOutputFile(sess: Session,
63
63
PM: lib::llvm::PassManagerRef, M: ModuleRef,
64
- Triple: *c_char,
64
+ Triple: &str,
65
+ Output: &str,
65
66
// FIXME: When #2334 is fixed, change
66
67
// c_uint to FileType
67
- Output: *c_char, FileType: c_uint,
68
+ FileType: c_uint,
68
69
OptLevel: c_int,
69
70
EnableSegmentedStacks: bool) {
70
71
unsafe {
71
- let result = llvm::LLVMRustWriteOutputFile(
72
- PM,
73
- M,
74
- Triple,
75
- Output,
76
- FileType,
77
- OptLevel,
78
- EnableSegmentedStacks);
79
- if (!result) {
80
- llvm_err(sess, ~" Could not write output") ;
72
+ do str::as_c_str(Triple) |Triple| {
73
+ do str::as_c_str(Output) |Output| {
74
+ let result = llvm::LLVMRustWriteOutputFile(
75
+ PM,
76
+ M,
77
+ Triple,
78
+ Output,
79
+ FileType,
80
+ OptLevel,
81
+ EnableSegmentedStacks);
82
+ if (!result) {
83
+ llvm_err(sess, ~" Could not write output") ;
84
+ }
85
+ }
81
86
}
82
87
}
83
88
}
@@ -310,66 +315,46 @@ pub mod write {
310
315
llvm:: LLVMWriteBitcodeToFile ( llmod, buf)
311
316
} ) ;
312
317
pm = mk_pass_manager ( ) ;
313
- // Save the assembly file if -S is used
314
318
319
+ // Save the assembly file if -S is used
315
320
if output_type == output_type_assembly {
316
- let _: ( ) = str:: as_c_str (
321
+ WriteOutputFile (
322
+ sess,
323
+ pm. llpm ,
324
+ llmod,
317
325
sess. targ_cfg . target_strs . target_triple ,
318
- |buf_t| {
319
- str:: as_c_str ( output. to_str ( ) , |buf_o| {
320
- WriteOutputFile (
321
- sess,
322
- pm. llpm ,
323
- llmod,
324
- buf_t,
325
- buf_o,
326
- lib:: llvm:: AssemblyFile as c_uint ,
327
- CodeGenOptLevel ,
328
- true )
329
- } )
330
- } ) ;
326
+ output. to_str ( ) ,
327
+ lib:: llvm:: AssemblyFile as c_uint ,
328
+ CodeGenOptLevel ,
329
+ true ) ;
331
330
}
332
331
333
-
334
332
// Save the object file for -c or --save-temps alone
335
333
// This .o is needed when an exe is built
336
334
if output_type == output_type_object ||
337
335
output_type == output_type_exe {
338
- let _: ( ) = str:: as_c_str (
336
+ WriteOutputFile (
337
+ sess,
338
+ pm. llpm ,
339
+ llmod,
339
340
sess. targ_cfg . target_strs . target_triple ,
340
- |buf_t| {
341
- str:: as_c_str ( output. to_str ( ) , |buf_o| {
342
- WriteOutputFile (
343
- sess,
344
- pm. llpm ,
345
- llmod,
346
- buf_t,
347
- buf_o,
348
- lib:: llvm:: ObjectFile as c_uint ,
349
- CodeGenOptLevel ,
350
- true )
351
- } )
352
- } ) ;
341
+ output. to_str ( ) ,
342
+ lib:: llvm:: ObjectFile as c_uint ,
343
+ CodeGenOptLevel ,
344
+ true ) ;
353
345
}
354
346
} else {
355
347
// If we aren't saving temps then just output the file
356
348
// type corresponding to the '-c' or '-S' flag used
357
-
358
- let _: ( ) = str:: as_c_str (
349
+ WriteOutputFile (
350
+ sess,
351
+ pm. llpm ,
352
+ llmod,
359
353
sess. targ_cfg . target_strs . target_triple ,
360
- |buf_t| {
361
- str:: as_c_str ( output. to_str ( ) , |buf_o| {
362
- WriteOutputFile (
363
- sess,
364
- pm. llpm ,
365
- llmod,
366
- buf_t,
367
- buf_o,
368
- FileType as c_uint ,
369
- CodeGenOptLevel ,
370
- true )
371
- } )
372
- } ) ;
354
+ output. to_str ( ) ,
355
+ FileType as c_uint ,
356
+ CodeGenOptLevel ,
357
+ true ) ;
373
358
}
374
359
// Clean up and return
375
360
0 commit comments