| ... | @@ -261,23 +261,15 @@ const Writer = struct { | ... | @@ -261,23 +261,15 @@ const Writer = struct { |
| 261 | => try self.writeBreak(stream, inst), | 261 | => try self.writeBreak(stream, inst), |
| 262 | .array_init, | 262 | .array_init, |
| 263 | .array_init_ref, | 263 | .array_init_ref, |
| 264 | => try self.writeArrayInit(stream, inst), | | |
| 265 | | | |
| 266 | .elem_ptr_node, | | |
| 267 | .elem_val_node, | | |
| 268 | .slice_start, | | |
| 269 | .slice_end, | | |
| 270 | .slice_sentinel, | | |
| 271 | .array_init_anon, | 264 | .array_init_anon, |
| 272 | .array_init_anon_ref, | 265 | .array_init_anon_ref, |
| 273 | .union_init_ptr, | 266 | => try self.writeArrayInit(stream, inst), |
| 274 | .shuffle, | 267 | |
| 275 | .select, | 268 | .slice_start => try self.writeSliceStart(stream, inst), |
| 276 | .mul_add, | 269 | .slice_end => try self.writeSliceEnd(stream, inst), |
| 277 | .builtin_call, | 270 | .slice_sentinel => try self.writeSliceSentinel(stream, inst), |
| 278 | .field_parent_ptr, | 271 | |
| 279 | .builtin_async_call, | 272 | .union_init_ptr => try self.writeUnionInitPtr(stream, inst), |
| 280 | => try self.writePlNode(stream, inst), | | |
| 281 | | 273 | |
| 282 | .struct_init, | 274 | .struct_init, |
| 283 | .struct_init_ref, | 275 | .struct_init_ref, |
| ... | @@ -288,6 +280,12 @@ const Writer = struct { | ... | @@ -288,6 +280,12 @@ const Writer = struct { |
| 288 | .atomic_rmw => try self.writeAtomicRmw(stream, inst), | 280 | .atomic_rmw => try self.writeAtomicRmw(stream, inst), |
| 289 | .memcpy => try self.writeMemcpy(stream, inst), | 281 | .memcpy => try self.writeMemcpy(stream, inst), |
| 290 | .memset => try self.writeMemset(stream, inst), | 282 | .memset => try self.writeMemset(stream, inst), |
| | 283 | .shuffle => try self.writeShuffle(stream, inst), |
| | 284 | .select => try self.writeSelect(stream, inst), |
| | 285 | .mul_add => try self.writeMulAdd(stream, inst), |
| | 286 | .field_parent_ptr => try self.writeFieldParentPtr(stream, inst), |
| | 287 | .builtin_call => try self.writeBuiltinCall(stream, inst), |
| | 288 | .builtin_async_call => try self.writeBuiltinAsyncCall(stream, inst), |
| 291 | | 289 | |
| 292 | .struct_init_anon, | 290 | .struct_init_anon, |
| 293 | .struct_init_anon_ref, | 291 | .struct_init_anon_ref, |
| ... | @@ -353,6 +351,8 @@ const Writer = struct { | ... | @@ -353,6 +351,8 @@ const Writer = struct { |
| 353 | .vector_type, | 351 | .vector_type, |
| 354 | .maximum, | 352 | .maximum, |
| 355 | .minimum, | 353 | .minimum, |
| | 354 | .elem_ptr_node, |
| | 355 | .elem_val_node, |
| 356 | => try self.writePlNodeBin(stream, inst), | 356 | => try self.writePlNodeBin(stream, inst), |
| 357 | | 357 | |
| 358 | .@"export" => try self.writePlNodeExport(stream, inst), | 358 | .@"export" => try self.writePlNodeExport(stream, inst), |
| ... | @@ -479,24 +479,23 @@ const Writer = struct { | ... | @@ -479,24 +479,23 @@ const Writer = struct { |
| 479 | .enum_decl => try self.writeEnumDecl(stream, extended), | 479 | .enum_decl => try self.writeEnumDecl(stream, extended), |
| 480 | .opaque_decl => try self.writeOpaqueDecl(stream, extended), | 480 | .opaque_decl => try self.writeOpaqueDecl(stream, extended), |
| 481 | | 481 | |
| 482 | .c_undef, .c_include => { | 482 | .c_undef, .c_include, .wasm_memory_size => { |
| 483 | const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 483 | const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| | 484 | const src: LazySrcLoc = .{ .node_offset = inst_data.node }; |
| 484 | try self.writeInstRef(stream, inst_data.operand); | 485 | try self.writeInstRef(stream, inst_data.operand); |
| 485 | try stream.writeAll(") "); | 486 | try stream.writeAll(")) "); |
| | 487 | try self.writeSrc(stream, src); |
| 486 | }, | 488 | }, |
| 487 | | 489 | |
| 488 | .c_define => { | 490 | .builtin_extern, .c_define, .wasm_memory_grow => { |
| 489 | const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 491 | const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| | 492 | const src: LazySrcLoc = .{ .node_offset = inst_data.node }; |
| 490 | try self.writeInstRef(stream, inst_data.lhs); | 493 | try self.writeInstRef(stream, inst_data.lhs); |
| 491 | try stream.writeAll(", "); | 494 | try stream.writeAll(", "); |
| 492 | try self.writeInstRef(stream, inst_data.rhs); | 495 | try self.writeInstRef(stream, inst_data.rhs); |
| 493 | try stream.writeByte(')'); | 496 | try stream.writeAll(")) "); |
| | 497 | try self.writeSrc(stream, src); |
| 494 | }, | 498 | }, |
| 495 | | | |
| 496 | .builtin_extern, | | |
| 497 | .wasm_memory_size, | | |
| 498 | .wasm_memory_grow, | | |
| 499 | => try stream.writeAll("TODO))"), | | |
| 500 | } | 499 | } |
| 501 | } | 500 | } |
| 502 | | 501 | |
| ... | @@ -542,8 +541,13 @@ const Writer = struct { | ... | @@ -542,8 +541,13 @@ const Writer = struct { |
| 542 | inst: Zir.Inst.Index, | 541 | inst: Zir.Inst.Index, |
| 543 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 542 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { |
| 544 | const inst_data = self.code.instructions.items(.data)[inst].array_type_sentinel; | 543 | const inst_data = self.code.instructions.items(.data)[inst].array_type_sentinel; |
| 545 | _ = inst_data; | 544 | const extra = self.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; |
| 546 | try stream.writeAll("TODO)"); | 545 | try self.writeInstRef(stream, inst_data.len); |
| | 546 | try stream.writeAll(", "); |
| | 547 | try self.writeInstRef(stream, extra.sentinel); |
| | 548 | try stream.writeAll(", "); |
| | 549 | try self.writeInstRef(stream, extra.elem_type); |
| | 550 | try stream.writeAll(")"); |
| 547 | } | 551 | } |
| 548 | | 552 | |
| 549 | fn writePtrTypeSimple( | 553 | fn writePtrTypeSimple( |
| ... | @@ -570,8 +574,42 @@ const Writer = struct { | ... | @@ -570,8 +574,42 @@ const Writer = struct { |
| 570 | inst: Zir.Inst.Index, | 574 | inst: Zir.Inst.Index, |
| 571 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 575 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { |
| 572 | const inst_data = self.code.instructions.items(.data)[inst].ptr_type; | 576 | const inst_data = self.code.instructions.items(.data)[inst].ptr_type; |
| 573 | _ = inst_data; | 577 | const str_allowzero = if (inst_data.flags.is_allowzero) "allowzero, " else ""; |
| 574 | try stream.writeAll("TODO)"); | 578 | const str_const = if (!inst_data.flags.is_mutable) "const, " else ""; |
| | 579 | const str_volatile = if (inst_data.flags.is_volatile) "volatile, " else ""; |
| | 580 | const extra = self.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); |
| | 581 | try self.writeInstRef(stream, extra.data.elem_type); |
| | 582 | try stream.print(", {s}{s}{s}{s}", .{ |
| | 583 | str_allowzero, |
| | 584 | str_const, |
| | 585 | str_volatile, |
| | 586 | @tagName(inst_data.size), |
| | 587 | }); |
| | 588 | var extra_index = extra.end; |
| | 589 | if (inst_data.flags.has_sentinel) { |
| | 590 | try stream.writeAll(", "); |
| | 591 | try self.writeInstRef(stream, @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index])); |
| | 592 | extra_index += 1; |
| | 593 | } |
| | 594 | if (inst_data.flags.has_align) { |
| | 595 | try stream.writeAll(", align("); |
| | 596 | try self.writeInstRef(stream, @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index])); |
| | 597 | extra_index += 1; |
| | 598 | if (inst_data.flags.has_bit_range) { |
| | 599 | const bit_start = extra_index + @boolToInt(inst_data.flags.has_addrspace); |
| | 600 | try stream.writeAll(":"); |
| | 601 | try self.writeInstRef(stream, @intToEnum(Zir.Inst.Ref, self.code.extra[bit_start])); |
| | 602 | try stream.writeAll(":"); |
| | 603 | try self.writeInstRef(stream, @intToEnum(Zir.Inst.Ref, self.code.extra[bit_start + 1])); |
| | 604 | } |
| | 605 | try stream.writeAll(")"); |
| | 606 | } |
| | 607 | if (inst_data.flags.has_addrspace) { |
| | 608 | try stream.writeAll(", addrspace("); |
| | 609 | try self.writeInstRef(stream, @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index])); |
| | 610 | try stream.writeAll(")"); |
| | 611 | } |
| | 612 | try stream.writeAll(")"); |
| 575 | } | 613 | } |
| 576 | | 614 | |
| 577 | fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 615 | fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| ... | @@ -623,9 +661,129 @@ const Writer = struct { | ... | @@ -623,9 +661,129 @@ const Writer = struct { |
| 623 | try stream.print("\"{}\")", .{std.zig.fmtEscapes(str)}); | 661 | try stream.print("\"{}\")", .{std.zig.fmtEscapes(str)}); |
| 624 | } | 662 | } |
| 625 | | 663 | |
| 626 | fn writePlNode(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 664 | fn writeSliceStart(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| | 665 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| | 666 | const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| | 667 | try self.writeInstRef(stream, extra.lhs); |
| | 668 | try stream.writeAll(", "); |
| | 669 | try self.writeInstRef(stream, extra.start); |
| | 670 | try stream.writeAll(") "); |
| | 671 | try self.writeSrc(stream, inst_data.src()); |
| | 672 | } |
| | 673 | |
| | 674 | fn writeSliceEnd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| | 675 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| | 676 | const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; |
| | 677 | try self.writeInstRef(stream, extra.lhs); |
| | 678 | try stream.writeAll(", "); |
| | 679 | try self.writeInstRef(stream, extra.start); |
| | 680 | try stream.writeAll(", "); |
| | 681 | try self.writeInstRef(stream, extra.end); |
| | 682 | try stream.writeAll(") "); |
| | 683 | try self.writeSrc(stream, inst_data.src()); |
| | 684 | } |
| | 685 | |
| | 686 | fn writeSliceSentinel(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| | 687 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| | 688 | const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; |
| | 689 | try self.writeInstRef(stream, extra.lhs); |
| | 690 | try stream.writeAll(", "); |
| | 691 | try self.writeInstRef(stream, extra.start); |
| | 692 | try stream.writeAll(", "); |
| | 693 | try self.writeInstRef(stream, extra.end); |
| | 694 | try stream.writeAll(", "); |
| | 695 | try self.writeInstRef(stream, extra.sentinel); |
| | 696 | try stream.writeAll(") "); |
| | 697 | try self.writeSrc(stream, inst_data.src()); |
| | 698 | } |
| | 699 | |
| | 700 | fn writeUnionInitPtr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| 627 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; | 701 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| 628 | try stream.writeAll("TODO) "); | 702 | const extra = self.code.extraData(Zir.Inst.UnionInitPtr, inst_data.payload_index).data; |
| | 703 | try self.writeInstRef(stream, extra.result_ptr); |
| | 704 | try stream.writeAll(", "); |
| | 705 | try self.writeInstRef(stream, extra.union_type); |
| | 706 | try stream.writeAll(", "); |
| | 707 | try self.writeInstRef(stream, extra.field_name); |
| | 708 | try stream.writeAll(") "); |
| | 709 | try self.writeSrc(stream, inst_data.src()); |
| | 710 | } |
| | 711 | |
| | 712 | fn writeShuffle(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| | 713 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| | 714 | const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; |
| | 715 | try self.writeInstRef(stream, extra.elem_type); |
| | 716 | try stream.writeAll(", "); |
| | 717 | try self.writeInstRef(stream, extra.a); |
| | 718 | try stream.writeAll(", "); |
| | 719 | try self.writeInstRef(stream, extra.b); |
| | 720 | try stream.writeAll(", "); |
| | 721 | try self.writeInstRef(stream, extra.mask); |
| | 722 | try stream.writeAll(") "); |
| | 723 | try self.writeSrc(stream, inst_data.src()); |
| | 724 | } |
| | 725 | |
| | 726 | fn writeSelect(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| | 727 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| | 728 | const extra = self.code.extraData(Zir.Inst.Select, inst_data.payload_index).data; |
| | 729 | try self.writeInstRef(stream, extra.elem_type); |
| | 730 | try stream.writeAll(", "); |
| | 731 | try self.writeInstRef(stream, extra.pred); |
| | 732 | try stream.writeAll(", "); |
| | 733 | try self.writeInstRef(stream, extra.a); |
| | 734 | try stream.writeAll(", "); |
| | 735 | try self.writeInstRef(stream, extra.b); |
| | 736 | try stream.writeAll(") "); |
| | 737 | try self.writeSrc(stream, inst_data.src()); |
| | 738 | } |
| | 739 | |
| | 740 | fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| | 741 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| | 742 | const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; |
| | 743 | try self.writeInstRef(stream, extra.mulend1); |
| | 744 | try stream.writeAll(", "); |
| | 745 | try self.writeInstRef(stream, extra.mulend2); |
| | 746 | try stream.writeAll(", "); |
| | 747 | try self.writeInstRef(stream, extra.addend); |
| | 748 | try stream.writeAll(") "); |
| | 749 | try self.writeSrc(stream, inst_data.src()); |
| | 750 | } |
| | 751 | |
| | 752 | fn writeBuiltinCall(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| | 753 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| | 754 | const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; |
| | 755 | try self.writeInstRef(stream, extra.options); |
| | 756 | try stream.writeAll(", "); |
| | 757 | try self.writeInstRef(stream, extra.callee); |
| | 758 | try stream.writeAll(", "); |
| | 759 | try self.writeInstRef(stream, extra.args); |
| | 760 | try stream.writeAll(") "); |
| | 761 | try self.writeSrc(stream, inst_data.src()); |
| | 762 | } |
| | 763 | |
| | 764 | fn writeFieldParentPtr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| | 765 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| | 766 | const extra = self.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data; |
| | 767 | try self.writeInstRef(stream, extra.parent_type); |
| | 768 | try stream.writeAll(", "); |
| | 769 | try self.writeInstRef(stream, extra.field_name); |
| | 770 | try stream.writeAll(", "); |
| | 771 | try self.writeInstRef(stream, extra.field_ptr); |
| | 772 | try stream.writeAll(") "); |
| | 773 | try self.writeSrc(stream, inst_data.src()); |
| | 774 | } |
| | 775 | |
| | 776 | fn writeBuiltinAsyncCall(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| | 777 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| | 778 | const extra = self.code.extraData(Zir.Inst.AsyncCall, inst_data.payload_index).data; |
| | 779 | try self.writeInstRef(stream, extra.frame_buffer); |
| | 780 | try stream.writeAll(", "); |
| | 781 | try self.writeInstRef(stream, extra.result_ptr); |
| | 782 | try stream.writeAll(", "); |
| | 783 | try self.writeInstRef(stream, extra.fn_ptr); |
| | 784 | try stream.writeAll(", "); |
| | 785 | try self.writeInstRef(stream, extra.args); |
| | 786 | try stream.writeAll(") "); |
| 629 | try self.writeSrc(stream, inst_data.src()); | 787 | try self.writeSrc(stream, inst_data.src()); |
| 630 | } | 788 | } |
| 631 | | 789 | |
| ... | @@ -782,7 +940,7 @@ const Writer = struct { | ... | @@ -782,7 +940,7 @@ const Writer = struct { |
| 782 | const field_name = self.code.nullTerminatedString(item.data.field_name); | 940 | const field_name = self.code.nullTerminatedString(item.data.field_name); |
| 783 | | 941 | |
| 784 | const prefix = if (field_i != 0) ", [" else "["; | 942 | const prefix = if (field_i != 0) ", [" else "["; |
| 785 | try stream.print("{s}[{s}=", .{ prefix, field_name }); | 943 | try stream.print("{s}{s}=", .{ prefix, field_name }); |
| 786 | try self.writeInstRef(stream, item.data.init); | 944 | try self.writeInstRef(stream, item.data.init); |
| 787 | try stream.writeAll("]"); | 945 | try stream.writeAll("]"); |
| 788 | } | 946 | } |