diff options
| author | Patrick Walton <[email protected]> | 2010-12-06 11:22:08 -0800 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2010-12-06 11:22:08 -0800 |
| commit | fb05d9184b83bc92dbeb7e4b8c0e2404ac8172f5 (patch) | |
| tree | 44b969f3b81e0c76c433e4e82952d87086579ec9 /src | |
| parent | Drop rec and tup alloca temporariles on block exit. (diff) | |
| download | rust-fb05d9184b83bc92dbeb7e4b8c0e2404ac8172f5.tar.xz rust-fb05d9184b83bc92dbeb7e4b8c0e2404ac8172f5.zip | |
rustc: Make copy_args_to_allocas not insist on a function type so it's easier to make it work with tag constructors
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/middle/trans.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 64cba812..9e703b15 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -1817,19 +1817,13 @@ fn new_fn_ctxt(@crate_ctxt cx, // allocas immediately upon entry; this permits us to GEP into structures we // were passed and whatnot. Apparently mem2reg will mop up. -fn copy_args_to_allocas(@block_ctxt cx, vec[ast.arg] args, &ast.ann ann) { - - let vec[typeck.arg] arg_ts = vec(); - let @typeck.ty fty = node_ann_type(cx.fcx.ccx, ann); - alt (fty.struct) { - case (typeck.ty_fn(?a, _)) { arg_ts += a; } - } +fn copy_args_to_allocas(@block_ctxt cx, vec[ast.arg] args, + vec[typeck.arg] arg_tys) { let uint arg_n = 0u; for (ast.arg aarg in args) { - auto arg = arg_ts.(arg_n); - auto arg_t = type_of(cx.fcx.ccx, arg.ty); + auto arg_t = type_of(cx.fcx.ccx, arg_tys.(arg_n).ty); auto alloca = cx.build.Alloca(arg_t); auto argval = cx.fcx.llargs.get(aarg.id); cx.build.Store(argval, alloca); @@ -1844,13 +1838,22 @@ fn is_terminated(@block_ctxt cx) -> bool { ret llvm.LLVMIsATerminatorInst(inst) as int != 0; } +fn arg_tys_of_fn(ast.ann ann) -> vec[typeck.arg] { + alt (typeck.ann_to_type(ann).struct) { + case (typeck.ty_fn(?arg_tys, _)) { + ret arg_tys; + } + } + fail; +} + impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid, &ast.ann ann) { auto fcx = new_fn_ctxt(cx, cx.path, f.inputs, fid); auto bcx = new_top_block_ctxt(fcx); - copy_args_to_allocas(bcx, f.inputs, ann); + copy_args_to_allocas(bcx, f.inputs, arg_tys_of_fn(ann)); auto res = trans_block(bcx, f.body); if (!is_terminated(res.bcx)) { |