Change calls for TypeName stuff to methods

This commit is contained in:
James Miller 2013-06-15 15:16:03 +12:00
parent 3dbdb3a364
commit b4b2cbb299
13 changed files with 78 additions and 81 deletions

View File

@ -2143,7 +2143,7 @@ impl TypeNames {
}
pub fn find_type(&self, s: &str) -> Option<TypeRef> {
self.named_types.find_equiv(s).map_consume(|x| *x)
self.named_types.find_equiv(&s).map_consume(|x| *x)
}
pub fn type_to_str(&self, ty: TypeRef) -> ~str {
@ -2181,7 +2181,7 @@ impl TypeNames {
}
Struct => {
let tys = struct_tys(ty);
let tys = tys.map(|ty| self.type_to_str(ty)).connect(", ");
let tys = tys.map(|&ty| self.type_to_str(ty)).connect(", ");
fmt!("{%s}", tys)
}
Array => {
@ -2195,9 +2195,16 @@ impl TypeNames {
let el_ty = self.type_to_str(el_ty);
fmt!("*%s", el_ty)
}
_ => fail!("Unknown Type Kind (%u)", kind as uint)
}
}
}
pub fn val_to_str(&self, val: ValueRef) -> ~str {
unsafe {
self.type_to_str(llvm::LLVMTypeOf(val))
}
}
}
pub fn float_width(llt: TypeRef) -> uint {

View File

@ -381,7 +381,7 @@ pub fn expand_nested_bindings<'r>(bcx: block,
bcx.to_str(),
matches_to_str(bcx, m),
col,
bcx.val_str(val));
bcx.val_to_str(val));
let _indenter = indenter();
do m.map |br| {
@ -428,7 +428,7 @@ pub fn enter_match<'r>(bcx: block,
bcx.to_str(),
matches_to_str(bcx, m),
col,
bcx.val_str(val));
bcx.val_to_str(val));
let _indenter = indenter();
let mut result = ~[];
@ -474,7 +474,7 @@ pub fn enter_default<'r>(bcx: block,
bcx.to_str(),
matches_to_str(bcx, m),
col,
bcx.val_str(val));
bcx.val_to_str(val));
let _indenter = indenter();
do enter_match(bcx, dm, m, col, val) |p| {
@ -521,7 +521,7 @@ pub fn enter_opt<'r>(bcx: block,
bcx.to_str(),
matches_to_str(bcx, m),
col,
bcx.val_str(val));
bcx.val_to_str(val));
let _indenter = indenter();
let tcx = bcx.tcx();
@ -632,7 +632,7 @@ pub fn enter_rec_or_struct<'r>(bcx: block,
bcx.to_str(),
matches_to_str(bcx, m),
col,
bcx.val_str(val));
bcx.val_to_str(val));
let _indenter = indenter();
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
@ -667,7 +667,7 @@ pub fn enter_tup<'r>(bcx: block,
bcx.to_str(),
matches_to_str(bcx, m),
col,
bcx.val_str(val));
bcx.val_to_str(val));
let _indenter = indenter();
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
@ -695,7 +695,7 @@ pub fn enter_tuple_struct<'r>(bcx: block,
bcx.to_str(),
matches_to_str(bcx, m),
col,
bcx.val_str(val));
bcx.val_to_str(val));
let _indenter = indenter();
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
@ -720,7 +720,7 @@ pub fn enter_box<'r>(bcx: block,
bcx.to_str(),
matches_to_str(bcx, m),
col,
bcx.val_str(val));
bcx.val_to_str(val));
let _indenter = indenter();
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
@ -747,7 +747,7 @@ pub fn enter_uniq<'r>(bcx: block,
bcx.to_str(),
matches_to_str(bcx, m),
col,
bcx.val_str(val));
bcx.val_to_str(val));
let _indenter = indenter();
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
@ -774,7 +774,7 @@ pub fn enter_region<'r>(bcx: block,
bcx.to_str(),
matches_to_str(bcx, m),
col,
bcx.val_str(val));
bcx.val_to_str(val));
let _indenter = indenter();
let dummy = @ast::pat { id: 0, node: ast::pat_wild, span: dummy_sp() };
@ -1202,9 +1202,7 @@ fn insert_lllocals(bcx: block,
}
};
debug!("binding %? to %s",
binding_info.id,
val_str(bcx.ccx().tn, llval));
debug!("binding %? to %s", binding_info.id, bcx.val_to_str(llval));
llmap.insert(binding_info.id, llval);
}
return bcx;
@ -1221,7 +1219,7 @@ pub fn compile_guard(bcx: block,
bcx.to_str(),
bcx.expr_to_str(guard_expr),
matches_to_str(bcx, m),
vals.map(|v| bcx.val_str(*v)));
vals.map(|v| bcx.val_to_str(*v)));
let _indenter = indenter();
let mut bcx = bcx;
@ -1272,7 +1270,7 @@ pub fn compile_submatch(bcx: block,
debug!("compile_submatch(bcx=%s, m=%s, vals=%?)",
bcx.to_str(),
matches_to_str(bcx, m),
vals.map(|v| bcx.val_str(*v)));
vals.map(|v| bcx.val_to_str(*v)));
let _indenter = indenter();
/*

View File

@ -191,8 +191,8 @@ pub fn Invoke(cx: block,
check_not_terminated(cx);
terminate(cx, "Invoke");
debug!("Invoke(%s with arguments (%s))",
val_str(cx.ccx().tn, Fn),
Args.map(|a| val_str(cx.ccx().tn, *a).to_owned()).connect(", "));
cx.val_to_str(Fn),
Args.map(|a| cx.val_to_str(*a)).connect(", "));
unsafe {
count_insn(cx, "invoke");
llvm::LLVMBuildInvoke(B(cx),
@ -576,8 +576,8 @@ pub fn Store(cx: block, Val: ValueRef, Ptr: ValueRef) {
unsafe {
if cx.unreachable { return; }
debug!("Store %s -> %s",
val_str(cx.ccx().tn, Val),
val_str(cx.ccx().tn, Ptr));
cx.val_to_str(Val),
cx.val_to_str(Ptr));
count_insn(cx, "store");
llvm::LLVMBuildStore(B(cx), Val, Ptr);
}
@ -587,8 +587,8 @@ pub fn AtomicStore(cx: block, Val: ValueRef, Ptr: ValueRef, order: AtomicOrderin
unsafe {
if cx.unreachable { return; }
debug!("Store %s -> %s",
val_str(cx.ccx().tn, Val),
val_str(cx.ccx().tn, Ptr));
cx.val_to_str(Val),
cx.val_to_str(Ptr));
count_insn(cx, "store.atomic");
let align = llalign_of_min(cx.ccx(), cx.ccx().int_type);
llvm::LLVMBuildAtomicStore(B(cx), Val, Ptr, order, align as c_uint);
@ -911,11 +911,11 @@ pub fn InlineAsmCall(cx: block, asm: *c_char, cons: *c_char,
else { lib::llvm::False };
let argtys = do inputs.map |v| {
debug!("Asm Input Type: %?", val_str(cx.ccx().tn, *v));
debug!("Asm Input Type: %?", cx.val_to_str(*v));
val_ty(*v)
};
debug!("Asm Output Type: %?", ty_str(cx.ccx().tn, output));
debug!("Asm Output Type: %?", cx.ccx().tn.type_to_str(output));
let llfty = T_fn(argtys, output);
let v = llvm::LLVMInlineAsm(llfty, asm, cons, volatile,
alignstack, dia as c_uint);
@ -930,8 +930,8 @@ pub fn Call(cx: block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
count_insn(cx, "call");
debug!("Call(Fn=%s, Args=%?)",
val_str(cx.ccx().tn, Fn),
Args.map(|arg| val_str(cx.ccx().tn, *arg)));
cx.val_to_str(Fn),
Args.map(|arg| cx.val_to_str(*arg)));
do vec::as_imm_buf(Args) |ptr, len| {
llvm::LLVMBuildCall(B(cx), Fn, ptr, len as c_uint, noname())

View File

@ -572,9 +572,9 @@ pub fn trans_call_inner(in_cx: block,
// Uncomment this to debug calls.
/*
io::println(fmt!("calling: %s", bcx.val_str(llfn)));
io::println(fmt!("calling: %s", bcx.val_to_str(llfn)));
for llargs.each |llarg| {
io::println(fmt!("arg: %s", bcx.val_str(*llarg)));
io::println(fmt!("arg: %s", bcx.val_to_str(*llarg)));
}
io::println("---");
*/
@ -731,7 +731,7 @@ pub fn trans_arg_expr(bcx: block,
formal_arg_ty.repr(bcx.tcx()),
self_mode,
arg_expr.repr(bcx.tcx()),
ret_flag.map(|v| bcx.val_str(*v)));
ret_flag.map(|v| bcx.val_to_str(*v)));
// translate the arg expr to a datum
let arg_datumblock = match ret_flag {
@ -842,11 +842,11 @@ pub fn trans_arg_expr(bcx: block,
ty::ByCopy => llformal_arg_ty,
};
debug!("casting actual type (%s) to match formal (%s)",
bcx.val_str(val), bcx.llty_str(llformal_arg_ty));
bcx.val_to_str(val), bcx.llty_str(llformal_arg_ty));
val = PointerCast(bcx, val, llformal_arg_ty);
}
}
debug!("--- trans_arg_expr passing %s", val_str(bcx.ccx().tn, val));
debug!("--- trans_arg_expr passing %s", bcx.val_to_str(val));
return rslt(bcx, val);
}

