wa-lang.org/wazero@v1.0.2/internal/wazeroir/signature_test.go (about) 1 package wazeroir 2 3 import ( 4 "testing" 5 6 "wa-lang.org/wazero/internal/testing/require" 7 "wa-lang.org/wazero/internal/wasm" 8 ) 9 10 func TestCompiler_wasmOpcodeSignature(t *testing.T) { 11 tests := []struct { 12 name string 13 body []byte 14 exp *signature 15 }{ 16 { 17 name: "i32.trunc_sat_f32_s", 18 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI32TruncSatF32S}, 19 exp: signature_F32_I32, 20 }, 21 { 22 name: "i32.trunc_sat_f32_u", 23 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI32TruncSatF32U}, 24 exp: signature_F32_I32, 25 }, 26 { 27 name: "i32.trunc_sat_f64_s", 28 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI32TruncSatF64S}, 29 exp: signature_F64_I32, 30 }, 31 { 32 name: "i32.trunc_sat_f64_u", 33 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI32TruncSatF64U}, 34 exp: signature_F64_I32, 35 }, 36 { 37 name: "i64.trunc_sat_f32_s", 38 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI64TruncSatF32S}, 39 exp: signature_F32_I64, 40 }, 41 { 42 name: "i64.trunc_sat_f32_u", 43 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI64TruncSatF32U}, 44 exp: signature_F32_I64, 45 }, 46 { 47 name: "i64.trunc_sat_f64_s", 48 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI64TruncSatF64S}, 49 exp: signature_F64_I64, 50 }, 51 { 52 name: "i64.trunc_sat_f64_u", 53 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI64TruncSatF64U}, 54 exp: signature_F64_I64, 55 }, 56 { 57 name: "memory.init", 58 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscMemoryInit}, 59 exp: signature_I32I32I32_None, 60 }, 61 { 62 name: "data.drop", 63 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscDataDrop}, 64 exp: signature_None_None, 65 }, 66 { 67 name: "memory.copy", 68 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscMemoryCopy}, 69 exp: signature_I32I32I32_None, 70 }, 71 { 72 name: "memory.fill", 73 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscMemoryFill}, 74 exp: signature_I32I32I32_None, 75 }, 76 { 77 name: "table.init", 78 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscTableInit}, 79 exp: signature_I32I32I32_None, 80 }, 81 { 82 name: "elem.drop", 83 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscElemDrop}, 84 exp: signature_None_None, 85 }, 86 { 87 name: "table.copy", 88 body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscTableCopy}, 89 exp: signature_I32I32I32_None, 90 }, 91 } 92 93 for _, tt := range tests { 94 tc := tt 95 t.Run(tc.name, func(t *testing.T) { 96 c := &compiler{body: tc.body} 97 actual, err := c.wasmOpcodeSignature(tc.body[0], 0) 98 require.NoError(t, err) 99 require.Equal(t, tc.exp, actual) 100 }) 101 } 102 }