trans: Use fmt::Debug for debugging instead of ad-hoc methods.

This commit is contained in:
Eduard Burtescu 2016-02-18 19:49:45 +02:00
parent abb1515c53
commit b47fcb8375
29 changed files with 280 additions and 392 deletions

View file

@ -133,6 +133,7 @@ pub enum DLLStorageClassTypes {
} }
bitflags! { bitflags! {
#[derive(Debug)]
flags Attribute : u64 { flags Attribute : u64 {
const ZExt = 1 << 0, const ZExt = 1 << 0,
const SExt = 1 << 1, const SExt = 1 << 1,

View file

@ -216,6 +216,7 @@ use trans::monomorphize;
use trans::tvec; use trans::tvec;
use trans::type_of; use trans::type_of;
use trans::Disr; use trans::Disr;
use trans::value::Value;
use middle::ty::{self, Ty, TyCtxt}; use middle::ty::{self, Ty, TyCtxt};
use middle::traits::ProjectionMode; use middle::traits::ProjectionMode;
use session::config::NoDebugInfo; use session::config::NoDebugInfo;
@ -448,6 +449,12 @@ impl<'tcx> Datum<'tcx, Lvalue> {
} }
} }
impl fmt::Debug for MatchInput {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&Value(self.val), f)
}
}
impl MatchInput { impl MatchInput {
fn from_val(val: ValueRef) -> MatchInput { fn from_val(val: ValueRef) -> MatchInput {
MatchInput { MatchInput {
@ -466,11 +473,8 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
col: usize, col: usize,
val: MatchInput) val: MatchInput)
-> Vec<Match<'a, 'p, 'blk, 'tcx>> { -> Vec<Match<'a, 'p, 'blk, 'tcx>> {
debug!("expand_nested_bindings(bcx={}, m={:?}, col={}, val={})", debug!("expand_nested_bindings(bcx={}, m={:?}, col={}, val={:?})",
bcx.to_str(), bcx.to_str(), m, col, val);
m,
col,
bcx.val_to_string(val.val));
let _indenter = indenter(); let _indenter = indenter();
m.iter().map(|br| { m.iter().map(|br| {
@ -506,11 +510,8 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
-> Vec<Match<'a, 'p, 'blk, 'tcx>> where -> Vec<Match<'a, 'p, 'blk, 'tcx>> where
F: FnMut(&[&'p hir::Pat]) -> Option<Vec<&'p hir::Pat>>, F: FnMut(&[&'p hir::Pat]) -> Option<Vec<&'p hir::Pat>>,
{ {
debug!("enter_match(bcx={}, m={:?}, col={}, val={})", debug!("enter_match(bcx={}, m={:?}, col={}, val={:?})",
bcx.to_str(), bcx.to_str(), m, col, val);
m,
col,
bcx.val_to_string(val.val));
let _indenter = indenter(); let _indenter = indenter();
m.iter().filter_map(|br| { m.iter().filter_map(|br| {
@ -549,11 +550,8 @@ fn enter_default<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
col: usize, col: usize,
val: MatchInput) val: MatchInput)
-> Vec<Match<'a, 'p, 'blk, 'tcx>> { -> Vec<Match<'a, 'p, 'blk, 'tcx>> {
debug!("enter_default(bcx={}, m={:?}, col={}, val={})", debug!("enter_default(bcx={}, m={:?}, col={}, val={:?})",
bcx.to_str(), bcx.to_str(), m, col, val);
m,
col,
bcx.val_to_string(val.val));
let _indenter = indenter(); let _indenter = indenter();
// Collect all of the matches that can match against anything. // Collect all of the matches that can match against anything.
@ -606,12 +604,8 @@ fn enter_opt<'a, 'p, 'blk, 'tcx>(
variant_size: usize, variant_size: usize,
val: MatchInput) val: MatchInput)
-> Vec<Match<'a, 'p, 'blk, 'tcx>> { -> Vec<Match<'a, 'p, 'blk, 'tcx>> {
debug!("enter_opt(bcx={}, m={:?}, opt={:?}, col={}, val={})", debug!("enter_opt(bcx={}, m={:?}, opt={:?}, col={}, val={:?})",
bcx.to_str(), bcx.to_str(), m, *opt, col, val);
m,
*opt,
col,
bcx.val_to_string(val.val));
let _indenter = indenter(); let _indenter = indenter();
let ctor = match opt { let ctor = match opt {
@ -1032,7 +1026,7 @@ fn insert_lllocals<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
bcx.fcx.schedule_drop_and_fill_mem(cs, llval, binding_info.ty, opt_datum); bcx.fcx.schedule_drop_and_fill_mem(cs, llval, binding_info.ty, opt_datum);
} }
debug!("binding {} to {}", binding_info.id, bcx.val_to_string(llval)); debug!("binding {} to {:?}", binding_info.id, Value(llval));
bcx.fcx.lllocals.borrow_mut().insert(binding_info.id, datum); bcx.fcx.lllocals.borrow_mut().insert(binding_info.id, datum);
debuginfo::create_match_binding_metadata(bcx, name, binding_info); debuginfo::create_match_binding_metadata(bcx, name, binding_info);
} }
@ -1047,11 +1041,8 @@ fn compile_guard<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
chk: &FailureHandler, chk: &FailureHandler,
has_genuine_default: bool) has_genuine_default: bool)
-> Block<'blk, 'tcx> { -> Block<'blk, 'tcx> {
debug!("compile_guard(bcx={}, guard_expr={:?}, m={:?}, vals=[{}])", debug!("compile_guard(bcx={}, guard_expr={:?}, m={:?}, vals={:?})",
bcx.to_str(), bcx.to_str(), guard_expr, m, vals);
guard_expr,
m,
vals.iter().map(|v| bcx.val_to_string(v.val)).collect::<Vec<_>>().join(", "));
let _indenter = indenter(); let _indenter = indenter();
let mut bcx = insert_lllocals(bcx, &data.bindings_map, None); let mut bcx = insert_lllocals(bcx, &data.bindings_map, None);
@ -1093,10 +1084,8 @@ fn compile_submatch<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
vals: &[MatchInput], vals: &[MatchInput],
chk: &FailureHandler, chk: &FailureHandler,
has_genuine_default: bool) { has_genuine_default: bool) {
debug!("compile_submatch(bcx={}, m={:?}, vals=[{}])", debug!("compile_submatch(bcx={}, m={:?}, vals=[{:?}])",
bcx.to_str(), bcx.to_str(), m, vals);
m,
vals.iter().map(|v| bcx.val_to_string(v.val)).collect::<Vec<_>>().join(", "));
let _indenter = indenter(); let _indenter = indenter();
let _icx = push_ctxt("match::compile_submatch"); let _icx = push_ctxt("match::compile_submatch");
let mut bcx = bcx; let mut bcx = bcx;
@ -1256,7 +1245,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
debug!("options={:?}", opts); debug!("options={:?}", opts);
let mut kind = NoBranch; let mut kind = NoBranch;
let mut test_val = val.val; let mut test_val = val.val;
debug!("test_val={}", bcx.val_to_string(test_val)); debug!("test_val={:?}", Value(test_val));
if !opts.is_empty() { if !opts.is_empty() {
match opts[0] { match opts[0] {
ConstantValue(..) | ConstantRange(..) => { ConstantValue(..) | ConstantRange(..) => {
@ -1761,8 +1750,8 @@ fn mk_binding_alloca<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>,
let lvalue = Lvalue::new_with_hint(caller_name, bcx, p_id, HintKind::DontZeroJustUse); let lvalue = Lvalue::new_with_hint(caller_name, bcx, p_id, HintKind::DontZeroJustUse);
let datum = Datum::new(llval, var_ty, lvalue); let datum = Datum::new(llval, var_ty, lvalue);
debug!("mk_binding_alloca cleanup_scope={:?} llval={} var_ty={:?}", debug!("mk_binding_alloca cleanup_scope={:?} llval={:?} var_ty={:?}",
cleanup_scope, bcx.ccx().tn().val_to_string(llval), var_ty); cleanup_scope, Value(llval), var_ty);
// Subtle: be sure that we *populate* the memory *before* // Subtle: be sure that we *populate* the memory *before*
// we schedule the cleanup. // we schedule the cleanup.
@ -1794,10 +1783,8 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
val: MatchInput, val: MatchInput,
cleanup_scope: cleanup::ScopeId) cleanup_scope: cleanup::ScopeId)
-> Block<'blk, 'tcx> { -> Block<'blk, 'tcx> {
debug!("bind_irrefutable_pat(bcx={}, pat={:?}, val={})", debug!("bind_irrefutable_pat(bcx={}, pat={:?}, val={:?})",
bcx.to_str(), bcx.to_str(), pat, val);
pat,
bcx.val_to_string(val.val));
if bcx.sess().asm_comments() { if bcx.sess().asm_comments() {
add_comment(bcx, &format!("bind_irrefutable_pat(pat={:?})", add_comment(bcx, &format!("bind_irrefutable_pat(pat={:?})",
@ -1923,7 +1910,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// a regular one // a regular one
if !type_is_sized(tcx, fty) { if !type_is_sized(tcx, fty) {
let scratch = alloc_ty(bcx, fty, "__struct_field_fat_ptr"); let scratch = alloc_ty(bcx, fty, "__struct_field_fat_ptr");
debug!("Creating fat pointer {}", bcx.val_to_string(scratch)); debug!("Creating fat pointer {:?}", Value(scratch));
Store(bcx, fldptr, expr::get_dataptr(bcx, scratch)); Store(bcx, fldptr, expr::get_dataptr(bcx, scratch));
Store(bcx, val.meta, expr::get_meta(bcx, scratch)); Store(bcx, val.meta, expr::get_meta(bcx, scratch));
fldptr = scratch; fldptr = scratch;

View file

@ -67,6 +67,7 @@ use trans::machine;
use trans::monomorphize; use trans::monomorphize;
use trans::type_::Type; use trans::type_::Type;
use trans::type_of; use trans::type_of;
use trans::value::Value;
type Hint = attr::ReprAttr; type Hint = attr::ReprAttr;
@ -88,11 +89,6 @@ impl TypeContext {
fn may_need_drop_flag(t: Type, needs_drop_flag: bool) -> TypeContext { fn may_need_drop_flag(t: Type, needs_drop_flag: bool) -> TypeContext {
TypeContext { prefix: t, needs_drop_flag: needs_drop_flag } TypeContext { prefix: t, needs_drop_flag: needs_drop_flag }
} }
pub fn to_string(self) -> String {
let TypeContext { prefix, needs_drop_flag } = self;
format!("TypeContext {{ prefix: {}, needs_drop_flag: {} }}",
prefix.to_string(), needs_drop_flag)
}
} }
/// Representations. /// Representations.
@ -1139,9 +1135,8 @@ pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, v
// There's no metadata available, log the case and just do the GEP. // There's no metadata available, log the case and just do the GEP.
if !val.has_meta() { if !val.has_meta() {
debug!("Unsized field `{}`, of `{}` has no metadata for adjustment", debug!("Unsized field `{}`, of `{:?}` has no metadata for adjustment",
ix, ix, Value(ptr_val));
bcx.val_to_string(ptr_val));
return StructGEP(bcx, ptr_val, ix); return StructGEP(bcx, ptr_val, ix);
} }
@ -1189,8 +1184,7 @@ pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, v
Neg(bcx, align, dbloc), Neg(bcx, align, dbloc),
dbloc); dbloc);
debug!("struct_field_ptr: DST field offset: {}", debug!("struct_field_ptr: DST field offset: {:?}", Value(offset));
bcx.val_to_string(offset));
// Cast and adjust pointer // Cast and adjust pointer
let byte_ptr = PointerCast(bcx, ptr_val, Type::i8p(bcx.ccx())); let byte_ptr = PointerCast(bcx, ptr_val, Type::i8p(bcx.ccx()));
@ -1198,7 +1192,7 @@ pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, v
// Finally, cast back to the type expected // Finally, cast back to the type expected
let ll_fty = type_of::in_memory_type_of(bcx.ccx(), fty); let ll_fty = type_of::in_memory_type_of(bcx.ccx(), fty);
debug!("struct_field_ptr: Field type is {}", ll_fty.to_string()); debug!("struct_field_ptr: Field type is {:?}", ll_fty);
PointerCast(bcx, byte_ptr, ll_fty.ptr_to()) PointerCast(bcx, byte_ptr, ll_fty.ptr_to())
} }
@ -1442,7 +1436,7 @@ fn padding(ccx: &CrateContext, size: u64) -> ValueRef {
fn roundup(x: u64, a: u32) -> u64 { let a = a as u64; ((x + (a - 1)) / a) * a } fn roundup(x: u64, a: u32) -> u64 { let a = a as u64; ((x + (a - 1)) / a) * a }
/// Get the discriminant of a constant value. /// Get the discriminant of a constant value.
pub fn const_get_discrim(ccx: &CrateContext, r: &Repr, val: ValueRef) -> Disr { pub fn const_get_discrim(r: &Repr, val: ValueRef) -> Disr {
match *r { match *r {
CEnum(ity, _, _) => { CEnum(ity, _, _) => {
match ity { match ity {
@ -1452,13 +1446,13 @@ pub fn const_get_discrim(ccx: &CrateContext, r: &Repr, val: ValueRef) -> Disr {
} }
General(ity, _, _) => { General(ity, _, _) => {
match ity { match ity {
attr::SignedInt(..) => Disr(const_to_int(const_get_elt(ccx, val, &[0])) as u64), attr::SignedInt(..) => Disr(const_to_int(const_get_elt(val, &[0])) as u64),
attr::UnsignedInt(..) => Disr(const_to_uint(const_get_elt(ccx, val, &[0]))) attr::UnsignedInt(..) => Disr(const_to_uint(const_get_elt(val, &[0])))
} }
} }
Univariant(..) => Disr(0), Univariant(..) => Disr(0),
RawNullablePointer { .. } | StructWrappedNullablePointer { .. } => { RawNullablePointer { .. } | StructWrappedNullablePointer { .. } => {
ccx.sess().bug("const discrim access of non c-like enum") unreachable!("const discrim access of non c-like enum")
} }
} }
} }
@ -1472,25 +1466,25 @@ pub fn const_get_field(ccx: &CrateContext, r: &Repr, val: ValueRef,
_discr: Disr, ix: usize) -> ValueRef { _discr: Disr, ix: usize) -> ValueRef {
match *r { match *r {
CEnum(..) => ccx.sess().bug("element access in C-like enum const"), CEnum(..) => ccx.sess().bug("element access in C-like enum const"),
Univariant(..) => const_struct_field(ccx, val, ix), Univariant(..) => const_struct_field(val, ix),
General(..) => const_struct_field(ccx, val, ix + 1), General(..) => const_struct_field(val, ix + 1),
RawNullablePointer { .. } => { RawNullablePointer { .. } => {
assert_eq!(ix, 0); assert_eq!(ix, 0);
val val
}, },
StructWrappedNullablePointer{ .. } => const_struct_field(ccx, val, ix) StructWrappedNullablePointer{ .. } => const_struct_field(val, ix)
} }
} }
/// Extract field of struct-like const, skipping our alignment padding. /// Extract field of struct-like const, skipping our alignment padding.
fn const_struct_field(ccx: &CrateContext, val: ValueRef, ix: usize) -> ValueRef { fn const_struct_field(val: ValueRef, ix: usize) -> ValueRef {
// Get the ix-th non-undef element of the struct. // Get the ix-th non-undef element of the struct.
let mut real_ix = 0; // actual position in the struct let mut real_ix = 0; // actual position in the struct
let mut ix = ix; // logical index relative to real_ix let mut ix = ix; // logical index relative to real_ix
let mut field; let mut field;
loop { loop {
loop { loop {
field = const_get_elt(ccx, val, &[real_ix]); field = const_get_elt(val, &[real_ix]);
if !is_undef(field) { if !is_undef(field) {
break; break;
} }

View file

@ -948,9 +948,9 @@ pub fn invoke<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
} }
if need_invoke(bcx) { if need_invoke(bcx) {
debug!("invoking {} at {:?}", bcx.val_to_string(llfn), bcx.llbb); debug!("invoking {:?} at {:?}", Value(llfn), bcx.llbb);
for &llarg in llargs { for &llarg in llargs {
debug!("arg: {}", bcx.val_to_string(llarg)); debug!("arg: {:?}", Value(llarg));
} }
let normal_bcx = bcx.fcx.new_temp_block("normal-return"); let normal_bcx = bcx.fcx.new_temp_block("normal-return");
let landing_pad = bcx.fcx.get_landing_pad(); let landing_pad = bcx.fcx.get_landing_pad();
@ -964,9 +964,9 @@ pub fn invoke<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
debug_loc); debug_loc);
return (llresult, normal_bcx); return (llresult, normal_bcx);
} else { } else {
debug!("calling {} at {:?}", bcx.val_to_string(llfn), bcx.llbb); debug!("calling {:?} at {:?}", Value(llfn), bcx.llbb);
for &llarg in llargs { for &llarg in llargs {
debug!("arg: {}", bcx.val_to_string(llarg)); debug!("arg: {:?}", Value(llarg));
} }
let llresult = Call(bcx, llfn, &llargs[..], Some(attributes), debug_loc); let llresult = Call(bcx, llfn, &llargs[..], Some(attributes), debug_loc);
@ -1058,10 +1058,7 @@ pub fn store_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>, v: ValueRef, dst: ValueRef, t
return; return;
} }
debug!("store_ty: {} : {:?} <- {}", debug!("store_ty: {:?} : {:?} <- {:?}", Value(dst), t, Value(v));
cx.val_to_string(dst),
t,
cx.val_to_string(v));
if common::type_is_fat_ptr(cx.tcx(), t) { if common::type_is_fat_ptr(cx.tcx(), t) {
Store(cx, Store(cx,
@ -2030,8 +2027,7 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
debug!("trans_closure: monomorphized_arg_type: {:?}", debug!("trans_closure: monomorphized_arg_type: {:?}",
monomorphized_arg_type); monomorphized_arg_type);
} }
debug!("trans_closure: function lltype: {}", debug!("trans_closure: function lltype: {:?}", Value(bcx.fcx.llfn));
bcx.fcx.ccx.tn().val_to_string(bcx.fcx.llfn));
let has_tupled_arg = match closure_env { let has_tupled_arg = match closure_env {
closure::ClosureEnv::NotClosure => abi == Abi::RustCall, closure::ClosureEnv::NotClosure => abi == Abi::RustCall,

View file

@ -20,6 +20,7 @@ use syntax::codemap::Span;
use trans::builder::Builder; use trans::builder::Builder;
use trans::type_::Type; use trans::type_::Type;
use trans::value::Value;
use trans::debuginfo::DebugLoc; use trans::debuginfo::DebugLoc;
use libc::{c_uint, c_char}; use libc::{c_uint, c_char};
@ -146,9 +147,11 @@ pub fn Invoke(cx: Block,
} }
check_not_terminated(cx); check_not_terminated(cx);
terminate(cx, "Invoke"); terminate(cx, "Invoke");
debug!("Invoke({} with arguments ({}))", debug!("Invoke({:?} with arguments ({}))",
cx.val_to_string(fn_), Value(fn_),
args.iter().map(|a| cx.val_to_string(*a)).collect::<Vec<String>>().join(", ")); args.iter().map(|a| {
format!("{:?}", Value(*a))
}).collect::<Vec<String>>().join(", "));
debug_loc.apply(cx.fcx); debug_loc.apply(cx.fcx);
let bundle = cx.lpad().and_then(|b| b.bundle()); let bundle = cx.lpad().and_then(|b| b.bundle());
B(cx).invoke(fn_, args, then, catch, bundle, attributes) B(cx).invoke(fn_, args, then, catch, bundle, attributes)

View file

@ -18,6 +18,7 @@ use trans::base;
use trans::common::*; use trans::common::*;
use trans::machine::llalign_of_pref; use trans::machine::llalign_of_pref;
use trans::type_::Type; use trans::type_::Type;
use trans::value::Value;
use util::nodemap::FnvHashMap; use util::nodemap::FnvHashMap;
use libc::{c_uint, c_char}; use libc::{c_uint, c_char};
@ -169,10 +170,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
-> ValueRef { -> ValueRef {
self.count_insn("invoke"); self.count_insn("invoke");
debug!("Invoke {} with args ({})", debug!("Invoke {:?} with args ({})",
self.ccx.tn().val_to_string(llfn), Value(llfn),
args.iter() args.iter()
.map(|&v| self.ccx.tn().val_to_string(v)) .map(|&v| format!("{:?}", Value(v)))
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(", ")); .join(", "));
@ -497,9 +498,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
pub fn store(&self, val: ValueRef, ptr: ValueRef) -> ValueRef { pub fn store(&self, val: ValueRef, ptr: ValueRef) -> ValueRef {
debug!("Store {} -> {}", debug!("Store {:?} -> {:?}", Value(val), Value(ptr));
self.ccx.tn().val_to_string(val),
self.ccx.tn().val_to_string(ptr));
assert!(!self.llbuilder.is_null()); assert!(!self.llbuilder.is_null());
self.count_insn("store"); self.count_insn("store");
unsafe { unsafe {
@ -508,9 +507,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
pub fn volatile_store(&self, val: ValueRef, ptr: ValueRef) -> ValueRef { pub fn volatile_store(&self, val: ValueRef, ptr: ValueRef) -> ValueRef {
debug!("Store {} -> {}", debug!("Store {:?} -> {:?}", Value(val), Value(ptr));
self.ccx.tn().val_to_string(val),
self.ccx.tn().val_to_string(ptr));
assert!(!self.llbuilder.is_null()); assert!(!self.llbuilder.is_null());
self.count_insn("store.volatile"); self.count_insn("store.volatile");
unsafe { unsafe {
@ -521,9 +518,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
pub fn atomic_store(&self, val: ValueRef, ptr: ValueRef, order: AtomicOrdering) { pub fn atomic_store(&self, val: ValueRef, ptr: ValueRef, order: AtomicOrdering) {
debug!("Store {} -> {}", debug!("Store {:?} -> {:?}", Value(val), Value(ptr));
self.ccx.tn().val_to_string(val),
self.ccx.tn().val_to_string(ptr));
self.count_insn("store.atomic"); self.count_insn("store.atomic");
unsafe { unsafe {
let ty = Type::from_ref(llvm::LLVMTypeOf(ptr)); let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
@ -796,11 +791,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
else { llvm::False }; else { llvm::False };
let argtys = inputs.iter().map(|v| { let argtys = inputs.iter().map(|v| {
debug!("Asm Input Type: {}", self.ccx.tn().val_to_string(*v)); debug!("Asm Input Type: {:?}", Value(*v));
val_ty(*v) val_ty(*v)
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
debug!("Asm Output Type: {}", self.ccx.tn().type_to_string(output)); debug!("Asm Output Type: {:?}", output);
let fty = Type::func(&argtys[..], &output); let fty = Type::func(&argtys[..], &output);
unsafe { unsafe {
let v = llvm::LLVMInlineAsm( let v = llvm::LLVMInlineAsm(
@ -814,10 +809,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
attributes: Option<AttrBuilder>) -> ValueRef { attributes: Option<AttrBuilder>) -> ValueRef {
self.count_insn("call"); self.count_insn("call");
debug!("Call {} with args ({})", debug!("Call {:?} with args ({})",
self.ccx.tn().val_to_string(llfn), Value(llfn),
args.iter() args.iter()
.map(|&v| self.ccx.tn().val_to_string(v)) .map(|&v| format!("{:?}", Value(v)))
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(", ")); .join(", "));
@ -838,11 +833,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if expected_ty != actual_ty { if expected_ty != actual_ty {
self.ccx.sess().bug( self.ccx.sess().bug(
&format!( &format!(
"Type mismatch in function call of {}. Expected {} for param {}, got {}", "Type mismatch in function call of {:?}. \
self.ccx.tn().val_to_string(llfn), Expected {:?} for param {}, got {:?}",
self.ccx.tn().type_to_string(expected_ty), Value(llfn),
i, expected_ty, i, actual_ty));
self.ccx.tn().type_to_string(actual_ty)));
} }
} }

View file

@ -24,7 +24,7 @@ use trans::cabi_mips;
use trans::cabi_asmjs; use trans::cabi_asmjs;
use trans::type_::Type; use trans::type_::Type;
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq, Debug)]
pub enum ArgKind { pub enum ArgKind {
/// Pass the argument directly using the normal converted /// Pass the argument directly using the normal converted
/// LLVM type or by coercing to another specified type /// LLVM type or by coercing to another specified type
@ -39,7 +39,7 @@ pub enum ArgKind {
/// should be passed to or returned from a function /// should be passed to or returned from a function
/// ///
/// This is borrowed from clang's ABIInfo.h /// This is borrowed from clang's ABIInfo.h
#[derive(Clone, Copy)] #[derive(Clone, Copy, Debug)]
pub struct ArgType { pub struct ArgType {
pub kind: ArgKind, pub kind: ArgKind,
/// Original LLVM type /// Original LLVM type

View file

@ -47,6 +47,7 @@ use trans::meth;
use trans::monomorphize; use trans::monomorphize;
use trans::type_::Type; use trans::type_::Type;
use trans::type_of; use trans::type_of;
use trans::value::Value;
use trans::Disr; use trans::Disr;
use middle::ty::{self, Ty, TyCtxt, TypeFoldable}; use middle::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc_front::hir; use rustc_front::hir;
@ -615,8 +616,8 @@ fn trans_call_inner<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
let llret_ty = common::val_ty(llretslot); let llret_ty = common::val_ty(llretslot);
if llformal_ret_ty != llret_ty { if llformal_ret_ty != llret_ty {
// this could happen due to e.g. subtyping // this could happen due to e.g. subtyping
debug!("casting actual return type ({}) to match formal ({})", debug!("casting actual return type ({:?}) to match formal ({:?})",
bcx.llty_str(llret_ty), bcx.llty_str(llformal_ret_ty)); llret_ty, llformal_ret_ty);
llretslot = PointerCast(bcx, llretslot, llformal_ret_ty); llretslot = PointerCast(bcx, llretslot, llformal_ret_ty);
} }
llargs.push(llretslot); llargs.push(llretslot);
@ -926,12 +927,11 @@ pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let mut bcx = bcx; let mut bcx = bcx;
let ccx = bcx.ccx(); let ccx = bcx.ccx();
debug!("trans_arg_datum({:?})", debug!("trans_arg_datum({:?})", formal_arg_ty);
formal_arg_ty);
let arg_datum_ty = arg_datum.ty; let arg_datum_ty = arg_datum.ty;
debug!(" arg datum: {}", arg_datum.to_string(bcx.ccx())); debug!(" arg datum: {:?}", arg_datum);
let mut val = if common::type_is_fat_ptr(bcx.tcx(), arg_datum_ty) && let mut val = if common::type_is_fat_ptr(bcx.tcx(), arg_datum_ty) &&
!bcx.fcx.type_needs_drop(arg_datum_ty) { !bcx.fcx.type_needs_drop(arg_datum_ty) {
@ -956,14 +956,14 @@ pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
if type_of::arg_is_indirect(ccx, formal_arg_ty) && formal_arg_ty != arg_datum_ty { if type_of::arg_is_indirect(ccx, formal_arg_ty) && formal_arg_ty != arg_datum_ty {
// this could happen due to e.g. subtyping // this could happen due to e.g. subtyping
let llformal_arg_ty = type_of::type_of_explicit_arg(ccx, formal_arg_ty); let llformal_arg_ty = type_of::type_of_explicit_arg(ccx, formal_arg_ty);
debug!("casting actual type ({}) to match formal ({})", debug!("casting actual type ({:?}) to match formal ({:?})",
bcx.val_to_string(val), bcx.llty_str(llformal_arg_ty)); Value(val), llformal_arg_ty);
debug!("Rust types: {:?}; {:?}", arg_datum_ty, debug!("Rust types: {:?}; {:?}", arg_datum_ty,
formal_arg_ty); formal_arg_ty);
val = PointerCast(bcx, val, llformal_arg_ty); val = PointerCast(bcx, val, llformal_arg_ty);
} }
debug!("--- trans_arg_datum passing {}", bcx.val_to_string(val)); debug!("--- trans_arg_datum passing {:?}", Value(val));
if common::type_is_fat_ptr(bcx.tcx(), formal_arg_ty) { if common::type_is_fat_ptr(bcx.tcx(), formal_arg_ty) {
llargs.push(Load(bcx, expr::get_dataptr(bcx, val))); llargs.push(Load(bcx, expr::get_dataptr(bcx, val)));

View file

@ -129,7 +129,9 @@ use trans::debuginfo::{DebugLoc, ToDebugLoc};
use trans::glue; use trans::glue;
use middle::region; use middle::region;
use trans::type_::Type; use trans::type_::Type;
use trans::value::Value;
use middle::ty::{Ty, TyCtxt}; use middle::ty::{Ty, TyCtxt};
use std::fmt; use std::fmt;
use syntax::ast; use syntax::ast;
@ -401,9 +403,8 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
ptr: val, ptr: val,
}; };
debug!("schedule_lifetime_end({:?}, val={})", debug!("schedule_lifetime_end({:?}, val={:?})",
cleanup_scope, cleanup_scope, Value(val));
self.ccx.tn().val_to_string(val));
self.schedule_clean(cleanup_scope, drop as CleanupObj); self.schedule_clean(cleanup_scope, drop as CleanupObj);
} }
@ -426,9 +427,9 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
drop_hint: drop_hint, drop_hint: drop_hint,
}; };
debug!("schedule_drop_mem({:?}, val={}, ty={:?}) fill_on_drop={} skip_dtor={}", debug!("schedule_drop_mem({:?}, val={:?}, ty={:?}) fill_on_drop={} skip_dtor={}",
cleanup_scope, cleanup_scope,
self.ccx.tn().val_to_string(val), Value(val),
ty, ty,
drop.fill_on_drop, drop.fill_on_drop,
drop.skip_dtor); drop.skip_dtor);
@ -454,10 +455,10 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
drop_hint: drop_hint, drop_hint: drop_hint,
}; };
debug!("schedule_drop_and_fill_mem({:?}, val={}, ty={:?}, debug!("schedule_drop_and_fill_mem({:?}, val={:?}, ty={:?},
fill_on_drop={}, skip_dtor={}, has_drop_hint={})", fill_on_drop={}, skip_dtor={}, has_drop_hint={})",
cleanup_scope, cleanup_scope,
self.ccx.tn().val_to_string(val), Value(val),
ty, ty,
drop.fill_on_drop, drop.fill_on_drop,
drop.skip_dtor, drop.skip_dtor,
@ -488,9 +489,9 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
drop_hint: None, drop_hint: None,
}; };
debug!("schedule_drop_adt_contents({:?}, val={}, ty={:?}) fill_on_drop={} skip_dtor={}", debug!("schedule_drop_adt_contents({:?}, val={:?}, ty={:?}) fill_on_drop={} skip_dtor={}",
cleanup_scope, cleanup_scope,
self.ccx.tn().val_to_string(val), Value(val),
ty, ty,
drop.fill_on_drop, drop.fill_on_drop,
drop.skip_dtor); drop.skip_dtor);
@ -514,9 +515,9 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
drop_hint: None, drop_hint: None,
}); });
debug!("schedule_drop_immediate({:?}, val={}, ty={:?}) fill_on_drop={} skip_dtor={}", debug!("schedule_drop_immediate({:?}, val={:?}, ty={:?}) fill_on_drop={} skip_dtor={}",
cleanup_scope, cleanup_scope,
self.ccx.tn().val_to_string(val), Value(val),
ty, ty,
drop.fill_on_drop, drop.fill_on_drop,
drop.skip_dtor); drop.skip_dtor);
@ -532,10 +533,8 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
content_ty: Ty<'tcx>) { content_ty: Ty<'tcx>) {
let drop = box FreeValue { ptr: val, heap: heap, content_ty: content_ty }; let drop = box FreeValue { ptr: val, heap: heap, content_ty: content_ty };
debug!("schedule_free_value({:?}, val={}, heap={:?})", debug!("schedule_free_value({:?}, val={:?}, heap={:?})",
cleanup_scope, cleanup_scope, Value(val), heap);
self.ccx.tn().val_to_string(val),
heap);
self.schedule_clean(cleanup_scope, drop as CleanupObj); self.schedule_clean(cleanup_scope, drop as CleanupObj);
} }

View file

@ -27,6 +27,7 @@ use trans::declare;
use trans::expr; use trans::expr;
use trans::monomorphize::{MonoId}; use trans::monomorphize::{MonoId};
use trans::type_of::*; use trans::type_of::*;
use trans::value::Value;
use trans::Disr; use trans::Disr;
use middle::ty; use middle::ty;
use session::config::FullDebugInfo; use session::config::FullDebugInfo;
@ -146,7 +147,7 @@ pub fn get_or_create_closure_declaration<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
if let Some(&llfn) = ccx.closure_vals().borrow().get(&mono_id) { if let Some(&llfn) = ccx.closure_vals().borrow().get(&mono_id) {
debug!("get_or_create_closure_declaration(): found closure {:?}: {:?}", debug!("get_or_create_closure_declaration(): found closure {:?}: {:?}",
mono_id, ccx.tn().val_to_string(llfn)); mono_id, Value(llfn));
return llfn; return llfn;
} }
@ -160,10 +161,8 @@ pub fn get_or_create_closure_declaration<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
attributes::inline(llfn, attributes::InlineAttr::Hint); attributes::inline(llfn, attributes::InlineAttr::Hint);
debug!("get_or_create_declaration_if_closure(): inserting new \ debug!("get_or_create_declaration_if_closure(): inserting new \
closure {:?} (type {}): {:?}", closure {:?}: {:?}",
mono_id, mono_id, Value(llfn));
ccx.tn().type_to_string(val_ty(llfn)),
ccx.tn().val_to_string(llfn));
ccx.closure_vals().borrow_mut().insert(mono_id, llfn); ccx.closure_vals().borrow_mut().insert(mono_id, llfn);
llfn llfn
@ -278,11 +277,8 @@ pub fn trans_closure_method<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
let tcx = ccx.tcx(); let tcx = ccx.tcx();
debug!("trans_closure_adapter_shim(llfn_closure_kind={:?}, \ debug!("trans_closure_adapter_shim(llfn_closure_kind={:?}, \
trait_closure_kind={:?}, \ trait_closure_kind={:?}, llfn={:?})",
llfn={})", llfn_closure_kind, trait_closure_kind, Value(llfn));
llfn_closure_kind,
trait_closure_kind,
ccx.tn().val_to_string(llfn));
match (llfn_closure_kind, trait_closure_kind) { match (llfn_closure_kind, trait_closure_kind) {
(ty::ClosureKind::Fn, ty::ClosureKind::Fn) | (ty::ClosureKind::Fn, ty::ClosureKind::Fn) |
@ -324,10 +320,8 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
llreffn: ValueRef) llreffn: ValueRef)
-> ValueRef -> ValueRef
{ {
debug!("trans_fn_once_adapter_shim(closure_def_id={:?}, substs={:?}, llreffn={})", debug!("trans_fn_once_adapter_shim(closure_def_id={:?}, substs={:?}, llreffn={:?})",
closure_def_id, closure_def_id, substs, Value(llreffn));
substs,
ccx.tn().val_to_string(llreffn));
let tcx = ccx.tcx(); let tcx = ccx.tcx();
let infcx = infer::normalizing_infer_ctxt(ccx.tcx(), &ccx.tcx().tables, ProjectionMode::Any); let infcx = infer::normalizing_infer_ctxt(ccx.tcx(), &ccx.tcx().tables, ProjectionMode::Any);
@ -391,8 +385,8 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
env_datum.to_lvalue_datum_in_scope(bcx, "self", env_datum.to_lvalue_datum_in_scope(bcx, "self",
self_scope_id)); self_scope_id));
debug!("trans_fn_once_adapter_shim: env_datum={}", debug!("trans_fn_once_adapter_shim: env_datum={:?}",
bcx.val_to_string(env_datum.val)); Value(env_datum.val));
llargs[self_idx] = env_datum.val; llargs[self_idx] = env_datum.val;
let dest = let dest =

View file

@ -37,6 +37,7 @@ use trans::machine;
use trans::monomorphize; use trans::monomorphize;
use trans::type_::Type; use trans::type_::Type;
use trans::type_of; use trans::type_of;
use trans::value::Value;
use middle::ty::{self, Ty, TyCtxt}; use middle::ty::{self, Ty, TyCtxt};
use middle::traits::{self, SelectionContext, ProjectionMode}; use middle::traits::{self, SelectionContext, ProjectionMode};
use middle::ty::fold::{TypeFolder, TypeFoldable}; use middle::ty::fold::{TypeFolder, TypeFoldable};
@ -652,14 +653,6 @@ impl<'blk, 'tcx> BlockS<'blk, 'tcx> {
} }
} }
pub fn val_to_string(&self, val: ValueRef) -> String {
self.ccx().tn().val_to_string(val)
}
pub fn llty_str(&self, ty: Type) -> String {
self.ccx().tn().type_to_string(ty)
}
pub fn to_str(&self) -> String { pub fn to_str(&self) -> String {
format!("[block {:p}]", self) format!("[block {:p}]", self)
} }
@ -767,10 +760,6 @@ impl<'blk, 'tcx> BlockAndBuilder<'blk, 'tcx> {
self.bcx.mir() self.bcx.mir()
} }
pub fn val_to_string(&self, val: ValueRef) -> String {
self.bcx.val_to_string(val)
}
pub fn monomorphize<T>(&self, value: &T) -> T pub fn monomorphize<T>(&self, value: &T) -> T
where T: TypeFoldable<'tcx> where T: TypeFoldable<'tcx>
{ {
@ -1028,15 +1017,15 @@ pub fn C_bytes_in_context(llcx: ContextRef, bytes: &[u8]) -> ValueRef {
} }
} }
pub fn const_get_elt(cx: &CrateContext, v: ValueRef, us: &[c_uint]) pub fn const_get_elt(v: ValueRef, us: &[c_uint])
-> ValueRef { -> ValueRef {
unsafe { unsafe {
let r = llvm::LLVMConstExtractValue(v, us.as_ptr(), us.len() as c_uint); let r = llvm::LLVMConstExtractValue(v, us.as_ptr(), us.len() as c_uint);
debug!("const_get_elt(v={}, us={:?}, r={})", debug!("const_get_elt(v={:?}, us={:?}, r={:?})",
cx.tn().val_to_string(v), us, cx.tn().val_to_string(r)); Value(v), us, Value(r));
return r; r
} }
} }

View file

@ -30,6 +30,7 @@ use trans::declare;
use trans::monomorphize; use trans::monomorphize;
use trans::type_::Type; use trans::type_::Type;
use trans::type_of; use trans::type_of;
use trans::value::Value;
use trans::Disr; use trans::Disr;
use middle::subst::Substs; use middle::subst::Substs;
use middle::ty::adjustment::{AdjustDerefRef, AdjustReifyFnPointer}; use middle::ty::adjustment::{AdjustDerefRef, AdjustReifyFnPointer};
@ -405,8 +406,8 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
// to use a different vtable. In that case, we want to // to use a different vtable. In that case, we want to
// load out the original data pointer so we can repackage // load out the original data pointer so we can repackage
// it. // it.
(const_get_elt(cx, llconst, &[abi::FAT_PTR_ADDR as u32]), (const_get_elt(llconst, &[abi::FAT_PTR_ADDR as u32]),
Some(const_get_elt(cx, llconst, &[abi::FAT_PTR_EXTRA as u32]))) Some(const_get_elt(llconst, &[abi::FAT_PTR_EXTRA as u32])))
} else { } else {
(llconst, None) (llconst, None)
}; };
@ -595,17 +596,15 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
/* Neither type is bottom, and we expect them to be unified /* Neither type is bottom, and we expect them to be unified
* already, so the following is safe. */ * already, so the following is safe. */
let (te1, ty) = try!(const_expr(cx, &e1, param_substs, fn_args, trueconst)); let (te1, ty) = try!(const_expr(cx, &e1, param_substs, fn_args, trueconst));
debug!("const_expr_unadjusted: te1={}, ty={:?}", debug!("const_expr_unadjusted: te1={:?}, ty={:?}",
cx.tn().val_to_string(te1), Value(te1), ty);
ty);
assert!(!ty.is_simd()); assert!(!ty.is_simd());
let is_float = ty.is_fp(); let is_float = ty.is_fp();
let signed = ty.is_signed(); let signed = ty.is_signed();
let (te2, ty2) = try!(const_expr(cx, &e2, param_substs, fn_args, trueconst)); let (te2, ty2) = try!(const_expr(cx, &e2, param_substs, fn_args, trueconst));
debug!("const_expr_unadjusted: te2={}, ty={:?}", debug!("const_expr_unadjusted: te2={:?}, ty={:?}",
cx.tn().val_to_string(te2), Value(te2), ty2);
ty2);
try!(check_binary_expr_validity(cx, e, ty, te1, te2, trueconst)); try!(check_binary_expr_validity(cx, e, ty, te1, te2, trueconst));
@ -689,8 +688,8 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let (arr, len) = match bt.sty { let (arr, len) = match bt.sty {
ty::TyArray(_, u) => (bv, C_uint(cx, u)), ty::TyArray(_, u) => (bv, C_uint(cx, u)),
ty::TySlice(..) | ty::TyStr => { ty::TySlice(..) | ty::TyStr => {
let e1 = const_get_elt(cx, bv, &[0]); let e1 = const_get_elt(bv, &[0]);
(load_const(cx, e1, bt), const_get_elt(cx, bv, &[1])) (load_const(cx, e1, bt), const_get_elt(bv, &[1]))
}, },
ty::TyRef(_, mt) => match mt.ty.sty { ty::TyRef(_, mt) => match mt.ty.sty {
ty::TyArray(_, u) => { ty::TyArray(_, u) => {
@ -725,7 +724,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
"const index-expr is out of bounds"); "const index-expr is out of bounds");
C_undef(val_ty(arr).element_type()) C_undef(val_ty(arr).element_type())
} else { } else {
const_get_elt(cx, arr, &[iv as c_uint]) const_get_elt(arr, &[iv as c_uint])
} }
}, },
hir::ExprCast(ref base, _) => { hir::ExprCast(ref base, _) => {
@ -741,10 +740,10 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let t_cast_inner = let t_cast_inner =
t_cast.builtin_deref(true, ty::NoPreference).expect("cast to non-pointer").ty; t_cast.builtin_deref(true, ty::NoPreference).expect("cast to non-pointer").ty;
let ptr_ty = type_of::in_memory_type_of(cx, t_cast_inner).ptr_to(); let ptr_ty = type_of::in_memory_type_of(cx, t_cast_inner).ptr_to();
let addr = ptrcast(const_get_elt(cx, v, &[abi::FAT_PTR_ADDR as u32]), let addr = ptrcast(const_get_elt(v, &[abi::FAT_PTR_ADDR as u32]),
ptr_ty); ptr_ty);
if type_is_fat_ptr(cx.tcx(), t_cast) { if type_is_fat_ptr(cx.tcx(), t_cast) {
let info = const_get_elt(cx, v, &[abi::FAT_PTR_EXTRA as u32]); let info = const_get_elt(v, &[abi::FAT_PTR_EXTRA as u32]);
return Ok(C_struct(cx, &[addr, info], false)) return Ok(C_struct(cx, &[addr, info], false))
} else { } else {
return Ok(addr); return Ok(addr);
@ -756,7 +755,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
) { ) {
(CastTy::Int(IntTy::CEnum), CastTy::Int(_)) => { (CastTy::Int(IntTy::CEnum), CastTy::Int(_)) => {
let repr = adt::represent_type(cx, t_expr); let repr = adt::represent_type(cx, t_expr);
let discr = adt::const_get_discrim(cx, &repr, v); let discr = adt::const_get_discrim(&repr, v);
let iv = C_integral(cx.int_type(), discr.0, false); let iv = C_integral(cx.int_type(), discr.0, false);
let s = adt::is_discr_signed(&repr) as Bool; let s = adt::is_discr_signed(&repr) as Bool;
llvm::LLVMConstIntCast(iv, llty.to_ref(), s) llvm::LLVMConstIntCast(iv, llty.to_ref(), s)

View file

@ -152,9 +152,8 @@ pub fn trans_if<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
els: Option<&hir::Expr>, els: Option<&hir::Expr>,
dest: expr::Dest) dest: expr::Dest)
-> Block<'blk, 'tcx> { -> Block<'blk, 'tcx> {
debug!("trans_if(bcx={}, if_id={}, cond={:?}, thn={}, dest={})", debug!("trans_if(bcx={}, if_id={}, cond={:?}, thn={}, dest={:?})",
bcx.to_str(), if_id, cond, thn.id, bcx.to_str(), if_id, cond, thn.id, dest);
dest.to_string(bcx.ccx()));
let _icx = push_ctxt("trans_if"); let _icx = push_ctxt("trans_if");
if bcx.unreachable.get() { if bcx.unreachable.get() {

View file

@ -101,6 +101,7 @@ use trans::cleanup;
use trans::cleanup::{CleanupMethods, DropHintDatum, DropHintMethods}; use trans::cleanup::{CleanupMethods, DropHintDatum, DropHintMethods};
use trans::expr; use trans::expr;
use trans::tvec; use trans::tvec;
use trans::value::Value;
use middle::ty::Ty; use middle::ty::Ty;
use std::fmt; use std::fmt;
@ -111,7 +112,7 @@ use syntax::codemap::DUMMY_SP;
/// describes where the value is stored, what Rust type the value has, /// describes where the value is stored, what Rust type the value has,
/// whether it is addressed by reference, and so forth. Please refer /// whether it is addressed by reference, and so forth. Please refer
/// the section on datums in `README.md` for more details. /// the section on datums in `README.md` for more details.
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy)]
pub struct Datum<'tcx, K> { pub struct Datum<'tcx, K> {
/// The llvm value. This is either a pointer to the Rust value or /// The llvm value. This is either a pointer to the Rust value or
/// the value itself, depending on `kind` below. /// the value itself, depending on `kind` below.
@ -124,6 +125,13 @@ pub struct Datum<'tcx, K> {
pub kind: K, pub kind: K,
} }
impl<'tcx, K: fmt::Debug> fmt::Debug for Datum<'tcx, K> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Datum({:?}, {:?}, {:?})",
Value(self.val), self.ty, self.kind)
}
}
pub struct DatumBlock<'blk, 'tcx: 'blk, K> { pub struct DatumBlock<'blk, 'tcx: 'blk, K> {
pub bcx: Block<'blk, 'tcx>, pub bcx: Block<'blk, 'tcx>,
pub datum: Datum<'tcx, K>, pub datum: Datum<'tcx, K>,
@ -311,8 +319,8 @@ pub fn lvalue_scratch_datum<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>,
// Very subtle: potentially initialize the scratch memory at point where it is alloca'ed. // Very subtle: potentially initialize the scratch memory at point where it is alloca'ed.
// (See discussion at Issue 30530.) // (See discussion at Issue 30530.)
let scratch = alloc_ty_init(bcx, ty, zero, name); let scratch = alloc_ty_init(bcx, ty, zero, name);
debug!("lvalue_scratch_datum scope={:?} scratch={} ty={:?}", debug!("lvalue_scratch_datum scope={:?} scratch={:?} ty={:?}",
scope, bcx.ccx().tn().val_to_string(scratch), ty); scope, Value(scratch), ty);
// Subtle. Populate the scratch memory *before* scheduling cleanup. // Subtle. Populate the scratch memory *before* scheduling cleanup.
let bcx = populate(arg, bcx, scratch); let bcx = populate(arg, bcx, scratch);
@ -351,8 +359,8 @@ fn add_rvalue_clean<'a, 'tcx>(mode: RvalueMode,
scope: cleanup::ScopeId, scope: cleanup::ScopeId,
val: ValueRef, val: ValueRef,
ty: Ty<'tcx>) { ty: Ty<'tcx>) {
debug!("add_rvalue_clean scope={:?} val={} ty={:?}", debug!("add_rvalue_clean scope={:?} val={:?} ty={:?}",
scope, fcx.ccx.tn().val_to_string(val), ty); scope, Value(val), ty);
match mode { match mode {
ByValue => { fcx.schedule_drop_immediate(scope, val, ty); } ByValue => { fcx.schedule_drop_immediate(scope, val, ty); }
ByRef => { ByRef => {
@ -617,7 +625,7 @@ impl<'tcx> Datum<'tcx, Expr> {
name: &str, name: &str,
expr_id: ast::NodeId) expr_id: ast::NodeId)
-> DatumBlock<'blk, 'tcx, Lvalue> { -> DatumBlock<'blk, 'tcx, Lvalue> {
debug!("to_lvalue_datum self: {}", self.to_string(bcx.ccx())); debug!("to_lvalue_datum self: {:?}", self);
self.match_kind( self.match_kind(
|l| DatumBlock::new(bcx, l), |l| DatumBlock::new(bcx, l),
@ -767,14 +775,6 @@ impl<'tcx, K: KindOps + fmt::Debug> Datum<'tcx, K> {
self.shallow_copy_raw(bcx, dst) self.shallow_copy_raw(bcx, dst)
} }
#[allow(dead_code)] // useful for debugging
pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String {
format!("Datum({}, {:?}, {:?})",
ccx.tn().val_to_string(self.val),
self.ty,
self.kind)
}
/// See the `appropriate_rvalue_mode()` function /// See the `appropriate_rvalue_mode()` function
pub fn appropriate_rvalue_mode<'a>(&self, ccx: &CrateContext<'a, 'tcx>) pub fn appropriate_rvalue_mode<'a>(&self, ccx: &CrateContext<'a, 'tcx>)
-> RvalueMode { -> RvalueMode {

View file

@ -129,7 +129,7 @@ pub fn declare_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
let sig = infer::normalize_associated_type(ccx.tcx(), &sig); let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
debug!("declare_rust_fn (after region erasure) sig={:?}", sig); debug!("declare_rust_fn (after region erasure) sig={:?}", sig);
let llfty = type_of::type_of_rust_fn(ccx, env, &sig, abi); let llfty = type_of::type_of_rust_fn(ccx, env, &sig, abi);
debug!("declare_rust_fn llfty={}", ccx.tn().type_to_string(llfty)); debug!("declare_rust_fn llfty={:?}", llfty);
// it is ok to directly access sig.0.output because we erased all // it is ok to directly access sig.0.output because we erased all
// late-bound-regions above // late-bound-regions above

View file

@ -69,6 +69,7 @@ use trans::glue;
use trans::machine; use trans::machine;
use trans::tvec; use trans::tvec;
use trans::type_of; use trans::type_of;
use trans::value::Value;
use trans::Disr; use trans::Disr;
use middle::ty::adjustment::{AdjustDerefRef, AdjustReifyFnPointer}; use middle::ty::adjustment::{AdjustDerefRef, AdjustReifyFnPointer};
use middle::ty::adjustment::{AdjustUnsafeFnPointer, AdjustMutToConstPointer}; use middle::ty::adjustment::{AdjustUnsafeFnPointer, AdjustMutToConstPointer};
@ -85,6 +86,7 @@ use rustc_front::hir;
use syntax::{ast, codemap}; use syntax::{ast, codemap};
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use std::fmt;
use std::mem; use std::mem;
// Destinations // Destinations
@ -98,11 +100,11 @@ pub enum Dest {
Ignore, Ignore,
} }
impl Dest { impl fmt::Debug for Dest {
pub fn to_string(&self, ccx: &CrateContext) -> String { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
SaveIn(v) => format!("SaveIn({})", ccx.tn().val_to_string(v)), SaveIn(v) => write!(f, "SaveIn({:?})", Value(v)),
Ignore => "Ignore".to_string() Ignore => f.write_str("Ignore")
} }
} }
} }
@ -377,10 +379,8 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
} }
Some(adj) => { adj } Some(adj) => { adj }
}; };
debug!("unadjusted datum for expr {:?}: {} adjustment={:?}", debug!("unadjusted datum for expr {:?}: {:?} adjustment={:?}",
expr, expr, datum, adjustment);
datum.to_string(bcx.ccx()),
adjustment);
match adjustment { match adjustment {
AdjustReifyFnPointer => { AdjustReifyFnPointer => {
match datum.ty.sty { match datum.ty.sty {
@ -452,7 +452,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
} }
} }
} }
debug!("after adjustments, datum={}", datum.to_string(bcx.ccx())); debug!("after adjustments, datum={:?}", datum);
DatumBlock::new(bcx, datum) DatumBlock::new(bcx, datum)
} }
@ -462,9 +462,7 @@ fn coerce_unsized<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
target: Datum<'tcx, Rvalue>) target: Datum<'tcx, Rvalue>)
-> Block<'blk, 'tcx> { -> Block<'blk, 'tcx> {
let mut bcx = bcx; let mut bcx = bcx;
debug!("coerce_unsized({} -> {})", debug!("coerce_unsized({:?} -> {:?})", source, target);
source.to_string(bcx.ccx()),
target.to_string(bcx.ccx()));
match (&source.ty.sty, &target.ty.sty) { match (&source.ty.sty, &target.ty.sty) {
(&ty::TyBox(a), &ty::TyBox(b)) | (&ty::TyBox(a), &ty::TyBox(b)) |
@ -854,8 +852,8 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let (base, len) = base_datum.get_vec_base_and_len(bcx); let (base, len) = base_datum.get_vec_base_and_len(bcx);
debug!("trans_index: base {}", bcx.val_to_string(base)); debug!("trans_index: base {:?}", Value(base));
debug!("trans_index: len {}", bcx.val_to_string(len)); debug!("trans_index: len {:?}", Value(len));
let bounds_check = ICmp(bcx, let bounds_check = ICmp(bcx,
llvm::IntUGE, llvm::IntUGE,
@ -1279,8 +1277,8 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
nid)); nid));
} }
}; };
debug!("take_local(nid={}, v={}, ty={})", debug!("take_local(nid={}, v={:?}, ty={})",
nid, bcx.val_to_string(datum.val), datum.ty); nid, Value(datum.val), datum.ty);
datum datum
} }
_ => { _ => {
@ -1829,12 +1827,10 @@ fn trans_binary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let lhs = unpack_datum!(bcx, trans(bcx, lhs)); let lhs = unpack_datum!(bcx, trans(bcx, lhs));
let lhs = unpack_datum!(bcx, lhs.to_rvalue_datum(bcx, "binop_lhs")); let lhs = unpack_datum!(bcx, lhs.to_rvalue_datum(bcx, "binop_lhs"));
debug!("trans_binary (expr {}): lhs={}", debug!("trans_binary (expr {}): lhs={:?}", expr.id, lhs);
expr.id, lhs.to_string(ccx));
let rhs = unpack_datum!(bcx, trans(bcx, rhs)); let rhs = unpack_datum!(bcx, trans(bcx, rhs));
let rhs = unpack_datum!(bcx, rhs.to_rvalue_datum(bcx, "binop_rhs")); let rhs = unpack_datum!(bcx, rhs.to_rvalue_datum(bcx, "binop_rhs"));
debug!("trans_binary (expr {}): rhs={}", debug!("trans_binary (expr {}): rhs={:?}", expr.id, rhs);
expr.id, rhs.to_string(ccx));
if type_is_fat_ptr(ccx.tcx(), lhs.ty) { if type_is_fat_ptr(ccx.tcx(), lhs.ty) {
assert!(type_is_fat_ptr(ccx.tcx(), rhs.ty), assert!(type_is_fat_ptr(ccx.tcx(), rhs.ty),
@ -2085,10 +2081,8 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
-> DatumBlock<'blk, 'tcx, Expr> { -> DatumBlock<'blk, 'tcx, Expr> {
let ccx = bcx.ccx(); let ccx = bcx.ccx();
debug!("deref_once(expr={:?}, datum={}, method_call={:?})", debug!("deref_once(expr={:?}, datum={:?}, method_call={:?})",
expr, expr, datum, method_call);
datum.to_string(ccx),
method_call);
let mut bcx = bcx; let mut bcx = bcx;
@ -2175,8 +2169,8 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
} }
}; };
debug!("deref_once(expr={}, method_call={:?}, result={})", debug!("deref_once(expr={}, method_call={:?}, result={:?})",
expr.id, method_call, r.datum.to_string(ccx)); expr.id, method_call, r.datum);
return r; return r;
} }

View file

@ -27,6 +27,7 @@ use trans::monomorphize;
use trans::type_::Type; use trans::type_::Type;
use trans::type_of::*; use trans::type_of::*;
use trans::type_of; use trans::type_of;
use trans::value::Value;
use middle::infer; use middle::infer;
use middle::ty::{self, Ty, TyCtxt}; use middle::ty::{self, Ty, TyCtxt};
use middle::subst::Substs; use middle::subst::Substs;
@ -254,12 +255,8 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
{ {
let ccx = bcx.ccx(); let ccx = bcx.ccx();
debug!("trans_native_call(callee_ty={:?}, \ debug!("trans_native_call(callee_ty={:?}, llfn={:?}, llretptr={:?})",
llfn={}, \ callee_ty, Value(llfn), Value(llretptr));
llretptr={})",
callee_ty,
ccx.tn().val_to_string(llfn),
ccx.tn().val_to_string(llretptr));
let (fn_abi, fn_sig) = match callee_ty.sty { let (fn_abi, fn_sig) = match callee_ty.sty {
ty::TyFnDef(_, _, ref fn_ty) | ty::TyFnDef(_, _, ref fn_ty) |
@ -306,11 +303,11 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// Does Rust pass this argument by pointer? // Does Rust pass this argument by pointer?
let rust_indirect = type_of::arg_is_indirect(ccx, passed_arg_tys[i]); let rust_indirect = type_of::arg_is_indirect(ccx, passed_arg_tys[i]);
debug!("argument {}, llarg_rust={}, rust_indirect={}, arg_ty={}", debug!("argument {}, llarg_rust={:?}, rust_indirect={}, arg_ty={:?}",
i, i,
ccx.tn().val_to_string(llarg_rust), Value(llarg_rust),
rust_indirect, rust_indirect,
ccx.tn().type_to_string(arg_ty.ty)); arg_ty.ty);
// Ensure that we always have the Rust value indirectly, // Ensure that we always have the Rust value indirectly,
// because it makes bitcasting easier. // because it makes bitcasting easier.
@ -326,8 +323,8 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
llarg_rust = scratch; llarg_rust = scratch;
} }
debug!("llarg_rust={} (after indirection)", debug!("llarg_rust={:?} (after indirection)",
ccx.tn().val_to_string(llarg_rust)); Value(llarg_rust));
// Check whether we need to do any casting // Check whether we need to do any casting
match arg_ty.cast { match arg_ty.cast {
@ -335,8 +332,8 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
None => () None => ()
} }
debug!("llarg_rust={} (after casting)", debug!("llarg_rust={:?} (after casting)",
ccx.tn().val_to_string(llarg_rust)); Value(llarg_rust));
// Finally, load the value if needed for the foreign ABI // Finally, load the value if needed for the foreign ABI
let foreign_indirect = arg_ty.is_indirect(); let foreign_indirect = arg_ty.is_indirect();
@ -351,8 +348,8 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
} }
}; };
debug!("argument {}, llarg_foreign={}", debug!("argument {}, llarg_foreign={:?}",
i, ccx.tn().val_to_string(llarg_foreign)); i, Value(llarg_foreign));
// fill padding with undef value // fill padding with undef value
match arg_ty.pad { match arg_ty.pad {
@ -421,10 +418,10 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
None => fn_type.ret_ty.ty None => fn_type.ret_ty.ty
}; };
debug!("llretptr={}", ccx.tn().val_to_string(llretptr)); debug!("llretptr={:?}", Value(llretptr));
debug!("llforeign_retval={}", ccx.tn().val_to_string(llforeign_retval)); debug!("llforeign_retval={:?}", Value(llforeign_retval));
debug!("llrust_ret_ty={}", ccx.tn().type_to_string(llrust_ret_ty)); debug!("llrust_ret_ty={:?}", llrust_ret_ty);
debug!("llforeign_ret_ty={}", ccx.tn().type_to_string(llforeign_ret_ty)); debug!("llforeign_ret_ty={:?}", llforeign_ret_ty);
if llrust_ret_ty == llforeign_ret_ty { if llrust_ret_ty == llforeign_ret_ty {
match fn_sig.output { match fn_sig.output {
@ -562,8 +559,8 @@ pub fn decl_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
let llfn = declare::declare_fn(ccx, name, cconv, llfn_ty, let llfn = declare::declare_fn(ccx, name, cconv, llfn_ty,
ty::FnConverging(ccx.tcx().mk_nil())); ty::FnConverging(ccx.tcx().mk_nil()));
add_argument_attributes(&tys, llfn); add_argument_attributes(&tys, llfn);
debug!("decl_rust_fn_with_foreign_abi(llfn_ty={}, llfn={})", debug!("decl_rust_fn_with_foreign_abi(llfn_ty={:?}, llfn={:?})",
ccx.tn().type_to_string(llfn_ty), ccx.tn().val_to_string(llfn)); llfn_ty, Value(llfn));
llfn llfn
} }
@ -585,8 +582,8 @@ pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext,
let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys); let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys);
let llfn = base::register_fn_llvmty(ccx, sp, sym, node_id, cconv, llfn_ty); let llfn = base::register_fn_llvmty(ccx, sp, sym, node_id, cconv, llfn_ty);
add_argument_attributes(&tys, llfn); add_argument_attributes(&tys, llfn);
debug!("register_rust_fn_with_foreign_abi(node_id={}, llfn_ty={}, llfn={})", debug!("register_rust_fn_with_foreign_abi(node_id={}, llfn_ty={:?}, llfn={:?})",
node_id, ccx.tn().type_to_string(llfn_ty), ccx.tn().val_to_string(llfn)); node_id, llfn_ty, Value(llfn));
llfn llfn
} }
@ -667,9 +664,9 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
let _icx = push_ctxt( let _icx = push_ctxt(
"foreign::trans_rust_fn_with_foreign_abi::build_wrap_fn"); "foreign::trans_rust_fn_with_foreign_abi::build_wrap_fn");
debug!("build_wrap_fn(llrustfn={}, llwrapfn={}, t={:?})", debug!("build_wrap_fn(llrustfn={:?}, llwrapfn={:?}, t={:?})",
ccx.tn().val_to_string(llrustfn), Value(llrustfn),
ccx.tn().val_to_string(llwrapfn), Value(llwrapfn),
t); t);
// Avoid all the Rust generation stuff and just generate raw // Avoid all the Rust generation stuff and just generate raw
@ -737,12 +734,12 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// alloca some scratch space on the stack. // alloca some scratch space on the stack.
match foreign_outptr { match foreign_outptr {
Some(llforeign_outptr) => { Some(llforeign_outptr) => {
debug!("out pointer, foreign={}", debug!("out pointer, foreign={:?}",
ccx.tn().val_to_string(llforeign_outptr)); Value(llforeign_outptr));
let llrust_retptr = let llrust_retptr =
builder.bitcast(llforeign_outptr, llrust_ret_ty.ptr_to()); builder.bitcast(llforeign_outptr, llrust_ret_ty.ptr_to());
debug!("out pointer, foreign={} (casted)", debug!("out pointer, foreign={:?} (casted)",
ccx.tn().val_to_string(llrust_retptr)); Value(llrust_retptr));
llrust_args.push(llrust_retptr); llrust_args.push(llrust_retptr);
return_alloca = None; return_alloca = None;
} }
@ -750,11 +747,11 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
None => { None => {
let slot = builder.alloca(llrust_ret_ty, "return_alloca"); let slot = builder.alloca(llrust_ret_ty, "return_alloca");
debug!("out pointer, \ debug!("out pointer, \
allocad={}, \ allocad={:?}, \
llrust_ret_ty={}, \ llrust_ret_ty={:?}, \
return_ty={:?}", return_ty={:?}",
ccx.tn().val_to_string(slot), Value(slot),
ccx.tn().type_to_string(llrust_ret_ty), llrust_ret_ty,
tys.fn_sig.output); tys.fn_sig.output);
llrust_args.push(slot); llrust_args.push(slot);
return_alloca = Some(slot); return_alloca = Some(slot);
@ -792,8 +789,8 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
let foreign_index = next_foreign_arg(llforeign_arg_ty.pad.is_some()); let foreign_index = next_foreign_arg(llforeign_arg_ty.pad.is_some());
let mut llforeign_arg = get_param(llwrapfn, foreign_index); let mut llforeign_arg = get_param(llwrapfn, foreign_index);
debug!("llforeign_arg {}{}: {}", "#", debug!("llforeign_arg {}{}: {:?}", "#",
i, ccx.tn().val_to_string(llforeign_arg)); i, Value(llforeign_arg));
debug!("rust_indirect = {}, foreign_indirect = {}", debug!("rust_indirect = {}, foreign_indirect = {}",
rust_indirect, foreign_indirect); rust_indirect, foreign_indirect);
@ -840,8 +837,8 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
} }
}; };
debug!("llrust_arg {}{}: {}", "#", debug!("llrust_arg {}{}: {:?}", "#",
i, ccx.tn().val_to_string(llrust_arg)); i, Value(llrust_arg));
if type_is_fat_ptr(ccx.tcx(), rust_ty) { if type_is_fat_ptr(ccx.tcx(), rust_ty) {
let next_llrust_ty = rust_param_tys.next().expect("Not enough parameter types!"); let next_llrust_ty = rust_param_tys.next().expect("Not enough parameter types!");
llrust_args.push(builder.load(builder.bitcast(builder.struct_gep( llrust_args.push(builder.load(builder.bitcast(builder.struct_gep(
@ -854,8 +851,8 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
} }
// Perform the call itself // Perform the call itself
debug!("calling llrustfn = {}, t = {:?}", debug!("calling llrustfn = {:?}, t = {:?}",
ccx.tn().val_to_string(llrustfn), t); Value(llrustfn), t);
let attributes = attributes::from_fn_type(ccx, t); let attributes = attributes::from_fn_type(ccx, t);
let llrust_ret_val = builder.call(llrustfn, &llrust_args, let llrust_ret_val = builder.call(llrustfn, &llrust_args,
None, Some(attributes)); None, Some(attributes));
@ -971,14 +968,14 @@ fn foreign_types_for_fn_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
llsig.ret_def); llsig.ret_def);
debug!("foreign_types_for_fn_ty(\ debug!("foreign_types_for_fn_ty(\
ty={:?}, \ ty={:?}, \
llsig={} -> {}, \ llsig={:?} -> {:?}, \
fn_ty={} -> {}, \ fn_ty={:?} -> {:?}, \
ret_def={}", ret_def={}",
ty, ty,
ccx.tn().types_to_str(&llsig.llarg_tys), llsig.llarg_tys,
ccx.tn().type_to_string(llsig.llret_ty), llsig.llret_ty,
ccx.tn().types_to_str(&fn_ty.arg_tys.iter().map(|t| t.ty).collect::<Vec<_>>()), fn_ty.arg_tys,
ccx.tn().type_to_string(fn_ty.ret_ty.ty), fn_ty.ret_ty,
llsig.ret_def); llsig.ret_def);
ForeignTypes { ForeignTypes {

View file

@ -37,6 +37,7 @@ use trans::machine::*;
use trans::monomorphize; use trans::monomorphize;
use trans::type_of::{type_of, sizing_type_of, align_of}; use trans::type_of::{type_of, sizing_type_of, align_of};
use trans::type_::Type; use trans::type_::Type;
use trans::value::Value;
use arena::TypedArena; use arena::TypedArena;
use libc::c_uint; use libc::c_uint;
@ -374,14 +375,14 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
pub fn size_and_align_of_dst<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, info: ValueRef) pub fn size_and_align_of_dst<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, info: ValueRef)
-> (ValueRef, ValueRef) { -> (ValueRef, ValueRef) {
debug!("calculate size of DST: {}; with lost info: {}", debug!("calculate size of DST: {}; with lost info: {:?}",
t, bcx.val_to_string(info)); t, Value(info));
if type_is_sized(bcx.tcx(), t) { if type_is_sized(bcx.tcx(), t) {
let sizing_type = sizing_type_of(bcx.ccx(), t); let sizing_type = sizing_type_of(bcx.ccx(), t);
let size = llsize_of_alloc(bcx.ccx(), sizing_type); let size = llsize_of_alloc(bcx.ccx(), sizing_type);
let align = align_of(bcx.ccx(), t); let align = align_of(bcx.ccx(), t);
debug!("size_and_align_of_dst t={} info={} size: {} align: {}", debug!("size_and_align_of_dst t={} info={:?} size: {} align: {}",
t, bcx.val_to_string(info), size, align); t, Value(info), size, align);
let size = C_uint(bcx.ccx(), size); let size = C_uint(bcx.ccx(), size);
let align = C_uint(bcx.ccx(), align); let align = C_uint(bcx.ccx(), align);
return (size, align); return (size, align);
@ -394,7 +395,7 @@ pub fn size_and_align_of_dst<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, in
assert!(!t.is_simd()); assert!(!t.is_simd());
let repr = adt::represent_type(ccx, t); let repr = adt::represent_type(ccx, t);
let sizing_type = adt::sizing_type_context_of(ccx, &repr, true); let sizing_type = adt::sizing_type_context_of(ccx, &repr, true);
debug!("DST {} sizing_type: {}", t, sizing_type.to_string()); debug!("DST {} sizing_type: {:?}", t, sizing_type);
let sized_size = llsize_of_alloc(ccx, sizing_type.prefix()); let sized_size = llsize_of_alloc(ccx, sizing_type.prefix());
let sized_align = llalign_of_min(ccx, sizing_type.prefix()); let sized_align = llalign_of_min(ccx, sizing_type.prefix());
debug!("DST {} statically sized prefix size: {} align: {}", debug!("DST {} statically sized prefix size: {} align: {}",

View file

@ -1552,7 +1552,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
let indices: Option<Vec<_>> = (0..n) let indices: Option<Vec<_>> = (0..n)
.map(|i| { .map(|i| {
let arg_idx = i; let arg_idx = i;
let val = const_get_elt(bcx.ccx(), vector, &[i as libc::c_uint]); let val = const_get_elt(vector, &[i as libc::c_uint]);
let c = const_to_opt_uint(val); let c = const_to_opt_uint(val);
match c { match c {
None => { None => {

View file

@ -1,36 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use trans::context::CrateContext;
use trans::type_::Type;
use llvm::ValueRef;
pub trait LlvmRepr {
fn llrepr(&self, ccx: &CrateContext) -> String;
}
impl<T:LlvmRepr> LlvmRepr for [T] {
fn llrepr(&self, ccx: &CrateContext) -> String {
let reprs: Vec<String> = self.iter().map(|t| t.llrepr(ccx)).collect();
format!("[{}]", reprs.join(","))
}
}
impl LlvmRepr for Type {
fn llrepr(&self, ccx: &CrateContext) -> String {
ccx.tn().type_to_string(*self)
}
}
impl LlvmRepr for ValueRef {
fn llrepr(&self, ccx: &CrateContext) -> String {
ccx.tn().val_to_string(*self)
}
}

View file

@ -33,6 +33,7 @@ use trans::glue;
use trans::machine; use trans::machine;
use trans::type_::Type; use trans::type_::Type;
use trans::type_of::*; use trans::type_of::*;
use trans::value::Value;
use middle::ty::{self, Ty, TyCtxt, TypeFoldable}; use middle::ty::{self, Ty, TyCtxt, TypeFoldable};
use syntax::ast::{self, Name}; use syntax::ast::{self, Name};
@ -171,10 +172,8 @@ pub fn get_virtual_method<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let ccx = bcx.ccx(); let ccx = bcx.ccx();
// Load the data pointer from the object. // Load the data pointer from the object.
debug!("get_virtual_method(callee_ty={}, vtable_index={}, llvtable={})", debug!("get_virtual_method(callee_ty={}, vtable_index={}, llvtable={:?})",
method_ty, method_ty, vtable_index, Value(llvtable));
vtable_index,
bcx.val_to_string(llvtable));
let mptr = Load(bcx, GEPi(bcx, llvtable, &[vtable_index + VTABLE_OFFSET])); let mptr = Load(bcx, GEPi(bcx, llvtable, &[vtable_index + VTABLE_OFFSET]));
@ -250,8 +249,8 @@ pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
let llself = llargs[self_idx]; let llself = llargs[self_idx];
let llvtable = llargs[self_idx + 1]; let llvtable = llargs[self_idx + 1];
debug!("trans_object_shim: llself={}, llvtable={}", debug!("trans_object_shim: llself={:?}, llvtable={:?}",
bcx.val_to_string(llself), bcx.val_to_string(llvtable)); Value(llself), Value(llvtable));
assert!(!fcx.needs_ret_allocas); assert!(!fcx.needs_ret_allocas);

View file

@ -38,8 +38,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
let val = if common::type_is_immediate(ccx, ty) { let val = if common::type_is_immediate(ccx, ty) {
OperandValue::Immediate(val) OperandValue::Immediate(val)
} else if common::type_is_fat_ptr(bcx.tcx(), ty) { } else if common::type_is_fat_ptr(bcx.tcx(), ty) {
let data = common::const_get_elt(ccx, val, &[abi::FAT_PTR_ADDR as u32]); let data = common::const_get_elt(val, &[abi::FAT_PTR_ADDR as u32]);
let extra = common::const_get_elt(ccx, val, &[abi::FAT_PTR_EXTRA as u32]); let extra = common::const_get_elt(val, &[abi::FAT_PTR_EXTRA as u32]);
OperandValue::FatPtr(data, extra) OperandValue::FatPtr(data, extra)
} else { } else {
OperandValue::Ref(val) OperandValue::Ref(val)

View file

@ -15,9 +15,12 @@ use trans::adt;
use trans::base; use trans::base;
use trans::common::{self, Block, BlockAndBuilder}; use trans::common::{self, Block, BlockAndBuilder};
use trans::datum; use trans::datum;
use trans::value::Value;
use trans::Disr; use trans::Disr;
use trans::glue; use trans::glue;
use std::fmt;
use super::{MirContext, TempRef, drop}; use super::{MirContext, TempRef, drop};
use super::lvalue::LvalueRef; use super::lvalue::LvalueRef;
@ -53,6 +56,25 @@ pub struct OperandRef<'tcx> {
pub ty: Ty<'tcx> pub ty: Ty<'tcx>
} }
impl<'tcx> fmt::Debug for OperandRef<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.val {
OperandValue::Ref(r) => {
write!(f, "OperandRef(Ref({:?}) @ {:?})",
Value(r), self.ty)
}
OperandValue::Immediate(i) => {
write!(f, "OperandRef(Immediate({:?}) @ {:?})",
Value(i), self.ty)
}
OperandValue::FatPtr(a, d) => {
write!(f, "OperandRef(FatPtr({:?}, {:?}) @ {:?})",
Value(a), Value(d), self.ty)
}
}
}
}
impl<'tcx> OperandRef<'tcx> { impl<'tcx> OperandRef<'tcx> {
/// Asserts that this operand refers to a scalar and returns /// Asserts that this operand refers to a scalar and returns
/// a reference to its value. /// a reference to its value.
@ -63,25 +85,6 @@ impl<'tcx> OperandRef<'tcx> {
} }
} }
pub fn repr<'bcx>(self, bcx: &BlockAndBuilder<'bcx, 'tcx>) -> String {
match self.val {
OperandValue::Ref(r) => {
format!("OperandRef(Ref({}) @ {:?})",
bcx.val_to_string(r), self.ty)
}
OperandValue::Immediate(i) => {
format!("OperandRef(Immediate({}) @ {:?})",
bcx.val_to_string(i), self.ty)
}
OperandValue::FatPtr(a, d) => {
format!("OperandRef(FatPtr({}, {}) @ {:?})",
bcx.val_to_string(a),
bcx.val_to_string(d),
self.ty)
}
}
}
pub fn from_rvalue_datum(datum: datum::Datum<'tcx, datum::Rvalue>) -> OperandRef { pub fn from_rvalue_datum(datum: datum::Datum<'tcx, datum::Rvalue>) -> OperandRef {
OperandRef { OperandRef {
ty: datum.ty, ty: datum.ty,
@ -100,7 +103,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
ty: Ty<'tcx>) ty: Ty<'tcx>)
-> OperandRef<'tcx> -> OperandRef<'tcx>
{ {
debug!("trans_load: {} @ {:?}", bcx.val_to_string(llval), ty); debug!("trans_load: {:?} @ {:?}", Value(llval), ty);
let val = match datum::appropriate_rvalue_mode(bcx.ccx(), ty) { let val = match datum::appropriate_rvalue_mode(bcx.ccx(), ty) {
datum::ByValue => { datum::ByValue => {
@ -164,7 +167,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
lldest: ValueRef, lldest: ValueRef,
operand: OperandRef<'tcx>) operand: OperandRef<'tcx>)
{ {
debug!("store_operand: operand={}", operand.repr(bcx)); debug!("store_operand: operand={:?}", operand);
bcx.with_block(|bcx| self.store_operand_direct(bcx, lldest, operand)) bcx.with_block(|bcx| self.store_operand_direct(bcx, lldest, operand))
} }

View file

@ -27,6 +27,7 @@ use trans::machine;
use trans::type_::Type; use trans::type_::Type;
use trans::type_of; use trans::type_of;
use trans::tvec; use trans::tvec;
use trans::value::Value;
use trans::Disr; use trans::Disr;
use super::MirContext; use super::MirContext;
@ -40,9 +41,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
rvalue: &mir::Rvalue<'tcx>) rvalue: &mir::Rvalue<'tcx>)
-> BlockAndBuilder<'bcx, 'tcx> -> BlockAndBuilder<'bcx, 'tcx>
{ {
debug!("trans_rvalue(dest.llval={}, rvalue={:?})", debug!("trans_rvalue(dest.llval={:?}, rvalue={:?})",
bcx.val_to_string(dest.llval), Value(dest.llval), rvalue);
rvalue);
match *rvalue { match *rvalue {
mir::Rvalue::Use(ref operand) => { mir::Rvalue::Use(ref operand) => {
@ -193,7 +193,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
match *rvalue { match *rvalue {
mir::Rvalue::Cast(ref kind, ref operand, cast_ty) => { mir::Rvalue::Cast(ref kind, ref operand, cast_ty) => {
let operand = self.trans_operand(&bcx, operand); let operand = self.trans_operand(&bcx, operand);
debug!("cast operand is {}", operand.repr(&bcx)); debug!("cast operand is {:?}", operand);
let cast_ty = bcx.monomorphize(&cast_ty); let cast_ty = bcx.monomorphize(&cast_ty);
let val = match *kind { let val = match *kind {
@ -237,8 +237,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
} }
OperandValue::Ref(_) => { OperandValue::Ref(_) => {
bcx.sess().bug( bcx.sess().bug(
&format!("by-ref operand {} in trans_rvalue_operand", &format!("by-ref operand {:?} in trans_rvalue_operand",
operand.repr(&bcx))); operand));
} }
} }
} }

View file

@ -53,7 +53,6 @@ mod foreign;
mod glue; mod glue;
mod inline; mod inline;
mod intrinsic; mod intrinsic;
mod llrepr;
mod machine; mod machine;
mod _match; mod _match;
mod meth; mod meth;

View file

@ -26,6 +26,7 @@ use trans::expr;
use trans::machine::llsize_of_alloc; use trans::machine::llsize_of_alloc;
use trans::type_::Type; use trans::type_::Type;
use trans::type_of; use trans::type_of;
use trans::value::Value;
use middle::ty::{self, Ty}; use middle::ty::{self, Ty};
use rustc_front::hir; use rustc_front::hir;
@ -33,20 +34,12 @@ use rustc_front::hir;
use syntax::ast; use syntax::ast;
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
#[derive(Copy, Clone)] #[derive(Copy, Clone, Debug)]
struct VecTypes<'tcx> { struct VecTypes<'tcx> {
unit_ty: Ty<'tcx>, unit_ty: Ty<'tcx>,
llunit_ty: Type llunit_ty: Type
} }
impl<'tcx> VecTypes<'tcx> {
pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String {
format!("VecTypes {{unit_ty={}, llunit_ty={}}}",
self.unit_ty,
ccx.tn().type_to_string(self.llunit_ty))
}
}
pub fn trans_fixed_vstore<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pub fn trans_fixed_vstore<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
expr: &hir::Expr, expr: &hir::Expr,
dest: expr::Dest) dest: expr::Dest)
@ -58,8 +51,7 @@ pub fn trans_fixed_vstore<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// to store the array of the suitable size, so all we have to do is // to store the array of the suitable size, so all we have to do is
// generate the content. // generate the content.
debug!("trans_fixed_vstore(expr={:?}, dest={})", debug!("trans_fixed_vstore(expr={:?}, dest={:?})", expr, dest);
expr, dest.to_string(bcx.ccx()));
let vt = vec_types_from_expr(bcx, expr); let vt = vec_types_from_expr(bcx, expr);
@ -82,7 +74,6 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
content_expr: &hir::Expr) content_expr: &hir::Expr)
-> DatumBlock<'blk, 'tcx, Expr> { -> DatumBlock<'blk, 'tcx, Expr> {
let fcx = bcx.fcx; let fcx = bcx.fcx;
let ccx = fcx.ccx;
let mut bcx = bcx; let mut bcx = bcx;
debug!("trans_slice_vec(slice_expr={:?})", debug!("trans_slice_vec(slice_expr={:?})",
@ -105,7 +96,7 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// Handle the &[...] case: // Handle the &[...] case:
let vt = vec_types_from_expr(bcx, content_expr); let vt = vec_types_from_expr(bcx, content_expr);
let count = elements_required(bcx, content_expr); let count = elements_required(bcx, content_expr);
debug!(" vt={}, count={}", vt.to_string(ccx), count); debug!(" vt={:?}, count={}", vt, count);
let fixed_ty = bcx.tcx().mk_array(vt.unit_ty, count); let fixed_ty = bcx.tcx().mk_array(vt.unit_ty, count);
@ -144,9 +135,7 @@ pub fn trans_lit_str<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
str_lit: InternedString, str_lit: InternedString,
dest: Dest) dest: Dest)
-> Block<'blk, 'tcx> { -> Block<'blk, 'tcx> {
debug!("trans_lit_str(lit_expr={:?}, dest={})", debug!("trans_lit_str(lit_expr={:?}, dest={:?})", lit_expr, dest);
lit_expr,
dest.to_string(bcx.ccx()));
match dest { match dest {
Ignore => bcx, Ignore => bcx,
@ -172,10 +161,8 @@ fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let fcx = bcx.fcx; let fcx = bcx.fcx;
let mut bcx = bcx; let mut bcx = bcx;
debug!("write_content(vt={}, dest={}, vstore_expr={:?})", debug!("write_content(vt={:?}, dest={:?}, vstore_expr={:?})",
vt.to_string(bcx.ccx()), vt, dest, vstore_expr);
dest.to_string(bcx.ccx()),
vstore_expr);
match content_expr.node { match content_expr.node {
hir::ExprLit(ref lit) => { hir::ExprLit(ref lit) => {
@ -214,8 +201,8 @@ fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let temp_scope = fcx.push_custom_cleanup_scope(); let temp_scope = fcx.push_custom_cleanup_scope();
for (i, element) in elements.iter().enumerate() { for (i, element) in elements.iter().enumerate() {
let lleltptr = GEPi(bcx, lldest, &[i]); let lleltptr = GEPi(bcx, lldest, &[i]);
debug!("writing index {} with lleltptr={}", debug!("writing index {} with lleltptr={:?}",
i, bcx.val_to_string(lleltptr)); i, Value(lleltptr));
bcx = expr::trans_into(bcx, &element, bcx = expr::trans_into(bcx, &element,
SaveIn(lleltptr)); SaveIn(lleltptr));
let scope = cleanup::CustomScope(temp_scope); let scope = cleanup::CustomScope(temp_scope);

View file

@ -11,7 +11,7 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use llvm; use llvm;
use llvm::{TypeRef, Bool, False, True, TypeKind, ValueRef}; use llvm::{TypeRef, Bool, False, True, TypeKind};
use llvm::{Float, Double, X86_FP80, PPC_FP128, FP128}; use llvm::{Float, Double, X86_FP80, PPC_FP128, FP128};
use trans::context::CrateContext; use trans::context::CrateContext;
@ -20,18 +20,27 @@ use util::nodemap::FnvHashMap;
use syntax::ast; use syntax::ast;
use std::ffi::CString; use std::ffi::CString;
use std::fmt;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use std::cell::RefCell; use std::cell::RefCell;
use libc::c_uint; use libc::c_uint;
#[derive(Clone, Copy, PartialEq, Debug)] #[derive(Clone, Copy, PartialEq)]
#[repr(C)] #[repr(C)]
pub struct Type { pub struct Type {
rf: TypeRef rf: TypeRef
} }
impl fmt::Debug for Type {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&llvm::build_string(|s| unsafe {
llvm::LLVMWriteTypeToString(self.to_ref(), s);
}).expect("non-UTF8 type description from LLVM"))
}
}
macro_rules! ty { macro_rules! ty {
($e:expr) => ( Type::from_ref(unsafe { $e })) ($e:expr) => ( Type::from_ref(unsafe { $e }))
} }
@ -50,12 +59,6 @@ impl Type {
self.rf self.rf
} }
pub fn to_string(self: Type) -> String {
llvm::build_string(|s| unsafe {
llvm::LLVMWriteTypeToString(self.to_ref(), s);
}).expect("non-UTF8 type description from LLVM")
}
pub fn to_ref_slice(slice: &[Type]) -> &[TypeRef] { pub fn to_ref_slice(slice: &[Type]) -> &[TypeRef] {
unsafe { mem::transmute(slice) } unsafe { mem::transmute(slice) }
} }
@ -301,7 +304,6 @@ impl Type {
} }
} }
/* Memory-managed object interface to type handles. */ /* Memory-managed object interface to type handles. */
pub struct TypeNames { pub struct TypeNames {
@ -323,19 +325,4 @@ impl TypeNames {
pub fn find_type(&self, s: &str) -> Option<Type> { pub fn find_type(&self, s: &str) -> Option<Type> {
self.named_types.borrow().get(s).map(|x| Type::from_ref(*x)) self.named_types.borrow().get(s).map(|x| Type::from_ref(*x))
} }
pub fn type_to_string(&self, ty: Type) -> String {
ty.to_string()
}
pub fn types_to_str(&self, tys: &[Type]) -> String {
let strs: Vec<String> = tys.iter().map(|t| self.type_to_string(*t)).collect();
format!("[{}]", strs.join(","))
}
pub fn val_to_string(&self, val: ValueRef) -> String {
llvm::build_string(|s| unsafe {
llvm::LLVMWriteValueToString(val, s);
}).expect("nun-UTF8 value description from LLVM")
}
} }

View file

@ -234,9 +234,7 @@ pub fn sizing_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Typ
ty::TySlice(_) | ty::TyTrait(..) | ty::TyStr => unreachable!() ty::TySlice(_) | ty::TyTrait(..) | ty::TyStr => unreachable!()
}; };
debug!("--> mapped t={:?} to llsizingty={}", debug!("--> mapped t={:?} to llsizingty={:?}", t, llsizingty);
t,
cx.tn().type_to_string(llsizingty));
cx.llsizingtypes().borrow_mut().insert(t, llsizingty); cx.llsizingtypes().borrow_mut().insert(t, llsizingty);
llsizingty llsizingty
@ -314,12 +312,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
if t != t_norm { if t != t_norm {
let llty = in_memory_type_of(cx, t_norm); let llty = in_memory_type_of(cx, t_norm);
debug!("--> normalized {:?} {:?} to {:?} {:?} llty={}", debug!("--> normalized {:?} to {:?} llty={:?}", t, t_norm, llty);
t,
t,
t_norm,
t_norm,
cx.tn().type_to_string(llty));
cx.lltypes().borrow_mut().insert(t, llty); cx.lltypes().borrow_mut().insert(t, llty);
return llty; return llty;
} }
@ -440,9 +433,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
ty::TyError => cx.sess().bug("type_of with TyError"), ty::TyError => cx.sess().bug("type_of with TyError"),
}; };
debug!("--> mapped t={:?} to llty={}", debug!("--> mapped t={:?} to llty={:?}", t, llty);
t,
cx.tn().type_to_string(llty));
cx.lltypes().borrow_mut().insert(t, llty); cx.lltypes().borrow_mut().insert(t, llty);

View file

@ -12,11 +12,22 @@ use llvm;
use llvm::{UseRef, ValueRef}; use llvm::{UseRef, ValueRef};
use trans::basic_block::BasicBlock; use trans::basic_block::BasicBlock;
use trans::common::Block; use trans::common::Block;
use std::fmt;
use libc::c_uint; use libc::c_uint;
#[derive(Copy, Clone)] #[derive(Copy, Clone, PartialEq)]
pub struct Value(pub ValueRef); pub struct Value(pub ValueRef);
impl fmt::Debug for Value {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&llvm::build_string(|s| unsafe {
llvm::LLVMWriteValueToString(self.0, s);
}).expect("nun-UTF8 value description from LLVM"))
}
}
macro_rules! opt_val { ($e:expr) => ( macro_rules! opt_val { ($e:expr) => (
unsafe { unsafe {
match $e { match $e {