2011-05-09 17:32:12 -05:00
|
|
|
|
2011-10-14 22:38:24 -05:00
|
|
|
import driver::session;
|
2011-06-15 13:19:50 -05:00
|
|
|
import middle::trans;
|
2011-11-10 10:41:42 -06:00
|
|
|
import middle::trans_common::{T_fn, T_i1, T_i8, T_i32,
|
2012-01-06 10:29:06 -06:00
|
|
|
T_int, T_nil, T_dict,
|
2011-11-10 10:41:42 -06:00
|
|
|
T_opaque_vec, T_ptr,
|
2011-11-15 13:31:48 -06:00
|
|
|
T_size_t, T_void};
|
2011-05-31 20:24:06 -05:00
|
|
|
import lib::llvm::type_names;
|
|
|
|
import lib::llvm::llvm::ModuleRef;
|
|
|
|
import lib::llvm::llvm::ValueRef;
|
|
|
|
import lib::llvm::llvm::TypeRef;
|
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
type upcalls =
|
2011-09-09 07:02:07 -05:00
|
|
|
{_fail: ValueRef,
|
2011-07-27 07:19:39 -05:00
|
|
|
malloc: ValueRef,
|
|
|
|
free: ValueRef,
|
|
|
|
shared_malloc: ValueRef,
|
|
|
|
shared_free: ValueRef,
|
|
|
|
mark: ValueRef,
|
2011-12-15 13:06:48 -06:00
|
|
|
create_shared_type_desc: ValueRef,
|
|
|
|
free_shared_type_desc: ValueRef,
|
2011-07-27 07:19:39 -05:00
|
|
|
get_type_desc: ValueRef,
|
2012-01-06 10:29:06 -06:00
|
|
|
intern_dict: ValueRef,
|
2011-09-02 09:09:41 -05:00
|
|
|
vec_grow: ValueRef,
|
|
|
|
vec_push: ValueRef,
|
2011-08-10 14:55:29 -05:00
|
|
|
cmp_type: ValueRef,
|
2011-08-17 13:42:51 -05:00
|
|
|
log_type: ValueRef,
|
|
|
|
dynastack_mark: ValueRef,
|
|
|
|
dynastack_alloc: ValueRef,
|
2011-09-07 13:44:34 -05:00
|
|
|
dynastack_free: ValueRef,
|
2011-09-28 20:15:28 -05:00
|
|
|
alloc_c_stack: ValueRef,
|
2011-11-18 17:40:23 -06:00
|
|
|
call_shim_on_c_stack: ValueRef,
|
2011-12-06 18:26:47 -06:00
|
|
|
rust_personality: ValueRef,
|
|
|
|
reset_stack_limit: ValueRef};
|
2011-05-09 17:32:12 -05:00
|
|
|
|
2011-10-14 22:38:24 -05:00
|
|
|
fn declare_upcalls(targ_cfg: @session::config,
|
|
|
|
_tn: type_names,
|
|
|
|
tydesc_type: TypeRef,
|
2011-10-20 04:56:45 -05:00
|
|
|
llmod: ModuleRef) -> @upcalls {
|
2011-09-12 04:27:30 -05:00
|
|
|
fn decl(llmod: ModuleRef, name: str, tys: [TypeRef], rv: TypeRef) ->
|
2011-08-19 17:16:48 -05:00
|
|
|
ValueRef {
|
|
|
|
let arg_tys: [TypeRef] = [];
|
|
|
|
for t: TypeRef in tys { arg_tys += [t]; }
|
2011-07-27 07:19:39 -05:00
|
|
|
let fn_ty = T_fn(arg_tys, rv);
|
2011-09-02 17:34:58 -05:00
|
|
|
ret trans::decl_cdecl_fn(llmod, "upcall_" + name, fn_ty);
|
2011-05-09 17:32:12 -05:00
|
|
|
}
|
2011-10-20 04:42:40 -05:00
|
|
|
let d = bind decl(llmod, _, _, _);
|
|
|
|
let dv = bind decl(llmod, _, _, T_void());
|
2011-05-09 17:32:12 -05:00
|
|
|
|
2011-10-14 22:38:24 -05:00
|
|
|
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 07:19:39 -05:00
|
|
|
malloc:
|
2011-10-14 22:38:24 -05:00
|
|
|
d("malloc", [size_t, T_ptr(tydesc_type)],
|
|
|
|
T_ptr(T_i8())),
|
2011-12-11 22:42:37 -06:00
|
|
|
free:
|
|
|
|
dv("free", [T_ptr(T_i8()), int_t]),
|
2011-07-27 07:19:39 -05:00
|
|
|
shared_malloc:
|
2011-10-14 22:38:24 -05:00
|
|
|
d("shared_malloc", [size_t, T_ptr(tydesc_type)],
|
2011-07-27 07:19:39 -05:00
|
|
|
T_ptr(T_i8())),
|
2011-12-11 22:42:37 -06:00
|
|
|
shared_free:
|
|
|
|
dv("shared_free", [T_ptr(T_i8())]),
|
|
|
|
mark:
|
|
|
|
d("mark", [T_ptr(T_i8())], int_t),
|
2011-12-15 13:06:48 -06:00
|
|
|
create_shared_type_desc:
|
|
|
|
d("create_shared_type_desc", [T_ptr(tydesc_type)],
|
2011-12-11 22:42:37 -06:00
|
|
|
T_ptr(tydesc_type)),
|
2011-12-15 13:06:48 -06:00
|
|
|
free_shared_type_desc:
|
|
|
|
dv("free_shared_type_desc", [T_ptr(tydesc_type)]),
|
2011-07-27 07:19:39 -05:00
|
|
|
get_type_desc:
|
2011-09-02 17:34:58 -05:00
|
|
|
d("get_type_desc",
|
2011-10-14 22:38:24 -05:00
|
|
|
[T_ptr(T_nil()), size_t,
|
|
|
|
size_t, size_t,
|
|
|
|
T_ptr(T_ptr(tydesc_type)), int_t],
|
|
|
|
T_ptr(tydesc_type)),
|
2012-01-06 10:29:06 -06:00
|
|
|
intern_dict:
|
|
|
|
d("intern_dict", [size_t, T_ptr(T_dict())], T_ptr(T_dict())),
|
2011-09-02 09:09:41 -05:00
|
|
|
vec_grow:
|
2011-12-11 22:42:37 -06:00
|
|
|
dv("vec_grow", [T_ptr(T_ptr(opaque_vec_t)), int_t]),
|
2011-09-02 09:09:41 -05:00
|
|
|
vec_push:
|
2011-10-20 04:42:40 -05:00
|
|
|
dv("vec_push",
|
2011-10-14 22:38:24 -05:00
|
|
|
[T_ptr(T_ptr(opaque_vec_t)), T_ptr(tydesc_type),
|
|
|
|
T_ptr(T_i8())]),
|
2011-08-08 17:05:12 -05:00
|
|
|
cmp_type:
|
2011-10-20 04:42:40 -05:00
|
|
|
dv("cmp_type",
|
2011-10-20 04:56:45 -05:00
|
|
|
[T_ptr(T_i1()), T_ptr(tydesc_type),
|
2011-08-19 17:16:48 -05:00
|
|
|
T_ptr(T_ptr(tydesc_type)), T_ptr(T_i8()), T_ptr(T_i8()),
|
2011-10-20 04:42:40 -05:00
|
|
|
T_i8()]),
|
2011-08-10 14:55:29 -05:00
|
|
|
log_type:
|
2011-10-20 04:42:40 -05:00
|
|
|
dv("log_type", [T_ptr(tydesc_type), T_ptr(T_i8()), T_i32()]),
|
2011-12-11 22:42:37 -06:00
|
|
|
dynastack_mark:
|
|
|
|
d("dynastack_mark", [], T_ptr(T_i8())),
|
2011-09-02 17:34:58 -05:00
|
|
|
dynastack_alloc:
|
2011-10-14 22:38:24 -05:00
|
|
|
d("dynastack_alloc_2", [size_t, T_ptr(tydesc_type)],
|
2011-09-02 17:34:58 -05:00
|
|
|
T_ptr(T_i8())),
|
2011-12-11 22:42:37 -06:00
|
|
|
dynastack_free:
|
|
|
|
dv("dynastack_free", [T_ptr(T_i8())]),
|
|
|
|
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),
|
|
|
|
rust_personality:
|
|
|
|
d("rust_personality", [], T_i32()),
|
|
|
|
reset_stack_limit:
|
|
|
|
dv("reset_stack_limit", [])
|
2011-09-07 13:44:34 -05:00
|
|
|
};
|
2011-05-09 17:32:12 -05:00
|
|
|
}
|
2011-05-20 18:45:51 -05:00
|
|
|
//
|
|
|
|
// Local Variables:
|
2011-05-20 18:47:48 -05:00
|
|
|
// mode: rust
|
2011-05-20 18:45:51 -05:00
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|
|
|
|
//
|