| ... | ... | @@ -8,6 +8,7 @@ const CompilationModule = @import("Module.zig"); |
| 8 | 8 | const File = CompilationModule.File; |
| 9 | 9 | const Module = @import("Package.zig"); |
| 10 | 10 | const Tokenizer = std.zig.Tokenizer; |
| 11 | const InternPool = @import("InternPool.zig"); |
| 11 | 12 | const Zir = @import("Zir.zig"); |
| 12 | 13 | const Ref = Zir.Inst.Ref; |
| 13 | 14 | const log = std.log.scoped(.autodoc); |
| ... | ... | @@ -106,18 +107,20 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 106 | 107 | const file = self.comp_module.import_table.get(abs_root_src_path).?; // file is expected to be present in the import table |
| 107 | 108 | // Append all the types in Zir.Inst.Ref. |
| 108 | 109 | { |
| 109 | | try self.types.append(self.arena, .{ |
| 110 | | .ComptimeExpr = .{ .name = "ComptimeExpr" }, |
| 111 | | }); |
| 112 | | |
| 113 | | // this skips Ref.none but it's ok becuse we replaced it with ComptimeExpr |
| 114 | | var i: u32 = 1; |
| 115 | | while (i <= @enumToInt(Ref.anyerror_void_error_union_type)) : (i += 1) { |
| 110 | comptime std.debug.assert(@enumToInt(InternPool.Index.first_type) == 0); |
| 111 | var i: u32 = 0; |
| 112 | while (i <= @enumToInt(InternPool.Index.last_type)) : (i += 1) { |
| 113 | const ip_index = @intToEnum(InternPool.Index, i); |
| 116 | 114 | var tmpbuf = std.ArrayList(u8).init(self.arena); |
| 117 | | try Ref.typed_value_map[i].val.fmtDebug().format("", .{}, tmpbuf.writer()); |
| 115 | if (ip_index == .generic_poison_type) { |
| 116 | // Not a real type, doesn't have a normal name |
| 117 | try tmpbuf.writer().writeAll("(generic poison)"); |
| 118 | } else { |
| 119 | try ip_index.toType().fmt(self.comp_module).format("", .{}, tmpbuf.writer()); |
| 120 | } |
| 118 | 121 | try self.types.append( |
| 119 | 122 | self.arena, |
| 120 | | switch (@intToEnum(Ref, i)) { |
| 123 | switch (ip_index) { |
| 121 | 124 | else => blk: { |
| 122 | 125 | // TODO: map the remaining refs to a correct type |
| 123 | 126 | // instead of just assinging "array" to them. |
| ... | ... | @@ -1038,7 +1041,7 @@ fn walkInstruction( |
| 1038 | 1041 | .ret_load => { |
| 1039 | 1042 | const un_node = data[inst_index].un_node; |
| 1040 | 1043 | const res_ptr_ref = un_node.operand; |
| 1041 | | const res_ptr_inst = @enumToInt(res_ptr_ref) - Ref.typed_value_map.len; |
| 1044 | const res_ptr_inst = Zir.refToIndex(res_ptr_ref).?; |
| 1042 | 1045 | // TODO: this instruction doesn't let us know trivially if there's |
| 1043 | 1046 | // branching involved or not. For now here's the strat: |
| 1044 | 1047 | // We search backwarts until `ret_ptr` for `store_node`, |
| ... | ... | @@ -2155,11 +2158,10 @@ fn walkInstruction( |
| 2155 | 2158 | const lhs_ref = blk: { |
| 2156 | 2159 | var lhs_extra = extra; |
| 2157 | 2160 | while (true) { |
| 2158 | | if (@enumToInt(lhs_extra.data.lhs) < Ref.typed_value_map.len) { |
| 2161 | const lhs = Zir.refToIndex(lhs_extra.data.lhs) orelse { |
| 2159 | 2162 | break :blk lhs_extra.data.lhs; |
| 2160 | | } |
| 2163 | }; |
| 2161 | 2164 | |
| 2162 | | const lhs = @enumToInt(lhs_extra.data.lhs) - Ref.typed_value_map.len; |
| 2163 | 2165 | if (tags[lhs] != .field_val and |
| 2164 | 2166 | tags[lhs] != .field_ptr and |
| 2165 | 2167 | tags[lhs] != .field_type) break :blk lhs_extra.data.lhs; |
| ... | ... | @@ -2186,8 +2188,7 @@ fn walkInstruction( |
| 2186 | 2188 | // TODO: double check that we really don't need type info here |
| 2187 | 2189 | |
| 2188 | 2190 | const wr = blk: { |
| 2189 | | if (@enumToInt(lhs_ref) >= Ref.typed_value_map.len) { |
| 2190 | | const lhs_inst = @enumToInt(lhs_ref) - Ref.typed_value_map.len; |
| 2191 | if (Zir.refToIndex(lhs_ref)) |lhs_inst| { |
| 2191 | 2192 | if (tags[lhs_inst] == .call or tags[lhs_inst] == .field_call) { |
| 2192 | 2193 | break :blk DocData.WalkResult{ |
| 2193 | 2194 | .expr = .{ |
| ... | ... | @@ -4670,16 +4671,19 @@ fn walkRef( |
| 4670 | 4671 | ref: Ref, |
| 4671 | 4672 | need_type: bool, // true when the caller needs also a typeRef for the return value |
| 4672 | 4673 | ) AutodocErrors!DocData.WalkResult { |
| 4673 | | const enum_value = @enumToInt(ref); |
| 4674 | | if (enum_value <= @enumToInt(Ref.anyerror_void_error_union_type)) { |
| 4674 | if (ref == .none) { |
| 4675 | return .{ .expr = .{ .comptimeExpr = 0 } }; |
| 4676 | } else if (@enumToInt(ref) <= @enumToInt(InternPool.Index.last_type)) { |
| 4675 | 4677 | // We can just return a type that indexes into `types` with the |
| 4676 | 4678 | // enum value because in the beginning we pre-filled `types` with |
| 4677 | 4679 | // the types that are listed in `Ref`. |
| 4678 | 4680 | return DocData.WalkResult{ |
| 4679 | 4681 | .typeRef = .{ .type = @enumToInt(std.builtin.TypeId.Type) }, |
| 4680 | | .expr = .{ .type = enum_value }, |
| 4682 | .expr = .{ .type = @enumToInt(ref) }, |
| 4681 | 4683 | }; |
| 4682 | | } else if (enum_value < Ref.typed_value_map.len) { |
| 4684 | } else if (Zir.refToIndex(ref)) |zir_index| { |
| 4685 | return self.walkInstruction(file, parent_scope, parent_src, zir_index, need_type); |
| 4686 | } else { |
| 4683 | 4687 | switch (ref) { |
| 4684 | 4688 | else => { |
| 4685 | 4689 | panicWithContext( |
| ... | ... | @@ -4772,9 +4776,6 @@ fn walkRef( |
| 4772 | 4776 | // } }; |
| 4773 | 4777 | // }, |
| 4774 | 4778 | } |
| 4775 | | } else { |
| 4776 | | const zir_index = enum_value - Ref.typed_value_map.len; |
| 4777 | | return self.walkInstruction(file, parent_scope, parent_src, zir_index, need_type); |
| 4778 | 4779 | } |
| 4779 | 4780 | } |
| 4780 | 4781 | |