| ... | @@ -226,9 +226,13 @@ static TypeTableEntry *get_type_for_type_node(AstNode *node) { | ... | @@ -226,9 +226,13 @@ static TypeTableEntry *get_type_for_type_node(AstNode *node) { |
| 226 | return const_val->data.x_type; | 226 | return const_val->data.x_type; |
| 227 | } | 227 | } |
| 228 | | 228 | |
| 229 | static void add_debug_source_node(CodeGen *g, AstNode *node) { | 229 | static void set_debug_source_node(CodeGen *g, AstNode *node) { |
| 230 | assert(node->block_context); | 230 | assert(node->block_context); |
| 231 | LLVMZigSetCurrentDebugLocation(g->builder, node->line + 1, node->column + 1, node->block_context->di_scope); | 231 | ZigLLVMSetCurrentDebugLocation(g->builder, node->line + 1, node->column + 1, node->block_context->di_scope); |
| | 232 | } |
| | 233 | |
| | 234 | static void clear_debug_source_node(CodeGen *g) { |
| | 235 | ZigLLVMClearCurrentDebugLocation(g->builder); |
| 232 | } | 236 | } |
| 233 | | 237 | |
| 234 | static TypeTableEntry *get_expr_type(AstNode *node) { | 238 | static TypeTableEntry *get_expr_type(AstNode *node) { |
| ... | @@ -325,7 +329,7 @@ static LLVMValueRef get_handle_value(CodeGen *g, AstNode *source_node, LLVMValue | ... | @@ -325,7 +329,7 @@ static LLVMValueRef get_handle_value(CodeGen *g, AstNode *source_node, LLVMValue |
| 325 | if (handle_is_ptr(type)) { | 329 | if (handle_is_ptr(type)) { |
| 326 | return ptr; | 330 | return ptr; |
| 327 | } else { | 331 | } else { |
| 328 | add_debug_source_node(g, source_node); | 332 | set_debug_source_node(g, source_node); |
| 329 | return LLVMBuildLoad(g->builder, ptr, ""); | 333 | return LLVMBuildLoad(g->builder, ptr, ""); |
| 330 | } | 334 | } |
| 331 | } | 335 | } |
| ... | @@ -347,7 +351,7 @@ static void add_bounds_check(CodeGen *g, AstNode *source_node, LLVMValueRef targ | ... | @@ -347,7 +351,7 @@ static void add_bounds_check(CodeGen *g, AstNode *source_node, LLVMValueRef targ |
| 347 | upper_value = nullptr; | 351 | upper_value = nullptr; |
| 348 | } | 352 | } |
| 349 | | 353 | |
| 350 | add_debug_source_node(g, source_node); | 354 | set_debug_source_node(g, source_node); |
| 351 | | 355 | |
| 352 | LLVMBasicBlockRef bounds_check_fail_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "BoundsCheckFail"); | 356 | LLVMBasicBlockRef bounds_check_fail_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "BoundsCheckFail"); |
| 353 | LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "BoundsCheckOk"); | 357 | LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "BoundsCheckOk"); |
| ... | @@ -382,7 +386,7 @@ static LLVMValueRef gen_err_name(CodeGen *g, AstNode *node) { | ... | @@ -382,7 +386,7 @@ static LLVMValueRef gen_err_name(CodeGen *g, AstNode *node) { |
| 382 | | 386 | |
| 383 | AstNode *err_val_node = node->data.fn_call_expr.params.at(0); | 387 | AstNode *err_val_node = node->data.fn_call_expr.params.at(0); |
| 384 | LLVMValueRef err_val = gen_expr(g, err_val_node); | 388 | LLVMValueRef err_val = gen_expr(g, err_val_node); |
| 385 | add_debug_source_node(g, node); | 389 | set_debug_source_node(g, node); |
| 386 | | 390 | |
| 387 | if (want_debug_safety(g, node)) { | 391 | if (want_debug_safety(g, node)) { |
| 388 | LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(err_val)); | 392 | LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(err_val)); |
| ... | @@ -425,7 +429,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { | ... | @@ -425,7 +429,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { |
| 425 | operand, | 429 | operand, |
| 426 | LLVMConstNull(LLVMInt1Type()), | 430 | LLVMConstNull(LLVMInt1Type()), |
| 427 | }; | 431 | }; |
| 428 | add_debug_source_node(g, node); | 432 | set_debug_source_node(g, node); |
| 429 | return LLVMBuildCall(g->builder, fn_val, params, 2, ""); | 433 | return LLVMBuildCall(g->builder, fn_val, params, 2, ""); |
| 430 | } | 434 | } |
| 431 | case BuiltinFnIdAddWithOverflow: | 435 | case BuiltinFnIdAddWithOverflow: |
| ... | @@ -457,7 +461,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { | ... | @@ -457,7 +461,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { |
| 457 | op2, | 461 | op2, |
| 458 | }; | 462 | }; |
| 459 | | 463 | |
| 460 | add_debug_source_node(g, node); | 464 | set_debug_source_node(g, node); |
| 461 | LLVMValueRef result_struct = LLVMBuildCall(g->builder, fn_val, params, 2, ""); | 465 | LLVMValueRef result_struct = LLVMBuildCall(g->builder, fn_val, params, 2, ""); |
| 462 | LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, ""); | 466 | LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, ""); |
| 463 | LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, ""); | 467 | LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, ""); |
| ... | @@ -479,7 +483,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { | ... | @@ -479,7 +483,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { |
| 479 | | 483 | |
| 480 | LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); | 484 | LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); |
| 481 | | 485 | |
| 482 | add_debug_source_node(g, node); | 486 | set_debug_source_node(g, node); |
| 483 | LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); | 487 | LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); |
| 484 | LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, ""); | 488 | LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, ""); |
| 485 | | 489 | |
| ... | @@ -510,7 +514,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { | ... | @@ -510,7 +514,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { |
| 510 | | 514 | |
| 511 | LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); | 515 | LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); |
| 512 | | 516 | |
| 513 | add_debug_source_node(g, node); | 517 | set_debug_source_node(g, node); |
| 514 | LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); | 518 | LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); |
| 515 | | 519 | |
| 516 | uint64_t align_in_bytes = get_memcpy_align(g, dest_type->data.pointer.child_type); | 520 | uint64_t align_in_bytes = get_memcpy_align(g, dest_type->data.pointer.child_type); |
| ... | @@ -540,7 +544,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { | ... | @@ -540,7 +544,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { |
| 540 | case BuiltinFnIdErrName: | 544 | case BuiltinFnIdErrName: |
| 541 | return gen_err_name(g, node); | 545 | return gen_err_name(g, node); |
| 542 | case BuiltinFnIdBreakpoint: | 546 | case BuiltinFnIdBreakpoint: |
| 543 | add_debug_source_node(g, node); | 547 | set_debug_source_node(g, node); |
| 544 | return LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, ""); | 548 | return LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, ""); |
| 545 | } | 549 | } |
| 546 | zig_unreachable(); | 550 | zig_unreachable(); |
| ... | @@ -570,7 +574,7 @@ static LLVMValueRef gen_enum_value_expr(CodeGen *g, AstNode *node, TypeTableEntr | ... | @@ -570,7 +574,7 @@ static LLVMValueRef gen_enum_value_expr(CodeGen *g, AstNode *node, TypeTableEntr |
| 570 | LLVMValueRef tmp_struct_ptr = node->data.field_access_expr.resolved_struct_val_expr.ptr; | 574 | LLVMValueRef tmp_struct_ptr = node->data.field_access_expr.resolved_struct_val_expr.ptr; |
| 571 | | 575 | |
| 572 | // populate the new tag value | 576 | // populate the new tag value |
| 573 | add_debug_source_node(g, node); | 577 | set_debug_source_node(g, node); |
| 574 | LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, 0, ""); | 578 | LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, 0, ""); |
| 575 | LLVMBuildStore(g->builder, tag_value, tag_field_ptr); | 579 | LLVMBuildStore(g->builder, tag_value, tag_field_ptr); |
| 576 | | 580 | |
| ... | @@ -610,14 +614,14 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, AstNode *source_node, TypeT | ... | @@ -610,14 +614,14 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, AstNode *source_node, TypeT |
| 610 | return expr_val; | 614 | return expr_val; |
| 611 | } else if (actual_bits < wanted_bits) { | 615 | } else if (actual_bits < wanted_bits) { |
| 612 | if (actual_type->id == TypeTableEntryIdFloat) { | 616 | if (actual_type->id == TypeTableEntryIdFloat) { |
| 613 | add_debug_source_node(g, source_node); | 617 | set_debug_source_node(g, source_node); |
| 614 | return LLVMBuildFPExt(g->builder, expr_val, wanted_type->type_ref, ""); | 618 | return LLVMBuildFPExt(g->builder, expr_val, wanted_type->type_ref, ""); |
| 615 | } else if (actual_type->id == TypeTableEntryIdInt) { | 619 | } else if (actual_type->id == TypeTableEntryIdInt) { |
| 616 | if (actual_type->data.integral.is_signed) { | 620 | if (actual_type->data.integral.is_signed) { |
| 617 | add_debug_source_node(g, source_node); | 621 | set_debug_source_node(g, source_node); |
| 618 | return LLVMBuildSExt(g->builder, expr_val, wanted_type->type_ref, ""); | 622 | return LLVMBuildSExt(g->builder, expr_val, wanted_type->type_ref, ""); |
| 619 | } else { | 623 | } else { |
| 620 | add_debug_source_node(g, source_node); | 624 | set_debug_source_node(g, source_node); |
| 621 | return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, ""); | 625 | return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, ""); |
| 622 | } | 626 | } |
| 623 | } else { | 627 | } else { |
| ... | @@ -625,10 +629,10 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, AstNode *source_node, TypeT | ... | @@ -625,10 +629,10 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, AstNode *source_node, TypeT |
| 625 | } | 629 | } |
| 626 | } else if (actual_bits > wanted_bits) { | 630 | } else if (actual_bits > wanted_bits) { |
| 627 | if (actual_type->id == TypeTableEntryIdFloat) { | 631 | if (actual_type->id == TypeTableEntryIdFloat) { |
| 628 | add_debug_source_node(g, source_node); | 632 | set_debug_source_node(g, source_node); |
| 629 | return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, ""); | 633 | return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, ""); |
| 630 | } else if (actual_type->id == TypeTableEntryIdInt) { | 634 | } else if (actual_type->id == TypeTableEntryIdInt) { |
| 631 | add_debug_source_node(g, source_node); | 635 | set_debug_source_node(g, source_node); |
| 632 | return LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, ""); | 636 | return LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, ""); |
| 633 | } else { | 637 | } else { |
| 634 | zig_unreachable(); | 638 | zig_unreachable(); |
| ... | @@ -675,12 +679,12 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { | ... | @@ -675,12 +679,12 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { |
| 675 | { | 679 | { |
| 676 | return expr_val; | 680 | return expr_val; |
| 677 | } else { | 681 | } else { |
| 678 | add_debug_source_node(g, node); | 682 | set_debug_source_node(g, node); |
| 679 | LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, 0, ""); | 683 | LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, 0, ""); |
| 680 | gen_assign_raw(g, node, BinOpTypeAssign, | 684 | gen_assign_raw(g, node, BinOpTypeAssign, |
| 681 | val_ptr, expr_val, child_type, actual_type); | 685 | val_ptr, expr_val, child_type, actual_type); |
| 682 | | 686 | |
| 683 | add_debug_source_node(g, node); | 687 | set_debug_source_node(g, node); |
| 684 | LLVMValueRef maybe_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, 1, ""); | 688 | LLVMValueRef maybe_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, 1, ""); |
| 685 | LLVMBuildStore(g->builder, LLVMConstAllOnes(LLVMInt1Type()), maybe_ptr); | 689 | LLVMBuildStore(g->builder, LLVMConstAllOnes(LLVMInt1Type()), maybe_ptr); |
| 686 | } | 690 | } |
| ... | @@ -700,7 +704,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { | ... | @@ -700,7 +704,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { |
| 700 | assert(wanted_type->id == TypeTableEntryIdErrorUnion); | 704 | assert(wanted_type->id == TypeTableEntryIdErrorUnion); |
| 701 | assert(actual_type); | 705 | assert(actual_type); |
| 702 | | 706 | |
| 703 | add_debug_source_node(g, node); | 707 | set_debug_source_node(g, node); |
| 704 | LLVMValueRef err_tag_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, 0, ""); | 708 | LLVMValueRef err_tag_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, 0, ""); |
| 705 | LLVMBuildStore(g->builder, ok_err_val, err_tag_ptr); | 709 | LLVMBuildStore(g->builder, ok_err_val, err_tag_ptr); |
| 706 | | 710 | |
| ... | @@ -720,13 +724,13 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { | ... | @@ -720,13 +724,13 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { |
| 720 | zig_panic("TODO"); | 724 | zig_panic("TODO"); |
| 721 | } | 725 | } |
| 722 | case CastOpPtrToInt: | 726 | case CastOpPtrToInt: |
| 723 | add_debug_source_node(g, node); | 727 | set_debug_source_node(g, node); |
| 724 | return LLVMBuildPtrToInt(g->builder, expr_val, wanted_type->type_ref, ""); | 728 | return LLVMBuildPtrToInt(g->builder, expr_val, wanted_type->type_ref, ""); |
| 725 | case CastOpIntToPtr: | 729 | case CastOpIntToPtr: |
| 726 | add_debug_source_node(g, node); | 730 | set_debug_source_node(g, node); |
| 727 | return LLVMBuildIntToPtr(g->builder, expr_val, wanted_type->type_ref, ""); | 731 | return LLVMBuildIntToPtr(g->builder, expr_val, wanted_type->type_ref, ""); |
| 728 | case CastOpPointerReinterpret: | 732 | case CastOpPointerReinterpret: |
| 729 | add_debug_source_node(g, node); | 733 | set_debug_source_node(g, node); |
| 730 | return LLVMBuildBitCast(g->builder, expr_val, wanted_type->type_ref, ""); | 734 | return LLVMBuildBitCast(g->builder, expr_val, wanted_type->type_ref, ""); |
| 731 | case CastOpWidenOrShorten: | 735 | case CastOpWidenOrShorten: |
| 732 | return gen_widen_or_shorten(g, node, actual_type, wanted_type, expr_val); | 736 | return gen_widen_or_shorten(g, node, actual_type, wanted_type, expr_val); |
| ... | @@ -738,7 +742,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { | ... | @@ -738,7 +742,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { |
| 738 | | 742 | |
| 739 | TypeTableEntry *pointer_type = wanted_type->data.structure.fields[0].type_entry; | 743 | TypeTableEntry *pointer_type = wanted_type->data.structure.fields[0].type_entry; |
| 740 | | 744 | |
| 741 | add_debug_source_node(g, node); | 745 | set_debug_source_node(g, node); |
| 742 | | 746 | |
| 743 | int ptr_index = wanted_type->data.structure.fields[0].gen_index; | 747 | int ptr_index = wanted_type->data.structure.fields[0].gen_index; |
| 744 | if (ptr_index >= 0) { | 748 | if (ptr_index >= 0) { |
| ... | @@ -758,26 +762,26 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { | ... | @@ -758,26 +762,26 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { |
| 758 | case CastOpIntToFloat: | 762 | case CastOpIntToFloat: |
| 759 | assert(actual_type->id == TypeTableEntryIdInt); | 763 | assert(actual_type->id == TypeTableEntryIdInt); |
| 760 | if (actual_type->data.integral.is_signed) { | 764 | if (actual_type->data.integral.is_signed) { |
| 761 | add_debug_source_node(g, node); | 765 | set_debug_source_node(g, node); |
| 762 | return LLVMBuildSIToFP(g->builder, expr_val, wanted_type->type_ref, ""); | 766 | return LLVMBuildSIToFP(g->builder, expr_val, wanted_type->type_ref, ""); |
| 763 | } else { | 767 | } else { |
| 764 | add_debug_source_node(g, node); | 768 | set_debug_source_node(g, node); |
| 765 | return LLVMBuildUIToFP(g->builder, expr_val, wanted_type->type_ref, ""); | 769 | return LLVMBuildUIToFP(g->builder, expr_val, wanted_type->type_ref, ""); |
| 766 | } | 770 | } |
| 767 | case CastOpFloatToInt: | 771 | case CastOpFloatToInt: |
| 768 | assert(wanted_type->id == TypeTableEntryIdInt); | 772 | assert(wanted_type->id == TypeTableEntryIdInt); |
| 769 | if (wanted_type->data.integral.is_signed) { | 773 | if (wanted_type->data.integral.is_signed) { |
| 770 | add_debug_source_node(g, node); | 774 | set_debug_source_node(g, node); |
| 771 | return LLVMBuildFPToSI(g->builder, expr_val, wanted_type->type_ref, ""); | 775 | return LLVMBuildFPToSI(g->builder, expr_val, wanted_type->type_ref, ""); |
| 772 | } else { | 776 | } else { |
| 773 | add_debug_source_node(g, node); | 777 | set_debug_source_node(g, node); |
| 774 | return LLVMBuildFPToUI(g->builder, expr_val, wanted_type->type_ref, ""); | 778 | return LLVMBuildFPToUI(g->builder, expr_val, wanted_type->type_ref, ""); |
| 775 | } | 779 | } |
| 776 | | 780 | |
| 777 | case CastOpBoolToInt: | 781 | case CastOpBoolToInt: |
| 778 | assert(wanted_type->id == TypeTableEntryIdInt); | 782 | assert(wanted_type->id == TypeTableEntryIdInt); |
| 779 | assert(actual_type->id == TypeTableEntryIdBool); | 783 | assert(actual_type->id == TypeTableEntryIdBool); |
| 780 | add_debug_source_node(g, node); | 784 | set_debug_source_node(g, node); |
| 781 | return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, ""); | 785 | return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, ""); |
| 782 | | 786 | |
| 783 | } | 787 | } |
| ... | @@ -850,7 +854,7 @@ static LLVMValueRef gen_fn_call_expr(CodeGen *g, AstNode *node) { | ... | @@ -850,7 +854,7 @@ static LLVMValueRef gen_fn_call_expr(CodeGen *g, AstNode *node) { |
| 850 | } | 854 | } |
| 851 | } | 855 | } |
| 852 | | 856 | |
| 853 | add_debug_source_node(g, node); | 857 | set_debug_source_node(g, node); |
| 854 | LLVMValueRef result = LLVMZigBuildCall(g->builder, fn_val, | 858 | LLVMValueRef result = LLVMZigBuildCall(g->builder, fn_val, |
| 855 | gen_param_values, gen_param_index, fn_type->data.fn.calling_convention, ""); | 859 | gen_param_values, gen_param_index, fn_type->data.fn.calling_convention, ""); |
| 856 | | 860 | |
| ... | @@ -873,7 +877,7 @@ static LLVMValueRef gen_array_base_ptr(CodeGen *g, AstNode *node) { | ... | @@ -873,7 +877,7 @@ static LLVMValueRef gen_array_base_ptr(CodeGen *g, AstNode *node) { |
| 873 | array_ptr = gen_field_access_expr(g, node, true); | 877 | array_ptr = gen_field_access_expr(g, node, true); |
| 874 | if (type_entry->id == TypeTableEntryIdPointer) { | 878 | if (type_entry->id == TypeTableEntryIdPointer) { |
| 875 | // we have a double pointer so we must dereference it once | 879 | // we have a double pointer so we must dereference it once |
| 876 | add_debug_source_node(g, node); | 880 | set_debug_source_node(g, node); |
| 877 | array_ptr = LLVMBuildLoad(g->builder, array_ptr, ""); | 881 | array_ptr = LLVMBuildLoad(g->builder, array_ptr, ""); |
| 878 | } | 882 | } |
| 879 | } else { | 883 | } else { |
| ... | @@ -904,14 +908,14 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal | ... | @@ -904,14 +908,14 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal |
| 904 | LLVMConstNull(g->builtin_types.entry_isize->type_ref), | 908 | LLVMConstNull(g->builtin_types.entry_isize->type_ref), |
| 905 | subscript_value | 909 | subscript_value |
| 906 | }; | 910 | }; |
| 907 | add_debug_source_node(g, source_node); | 911 | set_debug_source_node(g, source_node); |
| 908 | return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, ""); | 912 | return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, ""); |
| 909 | } else if (array_type->id == TypeTableEntryIdPointer) { | 913 | } else if (array_type->id == TypeTableEntryIdPointer) { |
| 910 | assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind); | 914 | assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind); |
| 911 | LLVMValueRef indices[] = { | 915 | LLVMValueRef indices[] = { |
| 912 | subscript_value | 916 | subscript_value |
| 913 | }; | 917 | }; |
| 914 | add_debug_source_node(g, source_node); | 918 | set_debug_source_node(g, source_node); |
| 915 | return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, ""); | 919 | return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, ""); |
| 916 | } else if (array_type->id == TypeTableEntryIdStruct) { | 920 | } else if (array_type->id == TypeTableEntryIdStruct) { |
| 917 | assert(array_type->data.structure.is_slice); | 921 | assert(array_type->data.structure.is_slice); |
| ... | @@ -919,7 +923,7 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal | ... | @@ -919,7 +923,7 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal |
| 919 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); | 923 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); |
| 920 | | 924 | |
| 921 | if (want_debug_safety(g, source_node)) { | 925 | if (want_debug_safety(g, source_node)) { |
| 922 | add_debug_source_node(g, source_node); | 926 | set_debug_source_node(g, source_node); |
| 923 | int len_index = array_type->data.structure.fields[1].gen_index; | 927 | int len_index = array_type->data.structure.fields[1].gen_index; |
| 924 | assert(len_index >= 0); | 928 | assert(len_index >= 0); |
| 925 | LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, len_index, ""); | 929 | LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, len_index, ""); |
| ... | @@ -927,7 +931,7 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal | ... | @@ -927,7 +931,7 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal |
| 927 | add_bounds_check(g, source_node, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len); | 931 | add_bounds_check(g, source_node, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len); |
| 928 | } | 932 | } |
| 929 | | 933 | |
| 930 | add_debug_source_node(g, source_node); | 934 | set_debug_source_node(g, source_node); |
| 931 | int ptr_index = array_type->data.structure.fields[0].gen_index; | 935 | int ptr_index = array_type->data.structure.fields[0].gen_index; |
| 932 | assert(ptr_index >= 0); | 936 | assert(ptr_index >= 0); |
| 933 | LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, ptr_index, ""); | 937 | LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, ptr_index, ""); |
| ... | @@ -960,8 +964,8 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou | ... | @@ -960,8 +964,8 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou |
| 960 | VariableTableEntry *var = get_resolved_expr(struct_expr_node)->variable; | 964 | VariableTableEntry *var = get_resolved_expr(struct_expr_node)->variable; |
| 961 | assert(var); | 965 | assert(var); |
| 962 | | 966 | |
| 963 | if (var->is_ptr && var->type->id == TypeTableEntryIdPointer) { | 967 | if (var->type->id == TypeTableEntryIdPointer) { |
| 964 | add_debug_source_node(g, node); | 968 | set_debug_source_node(g, node); |
| 965 | struct_ptr = LLVMBuildLoad(g->builder, var->value_ref, ""); | 969 | struct_ptr = LLVMBuildLoad(g->builder, var->value_ref, ""); |
| 966 | } else { | 970 | } else { |
| 967 | struct_ptr = var->value_ref; | 971 | struct_ptr = var->value_ref; |
| ... | @@ -971,7 +975,7 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou | ... | @@ -971,7 +975,7 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou |
| 971 | TypeTableEntry *field_type = get_expr_type(struct_expr_node); | 975 | TypeTableEntry *field_type = get_expr_type(struct_expr_node); |
| 972 | if (field_type->id == TypeTableEntryIdPointer) { | 976 | if (field_type->id == TypeTableEntryIdPointer) { |
| 973 | // we have a double pointer so we must dereference it once | 977 | // we have a double pointer so we must dereference it once |
| 974 | add_debug_source_node(g, node); | 978 | set_debug_source_node(g, node); |
| 975 | struct_ptr = LLVMBuildLoad(g->builder, struct_ptr, ""); | 979 | struct_ptr = LLVMBuildLoad(g->builder, struct_ptr, ""); |
| 976 | } | 980 | } |
| 977 | } else { | 981 | } else { |
| ... | @@ -986,7 +990,7 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou | ... | @@ -986,7 +990,7 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou |
| 986 | | 990 | |
| 987 | *out_type_entry = node->data.field_access_expr.type_struct_field->type_entry; | 991 | *out_type_entry = node->data.field_access_expr.type_struct_field->type_entry; |
| 988 | | 992 | |
| 989 | add_debug_source_node(g, node); | 993 | set_debug_source_node(g, node); |
| 990 | return LLVMBuildStructGEP(g->builder, struct_ptr, gen_field_index, ""); | 994 | return LLVMBuildStructGEP(g->builder, struct_ptr, gen_field_index, ""); |
| 991 | } | 995 | } |
| 992 | | 996 | |
| ... | @@ -1017,7 +1021,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { | ... | @@ -1017,7 +1021,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { |
| 1017 | } | 1021 | } |
| 1018 | } | 1022 | } |
| 1019 | | 1023 | |
| 1020 | add_debug_source_node(g, node); | 1024 | set_debug_source_node(g, node); |
| 1021 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, 0, ""); | 1025 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, 0, ""); |
| 1022 | LLVMValueRef indices[] = { | 1026 | LLVMValueRef indices[] = { |
| 1023 | LLVMConstNull(g->builtin_types.entry_isize->type_ref), | 1027 | LLVMConstNull(g->builtin_types.entry_isize->type_ref), |
| ... | @@ -1039,7 +1043,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { | ... | @@ -1039,7 +1043,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { |
| 1039 | add_bounds_check(g, node, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val); | 1043 | add_bounds_check(g, node, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val); |
| 1040 | } | 1044 | } |
| 1041 | | 1045 | |
| 1042 | add_debug_source_node(g, node); | 1046 | set_debug_source_node(g, node); |
| 1043 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, 0, ""); | 1047 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, 0, ""); |
| 1044 | LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, ""); | 1048 | LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, ""); |
| 1045 | LLVMBuildStore(g->builder, slice_start_ptr, ptr_field_ptr); | 1049 | LLVMBuildStore(g->builder, slice_start_ptr, ptr_field_ptr); |
| ... | @@ -1061,7 +1065,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { | ... | @@ -1061,7 +1065,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { |
| 1061 | | 1065 | |
| 1062 | LLVMValueRef prev_end = nullptr; | 1066 | LLVMValueRef prev_end = nullptr; |
| 1063 | if (!node->data.slice_expr.end || want_debug_safety(g, node)) { | 1067 | if (!node->data.slice_expr.end || want_debug_safety(g, node)) { |
| 1064 | add_debug_source_node(g, node); | 1068 | set_debug_source_node(g, node); |
| 1065 | LLVMValueRef src_len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, len_index, ""); | 1069 | LLVMValueRef src_len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, len_index, ""); |
| 1066 | prev_end = LLVMBuildLoad(g->builder, src_len_ptr, ""); | 1070 | prev_end = LLVMBuildLoad(g->builder, src_len_ptr, ""); |
| 1067 | } | 1071 | } |
| ... | @@ -1082,7 +1086,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { | ... | @@ -1082,7 +1086,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { |
| 1082 | } | 1086 | } |
| 1083 | } | 1087 | } |
| 1084 | | 1088 | |
| 1085 | add_debug_source_node(g, node); | 1089 | set_debug_source_node(g, node); |
| 1086 | LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, ptr_index, ""); | 1090 | LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, ptr_index, ""); |
| 1087 | LLVMValueRef src_ptr = LLVMBuildLoad(g->builder, src_ptr_ptr, ""); | 1091 | LLVMValueRef src_ptr = LLVMBuildLoad(g->builder, src_ptr_ptr, ""); |
| 1088 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, ptr_index, ""); | 1092 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, ptr_index, ""); |
| ... | @@ -1122,7 +1126,7 @@ static LLVMValueRef gen_array_access_expr(CodeGen *g, AstNode *node, bool is_lva | ... | @@ -1122,7 +1126,7 @@ static LLVMValueRef gen_array_access_expr(CodeGen *g, AstNode *node, bool is_lva |
| 1122 | if (is_lvalue || !ptr || handle_is_ptr(child_type)) { | 1126 | if (is_lvalue || !ptr || handle_is_ptr(child_type)) { |
| 1123 | return ptr; | 1127 | return ptr; |
| 1124 | } else { | 1128 | } else { |
| 1125 | add_debug_source_node(g, node); | 1129 | set_debug_source_node(g, node); |
| 1126 | return LLVMBuildLoad(g->builder, ptr, ""); | 1130 | return LLVMBuildLoad(g->builder, ptr, ""); |
| 1127 | } | 1131 | } |
| 1128 | } | 1132 | } |
| ... | @@ -1130,11 +1134,9 @@ static LLVMValueRef gen_array_access_expr(CodeGen *g, AstNode *node, bool is_lva | ... | @@ -1130,11 +1134,9 @@ static LLVMValueRef gen_array_access_expr(CodeGen *g, AstNode *node, bool is_lva |
| 1130 | static LLVMValueRef gen_variable(CodeGen *g, AstNode *source_node, VariableTableEntry *variable) { | 1134 | static LLVMValueRef gen_variable(CodeGen *g, AstNode *source_node, VariableTableEntry *variable) { |
| 1131 | if (!type_has_bits(variable->type)) { | 1135 | if (!type_has_bits(variable->type)) { |
| 1132 | return nullptr; | 1136 | return nullptr; |
| 1133 | } else if (variable->is_ptr) { | 1137 | } else { |
| 1134 | assert(variable->value_ref); | 1138 | assert(variable->value_ref); |
| 1135 | return get_handle_value(g, source_node, variable->value_ref, variable->type); | 1139 | return get_handle_value(g, source_node, variable->value_ref, variable->type); |
| 1136 | } else { | | |
| 1137 | return variable->value_ref; | | |
| 1138 | } | 1140 | } |
| 1139 | } | 1141 | } |
| 1140 | | 1142 | |
| ... | @@ -1157,7 +1159,7 @@ static LLVMValueRef gen_field_access_expr(CodeGen *g, AstNode *node, bool is_lva | ... | @@ -1157,7 +1159,7 @@ static LLVMValueRef gen_field_access_expr(CodeGen *g, AstNode *node, bool is_lva |
| 1157 | if (is_lvalue || handle_is_ptr(type_entry)) { | 1159 | if (is_lvalue || handle_is_ptr(type_entry)) { |
| 1158 | return ptr; | 1160 | return ptr; |
| 1159 | } else { | 1161 | } else { |
| 1160 | add_debug_source_node(g, node); | 1162 | set_debug_source_node(g, node); |
| 1161 | return LLVMBuildLoad(g->builder, ptr, ""); | 1163 | return LLVMBuildLoad(g->builder, ptr, ""); |
| 1162 | } | 1164 | } |
| 1163 | } else if (struct_type->id == TypeTableEntryIdMetaType) { | 1165 | } else if (struct_type->id == TypeTableEntryIdMetaType) { |
| ... | @@ -1233,10 +1235,10 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { | ... | @@ -1233,10 +1235,10 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { |
| 1233 | { | 1235 | { |
| 1234 | LLVMValueRef expr = gen_expr(g, expr_node); | 1236 | LLVMValueRef expr = gen_expr(g, expr_node); |
| 1235 | if (expr_type->id == TypeTableEntryIdInt) { | 1237 | if (expr_type->id == TypeTableEntryIdInt) { |
| 1236 | add_debug_source_node(g, node); | 1238 | set_debug_source_node(g, node); |
| 1237 | return LLVMBuildNeg(g->builder, expr, ""); | 1239 | return LLVMBuildNeg(g->builder, expr, ""); |
| 1238 | } else if (expr_type->id == TypeTableEntryIdFloat) { | 1240 | } else if (expr_type->id == TypeTableEntryIdFloat) { |
| 1239 | add_debug_source_node(g, node); | 1241 | set_debug_source_node(g, node); |
| 1240 | return LLVMBuildFNeg(g->builder, expr, ""); | 1242 | return LLVMBuildFNeg(g->builder, expr, ""); |
| 1241 | } else { | 1243 | } else { |
| 1242 | zig_unreachable(); | 1244 | zig_unreachable(); |
| ... | @@ -1246,13 +1248,13 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { | ... | @@ -1246,13 +1248,13 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { |
| 1246 | { | 1248 | { |
| 1247 | LLVMValueRef expr = gen_expr(g, expr_node); | 1249 | LLVMValueRef expr = gen_expr(g, expr_node); |
| 1248 | LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(expr)); | 1250 | LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(expr)); |
| 1249 | add_debug_source_node(g, node); | 1251 | set_debug_source_node(g, node); |
| 1250 | return LLVMBuildICmp(g->builder, LLVMIntEQ, expr, zero, ""); | 1252 | return LLVMBuildICmp(g->builder, LLVMIntEQ, expr, zero, ""); |
| 1251 | } | 1253 | } |
| 1252 | case PrefixOpBinNot: | 1254 | case PrefixOpBinNot: |
| 1253 | { | 1255 | { |
| 1254 | LLVMValueRef expr = gen_expr(g, expr_node); | 1256 | LLVMValueRef expr = gen_expr(g, expr_node); |
| 1255 | add_debug_source_node(g, node); | 1257 | set_debug_source_node(g, node); |
| 1256 | return LLVMBuildNot(g->builder, expr, ""); | 1258 | return LLVMBuildNot(g->builder, expr, ""); |
| 1257 | } | 1259 | } |
| 1258 | case PrefixOpAddressOf: | 1260 | case PrefixOpAddressOf: |
| ... | @@ -1291,13 +1293,13 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { | ... | @@ -1291,13 +1293,13 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { |
| 1291 | if (want_debug_safety(g, node)) { | 1293 | if (want_debug_safety(g, node)) { |
| 1292 | LLVMValueRef err_val; | 1294 | LLVMValueRef err_val; |
| 1293 | if (type_has_bits(child_type)) { | 1295 | if (type_has_bits(child_type)) { |
| 1294 | add_debug_source_node(g, node); | 1296 | set_debug_source_node(g, node); |
| 1295 | LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, expr_val, 0, ""); | 1297 | LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, expr_val, 0, ""); |
| 1296 | err_val = LLVMBuildLoad(g->builder, err_val_ptr, ""); | 1298 | err_val = LLVMBuildLoad(g->builder, err_val_ptr, ""); |
| 1297 | } else { | 1299 | } else { |
| 1298 | err_val = expr_val; | 1300 | err_val = expr_val; |
| 1299 | } | 1301 | } |
| 1300 | add_debug_source_node(g, node); | 1302 | set_debug_source_node(g, node); |
| 1301 | LLVMValueRef zero = LLVMConstNull(g->err_tag_type->type_ref); | 1303 | LLVMValueRef zero = LLVMConstNull(g->err_tag_type->type_ref); |
| 1302 | LLVMValueRef cond_val = LLVMBuildICmp(g->builder, LLVMIntEQ, err_val, zero, ""); | 1304 | LLVMValueRef cond_val = LLVMBuildICmp(g->builder, LLVMIntEQ, err_val, zero, ""); |
| 1303 | LLVMBasicBlockRef err_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "UnwrapErrError"); | 1305 | LLVMBasicBlockRef err_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "UnwrapErrError"); |
| ... | @@ -1327,7 +1329,7 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { | ... | @@ -1327,7 +1329,7 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { |
| 1327 | TypeTableEntry *child_type = expr_type->data.maybe.child_type; | 1329 | TypeTableEntry *child_type = expr_type->data.maybe.child_type; |
| 1328 | | 1330 | |
| 1329 | if (want_debug_safety(g, node)) { | 1331 | if (want_debug_safety(g, node)) { |
| 1330 | add_debug_source_node(g, node); | 1332 | set_debug_source_node(g, node); |
| 1331 | LLVMValueRef cond_val; | 1333 | LLVMValueRef cond_val; |
| 1332 | if (child_type->id == TypeTableEntryIdPointer || | 1334 | if (child_type->id == TypeTableEntryIdPointer || |
| 1333 | child_type->id == TypeTableEntryIdFn) | 1335 | child_type->id == TypeTableEntryIdFn) |
| ... | @@ -1356,7 +1358,7 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { | ... | @@ -1356,7 +1358,7 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { |
| 1356 | { | 1358 | { |
| 1357 | return expr_val; | 1359 | return expr_val; |
| 1358 | } else { | 1360 | } else { |
| 1359 | add_debug_source_node(g, node); | 1361 | set_debug_source_node(g, node); |
| 1360 | LLVMValueRef maybe_field_ptr = LLVMBuildStructGEP(g->builder, expr_val, 0, ""); | 1362 | LLVMValueRef maybe_field_ptr = LLVMBuildStructGEP(g->builder, expr_val, 0, ""); |
| 1361 | return get_handle_value(g, node, maybe_field_ptr, child_type); | 1363 | return get_handle_value(g, node, maybe_field_ptr, child_type); |
| 1362 | } | 1364 | } |
| ... | @@ -1375,26 +1377,26 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, | ... | @@ -1375,26 +1377,26 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, |
| 1375 | switch (bin_op) { | 1377 | switch (bin_op) { |
| 1376 | case BinOpTypeBinOr: | 1378 | case BinOpTypeBinOr: |
| 1377 | case BinOpTypeAssignBitOr: | 1379 | case BinOpTypeAssignBitOr: |
| 1378 | add_debug_source_node(g, source_node); | 1380 | set_debug_source_node(g, source_node); |
| 1379 | return LLVMBuildOr(g->builder, val1, val2, ""); | 1381 | return LLVMBuildOr(g->builder, val1, val2, ""); |
| 1380 | case BinOpTypeBinXor: | 1382 | case BinOpTypeBinXor: |
| 1381 | case BinOpTypeAssignBitXor: | 1383 | case BinOpTypeAssignBitXor: |
| 1382 | add_debug_source_node(g, source_node); | 1384 | set_debug_source_node(g, source_node); |
| 1383 | return LLVMBuildXor(g->builder, val1, val2, ""); | 1385 | return LLVMBuildXor(g->builder, val1, val2, ""); |
| 1384 | case BinOpTypeBinAnd: | 1386 | case BinOpTypeBinAnd: |
| 1385 | case BinOpTypeAssignBitAnd: | 1387 | case BinOpTypeAssignBitAnd: |
| 1386 | add_debug_source_node(g, source_node); | 1388 | set_debug_source_node(g, source_node); |
| 1387 | return LLVMBuildAnd(g->builder, val1, val2, ""); | 1389 | return LLVMBuildAnd(g->builder, val1, val2, ""); |
| 1388 | case BinOpTypeBitShiftLeft: | 1390 | case BinOpTypeBitShiftLeft: |
| 1389 | case BinOpTypeAssignBitShiftLeft: | 1391 | case BinOpTypeAssignBitShiftLeft: |
| 1390 | add_debug_source_node(g, source_node); | 1392 | set_debug_source_node(g, source_node); |
| 1391 | return LLVMBuildShl(g->builder, val1, val2, ""); | 1393 | return LLVMBuildShl(g->builder, val1, val2, ""); |
| 1392 | case BinOpTypeBitShiftRight: | 1394 | case BinOpTypeBitShiftRight: |
| 1393 | case BinOpTypeAssignBitShiftRight: | 1395 | case BinOpTypeAssignBitShiftRight: |
| 1394 | assert(op1_type->id == TypeTableEntryIdInt); | 1396 | assert(op1_type->id == TypeTableEntryIdInt); |
| 1395 | assert(op2_type->id == TypeTableEntryIdInt); | 1397 | assert(op2_type->id == TypeTableEntryIdInt); |
| 1396 | | 1398 | |
| 1397 | add_debug_source_node(g, source_node); | 1399 | set_debug_source_node(g, source_node); |
| 1398 | if (op1_type->data.integral.is_signed) { | 1400 | if (op1_type->data.integral.is_signed) { |
| 1399 | return LLVMBuildAShr(g->builder, val1, val2, ""); | 1401 | return LLVMBuildAShr(g->builder, val1, val2, ""); |
| 1400 | } else { | 1402 | } else { |
| ... | @@ -1402,7 +1404,7 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, | ... | @@ -1402,7 +1404,7 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, |
| 1402 | } | 1404 | } |
| 1403 | case BinOpTypeAdd: | 1405 | case BinOpTypeAdd: |
| 1404 | case BinOpTypeAssignPlus: | 1406 | case BinOpTypeAssignPlus: |
| 1405 | add_debug_source_node(g, source_node); | 1407 | set_debug_source_node(g, source_node); |
| 1406 | if (op1_type->id == TypeTableEntryIdFloat) { | 1408 | if (op1_type->id == TypeTableEntryIdFloat) { |
| 1407 | return LLVMBuildFAdd(g->builder, val1, val2, ""); | 1409 | return LLVMBuildFAdd(g->builder, val1, val2, ""); |
| 1408 | } else { | 1410 | } else { |
| ... | @@ -1410,7 +1412,7 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, | ... | @@ -1410,7 +1412,7 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, |
| 1410 | } | 1412 | } |
| 1411 | case BinOpTypeSub: | 1413 | case BinOpTypeSub: |
| 1412 | case BinOpTypeAssignMinus: | 1414 | case BinOpTypeAssignMinus: |
| 1413 | add_debug_source_node(g, source_node); | 1415 | set_debug_source_node(g, source_node); |
| 1414 | if (op1_type->id == TypeTableEntryIdFloat) { | 1416 | if (op1_type->id == TypeTableEntryIdFloat) { |
| 1415 | return LLVMBuildFSub(g->builder, val1, val2, ""); | 1417 | return LLVMBuildFSub(g->builder, val1, val2, ""); |
| 1416 | } else { | 1418 | } else { |
| ... | @@ -1418,7 +1420,7 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, | ... | @@ -1418,7 +1420,7 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, |
| 1418 | } | 1420 | } |
| 1419 | case BinOpTypeMult: | 1421 | case BinOpTypeMult: |
| 1420 | case BinOpTypeAssignTimes: | 1422 | case BinOpTypeAssignTimes: |
| 1421 | add_debug_source_node(g, source_node); | 1423 | set_debug_source_node(g, source_node); |
| 1422 | if (op1_type->id == TypeTableEntryIdFloat) { | 1424 | if (op1_type->id == TypeTableEntryIdFloat) { |
| 1423 | return LLVMBuildFMul(g->builder, val1, val2, ""); | 1425 | return LLVMBuildFMul(g->builder, val1, val2, ""); |
| 1424 | } else { | 1426 | } else { |
| ... | @@ -1426,7 +1428,7 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, | ... | @@ -1426,7 +1428,7 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, |
| 1426 | } | 1428 | } |
| 1427 | case BinOpTypeDiv: | 1429 | case BinOpTypeDiv: |
| 1428 | case BinOpTypeAssignDiv: | 1430 | case BinOpTypeAssignDiv: |
| 1429 | add_debug_source_node(g, source_node); | 1431 | set_debug_source_node(g, source_node); |
| 1430 | if (op1_type->id == TypeTableEntryIdFloat) { | 1432 | if (op1_type->id == TypeTableEntryIdFloat) { |
| 1431 | return LLVMBuildFDiv(g->builder, val1, val2, ""); | 1433 | return LLVMBuildFDiv(g->builder, val1, val2, ""); |
| 1432 | } else { | 1434 | } else { |
| ... | @@ -1439,7 +1441,7 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, | ... | @@ -1439,7 +1441,7 @@ static LLVMValueRef gen_arithmetic_bin_op(CodeGen *g, AstNode *source_node, |
| 1439 | } | 1441 | } |
| 1440 | case BinOpTypeMod: | 1442 | case BinOpTypeMod: |
| 1441 | case BinOpTypeAssignMod: | 1443 | case BinOpTypeAssignMod: |
| 1442 | add_debug_source_node(g, source_node); | 1444 | set_debug_source_node(g, source_node); |
| 1443 | if (op1_type->id == TypeTableEntryIdFloat) { | 1445 | if (op1_type->id == TypeTableEntryIdFloat) { |
| 1444 | return LLVMBuildFRem(g->builder, val1, val2, ""); | 1446 | return LLVMBuildFRem(g->builder, val1, val2, ""); |
| 1445 | } else { | 1447 | } else { |
| ... | @@ -1528,7 +1530,7 @@ static LLVMValueRef gen_cmp_expr(CodeGen *g, AstNode *node) { | ... | @@ -1528,7 +1530,7 @@ static LLVMValueRef gen_cmp_expr(CodeGen *g, AstNode *node) { |
| 1528 | TypeTableEntry *op2_type = get_expr_type(node->data.bin_op_expr.op2); | 1530 | TypeTableEntry *op2_type = get_expr_type(node->data.bin_op_expr.op2); |
| 1529 | assert(op1_type == op2_type); | 1531 | assert(op1_type == op2_type); |
| 1530 | | 1532 | |
| 1531 | add_debug_source_node(g, node); | 1533 | set_debug_source_node(g, node); |
| 1532 | if (op1_type->id == TypeTableEntryIdFloat) { | 1534 | if (op1_type->id == TypeTableEntryIdFloat) { |
| 1533 | LLVMRealPredicate pred = cmp_op_to_real_predicate(node->data.bin_op_expr.bin_op); | 1535 | LLVMRealPredicate pred = cmp_op_to_real_predicate(node->data.bin_op_expr.bin_op); |
| 1534 | return LLVMBuildFCmp(g->builder, pred, val1, val2, ""); | 1536 | return LLVMBuildFCmp(g->builder, pred, val1, val2, ""); |
| ... | @@ -1565,18 +1567,18 @@ static LLVMValueRef gen_bool_and_expr(CodeGen *g, AstNode *node) { | ... | @@ -1565,18 +1567,18 @@ static LLVMValueRef gen_bool_and_expr(CodeGen *g, AstNode *node) { |
| 1565 | // block for when val1 == false (don't even evaluate the second part) | 1567 | // block for when val1 == false (don't even evaluate the second part) |
| 1566 | LLVMBasicBlockRef false_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "BoolAndFalse"); | 1568 | LLVMBasicBlockRef false_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "BoolAndFalse"); |
| 1567 | | 1569 | |
| 1568 | add_debug_source_node(g, node); | 1570 | set_debug_source_node(g, node); |
| 1569 | LLVMBuildCondBr(g->builder, val1, true_block, false_block); | 1571 | LLVMBuildCondBr(g->builder, val1, true_block, false_block); |
| 1570 | | 1572 | |
| 1571 | LLVMPositionBuilderAtEnd(g->builder, true_block); | 1573 | LLVMPositionBuilderAtEnd(g->builder, true_block); |
| 1572 | LLVMValueRef val2 = gen_expr(g, node->data.bin_op_expr.op2); | 1574 | LLVMValueRef val2 = gen_expr(g, node->data.bin_op_expr.op2); |
| 1573 | LLVMBasicBlockRef post_val2_block = LLVMGetInsertBlock(g->builder); | 1575 | LLVMBasicBlockRef post_val2_block = LLVMGetInsertBlock(g->builder); |
| 1574 | | 1576 | |
| 1575 | add_debug_source_node(g, node); | 1577 | set_debug_source_node(g, node); |
| 1576 | LLVMBuildBr(g->builder, false_block); | 1578 | LLVMBuildBr(g->builder, false_block); |
| 1577 | | 1579 | |
| 1578 | LLVMPositionBuilderAtEnd(g->builder, false_block); | 1580 | LLVMPositionBuilderAtEnd(g->builder, false_block); |
| 1579 | add_debug_source_node(g, node); | 1581 | set_debug_source_node(g, node); |
| 1580 | LLVMValueRef phi = LLVMBuildPhi(g->builder, LLVMInt1Type(), ""); | 1582 | LLVMValueRef phi = LLVMBuildPhi(g->builder, LLVMInt1Type(), ""); |
| 1581 | LLVMValueRef incoming_values[2] = {val1, val2}; | 1583 | LLVMValueRef incoming_values[2] = {val1, val2}; |
| 1582 | LLVMBasicBlockRef incoming_blocks[2] = {post_val1_block, post_val2_block}; | 1584 | LLVMBasicBlockRef incoming_blocks[2] = {post_val1_block, post_val2_block}; |
| ... | @@ -1596,7 +1598,7 @@ static LLVMValueRef gen_bool_or_expr(CodeGen *g, AstNode *expr_node) { | ... | @@ -1596,7 +1598,7 @@ static LLVMValueRef gen_bool_or_expr(CodeGen *g, AstNode *expr_node) { |
| 1596 | // block for when val1 == true (don't even evaluate the second part) | 1598 | // block for when val1 == true (don't even evaluate the second part) |
| 1597 | LLVMBasicBlockRef true_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "BoolOrTrue"); | 1599 | LLVMBasicBlockRef true_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "BoolOrTrue"); |
| 1598 | | 1600 | |
| 1599 | add_debug_source_node(g, expr_node); | 1601 | set_debug_source_node(g, expr_node); |
| 1600 | LLVMBuildCondBr(g->builder, val1, true_block, false_block); | 1602 | LLVMBuildCondBr(g->builder, val1, true_block, false_block); |
| 1601 | | 1603 | |
| 1602 | LLVMPositionBuilderAtEnd(g->builder, false_block); | 1604 | LLVMPositionBuilderAtEnd(g->builder, false_block); |
| ... | @@ -1604,11 +1606,11 @@ static LLVMValueRef gen_bool_or_expr(CodeGen *g, AstNode *expr_node) { | ... | @@ -1604,11 +1606,11 @@ static LLVMValueRef gen_bool_or_expr(CodeGen *g, AstNode *expr_node) { |
| 1604 | | 1606 | |
| 1605 | LLVMBasicBlockRef post_val2_block = LLVMGetInsertBlock(g->builder); | 1607 | LLVMBasicBlockRef post_val2_block = LLVMGetInsertBlock(g->builder); |
| 1606 | | 1608 | |
| 1607 | add_debug_source_node(g, expr_node); | 1609 | set_debug_source_node(g, expr_node); |
| 1608 | LLVMBuildBr(g->builder, true_block); | 1610 | LLVMBuildBr(g->builder, true_block); |
| 1609 | | 1611 | |
| 1610 | LLVMPositionBuilderAtEnd(g->builder, true_block); | 1612 | LLVMPositionBuilderAtEnd(g->builder, true_block); |
| 1611 | add_debug_source_node(g, expr_node); | 1613 | set_debug_source_node(g, expr_node); |
| 1612 | LLVMValueRef phi = LLVMBuildPhi(g->builder, LLVMInt1Type(), ""); | 1614 | LLVMValueRef phi = LLVMBuildPhi(g->builder, LLVMInt1Type(), ""); |
| 1613 | LLVMValueRef incoming_values[2] = {val1, val2}; | 1615 | LLVMValueRef incoming_values[2] = {val1, val2}; |
| 1614 | LLVMBasicBlockRef incoming_blocks[2] = {post_val1_block, post_val2_block}; | 1616 | LLVMBasicBlockRef incoming_blocks[2] = {post_val1_block, post_val2_block}; |
| ... | @@ -1624,7 +1626,7 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, AstNode *source_node, LLVMValu | ... | @@ -1624,7 +1626,7 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, AstNode *source_node, LLVMValu |
| 1624 | | 1626 | |
| 1625 | LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); | 1627 | LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); |
| 1626 | | 1628 | |
| 1627 | add_debug_source_node(g, source_node); | 1629 | set_debug_source_node(g, source_node); |
| 1628 | LLVMValueRef src_ptr = LLVMBuildBitCast(g->builder, src, ptr_u8, ""); | 1630 | LLVMValueRef src_ptr = LLVMBuildBitCast(g->builder, src, ptr_u8, ""); |
| 1629 | LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, dest, ptr_u8, ""); | 1631 | LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, dest, ptr_u8, ""); |
| 1630 | | 1632 | |
| ... | @@ -1661,13 +1663,13 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, AstNode *source_node, BinOpType b | ... | @@ -1661,13 +1663,13 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, AstNode *source_node, BinOpType b |
| 1661 | | 1663 | |
| 1662 | if (bin_op != BinOpTypeAssign) { | 1664 | if (bin_op != BinOpTypeAssign) { |
| 1663 | assert(source_node->type == NodeTypeBinOpExpr); | 1665 | assert(source_node->type == NodeTypeBinOpExpr); |
| 1664 | add_debug_source_node(g, source_node->data.bin_op_expr.op1); | 1666 | set_debug_source_node(g, source_node->data.bin_op_expr.op1); |
| 1665 | LLVMValueRef left_value = LLVMBuildLoad(g->builder, target_ref, ""); | 1667 | LLVMValueRef left_value = LLVMBuildLoad(g->builder, target_ref, ""); |
| 1666 | | 1668 | |
| 1667 | value = gen_arithmetic_bin_op(g, source_node, left_value, value, op1_type, op2_type, bin_op); | 1669 | value = gen_arithmetic_bin_op(g, source_node, left_value, value, op1_type, op2_type, bin_op); |
| 1668 | } | 1670 | } |
| 1669 | | 1671 | |
| 1670 | add_debug_source_node(g, source_node); | 1672 | set_debug_source_node(g, source_node); |
| 1671 | LLVMBuildStore(g->builder, value, target_ref); | 1673 | LLVMBuildStore(g->builder, value, target_ref); |
| 1672 | return nullptr; | 1674 | return nullptr; |
| 1673 | } | 1675 | } |
| ... | @@ -1698,7 +1700,7 @@ static LLVMValueRef gen_unwrap_maybe(CodeGen *g, AstNode *node, LLVMValueRef may | ... | @@ -1698,7 +1700,7 @@ static LLVMValueRef gen_unwrap_maybe(CodeGen *g, AstNode *node, LLVMValueRef may |
| 1698 | { | 1700 | { |
| 1699 | return maybe_struct_ref; | 1701 | return maybe_struct_ref; |
| 1700 | } else { | 1702 | } else { |
| 1701 | add_debug_source_node(g, node); | 1703 | set_debug_source_node(g, node); |
| 1702 | LLVMValueRef maybe_field_ptr = LLVMBuildStructGEP(g->builder, maybe_struct_ref, 0, ""); | 1704 | LLVMValueRef maybe_field_ptr = LLVMBuildStructGEP(g->builder, maybe_struct_ref, 0, ""); |
| 1703 | return get_handle_value(g, node, maybe_field_ptr, child_type); | 1705 | return get_handle_value(g, node, maybe_field_ptr, child_type); |
| 1704 | } | 1706 | } |
| ... | @@ -1724,7 +1726,7 @@ static LLVMValueRef gen_unwrap_maybe_expr(CodeGen *g, AstNode *node) { | ... | @@ -1724,7 +1726,7 @@ static LLVMValueRef gen_unwrap_maybe_expr(CodeGen *g, AstNode *node) { |
| 1724 | cond_value = LLVMBuildICmp(g->builder, LLVMIntNE, maybe_struct_ref, | 1726 | cond_value = LLVMBuildICmp(g->builder, LLVMIntNE, maybe_struct_ref, |
| 1725 | LLVMConstNull(child_type->type_ref), ""); | 1727 | LLVMConstNull(child_type->type_ref), ""); |
| 1726 | } else { | 1728 | } else { |
| 1727 | add_debug_source_node(g, node); | 1729 | set_debug_source_node(g, node); |
| 1728 | LLVMValueRef maybe_field_ptr = LLVMBuildStructGEP(g->builder, maybe_struct_ref, 1, ""); | 1730 | LLVMValueRef maybe_field_ptr = LLVMBuildStructGEP(g->builder, maybe_struct_ref, 1, ""); |
| 1729 | cond_value = LLVMBuildLoad(g->builder, maybe_field_ptr, ""); | 1731 | cond_value = LLVMBuildLoad(g->builder, maybe_field_ptr, ""); |
| 1730 | } | 1732 | } |
| ... | @@ -1739,21 +1741,21 @@ static LLVMValueRef gen_unwrap_maybe_expr(CodeGen *g, AstNode *node) { | ... | @@ -1739,21 +1741,21 @@ static LLVMValueRef gen_unwrap_maybe_expr(CodeGen *g, AstNode *node) { |
| 1739 | | 1741 | |
| 1740 | LLVMPositionBuilderAtEnd(g->builder, non_null_block); | 1742 | LLVMPositionBuilderAtEnd(g->builder, non_null_block); |
| 1741 | LLVMValueRef non_null_result = gen_unwrap_maybe(g, op1_node, maybe_struct_ref); | 1743 | LLVMValueRef non_null_result = gen_unwrap_maybe(g, op1_node, maybe_struct_ref); |
| 1742 | add_debug_source_node(g, node); | 1744 | set_debug_source_node(g, node); |
| 1743 | LLVMBuildBr(g->builder, end_block); | 1745 | LLVMBuildBr(g->builder, end_block); |
| 1744 | LLVMBasicBlockRef post_non_null_result_block = LLVMGetInsertBlock(g->builder); | 1746 | LLVMBasicBlockRef post_non_null_result_block = LLVMGetInsertBlock(g->builder); |
| 1745 | | 1747 | |
| 1746 | LLVMPositionBuilderAtEnd(g->builder, null_block); | 1748 | LLVMPositionBuilderAtEnd(g->builder, null_block); |
| 1747 | LLVMValueRef null_result = gen_expr(g, op2_node); | 1749 | LLVMValueRef null_result = gen_expr(g, op2_node); |
| 1748 | if (null_reachable) { | 1750 | if (null_reachable) { |
| 1749 | add_debug_source_node(g, node); | 1751 | set_debug_source_node(g, node); |
| 1750 | LLVMBuildBr(g->builder, end_block); | 1752 | LLVMBuildBr(g->builder, end_block); |
| 1751 | } | 1753 | } |
| 1752 | LLVMBasicBlockRef post_null_result_block = LLVMGetInsertBlock(g->builder); | 1754 | LLVMBasicBlockRef post_null_result_block = LLVMGetInsertBlock(g->builder); |
| 1753 | | 1755 | |
| 1754 | LLVMPositionBuilderAtEnd(g->builder, end_block); | 1756 | LLVMPositionBuilderAtEnd(g->builder, end_block); |
| 1755 | if (null_reachable) { | 1757 | if (null_reachable) { |
| 1756 | add_debug_source_node(g, node); | 1758 | set_debug_source_node(g, node); |
| 1757 | LLVMValueRef phi = LLVMBuildPhi(g->builder, LLVMTypeOf(non_null_result), ""); | 1759 | LLVMValueRef phi = LLVMBuildPhi(g->builder, LLVMTypeOf(non_null_result), ""); |
| 1758 | LLVMValueRef incoming_values[2] = {non_null_result, null_result}; | 1760 | LLVMValueRef incoming_values[2] = {non_null_result, null_result}; |
| 1759 | LLVMBasicBlockRef incoming_blocks[2] = {post_non_null_result_block, post_null_result_block}; | 1761 | LLVMBasicBlockRef incoming_blocks[2] = {post_non_null_result_block, post_null_result_block}; |
| ... | @@ -1826,7 +1828,7 @@ static LLVMValueRef gen_unwrap_err_expr(CodeGen *g, AstNode *node) { | ... | @@ -1826,7 +1828,7 @@ static LLVMValueRef gen_unwrap_err_expr(CodeGen *g, AstNode *node) { |
| 1826 | assert(expr_type->id == TypeTableEntryIdErrorUnion); | 1828 | assert(expr_type->id == TypeTableEntryIdErrorUnion); |
| 1827 | TypeTableEntry *child_type = expr_type->data.error.child_type; | 1829 | TypeTableEntry *child_type = expr_type->data.error.child_type; |
| 1828 | LLVMValueRef err_val; | 1830 | LLVMValueRef err_val; |
| 1829 | add_debug_source_node(g, node); | 1831 | set_debug_source_node(g, node); |
| 1830 | if (handle_is_ptr(expr_type)) { | 1832 | if (handle_is_ptr(expr_type)) { |
| 1831 | LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, expr_val, 0, ""); | 1833 | LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, expr_val, 0, ""); |
| 1832 | err_val = LLVMBuildLoad(g->builder, err_val_ptr, ""); | 1834 | err_val = LLVMBuildLoad(g->builder, err_val_ptr, ""); |
| ... | @@ -1852,7 +1854,7 @@ static LLVMValueRef gen_unwrap_err_expr(CodeGen *g, AstNode *node) { | ... | @@ -1852,7 +1854,7 @@ static LLVMValueRef gen_unwrap_err_expr(CodeGen *g, AstNode *node) { |
| 1852 | LLVMBuildStore(g->builder, err_val, var->value_ref); | 1854 | LLVMBuildStore(g->builder, err_val, var->value_ref); |
| 1853 | } | 1855 | } |
| 1854 | LLVMValueRef err_result = gen_expr(g, op2); | 1856 | LLVMValueRef err_result = gen_expr(g, op2); |
| 1855 | add_debug_source_node(g, node); | 1857 | set_debug_source_node(g, node); |
| 1856 | if (have_end_block) { | 1858 | if (have_end_block) { |
| 1857 | LLVMBuildBr(g->builder, end_block); | 1859 | LLVMBuildBr(g->builder, end_block); |
| 1858 | } else if (err_reachable) { | 1860 | } else if (err_reachable) { |
| ... | @@ -1927,10 +1929,10 @@ static LLVMValueRef gen_return(CodeGen *g, AstNode *source_node, LLVMValueRef va | ... | @@ -1927,10 +1929,10 @@ static LLVMValueRef gen_return(CodeGen *g, AstNode *source_node, LLVMValueRef va |
| 1927 | if (handle_is_ptr(return_type)) { | 1929 | if (handle_is_ptr(return_type)) { |
| 1928 | assert(g->cur_ret_ptr); | 1930 | assert(g->cur_ret_ptr); |
| 1929 | gen_assign_raw(g, source_node, BinOpTypeAssign, g->cur_ret_ptr, value, return_type, return_type); | 1931 | gen_assign_raw(g, source_node, BinOpTypeAssign, g->cur_ret_ptr, value, return_type, return_type); |
| 1930 | add_debug_source_node(g, source_node); | 1932 | set_debug_source_node(g, source_node); |
| 1931 | LLVMBuildRetVoid(g->builder); | 1933 | LLVMBuildRetVoid(g->builder); |
| 1932 | } else { | 1934 | } else { |
| 1933 | add_debug_source_node(g, source_node); | 1935 | set_debug_source_node(g, source_node); |
| 1934 | LLVMBuildRet(g->builder, value); | 1936 | LLVMBuildRet(g->builder, value); |
| 1935 | } | 1937 | } |
| 1936 | return nullptr; | 1938 | return nullptr; |
| ... | @@ -1972,7 +1974,7 @@ static LLVMValueRef gen_return_expr(CodeGen *g, AstNode *node) { | ... | @@ -1972,7 +1974,7 @@ static LLVMValueRef gen_return_expr(CodeGen *g, AstNode *node) { |
| 1972 | LLVMBasicBlockRef return_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ErrRetReturn"); | 1974 | LLVMBasicBlockRef return_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ErrRetReturn"); |
| 1973 | LLVMBasicBlockRef continue_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ErrRetContinue"); | 1975 | LLVMBasicBlockRef continue_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ErrRetContinue"); |
| 1974 | | 1976 | |
| 1975 | add_debug_source_node(g, node); | 1977 | set_debug_source_node(g, node); |
| 1976 | LLVMValueRef err_val; | 1978 | LLVMValueRef err_val; |
| 1977 | if (type_has_bits(child_type)) { | 1979 | if (type_has_bits(child_type)) { |
| 1978 | LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, value, 0, ""); | 1980 | LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, value, 0, ""); |
| ... | @@ -1992,7 +1994,7 @@ static LLVMValueRef gen_return_expr(CodeGen *g, AstNode *node) { | ... | @@ -1992,7 +1994,7 @@ static LLVMValueRef gen_return_expr(CodeGen *g, AstNode *node) { |
| 1992 | if (type_has_bits(return_type->data.error.child_type)) { | 1994 | if (type_has_bits(return_type->data.error.child_type)) { |
| 1993 | assert(g->cur_ret_ptr); | 1995 | assert(g->cur_ret_ptr); |
| 1994 | | 1996 | |
| 1995 | add_debug_source_node(g, node); | 1997 | set_debug_source_node(g, node); |
| 1996 | LLVMValueRef tag_ptr = LLVMBuildStructGEP(g->builder, g->cur_ret_ptr, 0, ""); | 1998 | LLVMValueRef tag_ptr = LLVMBuildStructGEP(g->builder, g->cur_ret_ptr, 0, ""); |
| 1997 | LLVMBuildStore(g->builder, err_val, tag_ptr); | 1999 | LLVMBuildStore(g->builder, err_val, tag_ptr); |
| 1998 | LLVMBuildRetVoid(g->builder); | 2000 | LLVMBuildRetVoid(g->builder); |
| ... | @@ -2005,7 +2007,7 @@ static LLVMValueRef gen_return_expr(CodeGen *g, AstNode *node) { | ... | @@ -2005,7 +2007,7 @@ static LLVMValueRef gen_return_expr(CodeGen *g, AstNode *node) { |
| 2005 | | 2007 | |
| 2006 | LLVMPositionBuilderAtEnd(g->builder, continue_block); | 2008 | LLVMPositionBuilderAtEnd(g->builder, continue_block); |
| 2007 | if (type_has_bits(child_type)) { | 2009 | if (type_has_bits(child_type)) { |
| 2008 | add_debug_source_node(g, node); | 2010 | set_debug_source_node(g, node); |
| 2009 | LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, value, 1, ""); | 2011 | LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, value, 1, ""); |
| 2010 | return get_handle_value(g, node, val_ptr, child_type); | 2012 | return get_handle_value(g, node, val_ptr, child_type); |
| 2011 | } else { | 2013 | } else { |
| ... | @@ -2040,7 +2042,7 @@ static LLVMValueRef gen_if_bool_expr_raw(CodeGen *g, AstNode *source_node, LLVMV | ... | @@ -2040,7 +2042,7 @@ static LLVMValueRef gen_if_bool_expr_raw(CodeGen *g, AstNode *source_node, LLVMV |
| 2040 | endif_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "EndIf"); | 2042 | endif_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "EndIf"); |
| 2041 | } | 2043 | } |
| 2042 | | 2044 | |
| 2043 | add_debug_source_node(g, source_node); | 2045 | set_debug_source_node(g, source_node); |
| 2044 | LLVMBuildCondBr(g->builder, cond_value, then_block, else_block); | 2046 | LLVMBuildCondBr(g->builder, cond_value, then_block, else_block); |
| 2045 | | 2047 | |
| 2046 | LLVMPositionBuilderAtEnd(g->builder, then_block); | 2048 | LLVMPositionBuilderAtEnd(g->builder, then_block); |
| ... | @@ -2115,7 +2117,7 @@ static LLVMValueRef gen_if_var_expr(CodeGen *g, AstNode *node) { | ... | @@ -2115,7 +2117,7 @@ static LLVMValueRef gen_if_var_expr(CodeGen *g, AstNode *node) { |
| 2115 | { | 2117 | { |
| 2116 | cond_value = LLVMBuildICmp(g->builder, LLVMIntNE, init_val, LLVMConstNull(child_type->type_ref), ""); | 2118 | cond_value = LLVMBuildICmp(g->builder, LLVMIntNE, init_val, LLVMConstNull(child_type->type_ref), ""); |
| 2117 | } else { | 2119 | } else { |
| 2118 | add_debug_source_node(g, node); | 2120 | set_debug_source_node(g, node); |
| 2119 | LLVMValueRef maybe_field_ptr = LLVMBuildStructGEP(g->builder, init_val, 1, ""); | 2121 | LLVMValueRef maybe_field_ptr = LLVMBuildStructGEP(g->builder, init_val, 1, ""); |
| 2120 | cond_value = LLVMBuildLoad(g->builder, maybe_field_ptr, ""); | 2122 | cond_value = LLVMBuildLoad(g->builder, maybe_field_ptr, ""); |
| 2121 | } | 2123 | } |
| ... | @@ -2271,7 +2273,7 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) { | ... | @@ -2271,7 +2273,7 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) { |
| 2271 | LLVMValueRef asm_fn = LLVMConstInlineAsm(function_type, buf_ptr(&llvm_template), | 2273 | LLVMValueRef asm_fn = LLVMConstInlineAsm(function_type, buf_ptr(&llvm_template), |
| 2272 | buf_ptr(&constraint_buf), is_volatile, false); | 2274 | buf_ptr(&constraint_buf), is_volatile, false); |
| 2273 | | 2275 | |
| 2274 | add_debug_source_node(g, node); | 2276 | set_debug_source_node(g, node); |
| 2275 | return LLVMBuildCall(g->builder, asm_fn, param_values, input_and_output_count, ""); | 2277 | return LLVMBuildCall(g->builder, asm_fn, param_values, input_and_output_count, ""); |
| 2276 | } | 2278 | } |
| 2277 | | 2279 | |
| ... | @@ -2313,7 +2315,7 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) { | ... | @@ -2313,7 +2315,7 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) { |
| 2313 | } | 2315 | } |
| 2314 | assert(buf_eql_buf(type_struct_field->name, &field_node->data.struct_val_field.name)); | 2316 | assert(buf_eql_buf(type_struct_field->name, &field_node->data.struct_val_field.name)); |
| 2315 | | 2317 | |
| 2316 | add_debug_source_node(g, field_node); | 2318 | set_debug_source_node(g, field_node); |
| 2317 | LLVMValueRef field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, type_struct_field->gen_index, ""); | 2319 | LLVMValueRef field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, type_struct_field->gen_index, ""); |
| 2318 | AstNode *expr_node = field_node->data.struct_val_field.expr; | 2320 | AstNode *expr_node = field_node->data.struct_val_field.expr; |
| 2319 | LLVMValueRef value = gen_expr(g, expr_node); | 2321 | LLVMValueRef value = gen_expr(g, expr_node); |
| ... | @@ -2324,7 +2326,7 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) { | ... | @@ -2324,7 +2326,7 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) { |
| 2324 | return tmp_struct_ptr; | 2326 | return tmp_struct_ptr; |
| 2325 | } else if (type_entry->id == TypeTableEntryIdUnreachable) { | 2327 | } else if (type_entry->id == TypeTableEntryIdUnreachable) { |
| 2326 | assert(node->data.container_init_expr.entries.length == 0); | 2328 | assert(node->data.container_init_expr.entries.length == 0); |
| 2327 | add_debug_source_node(g, node); | 2329 | set_debug_source_node(g, node); |
| 2328 | if (want_debug_safety(g, node)) { | 2330 | if (want_debug_safety(g, node)) { |
| 2329 | LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, ""); | 2331 | LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, ""); |
| 2330 | } | 2332 | } |
| ... | @@ -2350,7 +2352,7 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) { | ... | @@ -2350,7 +2352,7 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) { |
| 2350 | LLVMConstNull(g->builtin_types.entry_isize->type_ref), | 2352 | LLVMConstNull(g->builtin_types.entry_isize->type_ref), |
| 2351 | LLVMConstInt(g->builtin_types.entry_isize->type_ref, i, false), | 2353 | LLVMConstInt(g->builtin_types.entry_isize->type_ref, i, false), |
| 2352 | }; | 2354 | }; |
| 2353 | add_debug_source_node(g, field_node); | 2355 | set_debug_source_node(g, field_node); |
| 2354 | LLVMValueRef elem_ptr = LLVMBuildInBoundsGEP(g->builder, tmp_array_ptr, indices, 2, ""); | 2356 | LLVMValueRef elem_ptr = LLVMBuildInBoundsGEP(g->builder, tmp_array_ptr, indices, 2, ""); |
| 2355 | gen_assign_raw(g, field_node, BinOpTypeAssign, elem_ptr, elem_val, | 2357 | gen_assign_raw(g, field_node, BinOpTypeAssign, elem_ptr, elem_val, |
| 2356 | child_type, get_expr_type(field_node)); | 2358 | child_type, get_expr_type(field_node)); |
| ... | @@ -2382,7 +2384,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { | ... | @@ -2382,7 +2384,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { |
| 2382 | end_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "WhileEnd"); | 2384 | end_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "WhileEnd"); |
| 2383 | } | 2385 | } |
| 2384 | | 2386 | |
| 2385 | add_debug_source_node(g, node); | 2387 | set_debug_source_node(g, node); |
| 2386 | LLVMBuildBr(g->builder, body_block); | 2388 | LLVMBuildBr(g->builder, body_block); |
| 2387 | | 2389 | |
| 2388 | if (continue_expr_node) { | 2390 | if (continue_expr_node) { |
| ... | @@ -2390,7 +2392,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { | ... | @@ -2390,7 +2392,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { |
| 2390 | | 2392 | |
| 2391 | gen_expr(g, continue_expr_node); | 2393 | gen_expr(g, continue_expr_node); |
| 2392 | | 2394 | |
| 2393 | add_debug_source_node(g, node); | 2395 | set_debug_source_node(g, node); |
| 2394 | LLVMBuildBr(g->builder, body_block); | 2396 | LLVMBuildBr(g->builder, body_block); |
| 2395 | } | 2397 | } |
| 2396 | | 2398 | |
| ... | @@ -2402,7 +2404,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { | ... | @@ -2402,7 +2404,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { |
| 2402 | g->continue_block_stack.pop(); | 2404 | g->continue_block_stack.pop(); |
| 2403 | | 2405 | |
| 2404 | if (get_expr_type(node->data.while_expr.body)->id != TypeTableEntryIdUnreachable) { | 2406 | if (get_expr_type(node->data.while_expr.body)->id != TypeTableEntryIdUnreachable) { |
| 2405 | add_debug_source_node(g, node); | 2407 | set_debug_source_node(g, node); |
| 2406 | LLVMBuildBr(g->builder, continue_block); | 2408 | LLVMBuildBr(g->builder, continue_block); |
| 2407 | } | 2409 | } |
| 2408 | | 2410 | |
| ... | @@ -2418,7 +2420,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { | ... | @@ -2418,7 +2420,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { |
| 2418 | LLVMAppendBasicBlock(g->cur_fn->fn_value, "WhileContinue") : cond_block; | 2420 | LLVMAppendBasicBlock(g->cur_fn->fn_value, "WhileContinue") : cond_block; |
| 2419 | LLVMBasicBlockRef end_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "WhileEnd"); | 2421 | LLVMBasicBlockRef end_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "WhileEnd"); |
| 2420 | | 2422 | |
| 2421 | add_debug_source_node(g, node); | 2423 | set_debug_source_node(g, node); |
| 2422 | LLVMBuildBr(g->builder, cond_block); | 2424 | LLVMBuildBr(g->builder, cond_block); |
| 2423 | | 2425 | |
| 2424 | if (continue_expr_node) { | 2426 | if (continue_expr_node) { |
| ... | @@ -2426,13 +2428,13 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { | ... | @@ -2426,13 +2428,13 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { |
| 2426 | | 2428 | |
| 2427 | gen_expr(g, continue_expr_node); | 2429 | gen_expr(g, continue_expr_node); |
| 2428 | | 2430 | |
| 2429 | add_debug_source_node(g, node); | 2431 | set_debug_source_node(g, node); |
| 2430 | LLVMBuildBr(g->builder, cond_block); | 2432 | LLVMBuildBr(g->builder, cond_block); |
| 2431 | } | 2433 | } |
| 2432 | | 2434 | |
| 2433 | LLVMPositionBuilderAtEnd(g->builder, cond_block); | 2435 | LLVMPositionBuilderAtEnd(g->builder, cond_block); |
| 2434 | LLVMValueRef cond_val = gen_expr(g, node->data.while_expr.condition); | 2436 | LLVMValueRef cond_val = gen_expr(g, node->data.while_expr.condition); |
| 2435 | add_debug_source_node(g, node->data.while_expr.condition); | 2437 | set_debug_source_node(g, node->data.while_expr.condition); |
| 2436 | LLVMBuildCondBr(g->builder, cond_val, body_block, end_block); | 2438 | LLVMBuildCondBr(g->builder, cond_val, body_block, end_block); |
| 2437 | | 2439 | |
| 2438 | LLVMPositionBuilderAtEnd(g->builder, body_block); | 2440 | LLVMPositionBuilderAtEnd(g->builder, body_block); |
| ... | @@ -2442,7 +2444,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { | ... | @@ -2442,7 +2444,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { |
| 2442 | g->break_block_stack.pop(); | 2444 | g->break_block_stack.pop(); |
| 2443 | g->continue_block_stack.pop(); | 2445 | g->continue_block_stack.pop(); |
| 2444 | if (get_expr_type(node->data.while_expr.body)->id != TypeTableEntryIdUnreachable) { | 2446 | if (get_expr_type(node->data.while_expr.body)->id != TypeTableEntryIdUnreachable) { |
| 2445 | add_debug_source_node(g, node); | 2447 | set_debug_source_node(g, node); |
| 2446 | LLVMBuildBr(g->builder, continue_block); | 2448 | LLVMBuildBr(g->builder, continue_block); |
| 2447 | } | 2449 | } |
| 2448 | | 2450 | |
| ... | @@ -2454,7 +2456,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { | ... | @@ -2454,7 +2456,7 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) { |
| 2454 | | 2456 | |
| 2455 | static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) { | 2457 | static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) { |
| 2456 | BlockContext *block_context = var->block_context; | 2458 | BlockContext *block_context = var->block_context; |
| 2457 | AstNode *source_node = block_context->node; | 2459 | AstNode *source_node = var->decl_node; |
| 2458 | LLVMZigDILocation *debug_loc = LLVMZigGetDebugLoc(source_node->line + 1, source_node->column + 1, | 2460 | LLVMZigDILocation *debug_loc = LLVMZigGetDebugLoc(source_node->line + 1, source_node->column + 1, |
| 2459 | block_context->di_scope); | 2461 | block_context->di_scope); |
| 2460 | LLVMZigInsertDeclareAtEnd(g->dbuilder, var->value_ref, var->di_loc_var, debug_loc, | 2462 | LLVMZigInsertDeclareAtEnd(g->dbuilder, var->value_ref, var->di_loc_var, debug_loc, |
| ... | @@ -2482,7 +2484,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) { | ... | @@ -2482,7 +2484,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) { |
| 2482 | LLVMBasicBlockRef continue_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForContinue"); | 2484 | LLVMBasicBlockRef continue_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForContinue"); |
| 2483 | | 2485 | |
| 2484 | LLVMValueRef array_val = gen_array_base_ptr(g, node->data.for_expr.array_expr); | 2486 | LLVMValueRef array_val = gen_array_base_ptr(g, node->data.for_expr.array_expr); |
| 2485 | add_debug_source_node(g, node); | 2487 | set_debug_source_node(g, node); |
| 2486 | LLVMBuildStore(g->builder, LLVMConstNull(index_var->type->type_ref), index_ptr); | 2488 | LLVMBuildStore(g->builder, LLVMConstNull(index_var->type->type_ref), index_ptr); |
| 2487 | | 2489 | |
| 2488 | gen_var_debug_decl(g, index_var); | 2490 | gen_var_debug_decl(g, index_var); |
| ... | @@ -2529,12 +2531,12 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) { | ... | @@ -2529,12 +2531,12 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) { |
| 2529 | g->break_block_stack.pop(); | 2531 | g->break_block_stack.pop(); |
| 2530 | g->continue_block_stack.pop(); | 2532 | g->continue_block_stack.pop(); |
| 2531 | if (get_expr_type(node->data.for_expr.body)->id != TypeTableEntryIdUnreachable) { | 2533 | if (get_expr_type(node->data.for_expr.body)->id != TypeTableEntryIdUnreachable) { |
| 2532 | add_debug_source_node(g, node); | 2534 | set_debug_source_node(g, node); |
| 2533 | LLVMBuildBr(g->builder, continue_block); | 2535 | LLVMBuildBr(g->builder, continue_block); |
| 2534 | } | 2536 | } |
| 2535 | | 2537 | |
| 2536 | LLVMPositionBuilderAtEnd(g->builder, continue_block); | 2538 | LLVMPositionBuilderAtEnd(g->builder, continue_block); |
| 2537 | add_debug_source_node(g, node); | 2539 | set_debug_source_node(g, node); |
| 2538 | LLVMValueRef new_index_val = LLVMBuildAdd(g->builder, index_val, one_const, ""); | 2540 | LLVMValueRef new_index_val = LLVMBuildAdd(g->builder, index_val, one_const, ""); |
| 2539 | LLVMBuildStore(g->builder, new_index_val, index_ptr); | 2541 | LLVMBuildStore(g->builder, new_index_val, index_ptr); |
| 2540 | LLVMBuildBr(g->builder, cond_block); | 2542 | LLVMBuildBr(g->builder, cond_block); |
| ... | @@ -2547,7 +2549,7 @@ static LLVMValueRef gen_break(CodeGen *g, AstNode *node) { | ... | @@ -2547,7 +2549,7 @@ static LLVMValueRef gen_break(CodeGen *g, AstNode *node) { |
| 2547 | assert(node->type == NodeTypeBreak); | 2549 | assert(node->type == NodeTypeBreak); |
| 2548 | LLVMBasicBlockRef dest_block = g->break_block_stack.last(); | 2550 | LLVMBasicBlockRef dest_block = g->break_block_stack.last(); |
| 2549 | | 2551 | |
| 2550 | add_debug_source_node(g, node); | 2552 | set_debug_source_node(g, node); |
| 2551 | return LLVMBuildBr(g->builder, dest_block); | 2553 | return LLVMBuildBr(g->builder, dest_block); |
| 2552 | } | 2554 | } |
| 2553 | | 2555 | |
| ... | @@ -2555,7 +2557,7 @@ static LLVMValueRef gen_continue(CodeGen *g, AstNode *node) { | ... | @@ -2555,7 +2557,7 @@ static LLVMValueRef gen_continue(CodeGen *g, AstNode *node) { |
| 2555 | assert(node->type == NodeTypeContinue); | 2557 | assert(node->type == NodeTypeContinue); |
| 2556 | LLVMBasicBlockRef dest_block = g->continue_block_stack.last(); | 2558 | LLVMBasicBlockRef dest_block = g->continue_block_stack.last(); |
| 2557 | | 2559 | |
| 2558 | add_debug_source_node(g, node); | 2560 | set_debug_source_node(g, node); |
| 2559 | return LLVMBuildBr(g->builder, dest_block); | 2561 | return LLVMBuildBr(g->builder, dest_block); |
| 2560 | } | 2562 | } |
| 2561 | | 2563 | |
| ... | @@ -2565,7 +2567,6 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa | ... | @@ -2565,7 +2567,6 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa |
| 2565 | VariableTableEntry *variable = var_decl->variable; | 2567 | VariableTableEntry *variable = var_decl->variable; |
| 2566 | | 2568 | |
| 2567 | assert(variable); | 2569 | assert(variable); |
| 2568 | assert(variable->is_ptr); | | |
| 2569 | | 2570 | |
| 2570 | if (var_decl->expr) { | 2571 | if (var_decl->expr) { |
| 2571 | *init_value = gen_expr(g, var_decl->expr); | 2572 | *init_value = gen_expr(g, var_decl->expr); |
| ... | @@ -2614,7 +2615,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa | ... | @@ -2614,7 +2615,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa |
| 2614 | | 2615 | |
| 2615 | LLVMValueRef size_val = gen_expr(g, size_node); | 2616 | LLVMValueRef size_val = gen_expr(g, size_node); |
| 2616 | | 2617 | |
| 2617 | add_debug_source_node(g, source_node); | 2618 | set_debug_source_node(g, source_node); |
| 2618 | LLVMValueRef ptr_val = LLVMBuildArrayAlloca(g->builder, child_type->type_ref, | 2619 | LLVMValueRef ptr_val = LLVMBuildArrayAlloca(g->builder, child_type->type_ref, |
| 2619 | size_val, ""); | 2620 | size_val, ""); |
| 2620 | | 2621 | |
| ... | @@ -2645,7 +2646,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa | ... | @@ -2645,7 +2646,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa |
| 2645 | uint64_t align_bytes = get_memcpy_align(g, variable->type); | 2646 | uint64_t align_bytes = get_memcpy_align(g, variable->type); |
| 2646 | | 2647 | |
| 2647 | // memset uninitialized memory to 0xa | 2648 | // memset uninitialized memory to 0xa |
| 2648 | add_debug_source_node(g, source_node); | 2649 | set_debug_source_node(g, source_node); |
| 2649 | LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); | 2650 | LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0); |
| 2650 | LLVMValueRef fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false); | 2651 | LLVMValueRef fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false); |
| 2651 | LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, variable->value_ref, ptr_u8, ""); | 2652 | LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, variable->value_ref, ptr_u8, ""); |
| ... | @@ -2708,11 +2709,11 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { | ... | @@ -2708,11 +2709,11 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { |
| 2708 | LLVMValueRef target_value; | 2709 | LLVMValueRef target_value; |
| 2709 | if (handle_is_ptr(target_type)) { | 2710 | if (handle_is_ptr(target_type)) { |
| 2710 | if (target_type->id == TypeTableEntryIdEnum) { | 2711 | if (target_type->id == TypeTableEntryIdEnum) { |
| 2711 | add_debug_source_node(g, node); | 2712 | set_debug_source_node(g, node); |
| 2712 | LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, target_value_handle, 0, ""); | 2713 | LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, target_value_handle, 0, ""); |
| 2713 | target_value = LLVMBuildLoad(g->builder, tag_field_ptr, ""); | 2714 | target_value = LLVMBuildLoad(g->builder, tag_field_ptr, ""); |
| 2714 | } else if (target_type->id == TypeTableEntryIdErrorUnion) { | 2715 | } else if (target_type->id == TypeTableEntryIdErrorUnion) { |
| 2715 | add_debug_source_node(g, node); | 2716 | set_debug_source_node(g, node); |
| 2716 | LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, target_value_handle, 0, ""); | 2717 | LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, target_value_handle, 0, ""); |
| 2717 | target_value = LLVMBuildLoad(g->builder, tag_field_ptr, ""); | 2718 | target_value = LLVMBuildLoad(g->builder, tag_field_ptr, ""); |
| 2718 | } else { | 2719 | } else { |
| ... | @@ -2732,7 +2733,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { | ... | @@ -2732,7 +2733,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { |
| 2732 | LLVMBasicBlockRef else_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchElse"); | 2733 | LLVMBasicBlockRef else_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchElse"); |
| 2733 | int prong_count = node->data.switch_expr.prongs.length; | 2734 | int prong_count = node->data.switch_expr.prongs.length; |
| 2734 | | 2735 | |
| 2735 | add_debug_source_node(g, node); | 2736 | set_debug_source_node(g, node); |
| 2736 | LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, target_value, else_block, prong_count); | 2737 | LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, target_value, else_block, prong_count); |
| 2737 | | 2738 | |
| 2738 | ZigList<LLVMValueRef> incoming_values = {0}; | 2739 | ZigList<LLVMValueRef> incoming_values = {0}; |
| ... | @@ -2789,7 +2790,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { | ... | @@ -2789,7 +2790,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { |
| 2789 | } | 2790 | } |
| 2790 | | 2791 | |
| 2791 | AstNode *var_node = prong_node->data.switch_prong.var_symbol; | 2792 | AstNode *var_node = prong_node->data.switch_prong.var_symbol; |
| 2792 | add_debug_source_node(g, var_node); | 2793 | set_debug_source_node(g, var_node); |
| 2793 | if (prong_node->data.switch_prong.var_is_target_expr) { | 2794 | if (prong_node->data.switch_prong.var_is_target_expr) { |
| 2794 | gen_assign_raw(g, var_node, BinOpTypeAssign, | 2795 | gen_assign_raw(g, var_node, BinOpTypeAssign, |
| 2795 | prong_var->value_ref, target_value, prong_var->type, target_type); | 2796 | prong_var->value_ref, target_value, prong_var->type, target_type); |
| ... | @@ -2844,7 +2845,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { | ... | @@ -2844,7 +2845,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { |
| 2844 | LLVMValueRef prong_val = gen_expr(g, prong_expr); | 2845 | LLVMValueRef prong_val = gen_expr(g, prong_expr); |
| 2845 | | 2846 | |
| 2846 | if (get_expr_type(prong_expr)->id != TypeTableEntryIdUnreachable) { | 2847 | if (get_expr_type(prong_expr)->id != TypeTableEntryIdUnreachable) { |
| 2847 | add_debug_source_node(g, prong_expr); | 2848 | set_debug_source_node(g, prong_expr); |
| 2848 | LLVMBuildBr(g->builder, end_block); | 2849 | LLVMBuildBr(g->builder, end_block); |
| 2849 | incoming_values.append(prong_val); | 2850 | incoming_values.append(prong_val); |
| 2850 | incoming_blocks.append(prong_block); | 2851 | incoming_blocks.append(prong_block); |
| ... | @@ -2853,7 +2854,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { | ... | @@ -2853,7 +2854,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { |
| 2853 | | 2854 | |
| 2854 | if (!else_prong) { | 2855 | if (!else_prong) { |
| 2855 | LLVMPositionBuilderAtEnd(g->builder, else_block); | 2856 | LLVMPositionBuilderAtEnd(g->builder, else_block); |
| 2856 | add_debug_source_node(g, node); | 2857 | set_debug_source_node(g, node); |
| 2857 | if (want_debug_safety(g, node)) { | 2858 | if (want_debug_safety(g, node)) { |
| 2858 | LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, ""); | 2859 | LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, ""); |
| 2859 | } | 2860 | } |
| ... | @@ -2867,7 +2868,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { | ... | @@ -2867,7 +2868,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) { |
| 2867 | LLVMPositionBuilderAtEnd(g->builder, end_block); | 2868 | LLVMPositionBuilderAtEnd(g->builder, end_block); |
| 2868 | | 2869 | |
| 2869 | if (result_has_bits) { | 2870 | if (result_has_bits) { |
| 2870 | add_debug_source_node(g, node); | 2871 | set_debug_source_node(g, node); |
| 2871 | LLVMValueRef phi = LLVMBuildPhi(g->builder, LLVMTypeOf(incoming_values.at(0)), ""); | 2872 | LLVMValueRef phi = LLVMBuildPhi(g->builder, LLVMTypeOf(incoming_values.at(0)), ""); |
| 2872 | LLVMAddIncoming(phi, incoming_values.items, incoming_blocks.items, incoming_values.length); | 2873 | LLVMAddIncoming(phi, incoming_values.items, incoming_blocks.items, incoming_values.length); |
| 2873 | return phi; | 2874 | return phi; |
| ... | @@ -2885,7 +2886,7 @@ static LLVMValueRef gen_goto(CodeGen *g, AstNode *node) { | ... | @@ -2885,7 +2886,7 @@ static LLVMValueRef gen_goto(CodeGen *g, AstNode *node) { |
| 2885 | BlockContext *target_context = label->decl_node->block_context; | 2886 | BlockContext *target_context = label->decl_node->block_context; |
| 2886 | gen_defers_for_block(g, this_context, target_context, false, false); | 2887 | gen_defers_for_block(g, this_context, target_context, false, false); |
| 2887 | | 2888 | |
| 2888 | add_debug_source_node(g, node); | 2889 | set_debug_source_node(g, node); |
| 2889 | LLVMBuildBr(g->builder, node->data.goto_expr.label_entry->basic_block); | 2890 | LLVMBuildBr(g->builder, node->data.goto_expr.label_entry->basic_block); |
| 2890 | return nullptr; | 2891 | return nullptr; |
| 2891 | } | 2892 | } |
| ... | @@ -2898,7 +2899,7 @@ static LLVMValueRef gen_label(CodeGen *g, AstNode *node) { | ... | @@ -2898,7 +2899,7 @@ static LLVMValueRef gen_label(CodeGen *g, AstNode *node) { |
| 2898 | | 2899 | |
| 2899 | LLVMBasicBlockRef basic_block = label->basic_block; | 2900 | LLVMBasicBlockRef basic_block = label->basic_block; |
| 2900 | if (label->entered_from_fallthrough) { | 2901 | if (label->entered_from_fallthrough) { |
| 2901 | add_debug_source_node(g, node); | 2902 | set_debug_source_node(g, node); |
| 2902 | LLVMBuildBr(g->builder, basic_block); | 2903 | LLVMBuildBr(g->builder, basic_block); |
| 2903 | } | 2904 | } |
| 2904 | LLVMPositionBuilderAtEnd(g->builder, basic_block); | 2905 | LLVMPositionBuilderAtEnd(g->builder, basic_block); |
| ... | @@ -3519,6 +3520,23 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -3519,6 +3520,23 @@ static void do_code_gen(CodeGen *g) { |
| 3519 | | 3520 | |
| 3520 | } | 3521 | } |
| 3521 | | 3522 | |
| | 3523 | clear_debug_source_node(g); |
| | 3524 | |
| | 3525 | // allocate structs which are the result of casts |
| | 3526 | for (int cea_i = 0; cea_i < fn_table_entry->cast_alloca_list.length; cea_i += 1) { |
| | 3527 | AstNode *fn_call_node = fn_table_entry->cast_alloca_list.at(cea_i); |
| | 3528 | Expr *expr = &fn_call_node->data.fn_call_expr.resolved_expr; |
| | 3529 | fn_call_node->data.fn_call_expr.tmp_ptr = LLVMBuildAlloca(g->builder, |
| | 3530 | expr->type_entry->type_ref, ""); |
| | 3531 | } |
| | 3532 | |
| | 3533 | // allocate structs which are struct value expressions |
| | 3534 | for (int alloca_i = 0; alloca_i < fn_table_entry->struct_val_expr_alloca_list.length; alloca_i += 1) { |
| | 3535 | StructValExprCodeGen *struct_val_expr_node = fn_table_entry->struct_val_expr_alloca_list.at(alloca_i); |
| | 3536 | struct_val_expr_node->ptr = LLVMBuildAlloca(g->builder, |
| | 3537 | struct_val_expr_node->type_entry->type_ref, ""); |
| | 3538 | } |
| | 3539 | |
| 3522 | // create debug variable declarations for variables and allocate all local variables | 3540 | // create debug variable declarations for variables and allocate all local variables |
| 3523 | for (int var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) { | 3541 | for (int var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) { |
| 3524 | VariableTableEntry *var = fn_table_entry->variable_list.at(var_i); | 3542 | VariableTableEntry *var = fn_table_entry->variable_list.at(var_i); |
| ... | @@ -3527,29 +3545,32 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -3527,29 +3545,32 @@ static void do_code_gen(CodeGen *g) { |
| 3527 | continue; | 3545 | continue; |
| 3528 | } | 3546 | } |
| 3529 | | 3547 | |
| 3530 | TypeTableEntry *gen_type; | | |
| 3531 | if (var->block_context->node->type == NodeTypeFnDef) { | 3548 | if (var->block_context->node->type == NodeTypeFnDef) { |
| 3532 | var->is_ptr = false; | | |
| 3533 | assert(var->gen_arg_index >= 0); | 3549 | assert(var->gen_arg_index >= 0); |
| 3534 | var->value_ref = LLVMGetParam(fn, var->gen_arg_index); | 3550 | if (handle_is_ptr(var->type)) { |
| 3535 | | 3551 | TypeTableEntry *gen_type = fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index].type; |
| 3536 | gen_type = fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index].type; | 3552 | var->value_ref = LLVMGetParam(fn, var->gen_arg_index); |
| | 3553 | var->di_loc_var = LLVMZigCreateParameterVariable(g->dbuilder, var->block_context->di_scope, |
| | 3554 | buf_ptr(&var->name), import->di_file, var->decl_node->line + 1, |
| | 3555 | gen_type->di_type, !g->strip_debug_symbols, 0, var->gen_arg_index + 1); |
| | 3556 | } else { |
| | 3557 | var->value_ref = LLVMBuildAlloca(g->builder, var->type->type_ref, buf_ptr(&var->name)); |
| | 3558 | uint64_t align_bytes = LLVMABISizeOfType(g->target_data_ref, var->type->type_ref); |
| | 3559 | LLVMSetAlignment(var->value_ref, align_bytes); |
| | 3560 | var->di_loc_var = LLVMZigCreateAutoVariable(g->dbuilder, var->block_context->di_scope, |
| | 3561 | buf_ptr(&var->name), import->di_file, var->decl_node->line + 1, |
| | 3562 | var->type->di_type, !g->strip_debug_symbols, 0); |
| | 3563 | } |
| 3537 | | 3564 | |
| 3538 | var->di_loc_var = LLVMZigCreateParameterVariable(g->dbuilder, var->block_context->di_scope, | | |
| 3539 | buf_ptr(&var->name), import->di_file, var->decl_node->line + 1, | | |
| 3540 | gen_type->di_type, !g->strip_debug_symbols, 0, var->gen_arg_index + 1); | | |
| 3541 | } else { | 3565 | } else { |
| 3542 | | | |
| 3543 | add_debug_source_node(g, var->decl_node); | | |
| 3544 | var->value_ref = LLVMBuildAlloca(g->builder, var->type->type_ref, buf_ptr(&var->name)); | 3566 | var->value_ref = LLVMBuildAlloca(g->builder, var->type->type_ref, buf_ptr(&var->name)); |
| | 3567 | |
| 3545 | uint64_t align_bytes = LLVMABISizeOfType(g->target_data_ref, var->type->type_ref); | 3568 | uint64_t align_bytes = LLVMABISizeOfType(g->target_data_ref, var->type->type_ref); |
| 3546 | LLVMSetAlignment(var->value_ref, align_bytes); | 3569 | LLVMSetAlignment(var->value_ref, align_bytes); |
| 3547 | | 3570 | |
| 3548 | gen_type = var->type; | | |
| 3549 | | | |
| 3550 | var->di_loc_var = LLVMZigCreateAutoVariable(g->dbuilder, var->block_context->di_scope, | 3571 | var->di_loc_var = LLVMZigCreateAutoVariable(g->dbuilder, var->block_context->di_scope, |
| 3551 | buf_ptr(&var->name), import->di_file, var->decl_node->line + 1, | 3572 | buf_ptr(&var->name), import->di_file, var->decl_node->line + 1, |
| 3552 | gen_type->di_type, !g->strip_debug_symbols, 0); | 3573 | var->type->di_type, !g->strip_debug_symbols, 0); |
| 3553 | } | 3574 | } |
| 3554 | } | 3575 | } |
| 3555 | | 3576 | |
| ... | @@ -3567,25 +3588,14 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -3567,25 +3588,14 @@ static void do_code_gen(CodeGen *g) { |
| 3567 | VariableTableEntry *variable = param_decl->data.param_decl.variable; | 3588 | VariableTableEntry *variable = param_decl->data.param_decl.variable; |
| 3568 | assert(variable); | 3589 | assert(variable); |
| 3569 | | 3590 | |
| 3570 | gen_var_debug_decl(g, variable); | 3591 | if (!handle_is_ptr(variable->type)) { |
| 3571 | } | 3592 | clear_debug_source_node(g); |
| | 3593 | LLVMBuildStore(g->builder, LLVMGetParam(fn, variable->gen_arg_index), variable->value_ref); |
| | 3594 | } |
| 3572 | | 3595 | |
| 3573 | // allocate structs which are the result of casts | 3596 | gen_var_debug_decl(g, variable); |
| 3574 | for (int cea_i = 0; cea_i < fn_table_entry->cast_alloca_list.length; cea_i += 1) { | | |
| 3575 | AstNode *fn_call_node = fn_table_entry->cast_alloca_list.at(cea_i); | | |
| 3576 | add_debug_source_node(g, fn_call_node); | | |
| 3577 | Expr *expr = &fn_call_node->data.fn_call_expr.resolved_expr; | | |
| 3578 | fn_call_node->data.fn_call_expr.tmp_ptr = LLVMBuildAlloca(g->builder, | | |
| 3579 | expr->type_entry->type_ref, ""); | | |
| 3580 | } | 3597 | } |
| 3581 | | 3598 | |
| 3582 | // allocate structs which are struct value expressions | | |
| 3583 | for (int alloca_i = 0; alloca_i < fn_table_entry->struct_val_expr_alloca_list.length; alloca_i += 1) { | | |
| 3584 | StructValExprCodeGen *struct_val_expr_node = fn_table_entry->struct_val_expr_alloca_list.at(alloca_i); | | |
| 3585 | add_debug_source_node(g, struct_val_expr_node->source_node); | | |
| 3586 | struct_val_expr_node->ptr = LLVMBuildAlloca(g->builder, | | |
| 3587 | struct_val_expr_node->type_entry->type_ref, ""); | | |
| 3588 | } | | |
| 3589 | | 3599 | |
| 3590 | TypeTableEntry *implicit_return_type = fn_def_node->data.fn_def.implicit_return_type; | 3600 | TypeTableEntry *implicit_return_type = fn_def_node->data.fn_def.implicit_return_type; |
| 3591 | gen_block(g, fn_def_node->data.fn_def.body, implicit_return_type); | 3601 | gen_block(g, fn_def_node->data.fn_def.body, implicit_return_type); |