diff options
| author | Patrick Walton <[email protected]> | 2011-05-03 18:03:59 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-05-03 18:03:59 -0700 |
| commit | ac8eb202247b61412143c621a1ccdcb167d6f313 (patch) | |
| tree | fb3acfd59670ebb27c6e35ce3d6ab857be8f9a0a /src | |
| parent | Revert "Rename the "llvm" API to "llvm-intrinsic"" due to tinderbox bustage (diff) | |
| download | rust-ac8eb202247b61412143c621a1ccdcb167d6f313.tar.xz rust-ac8eb202247b61412143c621a1ccdcb167d6f313.zip | |
rustc: Stub support for Rust intrinsics
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/front/ast.rs | 1 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 2 | ||||
| -rw-r--r-- | src/comp/middle/trans.rs | 83 | ||||
| -rw-r--r-- | src/comp/pretty/pprust.rs | 3 |
4 files changed, 61 insertions, 28 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 82b6d813..1f123f74 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 b886e8ae..e7a86d6e 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 288624da..6f216a97 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 7ef91ce8..62e6594b 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); |