1
2
3
4
5 package wasm
6
7 import (
8 "bytes"
9 "cmd/internal/obj"
10 "testing"
11 )
12
13
14
15
16
17 func TestWriteOpcode(t *testing.T) {
18 tests := []struct {
19 as obj.As
20 want []byte
21 }{
22 {AUnreachable, []byte{0x00}},
23 {AEnd, []byte{0x0B}},
24 {ADrop, []byte{0x1A}},
25 {ALocalGet, []byte{0x20}},
26 {AI32Load, []byte{0x28}},
27 {ARefNull, []byte{0xD0}},
28 {AContNew, []byte{0xE0}},
29 {AI32TruncSatF32S, []byte{0xFC, 0x00}},
30
31 {AV128Load, []byte{0xFD, 0x00}},
32 {AI32x4ExtaddPairwiseI16x8U, []byte{0xFD, 0x7F}},
33 {AI16x8Abs, []byte{0xFD, 0x80, 0x01}},
34 {AF64x2ConvertLowI32x4U, []byte{0xFD, 0xFF, 0x01}},
35 {AI8x16RelaxedSwizzle, []byte{0xFD, 0x80, 0x02}},
36 {AI32x4RelaxedDotI8x16I7x16AddS, []byte{0xFD, 0x93, 0x02}},
37 }
38 var buf bytes.Buffer
39 for _, test := range tests {
40 buf.Reset()
41 writeOpcode(&buf, test.as)
42 if got := buf.Bytes(); !bytes.Equal(got, test.want) {
43 t.Errorf("writeOpcode(%v) = % x, want % x", test.as, got, test.want)
44 }
45 }
46 }
47
View as plain text