@@ -1071,7 +1071,7 @@ fn trans_name(@block_ctxt cx, &ast.name n, &option.t[ast.def] dopt)
1071
1071
case ( ast. def_arg ( ?did) ) {
1072
1072
check ( cx. fcx . llargs . contains_key ( did) ) ;
1073
1073
ret tup( res ( cx, cx. fcx . llargs . get ( did) ) ,
1074
- false ) ;
1074
+ true ) ;
1075
1075
}
1076
1076
case ( ast. def_local ( ?did) ) {
1077
1077
check ( cx. fcx . lllocals . contains_key ( did) ) ;
@@ -1521,15 +1521,46 @@ fn new_fn_ctxt(@crate_ctxt cx,
1521
1521
ccx=cx) ;
1522
1522
}
1523
1523
1524
+
1525
+ // Recommended LLVM style, strange though this is, is to copy from args to
1526
+ // allocas immediately upon entry; this permits us to GEP into structures we
1527
+ // were passed and whatnot. Apparently mem2reg will mop up.
1528
+
1529
+ fn copy_args_to_allocas ( @block_ctxt cx , & ast . _fn f, & ast. ann ann ) {
1530
+
1531
+ let vec[ typeck. arg ] arg_ts = vec ( ) ;
1532
+ let @typeck. ty fty = node_ann_type ( cx. fcx . ccx , ann) ;
1533
+ alt ( fty. struct ) {
1534
+ case ( typeck. ty_fn ( ?a, _) ) { arg_ts += a; }
1535
+ }
1536
+
1537
+ let uint arg_n = 0 u;
1538
+
1539
+ for ( ast. arg aarg in f. inputs ) {
1540
+ auto arg = arg_ts. ( arg_n) ;
1541
+ auto arg_t = type_of ( cx. fcx . ccx , arg. ty ) ;
1542
+ auto alloca = cx. build . Alloca ( arg_t) ;
1543
+ auto argval = cx. fcx . llargs . get ( aarg. id ) ;
1544
+ cx. build . Store ( argval, alloca) ;
1545
+ // Overwrite the llargs entry for this arg with its alloca.
1546
+ cx. fcx . llargs . insert ( aarg. id , alloca) ;
1547
+ arg_n += 1 u;
1548
+ }
1549
+ }
1550
+
1524
1551
fn is_terminated ( @block_ctxt cx ) -> bool {
1525
1552
auto inst = llvm. LLVMGetLastInstruction ( cx. llbb ) ;
1526
1553
ret llvm. LLVMIsATerminatorInst ( inst) as int != 0 ;
1527
1554
}
1528
1555
1529
- impure fn trans_fn ( @crate_ctxt cx , & ast . _fn f, ast. def_id fid ) {
1556
+ impure fn trans_fn ( @crate_ctxt cx , & ast . _fn f, ast. def_id fid ,
1557
+ & ast. ann ann ) {
1530
1558
1531
1559
auto fcx = new_fn_ctxt ( cx, cx. path , f, fid) ;
1532
1560
auto bcx = new_top_block_ctxt ( fcx) ;
1561
+
1562
+ copy_args_to_allocas ( bcx, f, ann) ;
1563
+
1533
1564
auto res = trans_block ( bcx, f. body ) ;
1534
1565
if ( !is_terminated ( res. bcx ) ) {
1535
1566
// FIXME: until LLVM has a unit type, we are moving around
@@ -1540,9 +1571,9 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid) {
1540
1571
1541
1572
impure fn trans_item ( @crate_ctxt cx , & ast . item item) {
1542
1573
alt ( item. node ) {
1543
- case ( ast. item_fn ( ?name, ?f, _, ?fid, _ ) ) {
1574
+ case ( ast. item_fn ( ?name, ?f, _, ?fid, ?ann ) ) {
1544
1575
auto sub_cx = @rec ( path=cx. path + "." + name with * cx) ;
1545
- trans_fn ( sub_cx, f, fid) ;
1576
+ trans_fn ( sub_cx, f, fid, ann ) ;
1546
1577
}
1547
1578
case ( ast. item_mod ( ?name, ?m, _) ) {
1548
1579
auto sub_cx = @rec ( path=cx. path + "." + name with * cx) ;
0 commit comments