annotate mc-inline.c @ 541:4d853ee76ad6

minor fixes for s-dandy
author kono
date Sun, 01 Jan 2006 12:25:08 +0900
parents 80b5058f0535
children 25e61d68c545
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
462
kono
parents:
diff changeset
1 /* Micro-C Partial Evaluator Part */
kono
parents:
diff changeset
2 /* $Id$ */
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 #include <stdio.h>
kono
parents:
diff changeset
5 #include "mc.h"
kono
parents:
diff changeset
6 #include "mc-parse.h"
kono
parents:
diff changeset
7 #include "mc-codegen.h"
kono
parents:
diff changeset
8 #include "mc-switch.h"
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
9 #include "mc-code.h"
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
10 #include "mc-inline.h"
462
kono
parents:
diff changeset
11
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
12 static int pvartable;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
13 static int pdisp;
462
kono
parents:
diff changeset
14
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
15 static int ret_register,ret_reg_mode;
a2047e4555be inline continue....
kono
parents: 513
diff changeset
16
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
17 static int inline_lvars;
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
18
462
kono
parents:
diff changeset
19 /*
kono
parents:
diff changeset
20 Basic code generator from parse tree
kono
parents:
diff changeset
21 */
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 extern void
kono
parents:
diff changeset
24 st_decl(int e1){
kono
parents:
diff changeset
25 // NMTBL *n = (NMTBL *)caddr(e1);
kono
parents:
diff changeset
26 // int stmode = cadddr(e1);
kono
parents:
diff changeset
27 }
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 extern void
kono
parents:
diff changeset
30 st_if(int e1){
kono
parents:
diff changeset
31 int l1,l2,slfree;
kono
parents:
diff changeset
32 int e2=caddr(e1),e3;
kono
parents:
diff changeset
33 // conv->if_();
kono
parents:
diff changeset
34 slfree=lfree;
kono
parents:
diff changeset
35 checkret();
kono
parents:
diff changeset
36 l1 = bexpr(car(e2),0,fwdlabel());
kono
parents:
diff changeset
37 // conv->if_then_();
kono
parents:
diff changeset
38 g_expr_u(cadr(e2));
kono
parents:
diff changeset
39 checkret();
kono
parents:
diff changeset
40 if ((e3=caddr(e2))) { // else
kono
parents:
diff changeset
41 // conv->if_else_();
kono
parents:
diff changeset
42 if ((l2 = control))
kono
parents:
diff changeset
43 gen_jmp(l2=fwdlabel());
kono
parents:
diff changeset
44 fwddef(l1);
kono
parents:
diff changeset
45 g_expr_u(e3);
kono
parents:
diff changeset
46 checkret();
kono
parents:
diff changeset
47 if (l2) fwddef(l2);
kono
parents:
diff changeset
48 } else {
kono
parents:
diff changeset
49 fwddef(l1);
kono
parents:
diff changeset
50 }
kono
parents:
diff changeset
51 // conv->if_endif_();
kono
parents:
diff changeset
52 }
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 extern void
kono
parents:
diff changeset
56 st_do(int e1){
kono
parents:
diff changeset
57 int sbreak,scontinue,l;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 sbreak=blabel;
kono
parents:
diff changeset
60 scontinue=clabel;
kono
parents:
diff changeset
61 blabel=fwdlabel();
kono
parents:
diff changeset
62 clabel=fwdlabel();
kono
parents:
diff changeset
63 control=1;
kono
parents:
diff changeset
64 checkret();
kono
parents:
diff changeset
65 l=backdef();
kono
parents:
diff changeset
66 // conv->dowhile_();
kono
parents:
diff changeset
67 g_expr_u(cadddr(e1));
kono
parents:
diff changeset
68 checkret();
kono
parents:
diff changeset
69 // conv->dowhile_cond_();
kono
parents:
diff changeset
70 bexpr(caddr(e1),1,l);
kono
parents:
diff changeset
71 // conv->dowhile_end_();
kono
parents:
diff changeset
72 fwddef(blabel);
kono
parents:
diff changeset
73 clabel=scontinue;
kono
parents:
diff changeset
74 blabel=sbreak;
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 extern void
kono
parents:
diff changeset
79 st_while(int e1){
kono
parents:
diff changeset
80 int sbreak,scontinue,e;
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 sbreak=blabel;
kono
parents:
diff changeset
83 scontinue=clabel;
kono
parents:
diff changeset
84 blabel=fwdlabel();
kono
parents:
diff changeset
85 control=1;
kono
parents:
diff changeset
86 checkret();
kono
parents:
diff changeset
87 clabel=backdef();
kono
parents:
diff changeset
88 // conv->while_();
kono
parents:
diff changeset
89 // conv->while_body_();
kono
parents:
diff changeset
90 if(!(e=cadddr(e1))) {
kono
parents:
diff changeset
91 bexpr(caddr(e1),1,clabel);
kono
parents:
diff changeset
92 // conv->sm_();
kono
parents:
diff changeset
93 } else {
kono
parents:
diff changeset
94 bexpr(caddr(e1),0,blabel);
kono
parents:
diff changeset
95 g_expr_u(e);
kono
parents:
diff changeset
96 checkret();
kono
parents:
diff changeset
97 if(control)
kono
parents:
diff changeset
98 gen_jmp(clabel);
kono
parents:
diff changeset
99 }
kono
parents:
diff changeset
100 // conv->while_end_();
kono
parents:
diff changeset
101 fwddef(blabel);
kono
parents:
diff changeset
102 clabel=scontinue;
kono
parents:
diff changeset
103 blabel=sbreak;
kono
parents:
diff changeset
104 }
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 extern void
kono
parents:
diff changeset
108 st_for(int e1){
kono
parents:
diff changeset
109 int p0,p1,p2,body;
kono
parents:
diff changeset
110 int l,e;
kono
parents:
diff changeset
111 int sbreak=blabel;
kono
parents:
diff changeset
112 int scontinue=clabel;
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 e = caddr(e1);
kono
parents:
diff changeset
115 p0 = car(e); p1 = cadr(e); p2 = caddr(e); body = cadddr(e);
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 blabel=fwdlabel();
kono
parents:
diff changeset
118 // conv->for_();
kono
parents:
diff changeset
119 if (p0) {
kono
parents:
diff changeset
120 checkret();
kono
parents:
diff changeset
121 g_expr_u(p0);
kono
parents:
diff changeset
122 }
kono
parents:
diff changeset
123 // conv->for1_();
kono
parents:
diff changeset
124 control=1;
kono
parents:
diff changeset
125 checkret();
kono
parents:
diff changeset
126 l=backdef();
kono
parents:
diff changeset
127 if (p1) {
kono
parents:
diff changeset
128 bexpr(p1,0,blabel);
kono
parents:
diff changeset
129 }
kono
parents:
diff changeset
130 // conv->for2_();
kono
parents:
diff changeset
131 // conv->for_body_();
kono
parents:
diff changeset
132 if (!p2) {
kono
parents:
diff changeset
133 clabel=l;
kono
parents:
diff changeset
134 g_expr_u(body);
kono
parents:
diff changeset
135 checkret();
kono
parents:
diff changeset
136 } else {
kono
parents:
diff changeset
137 clabel=fwdlabel();
kono
parents:
diff changeset
138 g_expr_u(body);
kono
parents:
diff changeset
139 checkret();
kono
parents:
diff changeset
140 fwddef(clabel);
kono
parents:
diff changeset
141 g_expr_u(p2);
kono
parents:
diff changeset
142 }
kono
parents:
diff changeset
143 // conv->for_end_();
kono
parents:
diff changeset
144 gen_jmp(l);
kono
parents:
diff changeset
145 fwddef(blabel);
kono
parents:
diff changeset
146 clabel=scontinue;
kono
parents:
diff changeset
147 blabel=sbreak;
kono
parents:
diff changeset
148 }
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 extern void
kono
parents:
diff changeset
152 st_switch(int e1){
kono
parents:
diff changeset
153 int sbreak,scase,sdefault,slfree,svalue,slist;
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 checkret();
kono
parents:
diff changeset
156 slist = cslist;
kono
parents:
diff changeset
157 cslist = 0;
kono
parents:
diff changeset
158 sbreak=blabel; /* save parents break label */
kono
parents:
diff changeset
159 blabel=fwdlabel();
kono
parents:
diff changeset
160 sdefault=dlabel; /* save parents default label */
kono
parents:
diff changeset
161 dlabel=0;
kono
parents:
diff changeset
162 scase=cslabel; /* save parents next case label */
kono
parents:
diff changeset
163 // conv->switch_();
kono
parents:
diff changeset
164 slfree=lfree;
kono
parents:
diff changeset
165 svalue=csvalue1; /* save parents switch value */
506
96af6754acd3 *** empty log message ***
kono
parents: 505
diff changeset
166 gexpr(caddr(e1),1); /* switch value */
462
kono
parents:
diff changeset
167 csvalue1=csvalue() ;
kono
parents:
diff changeset
168 // conv->switch_body_();
kono
parents:
diff changeset
169 cslabel = control = 0;
kono
parents:
diff changeset
170 g_expr_u(cadddr(e1));
kono
parents:
diff changeset
171 // conv->switch_end_();
kono
parents:
diff changeset
172 checkret();
kono
parents:
diff changeset
173 #if CASE_CODE
kono
parents:
diff changeset
174 if (control) gen_jmp(blabel);
kono
parents:
diff changeset
175 genswitch(cslist,cslabel);
kono
parents:
diff changeset
176 #else
kono
parents:
diff changeset
177 if(dlabel) def_label(cslabel,dlabel);
kono
parents:
diff changeset
178 else fwddef(cslabel);
kono
parents:
diff changeset
179 #endif
kono
parents:
diff changeset
180 csvalue1=svalue;
kono
parents:
diff changeset
181 cslabel=scase;
kono
parents:
diff changeset
182 dlabel=sdefault;
kono
parents:
diff changeset
183 fwddef(blabel);
kono
parents:
diff changeset
184 blabel=sbreak;
kono
parents:
diff changeset
185 cslist = slist;
kono
parents:
diff changeset
186 }
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 extern void
kono
parents:
diff changeset
190 st_comp(int e1){
kono
parents:
diff changeset
191 g_expr_u(caddr(e1));
kono
parents:
diff changeset
192 }
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 extern void
kono
parents:
diff changeset
196 st_break(int e1){
kono
parents:
diff changeset
197 checkret();
kono
parents:
diff changeset
198 // conv->break_();
kono
parents:
diff changeset
199 if (control)
kono
parents:
diff changeset
200 gen_jmp(blabel);
kono
parents:
diff changeset
201 }
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 extern void
kono
parents:
diff changeset
205 st_continue(int e1){
kono
parents:
diff changeset
206 checkret();
kono
parents:
diff changeset
207 // conv->continue_();
kono
parents:
diff changeset
208 if (control) gen_jmp(clabel);
kono
parents:
diff changeset
209 }
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 extern void
kono
parents:
diff changeset
213 st_case(int e1){
kono
parents:
diff changeset
214 #if CASE_CODE
kono
parents:
diff changeset
215 int l,clist=caddr(e1),c;
kono
parents:
diff changeset
216 l = fwdlabel();
kono
parents:
diff changeset
217 // conv->case_begin_(0,0);
kono
parents:
diff changeset
218 // conv->case_(0,0);
kono
parents:
diff changeset
219 if (retpending) {
kono
parents:
diff changeset
220 ret(); retpending=0;
kono
parents:
diff changeset
221 }
kono
parents:
diff changeset
222 if (!cslabel) {
kono
parents:
diff changeset
223 if (!control) {
kono
parents:
diff changeset
224 cmpdimm(car(clist),csvalue1,cslabel=fwdlabel(),1);
kono
parents:
diff changeset
225 caddr(clist)=0;
kono
parents:
diff changeset
226 } else {
kono
parents:
diff changeset
227 error(-1);
kono
parents:
diff changeset
228 }
kono
parents:
diff changeset
229 }
kono
parents:
diff changeset
230 while(clist) {
kono
parents:
diff changeset
231 caddr(clist) = l;
kono
parents:
diff changeset
232 clist = cadr(c=clist); cadr(c) = 0; // insert destroy cadr of clist
kono
parents:
diff changeset
233 cslist=insert_ascend(cslist,c,docase_eq);
kono
parents:
diff changeset
234 }
kono
parents:
diff changeset
235 fwddef(l);
kono
parents:
diff changeset
236 control=1;
kono
parents:
diff changeset
237 #else
kono
parents:
diff changeset
238 /* casading branch implementation */
kono
parents:
diff changeset
239 int c,l;
kono
parents:
diff changeset
240 c = caddr(e1);
kono
parents:
diff changeset
241 if (retpending) {
kono
parents:
diff changeset
242 ret(); retpending=0;
kono
parents:
diff changeset
243 }
kono
parents:
diff changeset
244 // conv->case_begin_(0,0);
kono
parents:
diff changeset
245 // conv->case_(0,0);
kono
parents:
diff changeset
246 l=fwdlabel();
kono
parents:
diff changeset
247 if (control) {
kono
parents:
diff changeset
248 control=0;
kono
parents:
diff changeset
249 gen_jmp(l);
kono
parents:
diff changeset
250 }
kono
parents:
diff changeset
251 if (cslabel) fwddef(cslabel);
kono
parents:
diff changeset
252 while(cadr(c)) {
kono
parents:
diff changeset
253 cmpdimm(car(c),csvalue1,l,0);
kono
parents:
diff changeset
254 c=cadr(c);
kono
parents:
diff changeset
255 }
kono
parents:
diff changeset
256 cmpdimm(car(c),csvalue1,cslabel=fwdlabel(),1);
kono
parents:
diff changeset
257 if (l) fwddef(l);
kono
parents:
diff changeset
258 #endif
kono
parents:
diff changeset
259 }
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 extern void
kono
parents:
diff changeset
263 st_default(int e1){
kono
parents:
diff changeset
264 control=1;
kono
parents:
diff changeset
265 checkret();
kono
parents:
diff changeset
266 if (dlabel) error(STERR); // double default:
kono
parents:
diff changeset
267 dlabel = backdef();
kono
parents:
diff changeset
268 // conv->case_(0,1);
kono
parents:
diff changeset
269 }
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 extern void
kono
parents:
diff changeset
273 st_return(int e1){
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
274 int e,t;
462
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 if (!cslabel) gen_jmp(cslabel = fwdlabel());
kono
parents:
diff changeset
277 if(!(e=caddr(e1))) {
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
278 // no return value
462
kono
parents:
diff changeset
279 retpending = 1;
kono
parents:
diff changeset
280 return;
kono
parents:
diff changeset
281 }
kono
parents:
diff changeset
282 // conv->return_();
kono
parents:
diff changeset
283 if (struct_return) {
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
284 // certainly this is wrong for inline
462
kono
parents:
diff changeset
285 if ((car(type)==STRUCT || car(type)==UNION)&&
kono
parents:
diff changeset
286 size(type)==cadr(struct_return)) {
kono
parents:
diff changeset
287 if(car(e)==RSTRUCT && car(cadr(e))==FUNCTION) {
kono
parents:
diff changeset
288 /* pass the return pointer to the called function */
kono
parents:
diff changeset
289 replace_return_struct(cadr(e),
kono
parents:
diff changeset
290 rvalue_t(car(struct_return),caddr(struct_return)));
510
2bd6ff6ee9a8 inline continue...
kono
parents: 509
diff changeset
291 g_expr_u(cadr(e));
462
kono
parents:
diff changeset
292 } else {
kono
parents:
diff changeset
293 type = caddr(struct_return);
kono
parents:
diff changeset
294 // e1 = rvalue_t(cadr(struct_return),INT); /* size */
kono
parents:
diff changeset
295 e1 = cadr(struct_return); /* size */
510
2bd6ff6ee9a8 inline continue...
kono
parents: 509
diff changeset
296 g_expr_u(list4(STASS,rvalue(car(struct_return)),e,e1));
462
kono
parents:
diff changeset
297 }
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
298 if (ret_reg_mode==0) {
a2047e4555be inline continue....
kono
parents: 513
diff changeset
299 ret_reg_mode=1;
a2047e4555be inline continue....
kono
parents: 513
diff changeset
300 ret_register = code_get_fixed_creg(USE_CREG,INT);
a2047e4555be inline continue....
kono
parents: 513
diff changeset
301 } else {
a2047e4555be inline continue....
kono
parents: 513
diff changeset
302 code_set_fixed_creg(ret_register,1,INT);
a2047e4555be inline continue....
kono
parents: 513
diff changeset
303 }
462
kono
parents:
diff changeset
304 } else {
kono
parents:
diff changeset
305 error(TYERR); /* should check compatible */
kono
parents:
diff changeset
306 }
kono
parents:
diff changeset
307 } else {
526
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
308 g_expr(e);
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
309 t = type_value(cadr(fnptr->ty));
a2047e4555be inline continue....
kono
parents: 513
diff changeset
310 if (ret_reg_mode==0) {
524
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
311 // return value register is not fixed
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
312 ret_reg_mode=1;
a2047e4555be inline continue....
kono
parents: 513
diff changeset
313 ret_register = code_get_fixed_creg(USE_CREG,t);
a2047e4555be inline continue....
kono
parents: 513
diff changeset
314 } else {
a2047e4555be inline continue....
kono
parents: 513
diff changeset
315 code_set_fixed_creg(ret_register,1,t);
a2047e4555be inline continue....
kono
parents: 513
diff changeset
316 }
462
kono
parents:
diff changeset
317 }
kono
parents:
diff changeset
318 // conv->return_end_();
kono
parents:
diff changeset
319 retpending = 1;
kono
parents:
diff changeset
320 }
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 extern void
kono
parents:
diff changeset
323 st_goto(int e){
kono
parents:
diff changeset
324 NMTBL *nlist,*nptr0;
kono
parents:
diff changeset
325 int t,e1,e2,env;
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 checkret();
kono
parents:
diff changeset
328 // conv->goto_();
kono
parents:
diff changeset
329 e1 = caddr(e);
kono
parents:
diff changeset
330 if (car(e1)==RINDIRECT) {
kono
parents:
diff changeset
331 gen_indirect_goto(cadr(e1));
505
5d4112735c5c *** empty log message ***
kono
parents: 504
diff changeset
332 return ;
462
kono
parents:
diff changeset
333 } else if (car(e1)==FLABEL) {
kono
parents:
diff changeset
334 nlist = (NMTBL *)cadr(e1);
kono
parents:
diff changeset
335 nptr0 = name_space_search(nlist,0);
kono
parents:
diff changeset
336 t = nptr0->sc;
kono
parents:
diff changeset
337 if (t==EMPTY||t==EXTRN1||t==EXTRN) {
kono
parents:
diff changeset
338 nptr0 = make_local_scope(nlist,nptr0,0);
kono
parents:
diff changeset
339 nptr0->sc = FLABEL;
kono
parents:
diff changeset
340 nptr0->dsp = fwdlabel();
kono
parents:
diff changeset
341 } else if (!(t==FLABEL||t==BLABEL)) {
kono
parents:
diff changeset
342 error(STERR);
kono
parents:
diff changeset
343 }
kono
parents:
diff changeset
344 gen_jmp(nptr0->dsp);
kono
parents:
diff changeset
345 control=0;
kono
parents:
diff changeset
346 // conv->sm_();
kono
parents:
diff changeset
347 // conv->goto_label_(nptr0);
505
5d4112735c5c *** empty log message ***
kono
parents: 504
diff changeset
348 return ;
462
kono
parents:
diff changeset
349 } else {
kono
parents:
diff changeset
350 /* CbC continuation */
kono
parents:
diff changeset
351 // conv->jump_(env);
kono
parents:
diff changeset
352 e2 = cadr(e1);
kono
parents:
diff changeset
353 env = caddr(e1);
kono
parents:
diff changeset
354 if (car(e2) == FNAME) {
kono
parents:
diff changeset
355 nptr0=(NMTBL *)cadr(e2);
kono
parents:
diff changeset
356 if (nptr0->sc==EMPTY)
kono
parents:
diff changeset
357 nptr0->sc = EXTRN1;
kono
parents:
diff changeset
358 else if(nptr0->sc==FUNCTION)
kono
parents:
diff changeset
359 nptr0->sc = CODE;
kono
parents:
diff changeset
360 if (nptr0->ty>0&&car(nptr0->ty)==FUNCTION)
kono
parents:
diff changeset
361 car(nptr0->ty)=CODE;
kono
parents:
diff changeset
362 }
kono
parents:
diff changeset
363 gexpr(list3(CODE,e1,env),0);
kono
parents:
diff changeset
364 control=0;
kono
parents:
diff changeset
365 // conv->sm_();
505
5d4112735c5c *** empty log message ***
kono
parents: 504
diff changeset
366 return ;
462
kono
parents:
diff changeset
367 }
kono
parents:
diff changeset
368 }
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 #if ASM_CODE
kono
parents:
diff changeset
372 extern void
kono
parents:
diff changeset
373 st_asm(int e1){
kono
parents:
diff changeset
374 checkret();
kono
parents:
diff changeset
375 g_expr_u(list3(ASM,caddr(e1),cadddr(e1)));
kono
parents:
diff changeset
376 }
kono
parents:
diff changeset
377 #endif
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 extern void
kono
parents:
diff changeset
381 st_label(int e1){
kono
parents:
diff changeset
382 NMTBL *nptr,*nlist;
kono
parents:
diff changeset
383 nlist = (NMTBL *)caddr(e1);
kono
parents:
diff changeset
384 nptr = name_space_search(nlist,0);
kono
parents:
diff changeset
385 control=1;
kono
parents:
diff changeset
386 checkret();
kono
parents:
diff changeset
387 if(nptr->sc == FLABEL) {
kono
parents:
diff changeset
388 fwddef(nptr->dsp);
kono
parents:
diff changeset
389 } else if(nptr->sc != EMPTY && nptr->sc != EXTRN1 && nptr->sc !=BLABEL) {
kono
parents:
diff changeset
390 error(TYERR);
kono
parents:
diff changeset
391 } else {
kono
parents:
diff changeset
392 nptr->sc=EMPTY;
kono
parents:
diff changeset
393 nptr = make_local_scope(nlist,nptr,0);
kono
parents:
diff changeset
394 nptr->sc = BLABEL;
kono
parents:
diff changeset
395 nptr->dsp = backdef();
kono
parents:
diff changeset
396 }
kono
parents:
diff changeset
397 // conv->label_();
kono
parents:
diff changeset
398 }
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 extern void
kono
parents:
diff changeset
401 st_comment(int e1){
kono
parents:
diff changeset
402 gen_comment((char *)caddr(e1));
kono
parents:
diff changeset
403 }
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 /*
kono
parents:
diff changeset
406 partial evaluator
kono
parents:
diff changeset
407 */
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 static int
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
410 p_vartable(int e,int adisp,int ldisp)
462
kono
parents:
diff changeset
411 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
412 int i;
505
5d4112735c5c *** empty log message ***
kono
parents: 504
diff changeset
413 int pvartable = getfree(adisp-ldisp); // have to be local heap
509
e58848f6ebc1 inline continue...
kono
parents: 508
diff changeset
414 pdisp = pvartable-ldisp;
e58848f6ebc1 inline continue...
kono
parents: 508
diff changeset
415 for(i=ldisp;i<0;i++) {
e58848f6ebc1 inline continue...
kono
parents: 508
diff changeset
416 heap[pdisp+i] = 0;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
417 }
505
5d4112735c5c *** empty log message ***
kono
parents: 504
diff changeset
418 return pvartable;
462
kono
parents:
diff changeset
419 }
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 static int
kono
parents:
diff changeset
422 p_lvar(int e1)
kono
parents:
diff changeset
423 {
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
424 int sz = is_memory(e1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
425 int d = cadr(e1);
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
426 int d1,e;
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
427 if ((d1=(heap[pdisp+d]))) return d1;
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
428 e = heap[pdisp+d]=list3(LVAR,new_lvar(sz),0);
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
429 inline_lvars = glist2(e,inline_lvars);
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
430 return e;
462
kono
parents:
diff changeset
431 }
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 static int
kono
parents:
diff changeset
434 pfunction(int e)
kono
parents:
diff changeset
435 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
436 // list4(INLINE,e1,arglist,ftype);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
437 // include code segement case
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
438 int e1 = pexpr(cadr(e));
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
439 int arglist = caddr(e);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
440 int newargs = 0;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
441 int ftype = cadddr(e);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
442 int e3;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
443 for (e3 = arglist; e3; e3 = cadr(e3)) {
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
444 newargs = list3( pexpr(car(e3)), newargs, caddr(e3));
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
445 }
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
446 newargs = reverse0(newargs);
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
447 return list4(car(e),e1,newargs,ftype);
462
kono
parents:
diff changeset
448 }
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 static int
kono
parents:
diff changeset
451 prindirect(int e)
kono
parents:
diff changeset
452 {
525
d84cea14dbdc *** empty log message ***
kono
parents: 524
diff changeset
453 int lvar;
533
80b5058f0535 inline code-gen test passed.
kono
parents: 532
diff changeset
454 int offset = caddr(e);
530
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
455 if (car(lvar=cadr(e))==IVAR) {
525
d84cea14dbdc *** empty log message ***
kono
parents: 524
diff changeset
456 lvar=p_lvar(cadr(e)); // can be anything....
530
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
457 switch(car(lvar)) {
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
458 case LVAR:
533
80b5058f0535 inline code-gen test passed.
kono
parents: 532
diff changeset
459 if(offset) {
80b5058f0535 inline code-gen test passed.
kono
parents: 532
diff changeset
460 return list3(car(e),lvar,offset);
80b5058f0535 inline code-gen test passed.
kono
parents: 532
diff changeset
461 }
530
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
462 return rvalue_t(lvar,cadddr(e));
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
463 case REGISTER: case DREGISTER:
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
464 case FREGISTER: case LREGISTER:
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
465 case CONST: case FCONST: case DCONST: case LCONST:
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
466 // should do type check
533
80b5058f0535 inline code-gen test passed.
kono
parents: 532
diff changeset
467 if (offset) error(-1);
530
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
468 return lvar;
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
469 }
512
53ec17a8af7d inline continue....
kono
parents: 511
diff changeset
470 }
533
80b5058f0535 inline code-gen test passed.
kono
parents: 532
diff changeset
471 return list3(car(e),pexpr(cadr(e)),offset);
462
kono
parents:
diff changeset
472 }
kono
parents:
diff changeset
473
kono
parents:
diff changeset
474 static int
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
475 pindirect(int e)
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
476 {
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
477 int lvar;
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
478 if (car(lvar=cadr(e))==IVAR)
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
479 lvar=p_lvar(cadr(e)); // can be anything....
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
480 return list3(car(e),pexpr(cadr(e)),caddr(e));
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
481 }
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
482
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
483 static int
462
kono
parents:
diff changeset
484 paddress(int e)
kono
parents:
diff changeset
485 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
486 return list2(car(e),pexpr(cadr(e)));
462
kono
parents:
diff changeset
487 }
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 static int
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
490 p_conv(int e1,int e2)
462
kono
parents:
diff changeset
491 {
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
492 return list3(CONV,pexpr(e2),e1);
462
kono
parents:
diff changeset
493 }
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 static int
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
496 pbinop(int op,int e1,int e2)
462
kono
parents:
diff changeset
497 {
533
80b5058f0535 inline code-gen test passed.
kono
parents: 532
diff changeset
498 // we should call binop here, but we don't know the type...
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
499 return list3(op,pexpr(e1),pexpr(e2));
462
kono
parents:
diff changeset
500 }
kono
parents:
diff changeset
501
kono
parents:
diff changeset
502 static int
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
503 prexpr(int op,int e1,int e2)
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
504 {
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
505 return list3(op,pexpr(e1),pexpr(e2));
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
506 }
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
507
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
508 static int
526
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
509 plor(int op,int e1,int e2)
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
510 {
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
511 return list3(op,pexpr(e1),pexpr(e2));
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
512 }
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
513
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
514 static int
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
515 pland(int op,int e1,int e2)
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
516 {
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
517 return list3(op,pexpr(e1),pexpr(e2));
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
518 }
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
519
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
520 static int
462
kono
parents:
diff changeset
521 psassign(int e)
kono
parents:
diff changeset
522 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
523 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
524 }
kono
parents:
diff changeset
525
kono
parents:
diff changeset
526 static int
kono
parents:
diff changeset
527 passign(int e)
kono
parents:
diff changeset
528 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
529 return list3(car(e),pexpr(cadr(e)),pexpr(caddr(e)));
462
kono
parents:
diff changeset
530 }
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 static int
kono
parents:
diff changeset
533 passop(int e)
kono
parents:
diff changeset
534 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
535 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
536 }
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538 static int
kono
parents:
diff changeset
539 pdassign(int e)
kono
parents:
diff changeset
540 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
541 return list3(car(e),pexpr(cadr(e)),pexpr(caddr(e)));
462
kono
parents:
diff changeset
542 }
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 static int
kono
parents:
diff changeset
545 pdassop(int e)
kono
parents:
diff changeset
546 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
547 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
548 }
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 static int
kono
parents:
diff changeset
551 plassign(int e)
kono
parents:
diff changeset
552 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
553 return list3(car(e),pexpr(cadr(e)),pexpr(caddr(e)));
462
kono
parents:
diff changeset
554 }
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 static int
kono
parents:
diff changeset
557 plassop(int e)
kono
parents:
diff changeset
558 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
559 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
560 }
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 static int
kono
parents:
diff changeset
563 palloc(int e)
kono
parents:
diff changeset
564 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
565 return list2(car(e),pexpr(cadr(e)));
462
kono
parents:
diff changeset
566 }
kono
parents:
diff changeset
567
kono
parents:
diff changeset
568 static int
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
569 pcomma(int e1,int e2)
462
kono
parents:
diff changeset
570 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
571 return list3(COMMA,pexpr(e1),pexpr(e2));
462
kono
parents:
diff changeset
572 }
kono
parents:
diff changeset
573
kono
parents:
diff changeset
574 static int
kono
parents:
diff changeset
575 prbit_field(int e)
kono
parents:
diff changeset
576 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
577 return list3(car(e),pexpr(cadr(e)),caddr(e));
462
kono
parents:
diff changeset
578 }
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 static int
kono
parents:
diff changeset
581 pbassign(int e)
kono
parents:
diff changeset
582 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
583 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
584 }
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 static int
kono
parents:
diff changeset
587 pbassop(int e)
kono
parents:
diff changeset
588 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
589 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
590 }
kono
parents:
diff changeset
591
kono
parents:
diff changeset
592 static int
kono
parents:
diff changeset
593 p_decl(int e)
kono
parents:
diff changeset
594 {
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
595 // list4(ST_DECL,parse,(int)n,stmode);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
596 int stmode=cadddr(e);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
597 NMTBL *n=(NMTBL*)caddr(e);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
598 int dsp = n->dsp;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
599 int v;
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
600 // in real partial evaluation, we have to check whether this variable
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
601 // is used or not.
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
602 switch(stmode) {
528
d6fff671793a minor fix inline
kono
parents: 527
diff changeset
603 case EXTRN: case EXTRN1: case STATIC:
d6fff671793a minor fix inline
kono
parents: 527
diff changeset
604 return pexpr(cadr(e));
529
ad874ef77dde use_input_reg...
kono
parents: 528
diff changeset
605 #if 1
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
606 case REGISTER:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
607 switch(n->ty) {
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
608 case ULONGLONG: case LONGLONG:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
609 v = get_lregister_var(n); break;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
610 case FLOAT:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
611 v = get_dregister_var(n,0); break;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
612 case DOUBLE:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
613 v = get_dregister_var(n,1); break;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
614 default:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
615 if (scalar(n->ty))
524
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
616 v = get_register_var(n);
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
617 else
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
618 error(TYERR);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
619 }
529
ad874ef77dde use_input_reg...
kono
parents: 528
diff changeset
620 break;
528
d6fff671793a minor fix inline
kono
parents: 527
diff changeset
621 #endif
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
622 default:
519
b6eb97f0c11d *** empty log message ***
kono
parents: 514
diff changeset
623 v = list3(LVAR,new_lvar(size(n->ty)),(int)n);
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
624 }
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
625 inline_lvars = glist2(v,inline_lvars);
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
626 if (heap[pdisp+dsp]) error(-1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
627 heap[pdisp+dsp]=v;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
628 return pexpr(cadr(e));
462
kono
parents:
diff changeset
629 }
kono
parents:
diff changeset
630
kono
parents:
diff changeset
631 static int
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
632 p_if(int e1)
462
kono
parents:
diff changeset
633 {
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
634 int cond,l1,l2;
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
635 int e2=caddr(e1),e3;
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
636 cond = pexpr(car(e2));
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
637 // conv->if_then_();
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
638 l1 = pexpr(cadr(e2));
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
639 if ((e3=caddr(e2))) { // else
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
640 l2 = pexpr(e3);
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
641 } else {
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
642 l2 = 0;
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
643 }
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
644 return list3(ST_IF,pexpr(cadr(e1)),list3(cond,l1,l2));
462
kono
parents:
diff changeset
645 }
kono
parents:
diff changeset
646
kono
parents:
diff changeset
647 static int
kono
parents:
diff changeset
648 p_do(int e)
kono
parents:
diff changeset
649 {
524
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
650 int e2 = pexpr(caddr(e));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
651 int e3 = pexpr(cadddr(e));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
652 return list4(ST_DO,pexpr(cadr(e)),e2,e3);
462
kono
parents:
diff changeset
653 }
kono
parents:
diff changeset
654
kono
parents:
diff changeset
655 static int
kono
parents:
diff changeset
656 p_while(int e)
kono
parents:
diff changeset
657 {
524
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
658 int e2 = pexpr(caddr(e));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
659 int e3 = pexpr(cadddr(e));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
660 return list4(ST_WHILE,pexpr(cadr(e)),e2,e3);
462
kono
parents:
diff changeset
661 }
kono
parents:
diff changeset
662
kono
parents:
diff changeset
663 static int
kono
parents:
diff changeset
664 p_for(int e)
kono
parents:
diff changeset
665 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
666 int e1=caddr(e);
524
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
667 int p0=pexpr(car(e1));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
668 int p1=pexpr(cadr(e1));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
669 int p2=pexpr(caddr(e1));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
670 int p3=pexpr(cadddr(e1));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
671 return list3(ST_FOR,pexpr(cadr(e)), list4(p0,p1,p2,p3));
462
kono
parents:
diff changeset
672 }
kono
parents:
diff changeset
673
kono
parents:
diff changeset
674 static int
kono
parents:
diff changeset
675 p_switch(int e)
kono
parents:
diff changeset
676 {
524
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
677 int e2 = pexpr(caddr(e));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
678 int e3 = pexpr(cadddr(e));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
679 return list4(ST_SWITCH,pexpr(cadr(e)),e2,e3);
462
kono
parents:
diff changeset
680 }
kono
parents:
diff changeset
681
kono
parents:
diff changeset
682 static int
kono
parents:
diff changeset
683 p_comp(int e)
kono
parents:
diff changeset
684 {
524
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
685 int e1=pexpr(caddr(e));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
686 return list3(ST_COMP,pexpr(cadr(e)),e1);
462
kono
parents:
diff changeset
687 }
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 static int
kono
parents:
diff changeset
690 p_break(int e)
kono
parents:
diff changeset
691 {
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
692 return list2(ST_BREAK,pexpr(cadr(e)));
462
kono
parents:
diff changeset
693 }
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 static int
kono
parents:
diff changeset
696 p_continue(int e)
kono
parents:
diff changeset
697 {
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
698 return list2(ST_CONTINUE,pexpr(cadr(e)));
462
kono
parents:
diff changeset
699 }
kono
parents:
diff changeset
700
kono
parents:
diff changeset
701 static int
kono
parents:
diff changeset
702 p_case(int e)
kono
parents:
diff changeset
703 {
506
96af6754acd3 *** empty log message ***
kono
parents: 505
diff changeset
704 int new=0,clist = caddr(e);
96af6754acd3 *** empty log message ***
kono
parents: 505
diff changeset
705 // insert destory clist, we have to copy it now
96af6754acd3 *** empty log message ***
kono
parents: 505
diff changeset
706 for(;clist;clist=cadr(clist))
96af6754acd3 *** empty log message ***
kono
parents: 505
diff changeset
707 new=glist3(car(clist),new,0);
96af6754acd3 *** empty log message ***
kono
parents: 505
diff changeset
708 return list3(ST_CASE,pexpr(cadr(e)),reverse0(new));
462
kono
parents:
diff changeset
709 }
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 static int
kono
parents:
diff changeset
712 p_default(int e)
kono
parents:
diff changeset
713 {
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
714 return list2(ST_DEFAULT,pexpr(cadr(e)));
462
kono
parents:
diff changeset
715 }
kono
parents:
diff changeset
716
kono
parents:
diff changeset
717 static int
kono
parents:
diff changeset
718 p_return(int e)
kono
parents:
diff changeset
719 {
524
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
720 int e1=pexpr(caddr(e));
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
721 return list3(ST_RETURN,pexpr(cadr(e)),e1);
462
kono
parents:
diff changeset
722 }
kono
parents:
diff changeset
723
kono
parents:
diff changeset
724 static int
kono
parents:
diff changeset
725 p_goto(int e)
kono
parents:
diff changeset
726 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
727 int e1;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
728 if ((e1=caddr(e))) {
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
729 switch(car(e1)) {
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
730 case RINDIRECT: e1=pexpr(e1); break;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
731 case CODE: e1=list3(CODE,pexpr(cadr(e1)),pexpr(caddr(e1))); break;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
732 case FLABEL: break;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
733 }
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
734 }
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
735 return list3(ST_GOTO,pexpr(cadr(e)),e1);
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
736 }
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
737
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
738 static int
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
739 p_list_expr(int e)
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
740 {
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
741 int e3,new = 0;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
742 for (e3 = e; e3; e3 = cadr(e3)) {
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
743 new= list2( pexpr(car(e3)), new);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
744 }
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
745 return reverse0(new);
462
kono
parents:
diff changeset
746 }
kono
parents:
diff changeset
747
kono
parents:
diff changeset
748 static int
kono
parents:
diff changeset
749 p_asm(int e)
kono
parents:
diff changeset
750 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
751 int param=caddr(e);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
752 int e1 = p_list_expr(cadddr(e));
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
753 return list4(ST_ASM,pexpr(cadr(e)),param,e1);
462
kono
parents:
diff changeset
754 }
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 static int
kono
parents:
diff changeset
757 p_label(int e)
kono
parents:
diff changeset
758 {
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
759 return list3(ST_LABEL,pexpr(cadr(e)),caddr(e));
462
kono
parents:
diff changeset
760 }
kono
parents:
diff changeset
761
kono
parents:
diff changeset
762 static int
kono
parents:
diff changeset
763 p_bool(int e)
kono
parents:
diff changeset
764 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
765 error(-1);
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
766 return e;
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
767 }
462
kono
parents:
diff changeset
768
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
769 static int
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
770 p_comment(int e)
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
771 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
772 return list3(ST_COMMENT,pexpr(cadr(e)),caddr(e));
462
kono
parents:
diff changeset
773 }
kono
parents:
diff changeset
774
508
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
775 static int
512
53ec17a8af7d inline continue....
kono
parents: 511
diff changeset
776 p_inline(int e)
508
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
777 {
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
778 int e3;
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
779 int narg;
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
780
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
781 /* inline function arguments */
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
782 narg = 0;
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
783 for (e3 = caddr(e); e3; e3 = cadr(e3)) {
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
784 narg=list3(pexpr(car(e3)),narg,caddr(e3));
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
785 }
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
786 return list4(INLINE,cadr(e),reverse0(narg),cadddr(e));
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
787 }
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
788
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
789 extern int
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
790 pexpr(int e1)
462
kono
parents:
diff changeset
791 {
kono
parents:
diff changeset
792 int e2,e3;
kono
parents:
diff changeset
793
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
794 // if (inmode) error(-1);
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
795 if (e1==0) return 0;
462
kono
parents:
diff changeset
796 e2 = cadr(e1);
kono
parents:
diff changeset
797 switch (car(e1)){
kono
parents:
diff changeset
798 case GVAR: case RGVAR: case CRGVAR: case CURGVAR: case SRGVAR:
kono
parents:
diff changeset
799 case SURGVAR: case REGISTER:
kono
parents:
diff changeset
800 case DREGISTER: case FREGISTER:
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
801 case FRGVAR: case DRGVAR:
462
kono
parents:
diff changeset
802 case LREGISTER:
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
803 case LRGVAR: case LURGVAR:
462
kono
parents:
diff changeset
804 case LABEL: case CONST:
kono
parents:
diff changeset
805 case DCONST: case FCONST:
kono
parents:
diff changeset
806 case LCONST:
kono
parents:
diff changeset
807 case STRING:
kono
parents:
diff changeset
808 case FNAME:
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
809 case FLABEL:
462
kono
parents:
diff changeset
810 case RSTRUCT:
kono
parents:
diff changeset
811 return e1;
kono
parents:
diff changeset
812 case LVAR:
kono
parents:
diff changeset
813 case RLVAR: case CRLVAR: case CURLVAR: case SRLVAR: case SURLVAR:
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
814 case FRLVAR: case DRLVAR:
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
815 case LRLVAR: case LURLVAR:
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
816 return e1;
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
817 case IVAR:
462
kono
parents:
diff changeset
818 return p_lvar(e1);
kono
parents:
diff changeset
819 case FUNCTION:
kono
parents:
diff changeset
820 return pfunction(e1);
kono
parents:
diff changeset
821 case CODE:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
822 return list2(car(e1),pexpr(e2));
462
kono
parents:
diff changeset
823 case INLINE:
512
53ec17a8af7d inline continue....
kono
parents: 511
diff changeset
824 return p_inline(e1);
462
kono
parents:
diff changeset
825 case INDIRECT:
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
826 return pindirect(e1);
462
kono
parents:
diff changeset
827 case RINDIRECT: case URINDIRECT:
kono
parents:
diff changeset
828 case CRINDIRECT: case CURINDIRECT:
kono
parents:
diff changeset
829 case SRINDIRECT: case SURINDIRECT:
kono
parents:
diff changeset
830 case FRINDIRECT: case DRINDIRECT:
kono
parents:
diff changeset
831 case LRINDIRECT: case LURINDIRECT:
kono
parents:
diff changeset
832 return prindirect(e1);
kono
parents:
diff changeset
833 case ADDRESS:
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
834 return paddress(e1);
462
kono
parents:
diff changeset
835 case MINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
836 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
837 if (car(e3)==CONST) return list2(CONST,-cadr(e3));
kono
parents:
diff changeset
838 return list2(car(e1),e3);
kono
parents:
diff changeset
839 #if LONGLONG_CODE
kono
parents:
diff changeset
840 case LMINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
841 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
842 if (car(e3)==LCONST) return llist2(LCONST,-lcadr(e3));
kono
parents:
diff changeset
843 return list2(car(e1),e3);
kono
parents:
diff changeset
844 #endif
kono
parents:
diff changeset
845 #if FLOAT_CODE
kono
parents:
diff changeset
846 case DMINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
847 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
848 if (car(e3)==DCONST) return dlist2(DCONST,-dcadr(e3));
kono
parents:
diff changeset
849 if (car(e3)==FCONST) return dlist2(FCONST,-dcadr(e3));
kono
parents:
diff changeset
850 return list2(car(e1),e3);
kono
parents:
diff changeset
851 case FMINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
852 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
853 if (car(e3)==DCONST) return dlist2(DCONST,-dcadr(e3));
kono
parents:
diff changeset
854 if (car(e3)==FCONST) return dlist2(FCONST,-dcadr(e3));
kono
parents:
diff changeset
855 return list2(car(e1),e3);
kono
parents:
diff changeset
856 #endif
kono
parents:
diff changeset
857 case CONV:
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
858 return p_conv(caddr(e1),e2);
462
kono
parents:
diff changeset
859 case BNOT: /* ~ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
860 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
861 if (car(e3)==CONST) return list2(CONST,~cadr(e3));
kono
parents:
diff changeset
862 return list2(BNOT,e3);
kono
parents:
diff changeset
863 case LNOT: /* ! */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
864 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
865 if (car(e3)==CONST) return list2(CONST,!cadr(e3));
kono
parents:
diff changeset
866 return list2(LNOT,e3);
kono
parents:
diff changeset
867 case PREINC:
kono
parents:
diff changeset
868 case UPREINC:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
869 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
870 if (car(e3)==CONST) return list2(CONST,cadr(e3)+1);
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
871 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
872 case POSTINC:
kono
parents:
diff changeset
873 case UPOSTINC:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
874 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
875 if (car(e3)==CONST) return e3;
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
876 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
877 #if FLOAT_CODE
kono
parents:
diff changeset
878 case DPREINC: /* ++d */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
879 if ((e3 = pexpr(e2))==e2) return e1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
880 if (car(e3)==FCONST) return dlist2(FCONST,dcadr(e3)+cadr(e2));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
881 if (car(e3)==DCONST) return dlist2(DCONST,dcadr(e3)+cadr(e2));
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
882 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
883 case DPOSTINC: /* d++ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
884 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
885 if (car(e3)==FCONST||car(e3)==DCONST) return e3;
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
886 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
887 case FPREINC: /* ++f */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
888 if ((e3 = pexpr(e2))==e2) return e1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
889 if (car(e3)==FCONST) return dlist2(FCONST,dcadr(e3)+cadr(e2));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
890 if (car(e3)==DCONST) return dlist2(DCONST,dcadr(e3)+cadr(e2));
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
891 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
892 case FPOSTINC: /* f++ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
893 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
894 if (car(e3)==FCONST||car(e3)==DCONST) return e3;
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
895 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
896 #endif
kono
parents:
diff changeset
897 #if LONGLONG_CODE
kono
parents:
diff changeset
898 case LPREINC: /* ++d */
kono
parents:
diff changeset
899 case LUPREINC: /* ++d */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
900 if ((e3 = pexpr(e2))==e2) return e1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
901 if (car(e3)==LCONST) return llist2(LCONST,lcadr(e3)+cadr(e2));
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
902 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
903 case LPOSTINC: /* d++ */
kono
parents:
diff changeset
904 case LUPOSTINC: /* d++ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
905 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
906 if (car(e3)==LCONST) return e3;
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
907 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
908 #endif
kono
parents:
diff changeset
909 case MUL: case UMUL:
kono
parents:
diff changeset
910 case DIV: case UDIV:
kono
parents:
diff changeset
911 case MOD: case UMOD:
kono
parents:
diff changeset
912 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT:
kono
parents:
diff changeset
913 case ADD: case SUB: case BAND: case EOR: case BOR: case CMP: case CMPGE:
kono
parents:
diff changeset
914 case UCMP: case CMPEQ: case CMPNEQ: case UCMPGE:
kono
parents:
diff changeset
915 #if FLOAT_CODE
kono
parents:
diff changeset
916 case DMUL: case DDIV:
kono
parents:
diff changeset
917 case DADD: case DSUB:
kono
parents:
diff changeset
918 case DCMP: case DCMPGE: case DCMPEQ: case DCMPNEQ:
kono
parents:
diff changeset
919 case FMUL: case FDIV:
kono
parents:
diff changeset
920 case FADD: case FSUB:
kono
parents:
diff changeset
921 case FCMP: case FCMPGE: case FCMPEQ: case FCMPNEQ:
kono
parents:
diff changeset
922 #endif
kono
parents:
diff changeset
923 #if LONGLONG_CODE
kono
parents:
diff changeset
924 case LMUL: case LUMUL:
kono
parents:
diff changeset
925 case LDIV: case LUDIV:
kono
parents:
diff changeset
926 case LMOD: case LUMOD:
kono
parents:
diff changeset
927 case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT:
kono
parents:
diff changeset
928 case LADD: case LSUB: case LBAND: case LEOR: case LBOR: case LCMP:
kono
parents:
diff changeset
929 #endif
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
930 return pbinop(car(e1),e2,caddr(e1));
528
d6fff671793a minor fix inline
kono
parents: 527
diff changeset
931 case LCOND: case DCOND: case FCOND: case COND: case UCOND: case LUCOND:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
932 e3 = pexpr(e2);
532
cecf5103679e cond fix
kono
parents: 531
diff changeset
933 if (car(e3)==CONST) return
cecf5103679e cond fix
kono
parents: 531
diff changeset
934 caddr(e1)? pexpr(cadr(e3)?caddr(e1):cadddr(e1)) :
cecf5103679e cond fix
kono
parents: 531
diff changeset
935 pexpr(cadr(e3)?e3:cadddr(e1)); // GNU extension h?:g
cecf5103679e cond fix
kono
parents: 531
diff changeset
936 return list4(car(e1),e3,pexpr(caddr(e1)),pexpr(cadddr(e1)));
462
kono
parents:
diff changeset
937 case STASS:
kono
parents:
diff changeset
938 return psassign(e1);
kono
parents:
diff changeset
939 case ASS: case CASS: case SASS:
kono
parents:
diff changeset
940 return passign(e1);
kono
parents:
diff changeset
941 case SASSOP: case SUASSOP:
kono
parents:
diff changeset
942 case ASSOP: case CASSOP: case CUASSOP:
kono
parents:
diff changeset
943 return passop(e1);
kono
parents:
diff changeset
944 #if FLOAT_CODE
kono
parents:
diff changeset
945 case FASS: case DASS:
kono
parents:
diff changeset
946 return pdassign(e1);
kono
parents:
diff changeset
947 case DASSOP: case FASSOP:
kono
parents:
diff changeset
948 return pdassop(e1);
kono
parents:
diff changeset
949 #endif
kono
parents:
diff changeset
950 #if LONGLONG_CODE
kono
parents:
diff changeset
951 case LASS:
kono
parents:
diff changeset
952 return plassign(e1);
kono
parents:
diff changeset
953 case LASSOP: case LUASSOP:
kono
parents:
diff changeset
954 return plassop(e1);
kono
parents:
diff changeset
955 #endif
kono
parents:
diff changeset
956 case ALLOCA:
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
957 return palloc(e2);
462
kono
parents:
diff changeset
958 case BUILTINP:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
959 return list2(CONST,is_const(pexpr(e2)));
462
kono
parents:
diff changeset
960 case COMMA:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
961 return pcomma(pexpr(e2),pexpr(caddr(e1)));
462
kono
parents:
diff changeset
962 case RETURN:
kono
parents:
diff changeset
963 case ENVIRONMENT:
kono
parents:
diff changeset
964 case LCALL:
kono
parents:
diff changeset
965 return e1;
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
966 // relational operator
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
967 case GT: case UGT: case GE: case UGE: case LT:
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
968 case ULT: case LE: case ULE:
526
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
969 case LOP+GT: case LOP+UGT: case LOP+GE: case LOP+UGE: case LOP+LT:
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
970 case LOP+ULT: case LOP+LE: case LOP+ULE:
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
971 case DOP+GT: case DOP+GE: case DOP+LT: case DOP+LE:
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
972 case FOP+GT: case FOP+GE: case FOP+LT: case FOP+LE:
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
973 case FOP+EQ: case FOP+NEQ:
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
974 case EQ: case NEQ: case DOP+EQ: case DOP+NEQ:
526
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
975 case LOP+EQ: case LOP+NEQ:
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
976 return prexpr(car(e1),cadr(e1),caddr(e1));
526
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
977 case LAND:
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
978 return pland(car(e1),cadr(e1),caddr(e1));
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
979 case LOR:
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
980 return plor(car(e1),cadr(e1),caddr(e1));
462
kono
parents:
diff changeset
981 #if BIT_FIELD_CODE
kono
parents:
diff changeset
982 case RBIT_FIELD:
kono
parents:
diff changeset
983 return prbit_field(e1);
kono
parents:
diff changeset
984 case BASS:
kono
parents:
diff changeset
985 return pbassign(e1);
kono
parents:
diff changeset
986 case BPREINC:
kono
parents:
diff changeset
987 case BPOSTINC:
kono
parents:
diff changeset
988 case BASSOP:
kono
parents:
diff changeset
989 return pbassop(e1);
kono
parents:
diff changeset
990 #endif
kono
parents:
diff changeset
991 #if ASM_CODE
kono
parents:
diff changeset
992 case ASM:
kono
parents:
diff changeset
993 return list3(ASM,list4(
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
994 car(e2),cadr(e2),caddr(e2),cadddr(e2)),
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
995 caddr(e1));
462
kono
parents:
diff changeset
996 #endif
kono
parents:
diff changeset
997 case ST_DECL: return p_decl(e1);
kono
parents:
diff changeset
998 case ST_IF: return p_if(e1);
kono
parents:
diff changeset
999 case ST_DO: return p_do(e1);
kono
parents:
diff changeset
1000 case ST_WHILE: return p_while(e1);
kono
parents:
diff changeset
1001 case ST_FOR: return p_for(e1);
kono
parents:
diff changeset
1002 case ST_SWITCH: return p_switch(e1);
kono
parents:
diff changeset
1003 case ST_COMP: return p_comp(e1);
kono
parents:
diff changeset
1004 case ST_BREAK: return p_break(e1);
kono
parents:
diff changeset
1005 case ST_CONTINUE: return p_continue(e1);
kono
parents:
diff changeset
1006 case ST_CASE: return p_case(e1);
kono
parents:
diff changeset
1007 case ST_DEFAULT: return p_default(e1);
kono
parents:
diff changeset
1008 case ST_RETURN: return p_return(e1);
kono
parents:
diff changeset
1009 case ST_GOTO: return p_goto(e1);
kono
parents:
diff changeset
1010 case ST_ASM: return p_asm(e1);
kono
parents:
diff changeset
1011 case ST_LABEL: return p_label(e1);
kono
parents:
diff changeset
1012 case ST_COMMENT: return p_comment(e1);
kono
parents:
diff changeset
1013 default:
kono
parents:
diff changeset
1014 return p_bool(e1);
kono
parents:
diff changeset
1015 }
kono
parents:
diff changeset
1016 return VOID;
kono
parents:
diff changeset
1017 }
kono
parents:
diff changeset
1018
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1019 #define round4(i) ((i+(SIZE_OF_INT-1))&~(SIZE_OF_INT-1))
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1020
531
19f5882997f5 *** empty log message ***
kono
parents: 530
diff changeset
1021 // extern int lreg_count;
530
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
1022
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1023 extern int
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1024 gen_inline(int e)
462
kono
parents:
diff changeset
1025 {
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1026 // these saved value should be some struct
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1027 int sretlabel;
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1028 NMTBL *sfnptr;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1029 int svartable = pvartable;
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1030 int sretcont = retcont;
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1031 int scslabel = cslabel;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1032 int sdisp = pdisp;
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1033 int sret_register = ret_register;
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1034 int sret_reg_mode = ret_reg_mode;
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1035 int sinline_lvars = inline_lvars;
528
d6fff671793a minor fix inline
kono
parents: 527
diff changeset
1036 int slfree=lfree;
531
19f5882997f5 *** empty log message ***
kono
parents: 530
diff changeset
1037 // int slreg_count=lreg_count;
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1038
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1039 int narg,arg;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1040 NMTBL *n = (NMTBL*)cadr(cadr(e));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1041 int e1 = attr_value(n,INLINE);
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
1042 int parse = car(e1); // inline parse tree
519
b6eb97f0c11d *** empty log message ***
kono
parents: 514
diff changeset
1043 int arg_disp = cadr(e1); // number of arguments
511
14c7faf78910 inline continue (first binary run)
kono
parents: 510
diff changeset
1044 int e2,e3,t,e4,dots;
508
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
1045 int ret_type = function_type(cadddr(e),&dots);
526
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
1046 int fargtype;
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
1047 NMTBL *anptr;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1048
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1049 // checkret();
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1050
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1051 sretlabel = retlabel;
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1052 sfnptr = fnptr;
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1053 retcont = 0;
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1054 cslabel = -1;
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1055 retpending = 0;
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1056 ret_reg_mode = 0;
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1057 ret_register = 5555;
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1058 inline_lvars = 0;
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1059 retlabel = fwdlabel();
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1060
511
14c7faf78910 inline continue (first binary run)
kono
parents: 510
diff changeset
1061 enter_scope(); // to make label scope happy
14c7faf78910 inline continue (first binary run)
kono
parents: 510
diff changeset
1062
510
2bd6ff6ee9a8 inline continue...
kono
parents: 509
diff changeset
1063 fnptr = n; // st_return see this
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
1064 pvartable = p_vartable(e,arg_disp,caddr(e1));
526
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
1065
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
1066 /* function arguments type */
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
1067 fargtype = n->dsp; // we cannot do destruct reverse here
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
1068
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1069 /* inline function arguments */
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1070 narg = 0;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1071 for (e3 = e1 = reverse0(caddr(e)); e3; e3 = cadr(e3)) {
526
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
1072 anptr = (NMTBL*)caddr(fargtype);
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
1073 t=caddr(e3); // type
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
1074 e4 = car(e3);
524
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
1075 if (0 && is_const(e4) /* ||(is_memory(e3)&&is_readonly(e3)) */ ) {
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
1076 heap[pdisp+narg]=e4;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1077 } else {
509
e58848f6ebc1 inline continue...
kono
parents: 508
diff changeset
1078 arg = heap[pdisp+narg]=list3(LVAR,new_lvar(size(t)),0);
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1079 inline_lvars = glist2(arg,inline_lvars);
509
e58848f6ebc1 inline continue...
kono
parents: 508
diff changeset
1080 // should contain correct argument variable name
529
ad874ef77dde use_input_reg...
kono
parents: 528
diff changeset
1081 // if (anptr) printf("## var %s\n",anptr->nm);
ad874ef77dde use_input_reg...
kono
parents: 528
diff changeset
1082 // else printf("## var 0\n");
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
1083 g_expr_u(assign_expr0(arg,e4,t,t));
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1084 }
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
1085 narg ++;
526
9ff5cd7afe2f *** empty log message ***
kono
parents: 525
diff changeset
1086 fargtype = cadr(fargtype);
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1087 }
508
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
1088 caddr(e) = reverse0(e1); // make it normal
511
14c7faf78910 inline continue (first binary run)
kono
parents: 510
diff changeset
1089 e2 = pexpr(parse);
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
1090 pdisp = sdisp;
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
1091 pvartable = svartable;
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1092
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1093 if (ret_type!=VOID)
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1094 g_expr0(e2);
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1095 else
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1096 g_expr_u(e2);
524
135afeb2e134 inline first work. no constant propagation.
kono
parents: 519
diff changeset
1097 checkret();
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1098 fwddef(retlabel);
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1099 control=1;
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1100
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1101 if (retcont) error(STERR); // inline can't handle return/environment
510
2bd6ff6ee9a8 inline continue...
kono
parents: 509
diff changeset
1102
511
14c7faf78910 inline continue (first binary run)
kono
parents: 510
diff changeset
1103 leave_scope();
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1104 while(inline_lvars) {
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1105 int e;
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1106 int l = car(inline_lvars);
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1107 switch(car(l)) {
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1108 case LVAR: free_lvar(cadr(l)); break;
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1109 case REGISTER: case DREGISTER:
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1110 case FREGISTER: case LREGISTER:
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1111 free_register(cadr(l));
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1112 }
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1113 e = cadr(inline_lvars);
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1114 free_glist2(inline_lvars);
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1115 inline_lvars = e;
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1116 }
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1117 fnptr = sfnptr;
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1118 retlabel = sretlabel;
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1119 retcont = sretcont;
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1120 cslabel = scslabel;
514
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1121 ret_register = sret_register;
a2047e4555be inline continue....
kono
parents: 513
diff changeset
1122 ret_reg_mode = sret_reg_mode;
527
6b0fd56848e6 inline continue....
kono
parents: 526
diff changeset
1123 inline_lvars = sinline_lvars;
528
d6fff671793a minor fix inline
kono
parents: 527
diff changeset
1124 lfree=slfree;
513
4c2607e72ab5 inline continue... fix function call
kono
parents: 512
diff changeset
1125
531
19f5882997f5 *** empty log message ***
kono
parents: 530
diff changeset
1126 // if (slreg_count!=lreg_count && lreg_count>0) {
19f5882997f5 *** empty log message ***
kono
parents: 530
diff changeset
1127 // printf("## lreg_count %d != %d\n", slreg_count,lreg_count);
19f5882997f5 *** empty log message ***
kono
parents: 530
diff changeset
1128 // }
530
58aceee8e4b4 get_lregister messed up
kono
parents: 529
diff changeset
1129
508
d8102a46b78d inline test routine first compile passed.
kono
parents: 506
diff changeset
1130 return ret_type;
462
kono
parents:
diff changeset
1131 }
kono
parents:
diff changeset
1132
kono
parents:
diff changeset
1133 /* end */