about summary refs log tree commit diff
path: root/src/comp/back
diff options
context:
space:
mode:
Diffstat (limited to 'src/comp/back')
-rw-r--r--src/comp/back/link.rs126
1 files changed, 71 insertions, 55 deletions
diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs
index 3f09374309c..6a56ca94f94 100644
--- a/src/comp/back/link.rs
+++ b/src/comp/back/link.rs
@@ -32,11 +32,14 @@ tag output_type {
     output_type_exe;
 }
 
-fn llvm_err(sess: session::session, msg: str) {
+fn llvm_err(sess: session::session, msg: &istr) {
     let buf = llvm::LLVMRustGetLastError();
     if buf as uint == 0u {
-        sess.fatal(msg);
-    } else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); }
+        sess.fatal(istr::to_estr(msg));
+    } else {
+        sess.fatal(
+            istr::to_estr(msg) + ": " + str::str_from_cstr(buf));
+    }
 }
 
 fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
@@ -46,19 +49,20 @@ fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
     let membuf =
         llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(str::buf(path));
     if membuf as uint == 0u {
-        llvm_err(sess, "installation problem: couldn't open " + path);
+        llvm_err(sess, ~"installation problem: couldn't open "
+                 + istr::from_estr(path));
         fail;
     }
     let llintrinsicsmod = llvm::LLVMRustParseBitcode(membuf);
     llvm::LLVMDisposeMemoryBuffer(membuf);
     if llintrinsicsmod as uint == 0u {
-        llvm_err(sess, "installation problem: couldn't parse intrinsics.bc");
+        llvm_err(sess, ~"installation problem: couldn't parse intrinsics.bc");
         fail;
     }
     let linkres = llvm::LLVMLinkModules(llmod, llintrinsicsmod);
     llvm::LLVMDisposeModule(llintrinsicsmod);
     if linkres == False {
-        llvm_err(sess, "couldn't link the module with the intrinsics");
+        llvm_err(sess, ~"couldn't link the module with the intrinsics");
         fail;
     }
 }
