2012-12-03 16:48:01 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2011-05-09 15:32:12 -07:00
|
|
|
|
2012-09-04 11:54:36 -07:00
|
|
|
use driver::session;
|
|
|
|
use middle::trans::base;
|
2013-03-26 16:38:07 -04:00
|
|
|
use middle::trans::common::{T_fn, T_i8, T_i32, T_int, T_ptr, T_void};
|
|
|
|
use lib::llvm::{ModuleRef, ValueRef, TypeRef};
|
2011-05-31 18:24:06 -07:00
|
|
|
|
2013-02-19 02:40:42 -05:00
|
|
|
pub struct Upcalls {
|
|
|
|
trace: ValueRef,
|
|
|
|
call_shim_on_c_stack: ValueRef,
|
|
|
|
call_shim_on_rust_stack: ValueRef,
|
|
|
|
rust_personality: ValueRef,
|
|
|
|
reset_stack_limit: ValueRef
|
|
|
|
}
|
2011-05-09 15:32:12 -07:00
|
|
|
|
2013-01-29 15:48:50 -08:00
|
|
|
pub fn declare_upcalls(targ_cfg: @session::config,
|
2013-02-19 02:40:42 -05:00
|
|
|
llmod: ModuleRef) -> @Upcalls {
|
2012-07-13 22:57:48 -07:00
|
|
|
fn decl(llmod: ModuleRef, prefix: ~str, name: ~str,
|
2012-06-29 16:26:56 -07:00
|
|
|
tys: ~[TypeRef], rv: TypeRef) ->
|
2011-08-19 15:16:48 -07:00
|
|
|
ValueRef {
|
2012-10-18 09:14:11 -07:00
|
|
|
let arg_tys = tys.map(|t| *t);
|
2011-07-27 14:19:39 +02:00
|
|
|
let fn_ty = T_fn(arg_tys, rv);
|
2012-08-01 17:30:05 -07:00
|
|
|
return base::decl_cdecl_fn(llmod, prefix + name, fn_ty);
|
2012-04-25 18:53:54 -07:00
|
|
|
}
|
|
|
|
fn nothrow(f: ValueRef) -> ValueRef {
|
|
|
|
base::set_no_unwind(f); f
|
2011-05-09 15:32:12 -07:00
|
|
|
}
|
2013-05-07 14:20:56 -07:00
|
|
|
let d: &fn(a: ~str, b: ~[TypeRef], c: TypeRef) -> ValueRef =
|
2013-01-07 14:16:52 -08:00
|
|
|
|a,b,c| decl(llmod, ~"upcall_", a, b, c);
|
2013-05-07 14:20:56 -07:00
|
|
|
let dv: &fn(a: ~str, b: ~[TypeRef]) -> ValueRef =
|
2013-01-07 14:16:52 -08:00
|
|
|
|a,b| decl(llmod, ~"upcall_", a, b, T_void());
|
2011-05-09 15:32:12 -07:00
|
|
|
|
2011-10-14 20:38:24 -07:00
|
|
|
let int_t = T_int(targ_cfg);
|
|
|
|
|
2013-02-19 02:40:42 -05:00
|
|
|
@Upcalls {
|
|
|
|
trace: dv(~"trace", ~[T_ptr(T_i8()),
|
2012-05-18 19:02:39 -07:00
|
|
|
T_ptr(T_i8()),
|
2012-06-29 16:26:56 -07:00
|
|
|
int_t]),
|
2013-02-19 02:40:42 -05:00
|
|
|
call_shim_on_c_stack:
|
|
|
|
d(~"call_shim_on_c_stack",
|
|
|
|
// arguments: void *args, void *fn_ptr
|
|
|
|
~[T_ptr(T_i8()), T_ptr(T_i8())],
|
|
|
|
int_t),
|
|
|
|
call_shim_on_rust_stack:
|
|
|
|
d(~"call_shim_on_rust_stack",
|
|
|
|
~[T_ptr(T_i8()), T_ptr(T_i8())], int_t),
|
|
|
|
rust_personality:
|
|
|
|
nothrow(d(~"rust_personality", ~[], T_i32())),
|
|
|
|
reset_stack_limit:
|
|
|
|
nothrow(dv(~"reset_stack_limit", ~[]))
|
|
|
|
}
|
2011-05-09 15:32:12 -07:00
|
|
|
}
|