]> git.proxmox.com Git - rustc.git/blob - src/binaryen/test/control_flow.cpp
New upstream version 1.23.0+dfsg1
[rustc.git] / src / binaryen / test / control_flow.cpp
1 #include <cmath>
2 #include <algorithm>
3 #include <emscripten.h>
4
5 extern "C" {
6
7 int EMSCRIPTEN_KEEPALIVE check_if(int x) {
8 if (x < 10) x++;
9 return x;
10 }
11
12 int EMSCRIPTEN_KEEPALIVE check_loop(int x) {
13 while (x < 100) x *= 2;
14 return x;
15 }
16
17 int EMSCRIPTEN_KEEPALIVE check_loop_break(int x) {
18 while (x < 100) {
19 x *= 2;
20 if (x > 30) break;
21 x++;
22 }
23 return x;
24 }
25
26 int EMSCRIPTEN_KEEPALIVE check_loop_continue(int x) {
27 while (x < 100) {
28 x *= 2;
29 if (x > 30) continue;
30 x++;
31 }
32 return x;
33 }
34
35 int EMSCRIPTEN_KEEPALIVE check_do_loop(int x) {
36 do {
37 x *= 2;
38 if (x > 1000) break;
39 x--;
40 if (x > 30) continue;
41 x++;
42 } while (x < 100);
43 return x;
44 }
45
46 int EMSCRIPTEN_KEEPALIVE check_do_once(int x) {
47 do {
48 x *= 2;
49 if (x > 1000) break;
50 x--;
51 if (x > 30) continue;
52 x++;
53 } while (0);
54 return x;
55 }
56
57 int EMSCRIPTEN_KEEPALIVE check_while_forever(int x) {
58 while (1) {
59 x *= 2;
60 if (x > 1000) break;
61 x--;
62 if (x > 30) continue;
63 x++;
64 }
65 return x;
66 }
67
68 int EMSCRIPTEN_KEEPALIVE check_switch(int x) {
69 switch (x) {
70 case 1: return 10;
71 case 3: return 20;
72 case 5: return 30;
73 case 10: return 40;
74 case 11: return 50;
75 default: return 60;
76 }
77 return 70;
78 }
79
80 int EMSCRIPTEN_KEEPALIVE check_switch_nodefault(int x) {
81 switch (x) {
82 case 1: return 10;
83 case 3: return 20;
84 case 5: return 30;
85 case 10: return 40;
86 case 11: return 50;
87 }
88 return 70;
89 }
90
91 int EMSCRIPTEN_KEEPALIVE check_switch_rdefault(int x) {
92 switch (x) {
93 default: return -60;
94 case 1: return 10;
95 case 3: return 20;
96 case 5: return 30;
97 case 10: return 40;
98 case 11: return 50;
99 }
100 return 70;
101 }
102
103 int EMSCRIPTEN_KEEPALIVE check_switch_fallthrough(int x) {
104 switch (x) {
105 case 1: return 10;
106 case 2:
107 case 3: x++;
108 case 5: return x;
109 case 10: return 40;
110 case 11: return 50;
111 default: return 60;
112 }
113 return 70;
114 }
115
116 }
117