xref: /llvm-project/llvm/test/MC/WebAssembly/tables.s (revision 9d2e8dca12c8bbb70223eeb74330fe603e215ce3)
1# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types < %s | FileCheck %s
2# RUN: llvm-mc -show-encoding -triple=wasm32-unknown-unknown -mattr=+reference-types < %s | FileCheck -check-prefix=ENC %s
3# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types -filetype=obj < %s | obj2yaml | FileCheck -check-prefix=BIN %s
4
5# Creating several empty tables
6
7# CHECK:         .tabletype foo, externref
8# CHECK: foo:
9    .tabletype foo, externref
10foo:
11
12
13#      CHECK: bar:
14# CHECK-NEXT:         .tabletype bar, funcref
15bar:
16    .tabletype bar, funcref
17
18table1:
19    .tabletype table1, funcref, 42
20table2:
21    .tabletype table2, funcref, 42, 100
22
23# Table instructions
24
25#      CHECK: copy_tables:
26# CHECK-NEXT:         .functype	copy_tables (i32, i32) -> ()
27# CHECK-NEXT:	local.get	0
28# CHECK-NEXT:	local.get	1
29#      CHECK:	table.size	table1
30#      CHECK:	table.copy	table1, table2
31# CHECK-NEXT:	end_function
32copy_tables:
33    .functype copy_tables (i32, i32) -> ()
34    local.get 0
35    local.get 1
36
37    # ENC: table.size	table1                  # encoding: [0xfc,0x10,0x80'A',0x80'A',0x80'A',0x80'A',A]
38    table.size table1
39
40    # ENC: table.copy	table1, table2          # encoding: [0xfc,0x0e,0x80'A',0x80'A',0x80'A',0x80'A',A,0x80'B',0x80'B',0x80'B',0x80'B',B]
41    table.copy table1, table2
42    end_function
43
44#      CHECK: table_get:
45# CHECK-NEXT:	.functype	table_get (i32) -> (externref)
46# CHECK-NEXT:	local.get	0
47#      CHECK:	table.get	foo
48# CHECK-NEXT:	end_function
49table_get:
50    .functype table_get (i32) -> (externref)
51    local.get 0
52
53    # ENC: table.get	foo                     # encoding: [0x25,0x80'A',0x80'A',0x80'A',0x80'A',A]
54    table.get foo
55    end_function
56
57#      CHECK: table_set:
58# CHECK-NEXT:	.functype	table_set (i32, externref) -> ()
59# CHECK-NEXT:	local.get	0
60# CHECK-NEXT:	local.get	1
61#      CHECK:	table.set	foo
62# CHECK-NEXT:	end_function
63table_set:
64    .functype table_set (i32, externref) -> ()
65    local.get 0
66    local.get 1
67
68    # ENC: table.set	foo                     # encoding: [0x26,0x80'A',0x80'A',0x80'A',0x80'A',A]
69    table.set foo
70    end_function
71
72#      CHECK: table_grow:
73# CHECK-NEXT:	.functype	table_grow (i32) -> (i32)
74# CHECK-NEXT:	i32.const	0
75# CHECK-NEXT:	table.get	foo
76# CHECK-NEXT:	local.get	0
77#      CHECK:	table.grow	foo
78# CHECK-NEXT:	local.get	0
79# CHECK-NEXT:	i32.add
80# CHECK-NEXT:	end_function
81table_grow:
82    .functype table_grow (i32) -> (i32)
83    i32.const 0
84    table.get foo
85    local.get 0
86
87    # ENC: table.grow	foo                     # encoding: [0xfc,0x0f,0x80'A',0x80'A',0x80'A',0x80'A',A]
88    table.grow foo
89    local.get 0
90    i32.add
91    end_function
92
93#      CHECK: table_fill:
94# CHECK-NEXT:	.functype	table_fill (i32, i32) -> ()
95# CHECK-NEXT:	local.get	0
96# CHECK-NEXT:	i32.const	0
97# CHECK-NEXT:	table.get	table1
98# CHECK-NEXT:	local.get	1
99#      CHECK:	table.fill	table1
100# CHECK-NEXT:	end_function
101table_fill:
102    .functype table_fill (i32, i32) -> ()
103    local.get 0
104    i32.const 0
105    table.get table1
106    local.get 1
107
108    # ENC: table.fill	table1                  # encoding: [0xfc,0x11,0x80'A',0x80'A',0x80'A',0x80'A',A]
109    table.fill table1
110    end_function
111
112#      BIN:  - Type:            TABLE
113# BIN-NEXT:    Tables:
114# BIN-NEXT:      - Index:           0
115# BIN-NEXT:        ElemType:        EXTERNREF
116# BIN-NEXT:        Limits:
117# BIN-NEXT:          Minimum:         0x0
118# BIN-NEXT:      - Index:           1
119# BIN-NEXT:        ElemType:        FUNCREF
120# BIN-NEXT:        Limits:
121# BIN-NEXT:          Minimum:         0x0
122# BIN-NEXT:      - Index:           2
123# BIN-NEXT:        ElemType:        FUNCREF
124# BIN-NEXT:        Limits:
125# BIN-NEXT:          Minimum:         0x2A
126# BIN-NEXT:      - Index:           3
127# BIN-NEXT:        ElemType:        FUNCREF
128# BIN-NEXT:        Limits:
129# BIN-NEXT:          Flags:           [ HAS_MAX ]
130# BIN-NEXT:          Minimum:         0x2A
131# BIN-NEXT:          Maximum:         0x64
132
133#      BIN:  - Type:            CODE
134# BIN-NEXT:    Relocations:
135# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
136# BIN-NEXT:        Index:           2
137# BIN-NEXT:        Offset:          0x9
138# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
139# BIN-NEXT:        Index:           2
140# BIN-NEXT:        Offset:          0x10
141# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
142# BIN-NEXT:        Index:           3
143# BIN-NEXT:        Offset:          0x15
144# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
145# BIN-NEXT:        Index:           0
146# BIN-NEXT:        Offset:          0x20
147# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
148# BIN-NEXT:        Index:           0
149# BIN-NEXT:        Offset:          0x2D
150# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
151# BIN-NEXT:        Index:           0
152# BIN-NEXT:        Offset:          0x38
153# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
154# BIN-NEXT:        Index:           0
155# BIN-NEXT:        Offset:          0x41
156# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
157# BIN-NEXT:        Index:           2
158# BIN-NEXT:        Offset:          0x51
159# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
160# BIN-NEXT:        Index:           2
161# BIN-NEXT:        Offset:          0x5A
162# BIN-NEXT:    Functions:
163# BIN-NEXT:      - Index:           0
164# BIN-NEXT:        Locals:          []
165# BIN-NEXT:        Body:            20002001FC108280808000FC0E828080800083808080000B
166# BIN-NEXT:      - Index:           1
167# BIN-NEXT:        Locals:          []
168# BIN-NEXT:        Body:            20002580808080000B
169# BIN-NEXT:      - Index:           2
170# BIN-NEXT:        Locals:          []
171# BIN-NEXT:        Body:            200020012680808080000B
172# BIN-NEXT:      - Index:           3
173# BIN-NEXT:        Locals:          []
174# BIN-NEXT:        Body:            41002580808080002000FC0F808080800020006A0B
175# BIN-NEXT:      - Index:           4
176# BIN-NEXT:        Locals:          []
177# BIN-NEXT:        Body:            200041002582808080002001FC1182808080000B
178
179#      BIN:  - Type:            CUSTOM
180# BIN-NEXT:    Name:            linking
181# BIN-NEXT:    Version:         2
182# BIN-NEXT:    SymbolTable:
183# BIN-NEXT:      - Index:           0
184# BIN-NEXT:        Kind:            TABLE
185# BIN-NEXT:        Name:            foo
186# BIN-NEXT:        Flags:           [ BINDING_LOCAL ]
187# BIN-NEXT:        Table:           0
188# BIN-NEXT:      - Index:           1
189# BIN-NEXT:        Kind:            TABLE
190# BIN-NEXT:        Name:            bar
191# BIN-NEXT:        Flags:           [ BINDING_LOCAL ]
192# BIN-NEXT:        Table:           1
193# BIN-NEXT:      - Index:           2
194# BIN-NEXT:        Kind:            TABLE
195# BIN-NEXT:        Name:            table1
196# BIN-NEXT:        Flags:           [ BINDING_LOCAL ]
197# BIN-NEXT:        Table:           2
198# BIN-NEXT:      - Index:           3
199# BIN-NEXT:        Kind:            TABLE
200# BIN-NEXT:        Name:            table2
201# BIN-NEXT:        Flags:           [ BINDING_LOCAL ]
202# BIN-NEXT:        Table:           3
203# BIN-NEXT:      - Index:           4
204