2011-05-09 15:32:12 -07:00
|
|
|
|
2011-10-14 20:38:24 -07:00
|
|
|
import driver::session;
|
2012-01-27 13:17:06 +01:00
|
|
|
import middle::trans::base;
|
|
|
|
import middle::trans::common::{T_fn, T_i1, T_i8, T_i32,
|
2012-03-08 16:17:59 +01:00
|
|
|
T_int, T_nil,
|
2012-05-21 18:36:52 -07:00
|
|
|
T_opaque_vec, T_ptr, T_unique_ptr,
|
|
|
|
T_size_t, T_void, T_vec2};
|
2012-02-01 11:04:56 +01:00
|
|
|
import lib::llvm::{type_names, ModuleRef, ValueRef, TypeRef};
|
2011-05-31 18:24:06 -07:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
type upcalls =
|
2011-09-09 14:02:07 +02:00
|
|
|
{_fail: ValueRef,
|
2012-05-18 19:02:39 -07:00
|
|
|
trace: ValueRef,
|
2011-07-27 14:19:39 +02:00
|
|
|
malloc: ValueRef,
|
|
|
|
free: ValueRef,
|
2012-05-08 16:47:18 -07:00
|
|
|
exchange_malloc: ValueRef,
|
2012-05-21 18:36:52 -07:00
|
|
|
exchange_malloc_dyn: ValueRef,
|
2012-05-08 16:47:18 -07:00
|
|
|
exchange_free: ValueRef,
|
2012-02-01 18:52:08 -08:00
|
|
|
validate_box: ValueRef,
|
2011-07-27 14:19:39 +02:00
|
|
|
mark: ValueRef,
|
2011-09-02 16:09:41 +02:00
|
|
|
vec_grow: ValueRef,
|
2012-04-16 16:17:51 -07:00
|
|
|
str_new_uniq: ValueRef,
|
|
|
|
str_new_shared: ValueRef,
|
2012-03-19 14:06:59 -07:00
|
|
|
str_concat: ValueRef,
|
2011-08-10 12:55:29 -07:00
|
|
|
cmp_type: ValueRef,
|
2011-08-17 11:42:51 -07:00
|
|
|
log_type: ValueRef,
|
2011-09-28 18:15:28 -07:00
|
|
|
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,
|
2011-12-06 16:26:47 -08:00
|
|
|
rust_personality: ValueRef,
|
|
|
|
reset_stack_limit: ValueRef};
|
2011-05-09 15:32:12 -07:00
|
|
|
|
2011-10-14 20:38:24 -07:00
|
|
|
fn declare_upcalls(targ_cfg: @session::config,
|
|
|
|
_tn: type_names,
|
|
|
|
tydesc_type: TypeRef,
|
2011-10-20 11:56:45 +02:00
|
|
|
llmod: ModuleRef) -> @upcalls {
|
2012-02-17 12:08:03 -08:00
|
|
|
fn decl(llmod: ModuleRef, prefix: str, name: str,
|
|
|
|
tys: [TypeRef], rv: TypeRef) ->
|
2011-08-19 15:16:48 -07:00
|
|
|
ValueRef {
|
2012-03-15 09:47:03 -04:00
|
|
|
let mut arg_tys: [TypeRef] = [];
|
2012-04-06 20:01:43 +02:00
|
|
|
for tys.each {|t| arg_tys += [t]; }
|
2011-07-27 14:19:39 +02:00
|
|
|
let fn_ty = T_fn(arg_tys, rv);
|
2012-04-25 18:53:54 -07:00
|
|
|
ret base::decl_cdecl_fn(llmod, prefix + name, fn_ty);
|
|
|
|
}
|
|
|
|
fn nothrow(f: ValueRef) -> ValueRef {
|
|
|
|
base::set_no_unwind(f); f
|
2011-05-09 15:32:12 -07:00
|
|
|
}
|
2012-02-17 12:08:03 -08:00
|
|
|
let d = bind decl(llmod, "upcall_", _, _, _);
|
|
|
|
let dv = bind decl(llmod, "upcall_", _, _, 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);
|
|
|
|
let size_t = T_size_t(targ_cfg);
|
|
|
|
|
|
|
|
ret @{_fail: dv("fail", [T_ptr(T_i8()),
|
|
|
|
T_ptr(T_i8()),
|
|
|
|
size_t]),
|
2012-05-18 19:02:39 -07:00
|
|
|
trace: dv("trace", [T_ptr(T_i8()),
|
|
|
|
T_ptr(T_i8()),
|
|
|
|
int_t]),
|
2011-07-27 14:19:39 +02:00
|
|
|
malloc:
|
2012-04-25 18:53:54 -07:00
|
|
|
nothrow(d("malloc", [T_ptr(tydesc_type)],
|
|
|
|
T_ptr(T_i8()))),
|
2011-12-11 20:42:37 -08:00
|
|
|
free:
|
2012-04-25 18:53:54 -07:00
|
|
|
nothrow(dv("free", [T_ptr(T_i8())])),
|
2012-05-08 16:47:18 -07:00
|
|
|
exchange_malloc:
|
|
|
|
nothrow(d("exchange_malloc", [T_ptr(tydesc_type)],
|
|
|
|
T_ptr(T_i8()))),
|
2012-05-21 18:36:52 -07:00
|
|
|
exchange_malloc_dyn:
|
|
|
|
nothrow(d("exchange_malloc_dyn",
|
|
|
|
[T_ptr(tydesc_type), int_t],
|
|
|
|
T_ptr(T_i8()))),
|
2012-05-08 16:47:18 -07:00
|
|
|
exchange_free:
|
|
|
|
nothrow(dv("exchange_free", [T_ptr(T_i8())])),
|
2012-02-01 18:52:08 -08:00
|
|
|
validate_box:
|
2012-04-25 18:53:54 -07:00
|
|
|
nothrow(dv("validate_box", [T_ptr(T_i8())])),
|
2011-12-11 20:42:37 -08:00
|
|
|
mark:
|
|
|
|
d("mark", [T_ptr(T_i8())], int_t),
|
2011-09-02 16:09:41 +02:00
|
|
|
vec_grow:
|
2012-05-21 18:36:52 -07:00
|
|
|
nothrow(dv("vec_grow", [T_ptr(T_ptr(T_i8())), int_t])),
|
2012-04-16 16:17:51 -07:00
|
|
|
str_new_uniq:
|
2012-04-25 18:53:54 -07:00
|
|
|
nothrow(d("str_new_uniq", [T_ptr(T_i8()), int_t],
|
2012-05-21 18:36:52 -07:00
|
|
|
T_ptr(T_i8()))),
|
2012-04-16 16:17:51 -07:00
|
|
|
str_new_shared:
|
2012-04-25 18:53:54 -07:00
|
|
|
nothrow(d("str_new_shared", [T_ptr(T_i8()), int_t],
|
|
|
|
T_ptr(T_i8()))),
|
2012-03-19 14:06:59 -07:00
|
|
|
str_concat:
|
2012-05-21 18:36:52 -07:00
|
|
|
nothrow(d("str_concat", [T_ptr(T_i8()),
|
|
|
|
T_ptr(T_i8())],
|
|
|
|
T_ptr(T_i8()))),
|
2011-08-08 15:05:12 -07:00
|
|
|
cmp_type:
|
2011-10-20 11:42:40 +02:00
|
|
|
dv("cmp_type",
|
2011-10-20 11:56:45 +02:00
|
|
|
[T_ptr(T_i1()), T_ptr(tydesc_type),
|
2012-04-25 18:53:54 -07:00
|
|
|
T_ptr(T_ptr(tydesc_type)), T_ptr(T_i8()),
|
|
|
|
T_ptr(T_i8()),
|
2011-10-20 11:42:40 +02:00
|
|
|
T_i8()]),
|
2011-08-10 12:55:29 -07:00
|
|
|
log_type:
|
2012-04-25 18:53:54 -07:00
|
|
|
dv("log_type", [T_ptr(tydesc_type),
|
|
|
|
T_ptr(T_i8()), T_i32()]),
|
2011-12-11 20:42:37 -08:00
|
|
|
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),
|
2011-12-11 20:42:37 -08:00
|
|
|
rust_personality:
|
2012-04-25 18:53:54 -07:00
|
|
|
nothrow(d("rust_personality", [], T_i32())),
|
2011-12-11 20:42:37 -08:00
|
|
|
reset_stack_limit:
|
2012-04-25 18:53:54 -07:00
|
|
|
nothrow(dv("reset_stack_limit", []))
|
2011-09-07 11:44:34 -07:00
|
|
|
};
|
2011-05-09 15:32:12 -07:00
|
|
|
}
|
2011-05-20 16:45:51 -07:00
|
|
|
//
|
|
|
|
// Local Variables:
|
2011-05-20 16:47:48 -07:00
|
|
|
// mode: rust
|
2011-05-20 16:45:51 -07:00
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|
|
|
|
//
|