]> git.lizzy.rs Git - rust.git/blob - src/librustc/back/upcall.rs
librustc: Add argument to allow choosing "linker"
[rust.git] / src / librustc / back / upcall.rs
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.
4 //
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.
10
11
12 use driver::session;
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};
16
17 pub struct Upcalls {
18     trace: ValueRef,
19     call_shim_on_c_stack: ValueRef,
20     call_shim_on_rust_stack: ValueRef,
21     rust_personality: ValueRef,
22     reset_stack_limit: ValueRef
23 }
24
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) ->
29        ValueRef {
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);
33     }
34     fn nothrow(f: ValueRef) -> ValueRef {
35         base::set_no_unwind(f); f
36     }
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());
41
42     let int_t = T_int(targ_cfg);
43
44     @Upcalls {
45         trace: dv(~"trace", ~[T_ptr(T_i8()),
46                               T_ptr(T_i8()),
47                               int_t]),
48         call_shim_on_c_stack:
49             d(~"call_shim_on_c_stack",
50               // arguments: void *args, void *fn_ptr
51               ~[T_ptr(T_i8()), T_ptr(T_i8())],
52               int_t),
53         call_shim_on_rust_stack:
54             d(~"call_shim_on_rust_stack",
55               ~[T_ptr(T_i8()), T_ptr(T_i8())], int_t),
56         rust_personality:
57             nothrow(d(~"rust_personality", ~[], T_i32())),
58         reset_stack_limit:
59             nothrow(dv(~"reset_stack_limit", ~[]))
60     }
61 }