Skip to content

Commit b91709a

Browse files
authored
update control case (#12)
1 parent b2acde2 commit b91709a

File tree

5 files changed

+335
-0
lines changed

5 files changed

+335
-0
lines changed

test/control/case_spec.md

Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
## control testcase spec
2+
### tri_if_001
3+
``` c
4+
int getVal (int a, int b) {
5+
int res = (a + 1) * b;
6+
return res;
7+
}
8+
int main (void) {
9+
int res = 0;
10+
int cond = getVal(7, 10);
11+
if(cond > 10) {
12+
if (cond > 20) {
13+
if (cond > 30) {
14+
res = 30;
15+
} else {
16+
res = 25;
17+
}
18+
} else {
19+
res = 15;
20+
}
21+
}else {
22+
res = 5;
23+
}
24+
return res;
25+
}
26+
```
27+
28+
``` wasm
29+
(module
30+
(table 0 anyfunc)
31+
(memory $0 1)
32+
(export "memory" (memory $0))
33+
(export "getVal" (func $getVal))
34+
(export "main" (func $main))
35+
(func $getVal (; 0 ;) (param $0 i32) (param $1 i32) (result i32)
36+
(i32.mul
37+
(i32.add
38+
(get_local $0)
39+
(i32.const 1)
40+
)
41+
(get_local $1)
42+
)
43+
)
44+
(func $main (; 1 ;) (result i32)
45+
(local $0 i32)
46+
(local $1 i32)
47+
(set_local $1
48+
(i32.const 5)
49+
)
50+
(block $label$0
51+
(br_if $label$0
52+
(i32.lt_s
53+
(tee_local $0
54+
(call $getVal
55+
(i32.const 7)
56+
(i32.const 10)
57+
)
58+
)
59+
(i32.const 11)
60+
)
61+
)
62+
(set_local $1
63+
(i32.const 15)
64+
)
65+
(br_if $label$0
66+
(i32.lt_s
67+
(get_local $0)
68+
(i32.const 21)
69+
)
70+
)
71+
(set_local $1
72+
(select
73+
(i32.const 30)
74+
(i32.const 25)
75+
(i32.gt_s
76+
(get_local $0)
77+
(i32.const 30)
78+
)
79+
)
80+
)
81+
)
82+
(get_local $1)
83+
)
84+
)
85+
86+
```
87+
### tri_if_002
88+
``` c
89+
int getVal (int a, int b) {
90+
int res = (a + 1) * b;
91+
return res;
92+
}
93+
int main (void) {
94+
int res = 0;
95+
int cond = getVal(4, 10);
96+
if(cond > 100) {
97+
res = 100;
98+
} else if (cond > 90) {
99+
res = 90;
100+
} else if ( cond > 80) {
101+
res = 80;
102+
} else {
103+
res = 60;
104+
}
105+
return res;
106+
}
107+
```
108+
109+
``` wasm
110+
(module
111+
(table 0 anyfunc)
112+
(memory $0 1)
113+
(export "memory" (memory $0))
114+
(export "getVal" (func $getVal))
115+
(export "main" (func $main))
116+
(func $getVal (; 0 ;) (param $0 i32) (param $1 i32) (result i32)
117+
(i32.mul
118+
(i32.add
119+
(get_local $0)
120+
(i32.const 1)
121+
)
122+
(get_local $1)
123+
)
124+
)
125+
(func $main (; 1 ;) (result i32)
126+
(local $0 i32)
127+
(local $1 i32)
128+
(set_local $1
129+
(i32.const 100)
130+
)
131+
(block $label$0
132+
(br_if $label$0
133+
(i32.gt_s
134+
(tee_local $0
135+
(call $getVal
136+
(i32.const 4)
137+
(i32.const 10)
138+
)
139+
)
140+
(i32.const 100)
141+
)
142+
)
143+
(set_local $1
144+
(i32.const 90)
145+
)
146+
(br_if $label$0
147+
(i32.gt_s
148+
(get_local $0)
149+
(i32.const 90)
150+
)
151+
)
152+
(set_local $1
153+
(select
154+
(i32.const 80)
155+
(i32.const 60)
156+
(i32.gt_s
157+
(get_local $0)
158+
(i32.const 80)
159+
)
160+
)
161+
)
162+
)
163+
(get_local $1)
164+
)
165+
)
166+
167+
```
168+
169+
### loop_001
170+
``` c
171+
int getVal (int a, int b) {
172+
int res = (a + 1) * b;
173+
return res;
174+
}
175+
int main (void) {
176+
int res = 0;
177+
int cond = getVal(4, 10);
178+
for (int i = 0; i < cond; i++) {
179+
res = 10 * i + 1;
180+
}
181+
return res;
182+
}
183+
```
184+
185+
``` wasm
186+
(module
187+
(table 0 anyfunc)
188+
(memory $0 1)
189+
(export "memory" (memory $0))
190+
(export "getVal" (func $getVal))
191+
(export "main" (func $main))
192+
(func $getVal (; 0 ;) (param $0 i32) (param $1 i32) (result i32)
193+
(i32.mul
194+
(i32.add
195+
(get_local $0)
196+
(i32.const 1)
197+
)
198+
(get_local $1)
199+
)
200+
)
201+
(func $main (; 1 ;) (result i32)
202+
(local $0 i32)
203+
(block $label$0
204+
(br_if $label$0
205+
(i32.lt_s
206+
(tee_local $0
207+
(call $getVal
208+
(i32.const 4)
209+
(i32.const 10)
210+
)
211+
)
212+
(i32.const 1)
213+
)
214+
)
215+
(return
216+
(i32.or
217+
(i32.add
218+
(i32.mul
219+
(get_local $0)
220+
(i32.const 10)
221+
)
222+
(i32.const -10)
223+
)
224+
(i32.const 1)
225+
)
226+
)
227+
)
228+
(i32.const 0)
229+
)
230+
)
231+
```
232+
### switch_case_001
233+
``` c
234+
int getVal (int a, int b) {
235+
int res = (a + 1) * b;
236+
return res;
237+
}
238+
int main (void) {
239+
int res = 0;
240+
int cond = getVal(4, 10);
241+
switch (cond) {
242+
case 10:
243+
res = 10;
244+
break;
245+
case 20:
246+
res = 21;
247+
break;
248+
case 30:
249+
res = 32;
250+
break;
251+
case 40:
252+
case 50:
253+
case 60:
254+
res = 65;
255+
break;
256+
case 70:
257+
res = 79;
258+
break;
259+
default:
260+
res = 80;
261+
}
262+
return res;
263+
}
264+
```
265+
266+
``` wasm
267+
(module
268+
(table 0 anyfunc)
269+
(memory $0 1)
270+
(export "memory" (memory $0))
271+
(export "getVal" (func $getVal))
272+
(export "main" (func $main))
273+
(func $getVal (; 0 ;) (param $0 i32) (param $1 i32) (result i32)
274+
(i32.mul
275+
(i32.add
276+
(get_local $0)
277+
(i32.const 1)
278+
)
279+
(get_local $1)
280+
)
281+
)
282+
(func $main (; 1 ;) (result i32)
283+
(local $0 i32)
284+
(local $1 i32)
285+
(set_local $1
286+
(i32.const 10)
287+
)
288+
(block $label$0
289+
(block $label$1
290+
(block $label$2
291+
(block $label$3
292+
(block $label$4
293+
(br_if $label$4
294+
(i32.gt_u
295+
(tee_local $0
296+
(i32.add
297+
(call $getVal
298+
(i32.const 4)
299+
(i32.const 10)
300+
)
301+
(i32.const -10)
302+
)
303+
)
304+
(i32.const 60)
305+
)
306+
)
307+
(block $label$5
308+
(br_table $label$3 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$2 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$0 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$5 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$5 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$5 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$4 $label$1 $label$3
309+
(get_local $0)
310+
)
311+
)
312+
(return
313+
(i32.const 65)
314+
)
315+
)
316+
(set_local $1
317+
(i32.const 80)
318+
)
319+
)
320+
(return
321+
(get_local $1)
322+
)
323+
)
324+
(return
325+
(i32.const 21)
326+
)
327+
)
328+
(return
329+
(i32.const 79)
330+
)
331+
)
332+
(i32.const 32)
333+
)
334+
)
335+
```

test/control/loop_001.wasm

153 Bytes
Binary file not shown.

test/control/switch_case_001.wasm

248 Bytes
Binary file not shown.

test/control/tri_if_001.wasm

168 Bytes
Binary file not shown.

test/control/tri_if_002.wasm

174 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)