Convert the rest of rustc::lib::llvm to istrs. Issue #855

This commit is contained in:
Brian Anderson 2011-08-26 16:33:30 -07:00
parent d7fa75413f
commit fcdbdaf2ab
4 changed files with 50 additions and 49 deletions

View File

@ -91,7 +91,7 @@ mod write {
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
link_intrinsics(sess, llmod);
let pm = mk_pass_manager();
let td = mk_target_data(istr::to_estr(x86::get_data_layout()));
let td = mk_target_data(x86::get_data_layout());
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
// TODO: run the linter here also, once there are llvm-c bindings for
// it.

View File

@ -899,26 +899,26 @@ native "cdecl" mod llvm = "rustllvm" {
/* Memory-managed object interface to type handles. */
obj type_names(type_names: std::map::hashmap<TypeRef, str>,
obj type_names(type_names: std::map::hashmap<TypeRef, istr>,
named_types: std::map::hashmap<istr, TypeRef>) {
fn associate(s: str, t: TypeRef) {
assert (!named_types.contains_key(istr::from_estr(s)));
fn associate(s: &istr, t: TypeRef) {
assert (!named_types.contains_key(s));
assert (!type_names.contains_key(t));
type_names.insert(t, s);
named_types.insert(istr::from_estr(s), t);
named_types.insert(s, t);
}
fn type_has_name(t: TypeRef) -> bool { ret type_names.contains_key(t); }
fn get_name(t: TypeRef) -> str { ret type_names.get(t); }
fn get_name(t: TypeRef) -> istr { ret type_names.get(t); }
fn name_has_type(s: str) -> bool {
ret named_types.contains_key(istr::from_estr(s));
fn name_has_type(s: &istr) -> bool {
ret named_types.contains_key(s);
}
fn get_type(s: str) -> TypeRef {
ret named_types.get(istr::from_estr(s));
fn get_type(s: &istr) -> TypeRef {
ret named_types.get(s);
}
}
@ -931,17 +931,17 @@ fn mk_type_names() -> type_names {
let hasher: std::map::hashfn<TypeRef> = hash;
let eqer: std::map::eqfn<TypeRef> = eq;
let tn = std::map::mk_hashmap::<TypeRef, str>(hasher, eqer);
let tn = std::map::mk_hashmap::<TypeRef, istr>(hasher, eqer);
ret type_names(tn, nt);
}
fn type_to_str(names: type_names, ty: TypeRef) -> str {
fn type_to_str(names: type_names, ty: TypeRef) -> istr {
ret type_to_str_inner(names, [], ty);
}
fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
str {
istr {
if names.type_has_name(ty) { ret names.get_name(ty); }
@ -949,11 +949,12 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
let kind: int = llvm::LLVMGetTypeKind(ty);
fn tys_str(names: type_names, outer: &[TypeRef], tys: &[TypeRef]) -> str {
let s: str = "";
fn tys_str(names: type_names, outer: &[TypeRef],
tys: &[TypeRef]) -> istr {
let s: istr = ~"";
let first: bool = true;
for t: TypeRef in tys {
if first { first = false; } else { s += ", "; }
if first { first = false; } else { s += ~", "; }
s += type_to_str_inner(names, outer, t);
}
ret s;
@ -968,32 +969,32 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
// horrible, horrible. Complete as needed.
0 {
ret "Void";
ret ~"Void";
}
1 { ret "Float"; }
2 { ret "Double"; }
3 { ret "X86_FP80"; }
4 { ret "FP128"; }
5 { ret "PPC_FP128"; }
6 { ret "Label"; }
1 { ret ~"Float"; }
2 { ret ~"Double"; }
3 { ret ~"X86_FP80"; }
4 { ret ~"FP128"; }
5 { ret ~"PPC_FP128"; }
6 { ret ~"Label"; }
7 {
ret "i" + istr::to_estr(std::int::str(
llvm::LLVMGetIntTypeWidth(ty) as int));
ret ~"i" + std::int::str(
llvm::LLVMGetIntTypeWidth(ty) as int);
}
8 {
let s = "fn(";
let s = ~"fn(";
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
let n_args: uint = llvm::LLVMCountParamTypes(ty);
let args: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_args);
llvm::LLVMGetParamTypes(ty, vec::to_ptr(args));
s += tys_str(names, outer, args);
s += ") -> ";
s += ~") -> ";
s += type_to_str_inner(names, outer, out_ty);
ret s;
}
@ -1001,12 +1002,12 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
9 {
let s: str = "{";
let s: istr = ~"{";
let n_elts: uint = llvm::LLVMCountStructElementTypes(ty);
let elts: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_elts);
llvm::LLVMGetStructElementTypes(ty, vec::to_ptr(elts));
s += tys_str(names, outer, elts);
s += "}";
s += ~"}";
ret s;
}
@ -1014,7 +1015,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
10 {
let el_ty = llvm::LLVMGetElementType(ty);
ret "[" + type_to_str_inner(names, outer, el_ty) + "]";
ret ~"[" + type_to_str_inner(names, outer, el_ty) + ~"]";
}
@ -1025,20 +1026,20 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
i += 1u;
if tout as int == ty as int {
let n: uint = vec::len::<TypeRef>(outer0) - i;
ret "*\\" + istr::to_estr(std::int::str(n as int));
ret ~"*\\" + std::int::str(n as int);
}
}
ret "*" +
ret ~"*" +
type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty));
}
12 {
ret "Opaque";
ret ~"Opaque";
}
13 { ret "Vector"; }
14 { ret "Metadata"; }
13 { ret ~"Vector"; }
14 { ret ~"Metadata"; }
_ { log_err #fmt["unknown TypeKind %d", kind as int]; fail; }
}
}
@ -1068,8 +1069,8 @@ resource target_data_res(TD: TargetDataRef) {
type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
fn mk_target_data(string_rep: str) -> target_data {
let lltd = istr::as_buf(istr::from_estr(string_rep), { |buf|
fn mk_target_data(string_rep: &istr) -> target_data {
let lltd = istr::as_buf(string_rep, { |buf|
llvm::LLVMCreateTargetData(buf)
});
ret {lltd: lltd, dtor: @target_data_res(lltd)};

View File

@ -6306,7 +6306,7 @@ fn make_common_glue(sess: &session::session, output: &str) {
let _: () = istr::as_buf(x86::get_target_triple(), { |buf|
llvm::LLVMSetTarget(llmod, buf)
});
mk_target_data(istr::to_estr(x86::get_data_layout()));
mk_target_data(x86::get_data_layout());
declare_intrinsics(llmod);
let _: () = istr::as_buf(x86::get_module_asm(), { |buf|
llvm::LLVMSetModuleInlineAsm(llmod, buf)
@ -6411,14 +6411,14 @@ fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
let _: () = istr::as_buf(x86::get_target_triple(), { |buf|
llvm::LLVMSetTarget(llmod, buf)
});
let td = mk_target_data(istr::to_estr(x86::get_data_layout()));
let td = mk_target_data(x86::get_data_layout());
let tn = mk_type_names();
let intrinsics = declare_intrinsics(llmod);
let task_type = T_task();
let taskptr_type = T_ptr(task_type);
tn.associate("taskptr", taskptr_type);
tn.associate(~"taskptr", taskptr_type);
let tydesc_type = T_tydesc(taskptr_type);
tn.associate("tydesc", tydesc_type);
tn.associate(~"tydesc", tydesc_type);
let glues = make_glues(llmod, taskptr_type);
let hasher = ty::hash_ty;
let eqer = ty::eq_ty;

View File

@ -439,7 +439,7 @@ fn rslt(bcx: @block_ctxt, val: ValueRef) -> result {
}
fn ty_str(tn: type_names, t: TypeRef) -> str {
ret lib::llvm::type_to_str(tn, t);
ret istr::to_estr(lib::llvm::type_to_str(tn, t));
}
fn val_ty(v: ValueRef) -> TypeRef { ret llvm::LLVMTypeOf(v); }
@ -609,7 +609,7 @@ fn T_tydesc_field(cx: &crate_ctxt, field: int) -> TypeRef {
}
fn T_glue_fn(cx: &crate_ctxt) -> TypeRef {
let s = "glue_fn";
let s = ~"glue_fn";
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue);
cx.tn.associate(s, t);
@ -617,7 +617,7 @@ fn T_glue_fn(cx: &crate_ctxt) -> TypeRef {
}
fn T_cmp_glue_fn(cx: &crate_ctxt) -> TypeRef {
let s = "cmp_glue_fn";
let s = ~"cmp_glue_fn";
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
let t = T_tydesc_field(cx, abi::tydesc_field_cmp_glue);
cx.tn.associate(s, t);
@ -625,7 +625,7 @@ fn T_cmp_glue_fn(cx: &crate_ctxt) -> TypeRef {
}
fn T_copy_glue_fn(cx: &crate_ctxt) -> TypeRef {
let s = "copy_glue_fn";
let s = ~"copy_glue_fn";
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
let t = T_tydesc_field(cx, abi::tydesc_field_copy_glue);
cx.tn.associate(s, t);
@ -736,7 +736,7 @@ fn T_taskptr(cx: &crate_ctxt) -> TypeRef { ret T_ptr(cx.task_type); }
// This type must never be used directly; it must always be cast away.
fn T_typaram(tn: &type_names) -> TypeRef {
let s = "typaram";
let s = ~"typaram";
if tn.name_has_type(s) { ret tn.get_type(s); }
let t = T_i8();
tn.associate(s, t);
@ -755,7 +755,7 @@ fn T_closure_ptr(cx: &crate_ctxt, llbindings_ty: TypeRef, n_ty_params: uint)
}
fn T_opaque_closure_ptr(cx: &crate_ctxt) -> TypeRef {
let s = "*closure";
let s = ~"*closure";
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
let t = T_closure_ptr(cx, T_nil(), 0u);
cx.tn.associate(s, t);
@ -763,7 +763,7 @@ fn T_opaque_closure_ptr(cx: &crate_ctxt) -> TypeRef {
}
fn T_tag(tn: &type_names, size: uint) -> TypeRef {
let s = "tag_" + istr::to_estr(uint::to_str(size, 10u));
let s = ~"tag_" + uint::to_str(size, 10u);
if tn.name_has_type(s) { ret tn.get_type(s); }
let t = T_struct([T_int(), T_array(T_i8(), size)]);
tn.associate(s, t);
@ -771,7 +771,7 @@ fn T_tag(tn: &type_names, size: uint) -> TypeRef {
}
fn T_opaque_tag(tn: &type_names) -> TypeRef {
let s = "opaque_tag";
let s = ~"opaque_tag";
if tn.name_has_type(s) { ret tn.get_type(s); }
let t = T_struct([T_int(), T_i8()]);
tn.associate(s, t);