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-06-16 02:29:52 +12:00
|
|
|
use middle::trans::type_::Type;
|
|
|
|
use lib::llvm::{ModuleRef, ValueRef};
|
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-06-16 02:29:52 +12:00
|
|
|
macro_rules! upcall (
|
|
|
|
(fn $name:ident($($arg:expr),+) -> $ret:expr) => ({
|
2013-06-16 22:52:44 +12:00
|
|
|
let fn_ty = Type::func([ $($arg),* ], &$ret);
|
2013-06-16 02:29:52 +12:00
|
|
|
base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty)
|
|
|
|
});
|
|
|
|
(nothrow fn $name:ident($($arg:expr),+) -> $ret:expr) => ({
|
2013-06-16 22:52:44 +12:00
|
|
|
let fn_ty = Type::func([ $($arg),* ], &$ret);
|
2013-06-16 02:29:52 +12:00
|
|
|
let decl = base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty);
|
|
|
|
base::set_no_unwind(decl);
|
|
|
|
decl
|
|
|
|
});
|
|
|
|
(nothrow fn $name:ident -> $ret:expr) => ({
|
2013-06-16 22:52:44 +12:00
|
|
|
let fn_ty = Type::func([], &$ret);
|
2013-06-16 02:29:52 +12:00
|
|
|
let decl = base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty);
|
|
|
|
base::set_no_unwind(decl);
|
|
|
|
decl
|
|
|
|
})
|
|
|
|
)
|
2011-05-09 15:32:12 -07:00
|
|
|
|
2013-06-16 02:29:52 +12:00
|
|
|
pub fn declare_upcalls(targ_cfg: @session::config, llmod: ModuleRef) -> @Upcalls {
|
2013-06-16 22:52:44 +12:00
|
|
|
let opaque_ptr = Type::i8().ptr_to();
|
2013-06-16 02:29:52 +12:00
|
|
|
let int_ty = Type::int(targ_cfg.arch);
|
2011-10-14 20:38:24 -07:00
|
|
|
|
2013-02-19 02:40:42 -05:00
|
|
|
@Upcalls {
|
2013-06-16 02:29:52 +12:00
|
|
|
trace: upcall!(fn trace(opaque_ptr, opaque_ptr, int_ty) -> Type::void()),
|
|
|
|
call_shim_on_c_stack: upcall!(fn call_shim_on_c_stack(opaque_ptr, opaque_ptr) -> int_ty),
|
2013-02-19 02:40:42 -05:00
|
|
|
call_shim_on_rust_stack:
|
2013-06-16 02:29:52 +12:00
|
|
|
upcall!(fn call_shim_on_rust_stack(opaque_ptr, opaque_ptr) -> int_ty),
|
|
|
|
rust_personality: upcall!(nothrow fn rust_personality -> Type::i32()),
|
|
|
|
reset_stack_limit: upcall!(nothrow fn reset_stack_limit -> Type::void())
|
2013-02-19 02:40:42 -05:00
|
|
|
}
|
2011-05-09 15:32:12 -07:00
|
|
|
}
|