1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 use middle::trans::base;
14 use middle::trans::common::{T_fn, T_i8, T_i32, T_int, T_ptr, T_void};
15 use lib::llvm::{ModuleRef, ValueRef, TypeRef};
19 call_shim_on_c_stack: ValueRef,
20 call_shim_on_rust_stack: ValueRef,
21 rust_personality: ValueRef,
22 reset_stack_limit: ValueRef
25 pub fn declare_upcalls(targ_cfg: @session::config,
26 llmod: ModuleRef) -> @Upcalls {
27 fn decl(llmod: ModuleRef, prefix: ~str, name: ~str,
28 tys: ~[TypeRef], rv: TypeRef) ->
30 let arg_tys = tys.map(|t| *t);
31 let fn_ty = T_fn(arg_tys, rv);
32 return base::decl_cdecl_fn(llmod, prefix + name, fn_ty);
34 fn nothrow(f: ValueRef) -> ValueRef {
35 base::set_no_unwind(f); f
37 let d: &fn(+a: ~str, +b: ~[TypeRef], +c: TypeRef) -> ValueRef =
38 |a,b,c| decl(llmod, ~"upcall_", a, b, c);
39 let dv: &fn(+a: ~str, +b: ~[TypeRef]) -> ValueRef =
40 |a,b| decl(llmod, ~"upcall_", a, b, T_void());
42 let int_t = T_int(targ_cfg);
45 trace: dv(~"trace", ~[T_ptr(T_i8()),
49 d(~"call_shim_on_c_stack",
50 // arguments: void *args, void *fn_ptr
51 ~[T_ptr(T_i8()), T_ptr(T_i8())],
53 call_shim_on_rust_stack:
54 d(~"call_shim_on_rust_stack",
55 ~[T_ptr(T_i8()), T_ptr(T_i8())], int_t),
57 nothrow(d(~"rust_personality", ~[], T_i32())),
59 nothrow(dv(~"reset_stack_limit", ~[]))