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
20table2:
21    .tabletype table2, funcref
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
32# CHECK-NEXT:.Ltmp0:
33# CHECK-NEXT:	.size	copy_tables, .Ltmp0-copy_tables
34copy_tables:
35    .functype copy_tables (i32, i32) -> ()
36    local.get 0
37    local.get 1
38
39    # ENC: table.size	table1                  # encoding: [0xfc,0x10,0x80'A',0x80'A',0x80'A',0x80'A',A]
40    table.size table1
41
42    # 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]
43    table.copy table1, table2
44    end_function
45
46#      CHECK: table_get:
47# CHECK-NEXT:	.functype	table_get (i32) -> (externref)
48# CHECK-NEXT:	local.get	0
49#      CHECK:	table.get	foo
50# CHECK-NEXT:	end_function
51# CHECK-NEXT: .Ltmp1:
52# CHECK-NEXT:	.size	table_get, .Ltmp1-table_get
53table_get:
54    .functype table_get (i32) -> (externref)
55    local.get 0
56
57    # ENC: table.get	foo                     # encoding: [0x25,0x80'A',0x80'A',0x80'A',0x80'A',A]
58    table.get foo
59    end_function
60
61#      CHECK: table_set:
62# CHECK-NEXT:	.functype	table_set (i32, externref) -> ()
63# CHECK-NEXT:	local.get	0
64# CHECK-NEXT:	local.get	1
65#      CHECK:	table.set	foo
66# CHECK-NEXT:	end_function
67# CHECK-NEXT: .Ltmp2:
68# CHECK-NEXT:	.size	table_set, .Ltmp2-table_set
69table_set:
70    .functype table_set (i32, externref) -> ()
71    local.get 0
72    local.get 1
73
74    # ENC: table.set	foo                     # encoding: [0x26,0x80'A',0x80'A',0x80'A',0x80'A',A]
75    table.set foo
76    end_function
77
78#      CHECK: table_grow:
79# CHECK-NEXT:	.functype	table_grow (i32) -> (i32)
80# CHECK-NEXT:	i32.const	0
81# CHECK-NEXT:	table.get	foo
82# CHECK-NEXT:	local.get	0
83#      CHECK:	table.grow	foo
84# CHECK-NEXT:	local.get	0
85# CHECK-NEXT:	i32.add
86# CHECK-NEXT:	end_function
87# CHECK-NEXT: .Ltmp3:
88# CHECK-NEXT:	.size	table_grow, .Ltmp3-table_grow
89table_grow:
90    .functype table_grow (i32) -> (i32)
91    i32.const 0
92    table.get foo
93    local.get 0
94
95    # ENC: table.grow	foo                     # encoding: [0xfc,0x0f,0x80'A',0x80'A',0x80'A',0x80'A',A]
96    table.grow foo
97    local.get 0
98    i32.add
99    end_function
100
101#      CHECK: table_fill:
102# CHECK-NEXT:	.functype	table_fill (i32, i32) -> ()
103# CHECK-NEXT:	local.get	0
104# CHECK-NEXT:	i32.const	0
105# CHECK-NEXT:	table.get	table1
106# CHECK-NEXT:	local.get	1
107#      CHECK:	table.fill	table1
108# CHECK-NEXT:	end_function
109# CHECK-NEXT: .Ltmp4:
110# CHECK-NEXT:	.size	table_fill, .Ltmp4-table_fill
111table_fill:
112    .functype table_fill (i32, i32) -> ()
113    local.get 0
114    i32.const 0
115    table.get table1
116    local.get 1
117
118    # ENC: table.fill	table1                  # encoding: [0xfc,0x11,0x80'A',0x80'A',0x80'A',0x80'A',A]
119    table.fill table1
120    end_function
121
122#      BIN:  - Type:            TABLE
123# BIN-NEXT:    Tables:
124# BIN-NEXT:      - Index:           0
125# BIN-NEXT:        ElemType:        EXTERNREF
126# BIN-NEXT:        Limits:
127# BIN-NEXT:          Initial:         0x0
128# BIN-NEXT:      - Index:           1
129# BIN-NEXT:        ElemType:        FUNCREF
130# BIN-NEXT:        Limits:
131# BIN-NEXT:          Initial:         0x0
132# BIN-NEXT:      - Index:           2
133# BIN-NEXT:        ElemType:        FUNCREF
134# BIN-NEXT:        Limits:
135# BIN-NEXT:          Initial:         0x0
136# BIN-NEXT:      - Index:           3
137# BIN-NEXT:        ElemType:        FUNCREF
138# BIN-NEXT:        Limits:
139# BIN-NEXT:          Initial:         0x0
140
141#      BIN:  - Type:            CODE
142# BIN-NEXT:    Relocations:
143# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
144# BIN-NEXT:        Index:           2
145# BIN-NEXT:        Offset:          0x9
146# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
147# BIN-NEXT:        Index:           2
148# BIN-NEXT:        Offset:          0x10
149# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
150# BIN-NEXT:        Index:           3
151# BIN-NEXT:        Offset:          0x15
152# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
153# BIN-NEXT:        Index:           0
154# BIN-NEXT:        Offset:          0x20
155# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
156# BIN-NEXT:        Index:           0
157# BIN-NEXT:        Offset:          0x2D
158# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
159# BIN-NEXT:        Index:           0
160# BIN-NEXT:        Offset:          0x38
161# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
162# BIN-NEXT:        Index:           0
163# BIN-NEXT:        Offset:          0x41
164# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
165# BIN-NEXT:        Index:           2
166# BIN-NEXT:        Offset:          0x51
167# BIN-NEXT:      - Type:            R_WASM_TABLE_NUMBER_LEB
168# BIN-NEXT:        Index:           2
169# BIN-NEXT:        Offset:          0x5A
170# BIN-NEXT:    Functions:
171# BIN-NEXT:      - Index:           0
172# BIN-NEXT:        Locals:          []
173# BIN-NEXT:        Body:            20002001FC108280808000FC0E828080800083808080000B
174# BIN-NEXT:      - Index:           1
175# BIN-NEXT:        Locals:          []
176# BIN-NEXT:        Body:            20002580808080000B
177# BIN-NEXT:      - Index:           2
178# BIN-NEXT:        Locals:          []
179# BIN-NEXT:        Body:            200020012680808080000B
180# BIN-NEXT:      - Index:           3
181# BIN-NEXT:        Locals:          []
182# BIN-NEXT:        Body:            41002580808080002000FC0F808080800020006A0B
183# BIN-NEXT:      - Index:           4
184# BIN-NEXT:        Locals:          []
185# BIN-NEXT:        Body:            200041002582808080002001FC1182808080000B
186
187#      BIN:  - Type:            CUSTOM
188# BIN-NEXT:    Name:            linking
189# BIN-NEXT:    Version:         2
190# BIN-NEXT:    SymbolTable:
191# BIN-NEXT:      - Index:           0
192# BIN-NEXT:        Kind:            TABLE
193# BIN-NEXT:        Name:            foo
194# BIN-NEXT:        Flags:           [ BINDING_LOCAL ]
195# BIN-NEXT:        Table:           0
196# BIN-NEXT:      - Index:           1
197# BIN-NEXT:        Kind:            TABLE
198# BIN-NEXT:        Name:            bar
199# BIN-NEXT:        Flags:           [ BINDING_LOCAL ]
200# BIN-NEXT:        Table:           1
201# BIN-NEXT:      - Index:           2
202# BIN-NEXT:        Kind:            TABLE
203# BIN-NEXT:        Name:            table1
204# BIN-NEXT:        Flags:           [ BINDING_LOCAL ]
205# BIN-NEXT:        Table:           2
206# BIN-NEXT:      - Index:           3
207# BIN-NEXT:        Kind:            TABLE
208# BIN-NEXT:        Name:            table2
209# BIN-NEXT:        Flags:           [ BINDING_LOCAL ]
210# BIN-NEXT:        Table:           3
211# BIN-NEXT:      - Index:           4
212