| ... | @@ -30,6 +30,7 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -30,6 +30,7 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 30 | const is_obj = comp.config.output_mode == .Obj; | 30 | const is_obj = comp.config.output_mode == .Obj; |
| 31 | const target = &comp.root_mod.resolved_target.result; | 31 | const target = &comp.root_mod.resolved_target.result; |
| 32 | const is_wasm32 = target.cpu.arch == .wasm32; | 32 | const is_wasm32 = target.cpu.arch == .wasm32; |
| | 33 | const function_imports_len: u32 = @intCast(wasm.function_imports.entries.len); |
| 33 | | 34 | |
| 34 | const tags = mir.instruction_tags; | 35 | const tags = mir.instruction_tags; |
| 35 | const datas = mir.instruction_datas; | 36 | const datas = mir.instruction_datas; |
| ... | @@ -158,8 +159,8 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -158,8 +159,8 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 158 | }); | 159 | }); |
| 159 | code.appendNTimesAssumeCapacity(0, 5); | 160 | code.appendNTimesAssumeCapacity(0, 5); |
| 160 | } else { | 161 | } else { |
| 161 | const func_index = try wasm.navFunctionIndex(datas[inst].nav_index); | 162 | const func_index = Wasm.FunctionIndex.fromIpNav(wasm, datas[inst].nav_index).?; |
| 162 | leb.writeUleb128(code.fixedWriter(), @intFromEnum(func_index)) catch unreachable; | 163 | leb.writeUleb128(code.fixedWriter(), function_imports_len + @intFromEnum(func_index)) catch unreachable; |
| 163 | } | 164 | } |
| 164 | | 165 | |
| 165 | inst += 1; | 166 | inst += 1; |
| ... | @@ -199,8 +200,8 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -199,8 +200,8 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 199 | }); | 200 | }); |
| 200 | code.appendNTimesAssumeCapacity(0, 5); | 201 | code.appendNTimesAssumeCapacity(0, 5); |
| 201 | } else { | 202 | } else { |
| 202 | const func_index = try wasm.tagNameFunctionIndex(datas[inst].ip_index); | 203 | const func_index = Wasm.FunctionIndex.fromTagNameType(wasm, datas[inst].ip_index).?; |
| 203 | leb.writeUleb128(code.fixedWriter(), @intFromEnum(func_index)) catch unreachable; | 204 | leb.writeUleb128(code.fixedWriter(), function_imports_len + @intFromEnum(func_index)) catch unreachable; |
| 204 | } | 205 | } |
| 205 | | 206 | |
| 206 | inst += 1; | 207 | inst += 1; |
| ... | @@ -224,8 +225,8 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -224,8 +225,8 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 224 | }); | 225 | }); |
| 225 | code.appendNTimesAssumeCapacity(0, 5); | 226 | code.appendNTimesAssumeCapacity(0, 5); |
| 226 | } else { | 227 | } else { |
| 227 | const func_index = try wasm.symbolNameFunctionIndex(symbol_name); | 228 | const func_index = Wasm.FunctionIndex.fromSymbolName(wasm, symbol_name).?; |
| 228 | leb.writeUleb128(code.fixedWriter(), @intFromEnum(func_index)) catch unreachable; | 229 | leb.writeUleb128(code.fixedWriter(), function_imports_len + @intFromEnum(func_index)) catch unreachable; |
| 229 | } | 230 | } |
| 230 | | 231 | |
| 231 | inst += 1; | 232 | inst += 1; |
| ... | @@ -282,7 +283,7 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -282,7 +283,7 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 282 | try code.ensureUnusedCapacity(gpa, 11); | 283 | try code.ensureUnusedCapacity(gpa, 11); |
| 283 | code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i64_const)); | 284 | code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i64_const)); |
| 284 | const int64: i64 = @bitCast(mir.extraData(Mir.Imm64, datas[inst].payload).data.toInt()); | 285 | const int64: i64 = @bitCast(mir.extraData(Mir.Imm64, datas[inst].payload).data.toInt()); |
| 285 | leb.writeIleb128(code.writer(), int64) catch unreachable; | 286 | leb.writeIleb128(code.fixedWriter(), int64) catch unreachable; |
| 286 | | 287 | |
| 287 | inst += 1; | 288 | inst += 1; |
| 288 | continue :loop tags[inst]; | 289 | continue :loop tags[inst]; |
| ... | @@ -314,7 +315,7 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -314,7 +315,7 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 314 | => { | 315 | => { |
| 315 | try code.ensureUnusedCapacity(gpa, 1 + 20); | 316 | try code.ensureUnusedCapacity(gpa, 1 + 20); |
| 316 | code.appendAssumeCapacity(@intFromEnum(tags[inst])); | 317 | code.appendAssumeCapacity(@intFromEnum(tags[inst])); |
| 317 | encodeMemArg(code, mir.extraData(Mir.MemArg, datas[inst]).data); | 318 | encodeMemArg(code, mir.extraData(Mir.MemArg, datas[inst].payload).data); |
| 318 | inst += 1; | 319 | inst += 1; |
| 319 | continue :loop tags[inst]; | 320 | continue :loop tags[inst]; |
| 320 | }, | 321 | }, |
| ... | @@ -504,6 +505,13 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -504,6 +505,13 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 504 | continue :loop tags[inst]; | 505 | continue :loop tags[inst]; |
| 505 | }, | 506 | }, |
| 506 | | 507 | |
| | 508 | .table_init => @panic("TODO"), |
| | 509 | .elem_drop => @panic("TODO"), |
| | 510 | .table_copy => @panic("TODO"), |
| | 511 | .table_grow => @panic("TODO"), |
| | 512 | .table_size => @panic("TODO"), |
| | 513 | .table_fill => @panic("TODO"), |
| | 514 | |
| 507 | _ => unreachable, | 515 | _ => unreachable, |
| 508 | } | 516 | } |
| 509 | comptime unreachable; | 517 | comptime unreachable; |
| ... | @@ -560,7 +568,236 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -560,7 +568,236 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 560 | inst += 1; | 568 | inst += 1; |
| 561 | continue :loop tags[inst]; | 569 | continue :loop tags[inst]; |
| 562 | }, | 570 | }, |
| 563 | _ => unreachable, | 571 | |
| | 572 | .v128_load8x8_s => @panic("TODO"), |
| | 573 | .v128_load8x8_u => @panic("TODO"), |
| | 574 | .v128_load16x4_s => @panic("TODO"), |
| | 575 | .v128_load16x4_u => @panic("TODO"), |
| | 576 | .v128_load32x2_s => @panic("TODO"), |
| | 577 | .v128_load32x2_u => @panic("TODO"), |
| | 578 | .i8x16_swizzle => @panic("TODO"), |
| | 579 | .i8x16_eq => @panic("TODO"), |
| | 580 | .i16x8_eq => @panic("TODO"), |
| | 581 | .i32x4_eq => @panic("TODO"), |
| | 582 | .i8x16_ne => @panic("TODO"), |
| | 583 | .i16x8_ne => @panic("TODO"), |
| | 584 | .i32x4_ne => @panic("TODO"), |
| | 585 | .i8x16_lt_s => @panic("TODO"), |
| | 586 | .i16x8_lt_s => @panic("TODO"), |
| | 587 | .i32x4_lt_s => @panic("TODO"), |
| | 588 | .i8x16_lt_u => @panic("TODO"), |
| | 589 | .i16x8_lt_u => @panic("TODO"), |
| | 590 | .i32x4_lt_u => @panic("TODO"), |
| | 591 | .i8x16_gt_s => @panic("TODO"), |
| | 592 | .i16x8_gt_s => @panic("TODO"), |
| | 593 | .i32x4_gt_s => @panic("TODO"), |
| | 594 | .i8x16_gt_u => @panic("TODO"), |
| | 595 | .i16x8_gt_u => @panic("TODO"), |
| | 596 | .i32x4_gt_u => @panic("TODO"), |
| | 597 | .i8x16_le_s => @panic("TODO"), |
| | 598 | .i16x8_le_s => @panic("TODO"), |
| | 599 | .i32x4_le_s => @panic("TODO"), |
| | 600 | .i8x16_le_u => @panic("TODO"), |
| | 601 | .i16x8_le_u => @panic("TODO"), |
| | 602 | .i32x4_le_u => @panic("TODO"), |
| | 603 | .i8x16_ge_s => @panic("TODO"), |
| | 604 | .i16x8_ge_s => @panic("TODO"), |
| | 605 | .i32x4_ge_s => @panic("TODO"), |
| | 606 | .i8x16_ge_u => @panic("TODO"), |
| | 607 | .i16x8_ge_u => @panic("TODO"), |
| | 608 | .i32x4_ge_u => @panic("TODO"), |
| | 609 | .f32x4_eq => @panic("TODO"), |
| | 610 | .f64x2_eq => @panic("TODO"), |
| | 611 | .f32x4_ne => @panic("TODO"), |
| | 612 | .f64x2_ne => @panic("TODO"), |
| | 613 | .f32x4_lt => @panic("TODO"), |
| | 614 | .f64x2_lt => @panic("TODO"), |
| | 615 | .f32x4_gt => @panic("TODO"), |
| | 616 | .f64x2_gt => @panic("TODO"), |
| | 617 | .f32x4_le => @panic("TODO"), |
| | 618 | .f64x2_le => @panic("TODO"), |
| | 619 | .f32x4_ge => @panic("TODO"), |
| | 620 | .f64x2_ge => @panic("TODO"), |
| | 621 | .v128_not => @panic("TODO"), |
| | 622 | .v128_and => @panic("TODO"), |
| | 623 | .v128_andnot => @panic("TODO"), |
| | 624 | .v128_or => @panic("TODO"), |
| | 625 | .v128_xor => @panic("TODO"), |
| | 626 | .v128_bitselect => @panic("TODO"), |
| | 627 | .v128_any_true => @panic("TODO"), |
| | 628 | .v128_load8_lane => @panic("TODO"), |
| | 629 | .v128_load16_lane => @panic("TODO"), |
| | 630 | .v128_load32_lane => @panic("TODO"), |
| | 631 | .v128_load64_lane => @panic("TODO"), |
| | 632 | .v128_store8_lane => @panic("TODO"), |
| | 633 | .v128_store16_lane => @panic("TODO"), |
| | 634 | .v128_store32_lane => @panic("TODO"), |
| | 635 | .v128_store64_lane => @panic("TODO"), |
| | 636 | .v128_load32_zero => @panic("TODO"), |
| | 637 | .v128_load64_zero => @panic("TODO"), |
| | 638 | .f32x4_demote_f64x2_zero => @panic("TODO"), |
| | 639 | .f64x2_promote_low_f32x4 => @panic("TODO"), |
| | 640 | .i8x16_abs => @panic("TODO"), |
| | 641 | .i16x8_abs => @panic("TODO"), |
| | 642 | .i32x4_abs => @panic("TODO"), |
| | 643 | .i64x2_abs => @panic("TODO"), |
| | 644 | .i8x16_neg => @panic("TODO"), |
| | 645 | .i16x8_neg => @panic("TODO"), |
| | 646 | .i32x4_neg => @panic("TODO"), |
| | 647 | .i64x2_neg => @panic("TODO"), |
| | 648 | .i8x16_popcnt => @panic("TODO"), |
| | 649 | .i16x8_q15mulr_sat_s => @panic("TODO"), |
| | 650 | .i8x16_all_true => @panic("TODO"), |
| | 651 | .i16x8_all_true => @panic("TODO"), |
| | 652 | .i32x4_all_true => @panic("TODO"), |
| | 653 | .i64x2_all_true => @panic("TODO"), |
| | 654 | .i8x16_bitmask => @panic("TODO"), |
| | 655 | .i16x8_bitmask => @panic("TODO"), |
| | 656 | .i32x4_bitmask => @panic("TODO"), |
| | 657 | .i64x2_bitmask => @panic("TODO"), |
| | 658 | .i8x16_narrow_i16x8_s => @panic("TODO"), |
| | 659 | .i16x8_narrow_i32x4_s => @panic("TODO"), |
| | 660 | .i8x16_narrow_i16x8_u => @panic("TODO"), |
| | 661 | .i16x8_narrow_i32x4_u => @panic("TODO"), |
| | 662 | .f32x4_ceil => @panic("TODO"), |
| | 663 | .i16x8_extend_low_i8x16_s => @panic("TODO"), |
| | 664 | .i32x4_extend_low_i16x8_s => @panic("TODO"), |
| | 665 | .i64x2_extend_low_i32x4_s => @panic("TODO"), |
| | 666 | .f32x4_floor => @panic("TODO"), |
| | 667 | .i16x8_extend_high_i8x16_s => @panic("TODO"), |
| | 668 | .i32x4_extend_high_i16x8_s => @panic("TODO"), |
| | 669 | .i64x2_extend_high_i32x4_s => @panic("TODO"), |
| | 670 | .f32x4_trunc => @panic("TODO"), |
| | 671 | .i16x8_extend_low_i8x16_u => @panic("TODO"), |
| | 672 | .i32x4_extend_low_i16x8_u => @panic("TODO"), |
| | 673 | .i64x2_extend_low_i32x4_u => @panic("TODO"), |
| | 674 | .f32x4_nearest => @panic("TODO"), |
| | 675 | .i16x8_extend_high_i8x16_u => @panic("TODO"), |
| | 676 | .i32x4_extend_high_i16x8_u => @panic("TODO"), |
| | 677 | .i64x2_extend_high_i32x4_u => @panic("TODO"), |
| | 678 | .i8x16_shl => @panic("TODO"), |
| | 679 | .i16x8_shl => @panic("TODO"), |
| | 680 | .i32x4_shl => @panic("TODO"), |
| | 681 | .i64x2_shl => @panic("TODO"), |
| | 682 | .i8x16_shr_s => @panic("TODO"), |
| | 683 | .i16x8_shr_s => @panic("TODO"), |
| | 684 | .i32x4_shr_s => @panic("TODO"), |
| | 685 | .i64x2_shr_s => @panic("TODO"), |
| | 686 | .i8x16_shr_u => @panic("TODO"), |
| | 687 | .i16x8_shr_u => @panic("TODO"), |
| | 688 | .i32x4_shr_u => @panic("TODO"), |
| | 689 | .i64x2_shr_u => @panic("TODO"), |
| | 690 | .i8x16_add => @panic("TODO"), |
| | 691 | .i16x8_add => @panic("TODO"), |
| | 692 | .i32x4_add => @panic("TODO"), |
| | 693 | .i64x2_add => @panic("TODO"), |
| | 694 | .i8x16_add_sat_s => @panic("TODO"), |
| | 695 | .i16x8_add_sat_s => @panic("TODO"), |
| | 696 | .i8x16_add_sat_u => @panic("TODO"), |
| | 697 | .i16x8_add_sat_u => @panic("TODO"), |
| | 698 | .i8x16_sub => @panic("TODO"), |
| | 699 | .i16x8_sub => @panic("TODO"), |
| | 700 | .i32x4_sub => @panic("TODO"), |
| | 701 | .i64x2_sub => @panic("TODO"), |
| | 702 | .i8x16_sub_sat_s => @panic("TODO"), |
| | 703 | .i16x8_sub_sat_s => @panic("TODO"), |
| | 704 | .i8x16_sub_sat_u => @panic("TODO"), |
| | 705 | .i16x8_sub_sat_u => @panic("TODO"), |
| | 706 | .f64x2_ceil => @panic("TODO"), |
| | 707 | .f64x2_nearest => @panic("TODO"), |
| | 708 | .f64x2_floor => @panic("TODO"), |
| | 709 | .i16x8_mul => @panic("TODO"), |
| | 710 | .i32x4_mul => @panic("TODO"), |
| | 711 | .i64x2_mul => @panic("TODO"), |
| | 712 | .i8x16_min_s => @panic("TODO"), |
| | 713 | .i16x8_min_s => @panic("TODO"), |
| | 714 | .i32x4_min_s => @panic("TODO"), |
| | 715 | .i64x2_eq => @panic("TODO"), |
| | 716 | .i8x16_min_u => @panic("TODO"), |
| | 717 | .i16x8_min_u => @panic("TODO"), |
| | 718 | .i32x4_min_u => @panic("TODO"), |
| | 719 | .i64x2_ne => @panic("TODO"), |
| | 720 | .i8x16_max_s => @panic("TODO"), |
| | 721 | .i16x8_max_s => @panic("TODO"), |
| | 722 | .i32x4_max_s => @panic("TODO"), |
| | 723 | .i64x2_lt_s => @panic("TODO"), |
| | 724 | .i8x16_max_u => @panic("TODO"), |
| | 725 | .i16x8_max_u => @panic("TODO"), |
| | 726 | .i32x4_max_u => @panic("TODO"), |
| | 727 | .i64x2_gt_s => @panic("TODO"), |
| | 728 | .f64x2_trunc => @panic("TODO"), |
| | 729 | .i32x4_dot_i16x8_s => @panic("TODO"), |
| | 730 | .i64x2_le_s => @panic("TODO"), |
| | 731 | .i8x16_avgr_u => @panic("TODO"), |
| | 732 | .i16x8_avgr_u => @panic("TODO"), |
| | 733 | .i64x2_ge_s => @panic("TODO"), |
| | 734 | .i16x8_extadd_pairwise_i8x16_s => @panic("TODO"), |
| | 735 | .i16x8_extmul_low_i8x16_s => @panic("TODO"), |
| | 736 | .i32x4_extmul_low_i16x8_s => @panic("TODO"), |
| | 737 | .i64x2_extmul_low_i32x4_s => @panic("TODO"), |
| | 738 | .i16x8_extadd_pairwise_i8x16_u => @panic("TODO"), |
| | 739 | .i16x8_extmul_high_i8x16_s => @panic("TODO"), |
| | 740 | .i32x4_extmul_high_i16x8_s => @panic("TODO"), |
| | 741 | .i64x2_extmul_high_i32x4_s => @panic("TODO"), |
| | 742 | .i32x4_extadd_pairwise_i16x8_s => @panic("TODO"), |
| | 743 | .i16x8_extmul_low_i8x16_u => @panic("TODO"), |
| | 744 | .i32x4_extmul_low_i16x8_u => @panic("TODO"), |
| | 745 | .i64x2_extmul_low_i32x4_u => @panic("TODO"), |
| | 746 | .i32x4_extadd_pairwise_i16x8_u => @panic("TODO"), |
| | 747 | .i16x8_extmul_high_i8x16_u => @panic("TODO"), |
| | 748 | .i32x4_extmul_high_i16x8_u => @panic("TODO"), |
| | 749 | .i64x2_extmul_high_i32x4_u => @panic("TODO"), |
| | 750 | .f32x4_abs => @panic("TODO"), |
| | 751 | .f64x2_abs => @panic("TODO"), |
| | 752 | .f32x4_neg => @panic("TODO"), |
| | 753 | .f64x2_neg => @panic("TODO"), |
| | 754 | .f32x4_sqrt => @panic("TODO"), |
| | 755 | .f64x2_sqrt => @panic("TODO"), |
| | 756 | .f32x4_add => @panic("TODO"), |
| | 757 | .f64x2_add => @panic("TODO"), |
| | 758 | .f32x4_sub => @panic("TODO"), |
| | 759 | .f64x2_sub => @panic("TODO"), |
| | 760 | .f32x4_mul => @panic("TODO"), |
| | 761 | .f64x2_mul => @panic("TODO"), |
| | 762 | .f32x4_div => @panic("TODO"), |
| | 763 | .f64x2_div => @panic("TODO"), |
| | 764 | .f32x4_min => @panic("TODO"), |
| | 765 | .f64x2_min => @panic("TODO"), |
| | 766 | .f32x4_max => @panic("TODO"), |
| | 767 | .f64x2_max => @panic("TODO"), |
| | 768 | .f32x4_pmin => @panic("TODO"), |
| | 769 | .f64x2_pmin => @panic("TODO"), |
| | 770 | .f32x4_pmax => @panic("TODO"), |
| | 771 | .f64x2_pmax => @panic("TODO"), |
| | 772 | .i32x4_trunc_sat_f32x4_s => @panic("TODO"), |
| | 773 | .i32x4_trunc_sat_f32x4_u => @panic("TODO"), |
| | 774 | .f32x4_convert_i32x4_s => @panic("TODO"), |
| | 775 | .f32x4_convert_i32x4_u => @panic("TODO"), |
| | 776 | .i32x4_trunc_sat_f64x2_s_zero => @panic("TODO"), |
| | 777 | .i32x4_trunc_sat_f64x2_u_zero => @panic("TODO"), |
| | 778 | .f64x2_convert_low_i32x4_s => @panic("TODO"), |
| | 779 | .f64x2_convert_low_i32x4_u => @panic("TODO"), |
| | 780 | .i8x16_relaxed_swizzle => @panic("TODO"), |
| | 781 | .i32x4_relaxed_trunc_f32x4_s => @panic("TODO"), |
| | 782 | .i32x4_relaxed_trunc_f32x4_u => @panic("TODO"), |
| | 783 | .i32x4_relaxed_trunc_f64x2_s_zero => @panic("TODO"), |
| | 784 | .i32x4_relaxed_trunc_f64x2_u_zero => @panic("TODO"), |
| | 785 | .f32x4_relaxed_madd => @panic("TODO"), |
| | 786 | .f32x4_relaxed_nmadd => @panic("TODO"), |
| | 787 | .f64x2_relaxed_madd => @panic("TODO"), |
| | 788 | .f64x2_relaxed_nmadd => @panic("TODO"), |
| | 789 | .i8x16_relaxed_laneselect => @panic("TODO"), |
| | 790 | .i16x8_relaxed_laneselect => @panic("TODO"), |
| | 791 | .i32x4_relaxed_laneselect => @panic("TODO"), |
| | 792 | .i64x2_relaxed_laneselect => @panic("TODO"), |
| | 793 | .f32x4_relaxed_min => @panic("TODO"), |
| | 794 | .f32x4_relaxed_max => @panic("TODO"), |
| | 795 | .f64x2_relaxed_min => @panic("TODO"), |
| | 796 | .f64x2_relaxed_max => @panic("TODO"), |
| | 797 | .i16x8_relaxed_q15mulr_s => @panic("TODO"), |
| | 798 | .i16x8_relaxed_dot_i8x16_i7x16_s => @panic("TODO"), |
| | 799 | .i32x4_relaxed_dot_i8x16_i7x16_add_s => @panic("TODO"), |
| | 800 | .f32x4_relaxed_dot_bf16x8_add_f32x4 => @panic("TODO"), |
| 564 | } | 801 | } |
| 565 | comptime unreachable; | 802 | comptime unreachable; |
| 566 | }, | 803 | }, |
| ... | @@ -650,6 +887,9 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -650,6 +887,9 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 650 | inst += 1; | 887 | inst += 1; |
| 651 | continue :loop tags[inst]; | 888 | continue :loop tags[inst]; |
| 652 | }, | 889 | }, |
| | 890 | .memory_atomic_notify => @panic("TODO"), |
| | 891 | .memory_atomic_wait32 => @panic("TODO"), |
| | 892 | .memory_atomic_wait64 => @panic("TODO"), |
| 653 | } | 893 | } |
| 654 | comptime unreachable; | 894 | comptime unreachable; |
| 655 | }, | 895 | }, |