View File

@ -17,7 +17,7 @@ use driver::session;
use driver::session::Session;
use lib::llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef};
use lib::llvm::{True, False, Bool};
use lib::llvm::{llvm, TypeNames, associate_type, name_has_type};
use lib::llvm::{llvm, TypeNames};
use lib;
use middle::trans::base;
use middle::trans::build;
@ -372,7 +372,7 @@ pub fn add_clean(bcx: block, val: ValueRef, t: ty::t) {
if !ty::type_needs_drop(bcx.tcx(), t) { return; }
debug!("add_clean(%s, %s, %s)",
bcx.to_str(),
val_str(bcx.ccx().tn, val),
bcx.val_to_str(val),
t.repr(bcx.tcx()));
let (root, rooted) = root_for_cleanup(bcx, val, t);
let cleanup_type = cleanup_type(bcx.tcx(), t);
@ -387,7 +387,7 @@ pub fn add_clean(bcx: block, val: ValueRef, t: ty::t) {
pub fn add_clean_temp_immediate(cx: block, val: ValueRef, ty: ty::t) {
if !ty::type_needs_drop(cx.tcx(), ty) { return; }
debug!("add_clean_temp_immediate(%s, %s, %s)",
cx.to_str(), val_str(cx.ccx().tn, val),
cx.to_str(), cx.val_to_str(val),
ty.repr(cx.tcx()));
let cleanup_type = cleanup_type(cx.tcx(), ty);
do in_scope_cx(cx) |scope_info| {
@ -400,7 +400,7 @@ pub fn add_clean_temp_immediate(cx: block, val: ValueRef, ty: ty::t) {
pub fn add_clean_temp_mem(bcx: block, val: ValueRef, t: ty::t) {
if !ty::type_needs_drop(bcx.tcx(), t) { return; }
debug!("add_clean_temp_mem(%s, %s, %s)",
bcx.to_str(), val_str(bcx.ccx().tn, val),
bcx.to_str(), bcx.val_to_str(val),
t.repr(bcx.tcx()));
let (root, rooted) = root_for_cleanup(bcx, val, t);
let cleanup_type = cleanup_type(bcx.tcx(), t);
@ -427,8 +427,8 @@ pub fn add_clean_return_to_mut(bcx: block,
debug!("add_clean_return_to_mut(%s, %s, %s)",
bcx.to_str(),
val_str(bcx.ccx().tn, frozen_val_ref),
val_str(bcx.ccx().tn, bits_val_ref));
bcx.val_to_str(frozen_val_ref),
bcx.val_to_str(bits_val_ref));
do in_scope_cx(bcx) |scope_info| {
scope_info.cleanups.push(
clean_temp(
@ -623,20 +623,12 @@ impl Result {
}
}
pub fn ty_str(tn: @TypeNames, t: TypeRef) -> @str {
return lib::llvm::type_to_str(tn, t);
}
pub fn val_ty(v: ValueRef) -> TypeRef {
unsafe {
return llvm::LLVMTypeOf(v);
}
}
pub fn val_str(tn: @TypeNames, v: ValueRef) -> @str {
return ty_str(tn, val_ty(v));
}
pub fn in_scope_cx(cx: block, f: &fn(si: @mut scope_info)) {
let mut cur = cx;
loop {
@ -664,27 +656,27 @@ pub fn block_parent(cx: block) -> block {
// Accessors
impl block_ {
pub fn ccx(@mut self) -> @mut CrateContext { self.fcx.ccx }
pub fn tcx(@mut self) -> ty::ctxt { self.fcx.ccx.tcx }
pub fn sess(@mut self) -> Session { self.fcx.ccx.sess }
pub fn ccx(&self) -> @mut CrateContext { self.fcx.ccx }
pub fn tcx(&self) -> ty::ctxt { self.fcx.ccx.tcx }
pub fn sess(&self) -> Session { self.fcx.ccx.sess }
pub fn node_id_to_str(@mut self, id: ast::node_id) -> ~str {
pub fn node_id_to_str(&self, id: ast::node_id) -> ~str {
ast_map::node_id_to_str(self.tcx().items, id, self.sess().intr())
}
pub fn expr_to_str(@mut self, e: @ast::expr) -> ~str {
pub fn expr_to_str(&self, e: @ast::expr) -> ~str {
e.repr(self.tcx())
}
pub fn expr_is_lval(@mut self, e: @ast::expr) -> bool {
pub fn expr_is_lval(&self, e: @ast::expr) -> bool {
ty::expr_is_lval(self.tcx(), self.ccx().maps.method_map, e)
}
pub fn expr_kind(@mut self, e: @ast::expr) -> ty::ExprKind {
pub fn expr_kind(&self, e: @ast::expr) -> ty::ExprKind {
ty::expr_kind(self.tcx(), self.ccx().maps.method_map, e)
}
pub fn def(@mut self, nid: ast::node_id) -> ast::def {
pub fn def(&self, nid: ast::node_id) -> ast::def {
match self.tcx().def_map.find(&nid) {
Some(&v) => v,
None => {
@ -694,19 +686,19 @@ impl block_ {
}
}
pub fn val_str(@mut self, val: ValueRef) -> @str {
val_str(self.ccx().tn, val)
pub fn val_to_str(&self, val: ValueRef) -> ~str {
self.ccx().tn.val_to_str(val)
}
pub fn llty_str(@mut self, llty: TypeRef) -> @str {
ty_str(self.ccx().tn, llty)
pub fn llty_str(&self, llty: TypeRef) -> ~str {
self.ccx().tn.type_to_str(llty)
}
pub fn ty_to_str(@mut self, t: ty::t) -> ~str {
pub fn ty_to_str(&self, t: ty::t) -> ~str {
t.repr(self.tcx())
}
pub fn to_str(@mut self) -> ~str {
pub fn to_str(&self) -> ~str {
unsafe {
match self.node_info {
Some(node_info) => fmt!("[block %d]", node_info.id),
@ -885,12 +877,12 @@ pub fn T_tydesc_field(cx: &CrateContext, field: uint) -> TypeRef {
pub fn T_generic_glue_fn(cx: &mut CrateContext) -> TypeRef {
let s = @"glue_fn";
match name_has_type(cx.tn, s) {
match cx.tn.find_type(s) {
Some(t) => return t,
_ => ()
}
let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue);
associate_type(cx.tn, s, t);
cx.tn.associate_type(s, t);
return t;
}
@ -1227,7 +1219,7 @@ pub fn const_get_elt(cx: &CrateContext, v: ValueRef, us: &[c_uint])
};
debug!("const_get_elt(v=%s, us=%?, r=%s)",
val_str(cx.tn, v), us, val_str(cx.tn, r));
cx.tn.val_to_str(v), us, cx.tn.val_to_str(r));
return r;
}

View File

@ -14,7 +14,7 @@ use back::{upcall};
use driver::session;
use lib::llvm::{ContextRef, ModuleRef, ValueRef, TypeRef};
use lib::llvm::{llvm, TargetData, TypeNames};
use lib::llvm::{mk_target_data, mk_type_names};
use lib::llvm::{mk_target_data};
use lib;
use metadata::common::LinkMeta;
use middle::astencode;
@ -138,7 +138,7 @@ impl CrateContext {
let targ_cfg = sess.targ_cfg;
let td = mk_target_data(sess.targ_cfg.target_strs.data_layout);
let tn = TypeNames::new();
let mut tn = TypeNames::new();
let mut intrinsics = base::declare_intrinsics(llmod);
if sess.opts.extra_debuginfo {

View File

@ -280,7 +280,7 @@ impl Datum {
}
debug!("copy_to(self=%s, action=%?, dst=%s)",
self.to_str(bcx.ccx()), action, bcx.val_str(dst));
self.to_str(bcx.ccx()), action, bcx.val_to_str(dst));
// Watch out for the case where we are writing the copying the
// value into the same location we read it out from. We want
@ -345,7 +345,7 @@ impl Datum {
let mut bcx = bcx;
debug!("move_to(self=%s, action=%?, dst=%s)",
self.to_str(bcx.ccx()), action, bcx.val_str(dst));
self.to_str(bcx.ccx()), action, bcx.val_to_str(dst));
if ty::type_is_nil(self.ty) || ty::type_is_bot(self.ty) {
return bcx;
@ -409,7 +409,7 @@ impl Datum {
pub fn to_str(&self, ccx: &CrateContext) -> ~str {
fmt!("Datum { val=%s, ty=%s, mode=%? }",
val_str(ccx.tn, self.val),
ccx.tn.val_to_str(self.val),
ty_to_str(ccx.tcx, self.ty),
self.mode)
}

View File

@ -173,7 +173,7 @@ pub enum Dest {
impl Dest {
pub fn to_str(&self, ccx: &CrateContext) -> ~str {
match *self {
SaveIn(v) => fmt!("SaveIn(%s)", val_str(ccx.tn, v)),
SaveIn(v) => fmt!("SaveIn(%s)", ccx.tn.val_to_str(v)),
Ignore => ~"Ignore"
}
}
@ -914,8 +914,8 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
len = Sub(bcx, len, C_uint(bcx.ccx(), 1u));
}
debug!("trans_index: base %s", val_str(bcx.ccx().tn, base));
debug!("trans_index: len %s", val_str(bcx.ccx().tn, len));
debug!("trans_index: base %s", bcx.val_to_str(base));
debug!("trans_index: len %s", bcx.val_to_str(len));
let bounds_check = ICmp(bcx, lib::llvm::IntUGE, scaled_ix, len);
let bcx = do with_cond(bcx, bounds_check) |bcx| {
@ -1081,7 +1081,7 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum {
};
let ty = node_id_type(bcx, nid);
debug!("take_local(nid=%?, v=%s, ty=%s)",
nid, bcx.val_str(v), bcx.ty_to_str(ty));
nid, bcx.val_to_str(v), bcx.ty_to_str(ty));
Datum {
val: v,
ty: ty,

View File

@ -140,7 +140,7 @@ pub fn static_size_of_enum(cx: &mut CrateContext, t: ty::t) -> uint {
debug!("static_size_of_enum: variant %s type %s",
cx.tcx.sess.str_of(variant.name),
ty_str(cx.tn, T_struct(lltypes, false)));
cx.tn.type_to_str(T_struct(lltypes, false)));
let this_size = llsize_of_real(cx, T_struct(lltypes, false));
if max_size < this_size {

View File

@ -623,7 +623,7 @@ pub fn trans_trait_callee_from_llval(bcx: block,
// Load the vtable from the @Trait pair
debug!("(translating trait callee) loading vtable from pair %s",
val_str(bcx.ccx().tn, llpair));
bcx.val_to_str(llpair));
let llvtable = Load(bcx,
PointerCast(bcx,
GEPi(bcx, llpair,

View File

@ -96,7 +96,7 @@ impl Reflector {
debug!("passing %u args:", args.len());
let bcx = self.bcx;
for args.iter().enumerate().advance |(i, a)| {
debug!("arg %u: %s", i, val_str(bcx.ccx().tn, *a));
debug!("arg %u: %s", i, bcx.val_to_str(*a));
}
let bool_ty = ty::mk_bool();
let scratch = scratch_datum(bcx, bool_ty, false);

View File

@ -155,8 +155,8 @@ impl VecTypes {
fmt!("VecTypes {vec_ty=%s, unit_ty=%s, llunit_ty=%s, llunit_size=%s}",
ty_to_str(ccx.tcx, self.vec_ty),
ty_to_str(ccx.tcx, self.unit_ty),
ty_str(ccx.tn, self.llunit_ty),
val_str(ccx.tn, self.llunit_size))
ccx.tn.type_to_str(self.llunit_ty),
ccx.tn.val_to_str(self.llunit_size))
}
}
@ -336,7 +336,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block,
let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val));
debug!("alloc_vec() returned val=%s, dataptr=%s",
bcx.val_str(val), bcx.val_str(dataptr));
bcx.val_to_str(val), bcx.val_to_str(dataptr));
let bcx = write_content(bcx, &vt, vstore_expr,
content_expr, SaveIn(dataptr));
@ -389,7 +389,7 @@ pub fn write_content(bcx: block,
for elements.iter().enumerate().advance |(i, element)| {
let lleltptr = GEPi(bcx, lldest, [i]);
debug!("writing index %? with lleltptr=%?",
i, bcx.val_str(lleltptr));
i, bcx.val_to_str(lleltptr));
bcx = expr::trans_into(bcx, *element,
SaveIn(lleltptr));
add_clean_temp_mem(bcx, lleltptr, vt.unit_ty);

View File

@ -64,8 +64,8 @@ pub fn return_to_mut(mut bcx: block,
debug!("write_guard::return_to_mut(root_key=%?, %s, %s, %s)",
root_key,
bcx.to_str(),
val_str(bcx.ccx().tn, frozen_val_ref),
val_str(bcx.ccx().tn, bits_val_ref));
bcx.val_to_str(frozen_val_ref),
bcx.val_to_str(bits_val_ref));
let box_ptr =
Load(bcx, PointerCast(bcx,