• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+atomics,+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s
2# Check that it converts to .o without errors, but don't check any output:
3# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+atomics,+unimplemented-simd128,+nontrapping-fptoint,+exception-handling -o %t.o < %s
4
5
6empty_func:
7    .functype empty_func () -> ()
8    end_function
9
10test0:
11    # Test all types:
12    .functype   test0 (i32, i64) -> (i32)
13    .eventtype  __cpp_exception i32
14    .local      f32, f64, v128, v128
15    # Explicit getlocal/setlocal:
16    local.get   2
17    local.set   2
18    # Immediates:
19    i32.const   -1
20    f64.const   0x1.999999999999ap1
21    f32.const   -1.0
22    f32.const   -infinity
23    f32.const   nan
24    v128.const  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
25    v128.const  0, 1, 2, 3, 4, 5, 6, 7
26    # Indirect addressing:
27    local.get   0
28    f64.store   1234:p2align=4
29    f64.store   1234     # Natural alignment (3)
30    # Loops, conditionals, binary ops, calls etc:
31    block       i32
32    i32.const   1
33    local.get   0
34    i32.ge_s
35    br_if       0        # 0: down to label0
36.LBB0_1:
37    loop        i32      # label1:
38    call        something1
39    i64.const   1234
40    call        something2
41    i32.const   0
42    call_indirect (i32, f64) -> ()
43    i32.const   1
44    i32.add
45    local.tee   0
46    local.get   0
47    i32.lt_s
48    br_if       0        # 0: up to label1
49.LBB0_2:
50    end_loop
51    end_block            # label0:
52    local.get   4
53    local.get   5
54    block       void
55    block       i64
56    block       f32
57    block       f64
58    block       () -> (i32, i32)
59    i32.const   1
60    i32.const   2
61    end_block
62    drop
63    drop
64    br_table {0, 1, 2}   # 2 entries, default
65    end_block            # first entry jumps here.
66    i32.const   1
67    br          2
68    end_block            # second entry jumps here.
69    i32.const   2
70    br          1
71    end_block            # default jumps here.
72    i32.const   3
73    end_block            # "switch" exit.
74    if                   # void
75    if          i32
76    end_if
77    else
78    end_if
79    f32x4.add
80    # Test correct parsing of instructions with / and : in them:
81    # TODO: enable once instruction has been added.
82    #i32x4.trunc_sat_f32x4_s
83    i32.trunc_f32_s
84    try         exnref
85    i32.atomic.load 0
86    memory.atomic.notify 0
87.LBB0_3:
88    catch
89    local.set   0
90    block       i32
91    local.get   0
92    br_on_exn   0, __cpp_exception
93    rethrow
94.LBB0_4:
95    end_block
96    end_try
97    i32.const   .L.str
98    i32.load8_u .L.str+2
99    i32.load16_u .L.str:p2align=0
100    throw 0
101.LBB0_5:
102    #i32.trunc_sat_f32_s
103    global.get  __stack_pointer
104    end_function
105
106    .section    .rodata..L.str,"",@
107    .hidden     .L.str
108    .type       .L.str,@object
109.L.str:
110    .int8       'H'
111    .asciz      "ello, World!"
112    .int16      1234
113    .int64      5000000000
114    .int32      2000000000
115    .size       .L.str, 28
116
117    .section    .init_array.42,"",@
118    .p2align    2
119    .int32      test0
120
121    .ident      "clang version 9.0.0 (trunk 364502) (llvm/trunk 364571)"
122    .globaltype __stack_pointer, i32
123
124.tabletype empty_eref_table, externref
125empty_eref_table:
126
127.tabletype empty_fref_table, funcref
128empty_fref_table:
129
130
131# CHECK:           .text
132# CHECK-LABEL: empty_func:
133# CHECK-NEXT:      .functype	empty_func () -> ()
134# CHECK-NEXT:      end_function
135# CHECK-LABEL: test0:
136# CHECK-NEXT:      .functype   test0 (i32, i64) -> (i32)
137# CHECK-NEXT:      .eventtype  __cpp_exception i32
138# CHECK-NEXT:      .local      f32, f64
139# CHECK-NEXT:      local.get   2
140# CHECK-NEXT:      local.set   2
141# CHECK-NEXT:      i32.const   -1
142# CHECK-NEXT:      f64.const   0x1.999999999999ap1
143# CHECK-NEXT:      f32.const   -0x1p0
144# CHECK-NEXT:      f32.const   -infinity
145# CHECK-NEXT:      f32.const   nan
146# CHECK-NEXT:      v128.const  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
147# CHECK-NEXT:      v128.const  0, 1, 2, 3, 4, 5, 6, 7
148# CHECK-NEXT:      local.get   0
149# CHECK-NEXT:      f64.store   1234:p2align=4
150# CHECK-NEXT:      f64.store   1234
151# CHECK-NEXT:      block       i32
152# CHECK-NEXT:      i32.const   1
153# CHECK-NEXT:      local.get   0
154# CHECK-NEXT:      i32.ge_s
155# CHECK-NEXT:      br_if       0       # 0: down to label0
156# CHECK-NEXT:  .LBB0_1:
157# CHECK-NEXT:      loop        i32     # label1:
158# CHECK-NEXT:      call        something1
159# CHECK-NEXT:      i64.const   1234
160# CHECK-NEXT:      call        something2
161# CHECK-NEXT:      i32.const   0
162# CHECK-NEXT:      call_indirect (i32, f64) -> ()
163# CHECK-NEXT:      i32.const   1
164# CHECK-NEXT:      i32.add
165# CHECK-NEXT:      local.tee   0
166# CHECK-NEXT:      local.get   0
167# CHECK-NEXT:      i32.lt_s
168# CHECK-NEXT:      br_if       0       # 0: up to label1
169# CHECK-NEXT:  .LBB0_2:
170# CHECK-NEXT:      end_loop
171# CHECK-NEXT:      end_block           # label0:
172# CHECK-NEXT:      local.get   4
173# CHECK-NEXT:      local.get   5
174# CHECK-NEXT:      block
175# CHECK-NEXT:      block       i64
176# CHECK-NEXT:      block       f32
177# CHECK-NEXT:      block       f64
178# CHECK-NEXT:      block       () -> (i32, i32)
179# CHECK-NEXT:      i32.const   1
180# CHECK-NEXT:      i32.const   2
181# CHECK-NEXT:      end_block
182# CHECK-NEXT:      drop
183# CHECK-NEXT:      drop
184# CHECK-NEXT:      br_table {0, 1, 2}  # 1: down to label4
185# CHECK-NEXT:                          # 2: down to label3
186# CHECK-NEXT:      end_block           # label5:
187# CHECK-NEXT:      i32.const   1
188# CHECK-NEXT:      br          2       # 2: down to label2
189# CHECK-NEXT:      end_block           # label4:
190# CHECK-NEXT:      i32.const   2
191# CHECK-NEXT:      br          1       # 1: down to label2
192# CHECK-NEXT:      end_block           # label3:
193# CHECK-NEXT:      i32.const   3
194# CHECK-NEXT:      end_block           # label2:
195# CHECK-NEXT:      if
196# CHECK-NEXT:      if          i32
197# CHECK-NEXT:      end_if
198# CHECK-NEXT:      else
199# CHECK-NEXT:      end_if
200# CHECK-NEXT:      f32x4.add
201# CHECK-NEXT:      i32.trunc_f32_s
202# CHECK-NEXT:      try         exnref
203# CHECK-NEXT:      i32.atomic.load 0
204# CHECK-NEXT:      memory.atomic.notify 0
205# CHECK-NEXT:  .LBB0_3:
206# CHECK-NEXT:      catch
207# CHECK-NEXT:      local.set   0
208# CHECK-NEXT:      block       i32
209# CHECK-NEXT:      local.get   0
210# CHECK-NEXT:      br_on_exn   0, __cpp_exception
211# CHECK-NEXT:      rethrow
212# CHECK-NEXT:  .LBB0_4:
213# CHECK-NEXT:      end_block
214# CHECK-NEXT:      end_try
215# CHECK-NEXT:      i32.const   .L.str
216# CHECK-NEXT:      i32.load8_u .L.str+2
217# CHECK-NEXT:      i32.load16_u .L.str:p2align=0
218# CHECK-NEXT:      throw       0
219# CHECK-NEXT:  .LBB0_5:
220# CHECK-NEXT:      global.get  __stack_pointer
221# CHECK-NEXT:      end_function
222
223# CHECK:           .section    .rodata..L.str,"",@
224# CHECK-NEXT:      .hidden     .L.str
225# CHECK-NEXT:  .L.str:
226# CHECK-NEXT:      .int8       72
227# CHECK-NEXT:      .asciz      "ello, World!"
228# CHECK-NEXT:      .int16      1234
229# CHECK-NEXT:      .int64      5000000000
230# CHECK-NEXT:      .int32      2000000000
231# CHECK-NEXT:      .size       .L.str, 28
232
233# CHECK:           .section    .init_array.42,"",@
234# CHECK-NEXT:      .p2align    2
235# CHECK-NEXT:      .int32      test0
236
237# CHECK:           .globaltype __stack_pointer, i32
238
239# CHECK:           .tabletype empty_eref_table, externref
240# CHECK-NEXT: empty_eref_table:
241
242# CHECK:           .tabletype empty_fref_table, funcref
243# CHECK-NEXT: empty_fref_table:
244