| ... | @@ -1069,6 +1069,7 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertNonNull *) | ... | @@ -1069,6 +1069,7 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertNonNull *) |
| 1069 | return IrInstructionIdAssertNonNull; | 1069 | return IrInstructionIdAssertNonNull; |
| 1070 | } | 1070 | } |
| 1071 | | 1071 | |
| | 1072 | <<<<<<< HEAD |
| 1072 | static constexpr IrInstructionId ir_instruction_id(IrInstructionHasDecl *) { | 1073 | static constexpr IrInstructionId ir_instruction_id(IrInstructionHasDecl *) { |
| 1073 | return IrInstructionIdHasDecl; | 1074 | return IrInstructionIdHasDecl; |
| 1074 | } | 1075 | } |
| ... | @@ -1089,6 +1090,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionEndExpr *) { | ... | @@ -1089,6 +1090,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionEndExpr *) { |
| 1089 | return IrInstructionIdEndExpr; | 1090 | return IrInstructionIdEndExpr; |
| 1090 | } | 1091 | } |
| 1091 | | 1092 | |
| | 1093 | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInitNamedField *) { |
| | 1094 | return IrInstructionIdUnionInitNamedField; |
| | 1095 | } |
| | 1096 | |
| 1092 | template<typename T> | 1097 | template<typename T> |
| 1093 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { | 1098 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1094 | T *special_instruction = allocate<T>(1); | 1099 | T *special_instruction = allocate<T>(1); |
| ... | @@ -3324,6 +3329,21 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, | ... | @@ -3324,6 +3329,21 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, |
| 3324 | return &instruction->base; | 3329 | return &instruction->base; |
| 3325 | } | 3330 | } |
| 3326 | | 3331 | |
| | 3332 | static IrInstruction *ir_build_union_init_2(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| | 3333 | IrInstruction *union_type_value, IrInstruction *field_name_expr, IrInstruction *value) { |
| | 3334 | IrInstructionUnionInit2 *instruction = ir_build_instruction<IrInstructionUnionInit2>(irb, scope, source_node); |
| | 3335 | instruction->union_type_value = union_type_value; |
| | 3336 | instruction->field_name_expr = field_name_expr; |
| | 3337 | instruction->value = value; |
| | 3338 | |
| | 3339 | ir_ref_instruction(union_type_value, irb->current_basic_block); |
| | 3340 | ir_ref_instruction(field_name_expr, irb->current_basic_block); |
| | 3341 | ir_ref_instruction(value, irb->current_basic_block); |
| | 3342 | |
| | 3343 | return &instruction->base; |
| | 3344 | } |
| | 3345 | |
| | 3346 | |
| 3327 | static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *source_instruction, | 3347 | static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3328 | ZigType *result_type, IrInstruction *vector, IrInstruction *result_loc) | 3348 | ZigType *result_type, IrInstruction *vector, IrInstruction *result_loc) |
| 3329 | { | 3349 | { |
| ... | @@ -5651,6 +5671,29 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5651,6 +5671,29 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5651 | IrInstruction *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value); | 5671 | IrInstruction *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value); |
| 5652 | return ir_lval_wrap(irb, scope, has_decl, lval, result_loc); | 5672 | return ir_lval_wrap(irb, scope, has_decl, lval, result_loc); |
| 5653 | } | 5673 | } |
| | 5674 | case BuiltinFnIdUnionInit: |
| | 5675 | { |
| | 5676 | |
| | 5677 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| | 5678 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| | 5679 | if (arg0_value == irb->codegen->invalid_instruction) |
| | 5680 | return arg0_value; |
| | 5681 | |
| | 5682 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| | 5683 | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| | 5684 | if (arg1_value == irb->codegen->invalid_instruction) |
| | 5685 | return arg1_value; |
| | 5686 | |
| | 5687 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| | 5688 | IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| | 5689 | if (arg2_value == irb->codegen->invalid_instruction) |
| | 5690 | return arg2_value; |
| | 5691 | |
| | 5692 | IrInstruction *result = ir_build_union_init_2(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| | 5693 | |
| | 5694 | // TODO: Not sure if we need ir_lval_wrap or not. |
| | 5695 | return result; |
| | 5696 | } |
| 5654 | } | 5697 | } |
| 5655 | zig_unreachable(); | 5698 | zig_unreachable(); |
| 5656 | } | 5699 | } |
| ... | @@ -25326,6 +25369,35 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst | ... | @@ -25326,6 +25369,35 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst |
| 25326 | return instruction->result_loc_bit_cast->parent->gen_instruction; | 25369 | return instruction->result_loc_bit_cast->parent->gen_instruction; |
| 25327 | } | 25370 | } |
| 25328 | | 25371 | |
| | 25372 | static IrInstruction *ir_analyze_instruction_union_init_2(IrAnalyze *ira, IrInstructionUnionInit2 *union_init_instruction) |
| | 25373 | { |
| | 25374 | Error err; |
| | 25375 | IrInstruction *union_type_value = union_init_instruction->union_type_value->child; |
| | 25376 | ZigType *union_type = ir_resolve_type(ira, union_type_value); |
| | 25377 | if (type_is_invalid(union_type)) { |
| | 25378 | return ira->codegen->invalid_instruction; |
| | 25379 | } |
| | 25380 | |
| | 25381 | if (union_type->id != ZigTypeIdUnion) |
| | 25382 | return ira->codegen->invalid_instruction; |
| | 25383 | |
| | 25384 | if ((err = ensure_complete_type(ira->codegen, union_type))) |
| | 25385 | return ira->codegen->invalid_instruction; |
| | 25386 | |
| | 25387 | IrInstruction *field_name_expr = union_init_instruction->field_name_expr->child; |
| | 25388 | Buf *field_name = ir_resolve_str(ira, field_name_expr); |
| | 25389 | if (!field_name) |
| | 25390 | return ira->codegen->invalid_instruction; |
| | 25391 | |
| | 25392 | IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(1); |
| | 25393 | |
| | 25394 | fields[0].name = field_name; |
| | 25395 | fields[0].value = union_init_instruction->value; |
| | 25396 | fields[0].source_node = union_init_instruction->base.source_node; |
| | 25397 | |
| | 25398 | return ir_analyze_container_init_fields_union(ira, &union_init_instruction->base, union_type, 1, fields); |
| | 25399 | } |
| | 25400 | |
| 25329 | static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction *instruction) { | 25401 | static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction *instruction) { |
| 25330 | switch (instruction->id) { | 25402 | switch (instruction->id) { |
| 25331 | case IrInstructionIdInvalid: | 25403 | case IrInstructionIdInvalid: |
| ... | @@ -25641,6 +25713,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction | ... | @@ -25641,6 +25713,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 25641 | return ir_analyze_instruction_end_expr(ira, (IrInstructionEndExpr *)instruction); | 25713 | return ir_analyze_instruction_end_expr(ira, (IrInstructionEndExpr *)instruction); |
| 25642 | case IrInstructionIdBitCastSrc: | 25714 | case IrInstructionIdBitCastSrc: |
| 25643 | return ir_analyze_instruction_bit_cast_src(ira, (IrInstructionBitCastSrc *)instruction); | 25715 | return ir_analyze_instruction_bit_cast_src(ira, (IrInstructionBitCastSrc *)instruction); |
| | 25716 | case IrInstructionIdUnionInitNamedField: |
| | 25717 | return ir_analyze_instruction_union_init_named_field(ira, (IrInstructionUnionInitNamedField *)instruction); |
| 25644 | } | 25718 | } |
| 25645 | zig_unreachable(); | 25719 | zig_unreachable(); |
| 25646 | } | 25720 | } |
| ... | @@ -25794,6 +25868,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -25794,6 +25868,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 25794 | case IrInstructionIdCast: | 25868 | case IrInstructionIdCast: |
| 25795 | case IrInstructionIdContainerInitList: | 25869 | case IrInstructionIdContainerInitList: |
| 25796 | case IrInstructionIdContainerInitFields: | 25870 | case IrInstructionIdContainerInitFields: |
| | 25871 | case IrInstructionIdUnionInitNamedField: |
| 25797 | case IrInstructionIdFieldPtr: | 25872 | case IrInstructionIdFieldPtr: |
| 25798 | case IrInstructionIdElemPtr: | 25873 | case IrInstructionIdElemPtr: |
| 25799 | case IrInstructionIdVarPtr: | 25874 | case IrInstructionIdVarPtr: |