about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-04-05 21:21:32 +0000
committerGraydon Hoare <graydon@mozilla.com>2011-04-05 21:52:48 +0000
commit8703c8067fb8a22ec9b296efea162aac3e7f9521 (patch)
treec83079b978da5eb7db59ba80810c96bdfeb71099
parent361ee5a68bf23c9fc65aee39618b5d1b0db4941b (diff)
FIx native wrapper generation to handle more arg types.
-rw-r--r--src/comp/middle/trans.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 1ab8a18d9ef..6e3550bde35 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -6148,7 +6148,7 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
     auto arg_n = 3u;
     auto pass_task;
 
-    auto lltaskptr = bcx.build.PtrToInt(fcx.lltaskptr, T_int());
+    auto lltaskptr = vp2i(bcx, fcx.lltaskptr);
     alt (abi) {
         case (ast.native_abi_rust) {
             pass_task = true;
@@ -6156,7 +6156,7 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
             for each (uint i in _uint.range(0u, num_ty_param)) {
                 auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
                 check (llarg as int != 0);
-                call_args += vec(bcx.build.PointerCast(llarg, T_i32()));
+                call_args += vec(vp2i(bcx, llarg));
                 arg_n += 1u;
             }
         }
@@ -6169,6 +6169,26 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
         }
     }
 
+    fn push_arg(@block_ctxt cx,
+                &mutable vec[ValueRef] args,
+                ValueRef v,
+                @ty.t t) {
+        if (ty.type_is_integral(t)) {
+            auto lldsttype = T_int();
+            auto llsrctype = type_of(cx.fcx.ccx, t);
+            if (llvm.LLVMGetIntTypeWidth(lldsttype) >
+                llvm.LLVMGetIntTypeWidth(llsrctype)) {
+                args += vec(cx.build.ZExtOrBitCast(v, T_int()));
+            } else {
+                args += vec(cx.build.TruncOrBitCast(v, T_int()));
+            }
+        } else if (ty.type_is_fp(t)) {
+            args += vec(cx.build.FPToSI(v, T_int()));
+        } else {
+            args += vec(vp2i(cx, v));
+        }
+    }
+
     auto r;
     auto rptr;
     auto args = ty.ty_fn_args(fn_type);
@@ -6192,7 +6212,7 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
         for (ty.arg arg in args) {
             auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
             check (llarg as int != 0);
-            call_args += vec(bcx.build.PointerCast(llarg, T_i32()));
+            push_arg(bcx, call_args, llarg, arg.ty);
             arg_n += 1u;
         }