| ... | ... | @@ -2,18 +2,19 @@ const std = @import("std"); |
| 2 | 2 | const Autodoc = @This(); |
| 3 | 3 | const Compilation = @import("Compilation.zig"); |
| 4 | 4 | const Module = @import("Module.zig"); |
| 5 | const File = Module.File; |
| 5 | 6 | const Zir = @import("Zir.zig"); |
| 6 | 7 | const Ref = Zir.Inst.Ref; |
| 7 | 8 | |
| 8 | 9 | module: *Module, |
| 9 | | doc_location: ?Compilation.EmitLoc, |
| 10 | doc_location: Compilation.EmitLoc, |
| 10 | 11 | arena: std.mem.Allocator, |
| 11 | 12 | types: std.ArrayListUnmanaged(DocData.Type) = .{}, |
| 12 | 13 | decls: std.ArrayListUnmanaged(DocData.Decl) = .{}, |
| 13 | 14 | ast_nodes: std.ArrayListUnmanaged(DocData.AstNode) = .{}, |
| 14 | 15 | |
| 15 | 16 | var arena_allocator: std.heap.ArenaAllocator = undefined; |
| 16 | | pub fn init(m: *Module, doc_location: ?Compilation.EmitLoc) Autodoc { |
| 17 | pub fn init(m: *Module, doc_location: Compilation.EmitLoc) Autodoc { |
| 17 | 18 | arena_allocator = std.heap.ArenaAllocator.init(m.gpa); |
| 18 | 19 | return .{ |
| 19 | 20 | .module = m, |
| ... | ... | @@ -27,11 +28,9 @@ pub fn deinit(_: *Autodoc) void { |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | pub fn generateZirData(self: *Autodoc) !void { |
| 30 | | if (self.doc_location) |loc| { |
| 31 | | if (loc.directory) |dir| { |
| 32 | | if (dir.path) |path| { |
| 33 | | std.debug.print("path: {s}\n", .{path}); |
| 34 | | } |
| 31 | if (self.doc_location.directory) |dir| { |
| 32 | if (dir.path) |path| { |
| 33 | std.debug.print("path: {s}\n", .{path}); |
| 35 | 34 | } |
| 36 | 35 | } |
| 37 | 36 | std.debug.print("basename: {s}\n", .{self.doc_location.basename}); |
| ... | ... | @@ -45,7 +44,7 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 45 | 44 | const root_file_path = self.module.main_pkg.root_src_path; |
| 46 | 45 | const abs_root_path = try std.fs.path.join(self.arena, &.{ dir, root_file_path }); |
| 47 | 46 | defer self.arena.free(abs_root_path); |
| 48 | | const zir = self.module.import_table.get(abs_root_path).?.zir; |
| 47 | const file = self.module.import_table.get(abs_root_path).?; |
| 49 | 48 | |
| 50 | 49 | // append all the types in Zir.Inst.Ref |
| 51 | 50 | { |
| ... | ... | @@ -122,7 +121,7 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 122 | 121 | |
| 123 | 122 | var root_scope: Scope = .{ .parent = null }; |
| 124 | 123 | try self.ast_nodes.append(self.arena, .{ .name = "(root)" }); |
| 125 | | const main_type_index = try self.walkInstruction(zir, &root_scope, Zir.main_struct_inst); |
| 124 | const main_type_index = try self.walkInstruction(file, &root_scope, Zir.main_struct_inst); |
| 126 | 125 | |
| 127 | 126 | var data = DocData{ |
| 128 | 127 | .files = &[1][]const u8{root_file_path}, |
| ... | ... | @@ -467,12 +466,12 @@ const DocData = struct { |
| 467 | 466 | |
| 468 | 467 | fn walkInstruction( |
| 469 | 468 | self: *Autodoc, |
| 470 | | zir: Zir, |
| 469 | file: *File, |
| 471 | 470 | parent_scope: *Scope, |
| 472 | 471 | inst_index: usize, |
| 473 | 472 | ) error{OutOfMemory}!DocData.WalkResult { |
| 474 | | const tags = zir.instructions.items(.tag); |
| 475 | | const data = zir.instructions.items(.data); |
| 473 | const tags = file.zir.instructions.items(.tag); |
| 474 | const data = file.zir.instructions.items(.data); |
| 476 | 475 | |
| 477 | 476 | // We assume that the topmost ast_node entry corresponds to our decl |
| 478 | 477 | const self_ast_node_index = self.ast_nodes.items.len - 1; |
| ... | ... | @@ -484,6 +483,16 @@ fn walkInstruction( |
| 484 | 483 | .{@tagName(tags[inst_index])}, |
| 485 | 484 | ); |
| 486 | 485 | }, |
| 486 | .import => { |
| 487 | const str_tok = data[inst_index].str_tok; |
| 488 | const path = str_tok.get(file.zir); |
| 489 | // importFile cannot error out since all files |
| 490 | // are already loaded at this point |
| 491 | const new_file = self.module.importFile(file, path) catch unreachable; |
| 492 | // TODO: cycles not handled, add file info to outuput |
| 493 | var new_scope = Scope{ .parent = null }; |
| 494 | return self.walkInstruction(new_file.file, &new_scope, Zir.main_struct_inst); |
| 495 | }, |
| 487 | 496 | .int => { |
| 488 | 497 | const int = data[inst_index].int; |
| 489 | 498 | return DocData.WalkResult{ |
| ... | ... | @@ -509,7 +518,7 @@ fn walkInstruction( |
| 509 | 518 | .negate => { |
| 510 | 519 | const un_node = data[inst_index].un_node; |
| 511 | 520 | var operand: DocData.WalkResult = try self.walkRef( |
| 512 | | zir, |
| 521 | file, |
| 513 | 522 | parent_scope, |
| 514 | 523 | un_node.operand, |
| 515 | 524 | ); |
| ... | ... | @@ -518,11 +527,11 @@ fn walkInstruction( |
| 518 | 527 | }, |
| 519 | 528 | .as_node => { |
| 520 | 529 | const pl_node = data[inst_index].pl_node; |
| 521 | | const extra = zir.extraData(Zir.Inst.As, pl_node.payload_index); |
| 522 | | const dest_type_walk = try self.walkRef(zir, parent_scope, extra.data.dest_type); |
| 530 | const extra = file.zir.extraData(Zir.Inst.As, pl_node.payload_index); |
| 531 | const dest_type_walk = try self.walkRef(file, parent_scope, extra.data.dest_type); |
| 523 | 532 | const dest_type_ref = walkResultToTypeRef(dest_type_walk); |
| 524 | 533 | |
| 525 | | var operand = try self.walkRef(zir, parent_scope, extra.data.operand); |
| 534 | var operand = try self.walkRef(file, parent_scope, extra.data.operand); |
| 526 | 535 | |
| 527 | 536 | switch (operand) { |
| 528 | 537 | else => std.debug.panic( |
| ... | ... | @@ -562,20 +571,20 @@ fn walkInstruction( |
| 562 | 571 | }, |
| 563 | 572 | //.block => { |
| 564 | 573 | //const pl_node = data[inst_index].pl_node; |
| 565 | | //const extra = zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 566 | | //const last_instr_index = zir.extra[extra.end..][extra.data.body_len - 1]; |
| 574 | //const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 575 | //const last_instr_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 567 | 576 | //const break_operand = data[break_index].@"break".operand; |
| 568 | | //return self.walkRef(zir, parent_scope, break_operand); |
| 577 | //return self.walkRef(file, parent_scope, break_operand); |
| 569 | 578 | //}, |
| 570 | 579 | .block_inline => { |
| 571 | 580 | const pl_node = data[inst_index].pl_node; |
| 572 | | const extra = zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 573 | | const break_index = zir.extra[extra.end..][extra.data.body_len - 1]; |
| 581 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 582 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 574 | 583 | const break_operand = data[break_index].@"break".operand; |
| 575 | | return self.walkRef(zir, parent_scope, break_operand); |
| 584 | return self.walkRef(file, parent_scope, break_operand); |
| 576 | 585 | }, |
| 577 | 586 | .func => { |
| 578 | | const fn_info = zir.getFnInfo(@intCast(u32, inst_index)); |
| 587 | const fn_info = file.zir.getFnInfo(@intCast(u32, inst_index)); |
| 579 | 588 | |
| 580 | 589 | // TODO: change this to a resize and change the appends accordingly |
| 581 | 590 | try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len); |
| ... | ... | @@ -591,21 +600,21 @@ fn walkInstruction( |
| 591 | 600 | for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| { |
| 592 | 601 | if (tags[param_index] != .param) unreachable; // TODO: handle more param types |
| 593 | 602 | const pl_tok = data[param_index].pl_tok; |
| 594 | | const extra = zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 603 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 595 | 604 | const doc_comment = if (extra.data.doc_comment != 0) |
| 596 | | zir.nullTerminatedString(extra.data.doc_comment) |
| 605 | file.zir.nullTerminatedString(extra.data.doc_comment) |
| 597 | 606 | else |
| 598 | 607 | ""; |
| 599 | 608 | |
| 600 | 609 | param_ast_indexes.appendAssumeCapacity(self.ast_nodes.items.len); |
| 601 | 610 | try self.ast_nodes.append(self.arena, .{ |
| 602 | | .name = zir.nullTerminatedString(extra.data.name), |
| 611 | .name = file.zir.nullTerminatedString(extra.data.name), |
| 603 | 612 | .docs = doc_comment, |
| 604 | 613 | }); |
| 605 | 614 | |
| 606 | | const break_index = zir.extra[extra.end..][extra.data.body_len - 1]; |
| 615 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 607 | 616 | const break_operand = data[break_index].@"break".operand; |
| 608 | | const param_type_ref = try self.walkRef(zir, parent_scope, break_operand); |
| 617 | const param_type_ref = try self.walkRef(file, parent_scope, break_operand); |
| 609 | 618 | |
| 610 | 619 | param_type_refs.appendAssumeCapacity( |
| 611 | 620 | DocData.TypeRef.fromWalkResult(param_type_ref), |
| ... | ... | @@ -616,7 +625,7 @@ fn walkInstruction( |
| 616 | 625 | const ret_type_ref = blk: { |
| 617 | 626 | const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1]; |
| 618 | 627 | const break_operand = data[last_instr_index].@"break".operand; |
| 619 | | const wr = try self.walkRef(zir, parent_scope, break_operand); |
| 628 | const wr = try self.walkRef(file, parent_scope, break_operand); |
| 620 | 629 | break :blk DocData.TypeRef.fromWalkResult(wr); |
| 621 | 630 | }; |
| 622 | 631 | |
| ... | ... | @@ -647,34 +656,34 @@ fn walkInstruction( |
| 647 | 656 | var extra_index: usize = extended.operand; |
| 648 | 657 | |
| 649 | 658 | const src_node: ?i32 = if (small.has_src_node) blk: { |
| 650 | | const src_node = @bitCast(i32, zir.extra[extra_index]); |
| 659 | const src_node = @bitCast(i32, file.zir.extra[extra_index]); |
| 651 | 660 | extra_index += 1; |
| 652 | 661 | break :blk src_node; |
| 653 | 662 | } else null; |
| 654 | 663 | _ = src_node; |
| 655 | 664 | |
| 656 | 665 | const tag_type: ?Ref = if (small.has_tag_type) blk: { |
| 657 | | const tag_type = zir.extra[extra_index]; |
| 666 | const tag_type = file.zir.extra[extra_index]; |
| 658 | 667 | extra_index += 1; |
| 659 | 668 | break :blk @intToEnum(Ref, tag_type); |
| 660 | 669 | } else null; |
| 661 | 670 | _ = tag_type; |
| 662 | 671 | |
| 663 | 672 | const body_len = if (small.has_body_len) blk: { |
| 664 | | const body_len = zir.extra[extra_index]; |
| 673 | const body_len = file.zir.extra[extra_index]; |
| 665 | 674 | extra_index += 1; |
| 666 | 675 | break :blk body_len; |
| 667 | 676 | } else 0; |
| 668 | 677 | |
| 669 | 678 | const fields_len = if (small.has_fields_len) blk: { |
| 670 | | const fields_len = zir.extra[extra_index]; |
| 679 | const fields_len = file.zir.extra[extra_index]; |
| 671 | 680 | extra_index += 1; |
| 672 | 681 | break :blk fields_len; |
| 673 | 682 | } else 0; |
| 674 | 683 | _ = fields_len; |
| 675 | 684 | |
| 676 | 685 | const decls_len = if (small.has_decls_len) blk: { |
| 677 | | const decls_len = zir.extra[extra_index]; |
| 686 | const decls_len = file.zir.extra[extra_index]; |
| 678 | 687 | extra_index += 1; |
| 679 | 688 | break :blk decls_len; |
| 680 | 689 | } else 0; |
| ... | ... | @@ -687,17 +696,17 @@ fn walkInstruction( |
| 687 | 696 | // Done to make sure that all decl refs can be resolved correctly, |
| 688 | 697 | // even if we haven't fully analyzed the decl yet. |
| 689 | 698 | { |
| 690 | | var it = zir.declIterator(@intCast(u32, inst_index)); |
| 699 | var it = file.zir.declIterator(@intCast(u32, inst_index)); |
| 691 | 700 | try self.decls.resize(self.arena, decls_first_index + it.decls_len); |
| 692 | 701 | var decls_slot_index = decls_first_index; |
| 693 | 702 | while (it.next()) |d| : (decls_slot_index += 1) { |
| 694 | | const decl_name_index = zir.extra[d.sub_index + 5]; |
| 703 | const decl_name_index = file.zir.extra[d.sub_index + 5]; |
| 695 | 704 | try scope.insertDeclRef(self.arena, decl_name_index, decls_slot_index); |
| 696 | 705 | } |
| 697 | 706 | } |
| 698 | 707 | |
| 699 | 708 | extra_index = try self.walkDecls( |
| 700 | | zir, |
| 709 | file, |
| 701 | 710 | &scope, |
| 702 | 711 | decls_first_index, |
| 703 | 712 | decls_len, |
| ... | ... | @@ -706,7 +715,7 @@ fn walkInstruction( |
| 706 | 715 | extra_index, |
| 707 | 716 | ); |
| 708 | 717 | |
| 709 | | // const body = zir.extra[extra_index..][0..body_len]; |
| 718 | // const body = file.zir.extra[extra_index..][0..body_len]; |
| 710 | 719 | extra_index += body_len; |
| 711 | 720 | |
| 712 | 721 | var field_type_refs = try std.ArrayListUnmanaged(DocData.TypeRef).initCapacity( |
| ... | ... | @@ -718,7 +727,7 @@ fn walkInstruction( |
| 718 | 727 | fields_len, |
| 719 | 728 | ); |
| 720 | 729 | try self.collectUnionFieldInfo( |
| 721 | | zir, |
| 730 | file, |
| 722 | 731 | &scope, |
| 723 | 732 | fields_len, |
| 724 | 733 | &field_type_refs, |
| ... | ... | @@ -747,34 +756,34 @@ fn walkInstruction( |
| 747 | 756 | var extra_index: usize = extended.operand; |
| 748 | 757 | |
| 749 | 758 | const src_node: ?i32 = if (small.has_src_node) blk: { |
| 750 | | const src_node = @bitCast(i32, zir.extra[extra_index]); |
| 759 | const src_node = @bitCast(i32, file.zir.extra[extra_index]); |
| 751 | 760 | extra_index += 1; |
| 752 | 761 | break :blk src_node; |
| 753 | 762 | } else null; |
| 754 | 763 | _ = src_node; |
| 755 | 764 | |
| 756 | 765 | const tag_type: ?Ref = if (small.has_tag_type) blk: { |
| 757 | | const tag_type = zir.extra[extra_index]; |
| 766 | const tag_type = file.zir.extra[extra_index]; |
| 758 | 767 | extra_index += 1; |
| 759 | 768 | break :blk @intToEnum(Ref, tag_type); |
| 760 | 769 | } else null; |
| 761 | 770 | _ = tag_type; |
| 762 | 771 | |
| 763 | 772 | const body_len = if (small.has_body_len) blk: { |
| 764 | | const body_len = zir.extra[extra_index]; |
| 773 | const body_len = file.zir.extra[extra_index]; |
| 765 | 774 | extra_index += 1; |
| 766 | 775 | break :blk body_len; |
| 767 | 776 | } else 0; |
| 768 | 777 | |
| 769 | 778 | const fields_len = if (small.has_fields_len) blk: { |
| 770 | | const fields_len = zir.extra[extra_index]; |
| 779 | const fields_len = file.zir.extra[extra_index]; |
| 771 | 780 | extra_index += 1; |
| 772 | 781 | break :blk fields_len; |
| 773 | 782 | } else 0; |
| 774 | 783 | _ = fields_len; |
| 775 | 784 | |
| 776 | 785 | const decls_len = if (small.has_decls_len) blk: { |
| 777 | | const decls_len = zir.extra[extra_index]; |
| 786 | const decls_len = file.zir.extra[extra_index]; |
| 778 | 787 | extra_index += 1; |
| 779 | 788 | break :blk decls_len; |
| 780 | 789 | } else 0; |
| ... | ... | @@ -787,17 +796,17 @@ fn walkInstruction( |
| 787 | 796 | // Done to make sure that all decl refs can be resolved correctly, |
| 788 | 797 | // even if we haven't fully analyzed the decl yet. |
| 789 | 798 | { |
| 790 | | var it = zir.declIterator(@intCast(u32, inst_index)); |
| 799 | var it = file.zir.declIterator(@intCast(u32, inst_index)); |
| 791 | 800 | try self.decls.resize(self.arena, decls_first_index + it.decls_len); |
| 792 | 801 | var decls_slot_index = decls_first_index; |
| 793 | 802 | while (it.next()) |d| : (decls_slot_index += 1) { |
| 794 | | const decl_name_index = zir.extra[d.sub_index + 5]; |
| 803 | const decl_name_index = file.zir.extra[d.sub_index + 5]; |
| 795 | 804 | try scope.insertDeclRef(self.arena, decl_name_index, decls_slot_index); |
| 796 | 805 | } |
| 797 | 806 | } |
| 798 | 807 | |
| 799 | 808 | extra_index = try self.walkDecls( |
| 800 | | zir, |
| 809 | file, |
| 801 | 810 | &scope, |
| 802 | 811 | decls_first_index, |
| 803 | 812 | decls_len, |
| ... | ... | @@ -806,7 +815,7 @@ fn walkInstruction( |
| 806 | 815 | extra_index, |
| 807 | 816 | ); |
| 808 | 817 | |
| 809 | | // const body = zir.extra[extra_index..][0..body_len]; |
| 818 | // const body = file.zir.extra[extra_index..][0..body_len]; |
| 810 | 819 | extra_index += body_len; |
| 811 | 820 | |
| 812 | 821 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; |
| ... | ... | @@ -818,31 +827,31 @@ fn walkInstruction( |
| 818 | 827 | var idx: usize = 0; |
| 819 | 828 | while (idx < fields_len) : (idx += 1) { |
| 820 | 829 | if (idx % 32 == 0) { |
| 821 | | cur_bit_bag = zir.extra[bit_bag_idx]; |
| 830 | cur_bit_bag = file.zir.extra[bit_bag_idx]; |
| 822 | 831 | bit_bag_idx += 1; |
| 823 | 832 | } |
| 824 | 833 | |
| 825 | 834 | const has_value = @truncate(u1, cur_bit_bag) != 0; |
| 826 | 835 | cur_bit_bag >>= 1; |
| 827 | 836 | |
| 828 | | const field_name_index = zir.extra[extra_index]; |
| 837 | const field_name_index = file.zir.extra[extra_index]; |
| 829 | 838 | extra_index += 1; |
| 830 | 839 | |
| 831 | | const doc_comment_index = zir.extra[extra_index]; |
| 840 | const doc_comment_index = file.zir.extra[extra_index]; |
| 832 | 841 | extra_index += 1; |
| 833 | 842 | |
| 834 | 843 | const value_ref: ?Ref = if (has_value) blk: { |
| 835 | | const value_ref = zir.extra[extra_index]; |
| 844 | const value_ref = file.zir.extra[extra_index]; |
| 836 | 845 | extra_index += 1; |
| 837 | 846 | break :blk @intToEnum(Ref, value_ref); |
| 838 | 847 | } else null; |
| 839 | 848 | _ = value_ref; |
| 840 | 849 | |
| 841 | | const field_name = zir.nullTerminatedString(field_name_index); |
| 850 | const field_name = file.zir.nullTerminatedString(field_name_index); |
| 842 | 851 | |
| 843 | 852 | try field_name_indexes.append(self.arena, self.ast_nodes.items.len); |
| 844 | 853 | const doc_comment: ?[]const u8 = if (doc_comment_index != 0) |
| 845 | | zir.nullTerminatedString(doc_comment_index) |
| 854 | file.zir.nullTerminatedString(doc_comment_index) |
| 846 | 855 | else |
| 847 | 856 | null; |
| 848 | 857 | try self.ast_nodes.append(self.arena, .{ |
| ... | ... | @@ -872,27 +881,27 @@ fn walkInstruction( |
| 872 | 881 | var extra_index: usize = extended.operand; |
| 873 | 882 | |
| 874 | 883 | const src_node: ?i32 = if (small.has_src_node) blk: { |
| 875 | | const src_node = @bitCast(i32, zir.extra[extra_index]); |
| 884 | const src_node = @bitCast(i32, file.zir.extra[extra_index]); |
| 876 | 885 | extra_index += 1; |
| 877 | 886 | break :blk src_node; |
| 878 | 887 | } else null; |
| 879 | 888 | _ = src_node; |
| 880 | 889 | |
| 881 | 890 | const body_len = if (small.has_body_len) blk: { |
| 882 | | const body_len = zir.extra[extra_index]; |
| 891 | const body_len = file.zir.extra[extra_index]; |
| 883 | 892 | extra_index += 1; |
| 884 | 893 | break :blk body_len; |
| 885 | 894 | } else 0; |
| 886 | 895 | |
| 887 | 896 | const fields_len = if (small.has_fields_len) blk: { |
| 888 | | const fields_len = zir.extra[extra_index]; |
| 897 | const fields_len = file.zir.extra[extra_index]; |
| 889 | 898 | extra_index += 1; |
| 890 | 899 | break :blk fields_len; |
| 891 | 900 | } else 0; |
| 892 | 901 | _ = fields_len; |
| 893 | 902 | |
| 894 | 903 | const decls_len = if (small.has_decls_len) blk: { |
| 895 | | const decls_len = zir.extra[extra_index]; |
| 904 | const decls_len = file.zir.extra[extra_index]; |
| 896 | 905 | extra_index += 1; |
| 897 | 906 | break :blk decls_len; |
| 898 | 907 | } else 0; |
| ... | ... | @@ -905,17 +914,17 @@ fn walkInstruction( |
| 905 | 914 | // Done to make sure that all decl refs can be resolved correctly, |
| 906 | 915 | // even if we haven't fully analyzed the decl yet. |
| 907 | 916 | { |
| 908 | | var it = zir.declIterator(@intCast(u32, inst_index)); |
| 917 | var it = file.zir.declIterator(@intCast(u32, inst_index)); |
| 909 | 918 | try self.decls.resize(self.arena, decls_first_index + it.decls_len); |
| 910 | 919 | var decls_slot_index = decls_first_index; |
| 911 | 920 | while (it.next()) |d| : (decls_slot_index += 1) { |
| 912 | | const decl_name_index = zir.extra[d.sub_index + 5]; |
| 921 | const decl_name_index = file.zir.extra[d.sub_index + 5]; |
| 913 | 922 | try scope.insertDeclRef(self.arena, decl_name_index, decls_slot_index); |
| 914 | 923 | } |
| 915 | 924 | } |
| 916 | 925 | |
| 917 | 926 | extra_index = try self.walkDecls( |
| 918 | | zir, |
| 927 | file, |
| 919 | 928 | &scope, |
| 920 | 929 | decls_first_index, |
| 921 | 930 | decls_len, |
| ... | ... | @@ -924,13 +933,13 @@ fn walkInstruction( |
| 924 | 933 | extra_index, |
| 925 | 934 | ); |
| 926 | 935 | |
| 927 | | // const body = zir.extra[extra_index..][0..body_len]; |
| 936 | // const body = file.zir.extra[extra_index..][0..body_len]; |
| 928 | 937 | extra_index += body_len; |
| 929 | 938 | |
| 930 | 939 | var field_type_refs: std.ArrayListUnmanaged(DocData.TypeRef) = .{}; |
| 931 | 940 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; |
| 932 | 941 | try self.collectStructFieldInfo( |
| 933 | | zir, |
| 942 | file, |
| 934 | 943 | &scope, |
| 935 | 944 | fields_len, |
| 936 | 945 | &field_type_refs, |
| ... | ... | @@ -966,7 +975,7 @@ fn walkInstruction( |
| 966 | 975 | /// slots in `self.decls`, which are then filled out by `walkDecls`. |
| 967 | 976 | fn walkDecls( |
| 968 | 977 | self: *Autodoc, |
| 969 | | zir: Zir, |
| 978 | file: *File, |
| 970 | 979 | scope: *Scope, |
| 971 | 980 | decls_first_index: usize, |
| 972 | 981 | decls_len: u32, |
| ... | ... | @@ -984,7 +993,7 @@ fn walkDecls( |
| 984 | 993 | const decls_slot_index = decls_first_index + decl_i; |
| 985 | 994 | |
| 986 | 995 | if (decl_i % 8 == 0) { |
| 987 | | cur_bit_bag = zir.extra[bit_bag_index]; |
| 996 | cur_bit_bag = file.zir.extra[bit_bag_index]; |
| 988 | 997 | bit_bag_index += 1; |
| 989 | 998 | } |
| 990 | 999 | const is_pub = @truncate(u1, cur_bit_bag) != 0; |
| ... | ... | @@ -998,29 +1007,29 @@ fn walkDecls( |
| 998 | 1007 | |
| 999 | 1008 | // const sub_index = extra_index; |
| 1000 | 1009 | |
| 1001 | | // const hash_u32s = zir.extra[extra_index..][0..4]; |
| 1010 | // const hash_u32s = file.zir.extra[extra_index..][0..4]; |
| 1002 | 1011 | extra_index += 4; |
| 1003 | | // const line = zir.extra[extra_index]; |
| 1012 | // const line = file.zir.extra[extra_index]; |
| 1004 | 1013 | extra_index += 1; |
| 1005 | | const decl_name_index = zir.extra[extra_index]; |
| 1014 | const decl_name_index = file.zir.extra[extra_index]; |
| 1006 | 1015 | extra_index += 1; |
| 1007 | | const decl_index = zir.extra[extra_index]; |
| 1016 | const decl_index = file.zir.extra[extra_index]; |
| 1008 | 1017 | extra_index += 1; |
| 1009 | | const doc_comment_index = zir.extra[extra_index]; |
| 1018 | const doc_comment_index = file.zir.extra[extra_index]; |
| 1010 | 1019 | extra_index += 1; |
| 1011 | 1020 | |
| 1012 | 1021 | // const align_inst: Zir.Inst.Ref = if (!has_align) .none else inst: { |
| 1013 | | // const inst = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]); |
| 1022 | // const inst = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 1014 | 1023 | // extra_index += 1; |
| 1015 | 1024 | // break :inst inst; |
| 1016 | 1025 | // }; |
| 1017 | 1026 | // const section_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: { |
| 1018 | | // const inst = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]); |
| 1027 | // const inst = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 1019 | 1028 | // extra_index += 1; |
| 1020 | 1029 | // break :inst inst; |
| 1021 | 1030 | // }; |
| 1022 | 1031 | // const addrspace_inst: Zir.Inst.Ref = if (!has_section_or_addrspace) .none else inst: { |
| 1023 | | // const inst = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]); |
| 1032 | // const inst = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 1024 | 1033 | // extra_index += 1; |
| 1025 | 1034 | // break :inst inst; |
| 1026 | 1035 | // }; |
| ... | ... | @@ -1034,9 +1043,9 @@ fn walkDecls( |
| 1034 | 1043 | } else if (decl_name_index == 1) { |
| 1035 | 1044 | break :blk "test"; |
| 1036 | 1045 | } else { |
| 1037 | | const raw_decl_name = zir.nullTerminatedString(decl_name_index); |
| 1046 | const raw_decl_name = file.zir.nullTerminatedString(decl_name_index); |
| 1038 | 1047 | if (raw_decl_name.len == 0) { |
| 1039 | | break :blk zir.nullTerminatedString(decl_name_index + 1); |
| 1048 | break :blk file.zir.nullTerminatedString(decl_name_index + 1); |
| 1040 | 1049 | } else { |
| 1041 | 1050 | break :blk raw_decl_name; |
| 1042 | 1051 | } |
| ... | ... | @@ -1044,7 +1053,7 @@ fn walkDecls( |
| 1044 | 1053 | }; |
| 1045 | 1054 | |
| 1046 | 1055 | const doc_comment: ?[]const u8 = if (doc_comment_index != 0) |
| 1047 | | zir.nullTerminatedString(doc_comment_index) |
| 1056 | file.zir.nullTerminatedString(doc_comment_index) |
| 1048 | 1057 | else |
| 1049 | 1058 | null; |
| 1050 | 1059 | |
| ... | ... | @@ -1061,7 +1070,7 @@ fn walkDecls( |
| 1061 | 1070 | break :idx idx; |
| 1062 | 1071 | }; |
| 1063 | 1072 | |
| 1064 | | const walk_result = try self.walkInstruction(zir, scope, decl_index); |
| 1073 | const walk_result = try self.walkInstruction(file, scope, decl_index); |
| 1065 | 1074 | |
| 1066 | 1075 | if (is_pub) { |
| 1067 | 1076 | try decl_indexes.append(self.arena, decls_slot_index); |
| ... | ... | @@ -1098,7 +1107,7 @@ fn walkDecls( |
| 1098 | 1107 | |
| 1099 | 1108 | fn collectUnionFieldInfo( |
| 1100 | 1109 | self: *Autodoc, |
| 1101 | | zir: Zir, |
| 1110 | file: *File, |
| 1102 | 1111 | scope: *Scope, |
| 1103 | 1112 | fields_len: usize, |
| 1104 | 1113 | field_type_refs: *std.ArrayListUnmanaged(DocData.TypeRef), |
| ... | ... | @@ -1118,7 +1127,7 @@ fn collectUnionFieldInfo( |
| 1118 | 1127 | var field_i: u32 = 0; |
| 1119 | 1128 | while (field_i < fields_len) : (field_i += 1) { |
| 1120 | 1129 | if (field_i % fields_per_u32 == 0) { |
| 1121 | | cur_bit_bag = zir.extra[bit_bag_index]; |
| 1130 | cur_bit_bag = file.zir.extra[bit_bag_index]; |
| 1122 | 1131 | bit_bag_index += 1; |
| 1123 | 1132 | } |
| 1124 | 1133 | const has_type = @truncate(u1, cur_bit_bag) != 0; |
| ... | ... | @@ -1131,12 +1140,12 @@ fn collectUnionFieldInfo( |
| 1131 | 1140 | cur_bit_bag >>= 1; |
| 1132 | 1141 | _ = unused; |
| 1133 | 1142 | |
| 1134 | | const field_name = zir.nullTerminatedString(zir.extra[extra_index]); |
| 1143 | const field_name = file.zir.nullTerminatedString(file.zir.extra[extra_index]); |
| 1135 | 1144 | extra_index += 1; |
| 1136 | | const doc_comment_index = zir.extra[extra_index]; |
| 1145 | const doc_comment_index = file.zir.extra[extra_index]; |
| 1137 | 1146 | extra_index += 1; |
| 1138 | 1147 | const field_type = if (has_type) |
| 1139 | | @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]) |
| 1148 | @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]) |
| 1140 | 1149 | else |
| 1141 | 1150 | .void_type; |
| 1142 | 1151 | extra_index += 1; |
| ... | ... | @@ -1146,7 +1155,7 @@ fn collectUnionFieldInfo( |
| 1146 | 1155 | |
| 1147 | 1156 | // type |
| 1148 | 1157 | { |
| 1149 | | const walk_result = try self.walkRef(zir, scope, field_type); |
| 1158 | const walk_result = try self.walkRef(file, scope, field_type); |
| 1150 | 1159 | try field_type_refs.append( |
| 1151 | 1160 | self.arena, |
| 1152 | 1161 | walkResultToTypeRef(walk_result), |
| ... | ... | @@ -1157,7 +1166,7 @@ fn collectUnionFieldInfo( |
| 1157 | 1166 | { |
| 1158 | 1167 | try field_name_indexes.append(self.arena, self.ast_nodes.items.len); |
| 1159 | 1168 | const doc_comment: ?[]const u8 = if (doc_comment_index != 0) |
| 1160 | | zir.nullTerminatedString(doc_comment_index) |
| 1169 | file.zir.nullTerminatedString(doc_comment_index) |
| 1161 | 1170 | else |
| 1162 | 1171 | null; |
| 1163 | 1172 | try self.ast_nodes.append(self.arena, .{ |
| ... | ... | @@ -1170,7 +1179,7 @@ fn collectUnionFieldInfo( |
| 1170 | 1179 | |
| 1171 | 1180 | fn collectStructFieldInfo( |
| 1172 | 1181 | self: *Autodoc, |
| 1173 | | zir: Zir, |
| 1182 | file: *File, |
| 1174 | 1183 | scope: *Scope, |
| 1175 | 1184 | fields_len: usize, |
| 1176 | 1185 | field_type_refs: *std.ArrayListUnmanaged(DocData.TypeRef), |
| ... | ... | @@ -1190,7 +1199,7 @@ fn collectStructFieldInfo( |
| 1190 | 1199 | var field_i: u32 = 0; |
| 1191 | 1200 | while (field_i < fields_len) : (field_i += 1) { |
| 1192 | 1201 | if (field_i % fields_per_u32 == 0) { |
| 1193 | | cur_bit_bag = zir.extra[bit_bag_index]; |
| 1202 | cur_bit_bag = file.zir.extra[bit_bag_index]; |
| 1194 | 1203 | bit_bag_index += 1; |
| 1195 | 1204 | } |
| 1196 | 1205 | const has_align = @truncate(u1, cur_bit_bag) != 0; |
| ... | ... | @@ -1203,11 +1212,11 @@ fn collectStructFieldInfo( |
| 1203 | 1212 | cur_bit_bag >>= 1; |
| 1204 | 1213 | _ = unused; |
| 1205 | 1214 | |
| 1206 | | const field_name = zir.nullTerminatedString(zir.extra[extra_index]); |
| 1215 | const field_name = file.zir.nullTerminatedString(file.zir.extra[extra_index]); |
| 1207 | 1216 | extra_index += 1; |
| 1208 | | const field_type = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]); |
| 1217 | const field_type = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 1209 | 1218 | extra_index += 1; |
| 1210 | | const doc_comment_index = zir.extra[extra_index]; |
| 1219 | const doc_comment_index = file.zir.extra[extra_index]; |
| 1211 | 1220 | extra_index += 1; |
| 1212 | 1221 | |
| 1213 | 1222 | if (has_align) extra_index += 1; |
| ... | ... | @@ -1215,7 +1224,7 @@ fn collectStructFieldInfo( |
| 1215 | 1224 | |
| 1216 | 1225 | // type |
| 1217 | 1226 | { |
| 1218 | | const walk_result = try self.walkRef(zir, scope, field_type); |
| 1227 | const walk_result = try self.walkRef(file, scope, field_type); |
| 1219 | 1228 | try field_type_refs.append( |
| 1220 | 1229 | self.arena, |
| 1221 | 1230 | walkResultToTypeRef(walk_result), |
| ... | ... | @@ -1226,7 +1235,7 @@ fn collectStructFieldInfo( |
| 1226 | 1235 | { |
| 1227 | 1236 | try field_name_indexes.append(self.arena, self.ast_nodes.items.len); |
| 1228 | 1237 | const doc_comment: ?[]const u8 = if (doc_comment_index != 0) |
| 1229 | | zir.nullTerminatedString(doc_comment_index) |
| 1238 | file.zir.nullTerminatedString(doc_comment_index) |
| 1230 | 1239 | else |
| 1231 | 1240 | null; |
| 1232 | 1241 | try self.ast_nodes.append(self.arena, .{ |
| ... | ... | @@ -1239,7 +1248,7 @@ fn collectStructFieldInfo( |
| 1239 | 1248 | |
| 1240 | 1249 | fn walkRef( |
| 1241 | 1250 | self: *Autodoc, |
| 1242 | | zir: Zir, |
| 1251 | file: *File, |
| 1243 | 1252 | parent_scope: *Scope, |
| 1244 | 1253 | ref: Ref, |
| 1245 | 1254 | ) !DocData.WalkResult { |
| ... | ... | @@ -1327,7 +1336,7 @@ fn walkRef( |
| 1327 | 1336 | } |
| 1328 | 1337 | } else { |
| 1329 | 1338 | const zir_index = enum_value - Ref.typed_value_map.len; |
| 1330 | | return self.walkInstruction(zir, parent_scope, zir_index); |
| 1339 | return self.walkInstruction(file, parent_scope, zir_index); |
| 1331 | 1340 | } |
| 1332 | 1341 | } |
| 1333 | 1342 | |
| ... | ... | @@ -1343,6 +1352,6 @@ fn walkResultToTypeRef(wr: DocData.WalkResult) DocData.TypeRef { |
| 1343 | 1352 | }; |
| 1344 | 1353 | } |
| 1345 | 1354 | |
| 1346 | | //fn collectParamInfo(self: *Autodoc, zir: Zir, scope: *Scope, inst_idx: Zir.Index) void { |
| 1355 | //fn collectParamInfo(self: *Autodoc, file: *File, scope: *Scope, inst_idx: Zir.Index) void { |
| 1347 | 1356 | |
| 1348 | 1357 | //} |