qsym

A symbolic executor for the QBE intermediate language

git clone https://git.8pit.net/qsym.git

 1export
 2function w $first_divisor(w %.1) {
 3@start.1
 4	%.2 =l alloc4 4
 5	storew %.1, %.2
 6	%.3 =l alloc4 4
 7@body.2
 8	storew 2, %.3
 9@for_cond.3
10	%.4 =w loadw %.3
11	%.5 =w loadw %.2
12	%.6 =w cultw %.4, %.5
13	jnz %.6, @for_body.4, @for_join.6
14@for_body.4
15	%.7 =w loadw %.2
16	%.8 =w loadw %.3
17	%.9 =w urem %.7, %.8
18	%.10 =w ceqw %.9, 0
19	jnz %.10, @if_true.7, @if_false.8
20@if_true.7
21	%.11 =w loadw %.3
22	ret %.11
23@if_false.8
24@for_cont.5
25	%.12 =w loadw %.3
26	%.13 =w add %.12, 1
27	storew %.13, %.3
28	jmp @for_cond.3
29@for_join.6
30	%.14 =w loadw %.2
31	ret %.14
32}
33export
34function w $main(w %.1) {
35@start.9
36	%.2 =l alloc4 4
37	storew %.1, %.2
38@body.10
39	%.3 =w loadw %.2
40	%.4 =w culew %.3, 10
41	jnz %.4, @if_true.11, @if_false.12
42@if_true.11
43	%.5 =w loadw %.2
44	%.6 =w cugtw %.5, 1
45	jnz %.6, @logic_right.13, @logic_join.14
46@logic_right.13
47	%.7 =w loadw %.2
48	%.8 =w call $first_divisor(w %.7)
49	%.9 =w loadw %.2
50	%.10 =w ceqw %.8, %.9
51	%.11 =w cnew %.10, 0
52@logic_join.14
53	%.12 =w phi @if_true.11 0, @logic_right.13 %.11
54	jnz %.12, @if_true.15, @if_false.16
55@if_true.15
56	hlt
57@if_false.16
58	ret 0
59@if_join.17
60@if_false.12
61	ret 0
62}