diff options
| author | Rafael Ávila de Espíndola <[email protected]> | 2011-02-28 17:33:46 -0500 |
|---|---|---|
| committer | Rafael Ávila de Espíndola <[email protected]> | 2011-02-28 17:33:46 -0500 |
| commit | a172f5aef5f7d26fba9dbf94a1ade60d6d62ba74 (patch) | |
| tree | af9847dd7baea9053bf32a6057f3ae4c0a071cdb /src/comp | |
| parent | Update the function declarations with rust abi. A cdecl (diff) | |
| download | rust-a172f5aef5f7d26fba9dbf94a1ade60d6d62ba74.tar.xz rust-a172f5aef5f7d26fba9dbf94a1ade60d6d62ba74.zip | |
Declare wrappers to the native functions and use those to create
the fn/closure pairs.
Disable native2.rs for now as we are not yet defining the wrappers and it
fails to link.
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/middle/trans.rs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 3564b1b3..189c742c 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -4395,6 +4395,12 @@ fn decl_fn_and_pair(@crate_ctxt cx, // Declare the global constant pair that points to it. let str ps = cx.names.next("_rust_" + kind + "_pair") + sep() + name; + + register_fn_pair(cx, ps, llpairty, llfn, id); +} + +fn register_fn_pair(@crate_ctxt cx, str ps, TypeRef llpairty, ValueRef llfn, + ast.def_id id) { let ValueRef gvar = llvm.LLVMAddGlobal(cx.llmod, llpairty, _str.buf(ps)); auto pair = C_struct(vec(llfn, @@ -4410,16 +4416,34 @@ fn decl_fn_and_pair(@crate_ctxt cx, cx.fn_pairs.insert(id, gvar); } +fn native_fn_wrapper_type(@crate_ctxt cx, &ast.ann ann) -> TypeRef { + auto x = node_ann_type(cx, ann); + alt (x.struct) { + case (ty.ty_native_fn(?abi, ?args, ?out)) { + ret type_of_fn(cx, ast.proto_fn, args, out); + } + } + fail; +} + fn decl_native_fn_and_pair(@crate_ctxt cx, str name, &ast.ann ann, ast.def_id id) { + // Declare the wrapper. + auto wrapper_type = native_fn_wrapper_type(cx, ann); + let str s = cx.names.next("_rust_wrapper") + sep() + name; + let ValueRef wrapper_fn = decl_fastcall_fn(cx.llmod, s, wrapper_type); - auto llpairty = node_type(cx, ann); - auto llfty = get_pair_fn_ty(llpairty); + // Declare the global constant pair that points to it. + auto wrapper_pair_type = T_fn_pair(cx.tn, wrapper_type); + let str ps = cx.names.next("_rust_wrapper_pair") + sep() + name; - let ValueRef llfn = decl_cdecl_fn(cx.llmod, name, llfty); - cx.item_ids.insert(id, llfn); + register_fn_pair(cx, ps, wrapper_pair_type, wrapper_fn, id); + + // Declare the function itself. + auto llfty = get_pair_fn_ty(node_type(cx, ann)); + decl_cdecl_fn(cx.llmod, name, llfty); } fn collect_native_item(&@crate_ctxt cx, @ast.native_item i) -> @crate_ctxt { |