about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-08-10 12:55:29 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-08-10 14:35:12 -0700
commitadce35acd481d6ecc087c5957601b0a680e936a8 (patch)
tree372b8b1a985ce9ac10bffaf159867743ad22c3ee /src/comp
parent40ae704ff2fc419c162527345bad63dd06394afe (diff)
downloadrust-adce35acd481d6ecc087c5957601b0a680e936a8.tar.gz
rust-adce35acd481d6ecc087c5957601b0a680e936a8.zip
rustc: Use polymorphic logging
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/back/upcall.rs17
-rw-r--r--src/comp/middle/trans.rs50
-rw-r--r--src/comp/middle/trans_dps.rs64
3 files changed, 26 insertions, 105 deletions
diff --git a/src/comp/back/upcall.rs b/src/comp/back/upcall.rs
index ee59a05f620..fc84dd4fefe 100644
--- a/src/comp/back/upcall.rs
+++ b/src/comp/back/upcall.rs
@@ -26,11 +26,6 @@ import lib::llvm::llvm::TypeRef;
 
 type upcalls =
     {grow_task: ValueRef,
-     log_int: ValueRef,
-     log_float: ValueRef,
-     log_double: ValueRef,
-     log_str: ValueRef,
-     log_istr: ValueRef,
      trace_word: ValueRef,
      trace_str: ValueRef,
      new_port: ValueRef,
@@ -67,7 +62,8 @@ type upcalls =
      ivec_spill: ValueRef,
      ivec_resize_shared: ValueRef,
      ivec_spill_shared: ValueRef,
-     cmp_type: ValueRef};
+     cmp_type: ValueRef,
+     log_type: ValueRef};
 
 fn declare_upcalls(tn: type_names, tydesc_type: TypeRef,
                    taskptr_type: TypeRef, llmod: ModuleRef) -> @upcalls {
@@ -89,11 +85,6 @@ fn declare_upcalls(tn: type_names, tydesc_type: TypeRef,
 
     let empty_vec: [TypeRef] = ~[];
     ret @{grow_task: dv("grow_task", ~[T_size_t()]),
-          log_int: dv("log_int", ~[T_i32(), T_i32()]),
-          log_float: dv("log_float", ~[T_i32(), T_f32()]),
-          log_double: dv("log_double", ~[T_i32(), T_ptr(T_f64())]),
-          log_str: dv("log_str", ~[T_i32(), T_ptr(T_str())]),
-          log_istr: dv("log_istr", ~[T_i32(), T_ptr(T_ivec(T_i8()))]),
           trace_word: dv("trace_word", ~[T_int()]),
           trace_str: dv("trace_str", ~[T_ptr(T_i8())]),
           new_port: d("new_port", ~[T_size_t()], T_opaque_port_ptr()),
@@ -159,6 +150,10 @@ fn declare_upcalls(tn: type_names, tydesc_type: TypeRef,
               dr("cmp_type", ~[T_ptr(T_i1()), taskptr_type,
                  T_ptr(tydesc_type), T_ptr(T_ptr(tydesc_type)),
                  T_ptr(T_i8()), T_ptr(T_i8()), T_i8()],
+                 T_void()),
+          log_type:
+              dr("log_type", ~[taskptr_type, T_ptr(tydesc_type),
+                 T_ptr(T_i8()), T_i32()],
                  T_void())};
 }
 //
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 794da1590c1..6167bbcbe73 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -5190,48 +5190,18 @@ fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result {
     let sub = trans_expr(log_cx, e);
     let e_ty = ty::expr_ty(bcx_tcx(cx), e);
     let log_bcx = sub.bcx;
-    if ty::type_is_fp(bcx_tcx(cx), e_ty) {
-        let tr: TypeRef;
-        let is32bit: bool = false;
-        alt ty::struct(bcx_tcx(cx), e_ty) {
-          ty::ty_machine(ast::ty_f32.) { tr = T_f32(); is32bit = true; }
-          ty::ty_machine(ast::ty_f64.) { tr = T_f64(); }
-          _ { tr = T_float(); }
-        }
-        if is32bit {
-            log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_float,
-                               ~[log_bcx.fcx.lltaskptr, C_int(lvl), sub.val]);
-        } else {
-            // FIXME: Eliminate this level of indirection.
 
-            let tmp = alloca(log_bcx, tr);
-            sub.bcx.build.Store(sub.val, tmp);
-            log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_double,
-                               ~[log_bcx.fcx.lltaskptr, C_int(lvl), tmp]);
-        }
-    } else if (ty::type_is_integral(bcx_tcx(cx), e_ty) ||
-                   ty::type_is_bool(bcx_tcx(cx), e_ty)) {
-        // FIXME: Handle signedness properly.
-
-        let llintval =
-            int_cast(log_bcx, T_int(), val_ty(sub.val), sub.val, false);
-        log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_int,
-                           ~[log_bcx.fcx.lltaskptr, C_int(lvl), llintval]);
-    } else {
-        alt ty::struct(bcx_tcx(cx), e_ty) {
-          ty::ty_str. {
-            log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_str,
-                               ~[log_bcx.fcx.lltaskptr, C_int(lvl), sub.val]);
-          }
-          _ {
-            // FIXME: Support these types.
+    let ti = none[@tydesc_info];
+    let r = get_tydesc(log_bcx, e_ty, false, ti);
+    log_bcx = r.bcx;
+
+    // Call the polymorphic log function.
+    let llvalptr = spill_if_immediate(log_bcx, sub.val, e_ty);
+    let llval_i8 = log_bcx.build.PointerCast(llvalptr, T_ptr(T_i8()));
+
+    log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_type,
+                       ~[log_bcx.fcx.lltaskptr, r.val, llval_i8, C_int(lvl)]);
 
-            bcx_ccx(cx).sess.span_fatal(e.span,
-                                        "log called on unsupported type " +
-                                            ty_to_str(bcx_tcx(cx), e_ty));
-          }
-        }
-    }
     log_bcx = trans_block_cleanups(log_bcx, log_cx);
     log_bcx.build.Br(after_cx.llbb);
     ret rslt(after_cx, C_nil());
