2011-05-12 10:24:54 -05:00
|
|
|
import middle::trans;
|
2011-05-09 17:32:12 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
import trans::decl_cdecl_fn;
|
|
|
|
import trans::type_names;
|
|
|
|
import trans::ModuleRef;
|
|
|
|
import trans::TypeRef;
|
|
|
|
import trans::ValueRef;
|
2011-05-09 17:32:12 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
import trans::T_crate;
|
|
|
|
import trans::T_f32;
|
|
|
|
import trans::T_f64;
|
|
|
|
import trans::T_fn;
|
|
|
|
import trans::T_i8;
|
|
|
|
import trans::T_i32;
|
|
|
|
import trans::T_int;
|
|
|
|
import trans::T_opaque_chan_ptr;
|
|
|
|
import trans::T_opaque_port_ptr;
|
|
|
|
import trans::T_opaque_vec_ptr;
|
|
|
|
import trans::T_ptr;
|
|
|
|
import trans::T_size_t;
|
|
|
|
import trans::T_str;
|
|
|
|
import trans::T_taskptr;
|
|
|
|
import trans::T_tydesc;
|
|
|
|
import trans::T_void;
|
2011-05-09 17:32:12 -05:00
|
|
|
|
|
|
|
type upcalls = rec(
|
|
|
|
ValueRef grow_task,
|
|
|
|
ValueRef log_int,
|
|
|
|
ValueRef log_float,
|
|
|
|
ValueRef log_double,
|
|
|
|
ValueRef log_str,
|
|
|
|
ValueRef trace_word,
|
|
|
|
ValueRef trace_str,
|
|
|
|
ValueRef new_port,
|
|
|
|
ValueRef del_port,
|
|
|
|
ValueRef new_chan,
|
|
|
|
ValueRef flush_chan,
|
|
|
|
ValueRef del_chan,
|
|
|
|
ValueRef clone_chan,
|
|
|
|
ValueRef _yield,
|
|
|
|
ValueRef sleep,
|
|
|
|
ValueRef _join,
|
|
|
|
ValueRef send,
|
|
|
|
ValueRef recv,
|
|
|
|
ValueRef _fail,
|
|
|
|
ValueRef kill,
|
|
|
|
ValueRef exit,
|
|
|
|
ValueRef malloc,
|
|
|
|
ValueRef free,
|
|
|
|
ValueRef mark,
|
|
|
|
ValueRef new_str,
|
|
|
|
ValueRef new_vec,
|
|
|
|
ValueRef vec_grow,
|
|
|
|
ValueRef require_rust_sym,
|
|
|
|
ValueRef require_c_sym,
|
|
|
|
ValueRef get_type_desc,
|
|
|
|
ValueRef new_task,
|
|
|
|
ValueRef start_task,
|
|
|
|
ValueRef new_thread,
|
|
|
|
ValueRef start_thread
|
|
|
|
);
|
|
|
|
|
2011-05-09 18:58:19 -05:00
|
|
|
fn declare_upcalls(type_names tn, ModuleRef llmod) -> @upcalls {
|
|
|
|
fn decl(type_names tn, ModuleRef llmod, str name, vec[TypeRef] tys,
|
|
|
|
TypeRef rv) -> ValueRef {
|
2011-05-09 17:32:12 -05:00
|
|
|
let vec[TypeRef] arg_tys = vec(T_taskptr(tn));
|
|
|
|
for (TypeRef t in tys) { arg_tys += vec(t); }
|
2011-05-09 18:58:19 -05:00
|
|
|
auto fn_ty = T_fn(arg_tys, rv);
|
2011-05-12 10:24:54 -05:00
|
|
|
ret trans::decl_cdecl_fn(llmod, "upcall_" + name, fn_ty);
|
2011-05-09 17:32:12 -05:00
|
|
|
}
|
|
|
|
|
2011-05-09 18:58:19 -05:00
|
|
|
auto dv = bind decl(tn, llmod, _, _, T_void());
|
|
|
|
auto d = bind decl(tn, llmod, _, _, _);
|
2011-05-09 17:32:12 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
// FIXME: Sigh:.. remove this when I fix the typechecker pushdown.
|
2011-05-09 17:32:12 -05:00
|
|
|
// --pcwalton
|
|
|
|
let vec[TypeRef] empty_vec = vec();
|
|
|
|
|
2011-05-09 18:58:19 -05:00
|
|
|
ret @rec(
|
|
|
|
grow_task=dv("grow_task", vec(T_size_t())),
|
|
|
|
log_int=dv("log_int", vec(T_i32(), T_i32())),
|
|
|
|
log_float=dv("log_float", vec(T_i32(), T_f32())),
|
|
|
|
log_double=dv("log_double", vec(T_i32(), T_ptr(T_f64()))),
|
|
|
|
log_str=dv("log_str", vec(T_i32(), T_ptr(T_str()))),
|
|
|
|
trace_word=dv("trace_word", vec(T_int())),
|
|
|
|
trace_str=dv("trace_str", vec(T_ptr(T_i8()))),
|
2011-05-10 16:03:47 -05:00
|
|
|
new_port=d("new_port", vec(T_size_t()), T_opaque_port_ptr()),
|
|
|
|
del_port=dv("del_port", vec(T_opaque_port_ptr())),
|
|
|
|
new_chan=d("new_chan", vec(T_opaque_port_ptr()), T_opaque_chan_ptr()),
|
|
|
|
flush_chan=dv("flush_chan", vec(T_opaque_chan_ptr())),
|
|
|
|
del_chan=dv("del_chan", vec(T_opaque_chan_ptr())),
|
|
|
|
clone_chan=d("clone_chan", vec(T_taskptr(tn), T_opaque_chan_ptr()),
|
|
|
|
T_opaque_chan_ptr()),
|
2011-05-09 18:58:19 -05:00
|
|
|
_yield=dv("yield", empty_vec),
|
|
|
|
sleep=dv("sleep", vec(T_size_t())),
|
|
|
|
_join=dv("join", vec(T_taskptr(tn))),
|
2011-05-10 16:03:47 -05:00
|
|
|
send=dv("send", vec(T_opaque_chan_ptr(), T_ptr(T_i8()))),
|
|
|
|
recv=dv("recv", vec(T_ptr(T_ptr(T_i8())), T_opaque_port_ptr())),
|
2011-05-09 18:58:19 -05:00
|
|
|
_fail=dv("fail", vec(T_ptr(T_i8()), T_ptr(T_i8()), T_size_t())),
|
|
|
|
kill=dv("kill", vec(T_taskptr(tn))),
|
|
|
|
exit=dv("exit", empty_vec),
|
|
|
|
malloc=d("malloc", vec(T_size_t(), T_ptr(T_tydesc(tn))),
|
|
|
|
T_ptr(T_i8())),
|
|
|
|
free=dv("free", vec(T_ptr(T_i8()), T_int())),
|
|
|
|
mark=d("mark", vec(T_ptr(T_i8())), T_int()),
|
|
|
|
new_str=d("new_str", vec(T_ptr(T_i8()), T_size_t()), T_ptr(T_str())),
|
|
|
|
new_vec=d("new_vec", vec(T_size_t(), T_ptr(T_tydesc(tn))),
|
|
|
|
T_opaque_vec_ptr()),
|
2011-05-09 17:32:12 -05:00
|
|
|
vec_grow=d("vec_grow", vec(T_opaque_vec_ptr(), T_size_t(),
|
2011-05-09 18:58:19 -05:00
|
|
|
T_ptr(T_int()), T_ptr(T_tydesc(tn))),
|
|
|
|
T_opaque_vec_ptr()),
|
2011-05-09 17:32:12 -05:00
|
|
|
require_rust_sym=d("require_rust_sym",
|
|
|
|
vec(T_ptr(T_crate(tn)), T_size_t(), T_size_t(),
|
|
|
|
T_size_t(), T_ptr(T_i8()),
|
2011-05-09 18:58:19 -05:00
|
|
|
T_ptr(T_ptr(T_i8()))),
|
|
|
|
T_int()),
|
2011-05-09 17:32:12 -05:00
|
|
|
require_c_sym=d("require_c_sym",
|
|
|
|
vec(T_ptr(T_crate(tn)), T_size_t(), T_size_t(),
|
2011-05-09 18:58:19 -05:00
|
|
|
T_ptr(T_i8()), T_ptr(T_i8())),
|
|
|
|
T_int()),
|
2011-05-09 17:32:12 -05:00
|
|
|
get_type_desc=d("get_type_desc",
|
|
|
|
vec(T_ptr(T_crate(tn)), T_size_t(), T_size_t(),
|
2011-05-09 18:58:19 -05:00
|
|
|
T_size_t(), T_ptr(T_ptr(T_tydesc(tn)))),
|
|
|
|
T_ptr(T_tydesc(tn))),
|
|
|
|
new_task=d("new_task", vec(T_ptr(T_i8())), T_taskptr(tn)),
|
2011-05-09 17:32:12 -05:00
|
|
|
start_task=d("start_task", vec(T_taskptr(tn), T_int(), T_int(),
|
2011-05-09 18:58:19 -05:00
|
|
|
T_int(), T_size_t()),
|
|
|
|
T_taskptr(tn)),
|
|
|
|
new_thread=d("new_thread", vec(T_ptr(T_i8())), T_taskptr(tn)),
|
2011-05-09 17:32:12 -05:00
|
|
|
start_thread=d("start_thread", vec(T_taskptr(tn), T_int(), T_int(),
|
2011-05-09 18:58:19 -05:00
|
|
|
T_int(), T_size_t()),
|
|
|
|
T_taskptr(tn))
|
2011-05-09 17:32:12 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|