xref: /llvm-project/llvm/test/MC/WebAssembly/wasm64.s (revision c5c4ba37b19e14f3f4c9c1bf950d46e90602c084)
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
123# CHECK:              .section        .rodata..L.str,"",@
124# CHECK-NEXT:         .hidden .L.str
125# CHECK-NEXT: .L.str:
126# CHECK-NEXT:         .asciz  "Hello, World!!!"
127# CHECK-NEXT:         .int64      .L.str
128# CHECK-NEXT:         .size       .L.str, 24
129
130
131
132# BIN:      --- !WASM
133# BIN-NEXT: FileHeader:
134# BIN-NEXT:   Version:         0x1
135# BIN-NEXT: Sections:
136# BIN-NEXT:   - Type:            TYPE
137# BIN-NEXT:     Signatures:
138# BIN-NEXT:       - Index:           0
139# BIN-NEXT:         ParamTypes:
140# BIN-NEXT:           - I64
141# BIN-NEXT:         ReturnTypes:     []
142# BIN-NEXT:   - Type:            IMPORT
143# BIN-NEXT:     Imports:
144# BIN-NEXT:       - Module:          env
145# BIN-NEXT:         Field:           __linear_memory
146# BIN-NEXT:         Kind:            MEMORY
147# BIN-NEXT:         Memory:
148# BIN-NEXT:           Flags:           [ IS_64 ]
149# BIN-NEXT:           Minimum:         0x1
150# BIN-NEXT:       - Module:          env
151# BIN-NEXT:         Field:           myglob64
152# BIN-NEXT:         Kind:            GLOBAL
153# BIN-NEXT:         GlobalType:      I64
154# BIN-NEXT:         GlobalMutable:   true
155# BIN-NEXT:       - Module:          env
156# BIN-NEXT:         Field:           __stack_pointer
157# BIN-NEXT:         Kind:            GLOBAL
158# BIN-NEXT:         GlobalType:      I64
159# BIN-NEXT:         GlobalMutable:   true
160# BIN-NEXT:   - Type:            FUNCTION
161# BIN-NEXT:     FunctionTypes:   [ 0 ]
162# BIN-NEXT:   - Type:            DATACOUNT
163# BIN-NEXT:     Count:           1
164# BIN-NEXT:   - Type:            CODE
165# BIN-NEXT:     Relocations:
166# BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB64
167# BIN-NEXT:         Index:           1
168# BIN-NEXT:         Offset:          0x13
169# BIN-NEXT:       - Type:            R_WASM_GLOBAL_INDEX_LEB
170# BIN-NEXT:         Index:           2
171# BIN-NEXT:         Offset:          0x22
172# BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_LEB64
173# BIN-NEXT:         Index:           1
174# BIN-NEXT:         Offset:          0x2F
175# BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB64
176# BIN-NEXT:         Index:           1
177# BIN-NEXT:         Offset:          0x4F
178# BIN-NEXT:       - Type:            R_WASM_GLOBAL_INDEX_LEB
179# BIN-NEXT:         Index:           2
180# BIN-NEXT:         Offset:          0x62
181# BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_LEB64
182# BIN-NEXT:         Index:           1
183# BIN-NEXT:         Offset:          0x78
184# BIN-NEXT:       - Type: R_WASM_GLOBAL_INDEX_LEB
185# BIN-NEXT:         Index: 3
186# BIN-NEXT:         Offset: 0x83
187# BIN-NEXT:     Functions:
188# BIN-NEXT:       - Index:           0
189# BIN-NEXT:         Locals:
190# BIN-NEXT:           - Type:            I64
191# BIN-NEXT:             Count:           1
192# BIN-NEXT:         Body:            42002A02001A20002A02001A42808080808080808080002A02001A2380808080002A02001A42002A02808080808080808080001A4200430000000038020020004300000000380200428080808080808080800043000000003802002380808080004300000000380200420043000000003802808080808080808080002381808080001A0B
193# BIN-NEXT:   - Type:            DATA
194# BIN-NEXT:     Relocations:
195# BIN-NEXT:       - Type:            R_WASM_MEMORY_ADDR_I64
196# BIN-NEXT:         Index:           1
197# BIN-NEXT:         Offset:          0x16
198# BIN-NEXT:     Segments:
199# BIN-NEXT:       - SectionOffset:   6
200# BIN-NEXT:         InitFlags:       0
201# BIN-NEXT:         Offset:
202# BIN-NEXT:           Opcode:          I64_CONST
203# BIN-NEXT:           Value:           0
204# BIN-NEXT:         Content:         48656C6C6F2C20576F726C64212121000000000000000000
205# BIN-NEXT:   - Type:            CUSTOM
206# BIN-NEXT:     Name:            linking
207# BIN-NEXT:     Version:         2
208# BIN-NEXT:     SymbolTable:
209# BIN-NEXT:       - Index:           0
210# BIN-NEXT:         Kind:            FUNCTION
211# BIN-NEXT:         Name:            test
212# BIN-NEXT:         Flags:           [ BINDING_LOCAL ]
213# BIN-NEXT:         Function:        0
214# BIN-NEXT:       - Index:           1
215# BIN-NEXT:         Kind:            DATA
216# BIN-NEXT:         Name:            .L.str
217# BIN-NEXT:         Flags:           [ BINDING_LOCAL, VISIBILITY_HIDDEN ]
218# BIN-NEXT:         Segment:         0
219# BIN-NEXT:         Size:            24
220# BIN-NEXT:       - Index:           2
221# BIN-NEXT:         Kind:            GLOBAL
222# BIN-NEXT:         Name:            myglob64
223# BIN-NEXT:         Flags:           [ UNDEFINED ]
224# BIN-NEXT:         Global:          0
225# BIN-NEXT:       - Index:           3
226# BIN-NEXT:         Kind:            GLOBAL
227# BIN-NEXT:         Name:            __stack_pointer
228# BIN-NEXT:         Flags:           [ UNDEFINED ]
229# BIN-NEXT:         Global:          1
230# BIN-NEXT:     SegmentInfo:
231# BIN-NEXT:       - Index:           0
232# BIN-NEXT:         Name:            .rodata..L.str
233# BIN-NEXT:         Alignment:       0
234# BIN-NEXT:         Flags:           [  ]
235# BIN-NEXT: ...
236