authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-07 15:48:28-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-07 15:48:28-04:00
logede3436b087223f88c65124a12b7d477d792748d
tree94fd91348da3f1ffa6d8fcb26747e5c77222304f
parentec8d8a9774c01945dbd2c9ddf4e0f5d77e7ebbb9
signaturelock-open Commit is signed but in an unrecognized format.

hook up peer result locs to while bool and optional


2 files changed, 32 insertions(+), 9 deletions(-)

BRANCH_TODO-1
......@@ -1,7 +1,6 @@
11Scratch pad for stuff to do before merging master
22=================================================
33
4 * hook up peer result locs to while bool, while optional, and while err
54 * hook up peer result locs to for
65 * hook up peer result locs to catch
76 * struct initializations
src/ir.cpp+32-8
......@@ -5732,6 +5732,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
57325732 if (!instr_is_unreachable(is_err)) {
57335733 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_err,
57345734 else_block, body_block, is_comptime);
5735 cond_br_inst->is_gen = true;
57355736 } else {
57365737 cond_br_inst = is_err; // for the purposes of the source instruction to create_binary_result_peers
57375738 }
......@@ -5827,11 +5828,17 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
58275828 IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node->data.while_expr.condition, maybe_val);
58285829 IrBasicBlock *after_cond_block = irb->current_basic_block;
58295830 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
5831 IrInstruction *cond_br_inst;
58305832 if (!instr_is_unreachable(is_non_null)) {
5831 ir_mark_gen(ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null,
5832 body_block, else_block, is_comptime));
5833 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null,
5834 body_block, else_block, is_comptime);
5835 cond_br_inst->is_gen = true;
5836 } else {
5837 cond_br_inst = is_non_null; // for the purposes of source instruction for create_binary_result_peers
58335838 }
58345839
5840 ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, result_loc);
5841
58355842 ir_set_cursor_at_end_and_append_block(irb, body_block);
58365843 IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false);
58375844 IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ?
......@@ -5847,7 +5854,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
58475854 loop_scope->is_comptime = is_comptime;
58485855 loop_scope->incoming_blocks = &incoming_blocks;
58495856 loop_scope->incoming_values = &incoming_values;
5857 loop_scope->lval = lval;
5858 loop_scope->result_loc = &peer_parent->peers[0].base;
58505859
5860 // Note the body block of the loop is not the place that lval and result_loc are used -
5861 // it's actually in break statements, handled similarly to return statements.
5862 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
58515863 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
58525864 if (body_result == irb->codegen->invalid_instruction)
58535865 return body_result;
......@@ -5872,7 +5884,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
58725884 if (else_node) {
58735885 ir_set_cursor_at_end_and_append_block(irb, else_block);
58745886
5875 else_result = ir_gen_node(irb, else_node, scope);
5887 else_result = ir_gen_node_extra(irb, else_node, scope, lval, &peer_parent->peers[1].base);
58765888 if (else_result == irb->codegen->invalid_instruction)
58775889 return else_result;
58785890 if (!instr_is_unreachable(else_result))
......@@ -5888,7 +5900,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
58885900 incoming_values.append(void_else_result);
58895901 }
58905902
5891 return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
5903 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
5904 return ir_expr_wrap(irb, scope, phi, result_loc);
58925905 } else {
58935906 ir_set_cursor_at_end_and_append_block(irb, cond_block);
58945907 IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);
......@@ -5896,11 +5909,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
58965909 return cond_val;
58975910 IrBasicBlock *after_cond_block = irb->current_basic_block;
58985911 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
5912 IrInstruction *cond_br_inst;
58995913 if (!instr_is_unreachable(cond_val)) {
5900 ir_mark_gen(ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,
5901 body_block, else_block, is_comptime));
5914 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,
5915 body_block, else_block, is_comptime);
5916 cond_br_inst->is_gen = true;
5917 } else {
5918 cond_br_inst = cond_val; // for the source instruction arg to create_binary_result_peers
59025919 }
59035920
5921 ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, result_loc);
59045922 ir_set_cursor_at_end_and_append_block(irb, body_block);
59055923
59065924 ZigList<IrInstruction *> incoming_values = {0};
......@@ -5914,7 +5932,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
59145932 loop_scope->is_comptime = is_comptime;
59155933 loop_scope->incoming_blocks = &incoming_blocks;
59165934 loop_scope->incoming_values = &incoming_values;
5935 loop_scope->lval = lval;
5936 loop_scope->result_loc = &peer_parent->peers[0].base;
59175937
5938 // Note the body block of the loop is not the place that lval and result_loc are used -
5939 // it's actually in break statements, handled similarly to return statements.
5940 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
59185941 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
59195942 if (body_result == irb->codegen->invalid_instruction)
59205943 return body_result;
......@@ -5939,7 +5962,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
59395962 if (else_node) {
59405963 ir_set_cursor_at_end_and_append_block(irb, else_block);
59415964
5942 else_result = ir_gen_node(irb, else_node, subexpr_scope);
5965 else_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers[1].base);
59435966 if (else_result == irb->codegen->invalid_instruction)
59445967 return else_result;
59455968 if (!instr_is_unreachable(else_result))
......@@ -5955,7 +5978,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
59555978 incoming_values.append(void_else_result);
59565979 }
59575980
5958 return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
5981 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
5982 return ir_expr_wrap(irb, scope, phi, result_loc);
59595983 }
59605984}
59615985