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;
|
2011-05-09 17:32:12 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
import trans::T_f32;
|
|
|
|
import trans::T_f64;
|
|
|
|
import trans::T_fn;
|
|
|
|
import trans::T_i8;
|
|
|
|
import trans::T_i32;
|
|
|
|
import trans::T_int;
|
2011-05-26 20:20:48 -05:00
|
|
|
import trans::T_nil;
|
2011-05-12 10:24:54 -05:00
|
|
|
import trans::T_opaque_chan_ptr;
|
2011-06-13 20:52:04 -05:00
|
|
|
import trans::T_opaque_ivec;
|
2011-05-12 10:24:54 -05:00
|
|
|
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
|
|
|
|
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-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 get_type_desc,
|
|
|
|
ValueRef new_task,
|
|
|
|
ValueRef start_task,
|
|
|
|
ValueRef new_thread,
|
2011-06-13 20:52:04 -05:00
|
|
|
ValueRef start_thread,
|
|
|
|
ValueRef ivec_resize,
|
|
|
|
ValueRef ivec_spill
|
2011-05-09 17:32:12 -05:00
|
|
|
);
|
|
|
|
|
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-16 20:21:22 -05:00
|
|
|
let vec[TypeRef] arg_tys = [T_taskptr(tn)];
|
|
|
|
for (TypeRef t in tys) { arg_tys += [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
|
2011-05-16 20:21:22 -05:00
|
|
|
let vec[TypeRef] empty_vec = [];
|
2011-05-09 17:32:12 -05:00
|
|
|
|
2011-05-09 18:58:19 -05:00
|
|
|
ret @rec(
|
2011-05-16 20:21:22 -05:00
|
|
|
grow_task=dv("grow_task", [T_size_t()]),
|
|
|
|
log_int=dv("log_int", [T_i32(), T_i32()]),
|
|
|
|
log_float=dv("log_float", [T_i32(), T_f32()]),
|
|
|
|
log_double=dv("log_double", [T_i32(), T_ptr(T_f64())]),
|
|
|
|
log_str=dv("log_str", [T_i32(), T_ptr(T_str())]),
|
|
|
|
trace_word=dv("trace_word", [T_int()]),
|
|
|
|
trace_str=dv("trace_str", [T_ptr(T_i8())]),
|
|
|
|
new_port=d("new_port", [T_size_t()], T_opaque_port_ptr()),
|
|
|
|
del_port=dv("del_port", [T_opaque_port_ptr()]),
|
|
|
|
new_chan=d("new_chan", [T_opaque_port_ptr()], T_opaque_chan_ptr()),
|
|
|
|
flush_chan=dv("flush_chan", [T_opaque_chan_ptr()]),
|
|
|
|
del_chan=dv("del_chan", [T_opaque_chan_ptr()]),
|
|
|
|
clone_chan=d("clone_chan", [T_taskptr(tn), T_opaque_chan_ptr()],
|
2011-05-10 16:03:47 -05:00
|
|
|
T_opaque_chan_ptr()),
|
2011-05-09 18:58:19 -05:00
|
|
|
_yield=dv("yield", empty_vec),
|
2011-05-16 20:21:22 -05:00
|
|
|
sleep=dv("sleep", [T_size_t()]),
|
|
|
|
_join=dv("join", [T_taskptr(tn)]),
|
|
|
|
send=dv("send", [T_opaque_chan_ptr(), T_ptr(T_i8())]),
|
|
|
|
recv=dv("recv", [T_ptr(T_ptr(T_i8())), T_opaque_port_ptr()]),
|
|
|
|
_fail=dv("fail", [T_ptr(T_i8()), T_ptr(T_i8()), T_size_t()]),
|
|
|
|
kill=dv("kill", [T_taskptr(tn)]),
|
2011-05-09 18:58:19 -05:00
|
|
|
exit=dv("exit", empty_vec),
|
2011-05-16 20:21:22 -05:00
|
|
|
malloc=d("malloc", [T_size_t(), T_ptr(T_tydesc(tn))],
|
2011-05-09 18:58:19 -05:00
|
|
|
T_ptr(T_i8())),
|
2011-05-16 20:21:22 -05:00
|
|
|
free=dv("free", [T_ptr(T_i8()), T_int()]),
|
|
|
|
mark=d("mark", [T_ptr(T_i8())], T_int()),
|
|
|
|
new_str=d("new_str", [T_ptr(T_i8()), T_size_t()], T_ptr(T_str())),
|
|
|
|
new_vec=d("new_vec", [T_size_t(), T_ptr(T_tydesc(tn))],
|
2011-05-09 18:58:19 -05:00
|
|
|
T_opaque_vec_ptr()),
|
2011-05-16 20:21:22 -05:00
|
|
|
vec_grow=d("vec_grow", [T_opaque_vec_ptr(), T_size_t(),
|
|
|
|
T_ptr(T_int()), T_ptr(T_tydesc(tn))],
|
2011-05-09 18:58:19 -05:00
|
|
|
T_opaque_vec_ptr()),
|
2011-05-09 17:32:12 -05:00
|
|
|
get_type_desc=d("get_type_desc",
|
2011-05-26 20:20:48 -05:00
|
|
|
[T_ptr(T_nil()), T_size_t(), T_size_t(),
|
|
|
|
T_size_t(), T_ptr(T_ptr(T_tydesc(tn)))],
|
2011-05-09 18:58:19 -05:00
|
|
|
T_ptr(T_tydesc(tn))),
|
2011-05-20 16:29:26 -05:00
|
|
|
new_task=d("new_task", [T_ptr(T_str())], T_taskptr(tn)),
|
2011-05-20 18:45:51 -05:00
|
|
|
start_task=d("start_task", [T_taskptr(tn),
|
2011-05-31 19:44:54 -05:00
|
|
|
T_int(), T_int(), T_size_t()],
|
2011-05-09 18:58:19 -05:00
|
|
|
T_taskptr(tn)),
|
2011-05-16 20:21:22 -05:00
|
|
|
new_thread=d("new_thread", [T_ptr(T_i8())], T_taskptr(tn)),
|
|
|
|
start_thread=d("start_thread", [T_taskptr(tn), T_int(), T_int(),
|
|
|
|
T_int(), T_size_t()],
|
2011-06-13 20:52:04 -05:00
|
|
|
T_taskptr(tn)),
|
|
|
|
ivec_resize=d("ivec_resize", [T_ptr(T_opaque_ivec()), T_int()],
|
|
|
|
T_void()),
|
|
|
|
ivec_spill=d("ivec_spill", [T_ptr(T_opaque_ivec()), T_int()],
|
|
|
|
T_void())
|
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
|
|
|
|
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|
|
|
|
//
|