Mercurial > hg > CbC > CbC_gcc
comparison CbC-examples/conv1.c @ 119:9d1ff3ae1824
fix conv1 example
author | kono |
---|---|
date | Thu, 08 Mar 2018 12:20:02 +0900 |
parents | 959d4c8c8abc |
children | f93fa5091070 |
comparison
equal
deleted
inserted
replaced
118:fd00160c1b76 | 119:9d1ff3ae1824 |
---|---|
1 #include "stdio.h" | 1 #include "stdio.h" |
2 | |
3 extern int atoi (const char *); | |
2 | 4 |
3 static int loop; | 5 static int loop; |
4 | 6 |
5 #if 1 // def __micro_c__ | 7 #if 1 // def __micro_c__ |
6 #define CC_ONLY 0 | 8 #define CC_ONLY 0 |
7 #else | 9 #else |
8 #define CC_ONLY 1 | 10 #define CC_ONLY 1 |
9 #endif | 11 #endif |
10 | 12 |
11 /* classical function call case (0) */ | 13 /* classical function call case (0) */ |
12 | 14 int g0(int); |
15 int h0(int); | |
16 | |
17 int | |
13 f0(int i) { | 18 f0(int i) { |
14 int k,j; | 19 int k,j; |
15 k = 3+i; | 20 k = 3+i; |
16 j = g0(i+3); | 21 j = g0(i+3); |
17 return k+4+j; | 22 return k+4+j; |
18 } | 23 } |
19 | 24 |
25 int | |
20 g0(int i) { | 26 g0(int i) { |
21 return h0(i+4)+i; | 27 return h0(i+4)+i; |
22 } | 28 } |
23 | 29 |
30 int | |
24 h0(int i) { | 31 h0(int i) { |
25 return i+4; | 32 return i+4; |
26 } | 33 } |
27 | 34 |
28 #if !CC_ONLY | 35 #if !CC_ONLY |
29 | 36 |
30 /* straight conversion case (1) */ | 37 /* straight conversion case (1) */ |
31 | 38 |
32 typedef char *stack; | 39 typedef void *stack; |
33 | 40 |
34 struct cont_interface { // General Return Continuation | 41 struct cont_interface { // General Return Continuation |
35 __code (*ret)(int, void *); | 42 __code (*ret)(int, void *); |
36 }; | 43 }; |
44 | |
45 #ifndef __llvm__ | |
46 __code f_g0(int i,int k,stack sp); | |
47 __code f_g1(int j,stack sp); | |
48 __code g(int i,stack sp); | |
49 __code h(int i,stack sp); | |
50 __code f2(int i,char *sp); | |
51 __code g2(int i,int k,int j,char *sp); | |
52 __code h2(int i,int k,char *sp); | |
53 __code main_return2(int i,stack sp); | |
54 __code g2_1(int k,int i,stack *sp); | |
55 __code h2_11(int i,int k,stack *sp); | |
56 #endif | |
37 | 57 |
38 __code f(int i,stack sp) { | 58 __code f(int i,stack sp) { |
39 int k,j; | 59 int k,j; |
40 k = 3+i; | 60 k = 3+i; |
41 goto f_g0(i,k,sp); | 61 goto f_g0(i,k,sp); |
135 ((struct main_continuation *)sp)->env); | 155 ((struct main_continuation *)sp)->env); |
136 } | 156 } |
137 | 157 |
138 /* little optimizaed case (3) */ | 158 /* little optimizaed case (3) */ |
139 | 159 |
140 __code f2_1(int i,char *sp) { | 160 __code f2_1(int i,stack *sp) { |
141 int k,j; | 161 int k,j; |
142 k = 3+i; | 162 k = 3+i; |
143 goto g2_1(k,i+3,sp); | 163 goto g2_1(k,i+3,sp); |
144 } | 164 } |
145 | 165 |
146 __code g2_1(int k,int i,char *sp) { | 166 __code g2_1(int k,int i,stack *sp) { |
147 goto h2_11(k,i+4,sp); | 167 goto h2_11(k,i+4,sp); |
148 } | 168 } |
149 | 169 |
150 __code f2_0_1(int k,int j,char *sp); | 170 __code f2_0_1(int k,int j,stack *sp); |
151 __code h2_1_1(int i,int k,int j,char *sp) { | 171 __code h2_1_1(int i,int k,int j,stack *sp) { |
152 goto f2_0_1(k,i+j,sp); | 172 goto f2_0_1(k,i+j,sp); |
153 } | 173 } |
154 | 174 |
155 __code h2_11(int i,int k,char *sp) { | 175 __code h2_11(int i,int k,stack *sp) { |
156 goto h2_1_1(i,k,i+4,sp); | 176 goto h2_1_1(i,k,i+4,sp); |
157 } | 177 } |
158 | 178 |
159 __code f2_0_1(int k,int j,char *sp) { | 179 __code f2_0_1(int k,int j,stack *sp) { |
160 goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); | 180 goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); |
161 } | 181 } |
162 | 182 |
163 __code main_return2_1(int i,stack sp) { | 183 __code main_return2_1(int i,stack sp) { |
164 if (loop-->0) | 184 if (loop-->0) |
174 | 194 |
175 #endif | 195 #endif |
176 | 196 |
177 #define LOOP_COUNT 10000000 | 197 #define LOOP_COUNT 10000000 |
178 | 198 |
199 int | |
179 main(int ac,char *av[]) | 200 main(int ac,char *av[]) |
180 { | 201 { |
181 #if !CC_ONLY | 202 #if !CC_ONLY |
182 struct main_continuation *cont; | 203 struct main_continuation *cont; |
183 stack sp = stack_last; | 204 stack sp = stack_last; |