| ... | @@ -558,100 +558,125 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c | ... | @@ -558,100 +558,125 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c |
| 558 | } else { | 558 | } else { |
| 559 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdStruct); | 559 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdStruct); |
| 560 | | 560 | |
| | 561 | // If the child type is []const T then we need to make sure the type ref |
| | 562 | // and debug info is the same as if the child type were []T. |
| | 563 | if (is_slice(child_type)) { |
| | 564 | TypeTableEntry *ptr_type = child_type->data.structure.fields[0].type_entry; |
| | 565 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| | 566 | if (ptr_type->data.pointer.is_const) { |
| | 567 | TypeTableEntry *non_const_child_type = get_slice_type(g, |
| | 568 | ptr_type->data.pointer.child_type, false); |
| | 569 | TypeTableEntry *var_peer = get_slice_type(g, non_const_child_type, false); |
| | 570 | |
| | 571 | entry->type_ref = var_peer->type_ref; |
| | 572 | entry->di_type = var_peer->di_type; |
| | 573 | } |
| | 574 | } |
| | 575 | |
| 561 | buf_resize(&entry->name, 0); | 576 | buf_resize(&entry->name, 0); |
| 562 | buf_appendf(&entry->name, "[]%s", buf_ptr(&child_type->name)); | 577 | buf_appendf(&entry->name, "[]%s", buf_ptr(&child_type->name)); |
| 563 | entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&entry->name)); | | |
| 564 | | | |
| 565 | ZigLLVMDIScope *compile_unit_scope = ZigLLVMCompileUnitToScope(g->compile_unit); | | |
| 566 | ZigLLVMDIFile *di_file = nullptr; | | |
| 567 | unsigned line = 0; | | |
| 568 | entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder, | | |
| 569 | ZigLLVMTag_DW_structure_type(), buf_ptr(&entry->name), | | |
| 570 | compile_unit_scope, di_file, line); | | |
| 571 | | 578 | |
| | 579 | slice_type_common_init(g, child_type, is_const, entry); |
| 572 | if (child_type->zero_bits) { | 580 | if (child_type->zero_bits) { |
| 573 | LLVMTypeRef element_types[] = { | | |
| 574 | g->builtin_types.entry_usize->type_ref, | | |
| 575 | }; | | |
| 576 | LLVMStructSetBody(entry->type_ref, element_types, 1, false); | | |
| 577 | | | |
| 578 | slice_type_common_init(g, child_type, is_const, entry); | | |
| 579 | | | |
| 580 | entry->data.structure.gen_field_count = 1; | 581 | entry->data.structure.gen_field_count = 1; |
| 581 | entry->data.structure.fields[0].gen_index = -1; | 582 | entry->data.structure.fields[0].gen_index = -1; |
| 582 | entry->data.structure.fields[1].gen_index = 0; | 583 | entry->data.structure.fields[1].gen_index = 0; |
| | 584 | } |
| 583 | | 585 | |
| 584 | TypeTableEntry *usize_type = g->builtin_types.entry_usize; | 586 | if (!entry->type_ref) { |
| 585 | uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref); | 587 | entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&entry->name)); |
| 586 | uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, usize_type->type_ref); | | |
| 587 | uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); | | |
| 588 | | | |
| 589 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref); | | |
| 590 | uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, entry->type_ref); | | |
| 591 | | | |
| 592 | ZigLLVMDIType *di_element_types[] = { | | |
| 593 | ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(entry->di_type), | | |
| 594 | "len", di_file, line, | | |
| 595 | len_debug_size_in_bits, | | |
| 596 | len_debug_align_in_bits, | | |
| 597 | len_offset_in_bits, | | |
| 598 | 0, usize_type->di_type), | | |
| 599 | }; | | |
| 600 | ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder, | | |
| 601 | compile_unit_scope, | | |
| 602 | buf_ptr(&entry->name), | | |
| 603 | di_file, line, debug_size_in_bits, debug_align_in_bits, 0, | | |
| 604 | nullptr, di_element_types, 1, 0, nullptr, ""); | | |
| 605 | | | |
| 606 | ZigLLVMReplaceTemporary(g->dbuilder, entry->di_type, replacement_di_type); | | |
| 607 | entry->di_type = replacement_di_type; | | |
| 608 | } else { | | |
| 609 | TypeTableEntry *pointer_type = get_pointer_to_type(g, child_type, is_const); | | |
| 610 | | | |
| 611 | unsigned element_count = 2; | | |
| 612 | LLVMTypeRef element_types[] = { | | |
| 613 | pointer_type->type_ref, | | |
| 614 | g->builtin_types.entry_usize->type_ref, | | |
| 615 | }; | | |
| 616 | LLVMStructSetBody(entry->type_ref, element_types, element_count, false); | | |
| 617 | | | |
| 618 | slice_type_common_init(g, child_type, is_const, entry); | | |
| 619 | | | |
| 620 | | | |
| 621 | uint64_t ptr_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, pointer_type->type_ref); | | |
| 622 | uint64_t ptr_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, pointer_type->type_ref); | | |
| 623 | uint64_t ptr_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); | | |
| 624 | | | |
| 625 | TypeTableEntry *usize_type = g->builtin_types.entry_usize; | | |
| 626 | uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref); | | |
| 627 | uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, usize_type->type_ref); | | |
| 628 | uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1); | | |
| 629 | | | |
| 630 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref); | | |
| 631 | uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, entry->type_ref); | | |
| 632 | | 588 | |
| 633 | ZigLLVMDIType *di_element_types[] = { | 589 | ZigLLVMDIScope *compile_unit_scope = ZigLLVMCompileUnitToScope(g->compile_unit); |
| 634 | ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(entry->di_type), | 590 | ZigLLVMDIFile *di_file = nullptr; |
| 635 | "ptr", di_file, line, | 591 | unsigned line = 0; |
| 636 | ptr_debug_size_in_bits, | 592 | entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder, |
| 637 | ptr_debug_align_in_bits, | 593 | ZigLLVMTag_DW_structure_type(), buf_ptr(&entry->name), |
| 638 | ptr_offset_in_bits, | 594 | compile_unit_scope, di_file, line); |
| 639 | 0, pointer_type->di_type), | | |
| 640 | ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(entry->di_type), | | |
| 641 | "len", di_file, line, | | |
| 642 | len_debug_size_in_bits, | | |
| 643 | len_debug_align_in_bits, | | |
| 644 | len_offset_in_bits, | | |
| 645 | 0, usize_type->di_type), | | |
| 646 | }; | | |
| 647 | ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder, | | |
| 648 | compile_unit_scope, | | |
| 649 | buf_ptr(&entry->name), | | |
| 650 | di_file, line, debug_size_in_bits, debug_align_in_bits, 0, | | |
| 651 | nullptr, di_element_types, 2, 0, nullptr, ""); | | |
| 652 | | 595 | |
| 653 | ZigLLVMReplaceTemporary(g->dbuilder, entry->di_type, replacement_di_type); | 596 | if (child_type->zero_bits) { |
| 654 | entry->di_type = replacement_di_type; | 597 | LLVMTypeRef element_types[] = { |
| | 598 | g->builtin_types.entry_usize->type_ref, |
| | 599 | }; |
| | 600 | LLVMStructSetBody(entry->type_ref, element_types, 1, false); |
| | 601 | |
| | 602 | slice_type_common_init(g, child_type, is_const, entry); |
| | 603 | |
| | 604 | entry->data.structure.gen_field_count = 1; |
| | 605 | entry->data.structure.fields[0].gen_index = -1; |
| | 606 | entry->data.structure.fields[1].gen_index = 0; |
| | 607 | |
| | 608 | TypeTableEntry *usize_type = g->builtin_types.entry_usize; |
| | 609 | uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref); |
| | 610 | uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, usize_type->type_ref); |
| | 611 | uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); |
| | 612 | |
| | 613 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref); |
| | 614 | uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, entry->type_ref); |
| | 615 | |
| | 616 | ZigLLVMDIType *di_element_types[] = { |
| | 617 | ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(entry->di_type), |
| | 618 | "len", di_file, line, |
| | 619 | len_debug_size_in_bits, |
| | 620 | len_debug_align_in_bits, |
| | 621 | len_offset_in_bits, |
| | 622 | 0, usize_type->di_type), |
| | 623 | }; |
| | 624 | ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder, |
| | 625 | compile_unit_scope, |
| | 626 | buf_ptr(&entry->name), |
| | 627 | di_file, line, debug_size_in_bits, debug_align_in_bits, 0, |
| | 628 | nullptr, di_element_types, 1, 0, nullptr, ""); |
| | 629 | |
| | 630 | ZigLLVMReplaceTemporary(g->dbuilder, entry->di_type, replacement_di_type); |
| | 631 | entry->di_type = replacement_di_type; |
| | 632 | } else { |
| | 633 | TypeTableEntry *pointer_type = get_pointer_to_type(g, child_type, is_const); |
| | 634 | |
| | 635 | unsigned element_count = 2; |
| | 636 | LLVMTypeRef element_types[] = { |
| | 637 | pointer_type->type_ref, |
| | 638 | g->builtin_types.entry_usize->type_ref, |
| | 639 | }; |
| | 640 | LLVMStructSetBody(entry->type_ref, element_types, element_count, false); |
| | 641 | |
| | 642 | slice_type_common_init(g, child_type, is_const, entry); |
| | 643 | |
| | 644 | |
| | 645 | uint64_t ptr_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, pointer_type->type_ref); |
| | 646 | uint64_t ptr_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, pointer_type->type_ref); |
| | 647 | uint64_t ptr_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); |
| | 648 | |
| | 649 | TypeTableEntry *usize_type = g->builtin_types.entry_usize; |
| | 650 | uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref); |
| | 651 | uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, usize_type->type_ref); |
| | 652 | uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1); |
| | 653 | |
| | 654 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref); |
| | 655 | uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, entry->type_ref); |
| | 656 | |
| | 657 | ZigLLVMDIType *di_element_types[] = { |
| | 658 | ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(entry->di_type), |
| | 659 | "ptr", di_file, line, |
| | 660 | ptr_debug_size_in_bits, |
| | 661 | ptr_debug_align_in_bits, |
| | 662 | ptr_offset_in_bits, |
| | 663 | 0, pointer_type->di_type), |
| | 664 | ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(entry->di_type), |
| | 665 | "len", di_file, line, |
| | 666 | len_debug_size_in_bits, |
| | 667 | len_debug_align_in_bits, |
| | 668 | len_offset_in_bits, |
| | 669 | 0, usize_type->di_type), |
| | 670 | }; |
| | 671 | ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder, |
| | 672 | compile_unit_scope, |
| | 673 | buf_ptr(&entry->name), |
| | 674 | di_file, line, debug_size_in_bits, debug_align_in_bits, 0, |
| | 675 | nullptr, di_element_types, 2, 0, nullptr, ""); |
| | 676 | |
| | 677 | ZigLLVMReplaceTemporary(g->dbuilder, entry->di_type, replacement_di_type); |
| | 678 | entry->di_type = replacement_di_type; |
| | 679 | } |
| 655 | } | 680 | } |
| 656 | | 681 | |
| 657 | | 682 | |
| ... | @@ -1695,6 +1720,7 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN | ... | @@ -1695,6 +1720,7 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN |
| 1695 | | 1720 | |
| 1696 | bool is_main_fn = !is_generic_instance && | 1721 | bool is_main_fn = !is_generic_instance && |
| 1697 | !parent_decl && (import == g->root_import) && | 1722 | !parent_decl && (import == g->root_import) && |
| | 1723 | !proto_node->data.fn_proto.skip && |
| 1698 | buf_eql_str(proto_name, "main"); | 1724 | buf_eql_str(proto_name, "main"); |
| 1699 | if (is_main_fn) { | 1725 | if (is_main_fn) { |
| 1700 | g->main_fn = fn_table_entry; | 1726 | g->main_fn = fn_table_entry; |