| ... | ... | @@ -2866,17 +2866,11 @@ const Writer = struct { |
| 2866 | 2866 | .slice_start, |
| 2867 | 2867 | .slice_end, |
| 2868 | 2868 | .slice_sentinel, |
| 2869 | | .struct_init, |
| 2870 | | .struct_init_ref, |
| 2871 | | .struct_init_anon, |
| 2872 | | .struct_init_anon_ref, |
| 2873 | 2869 | .array_init, |
| 2874 | 2870 | .array_init_anon, |
| 2875 | 2871 | .array_init_ref, |
| 2876 | 2872 | .array_init_anon_ref, |
| 2877 | 2873 | .union_init_ptr, |
| 2878 | | .field_type, |
| 2879 | | .field_type_ref, |
| 2880 | 2874 | .cmpxchg_strong, |
| 2881 | 2875 | .cmpxchg_weak, |
| 2882 | 2876 | .shuffle, |
| ... | ... | @@ -2890,6 +2884,17 @@ const Writer = struct { |
| 2890 | 2884 | .builtin_async_call, |
| 2891 | 2885 | => try self.writePlNode(stream, inst), |
| 2892 | 2886 | |
| 2887 | .struct_init, |
| 2888 | .struct_init_ref, |
| 2889 | => try self.writeStructInit(stream, inst), |
| 2890 | |
| 2891 | .struct_init_anon, |
| 2892 | .struct_init_anon_ref, |
| 2893 | => try self.writeStructInitAnon(stream, inst), |
| 2894 | |
| 2895 | .field_type => try self.writeFieldType(stream, inst), |
| 2896 | .field_type_ref => try self.writeFieldTypeRef(stream, inst), |
| 2897 | |
| 2893 | 2898 | .error_set_decl => try self.writePlNodeErrorSetDecl(stream, inst), |
| 2894 | 2899 | |
| 2895 | 2900 | .add, |
| ... | ... | @@ -3240,6 +3245,70 @@ const Writer = struct { |
| 3240 | 3245 | try self.writeSrc(stream, inst_data.src()); |
| 3241 | 3246 | } |
| 3242 | 3247 | |
| 3248 | fn writeStructInit(self: *Writer, stream: anytype, inst: Inst.Index) !void { |
| 3249 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| 3250 | const extra = self.code.extraData(Inst.StructInit, inst_data.payload_index); |
| 3251 | var field_i: u32 = 0; |
| 3252 | var extra_index = extra.end; |
| 3253 | |
| 3254 | while (field_i < extra.data.fields_len) : (field_i += 1) { |
| 3255 | const item = self.code.extraData(Inst.StructInit.Item, extra_index); |
| 3256 | extra_index = item.end; |
| 3257 | |
| 3258 | if (field_i != 0) { |
| 3259 | try stream.writeAll(", ["); |
| 3260 | } else { |
| 3261 | try stream.writeAll("["); |
| 3262 | } |
| 3263 | try self.writeInstIndex(stream, item.data.field_type); |
| 3264 | try stream.writeAll(", "); |
| 3265 | try self.writeInstRef(stream, item.data.init); |
| 3266 | try stream.writeAll("]"); |
| 3267 | } |
| 3268 | try stream.writeAll(") "); |
| 3269 | try self.writeSrc(stream, inst_data.src()); |
| 3270 | } |
| 3271 | |
| 3272 | fn writeStructInitAnon(self: *Writer, stream: anytype, inst: Inst.Index) !void { |
| 3273 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| 3274 | const extra = self.code.extraData(Inst.StructInitAnon, inst_data.payload_index); |
| 3275 | var field_i: u32 = 0; |
| 3276 | var extra_index = extra.end; |
| 3277 | |
| 3278 | while (field_i < extra.data.fields_len) : (field_i += 1) { |
| 3279 | const item = self.code.extraData(Inst.StructInitAnon.Item, extra_index); |
| 3280 | extra_index = item.end; |
| 3281 | |
| 3282 | const field_name = self.code.nullTerminatedString(item.data.field_name); |
| 3283 | |
| 3284 | const prefix = if (field_i != 0) ", [" else "["; |
| 3285 | try stream.print("{s}[{s}=", .{ prefix, field_name }); |
| 3286 | try self.writeInstRef(stream, item.data.init); |
| 3287 | try stream.writeAll("]"); |
| 3288 | } |
| 3289 | try stream.writeAll(") "); |
| 3290 | try self.writeSrc(stream, inst_data.src()); |
| 3291 | } |
| 3292 | |
| 3293 | fn writeFieldType(self: *Writer, stream: anytype, inst: Inst.Index) !void { |
| 3294 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| 3295 | const extra = self.code.extraData(Inst.FieldType, inst_data.payload_index).data; |
| 3296 | try self.writeInstRef(stream, extra.container_type); |
| 3297 | const field_name = self.code.nullTerminatedString(extra.name_start); |
| 3298 | try stream.print(", {s}) ", .{field_name}); |
| 3299 | try self.writeSrc(stream, inst_data.src()); |
| 3300 | } |
| 3301 | |
| 3302 | fn writeFieldTypeRef(self: *Writer, stream: anytype, inst: Inst.Index) !void { |
| 3303 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| 3304 | const extra = self.code.extraData(Inst.FieldTypeRef, inst_data.payload_index).data; |
| 3305 | try self.writeInstRef(stream, extra.container_type); |
| 3306 | try stream.writeAll(", "); |
| 3307 | try self.writeInstRef(stream, extra.field_name); |
| 3308 | try stream.writeAll(") "); |
| 3309 | try self.writeSrc(stream, inst_data.src()); |
| 3310 | } |
| 3311 | |
| 3243 | 3312 | fn writePlNodeErrorSetDecl(self: *Writer, stream: anytype, inst: Inst.Index) !void { |
| 3244 | 3313 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| 3245 | 3314 | const extra = self.code.extraData(Inst.ErrorSetDecl, inst_data.payload_index); |