authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-07 14:49:26-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-07 14:49:26-04:00
log0e8b65c537c897786803e452bd054948b4b57bfe
treef01dee6fbb9df9d6bf697838e6bf170df0dc6a36
parentec17f4ebbef624526ed68f4fffcb2c5eec71bef9
signaturelock-open Commit is signed but in an unrecognized format.

hook up peer result locs to if optional and if err


2 files changed, 51 insertions(+), 14 deletions(-)

BRANCH_TODO-2
......@@ -1,8 +1,6 @@
11Scratch pad for stuff to do before merging master
22=================================================
33
4 * if bool - do we need to call lval wrap or just expr wrap?
5 * hook up peer result locs to if optional and if err
64 * hook up peer result locs to while bool, while optional, and while err
75 * hook up peer result locs to for
86 * hook up peer result locs to catch
src/ir.cpp+51-12
......@@ -6339,7 +6339,9 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
63396339 input_list, output_types, output_vars, return_count, is_volatile);
63406340}
63416341
6342static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
6342static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
6343 ResultLoc *result_loc)
6344{
63436345 assert(node->type == NodeTypeIfOptional);
63446346
63456347 Buf *var_symbol = node->data.test_expr.var_symbol;
......@@ -6365,7 +6367,23 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
63656367 } else {
63666368 is_comptime = ir_build_test_comptime(irb, scope, node, is_non_null);
63676369 }
6368 ir_build_cond_br(irb, scope, node, is_non_null, then_block, else_block, is_comptime);
6370 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null,
6371 then_block, else_block, is_comptime);
6372
6373 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
6374 peer_parent->base.id = ResultLocIdPeerParent;
6375 peer_parent->base.source_instruction = cond_br_inst;
6376 peer_parent->parent = result_loc;
6377 peer_parent->peer_count = 2;
6378 peer_parent->peers = allocate<ResultLocPeer>(2);
6379 peer_parent->peers[0].base.id = ResultLocIdPeer;
6380 peer_parent->peers[0].base.source_instruction = cond_br_inst;
6381 peer_parent->peers[0].parent = peer_parent;
6382 peer_parent->peers[0].next_bb = else_block;
6383 peer_parent->peers[1].base.id = ResultLocIdPeer;
6384 peer_parent->peers[1].base.source_instruction = cond_br_inst;
6385 peer_parent->peers[1].parent = peer_parent;
6386 peer_parent->peers[1].next_bb = endif_block;
63696387
63706388 ir_set_cursor_at_end_and_append_block(irb, then_block);
63716389
......@@ -6384,7 +6402,8 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
63846402 } else {
63856403 var_scope = subexpr_scope;
63866404 }
6387 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope);
6405 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
6406 &peer_parent->peers[0].base);
63886407 if (then_expr_result == irb->codegen->invalid_instruction)
63896408 return then_expr_result;
63906409 IrBasicBlock *after_then_block = irb->current_basic_block;
......@@ -6394,7 +6413,7 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
63946413 ir_set_cursor_at_end_and_append_block(irb, else_block);
63956414 IrInstruction *else_expr_result;
63966415 if (else_node) {
6397 else_expr_result = ir_gen_node(irb, else_node, subexpr_scope);
6416 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers[1].base);
63986417 if (else_expr_result == irb->codegen->invalid_instruction)
63996418 return else_expr_result;
64006419 } else {
......@@ -6412,10 +6431,13 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
64126431 incoming_blocks[0] = after_then_block;
64136432 incoming_blocks[1] = after_else_block;
64146433
6415 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values);
6434 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values);
6435 return ir_expr_wrap(irb, scope, phi, result_loc);
64166436}
64176437
6418static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
6438static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
6439 ResultLoc *result_loc)
6440{
64196441 assert(node->type == NodeTypeIfErrorExpr);
64206442
64216443 AstNode *target_node = node->data.if_err_expr.target_node;
......@@ -6439,7 +6461,22 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
64396461
64406462 bool force_comptime = ir_should_inline(irb->exec, scope);
64416463 IrInstruction *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err);
6442 ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime);
6464 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime);
6465
6466 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
6467 peer_parent->base.id = ResultLocIdPeerParent;
6468 peer_parent->base.source_instruction = cond_br_inst;
6469 peer_parent->parent = result_loc;
6470 peer_parent->peer_count = 2;
6471 peer_parent->peers = allocate<ResultLocPeer>(2);
6472 peer_parent->peers[0].base.id = ResultLocIdPeer;
6473 peer_parent->peers[0].base.source_instruction = cond_br_inst;
6474 peer_parent->peers[0].parent = peer_parent;
6475 peer_parent->peers[0].next_bb = else_block;
6476 peer_parent->peers[1].base.id = ResultLocIdPeer;
6477 peer_parent->peers[1].base.source_instruction = cond_br_inst;
6478 peer_parent->peers[1].parent = peer_parent;
6479 peer_parent->peers[1].next_bb = endif_block;
64436480
64446481 ir_set_cursor_at_end_and_append_block(irb, ok_block);
64456482
......@@ -6459,7 +6496,8 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
64596496 } else {
64606497 var_scope = subexpr_scope;
64616498 }
6462 IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope);
6499 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
6500 &peer_parent->peers[0].base);
64636501 if (then_expr_result == irb->codegen->invalid_instruction)
64646502 return then_expr_result;
64656503 IrBasicBlock *after_then_block = irb->current_basic_block;
......@@ -6483,7 +6521,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
64836521 } else {
64846522 err_var_scope = subexpr_scope;
64856523 }
6486 else_expr_result = ir_gen_node(irb, else_node, err_var_scope);
6524 else_expr_result = ir_gen_node_extra(irb, else_node, err_var_scope, lval, &peer_parent->peers[1].base);
64876525 if (else_expr_result == irb->codegen->invalid_instruction)
64886526 return else_expr_result;
64896527 } else {
......@@ -6501,7 +6539,8 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
65016539 incoming_blocks[0] = after_then_block;
65026540 incoming_blocks[1] = after_else_block;
65036541
6504 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values);
6542 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values);
6543 return ir_expr_wrap(irb, scope, phi, result_loc);
65056544}
65066545
65076546static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node,
......@@ -7866,9 +7905,9 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
78667905 case NodeTypeNullLiteral:
78677906 return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval, result_loc);
78687907 case NodeTypeIfErrorExpr:
7869 return ir_lval_wrap(irb, scope, ir_gen_if_err_expr(irb, scope, node), lval, result_loc);
7908 return ir_gen_if_err_expr(irb, scope, node, lval, result_loc);
78707909 case NodeTypeIfOptional:
7871 return ir_lval_wrap(irb, scope, ir_gen_if_optional_expr(irb, scope, node), lval, result_loc);
7910 return ir_gen_if_optional_expr(irb, scope, node, lval, result_loc);
78727911 case NodeTypeSwitchExpr:
78737912 return ir_gen_switch_expr(irb, scope, node, lval, result_loc);
78747913 case NodeTypeCompTime: