about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-05-03 18:03:59 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-05-03 18:03:59 -0700
commitac8eb202247b61412143c621a1ccdcb167d6f313 (patch)
treefb3acfd59670ebb27c6e35ce3d6ab857be8f9a0a /src/comp
parent2bc17adc299ef0fcfbf7c41fc1ad12950ffd7e56 (diff)
downloadrust-ac8eb202247b61412143c621a1ccdcb167d6f313.tar.gz
rust-ac8eb202247b61412143c621a1ccdcb167d6f313.zip
rustc: Stub support for Rust intrinsics
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/front/ast.rs1
-rw-r--r--src/comp/front/parser.rs2
-rw-r--r--src/comp/middle/trans.rs83
-rw-r--r--src/comp/pretty/pprust.rs3
4 files changed, 61 insertions, 28 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 82b6d81303f..1f123f74864 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -380,6 +380,7 @@ tag native_abi {
     native_abi_rust;
     native_abi_cdecl;
     native_abi_llvm;
+    native_abi_rust_intrinsic;
 }
 
 type native_mod = rec(str native_name,
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index b886e8ae8ed..e7a86d6efed 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -2015,6 +2015,8 @@ fn parse_item_native_mod(parser p) -> @ast.item {
             abi = ast.native_abi_rust;
         } else if (_str.eq(t, "llvm")) {
             abi = ast.native_abi_llvm;
+        } else if (_str.eq(t, "rust-intrinsic")) {
+            abi = ast.native_abi_rust_intrinsic;
         } else {
             p.err("unsupported abi: " + t);
             fail;
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 288624daabc..6f216a97f8a 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -6737,6 +6737,10 @@ fn decl_native_fn_and_pair(@crate_ctxt ccx,
                 arg_n += 1u;
             }
         }
+        case (ast.native_abi_rust_intrinsic) {
+            pass_task = true;
+            call_args += vec(lltaskptr);
+        }
         case (ast.native_abi_cdecl) {
             pass_task = false;
         }
@@ -6772,46 +6776,69 @@ fn decl_native_fn_and_pair(@crate_ctxt ccx,
         args += vec(vp2i(cx, v));
     }
 
-    auto r;
-    auto rptr;
-    auto args = ty.ty_fn_args(ccx.tcx, fn_type);
-    if (abi == ast.native_abi_llvm) {
-        let vec[ValueRef] call_args = vec();
+    fn trans_simple_native_abi(@block_ctxt bcx,
+                               str name,
+                               vec[ty.arg] args,
+                               &mutable vec[ValueRef] call_args,
+                               ty.t fn_type) -> tup(ValueRef, ValueRef) {
         let vec[TypeRef] call_arg_tys = vec();
         auto i = 0u;
         while (i < _vec.len[ty.arg](args)) {
-            auto call_arg = llvm.LLVMGetParam(fcx.llfn, i + 3u);
+            auto call_arg = llvm.LLVMGetParam(bcx.fcx.llfn, i + 3u);
             call_args += vec(call_arg);
             call_arg_tys += vec(val_ty(call_arg));
             i += 1u;
         }
-        auto llnativefnty = T_fn(call_arg_tys,
-                                 type_of(ccx,
-                                         ty.ty_fn_ret(ccx.tcx, fn_type)));
-        auto llnativefn = get_extern_fn(ccx.externs, ccx.llmod, name,
-                                        lib.llvm.LLVMCCallConv, llnativefnty);
-        r = bcx.build.Call(llnativefn, call_args);
-        rptr = fcx.llretptr;
-    } else {
+        auto llnativefnty =
+            T_fn(call_arg_tys,
+                 type_of(bcx.fcx.lcx.ccx,
+                         ty.ty_fn_ret(bcx.fcx.lcx.ccx.tcx, fn_type)));
+        auto llnativefn = get_extern_fn(bcx.fcx.lcx.ccx.externs,
+                                        bcx.fcx.lcx.ccx.llmod,
+                                        name,
+                                        lib.llvm.LLVMCCallConv,
+                                        llnativefnty);
 
-        let vec[tup(ValueRef, ty.t)] drop_args = vec();
+        auto r = bcx.build.Call(llnativefn, call_args);
+        auto rptr = bcx.fcx.llretptr;
+        ret tup(r, rptr);
+    }
 
-        for (ty.arg arg in args) {
-            auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
-            assert (llarg as int != 0);
-            push_arg(bcx, call_args, llarg, arg.ty, arg.mode);
-            if (arg.mode == ast.val) {
-                drop_args += vec(tup(llarg, arg.ty));
-            }
-            arg_n += 1u;
+    auto r;
+    auto rptr;
+    auto args = ty.ty_fn_args(ccx.tcx, fn_type);
+    alt (abi) {
+        case (ast.native_abi_llvm) {
+            auto result = trans_simple_native_abi(bcx, name, args, call_args,
+                                                  fn_type);
+            r = result._0; rptr = result._1;
+        }
+        case (ast.native_abi_rust_intrinsic) {
+            auto result = trans_simple_native_abi(bcx, name, args, call_args,
+                                                  fn_type);
+            r = result._0; rptr = result._1;
         }
+        case (_) {
+            let vec[tup(ValueRef, ty.t)] drop_args = vec();
 
-        r = trans_native_call(bcx.build, ccx.glues, lltaskptr, ccx.externs,
-                              ccx.tn, ccx.llmod, name, pass_task, call_args);
-        rptr = bcx.build.BitCast(fcx.llretptr, T_ptr(T_i32()));
+            for (ty.arg arg in args) {
+                auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
+                assert (llarg as int != 0);
+                push_arg(bcx, call_args, llarg, arg.ty, arg.mode);
+                if (arg.mode == ast.val) {
+                    drop_args += vec(tup(llarg, arg.ty));
+                }
+                arg_n += 1u;
+            }
 
-        for (tup(ValueRef, ty.t) d in drop_args) {
-            bcx = drop_ty(bcx, d._0, d._1).bcx;
+            r = trans_native_call(bcx.build, ccx.glues, lltaskptr,
+                                  ccx.externs, ccx.tn, ccx.llmod, name,
+                                  pass_task, call_args);
+            rptr = bcx.build.BitCast(fcx.llretptr, T_ptr(T_i32()));
+
+            for (tup(ValueRef, ty.t) d in drop_args) {
+                bcx = drop_ty(bcx, d._0, d._1).bcx;
+            }
         }
     }
 
diff --git a/src/comp/pretty/pprust.rs b/src/comp/pretty/pprust.rs
index 7ef91ce89e4..62e6594b627 100644
--- a/src/comp/pretty/pprust.rs
+++ b/src/comp/pretty/pprust.rs
@@ -230,6 +230,9 @@ fn print_item(ps s, @ast.item item) {
             alt (nmod.abi) {
                 case (ast.native_abi_rust) {wrd1(s, "\"rust\"");}
                 case (ast.native_abi_cdecl) {wrd1(s, "\"cdecl\"");}
+                case (ast.native_abi_rust_intrinsic) {
+                    wrd1(s, "\"rust-intrinstic\"");
+                }
             }
             wrd1(s, "mod");
             wrd1(s, id);