1# RUN: llvm-mc -triple=wasm64-unknown-unknown -mattr=+atomics,+simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s
2# RUN: llvm-mc -triple=wasm64-unknown-unknown -filetype=obj -mattr=+atomics,+simd128,+nontrapping-fptoint,+exception-handling -o - < %s | obj2yaml | FileCheck %s -check-prefix=BIN
3
4# Most of our other tests are for wasm32, this one adds some wasm64 specific tests.
5
6.globaltype myglob64, i64
7.globaltype __stack_pointer, i64
8
9test:
10    .functype   test (i64) -> ()
11    .local      i64
12
13    ### basic loads
14
15    i64.const   0         # get i64 from constant.
16    f32.load    0
17    drop
18
19    local.get   0         # get i64 from local.
20    f32.load    0
21    drop
22
23    i64.const   .L.str    # get i64 relocatable.
24    f32.load    0
25    drop
26
27    global.get  myglob64  # get i64 from global
28    f32.load    0
29    drop
30
31    i64.const   0
32    f32.load    .L.str    # relocatable offset!
33    drop
34
35    ### basic stores
36
37    i64.const   0         # get i64 from constant.
38    f32.const   0.0
39    f32.store   0
40
41    local.get   0         # get i64 from local.
42    f32.const   0.0
43    f32.store   0
44
45    i64.const   .L.str    # get i64 relocatable.
46    f32.const   0.0
47    f32.store   0
48
49    global.get  myglob64  # get i64 from global
50    f32.const   0.0
51    f32.store   0
52
53    i64.const   0
54    f32.const   0.0
55    f32.store   .L.str    # relocatable offset!
56
57    ### 64-bit SP
58
59    global.get  __stack_pointer
60    drop
61
62    end_function
63
64    .section    .rodata..L.str,"",@
65    .hidden     .L.str
66    .type       .L.str,@object
67.L.str:
68    .asciz      "Hello, World!!!"
69    .int64      .L.str    # relocatable inside data.
70    .size       .L.str, 24
71
72
73# CHECK:              .globaltype     myglob64, i64
74
75# CHECK:              .functype       test (i64) -> ()
76# CHECK-NEXT:         .local          i64
77
78
79# CHECK:              i64.const       0
80# CHECK-NEXT:         f32.load        0
81# CHECK-NEXT:         drop
82
83# CHECK:              local.get       0
84# CHECK-NEXT:         f32.load        0
85# CHECK-NEXT:         drop
86
87# CHECK:              i64.const       .L.str
88# CHECK-NEXT:         f32.load        0
89# CHECK-NEXT:         drop
90
91# CHECK:              global.get      myglob64
92# CHECK-NEXT:         f32.load        0
93# CHECK-NEXT:         drop
94
95# CHECK:              i64.const       0
96# CHECK-NEXT:         f32.load        .L.str
97# CHECK-NEXT:         drop
98
99
100# CHECK:              i64.const       0
101# CHECK-NEXT:         f32.const       0x0p0
102# CHECK-NEXT:         f32.store       0
103
104# CHECK:              local.get       0
105# CHECK-NEXT:         f32.const       0x0p0
106# CHECK-NEXT:         f32.store       0
107
108# CHECK:              i64.const       .L.str
109# CHECK-NEXT:         f32.const       0x0p0
110# CHECK-NEXT:         f32.store       0
111
112# CHECK:              global.get      myglob64
113# CHECK-NEXT:         f32.const       0x0p0
114# CHECK-NEXT:         f32.store       0
115
116# CHECK:              i64.const       0
117# CHECK-NEXT:         f32.const       0x0p0
118# CHECK-NEXT:         f32.store       .L.str
119
120
121# CHECK:              end_function
122# CHECK-NEXT: .Ltmp0:
123# CHECK-NEXT:         .size   test, .Ltmp0-test
124
125# CHECK:              .section        .rodata..L.str,"",@
126# CHECK-NEXT:         .hidden .L.str
127# CHECK-NEXT: .L.str:
128# CHECK-NEXT:         .asciz  "Hello, World!!!"
129# CHECK-NEXT:         .int64      .L.str
130# CHECK-NEXT:         .size       .L.str, 24
131
132
133
134# BIN:      --- !WASM
135# BIN-NEXT: FileHeader:
136# BIN-NEXT:   Version:         0x1
137# BIN-NEXT: Sections:
138# BIN-NEXT:   - Type:            TYPE
139# BIN-NEXT:     Signatures:
140# BIN-NEXT:       - Index:           0
141# BIN-NEXT:         ParamTypes:
142# BIN-NEXT:           - I64
143# BIN-NEXT:         ReturnTypes:     []
144# BIN-NEXT:   - Type:            IMPORT
145# BIN-NEXT:     Imports:
146# BIN-NEXT:       - Module:          env
147# BIN-NEXT:         Field:           __linear_memory
148# BIN-NEXT:         Kind:            MEMORY
149# BIN-NEXT:         Memory:
150# BIN-NEXT:           Flags:           [ IS_64 ]
151# BIN-NEXT:           Minimum:         0x1
152# BIN-NEXT:       - Module:          env
153# BIN-NEXT:         Field:           myglob64
154# BIN-NEXT:         Kind:            GLOBAL
155# BIN-NEXT:         GlobalType:      I64
156# BIN-NEXT:         GlobalMutable:   true
157# BIN-NEXT:       - Module:          env
158# BIN-NEXT:         Field:           __stack_pointer
159# BIN-NEXT:         Kind:            GLOBAL
160# BIN-NEXT:         GlobalType:      I64
161# BIN-NEXT:         GlobalMutable:   true
162# BIN-NEXT:   - Type:            FUNCTION
163# BIN-NEXT:     FunctionTypes:   [ 0 ]
164# BIN-NEXT:   - Type:            DATACOUNT
165# BIN-NEXT:     Count:           1
166# BIN-NEXT:   - Type:            CODE
167# BIN-NEXT:     Relocations:
168# BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB64
169# BIN-NEXT:         Index:           1
170# BIN-NEXT:         Offset:          0x13
171# BIN-NEXT:       - Type:            R_WASM_GLOBAL_INDEX_LEB
172# BIN-NEXT:         Index:           2
173# BIN-NEXT:         Offset:          0x22
174# BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_LEB64
175# BIN-NEXT:         Index:           1
176# BIN-NEXT:         Offset:          0x2F
177# BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB64
178# BIN-NEXT:         Index:           1
179# BIN-NEXT:         Offset:          0x4F
180# BIN-NEXT:       - Type:            R_WASM_GLOBAL_INDEX_LEB
181# BIN-NEXT:         Index:           2
182# BIN-NEXT:         Offset:          0x62
183# BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_LEB64
184# BIN-NEXT:         Index:           1
185# BIN-NEXT:         Offset:          0x78
186# BIN-NEXT:       - Type: R_WASM_GLOBAL_INDEX_LEB
187# BIN-NEXT:         Index: 3
188# BIN-NEXT:         Offset: 0x83
189# BIN-NEXT:     Functions:
190# BIN-NEXT:       - Index:           0
191# BIN-NEXT:         Locals:
192# BIN-NEXT:           - Type:            I64
193# BIN-NEXT:             Count:           1
194# BIN-NEXT:         Body:            42002A02001A20002A02001A42808080808080808080002A02001A2380808080002A02001A42002A02808080808080808080001A4200430000000038020020004300000000380200428080808080808080800043000000003802002380808080004300000000380200420043000000003802808080808080808080002381808080001A0B
195# BIN-NEXT:   - Type:            DATA
196# BIN-NEXT:     Relocations:
197# BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_I64
198# BIN-NEXT:         Index:           1
199# BIN-NEXT:         Offset:          0x16
200# BIN-NEXT:     Segments:
201# BIN-NEXT:       - SectionOffset:   6
202# BIN-NEXT:         InitFlags:       0
203# BIN-NEXT:         Offset:
204# BIN-NEXT:           Opcode:          I64_CONST
205# BIN-NEXT:           Value:           0
206# BIN-NEXT:         Content:         48656C6C6F2C20576F726C64212121000000000000000000
207# BIN-NEXT:   - Type:            CUSTOM
208# BIN-NEXT:     Name:            linking
209# BIN-NEXT:     Version:         2
210# BIN-NEXT:     SymbolTable:
211# BIN-NEXT:       - Index:           0
212# BIN-NEXT:         Kind:            FUNCTION
213# BIN-NEXT:         Name:            test
214# BIN-NEXT:         Flags:           [ BINDING_LOCAL ]
215# BIN-NEXT:         Function:        0
216# BIN-NEXT:       - Index:           1
217# BIN-NEXT:         Kind:            DATA
218# BIN-NEXT:         Name:            .L.str
219# BIN-NEXT:         Flags:           [ BINDING_LOCAL, VISIBILITY_HIDDEN ]
220# BIN-NEXT:         Segment:         0
221# BIN-NEXT:         Size:            24
222# BIN-NEXT:       - Index:           2
223# BIN-NEXT:         Kind:            GLOBAL
224# BIN-NEXT:         Name:            myglob64
225# BIN-NEXT:         Flags:           [ UNDEFINED ]
226# BIN-NEXT:         Global:          0
227# BIN-NEXT:       - Index:           3
228# BIN-NEXT:         Kind:            GLOBAL
229# BIN-NEXT:         Name:            __stack_pointer
230# BIN-NEXT:         Flags:           [ UNDEFINED ]
231# BIN-NEXT:         Global:          1
232# BIN-NEXT:     SegmentInfo:
233# BIN-NEXT:       - Index:           0
234# BIN-NEXT:         Name:            .rodata..L.str
235# BIN-NEXT:         Alignment:       0
236# BIN-NEXT:         Flags:           [  ]
237# BIN-NEXT: ...
238