annotate test/conv1.c @ 275:8f09f8bbc494

MIPS switch statement. basic.c passed.
author kono
date Fri, 21 May 2004 14:00:02 +0900
parents 096559f07a70
children 0c256ea2a97e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
1 #include "stdio.h"
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
2
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
3 static int loop;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
4
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
5 #ifdef __micro_c__
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
6 #define CC_ONLY 0
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
7 #else
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
8 #define CC_ONLY 1
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
9 #endif
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
10
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
11 /* classical function call case (0) */
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
12
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
13 f0(int i) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
14 int k,j;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
15 k = 3+i;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
16 j = g0(i+3);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
17 return k+4+j;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
18 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
19
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
20 g0(int i) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
21 return h0(i+4)+i;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
22 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
23
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
24 h0(int i) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
25 return i+4;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
26 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
27
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
28 #if !CC_ONLY
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
29
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
30 /* straight conversion case (1) */
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
31
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
32 typedef char *stack;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
33
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
34 struct cont_interface { // General Return Continuation
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
35 code (*ret)();
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
36 };
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
37
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
38 code f(int i,stack sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
39 int k,j;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
40 k = 3+i;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
41 goto f_g0(i,k,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
42 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
43
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
44 struct f_g0_interface { // Specialized Return Continuation
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
45 code (*ret)();
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
46 int i_,k_,j_;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
47 };
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
48
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
49 code f_g1(int j,stack sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
50
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
51 code f_g0(int i,int k,stack sp) { // Caller
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
52 struct f_g0_interface *c =
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
53 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface));
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
54
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
55 c->ret = f_g1;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
56 c->k_ = k;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
57 c->i_ = i;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
58
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
59 goto g(i+3,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
60 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
61
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
62 code f_g1(int j,stack sp) { // Continuation
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
63 struct f_g0_interface *c = sp;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
64 int k = c->k_;
158
7bc02f0800a9 fix conv1
kono
parents: 155
diff changeset
65 sp+=sizeof(struct f_g0_interface);
7bc02f0800a9 fix conv1
kono
parents: 155
diff changeset
66 c = (struct f_g0_interface *)sp;
7bc02f0800a9 fix conv1
kono
parents: 155
diff changeset
67 goto (c->ret)(k+4+j,sp);
155
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
68 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
69
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
70 code g(int i,stack sp) { // Caller
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
71 struct f_g0_interface *c =
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
72 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface));
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
73
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
74 c->ret = g_h1;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
75 c->i_ = i;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
76
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
77 goto h(i+3,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
78 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
79
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
80 code g_h1(int j,stack sp) { // Continuation
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
81 struct f_g0_interface *c = sp;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
82 int i = c->i_;
158
7bc02f0800a9 fix conv1
kono
parents: 155
diff changeset
83 sp+=sizeof(struct f_g0_interface);
7bc02f0800a9 fix conv1
kono
parents: 155
diff changeset
84 c = (struct f_g0_interface *)sp;
7bc02f0800a9 fix conv1
kono
parents: 155
diff changeset
85 goto (c->ret)(j+i,sp);
155
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
86 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
87
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
88 code h(int i,stack sp) {
158
7bc02f0800a9 fix conv1
kono
parents: 155
diff changeset
89 struct f_g0_interface *c = sp;
7bc02f0800a9 fix conv1
kono
parents: 155
diff changeset
90 goto (c->ret)(i+4,sp);
155
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
91 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
92
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
93 struct main_continuation { // General Return Continuation
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
94 code (*ret)();
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
95 code (*main_ret)();
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
96 void *env;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
97 };
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
98
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
99 code main_return(int i,stack sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
100 if (loop-->0)
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
101 goto f(233,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
102 printf("%d\n",i);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
103 goto (( (struct main_continuation *)sp)->main_ret)(0),
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
104 ((struct main_continuation *)sp)->env;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
105 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
106
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
107 /* little optimzation without stack continuation (2) */
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
108
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
109 code f2(int i,char *sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
110 int k,j;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
111 k = 3+i;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
112 goto g2(i,k,i+3,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
113 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
114
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
115 code g2(int i,int k,int j,char *sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
116 j = j+4;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
117 goto h2(i,k+4+j,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
118 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
119
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
120 code h2_1(int i,int k,int j,char *sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
121 goto main_return2(i+j,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
122 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
123
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
124 code h2(int i,int k,char *sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
125 goto h2_1(i,k,i+4,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
126 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
127
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
128 code main_return2(int i,stack sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
129 if (loop-->0)
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
130 goto f2(233,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
131 printf("%d\n",i);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
132 goto (( (struct main_continuation *)sp)->main_ret)(0),
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
133 ((struct main_continuation *)sp)->env;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
134 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
135
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
136 /* little optimizaed case (3) */
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
137
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
138 code f2_1(int i,char *sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
139 int k,j;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
140 k = 3+i;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
141 goto g2_1(k,i+3,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
142 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
143
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
144 code g2_1(int k,int i,char *sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
145 goto h2_11(k,i+4,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
146 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
147
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
148 code f2_0_1(int k,int j,char *sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
149 code h2_1_1(int i,int k,int j,char *sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
150 goto f2_0_1(k,i+j,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
151 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
152
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
153 code h2_11(int i,int k,char *sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
154 goto h2_1_1(i,k,i+4,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
155 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
156
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
157 code f2_0_1(int k,int j,char *sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
158 goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
159 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
160
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
161 code main_return2_1(int i,stack sp) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
162 if (loop-->0)
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
163 goto f2_1(233,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
164 printf("%d\n",i);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
165 goto (( (struct main_continuation *)sp)->main_ret)(0),
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
166 ((struct main_continuation *)sp)->env;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
167 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
168
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
169 #define STACK_SIZE 2048
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
170 stack main_stack[STACK_SIZE];
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
171 #define stack_last (&main_stack[STACK_SIZE])
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
172
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
173 #endif
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
174
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
175 #define LOOP_COUNT 10000000
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
176
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
177 main(int ac,char *av[])
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
178 {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
179 #if !CC_ONLY
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
180 struct main_continuation *cont;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
181 stack sp = stack_last;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
182 #endif
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
183 int sw;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
184 int j;
172
096559f07a70 some check
kono
parents: 158
diff changeset
185 if (ac==2) sw = atoi(av[1]);
096559f07a70 some check
kono
parents: 158
diff changeset
186 else sw=3;
155
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
187
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
188 if (sw==0) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
189 for(loop=0;loop<LOOP_COUNT;loop++) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
190 j = f0(233);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
191 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
192 printf("%d\n",j);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
193 #if !CC_ONLY
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
194 } else if (sw==1) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
195 loop = LOOP_COUNT;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
196 sp -= sizeof(*cont);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
197 cont = (struct main_continuation *)sp;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
198 cont->ret = main_return;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
199 cont->main_ret = return;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
200 cont->env = environment;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
201 goto f(233,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
202 } else if (sw==2) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
203 loop = LOOP_COUNT;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
204 sp -= sizeof(*cont);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
205 cont = (struct main_continuation *)sp;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
206 cont->ret = main_return2;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
207 cont->main_ret = return;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
208 cont->env = environment;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
209 goto f2(233,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
210 } else if (sw==3) {
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
211 loop = LOOP_COUNT;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
212 sp -= sizeof(*cont);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
213 cont = (struct main_continuation *)sp;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
214 cont->ret = main_return2_1;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
215 cont->main_ret = return;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
216 cont->env = environment;
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
217 goto f2_1(233,sp);
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
218 #endif
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
219 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
220 }
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
221
ccb2002d8a31 *** empty log message ***
kono
parents:
diff changeset
222 /* end */