about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSeo Sanghyeon <sanxiyn@gmail.com>2013-04-22 20:17:25 +0900
committerSeo Sanghyeon <sanxiyn@gmail.com>2013-04-22 20:17:25 +0900
commitba1f3c9b1fdf2c5ff8426f1a2ac97fd8f6429505 (patch)
tree9b6cc31b260e02b7a0dd66e0ac485dbc5e4e94bc /src
parent3830040a89297dd55f920ec26ab97fb2e33c7a00 (diff)
downloadrust-ba1f3c9b1fdf2c5ff8426f1a2ac97fd8f6429505.tar.gz
rust-ba1f3c9b1fdf2c5ff8426f1a2ac97fd8f6429505.zip
Convert to C string inside WriteOutputFile
Diffstat (limited to 'src')
-rw-r--r--src/librustc/back/link.rs99
1 files changed, 42 insertions, 57 deletions
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index 3dfa318826b..3d2b46eb51a 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -61,23 +61,28 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! {
 
 pub fn WriteOutputFile(sess: Session,
         PM: lib::llvm::PassManagerRef, M: ModuleRef,
-        Triple: *c_char,
+        Triple: &str,
+        Output: &str,
         // FIXME: When #2334 is fixed, change
         // c_uint to FileType
-        Output: *c_char, FileType: c_uint,
+        FileType: c_uint,
         OptLevel: c_int,
         EnableSegmentedStacks: bool) {
     unsafe {
-        let result = llvm::LLVMRustWriteOutputFile(
-                PM,
-                M,
-                Triple,
-                Output,
-                FileType,
-                OptLevel,
-                EnableSegmentedStacks);
-        if (!result) {
-            llvm_err(sess, ~"Could not write output");
+        do str::as_c_str(Triple) |Triple| {
+            do str::as_c_str(Output) |Output| {
+                let result = llvm::LLVMRustWriteOutputFile(
+                        PM,
+                        M,
+                        Triple,
+                        Output,
+                        FileType,
+                        OptLevel,
+                        EnableSegmentedStacks);
+                if (!result) {
+                    llvm_err(sess, ~"Could not write output");
+                }
+            }
         }
     }
 }
@@ -310,66 +315,46 @@ pub mod write {
                         llvm::LLVMWriteBitcodeToFile(llmod, buf)
                     });
                     pm = mk_pass_manager();
-                    // Save the assembly file if -S is used
 
+                    // Save the assembly file if -S is used
                     if output_type == output_type_assembly {
-                        let _: () = str::as_c_str(
+                        WriteOutputFile(
+                            sess,
+                            pm.llpm,
+                            llmod,
                             sess.targ_cfg.target_strs.target_triple,
-                            |buf_t| {
-                                str::as_c_str(output.to_str(), |buf_o| {
-                                    WriteOutputFile(
-                                        sess,
-                                        pm.llpm,
-                                        llmod,
-                                        buf_t,
-                                        buf_o,
-                                        lib::llvm::AssemblyFile as c_uint,
-                                        CodeGenOptLevel,
-                                        true)
-                                })
-                            });
+                            output.to_str(),
+                            lib::llvm::AssemblyFile as c_uint,
+                            CodeGenOptLevel,
+                            true);
                     }
 
-
                     // Save the object file for -c or --save-temps alone
                     // This .o is needed when an exe is built
                     if output_type == output_type_object ||
                            output_type == output_type_exe {
-                        let _: () = str::as_c_str(
+                        WriteOutputFile(
+                            sess,
+                            pm.llpm,
+                            llmod,
                             sess.targ_cfg.target_strs.target_triple,
-                            |buf_t| {
-                                str::as_c_str(output.to_str(), |buf_o| {
-                                    WriteOutputFile(
-                                        sess,
-                                        pm.llpm,
-                                        llmod,
-                                        buf_t,
-                                        buf_o,
-                                        lib::llvm::ObjectFile as c_uint,
-                                        CodeGenOptLevel,
-                                        true)
-                                })
-                            });
+                            output.to_str(),
+                            lib::llvm::ObjectFile as c_uint,
+                            CodeGenOptLevel,
+                            true);
                     }
                 } else {
                     // If we aren't saving temps then just output the file
                     // type corresponding to the '-c' or '-S' flag used
-
-                    let _: () = str::as_c_str(
+                    WriteOutputFile(
+                        sess,
+                        pm.llpm,
+                        llmod,
                         sess.targ_cfg.target_strs.target_triple,
-                        |buf_t| {
-                            str::as_c_str(output.to_str(), |buf_o| {
-                                WriteOutputFile(
-                                    sess,
-                                    pm.llpm,
-                                    llmod,
-                                    buf_t,
-                                    buf_o,
-                                    FileType as c_uint,
-                                    CodeGenOptLevel,
-                                    true)
-                            })
-                        });
+                        output.to_str(),
+                        FileType as c_uint,
+                        CodeGenOptLevel,
+                        true);
                 }
                 // Clean up and return