Skip to content

Commit 32b4524

Browse files
committed
Convert middle::trans_common to istrs. Issue #855
1 parent fcdbdaf commit 32b4524

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

src/comp/back/link.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,15 @@ fn mangle_internal_name_by_type_only(ccx: &@crate_ctxt, t: ty::t, name: &istr)
490490

491491
fn mangle_internal_name_by_path_and_seq(ccx: &@crate_ctxt, path: &[istr],
492492
flav: &istr) -> istr {
493-
ret mangle(path +
494-
istr::from_estrs([ccx.names.next(istr::to_estr(flav))]));
493+
ret mangle(path + [ccx.names.next(flav)]);
495494
}
496495

497496
fn mangle_internal_name_by_path(_ccx: &@crate_ctxt, path: &[istr]) -> istr {
498497
ret mangle(path);
499498
}
500499

501500
fn mangle_internal_name_by_seq(ccx: &@crate_ctxt, flav: &istr) -> istr {
502-
ret istr::from_estr(ccx.names.next(istr::to_estr(flav)));
501+
ret ccx.names.next(flav);
503502
}
504503
//
505504
// Local Variables:

src/comp/middle/shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fn s_float(_tcx: &ty_ctxt) -> u8 {
248248
}
249249

250250
fn mk_ctxt(llmod: ModuleRef) -> ctxt {
251-
let llshapetablesty = trans_common::T_named_struct("shapes");
251+
let llshapetablesty = trans_common::T_named_struct(~"shapes");
252252
let llshapetables = istr::as_buf(~"shapes", { |buf|
253253
lib::llvm::llvm::LLVMAddGlobal(llmod, llshapetablesty, buf)
254254
});

src/comp/middle/trans.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,7 @@ fn trans_lit_istr(cx: &@block_ctxt, s: str) -> result {
24922492
let llvecptr = alloc_res.llptr;
24932493
let llfirsteltptr = alloc_res.llfirsteltptr;
24942494

2495-
let llcstr = C_cstr(bcx_ccx(cx), s);
2495+
let llcstr = C_cstr(bcx_ccx(cx), istr::from_estr(s));
24962496

24972497
// FIXME: We need to avoid this memmove
24982498
bcx = call_memmove(bcx, llfirsteltptr, llcstr, C_uint(veclen)).bcx;
@@ -2523,16 +2523,16 @@ fn trans_crate_lit(cx: &@crate_ctxt, lit: &ast::lit) -> ValueRef {
25232523
}
25242524
ret C_integral(t, i as uint, s);
25252525
}
2526-
ast::lit_float(fs) { ret C_float(fs); }
2526+
ast::lit_float(fs) { ret C_float(istr::from_estr(fs)); }
25272527
ast::lit_mach_float(tm, s) {
25282528
let t = T_float();
25292529
alt tm { ast::ty_f32. { t = T_f32(); } ast::ty_f64. { t = T_f64(); } }
2530-
ret C_floating(s, t);
2530+
ret C_floating(istr::from_estr(s), t);
25312531
}
25322532
ast::lit_char(c) { ret C_integral(T_char(), c as uint, False); }
25332533
ast::lit_bool(b) { ret C_bool(b); }
25342534
ast::lit_nil. { ret C_nil(); }
2535-
ast::lit_str(s, ast::sk_rc.) { ret C_str(cx, s); }
2535+
ast::lit_str(s, ast::sk_rc.) { ret C_str(cx, istr::from_estr(s)); }
25362536
ast::lit_str(s, ast::sk_unique.) {
25372537
cx.sess.span_unimpl(lit.span, "unique string in this context");
25382538
}
@@ -4317,7 +4317,8 @@ fn trans_expr_out(cx: &@block_ctxt, e: &@ast::expr, output: out_method) ->
43174317
let ccx = bcx_ccx(cx);
43184318
let llfnty: TypeRef =
43194319
type_of_fn_from_ty(ccx, e.span, node_id_type(ccx, e.id), 0u);
4320-
let sub_cx = extend_path(cx.fcx.lcx, ccx.names.next("anon"));
4320+
let sub_cx = extend_path(cx.fcx.lcx,
4321+
istr::to_estr(ccx.names.next(~"anon")));
43214322
let s = mangle_internal_name_by_path(ccx,
43224323
istr::from_estrs(sub_cx.path));
43234324
let llfn = decl_internal_fastcall_fn(ccx.llmod,
@@ -4632,7 +4633,7 @@ fn trans_fail_expr(cx: &@block_ctxt, sp_opt: &option::t<span>,
46324633

46334634
fn trans_fail(cx: &@block_ctxt, sp_opt: &option::t<span>, fail_str: &str) ->
46344635
result {
4635-
let V_fail_str = C_cstr(bcx_ccx(cx), fail_str);
4636+
let V_fail_str = C_cstr(bcx_ccx(cx), istr::from_estr(fail_str));
46364637
ret trans_fail_value(cx, sp_opt, V_fail_str);
46374638
}
46384639

@@ -4643,10 +4644,10 @@ fn trans_fail_value(cx: &@block_ctxt, sp_opt: &option::t<span>,
46434644
alt sp_opt {
46444645
some(sp) {
46454646
let loc = bcx_ccx(cx).sess.lookup_pos(sp.lo);
4646-
V_filename = C_cstr(bcx_ccx(cx), loc.filename);
4647+
V_filename = C_cstr(bcx_ccx(cx), istr::from_estr(loc.filename));
46474648
V_line = loc.line as int;
46484649
}
4649-
none. { V_filename = C_cstr(bcx_ccx(cx), "<runtime>"); V_line = 0; }
4650+
none. { V_filename = C_cstr(bcx_ccx(cx), ~"<runtime>"); V_line = 0; }
46504651
}
46514652
let V_str = bld::PointerCast(cx, V_fail_str, T_ptr(T_i8()));
46524653
V_filename = bld::PointerCast(cx, V_filename, T_ptr(T_i8()));
@@ -4924,12 +4925,12 @@ fn trans_stmt(cx: &@block_ctxt, s: &ast::stmt) -> result {
49244925
// next three functions instead.
49254926
fn new_block_ctxt(cx: &@fn_ctxt, parent: &block_parent, kind: block_kind,
49264927
name: &str) -> @block_ctxt {
4927-
let s = "";
4928+
let s = ~"";
49284929
if cx.lcx.ccx.sess.get_opts().save_temps ||
49294930
cx.lcx.ccx.sess.get_opts().debuginfo {
4930-
s = cx.lcx.ccx.names.next(name);
4931+
s = cx.lcx.ccx.names.next(istr::from_estr(name));
49314932
}
4932-
let llbb: BasicBlockRef = istr::as_buf(istr::from_estr(s), { |buf|
4933+
let llbb: BasicBlockRef = istr::as_buf(s, { |buf|
49334934
llvm::LLVMAppendBasicBlock(cx.llfn, buf)
49344935
});
49354936
ret @{llbb: llbb,
@@ -6325,7 +6326,7 @@ fn create_module_map(ccx: &@crate_ctxt) -> ValueRef {
63256326
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
63266327
let elts: [ValueRef] = [];
63276328
for each item: @{key: istr, val: ValueRef} in ccx.module_data.items() {
6328-
let elt = C_struct([p2i(C_cstr(ccx, istr::to_estr(item.key))),
6329+
let elt = C_struct([p2i(C_cstr(ccx, item.key)),
63296330
p2i(item.val)]);
63306331
elts += [elt];
63316332
}
@@ -6370,7 +6371,8 @@ fn create_crate_map(ccx: &@crate_ctxt) -> ValueRef {
63706371

63716372
fn write_metadata(cx: &@crate_ctxt, crate: &@ast::crate) {
63726373
if !cx.sess.get_opts().library { ret; }
6373-
let llmeta = C_postr(metadata::encoder::encode_metadata(cx, crate));
6374+
let llmeta = C_postr(
6375+
istr::from_estr(metadata::encoder::encode_metadata(cx, crate)));
63746376
let llconst = trans_common::C_struct([llmeta]);
63756377
let llglobal = istr::as_buf(~"rust_metadata", { |buf|
63766378
llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst), buf)

src/comp/middle/trans_common.rs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ import trans::type_of_fn_full;
6363
import trans::drop_ty;
6464

6565
obj namegen(mutable i: int) {
66-
fn next(prefix: str) -> str {
67-
i += 1; ret prefix + istr::to_estr(int::str(i));
66+
fn next(prefix: &istr) -> istr {
67+
i += 1; ret prefix + int::str(i);
6868
}
6969
}
7070

@@ -438,13 +438,15 @@ fn rslt(bcx: @block_ctxt, val: ValueRef) -> result {
438438
ret {bcx: bcx, val: val};
439439
}
440440

441-
fn ty_str(tn: type_names, t: TypeRef) -> str {
442-
ret istr::to_estr(lib::llvm::type_to_str(tn, t));
441+
fn ty_str(tn: type_names, t: TypeRef) -> istr {
442+
ret lib::llvm::type_to_str(tn, t);
443443
}
444444

445445
fn val_ty(v: ValueRef) -> TypeRef { ret llvm::LLVMTypeOf(v); }
446446

447-
fn val_str(tn: type_names, v: ValueRef) -> str { ret ty_str(tn, val_ty(v)); }
447+
fn val_str(tn: type_names, v: ValueRef) -> istr {
448+
ret ty_str(tn, val_ty(v));
449+
}
448450

449451
// Returns the nth element of the given LLVM structure type.
450452
fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef {
@@ -551,9 +553,9 @@ fn T_struct(elts: &[TypeRef]) -> TypeRef {
551553
False);
552554
}
553555

554-
fn T_named_struct(name: &str) -> TypeRef {
556+
fn T_named_struct(name: &istr) -> TypeRef {
555557
let c = llvm::LLVMGetGlobalContext();
556-
ret istr::as_buf(istr::from_estr(name), { |buf|
558+
ret istr::as_buf(name, { |buf|
557559
llvm::LLVMStructCreateNamed(c, buf)
558560
});
559561
}
@@ -570,14 +572,14 @@ fn T_empty_struct() -> TypeRef { ret T_struct([]); }
570572
// existing objects, use ccx.rust_object_type. Calling
571573
// T_rust_object() again will return a different one.
572574
fn T_rust_object() -> TypeRef {
573-
let t = T_named_struct("rust_object");
575+
let t = T_named_struct(~"rust_object");
574576
let e = T_ptr(T_empty_struct());
575577
set_struct_body(t, [e, e]);
576578
ret t;
577579
}
578580

579581
fn T_task() -> TypeRef {
580-
let t = T_named_struct("task");
582+
let t = T_named_struct(~"task");
581583

582584
// Refcount
583585
// Delegate pointer
@@ -633,7 +635,7 @@ fn T_copy_glue_fn(cx: &crate_ctxt) -> TypeRef {
633635
}
634636

635637
fn T_tydesc(taskptr_type: TypeRef) -> TypeRef {
636-
let tydesc = T_named_struct("tydesc");
638+
let tydesc = T_named_struct(~"tydesc");
637639
let tydescpp = T_ptr(T_ptr(tydesc));
638640
let pvoid = T_ptr(T_i8());
639641
let glue_fn_ty =
@@ -817,14 +819,14 @@ fn C_integral(t: TypeRef, u: uint, sign_extend: Bool) -> ValueRef {
817819
ret llvm::LLVMRustConstSmallInt(t, u, sign_extend);
818820
}
819821

820-
fn C_float(s: &str) -> ValueRef {
821-
ret istr::as_buf(istr::from_estr(s), { |buf|
822+
fn C_float(s: &istr) -> ValueRef {
823+
ret istr::as_buf(s, { |buf|
822824
llvm::LLVMConstRealOfString(T_float(), buf)
823825
});
824826
}
825827

826-
fn C_floating(s: &str, t: TypeRef) -> ValueRef {
827-
ret istr::as_buf(istr::from_estr(s), { |buf|
828+
fn C_floating(s: &istr, t: TypeRef) -> ValueRef {
829+
ret istr::as_buf(s, { |buf|
828830
llvm::LLVMConstRealOfString(t, buf)
829831
});
830832
}
@@ -850,11 +852,11 @@ fn C_u8(i: uint) -> ValueRef { ret C_integral(T_i8(), i, False); }
850852

851853
// This is a 'c-like' raw string, which differs from
852854
// our boxed-and-length-annotated strings.
853-
fn C_cstr(cx: &@crate_ctxt, s: &str) -> ValueRef {
854-
let sc = istr::as_buf(istr::from_estr(s), { |buf|
855-
llvm::LLVMConstString(buf, str::byte_len(s), False)
855+
fn C_cstr(cx: &@crate_ctxt, s: &istr) -> ValueRef {
856+
let sc = istr::as_buf(s, { |buf|
857+
llvm::LLVMConstString(buf, istr::byte_len(s), False)
856858
});
857-
let g = istr::as_buf(istr::from_estr(cx.names.next("str")), { |buf|
859+
let g = istr::as_buf(cx.names.next(~"str"), { |buf|
858860
llvm::LLVMAddGlobal(cx.llmod, val_ty(sc), buf)
859861
});
860862
llvm::LLVMSetInitializer(g, sc);
@@ -865,19 +867,19 @@ fn C_cstr(cx: &@crate_ctxt, s: &str) -> ValueRef {
865867

866868

867869
// A rust boxed-and-length-annotated string.
868-
fn C_str(cx: &@crate_ctxt, s: &str) -> ValueRef {
870+
fn C_str(cx: &@crate_ctxt, s: &istr) -> ValueRef {
869871
let len =
870-
str::byte_len(s); // 'alloc'
872+
istr::byte_len(s); // 'alloc'
871873
// 'fill'
872874
// 'pad'
873875

874-
let cstr = istr::as_buf(istr::from_estr(s), { |buf|
876+
let cstr = istr::as_buf(s, { |buf|
875877
llvm::LLVMConstString(buf, len, False)
876878
});
877879
let box =
878880
C_struct([C_int(abi::const_refcount as int), C_int(len + 1u as int),
879881
C_int(len + 1u as int), C_int(0), cstr]);
880-
let g = istr::as_buf(istr::from_estr(cx.names.next("str")), { |buf|
882+
let g = istr::as_buf(cx.names.next(~"str"), { |buf|
881883
llvm::LLVMAddGlobal(cx.llmod, val_ty(box), buf)
882884
});
883885
llvm::LLVMSetInitializer(g, box);
@@ -887,9 +889,9 @@ fn C_str(cx: &@crate_ctxt, s: &str) -> ValueRef {
887889
}
888890

889891
// Returns a Plain Old LLVM String:
890-
fn C_postr(s: &str) -> ValueRef {
891-
ret istr::as_buf(istr::from_estr(s), { |buf|
892-
llvm::LLVMConstString(buf, str::byte_len(s), False)
892+
fn C_postr(s: &istr) -> ValueRef {
893+
ret istr::as_buf(s, { |buf|
894+
llvm::LLVMConstString(buf, istr::byte_len(s), False)
893895
});
894896
}
895897

@@ -922,8 +924,7 @@ fn C_bytes(bytes: &[u8]) -> ValueRef {
922924

923925
fn C_shape(ccx: &@crate_ctxt, bytes: &[u8]) -> ValueRef {
924926
let llshape = C_bytes(bytes);
925-
let llglobal = istr::as_buf(
926-
istr::from_estr(ccx.names.next("shape")), { |buf|
927+
let llglobal = istr::as_buf(ccx.names.next(~"shape"), { |buf|
927928
llvm::LLVMAddGlobal(ccx.llmod, val_ty(llshape), buf)
928929
});
929930
llvm::LLVMSetInitializer(llglobal, llshape);

0 commit comments

Comments
 (0)