Skip to content

Commit fcdbdaf

Browse files
committed
Convert the rest of rustc::lib::llvm to istrs. Issue #855
1 parent d7fa754 commit fcdbdaf

File tree

4 files changed

+50
-49
lines changed

4 files changed

+50
-49
lines changed

src/comp/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ mod write {
9191
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
9292
link_intrinsics(sess, llmod);
9393
let pm = mk_pass_manager();
94-
let td = mk_target_data(istr::to_estr(x86::get_data_layout()));
94+
let td = mk_target_data(x86::get_data_layout());
9595
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
9696
// TODO: run the linter here also, once there are llvm-c bindings for
9797
// it.

src/comp/lib/llvm.rs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -899,26 +899,26 @@ native "cdecl" mod llvm = "rustllvm" {
899899

900900
/* Memory-managed object interface to type handles. */
901901

902-
obj type_names(type_names: std::map::hashmap<TypeRef, str>,
902+
obj type_names(type_names: std::map::hashmap<TypeRef, istr>,
903903
named_types: std::map::hashmap<istr, TypeRef>) {
904904

905-
fn associate(s: str, t: TypeRef) {
906-
assert (!named_types.contains_key(istr::from_estr(s)));
905+
fn associate(s: &istr, t: TypeRef) {
906+
assert (!named_types.contains_key(s));
907907
assert (!type_names.contains_key(t));
908908
type_names.insert(t, s);
909-
named_types.insert(istr::from_estr(s), t);
909+
named_types.insert(s, t);
910910
}
911911

912912
fn type_has_name(t: TypeRef) -> bool { ret type_names.contains_key(t); }
913913

914-
fn get_name(t: TypeRef) -> str { ret type_names.get(t); }
914+
fn get_name(t: TypeRef) -> istr { ret type_names.get(t); }
915915

916-
fn name_has_type(s: str) -> bool {
917-
ret named_types.contains_key(istr::from_estr(s));
916+
fn name_has_type(s: &istr) -> bool {
917+
ret named_types.contains_key(s);
918918
}
919919

920-
fn get_type(s: str) -> TypeRef {
921-
ret named_types.get(istr::from_estr(s));
920+
fn get_type(s: &istr) -> TypeRef {
921+
ret named_types.get(s);
922922
}
923923
}
924924

@@ -931,29 +931,30 @@ fn mk_type_names() -> type_names {
931931

932932
let hasher: std::map::hashfn<TypeRef> = hash;
933933
let eqer: std::map::eqfn<TypeRef> = eq;
934-
let tn = std::map::mk_hashmap::<TypeRef, str>(hasher, eqer);
934+
let tn = std::map::mk_hashmap::<TypeRef, istr>(hasher, eqer);
935935

936936
ret type_names(tn, nt);
937937
}
938938

939-
fn type_to_str(names: type_names, ty: TypeRef) -> str {
939+
fn type_to_str(names: type_names, ty: TypeRef) -> istr {
940940
ret type_to_str_inner(names, [], ty);
941941
}
942942

943943
fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
944-
str {
944+
istr {
945945

946946
if names.type_has_name(ty) { ret names.get_name(ty); }
947947

948948
let outer = outer0 + [ty];
949949

950950
let kind: int = llvm::LLVMGetTypeKind(ty);
951951

952-
fn tys_str(names: type_names, outer: &[TypeRef], tys: &[TypeRef]) -> str {
953-
let s: str = "";
952+
fn tys_str(names: type_names, outer: &[TypeRef],
953+
tys: &[TypeRef]) -> istr {
954+
let s: istr = ~"";
954955
let first: bool = true;
955956
for t: TypeRef in tys {
956-
if first { first = false; } else { s += ", "; }
957+
if first { first = false; } else { s += ~", "; }
957958
s += type_to_str_inner(names, outer, t);
958959
}
959960
ret s;
@@ -968,53 +969,53 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
968969
// horrible, horrible. Complete as needed.
969970
970971
0 {
971-
ret "Void";
972+
ret ~"Void";
972973
}
973-
1 { ret "Float"; }
974-
2 { ret "Double"; }
975-
3 { ret "X86_FP80"; }
976-
4 { ret "FP128"; }
977-
5 { ret "PPC_FP128"; }
978-
6 { ret "Label"; }
974+
1 { ret ~"Float"; }
975+
2 { ret ~"Double"; }
976+
3 { ret ~"X86_FP80"; }
977+
4 { ret ~"FP128"; }
978+
5 { ret ~"PPC_FP128"; }
979+
6 { ret ~"Label"; }
979980

980981

981982

982983
7 {
983-
ret "i" + istr::to_estr(std::int::str(
984-
llvm::LLVMGetIntTypeWidth(ty) as int));
984+
ret ~"i" + std::int::str(
985+
llvm::LLVMGetIntTypeWidth(ty) as int);
985986
}
986987

987988

988989

989990
8 {
990-
let s = "fn(";
991+
let s = ~"fn(";
991992
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
992993
let n_args: uint = llvm::LLVMCountParamTypes(ty);
993994
let args: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_args);
994995
llvm::LLVMGetParamTypes(ty, vec::to_ptr(args));
995996
s += tys_str(names, outer, args);
996-
s += ") -> ";
997+
s += ~") -> ";
997998
s += type_to_str_inner(names, outer, out_ty);
998999
ret s;
9991000
}
10001001
10011002
10021003
10031004
9 {
1004-
let s: str = "{";
1005+
let s: istr = ~"{";
10051006
let n_elts: uint = llvm::LLVMCountStructElementTypes(ty);
10061007
let elts: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_elts);
10071008
llvm::LLVMGetStructElementTypes(ty, vec::to_ptr(elts));
10081009
s += tys_str(names, outer, elts);
1009-
s += "}";
1010+
s += ~"}";
10101011
ret s;
10111012
}
10121013
10131014
10141015
10151016
10 {
10161017
let el_ty = llvm::LLVMGetElementType(ty);
1017-
ret "[" + type_to_str_inner(names, outer, el_ty) + "]";
1018+
ret ~"[" + type_to_str_inner(names, outer, el_ty) + ~"]";
10181019
}
10191020

10201021

@@ -1025,20 +1026,20 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
10251026
i += 1u;
10261027
if tout as int == ty as int {
10271028
let n: uint = vec::len::<TypeRef>(outer0) - i;
1028-
ret "*\\" + istr::to_estr(std::int::str(n as int));
1029+
ret ~"*\\" + std::int::str(n as int);
10291030
}
10301031
}
1031-
ret "*" +
1032+
ret ~"*" +
10321033
type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty));
10331034
}
10341035
10351036
10361037
10371038
12 {
1038-
ret "Opaque";
1039+
ret ~"Opaque";
10391040
}
1040-
13 { ret "Vector"; }
1041-
14 { ret "Metadata"; }
1041+
13 { ret ~"Vector"; }
1042+
14 { ret ~"Metadata"; }
10421043
_ { log_err #fmt["unknown TypeKind %d", kind as int]; fail; }
10431044
}
10441045
}
@@ -1068,8 +1069,8 @@ resource target_data_res(TD: TargetDataRef) {
10681069

10691070
type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
10701071

1071-
fn mk_target_data(string_rep: str) -> target_data {
1072-
let lltd = istr::as_buf(istr::from_estr(string_rep), { |buf|
1072+
fn mk_target_data(string_rep: &istr) -> target_data {
1073+
let lltd = istr::as_buf(string_rep, { |buf|
10731074
llvm::LLVMCreateTargetData(buf)
10741075
});
10751076
ret {lltd: lltd, dtor: @target_data_res(lltd)};

src/comp/middle/trans.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6306,7 +6306,7 @@ fn make_common_glue(sess: &session::session, output: &str) {
63066306
let _: () = istr::as_buf(x86::get_target_triple(), { |buf|
63076307
llvm::LLVMSetTarget(llmod, buf)
63086308
});
6309-
mk_target_data(istr::to_estr(x86::get_data_layout()));
6309+
mk_target_data(x86::get_data_layout());
63106310
declare_intrinsics(llmod);
63116311
let _: () = istr::as_buf(x86::get_module_asm(), { |buf|
63126312
llvm::LLVMSetModuleInlineAsm(llmod, buf)
@@ -6411,14 +6411,14 @@ fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
64116411
let _: () = istr::as_buf(x86::get_target_triple(), { |buf|
64126412
llvm::LLVMSetTarget(llmod, buf)
64136413
});
6414-
let td = mk_target_data(istr::to_estr(x86::get_data_layout()));
6414+
let td = mk_target_data(x86::get_data_layout());
64156415
let tn = mk_type_names();
64166416
let intrinsics = declare_intrinsics(llmod);
64176417
let task_type = T_task();
64186418
let taskptr_type = T_ptr(task_type);
6419-
tn.associate("taskptr", taskptr_type);
6419+
tn.associate(~"taskptr", taskptr_type);
64206420
let tydesc_type = T_tydesc(taskptr_type);
6421-
tn.associate("tydesc", tydesc_type);
6421+
tn.associate(~"tydesc", tydesc_type);
64226422
let glues = make_glues(llmod, taskptr_type);
64236423
let hasher = ty::hash_ty;
64246424
let eqer = ty::eq_ty;

src/comp/middle/trans_common.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ fn rslt(bcx: @block_ctxt, val: ValueRef) -> result {
439439
}
440440

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

445445
fn val_ty(v: ValueRef) -> TypeRef { ret llvm::LLVMTypeOf(v); }
@@ -609,23 +609,23 @@ fn T_tydesc_field(cx: &crate_ctxt, field: int) -> TypeRef {
609609
}
610610

611611
fn T_glue_fn(cx: &crate_ctxt) -> TypeRef {
612-
let s = "glue_fn";
612+
let s = ~"glue_fn";
613613
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
614614
let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue);
615615
cx.tn.associate(s, t);
616616
ret t;
617617
}
618618

619619
fn T_cmp_glue_fn(cx: &crate_ctxt) -> TypeRef {
620-
let s = "cmp_glue_fn";
620+
let s = ~"cmp_glue_fn";
621621
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
622622
let t = T_tydesc_field(cx, abi::tydesc_field_cmp_glue);
623623
cx.tn.associate(s, t);
624624
ret t;
625625
}
626626

627627
fn T_copy_glue_fn(cx: &crate_ctxt) -> TypeRef {
628-
let s = "copy_glue_fn";
628+
let s = ~"copy_glue_fn";
629629
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
630630
let t = T_tydesc_field(cx, abi::tydesc_field_copy_glue);
631631
cx.tn.associate(s, t);
@@ -736,7 +736,7 @@ fn T_taskptr(cx: &crate_ctxt) -> TypeRef { ret T_ptr(cx.task_type); }
736736

737737
// This type must never be used directly; it must always be cast away.
738738
fn T_typaram(tn: &type_names) -> TypeRef {
739-
let s = "typaram";
739+
let s = ~"typaram";
740740
if tn.name_has_type(s) { ret tn.get_type(s); }
741741
let t = T_i8();
742742
tn.associate(s, t);
@@ -755,23 +755,23 @@ fn T_closure_ptr(cx: &crate_ctxt, llbindings_ty: TypeRef, n_ty_params: uint)
755755
}
756756

757757
fn T_opaque_closure_ptr(cx: &crate_ctxt) -> TypeRef {
758-
let s = "*closure";
758+
let s = ~"*closure";
759759
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
760760
let t = T_closure_ptr(cx, T_nil(), 0u);
761761
cx.tn.associate(s, t);
762762
ret t;
763763
}
764764

765765
fn T_tag(tn: &type_names, size: uint) -> TypeRef {
766-
let s = "tag_" + istr::to_estr(uint::to_str(size, 10u));
766+
let s = ~"tag_" + uint::to_str(size, 10u);
767767
if tn.name_has_type(s) { ret tn.get_type(s); }
768768
let t = T_struct([T_int(), T_array(T_i8(), size)]);
769769
tn.associate(s, t);
770770
ret t;
771771
}
772772

773773
fn T_opaque_tag(tn: &type_names) -> TypeRef {
774-
let s = "opaque_tag";
774+
let s = ~"opaque_tag";
775775
if tn.name_has_type(s) { ret tn.get_type(s); }
776776
let t = T_struct([T_int(), T_i8()]);
777777
tn.associate(s, t);

0 commit comments

Comments
 (0)