diff --git a/src/comp/middle/trans_dps.rs b/src/comp/middle/trans_dps.rs
index d59c07a7cd8..80590466c03 100644
--- a/src/comp/middle/trans_dps.rs
+++ b/src/comp/middle/trans_dps.rs
@@ -343,36 +343,6 @@ fn trans_log(cx: &@block_ctxt, sp: &span, level: int, expr: &@ast::expr) ->
         ret lllevelptr;
     }
 
-    tag upcall_style { us_imm; us_imm_i32_zext; us_alias; us_alias_istr; }
-    fn get_upcall(ccx: &@crate_ctxt, sp: &span, t: ty::t) ->
-       {val: ValueRef, st: upcall_style} {
-        alt ty::struct(ccx_tcx(ccx), t) {
-          ty::ty_machine(ast::ty_f32.) {
-            ret {val: ccx.upcalls.log_float, st: us_imm};
-          }
-          ty::ty_machine(ast::ty_f64.) | ty::ty_float. {
-            // TODO: We have to spill due to legacy calling conventions that
-            // should probably be modernized.
-            ret {val: ccx.upcalls.log_double, st: us_alias};
-          }
-          ty::ty_bool. | ty::ty_machine(ast::ty_i8.) |
-          ty::ty_machine(ast::ty_i16.) | ty::ty_machine(ast::ty_u8.) |
-          ty::ty_machine(ast::ty_u16.) {
-            ret {val: ccx.upcalls.log_int, st: us_imm_i32_zext};
-          }
-          ty::ty_int. | ty::ty_machine(ast::ty_i32.) |
-          ty::ty_machine(ast::ty_u32.) {
-            ret {val: ccx.upcalls.log_int, st: us_imm};
-          }
-          ty::ty_istr. { ret {val: ccx.upcalls.log_istr, st: us_alias_istr}; }
-          _ {
-            ccx.sess.span_unimpl(sp,
-                                 "logging for values of type " +
-                                     ppaux::ty_to_str(ccx_tcx(ccx), t));
-          }
-        }
-    }
-
     let bcx = cx;
 
     let lllevelptr = trans_log_level(bcx_lcx(bcx));
@@ -386,34 +356,20 @@ fn trans_log(cx: &@block_ctxt, sp: &span, level: int, expr: &@ast::expr) ->
     bcx.build.CondBr(should_log, log_bcx.llbb, next_bcx.llbb);
 
     let expr_t = ty::expr_ty(bcx_tcx(log_bcx), expr);
-    let r = get_upcall(bcx_ccx(bcx), sp, expr_t);
-    let llupcall = r.val;
-    let style = r.st;
-
-    let arg_dest;
-    alt style {
-      us_imm. | us_imm_i32_zext. {
-        arg_dest = dest_imm(bcx_tcx(log_bcx), expr_t);
-      }
-      us_alias. | us_alias_istr. {
-        arg_dest = dest_alias(bcx_tcx(log_bcx), expr_t);
-      }
-    }
+    let arg_dest = dest_alias(bcx_tcx(log_bcx), expr_t);
     log_bcx = trans_expr(log_bcx, arg_dest, expr);
 
     let llarg = dest_llval(arg_dest);
-    alt style {
-      us_imm. | us_alias. {/* no-op */ }
-      us_imm_i32_zext. { llarg = log_bcx.build.ZExt(llarg, tc::T_i32()); }
-      us_alias_istr. {
-        llarg =
-            log_bcx.build.PointerCast(llarg,
-                                      tc::T_ptr(tc::T_ivec(tc::T_i8())));
-      }
-    }
+    let llarg_i8 = bcx.build.PointerCast(llarg, T_ptr(T_i8()));
+
+    let ti = none;
+    let r2 = trans::get_tydesc(bcx, expr_t, false, ti);
+    bcx = r2.bcx;
+    let lltydesc = r2.val;
 
-    log_bcx.build.Call(llupcall,
-                       ~[bcx_fcx(bcx).lltaskptr, tc::C_int(level), llarg]);
+    log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_type,
+                       ~[bcx_fcx(bcx).lltaskptr, lltydesc, llarg_i8,
+                         tc::C_int(level)]);
 
     log_bcx =
         trans::trans_block_cleanups(log_bcx, tc::find_scope_cx(log_bcx));