Created
May 25, 2011 22:16
-
-
Save eholk/992122 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn mk_spawn_wrapper(&@block_ctxt cx, | |
&str tname, | |
&@ast::expr func, | |
&ty::t args_ty) -> result { | |
auto llmod = cx.fcx.lcx.ccx.llmod; | |
let TypeRef args_ty_tref = type_of(cx.fcx.lcx.ccx, cx.sp, args_ty); | |
let TypeRef wrapper_fn_type = T_fn([args_ty_tref], T_void()); | |
log_err #fmt("wrapper args type", | |
ty_str(cx.fcx.lcx.ccx.tn, args_ty_tref)); | |
log_err #fmt("wrapper fn desired type", | |
ty_str(cx.fcx.lcx.ccx.tn, wrapper_fn_type)); | |
// TODO: construct a name based on tname | |
auto llfndecl = decl_cdecl_fn(llmod, "spawn_wrap", | |
wrapper_fn_type); | |
log_err #fmt("spawn wrapper decl type: %s", | |
ty_str(cx.fcx.lcx.ccx.tn, llfndecl)); | |
auto fcx = new_fn_ctxt(cx.fcx.lcx, cx.sp, llfndecl); | |
auto fbcx = new_top_block_ctxt(fcx); | |
log_err #fmt("spawn wrapper type: %s", ty_str(fcx.lcx.ccx.tn, | |
fcx.llfn)); | |
// 3u to skip the three implicit args | |
let ValueRef arg = llvm::LLVMGetParam(fcx.llfn, 0u); | |
log_err #fmt("arg type: %s", ty_str(fbcx.fcx.lcx.ccx.tn, arg)); | |
let vec[ValueRef] child_args = []; | |
// unpack the arguments | |
alt(ty::struct(fcx.lcx.ccx.tcx, args_ty)) { | |
case(ty::ty_tup(?elements)) { | |
auto i = 0; | |
for(ty::mt m in elements) { | |
log_err #fmt("GEP arg %d", i); | |
auto src = fbcx.build.GEP(arg, [C_int(0), C_int(i)]); | |
i += 1; | |
auto child_arg = fbcx.build.Load(src); | |
child_args += [child_arg]; | |
} | |
} | |
} | |
// Find the function | |
auto fnptr = trans_lval(fbcx, func).res; | |
fbcx = fnptr.bcx; | |
log_err "SPAWN 1"; | |
auto llfnptr = fbcx.build.GEP(fnptr.val, | |
[C_int(0), C_int(0)]); | |
log_err "SPAWN 2"; | |
fbcx.build.Call(llfnptr, | |
child_args); | |
// all done... with the wrapper function | |
// now evaluate the wrapper into something we can pass to | |
// upcall_start_task. | |
// TODO! | |
fail; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment