| ... | ... | @@ -1557,7 +1557,7 @@ pub const Inst = struct { |
| 1557 | 1557 | /// 0bX0: whether corresponding decl is exported |
| 1558 | 1558 | /// 4. decl: { // for every decls_len |
| 1559 | 1559 | /// name: u32, // null terminated string index |
| 1560 | | /// value: Ref, |
| 1560 | /// value: Index, |
| 1561 | 1561 | /// } |
| 1562 | 1562 | pub const StructDecl = struct { |
| 1563 | 1563 | body_len: u32, |
| ... | ... | @@ -2044,6 +2044,12 @@ const Writer = struct { |
| 2044 | 2044 | } |
| 2045 | 2045 | |
| 2046 | 2046 | fn writePlNodeBlock(self: *Writer, stream: anytype, inst: Inst.Index) !void { |
| 2047 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| 2048 | try self.writePlNodeBlockWithoutSrc(stream, inst); |
| 2049 | try self.writeSrc(stream, inst_data.src()); |
| 2050 | } |
| 2051 | |
| 2052 | fn writePlNodeBlockWithoutSrc(self: *Writer, stream: anytype, inst: Inst.Index) !void { |
| 2047 | 2053 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| 2048 | 2054 | const extra = self.code.extraData(Inst.Block, inst_data.payload_index); |
| 2049 | 2055 | const body = self.code.extra[extra.end..][0..extra.data.body_len]; |
| ... | ... | @@ -2053,7 +2059,6 @@ const Writer = struct { |
| 2053 | 2059 | self.indent -= 2; |
| 2054 | 2060 | try stream.writeByteNTimes(' ', self.indent); |
| 2055 | 2061 | try stream.writeAll("}) "); |
| 2056 | | try self.writeSrc(stream, inst_data.src()); |
| 2057 | 2062 | } |
| 2058 | 2063 | |
| 2059 | 2064 | fn writePlNodeCondBr(self: *Writer, stream: anytype, inst: Inst.Index) !void { |
| ... | ... | @@ -2083,9 +2088,6 @@ const Writer = struct { |
| 2083 | 2088 | const fields_len = extra.data.fields_len; |
| 2084 | 2089 | const decls_len = extra.data.decls_len; |
| 2085 | 2090 | |
| 2086 | | const prev_parent_decl_node = self.parent_decl_node; |
| 2087 | | self.parent_decl_node = self.relativeToNodeIndex(inst_data.src_node); |
| 2088 | | |
| 2089 | 2091 | var extra_index: usize = undefined; |
| 2090 | 2092 | |
| 2091 | 2093 | if (fields_len == 0) { |
| ... | ... | @@ -2157,11 +2159,11 @@ const Writer = struct { |
| 2157 | 2159 | try stream.writeByteNTimes(' ', self.indent); |
| 2158 | 2160 | try stream.writeAll("}) "); |
| 2159 | 2161 | } |
| 2160 | | self.parent_decl_node = prev_parent_decl_node; |
| 2161 | 2162 | try self.writeSrc(stream, inst_data.src()); |
| 2162 | 2163 | } |
| 2163 | 2164 | |
| 2164 | 2165 | fn writeDecls(self: *Writer, stream: anytype, decls_len: u32, extra_start: usize) !void { |
| 2166 | const parent_decl_node = self.parent_decl_node; |
| 2165 | 2167 | const bit_bags_count = std.math.divCeil(usize, decls_len, 16) catch unreachable; |
| 2166 | 2168 | var extra_index = extra_start + bit_bags_count; |
| 2167 | 2169 | var bit_bag_index: usize = extra_start; |
| ... | ... | @@ -2179,14 +2181,23 @@ const Writer = struct { |
| 2179 | 2181 | |
| 2180 | 2182 | const decl_name = self.code.nullTerminatedString(self.code.extra[extra_index]); |
| 2181 | 2183 | extra_index += 1; |
| 2182 | | const decl_value = @intToEnum(Inst.Ref, self.code.extra[extra_index]); |
| 2184 | const decl_index = self.code.extra[extra_index]; |
| 2183 | 2185 | extra_index += 1; |
| 2184 | 2186 | |
| 2187 | const tag = self.code.instructions.items(.tag)[decl_index]; |
| 2185 | 2188 | const pub_str = if (is_pub) "pub " else ""; |
| 2186 | 2189 | const export_str = if (is_exported) "export " else ""; |
| 2187 | 2190 | try stream.writeByteNTimes(' ', self.indent); |
| 2188 | | try stream.print("{s}{s}{} = ", .{ pub_str, export_str, std.zig.fmtId(decl_name) }); |
| 2189 | | try self.writeInstRef(stream, decl_value); |
| 2191 | try stream.print("{s}{s}{}: %{d} = {s}(", .{ |
| 2192 | pub_str, export_str, std.zig.fmtId(decl_name), decl_index, @tagName(tag), |
| 2193 | }); |
| 2194 | |
| 2195 | const decl_block_inst_data = self.code.instructions.items(.data)[decl_index].pl_node; |
| 2196 | const sub_decl_node_off = decl_block_inst_data.src_node; |
| 2197 | self.parent_decl_node = self.relativeToNodeIndex(sub_decl_node_off); |
| 2198 | try self.writePlNodeBlockWithoutSrc(stream, decl_index); |
| 2199 | self.parent_decl_node = parent_decl_node; |
| 2200 | try self.writeSrc(stream, decl_block_inst_data.src()); |
| 2190 | 2201 | try stream.writeAll("\n"); |
| 2191 | 2202 | } |
| 2192 | 2203 | } |