Convert the rest of rustc::lib::llvm to istrs. Issue #855
This commit is contained in:
@@ -91,7 +91,7 @@ mod write {
|
|||||||
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
|
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
|
||||||
link_intrinsics(sess, llmod);
|
link_intrinsics(sess, llmod);
|
||||||
let pm = mk_pass_manager();
|
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);
|
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
|
||||||
// TODO: run the linter here also, once there are llvm-c bindings for
|
// TODO: run the linter here also, once there are llvm-c bindings for
|
||||||
// it.
|
// it.
|
||||||
|
|||||||
@@ -899,26 +899,26 @@ native "cdecl" mod llvm = "rustllvm" {
|
|||||||
|
|
||||||
/* Memory-managed object interface to type handles. */
|
/* 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>) {
|
named_types: std::map::hashmap<istr, TypeRef>) {
|
||||||
|
|
||||||
fn associate(s: str, t: TypeRef) {
|
fn associate(s: &istr, t: TypeRef) {
|
||||||
assert (!named_types.contains_key(istr::from_estr(s)));
|
assert (!named_types.contains_key(s));
|
||||||
assert (!type_names.contains_key(t));
|
assert (!type_names.contains_key(t));
|
||||||
type_names.insert(t, s);
|
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 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 {
|
fn name_has_type(s: &istr) -> bool {
|
||||||
ret named_types.contains_key(istr::from_estr(s));
|
ret named_types.contains_key(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_type(s: str) -> TypeRef {
|
fn get_type(s: &istr) -> TypeRef {
|
||||||
ret named_types.get(istr::from_estr(s));
|
ret named_types.get(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -931,17 +931,17 @@ fn mk_type_names() -> type_names {
|
|||||||
|
|
||||||
let hasher: std::map::hashfn<TypeRef> = hash;
|
let hasher: std::map::hashfn<TypeRef> = hash;
|
||||||
let eqer: std::map::eqfn<TypeRef> = eq;
|
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);
|
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);
|
ret type_to_str_inner(names, [], ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
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); }
|
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);
|
let kind: int = llvm::LLVMGetTypeKind(ty);
|
||||||
|
|
||||||
fn tys_str(names: type_names, outer: &[TypeRef], tys: &[TypeRef]) -> str {
|
fn tys_str(names: type_names, outer: &[TypeRef],
|
||||||
let s: str = "";
|
tys: &[TypeRef]) -> istr {
|
||||||
|
let s: istr = ~"";
|
||||||
let first: bool = true;
|
let first: bool = true;
|
||||||
for t: TypeRef in tys {
|
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);
|
s += type_to_str_inner(names, outer, t);
|
||||||
}
|
}
|
||||||
ret s;
|
ret s;
|
||||||
@@ -968,32 +969,32 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||||||
// horrible, horrible. Complete as needed.
|
// horrible, horrible. Complete as needed.
|
||||||
|
|
||||||
0 {
|
0 {
|
||||||
ret "Void";
|
ret ~"Void";
|
||||||
}
|
}
|
||||||
1 { ret "Float"; }
|
1 { ret ~"Float"; }
|
||||||
2 { ret "Double"; }
|
2 { ret ~"Double"; }
|
||||||
3 { ret "X86_FP80"; }
|
3 { ret ~"X86_FP80"; }
|
||||||
4 { ret "FP128"; }
|
4 { ret ~"FP128"; }
|
||||||
5 { ret "PPC_FP128"; }
|
5 { ret ~"PPC_FP128"; }
|
||||||
6 { ret "Label"; }
|
6 { ret ~"Label"; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
7 {
|
7 {
|
||||||
ret "i" + istr::to_estr(std::int::str(
|
ret ~"i" + std::int::str(
|
||||||
llvm::LLVMGetIntTypeWidth(ty) as int));
|
llvm::LLVMGetIntTypeWidth(ty) as int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
8 {
|
8 {
|
||||||
let s = "fn(";
|
let s = ~"fn(";
|
||||||
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
|
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
|
||||||
let n_args: uint = llvm::LLVMCountParamTypes(ty);
|
let n_args: uint = llvm::LLVMCountParamTypes(ty);
|
||||||
let args: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_args);
|
let args: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_args);
|
||||||
llvm::LLVMGetParamTypes(ty, vec::to_ptr(args));
|
llvm::LLVMGetParamTypes(ty, vec::to_ptr(args));
|
||||||
s += tys_str(names, outer, args);
|
s += tys_str(names, outer, args);
|
||||||
s += ") -> ";
|
s += ~") -> ";
|
||||||
s += type_to_str_inner(names, outer, out_ty);
|
s += type_to_str_inner(names, outer, out_ty);
|
||||||
ret s;
|
ret s;
|
||||||
}
|
}
|
||||||
@@ -1001,12 +1002,12 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||||||
|
|
||||||
|
|
||||||
9 {
|
9 {
|
||||||
let s: str = "{";
|
let s: istr = ~"{";
|
||||||
let n_elts: uint = llvm::LLVMCountStructElementTypes(ty);
|
let n_elts: uint = llvm::LLVMCountStructElementTypes(ty);
|
||||||
let elts: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_elts);
|
let elts: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_elts);
|
||||||
llvm::LLVMGetStructElementTypes(ty, vec::to_ptr(elts));
|
llvm::LLVMGetStructElementTypes(ty, vec::to_ptr(elts));
|
||||||
s += tys_str(names, outer, elts);
|
s += tys_str(names, outer, elts);
|
||||||
s += "}";
|
s += ~"}";
|
||||||
ret s;
|
ret s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1014,7 +1015,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) ->
|
|||||||
|
|
||||||
10 {
|
10 {
|
||||||
let el_ty = llvm::LLVMGetElementType(ty);
|
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;
|
i += 1u;
|
||||||
if tout as int == ty as int {
|
if tout as int == ty as int {
|
||||||
let n: uint = vec::len::<TypeRef>(outer0) - i;
|
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));
|
type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
12 {
|
12 {
|
||||||
ret "Opaque";
|
ret ~"Opaque";
|
||||||
}
|
}
|
||||||
13 { ret "Vector"; }
|
13 { ret ~"Vector"; }
|
||||||
14 { ret "Metadata"; }
|
14 { ret ~"Metadata"; }
|
||||||
_ { log_err #fmt["unknown TypeKind %d", kind as int]; fail; }
|
_ { 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};
|
type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
|
||||||
|
|
||||||
fn mk_target_data(string_rep: str) -> target_data {
|
fn mk_target_data(string_rep: &istr) -> target_data {
|
||||||
let lltd = istr::as_buf(istr::from_estr(string_rep), { |buf|
|
let lltd = istr::as_buf(string_rep, { |buf|
|
||||||
llvm::LLVMCreateTargetData(buf)
|
llvm::LLVMCreateTargetData(buf)
|
||||||
});
|
});
|
||||||
ret {lltd: lltd, dtor: @target_data_res(lltd)};
|
ret {lltd: lltd, dtor: @target_data_res(lltd)};
|
||||||
|
|||||||
@@ -6306,7 +6306,7 @@ fn make_common_glue(sess: &session::session, output: &str) {
|
|||||||
let _: () = istr::as_buf(x86::get_target_triple(), { |buf|
|
let _: () = istr::as_buf(x86::get_target_triple(), { |buf|
|
||||||
llvm::LLVMSetTarget(llmod, 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);
|
declare_intrinsics(llmod);
|
||||||
let _: () = istr::as_buf(x86::get_module_asm(), { |buf|
|
let _: () = istr::as_buf(x86::get_module_asm(), { |buf|
|
||||||
llvm::LLVMSetModuleInlineAsm(llmod, 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|
|
let _: () = istr::as_buf(x86::get_target_triple(), { |buf|
|
||||||
llvm::LLVMSetTarget(llmod, 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 tn = mk_type_names();
|
||||||
let intrinsics = declare_intrinsics(llmod);
|
let intrinsics = declare_intrinsics(llmod);
|
||||||
let task_type = T_task();
|
let task_type = T_task();
|
||||||
let taskptr_type = T_ptr(task_type);
|
let taskptr_type = T_ptr(task_type);
|
||||||
tn.associate("taskptr", taskptr_type);
|
tn.associate(~"taskptr", taskptr_type);
|
||||||
let tydesc_type = T_tydesc(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 glues = make_glues(llmod, taskptr_type);
|
||||||
let hasher = ty::hash_ty;
|
let hasher = ty::hash_ty;
|
||||||
let eqer = ty::eq_ty;
|
let eqer = ty::eq_ty;
|
||||||
|
|||||||
@@ -439,7 +439,7 @@ fn rslt(bcx: @block_ctxt, val: ValueRef) -> result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ty_str(tn: type_names, t: TypeRef) -> str {
|
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); }
|
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 {
|
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); }
|
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
|
||||||
let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue);
|
let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue);
|
||||||
cx.tn.associate(s, t);
|
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 {
|
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); }
|
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
|
||||||
let t = T_tydesc_field(cx, abi::tydesc_field_cmp_glue);
|
let t = T_tydesc_field(cx, abi::tydesc_field_cmp_glue);
|
||||||
cx.tn.associate(s, t);
|
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 {
|
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); }
|
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
|
||||||
let t = T_tydesc_field(cx, abi::tydesc_field_copy_glue);
|
let t = T_tydesc_field(cx, abi::tydesc_field_copy_glue);
|
||||||
cx.tn.associate(s, t);
|
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.
|
// This type must never be used directly; it must always be cast away.
|
||||||
fn T_typaram(tn: &type_names) -> TypeRef {
|
fn T_typaram(tn: &type_names) -> TypeRef {
|
||||||
let s = "typaram";
|
let s = ~"typaram";
|
||||||
if tn.name_has_type(s) { ret tn.get_type(s); }
|
if tn.name_has_type(s) { ret tn.get_type(s); }
|
||||||
let t = T_i8();
|
let t = T_i8();
|
||||||
tn.associate(s, t);
|
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 {
|
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); }
|
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
|
||||||
let t = T_closure_ptr(cx, T_nil(), 0u);
|
let t = T_closure_ptr(cx, T_nil(), 0u);
|
||||||
cx.tn.associate(s, t);
|
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 {
|
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); }
|
if tn.name_has_type(s) { ret tn.get_type(s); }
|
||||||
let t = T_struct([T_int(), T_array(T_i8(), size)]);
|
let t = T_struct([T_int(), T_array(T_i8(), size)]);
|
||||||
tn.associate(s, t);
|
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 {
|
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); }
|
if tn.name_has_type(s) { ret tn.get_type(s); }
|
||||||
let t = T_struct([T_int(), T_i8()]);
|
let t = T_struct([T_int(), T_i8()]);
|
||||||
tn.associate(s, t);
|
tn.associate(s, t);
|
||||||
|
|||||||
Reference in New Issue
Block a user