rust/src/rustc/back/upcall.rs

105 lines
3.5 KiB
Rust
Raw Normal View History

import driver::session;
import middle::trans::base;
import middle::trans::common::{T_fn, T_i1, T_i8, T_i32,
T_int, T_nil,
T_opaque_vec, T_ptr,
T_size_t, T_void};
import lib::llvm::{type_names, ModuleRef, ValueRef, TypeRef};
type upcalls =
{_fail: ValueRef,
2011-07-27 14:19:39 +02:00
malloc: ValueRef,
free: ValueRef,
validate_box: ValueRef,
2011-07-27 14:19:39 +02:00
shared_malloc: ValueRef,
shared_free: ValueRef,
2012-02-17 12:08:03 -08:00
shared_realloc: ValueRef,
2011-07-27 14:19:39 +02:00
mark: ValueRef,
2011-09-02 16:09:41 +02:00
vec_grow: ValueRef,
2012-04-02 17:37:59 -07:00
str_new: ValueRef,
str_concat: ValueRef,
2011-08-10 12:55:29 -07:00
cmp_type: ValueRef,
log_type: ValueRef,
alloc_c_stack: ValueRef,
2011-11-18 15:40:23 -08:00
call_shim_on_c_stack: ValueRef,
2012-02-13 16:06:56 -08:00
call_shim_on_rust_stack: ValueRef,
rust_personality: ValueRef,
reset_stack_limit: ValueRef};
fn declare_upcalls(targ_cfg: @session::config,
_tn: type_names,
tydesc_type: TypeRef,
llmod: ModuleRef) -> @upcalls {
2012-02-17 12:08:03 -08:00
fn decl(llmod: ModuleRef, prefix: str, name: str,
tys: [TypeRef], rv: TypeRef) ->
ValueRef {
let mut arg_tys: [TypeRef] = [];
for t: TypeRef in tys { arg_tys += [t]; }
2011-07-27 14:19:39 +02:00
let fn_ty = T_fn(arg_tys, rv);
2012-02-17 12:08:03 -08:00
ret base::decl_cdecl_fn(llmod, prefix + name, fn_ty);
}
2012-02-17 12:08:03 -08:00
let d = bind decl(llmod, "upcall_", _, _, _);
let dv = bind decl(llmod, "upcall_", _, _, T_void());
let int_t = T_int(targ_cfg);
let size_t = T_size_t(targ_cfg);
let opaque_vec_t = T_opaque_vec(targ_cfg);
ret @{_fail: dv("fail", [T_ptr(T_i8()),
T_ptr(T_i8()),
size_t]),
2011-07-27 14:19:39 +02:00
malloc:
d("malloc", [T_ptr(tydesc_type)], T_ptr(T_i8())),
free:
dv("free", [T_ptr(T_i8())]),
validate_box:
dv("validate_box", [T_ptr(T_i8())]),
2011-07-27 14:19:39 +02:00
shared_malloc:
d("shared_malloc", [size_t], T_ptr(T_i8())),
shared_free:
dv("shared_free", [T_ptr(T_i8())]),
2012-02-17 12:08:03 -08:00
shared_realloc:
d("shared_realloc", [T_ptr(T_i8()), size_t], T_ptr(T_i8())),
mark:
d("mark", [T_ptr(T_i8())], int_t),
2011-09-02 16:09:41 +02:00
vec_grow:
dv("vec_grow", [T_ptr(T_ptr(opaque_vec_t)), int_t]),
2012-04-02 17:37:59 -07:00
str_new:
d("str_new", [T_ptr(T_i8()), int_t], T_ptr(opaque_vec_t)),
str_concat:
d("str_concat", [T_ptr(opaque_vec_t), T_ptr(opaque_vec_t)],
T_ptr(opaque_vec_t)),
2011-08-08 15:05:12 -07:00
cmp_type:
dv("cmp_type",
[T_ptr(T_i1()), T_ptr(tydesc_type),
T_ptr(T_ptr(tydesc_type)), T_ptr(T_i8()), T_ptr(T_i8()),
T_i8()]),
2011-08-10 12:55:29 -07:00
log_type:
dv("log_type", [T_ptr(tydesc_type), T_ptr(T_i8()), T_i32()]),
alloc_c_stack:
d("alloc_c_stack", [size_t], T_ptr(T_i8())),
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),
2012-02-13 16:06:56 -08:00
call_shim_on_rust_stack:
d("call_shim_on_rust_stack",
[T_ptr(T_i8()), T_ptr(T_i8())], int_t),
rust_personality:
d("rust_personality", [], T_i32()),
reset_stack_limit:
dv("reset_stack_limit", [])
};
}
//
// Local Variables:
2011-05-20 16:47:48 -07:00
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
//