@@ -74,15 +78,15 @@ mod write {
 
     // Decides what to call an intermediate file, given the name of the output
     // and the extension to use.
-    fn mk_intermediate_name(output_path: str, extension: str) -> str {
-        let dot_pos = str::index(output_path, '.' as u8);
+    fn mk_intermediate_name(output_path: &istr, extension: &istr) -> istr {
+        let dot_pos = istr::index(output_path, '.' as u8);
         let stem;
         if dot_pos < 0 {
             stem = output_path;
-        } else { stem = str::substr(output_path, 0u, dot_pos as uint); }
-        ret stem + "." + extension;
+        } else { stem = istr::substr(output_path, 0u, dot_pos as uint); }
+        ret stem + ~"." + extension;
     }
-    fn run_passes(sess: session::session, llmod: ModuleRef, output: str) {
+    fn run_passes(sess: session::session, llmod: ModuleRef, output: &istr) {
         let opts = sess.get_opts();
         if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
         link_intrinsics(sess, llmod);
@@ -99,12 +103,14 @@ mod write {
             alt opts.output_type {
               output_type_bitcode. {
                 if opts.optimize != 0u {
-                    let filename = mk_intermediate_name(output, "no-opt.bc");
+                    let filename = mk_intermediate_name(output, ~"no-opt.bc");
+                    let filename = istr::to_estr(filename);
                     llvm::LLVMWriteBitcodeToFile(llmod, str::buf(filename));
                 }
               }
               _ {
-                let filename = mk_intermediate_name(output, "bc");
+                let filename = mk_intermediate_name(output, ~"bc");
+                let filename = istr::to_estr(filename);
                 llvm::LLVMWriteBitcodeToFile(llmod, str::buf(filename));
               }
             }
@@ -176,7 +182,8 @@ mod write {
             if opts.save_temps {
                 // Always output the bitcode file with --save-temps
 
-                let filename = mk_intermediate_name(output, "opt.bc");
+                let filename = mk_intermediate_name(output, ~"opt.bc");
+                let filename = istr::to_estr(filename);
                 llvm::LLVMRunPassManager(pm.llpm, llmod);
                 llvm::LLVMWriteBitcodeToFile(llmod, str::buf(filename));
                 pm = mk_pass_manager();
@@ -184,6 +191,7 @@ mod write {
 
                 if opts.output_type == output_type_assembly {
                     let triple = x86::get_target_triple();
+                    let output = istr::to_estr(output);
                     llvm::LLVMRustWriteOutputFile(pm.llpm, llmod,
                                                   str::buf(triple),
                                                   str::buf(output),
@@ -197,6 +205,7 @@ mod write {
                 if opts.output_type == output_type_object ||
                        opts.output_type == output_type_exe {
                     let triple = x86::get_target_triple();
+                    let output = istr::to_estr(output);
                     llvm::LLVMRustWriteOutputFile(pm.llpm, llmod,
                                                   str::buf(triple),
                                                   str::buf(output),
@@ -208,6 +217,7 @@ mod write {
                 // type corresponding to the '-c' or '-S' flag used
 
                 let triple = x86::get_target_triple();
+                let output = istr::to_estr(output);
                 llvm::LLVMRustWriteOutputFile(pm.llpm, llmod,
                                               str::buf(triple),
                                               str::buf(output), FileType,
@@ -223,6 +233,7 @@ mod write {
         // flag, then output it here
 
         llvm::LLVMRunPassManager(pm.llpm, llmod);
+        let output = istr::to_estr(output);
         llvm::LLVMWriteBitcodeToFile(llmod, str::buf(output));
         llvm::LLVMDisposeModule(llmod);
         if opts.time_llvm_passes { llvm::LLVMRustPrintPassTimings(); }
@@ -281,32 +292,32 @@ mod write {
  *
  */
 
-type link_meta = {name: str, vers: str, extras_hash: str};
+type link_meta = {name: istr, vers: istr, extras_hash: istr};
 
-fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str,
+fn build_link_meta(sess: &session::session, c: &ast::crate, output: &istr,
                    sha: sha1) -> link_meta {
 
     type provided_metas =
-        {name: option::t<str>,
-         vers: option::t<str>,
+        {name: option::t<istr>,
+         vers: option::t<istr>,
          cmh_items: [@ast::meta_item]};
 
     fn provided_link_metas(sess: &session::session, c: &ast::crate) ->
        provided_metas {
-        let name: option::t<str> = none;
-        let vers: option::t<str> = none;
+        let name: option::t<istr> = none;
+        let vers: option::t<istr> = none;
         let cmh_items: [@ast::meta_item] = [];
         let linkage_metas = attr::find_linkage_metas(c.node.attrs);
         attr::require_unique_names(sess, linkage_metas);
         for meta: @ast::meta_item in linkage_metas {
             if attr::get_meta_item_name(meta) == ~"name" {
                 alt attr::get_meta_item_value_str(meta) {
-                  some(v) { name = some(v); }
+                  some(v) { name = some(istr::from_estr(v)); }
                   none. { cmh_items += [meta]; }
                 }
             } else if attr::get_meta_item_name(meta) == ~"vers" {
                 alt attr::get_meta_item_value_str(meta) {
-                  some(v) { vers = some(v); }
+                  some(v) { vers = some(istr::from_estr(v)); }
                   none. { cmh_items += [meta]; }
                 }
             } else { cmh_items += [meta]; }
@@ -316,7 +327,7 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str,
 
     // This calculates CMH as defined above
     fn crate_meta_extras_hash(sha: sha1, _crate: &ast::crate,
-                              metas: &provided_metas) -> str {
+                              metas: &provided_metas) -> istr {
         fn len_and_str(s: &istr) -> istr {
             ret istr::from_estr(#fmt["%u_%s",
                                      istr::byte_len(s),
@@ -349,39 +360,39 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str,
         ret truncated_sha1_result(sha);
     }
 
-    fn warn_missing(sess: &session::session, name: str, default: str) {
+    fn warn_missing(sess: &session::session, name: &istr, default: &istr) {
         if !sess.get_opts().library { ret; }
         sess.warn(#fmt["missing crate link meta '%s', using '%s' as default",
-                       name, default]);
+                       istr::to_estr(name), istr::to_estr(default)]);
     }
 
     fn crate_meta_name(sess: &session::session, _crate: &ast::crate,
-                       output: &str, metas: &provided_metas) -> str {
+                       output: &istr, metas: &provided_metas) -> istr {
         ret alt metas.name {
               some(v) { v }
               none. {
                 let name =
                     {
                         let os = istr::split(
-                            fs::basename(istr::from_estr(output)),
+                            fs::basename(output),
                             '.' as u8);
                         assert (vec::len(os) >= 2u);
                         vec::pop(os);
-                        istr::to_estr(istr::connect(os, ~"."))
+                        istr::connect(os, ~".")
                     };
-                warn_missing(sess, "name", name);
+                warn_missing(sess, ~"name", name);
                 name
               }
             };
     }
 
     fn crate_meta_vers(sess: &session::session, _crate: &ast::crate,
-                       metas: &provided_metas) -> str {
+                       metas: &provided_metas) -> istr {
         ret alt metas.vers {
               some(v) { v }
               none. {
-                let vers = "0.0";
-                warn_missing(sess, "vers", vers);
+                let vers = ~"0.0";
+                warn_missing(sess, ~"vers", vers);
                 vers
               }
             };
@@ -395,32 +406,32 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str,
     ret {name: name, vers: vers, extras_hash: extras_hash};
 }
 
-fn truncated_sha1_result(sha: sha1) -> str {
-    ret istr::to_estr(istr::substr(sha.result_str(), 0u, 16u));
+fn truncated_sha1_result(sha: sha1) -> istr {
+    ret istr::substr(sha.result_str(), 0u, 16u);
 }
 
 
 // This calculates STH for a symbol, as defined above
 fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: &link_meta) ->
-   str {
+   istr {
     // NB: do *not* use abbrevs here as we want the symbol names
     // to be independent of one another in the crate.
 
     sha.reset();
-    sha.input_str(istr::from_estr(link_meta.name));
+    sha.input_str(link_meta.name);
     sha.input_str(~"-");
     // FIXME: This wants to be link_meta.meta_hash
-    sha.input_str(istr::from_estr(link_meta.name));
+    sha.input_str(link_meta.name);
     sha.input_str(~"-");
     sha.input_str(encoder::encoded_ty(tcx, t));
     let hash = truncated_sha1_result(sha);
     // Prefix with _ so that it never blends into adjacent digits
 
-    ret "_" + hash;
+    ret ~"_" + hash;
 }
 
-fn get_symbol_hash(ccx: &@crate_ctxt, t: ty::t) -> str {
-    let hash = "";
+fn get_symbol_hash(ccx: &@crate_ctxt, t: ty::t) -> istr {
+    let hash = ~"";
     alt ccx.type_sha1s.find(t) {
       some(h) { hash = h; }
       none. {
@@ -431,47 +442,52 @@ fn get_symbol_hash(ccx: &@crate_ctxt, t: ty::t) -> str {
     ret hash;
 }
 
-fn mangle(ss: &[str]) -> str {
+fn mangle(ss: &[istr]) -> istr {
     // Follow C++ namespace-mangling style
 
-    let n = "_ZN"; // Begin name-sequence.
+    let n = ~"_ZN"; // Begin name-sequence.
 
-    for s: str in ss { n += #fmt["%u%s", str::byte_len(s), s]; }
-    n += "E"; // End name-sequence.
+    for s: istr in ss {
+        n += istr::from_estr(#fmt["%u%s",
+                                  istr::byte_len(s),
+                                  istr::to_estr(s)]);
+    }
+    n += ~"E"; // End name-sequence.
 
     ret n;
 }
 
-fn exported_name(path: &[str], hash: &str, _vers: &str) -> str {
+fn exported_name(path: &[istr], hash: &istr, _vers: &istr) -> istr {
     // FIXME: versioning isn't working yet
 
     ret mangle(path + [hash]); //  + "@" + vers;
 
 }
 
-fn mangle_exported_name(ccx: &@crate_ctxt, path: &[str], t: ty::t) -> str {
+fn mangle_exported_name(ccx: &@crate_ctxt, path: &[istr], t: ty::t) -> istr {
     let hash = get_symbol_hash(ccx, t);
     ret exported_name(path, hash, ccx.link_meta.vers);
 }
 
-fn mangle_internal_name_by_type_only(ccx: &@crate_ctxt, t: ty::t, name: &str)
-   -> str {
+fn mangle_internal_name_by_type_only(ccx: &@crate_ctxt, t: ty::t, name: &istr)
+   -> istr {
     let s = util::ppaux::ty_to_short_str(ccx.tcx, t);
     let hash = get_symbol_hash(ccx, t);
-    ret mangle([name, istr::to_estr(s), hash]);
+    ret mangle([name, s, hash]);
 }
 
-fn mangle_internal_name_by_path_and_seq(ccx: &@crate_ctxt, path: &[str],
-                                        flav: &str) -> str {
-    ret mangle(path + [ccx.names.next(flav)]);
+fn mangle_internal_name_by_path_and_seq(ccx: &@crate_ctxt, path: &[istr],
+                                        flav: &istr) -> istr {
+    ret mangle(path +
+               istr::from_estrs([ccx.names.next(istr::to_estr(flav))]));
 }
 
-fn mangle_internal_name_by_path(_ccx: &@crate_ctxt, path: &[str]) -> str {
+fn mangle_internal_name_by_path(_ccx: &@crate_ctxt, path: &[istr]) -> istr {
     ret mangle(path);
 }
 
-fn mangle_internal_name_by_seq(ccx: &@crate_ctxt, flav: &str) -> str {
-    ret ccx.names.next(flav);
+fn mangle_internal_name_by_seq(ccx: &@crate_ctxt, flav: &istr) -> istr {
+    ret istr::from_estr(ccx.names.next(istr::to_estr(flav)));
 }
 //
 // Local Variables: