annotate mc-inline.c @ 464:d88f08d81bba

inline continue.... const type lvar offset for inline local will be add
author kono
date Tue, 07 Dec 2004 12:30:18 +0900
parents 50a59dfb4606
children 0a4ca939f403
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
kono
parents:
diff changeset
15 /*
kono
parents:
diff changeset
16 Basic code generator from parse tree
kono
parents:
diff changeset
17 */
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 extern void
kono
parents:
diff changeset
20 st_decl(int e1){
kono
parents:
diff changeset
21 // NMTBL *n = (NMTBL *)caddr(e1);
kono
parents:
diff changeset
22 // int stmode = cadddr(e1);
kono
parents:
diff changeset
23 }
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 extern void
kono
parents:
diff changeset
26 st_if(int e1){
kono
parents:
diff changeset
27 int l1,l2,slfree;
kono
parents:
diff changeset
28 int e2=caddr(e1),e3;
kono
parents:
diff changeset
29 // conv->if_();
kono
parents:
diff changeset
30 slfree=lfree;
kono
parents:
diff changeset
31 checkret();
kono
parents:
diff changeset
32 l1 = bexpr(car(e2),0,fwdlabel());
kono
parents:
diff changeset
33 // conv->if_then_();
kono
parents:
diff changeset
34 g_expr_u(cadr(e2));
kono
parents:
diff changeset
35 checkret();
kono
parents:
diff changeset
36 if ((e3=caddr(e2))) { // else
kono
parents:
diff changeset
37 // conv->if_else_();
kono
parents:
diff changeset
38 if ((l2 = control))
kono
parents:
diff changeset
39 gen_jmp(l2=fwdlabel());
kono
parents:
diff changeset
40 fwddef(l1);
kono
parents:
diff changeset
41 g_expr_u(e3);
kono
parents:
diff changeset
42 checkret();
kono
parents:
diff changeset
43 if (l2) fwddef(l2);
kono
parents:
diff changeset
44 } else {
kono
parents:
diff changeset
45 fwddef(l1);
kono
parents:
diff changeset
46 }
kono
parents:
diff changeset
47 // conv->if_endif_();
kono
parents:
diff changeset
48 }
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 extern void
kono
parents:
diff changeset
52 st_do(int e1){
kono
parents:
diff changeset
53 int sbreak,scontinue,l;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 sbreak=blabel;
kono
parents:
diff changeset
56 scontinue=clabel;
kono
parents:
diff changeset
57 blabel=fwdlabel();
kono
parents:
diff changeset
58 clabel=fwdlabel();
kono
parents:
diff changeset
59 control=1;
kono
parents:
diff changeset
60 checkret();
kono
parents:
diff changeset
61 l=backdef();
kono
parents:
diff changeset
62 // conv->dowhile_();
kono
parents:
diff changeset
63 g_expr_u(cadddr(e1));
kono
parents:
diff changeset
64 checkret();
kono
parents:
diff changeset
65 // conv->dowhile_cond_();
kono
parents:
diff changeset
66 bexpr(caddr(e1),1,l);
kono
parents:
diff changeset
67 // conv->dowhile_end_();
kono
parents:
diff changeset
68 fwddef(blabel);
kono
parents:
diff changeset
69 clabel=scontinue;
kono
parents:
diff changeset
70 blabel=sbreak;
kono
parents:
diff changeset
71 }
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 extern void
kono
parents:
diff changeset
75 st_while(int e1){
kono
parents:
diff changeset
76 int sbreak,scontinue,e;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 sbreak=blabel;
kono
parents:
diff changeset
79 scontinue=clabel;
kono
parents:
diff changeset
80 blabel=fwdlabel();
kono
parents:
diff changeset
81 control=1;
kono
parents:
diff changeset
82 checkret();
kono
parents:
diff changeset
83 clabel=backdef();
kono
parents:
diff changeset
84 // conv->while_();
kono
parents:
diff changeset
85 // conv->while_body_();
kono
parents:
diff changeset
86 if(!(e=cadddr(e1))) {
kono
parents:
diff changeset
87 bexpr(caddr(e1),1,clabel);
kono
parents:
diff changeset
88 // conv->sm_();
kono
parents:
diff changeset
89 } else {
kono
parents:
diff changeset
90 bexpr(caddr(e1),0,blabel);
kono
parents:
diff changeset
91 g_expr_u(e);
kono
parents:
diff changeset
92 checkret();
kono
parents:
diff changeset
93 if(control)
kono
parents:
diff changeset
94 gen_jmp(clabel);
kono
parents:
diff changeset
95 }
kono
parents:
diff changeset
96 // conv->while_end_();
kono
parents:
diff changeset
97 fwddef(blabel);
kono
parents:
diff changeset
98 clabel=scontinue;
kono
parents:
diff changeset
99 blabel=sbreak;
kono
parents:
diff changeset
100 }
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 extern void
kono
parents:
diff changeset
104 st_for(int e1){
kono
parents:
diff changeset
105 int p0,p1,p2,body;
kono
parents:
diff changeset
106 int l,e;
kono
parents:
diff changeset
107 int sbreak=blabel;
kono
parents:
diff changeset
108 int scontinue=clabel;
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 e = caddr(e1);
kono
parents:
diff changeset
111 p0 = car(e); p1 = cadr(e); p2 = caddr(e); body = cadddr(e);
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 blabel=fwdlabel();
kono
parents:
diff changeset
114 // conv->for_();
kono
parents:
diff changeset
115 if (p0) {
kono
parents:
diff changeset
116 checkret();
kono
parents:
diff changeset
117 g_expr_u(p0);
kono
parents:
diff changeset
118 }
kono
parents:
diff changeset
119 // conv->for1_();
kono
parents:
diff changeset
120 control=1;
kono
parents:
diff changeset
121 checkret();
kono
parents:
diff changeset
122 l=backdef();
kono
parents:
diff changeset
123 if (p1) {
kono
parents:
diff changeset
124 bexpr(p1,0,blabel);
kono
parents:
diff changeset
125 }
kono
parents:
diff changeset
126 // conv->for2_();
kono
parents:
diff changeset
127 // conv->for_body_();
kono
parents:
diff changeset
128 if (!p2) {
kono
parents:
diff changeset
129 clabel=l;
kono
parents:
diff changeset
130 g_expr_u(body);
kono
parents:
diff changeset
131 checkret();
kono
parents:
diff changeset
132 } else {
kono
parents:
diff changeset
133 clabel=fwdlabel();
kono
parents:
diff changeset
134 g_expr_u(body);
kono
parents:
diff changeset
135 checkret();
kono
parents:
diff changeset
136 fwddef(clabel);
kono
parents:
diff changeset
137 g_expr_u(p2);
kono
parents:
diff changeset
138 }
kono
parents:
diff changeset
139 // conv->for_end_();
kono
parents:
diff changeset
140 gen_jmp(l);
kono
parents:
diff changeset
141 fwddef(blabel);
kono
parents:
diff changeset
142 clabel=scontinue;
kono
parents:
diff changeset
143 blabel=sbreak;
kono
parents:
diff changeset
144 }
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 extern void
kono
parents:
diff changeset
148 st_switch(int e1){
kono
parents:
diff changeset
149 int sbreak,scase,sdefault,slfree,svalue,slist;
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 checkret();
kono
parents:
diff changeset
152 slist = cslist;
kono
parents:
diff changeset
153 cslist = 0;
kono
parents:
diff changeset
154 sbreak=blabel; /* save parents break label */
kono
parents:
diff changeset
155 blabel=fwdlabel();
kono
parents:
diff changeset
156 sdefault=dlabel; /* save parents default label */
kono
parents:
diff changeset
157 dlabel=0;
kono
parents:
diff changeset
158 scase=cslabel; /* save parents next case label */
kono
parents:
diff changeset
159 // conv->switch_();
kono
parents:
diff changeset
160 slfree=lfree;
kono
parents:
diff changeset
161 svalue=csvalue1; /* save parents switch value */
kono
parents:
diff changeset
162 gexpr(caddr(e1),1);
kono
parents:
diff changeset
163 csvalue1=csvalue() ;
kono
parents:
diff changeset
164 // conv->switch_body_();
kono
parents:
diff changeset
165 cslabel = control = 0;
kono
parents:
diff changeset
166 g_expr_u(cadddr(e1));
kono
parents:
diff changeset
167 // conv->switch_end_();
kono
parents:
diff changeset
168 checkret();
kono
parents:
diff changeset
169 #if CASE_CODE
kono
parents:
diff changeset
170 if (control) gen_jmp(blabel);
kono
parents:
diff changeset
171 genswitch(cslist,cslabel);
kono
parents:
diff changeset
172 #else
kono
parents:
diff changeset
173 if(dlabel) def_label(cslabel,dlabel);
kono
parents:
diff changeset
174 else fwddef(cslabel);
kono
parents:
diff changeset
175 #endif
kono
parents:
diff changeset
176 csvalue1=svalue;
kono
parents:
diff changeset
177 cslabel=scase;
kono
parents:
diff changeset
178 dlabel=sdefault;
kono
parents:
diff changeset
179 fwddef(blabel);
kono
parents:
diff changeset
180 blabel=sbreak;
kono
parents:
diff changeset
181 cslist = slist;
kono
parents:
diff changeset
182 }
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 extern void
kono
parents:
diff changeset
186 st_comp(int e1){
kono
parents:
diff changeset
187 g_expr_u(caddr(e1));
kono
parents:
diff changeset
188 }
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 extern void
kono
parents:
diff changeset
192 st_break(int e1){
kono
parents:
diff changeset
193 checkret();
kono
parents:
diff changeset
194 // conv->break_();
kono
parents:
diff changeset
195 if (control)
kono
parents:
diff changeset
196 gen_jmp(blabel);
kono
parents:
diff changeset
197 }
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 extern void
kono
parents:
diff changeset
201 st_continue(int e1){
kono
parents:
diff changeset
202 checkret();
kono
parents:
diff changeset
203 // conv->continue_();
kono
parents:
diff changeset
204 if (control) gen_jmp(clabel);
kono
parents:
diff changeset
205 }
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 extern void
kono
parents:
diff changeset
209 st_case(int e1){
kono
parents:
diff changeset
210 #if CASE_CODE
kono
parents:
diff changeset
211 int l,clist=caddr(e1),c;
kono
parents:
diff changeset
212 l = fwdlabel();
kono
parents:
diff changeset
213 // conv->case_begin_(0,0);
kono
parents:
diff changeset
214 // conv->case_(0,0);
kono
parents:
diff changeset
215 if (retpending) {
kono
parents:
diff changeset
216 ret(); retpending=0;
kono
parents:
diff changeset
217 }
kono
parents:
diff changeset
218 if (!cslabel) {
kono
parents:
diff changeset
219 if (!control) {
kono
parents:
diff changeset
220 cmpdimm(car(clist),csvalue1,cslabel=fwdlabel(),1);
kono
parents:
diff changeset
221 caddr(clist)=0;
kono
parents:
diff changeset
222 } else {
kono
parents:
diff changeset
223 error(-1);
kono
parents:
diff changeset
224 }
kono
parents:
diff changeset
225 }
kono
parents:
diff changeset
226 while(clist) {
kono
parents:
diff changeset
227 caddr(clist) = l;
kono
parents:
diff changeset
228 clist = cadr(c=clist); cadr(c) = 0; // insert destroy cadr of clist
kono
parents:
diff changeset
229 cslist=insert_ascend(cslist,c,docase_eq);
kono
parents:
diff changeset
230 }
kono
parents:
diff changeset
231 fwddef(l);
kono
parents:
diff changeset
232 control=1;
kono
parents:
diff changeset
233 #else
kono
parents:
diff changeset
234 /* casading branch implementation */
kono
parents:
diff changeset
235 int c,l;
kono
parents:
diff changeset
236 c = caddr(e1);
kono
parents:
diff changeset
237 if (retpending) {
kono
parents:
diff changeset
238 ret(); retpending=0;
kono
parents:
diff changeset
239 }
kono
parents:
diff changeset
240 // conv->case_begin_(0,0);
kono
parents:
diff changeset
241 // conv->case_(0,0);
kono
parents:
diff changeset
242 l=fwdlabel();
kono
parents:
diff changeset
243 if (control) {
kono
parents:
diff changeset
244 control=0;
kono
parents:
diff changeset
245 gen_jmp(l);
kono
parents:
diff changeset
246 }
kono
parents:
diff changeset
247 if (cslabel) fwddef(cslabel);
kono
parents:
diff changeset
248 while(cadr(c)) {
kono
parents:
diff changeset
249 cmpdimm(car(c),csvalue1,l,0);
kono
parents:
diff changeset
250 c=cadr(c);
kono
parents:
diff changeset
251 }
kono
parents:
diff changeset
252 cmpdimm(car(c),csvalue1,cslabel=fwdlabel(),1);
kono
parents:
diff changeset
253 if (l) fwddef(l);
kono
parents:
diff changeset
254 #endif
kono
parents:
diff changeset
255 }
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 extern void
kono
parents:
diff changeset
259 st_default(int e1){
kono
parents:
diff changeset
260 control=1;
kono
parents:
diff changeset
261 checkret();
kono
parents:
diff changeset
262 if (dlabel) error(STERR); // double default:
kono
parents:
diff changeset
263 dlabel = backdef();
kono
parents:
diff changeset
264 // conv->case_(0,1);
kono
parents:
diff changeset
265 }
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 extern void
kono
parents:
diff changeset
269 st_return(int e1){
kono
parents:
diff changeset
270 int e;
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 if (!cslabel) gen_jmp(cslabel = fwdlabel());
kono
parents:
diff changeset
273 if(!(e=caddr(e1))) {
kono
parents:
diff changeset
274 // conv->return_();
kono
parents:
diff changeset
275 // conv->return_end_();
kono
parents:
diff changeset
276 retpending = 1;
kono
parents:
diff changeset
277 return;
kono
parents:
diff changeset
278 }
kono
parents:
diff changeset
279 // conv->return_();
kono
parents:
diff changeset
280 if (struct_return) {
kono
parents:
diff changeset
281 if ((car(type)==STRUCT || car(type)==UNION)&&
kono
parents:
diff changeset
282 size(type)==cadr(struct_return)) {
kono
parents:
diff changeset
283 if(car(e)==RSTRUCT && car(cadr(e))==FUNCTION) {
kono
parents:
diff changeset
284 /* pass the return pointer to the called function */
kono
parents:
diff changeset
285 replace_return_struct(cadr(e),
kono
parents:
diff changeset
286 rvalue_t(car(struct_return),caddr(struct_return)));
kono
parents:
diff changeset
287 replace_return_struct(cadr(e),
kono
parents:
diff changeset
288 rvalue_t(car(struct_return),caddr(struct_return)));
kono
parents:
diff changeset
289 gexpr(cadr(e),0);
kono
parents:
diff changeset
290 } else {
kono
parents:
diff changeset
291 type = caddr(struct_return);
kono
parents:
diff changeset
292 // e1 = rvalue_t(cadr(struct_return),INT); /* size */
kono
parents:
diff changeset
293 e1 = cadr(struct_return); /* size */
kono
parents:
diff changeset
294 gexpr(list4(STASS,rvalue(car(struct_return)),e,e1),0);
kono
parents:
diff changeset
295 }
kono
parents:
diff changeset
296 } else {
kono
parents:
diff changeset
297 error(TYERR); /* should check compatible */
kono
parents:
diff changeset
298 }
kono
parents:
diff changeset
299 } else {
kono
parents:
diff changeset
300 gexpr(correct_type(e,cadr(fnptr->ty)),1);
kono
parents:
diff changeset
301 }
kono
parents:
diff changeset
302 // conv->return_end_();
kono
parents:
diff changeset
303 retpending = 1;
kono
parents:
diff changeset
304 }
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 extern void
kono
parents:
diff changeset
308 st_goto(int e){
kono
parents:
diff changeset
309 NMTBL *nlist,*nptr0;
kono
parents:
diff changeset
310 int t,e1,e2,env;
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 checkret();
kono
parents:
diff changeset
313 // conv->goto_();
kono
parents:
diff changeset
314 e1 = caddr(e);
kono
parents:
diff changeset
315 if (car(e1)==RINDIRECT) {
kono
parents:
diff changeset
316 gen_indirect_goto(cadr(e1));
kono
parents:
diff changeset
317 return;
kono
parents:
diff changeset
318 } else if (car(e1)==FLABEL) {
kono
parents:
diff changeset
319 nlist = (NMTBL *)cadr(e1);
kono
parents:
diff changeset
320 nptr0 = name_space_search(nlist,0);
kono
parents:
diff changeset
321 t = nptr0->sc;
kono
parents:
diff changeset
322 if (t==EMPTY||t==EXTRN1||t==EXTRN) {
kono
parents:
diff changeset
323 nptr0 = make_local_scope(nlist,nptr0,0);
kono
parents:
diff changeset
324 nptr0->sc = FLABEL;
kono
parents:
diff changeset
325 nptr0->dsp = fwdlabel();
kono
parents:
diff changeset
326 } else if (!(t==FLABEL||t==BLABEL)) {
kono
parents:
diff changeset
327 error(STERR);
kono
parents:
diff changeset
328 }
kono
parents:
diff changeset
329 gen_jmp(nptr0->dsp);
kono
parents:
diff changeset
330 control=0;
kono
parents:
diff changeset
331 // conv->sm_();
kono
parents:
diff changeset
332 // conv->goto_label_(nptr0);
kono
parents:
diff changeset
333 return;
kono
parents:
diff changeset
334 } else {
kono
parents:
diff changeset
335 /* CbC continuation */
kono
parents:
diff changeset
336 // conv->jump_(env);
kono
parents:
diff changeset
337 e2 = cadr(e1);
kono
parents:
diff changeset
338 env = caddr(e1);
kono
parents:
diff changeset
339 if (car(e2) == FNAME) {
kono
parents:
diff changeset
340 nptr0=(NMTBL *)cadr(e2);
kono
parents:
diff changeset
341 if (nptr0->sc==EMPTY)
kono
parents:
diff changeset
342 nptr0->sc = EXTRN1;
kono
parents:
diff changeset
343 else if(nptr0->sc==FUNCTION)
kono
parents:
diff changeset
344 nptr0->sc = CODE;
kono
parents:
diff changeset
345 if (nptr0->ty>0&&car(nptr0->ty)==FUNCTION)
kono
parents:
diff changeset
346 car(nptr0->ty)=CODE;
kono
parents:
diff changeset
347 }
kono
parents:
diff changeset
348 gexpr(list3(CODE,e1,env),0);
kono
parents:
diff changeset
349 control=0;
kono
parents:
diff changeset
350 // conv->sm_();
kono
parents:
diff changeset
351 return;
kono
parents:
diff changeset
352 }
kono
parents:
diff changeset
353 }
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 #if ASM_CODE
kono
parents:
diff changeset
357 extern void
kono
parents:
diff changeset
358 st_asm(int e1){
kono
parents:
diff changeset
359 checkret();
kono
parents:
diff changeset
360 g_expr_u(list3(ASM,caddr(e1),cadddr(e1)));
kono
parents:
diff changeset
361 }
kono
parents:
diff changeset
362 #endif
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 extern void
kono
parents:
diff changeset
366 st_label(int e1){
kono
parents:
diff changeset
367 NMTBL *nptr,*nlist;
kono
parents:
diff changeset
368 nlist = (NMTBL *)caddr(e1);
kono
parents:
diff changeset
369 nptr = name_space_search(nlist,0);
kono
parents:
diff changeset
370 control=1;
kono
parents:
diff changeset
371 checkret();
kono
parents:
diff changeset
372 if(nptr->sc == FLABEL) {
kono
parents:
diff changeset
373 fwddef(nptr->dsp);
kono
parents:
diff changeset
374 } else if(nptr->sc != EMPTY && nptr->sc != EXTRN1 && nptr->sc !=BLABEL) {
kono
parents:
diff changeset
375 error(TYERR);
kono
parents:
diff changeset
376 } else {
kono
parents:
diff changeset
377 nptr->sc=EMPTY;
kono
parents:
diff changeset
378 nptr = make_local_scope(nlist,nptr,0);
kono
parents:
diff changeset
379 nptr->sc = BLABEL;
kono
parents:
diff changeset
380 nptr->dsp = backdef();
kono
parents:
diff changeset
381 }
kono
parents:
diff changeset
382 // conv->label_();
kono
parents:
diff changeset
383 }
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 extern void
kono
parents:
diff changeset
386 st_comment(int e1){
kono
parents:
diff changeset
387 gen_comment((char *)caddr(e1));
kono
parents:
diff changeset
388 }
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 /*
kono
parents:
diff changeset
391 partial evaluator
kono
parents:
diff changeset
392 */
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 static int
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
395 p_vartable(int e,int adisp,int ldisp)
462
kono
parents:
diff changeset
396 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
397 int i;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
398 pvartable = getfree(adisp+ldisp);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
399 pdisp = pvartable+adisp;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
400 for(i=adisp+ldisp;i>=0;i--) {
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
401 pvartable = 0;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
402 }
462
kono
parents:
diff changeset
403 return 0;
kono
parents:
diff changeset
404 }
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 static int
kono
parents:
diff changeset
407 p_lvar(int e1)
kono
parents:
diff changeset
408 {
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
409 int sz = is_memory(e1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
410 int d = cadr(e1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
411 int d1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
412 if ((d1=(heap[pdisp+e1]))) return d1;
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
413 return (heap[pdisp+d]=new_lvar(sz));
462
kono
parents:
diff changeset
414 }
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 static int
kono
parents:
diff changeset
417 pfunction(int e)
kono
parents:
diff changeset
418 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
419 return e;
462
kono
parents:
diff changeset
420 }
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 static int
kono
parents:
diff changeset
423 prindirect(int e)
kono
parents:
diff changeset
424 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
425 return e;
462
kono
parents:
diff changeset
426 }
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 static int
kono
parents:
diff changeset
429 paddress(int e)
kono
parents:
diff changeset
430 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
431 return e;
462
kono
parents:
diff changeset
432 }
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 static int
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
435 p_conv(int e1,int e2)
462
kono
parents:
diff changeset
436 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
437 return e1;
462
kono
parents:
diff changeset
438 }
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 static int
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
441 pbinop(int op,int e1,int e2)
462
kono
parents:
diff changeset
442 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
443 return e1;
462
kono
parents:
diff changeset
444 }
kono
parents:
diff changeset
445
kono
parents:
diff changeset
446 static int
kono
parents:
diff changeset
447 psassign(int e)
kono
parents:
diff changeset
448 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
449 return e;
462
kono
parents:
diff changeset
450 }
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 static int
kono
parents:
diff changeset
453 passign(int e)
kono
parents:
diff changeset
454 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
455 return e;
462
kono
parents:
diff changeset
456 }
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 static int
kono
parents:
diff changeset
459 passop(int e)
kono
parents:
diff changeset
460 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
461 return e;
462
kono
parents:
diff changeset
462 }
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 static int
kono
parents:
diff changeset
465 pdassign(int e)
kono
parents:
diff changeset
466 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
467 return e;
462
kono
parents:
diff changeset
468 }
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 static int
kono
parents:
diff changeset
471 pdassop(int e)
kono
parents:
diff changeset
472 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
473 return e;
462
kono
parents:
diff changeset
474 }
kono
parents:
diff changeset
475
kono
parents:
diff changeset
476 static int
kono
parents:
diff changeset
477 plassign(int e)
kono
parents:
diff changeset
478 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
479 return e;
462
kono
parents:
diff changeset
480 }
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 static int
kono
parents:
diff changeset
483 plassop(int e)
kono
parents:
diff changeset
484 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
485 return e;
462
kono
parents:
diff changeset
486 }
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 static int
kono
parents:
diff changeset
489 palloc(int e)
kono
parents:
diff changeset
490 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
491 return e;
462
kono
parents:
diff changeset
492 }
kono
parents:
diff changeset
493
kono
parents:
diff changeset
494 static int
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
495 pcomma(int e1,int e2)
462
kono
parents:
diff changeset
496 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
497 return e1;
462
kono
parents:
diff changeset
498 }
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 static int
kono
parents:
diff changeset
501 prbit_field(int e)
kono
parents:
diff changeset
502 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
503 return e;
462
kono
parents:
diff changeset
504 }
kono
parents:
diff changeset
505
kono
parents:
diff changeset
506 static int
kono
parents:
diff changeset
507 pbassign(int e)
kono
parents:
diff changeset
508 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
509 return e;
462
kono
parents:
diff changeset
510 }
kono
parents:
diff changeset
511
kono
parents:
diff changeset
512 static int
kono
parents:
diff changeset
513 pbassop(int e)
kono
parents:
diff changeset
514 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
515 return e;
462
kono
parents:
diff changeset
516 }
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 static int
kono
parents:
diff changeset
519 p_decl(int e)
kono
parents:
diff changeset
520 {
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
521 // list4(ST_DECL,parse,(int)n,stmode);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
522 int stmode=cadddr(e);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
523 NMTBL *n=(NMTBL*)caddr(e);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
524 int dsp = n->dsp;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
525 int v;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
526 switch(stmode) {
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
527 case REGISTER:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
528 switch(n->ty) {
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
529 case ULONGLONG: case LONGLONG:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
530 v = get_lregister_var(n); break;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
531 case FLOAT:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
532 v = get_dregister_var(n,0); break;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
533 case DOUBLE:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
534 v = get_dregister_var(n,1); break;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
535 default:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
536 if (scalar(n->ty))
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
537 v = get_dregister_var(n,1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
538 else
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
539 error(TYERR);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
540 }
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
541 case EXTRN: case EXTRN1: case STATIC:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
542 return pexpr(cadr(e));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
543 default:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
544 v = new_lvar(size(n->dsp));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
545 }
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
546 if (heap[pdisp+dsp]) error(-1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
547 heap[pdisp+dsp]=v;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
548 return pexpr(cadr(e));
462
kono
parents:
diff changeset
549 }
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 static int
kono
parents:
diff changeset
552 p_if(int e)
kono
parents:
diff changeset
553 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
554 return e;
462
kono
parents:
diff changeset
555 }
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 static int
kono
parents:
diff changeset
558 p_do(int e)
kono
parents:
diff changeset
559 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
560 return e;
462
kono
parents:
diff changeset
561 }
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 static int
kono
parents:
diff changeset
564 p_while(int e)
kono
parents:
diff changeset
565 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
566 return e;
462
kono
parents:
diff changeset
567 }
kono
parents:
diff changeset
568
kono
parents:
diff changeset
569 static int
kono
parents:
diff changeset
570 p_for(int e)
kono
parents:
diff changeset
571 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
572 return e;
462
kono
parents:
diff changeset
573 }
kono
parents:
diff changeset
574
kono
parents:
diff changeset
575 static int
kono
parents:
diff changeset
576 p_switch(int e)
kono
parents:
diff changeset
577 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
578 return e;
462
kono
parents:
diff changeset
579 }
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581 static int
kono
parents:
diff changeset
582 p_comp(int e)
kono
parents:
diff changeset
583 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
584 return e;
462
kono
parents:
diff changeset
585 }
kono
parents:
diff changeset
586
kono
parents:
diff changeset
587 static int
kono
parents:
diff changeset
588 p_break(int e)
kono
parents:
diff changeset
589 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
590 return e;
462
kono
parents:
diff changeset
591 }
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 static int
kono
parents:
diff changeset
594 p_continue(int e)
kono
parents:
diff changeset
595 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
596 return e;
462
kono
parents:
diff changeset
597 }
kono
parents:
diff changeset
598
kono
parents:
diff changeset
599 static int
kono
parents:
diff changeset
600 p_case(int e)
kono
parents:
diff changeset
601 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
602 return e;
462
kono
parents:
diff changeset
603 }
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 static int
kono
parents:
diff changeset
606 p_default(int e)
kono
parents:
diff changeset
607 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
608 return e;
462
kono
parents:
diff changeset
609 }
kono
parents:
diff changeset
610
kono
parents:
diff changeset
611 static int
kono
parents:
diff changeset
612 p_return(int e)
kono
parents:
diff changeset
613 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
614 return e;
462
kono
parents:
diff changeset
615 }
kono
parents:
diff changeset
616
kono
parents:
diff changeset
617 static int
kono
parents:
diff changeset
618 p_goto(int e)
kono
parents:
diff changeset
619 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
620 return e;
462
kono
parents:
diff changeset
621 }
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 static int
kono
parents:
diff changeset
624 p_asm(int e)
kono
parents:
diff changeset
625 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
626 return e;
462
kono
parents:
diff changeset
627 }
kono
parents:
diff changeset
628
kono
parents:
diff changeset
629 static int
kono
parents:
diff changeset
630 p_label(int e)
kono
parents:
diff changeset
631 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
632 return e;
462
kono
parents:
diff changeset
633 }
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 static int
kono
parents:
diff changeset
636 p_bool(int e)
kono
parents:
diff changeset
637 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
638 return e;
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
639 }
462
kono
parents:
diff changeset
640
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
641 static int
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
642 p_comment(int e)
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
643 {
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
644 return e;
462
kono
parents:
diff changeset
645 }
kono
parents:
diff changeset
646
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
647 extern int
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
648 pexpr(int e1)
462
kono
parents:
diff changeset
649 {
kono
parents:
diff changeset
650 int e2,e3;
kono
parents:
diff changeset
651
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
652 // if (inmode) error(-1);
462
kono
parents:
diff changeset
653 e2 = cadr(e1);
kono
parents:
diff changeset
654 switch (car(e1)){
kono
parents:
diff changeset
655 case GVAR: case RGVAR: case CRGVAR: case CURGVAR: case SRGVAR:
kono
parents:
diff changeset
656 case SURGVAR: case REGISTER:
kono
parents:
diff changeset
657 #if FLOAT_CODE
kono
parents:
diff changeset
658 case DREGISTER: case FREGISTER:
kono
parents:
diff changeset
659 #endif
kono
parents:
diff changeset
660 #if LONGLONG_CODE
kono
parents:
diff changeset
661 case LREGISTER:
kono
parents:
diff changeset
662 #endif
kono
parents:
diff changeset
663 case LABEL: case CONST:
kono
parents:
diff changeset
664 #if FLOAT_CODE
kono
parents:
diff changeset
665 case DCONST: case FCONST:
kono
parents:
diff changeset
666 #endif
kono
parents:
diff changeset
667 #if LONGLONG_CODE
kono
parents:
diff changeset
668 case LCONST:
kono
parents:
diff changeset
669 #endif
kono
parents:
diff changeset
670 case STRING:
kono
parents:
diff changeset
671 case FNAME:
kono
parents:
diff changeset
672 case RSTRUCT:
kono
parents:
diff changeset
673 return e1;
kono
parents:
diff changeset
674 case LVAR:
kono
parents:
diff changeset
675 case RLVAR: case CRLVAR: case CURLVAR: case SRLVAR: case SURLVAR:
kono
parents:
diff changeset
676 #if FLOAT_CODE
kono
parents:
diff changeset
677 case FRLVAR: case FRGVAR: case DRLVAR: case DRGVAR:
kono
parents:
diff changeset
678 #endif
kono
parents:
diff changeset
679 #if LONGLONG_CODE
kono
parents:
diff changeset
680 case LRLVAR: case LRGVAR: case LURLVAR: case LURGVAR:
kono
parents:
diff changeset
681 return p_lvar(e1);
kono
parents:
diff changeset
682 #endif
kono
parents:
diff changeset
683 case FUNCTION:
kono
parents:
diff changeset
684 return pfunction(e1);
kono
parents:
diff changeset
685 case CODE:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
686 return list2(car(e1),pexpr(e2));
462
kono
parents:
diff changeset
687 case INLINE:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
688 return gen_inline(e1);
462
kono
parents:
diff changeset
689 case INDIRECT:
kono
parents:
diff changeset
690 return prindirect(e1);
kono
parents:
diff changeset
691 case RINDIRECT: case URINDIRECT:
kono
parents:
diff changeset
692 case CRINDIRECT: case CURINDIRECT:
kono
parents:
diff changeset
693 case SRINDIRECT: case SURINDIRECT:
kono
parents:
diff changeset
694 #if FLOAT_CODE
kono
parents:
diff changeset
695 case FRINDIRECT: case DRINDIRECT:
kono
parents:
diff changeset
696 #endif
kono
parents:
diff changeset
697 #if LONGLONG_CODE
kono
parents:
diff changeset
698 case LRINDIRECT: case LURINDIRECT:
kono
parents:
diff changeset
699 #endif
kono
parents:
diff changeset
700 return prindirect(e1);
kono
parents:
diff changeset
701 case ADDRESS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
702 return paddress(pexpr(e2));
462
kono
parents:
diff changeset
703 case MINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
704 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
705 if (car(e3)==CONST) return list2(CONST,-cadr(e3));
kono
parents:
diff changeset
706 return list2(car(e1),e3);
kono
parents:
diff changeset
707 #if LONGLONG_CODE
kono
parents:
diff changeset
708 case LMINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
709 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
710 if (car(e3)==LCONST) return llist2(LCONST,-lcadr(e3));
kono
parents:
diff changeset
711 return list2(car(e1),e3);
kono
parents:
diff changeset
712 #endif
kono
parents:
diff changeset
713 #if FLOAT_CODE
kono
parents:
diff changeset
714 case DMINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
715 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
716 if (car(e3)==DCONST) return dlist2(DCONST,-dcadr(e3));
kono
parents:
diff changeset
717 if (car(e3)==FCONST) return dlist2(FCONST,-dcadr(e3));
kono
parents:
diff changeset
718 return list2(car(e1),e3);
kono
parents:
diff changeset
719 case FMINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
720 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
721 if (car(e3)==DCONST) return dlist2(DCONST,-dcadr(e3));
kono
parents:
diff changeset
722 if (car(e3)==FCONST) return dlist2(FCONST,-dcadr(e3));
kono
parents:
diff changeset
723 return list2(car(e1),e3);
kono
parents:
diff changeset
724 #endif
kono
parents:
diff changeset
725 case CONV:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
726 return p_conv(caddr(e1),pexpr(e2));
462
kono
parents:
diff changeset
727 case BNOT: /* ~ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
728 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
729 if (car(e3)==CONST) return list2(CONST,~cadr(e3));
kono
parents:
diff changeset
730 return list2(BNOT,e3);
kono
parents:
diff changeset
731 case LNOT: /* ! */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
732 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
733 if (car(e3)==CONST) return list2(CONST,!cadr(e3));
kono
parents:
diff changeset
734 return list2(LNOT,e3);
kono
parents:
diff changeset
735 case PREINC:
kono
parents:
diff changeset
736 case UPREINC:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
737 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
738 if (car(e3)==CONST) return list2(CONST,cadr(e3)+1);
kono
parents:
diff changeset
739 return list2(car(e1),e3);
kono
parents:
diff changeset
740 case POSTINC:
kono
parents:
diff changeset
741 case UPOSTINC:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
742 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
743 if (car(e3)==CONST) return e3;
kono
parents:
diff changeset
744 return list2(car(e1),e3);
kono
parents:
diff changeset
745 #if FLOAT_CODE
kono
parents:
diff changeset
746 case DPREINC: /* ++d */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
747 if ((e3 = pexpr(e2))==e2) return e1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
748 if (car(e3)==FCONST) return dlist2(FCONST,dcadr(e3)+cadr(e2));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
749 if (car(e3)==DCONST) return dlist2(DCONST,dcadr(e3)+cadr(e2));
462
kono
parents:
diff changeset
750 return list2(car(e1),e3);
kono
parents:
diff changeset
751 case DPOSTINC: /* d++ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
752 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
753 if (car(e3)==FCONST||car(e3)==DCONST) return e3;
kono
parents:
diff changeset
754 return list2(car(e1),e3);
kono
parents:
diff changeset
755 case FPREINC: /* ++f */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
756 if ((e3 = pexpr(e2))==e2) return e1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
757 if (car(e3)==FCONST) return dlist2(FCONST,dcadr(e3)+cadr(e2));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
758 if (car(e3)==DCONST) return dlist2(DCONST,dcadr(e3)+cadr(e2));
462
kono
parents:
diff changeset
759 return list2(car(e1),e3);
kono
parents:
diff changeset
760 case FPOSTINC: /* f++ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
761 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
762 if (car(e3)==FCONST||car(e3)==DCONST) return e3;
kono
parents:
diff changeset
763 return list2(car(e1),e3);
kono
parents:
diff changeset
764 #endif
kono
parents:
diff changeset
765 #if LONGLONG_CODE
kono
parents:
diff changeset
766 case LPREINC: /* ++d */
kono
parents:
diff changeset
767 case LUPREINC: /* ++d */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
768 if ((e3 = pexpr(e2))==e2) return e1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
769 if (car(e3)==LCONST) return llist2(LCONST,lcadr(e3)+cadr(e2));
462
kono
parents:
diff changeset
770 return list2(car(e1),e3);
kono
parents:
diff changeset
771 case LPOSTINC: /* d++ */
kono
parents:
diff changeset
772 case LUPOSTINC: /* d++ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
773 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
774 if (car(e3)==LCONST) return e3;
kono
parents:
diff changeset
775 return list2(car(e1),e3);
kono
parents:
diff changeset
776 #endif
kono
parents:
diff changeset
777 case MUL: case UMUL:
kono
parents:
diff changeset
778 case DIV: case UDIV:
kono
parents:
diff changeset
779 case MOD: case UMOD:
kono
parents:
diff changeset
780 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT:
kono
parents:
diff changeset
781 case ADD: case SUB: case BAND: case EOR: case BOR: case CMP: case CMPGE:
kono
parents:
diff changeset
782 case UCMP: case CMPEQ: case CMPNEQ: case UCMPGE:
kono
parents:
diff changeset
783 #if FLOAT_CODE
kono
parents:
diff changeset
784 case DMUL: case DDIV:
kono
parents:
diff changeset
785 case DADD: case DSUB:
kono
parents:
diff changeset
786 case DCMP: case DCMPGE: case DCMPEQ: case DCMPNEQ:
kono
parents:
diff changeset
787 case FMUL: case FDIV:
kono
parents:
diff changeset
788 case FADD: case FSUB:
kono
parents:
diff changeset
789 case FCMP: case FCMPGE: case FCMPEQ: case FCMPNEQ:
kono
parents:
diff changeset
790 #endif
kono
parents:
diff changeset
791 #if LONGLONG_CODE
kono
parents:
diff changeset
792 case LMUL: case LUMUL:
kono
parents:
diff changeset
793 case LDIV: case LUDIV:
kono
parents:
diff changeset
794 case LMOD: case LUMOD:
kono
parents:
diff changeset
795 case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT:
kono
parents:
diff changeset
796 case LADD: case LSUB: case LBAND: case LEOR: case LBOR: case LCMP:
kono
parents:
diff changeset
797 #endif
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
798 e3 = pexpr(e2); e2 = pexpr(caddr(e1));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
799 if (e3==cadr(e1)&&e2==caddr(e1)) return e1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
800 return pbinop(car(e1),e3,e2);
462
kono
parents:
diff changeset
801 case LCOND: case DCOND: case FCOND: case COND:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
802 e3 = pexpr(e2);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
803 if (car(e3)==CONST) return pexpr(cadr(e3)?caddr(e1):cadddr(e1));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
804 return list4(car(e1),e3,pexpr(cadr(e1)),pexpr(cadr(e2)));
462
kono
parents:
diff changeset
805 case STASS:
kono
parents:
diff changeset
806 return psassign(e1);
kono
parents:
diff changeset
807 case ASS: case CASS: case SASS:
kono
parents:
diff changeset
808 return passign(e1);
kono
parents:
diff changeset
809 case SASSOP: case SUASSOP:
kono
parents:
diff changeset
810 case ASSOP: case CASSOP: case CUASSOP:
kono
parents:
diff changeset
811 return passop(e1);
kono
parents:
diff changeset
812 #if FLOAT_CODE
kono
parents:
diff changeset
813 case FASS: case DASS:
kono
parents:
diff changeset
814 return pdassign(e1);
kono
parents:
diff changeset
815 case DASSOP: case FASSOP:
kono
parents:
diff changeset
816 return pdassop(e1);
kono
parents:
diff changeset
817 #endif
kono
parents:
diff changeset
818 #if LONGLONG_CODE
kono
parents:
diff changeset
819 case LASS:
kono
parents:
diff changeset
820 return plassign(e1);
kono
parents:
diff changeset
821 case LASSOP: case LUASSOP:
kono
parents:
diff changeset
822 return plassop(e1);
kono
parents:
diff changeset
823 #endif
kono
parents:
diff changeset
824 case ALLOCA:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
825 return palloc(pexpr(e2));
462
kono
parents:
diff changeset
826 case BUILTINP:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
827 return list2(CONST,is_const(pexpr(e2)));
462
kono
parents:
diff changeset
828 case COMMA:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
829 return pcomma(pexpr(e2),pexpr(caddr(e1)));
462
kono
parents:
diff changeset
830 case RETURN:
kono
parents:
diff changeset
831 case ENVIRONMENT:
kono
parents:
diff changeset
832 case LCALL:
kono
parents:
diff changeset
833 return e1;
kono
parents:
diff changeset
834 #if BIT_FIELD_CODE
kono
parents:
diff changeset
835 case RBIT_FIELD:
kono
parents:
diff changeset
836 return prbit_field(e1);
kono
parents:
diff changeset
837 case BASS:
kono
parents:
diff changeset
838 return pbassign(e1);
kono
parents:
diff changeset
839 case BPREINC:
kono
parents:
diff changeset
840 case BPOSTINC:
kono
parents:
diff changeset
841 case BASSOP:
kono
parents:
diff changeset
842 return pbassop(e1);
kono
parents:
diff changeset
843 #endif
kono
parents:
diff changeset
844 #if ASM_CODE
kono
parents:
diff changeset
845 case ASM:
kono
parents:
diff changeset
846 return list3(ASM,list4(
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
847 pexpr(car(e2)),pexpr(cadr(e2)),pexpr(caddr(e2)),pexpr(cadddr(e2))),
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
848 pexpr(caddr(e1)));
462
kono
parents:
diff changeset
849 #endif
kono
parents:
diff changeset
850 case ST_DECL: return p_decl(e1);
kono
parents:
diff changeset
851 case ST_IF: return p_if(e1);
kono
parents:
diff changeset
852 case ST_DO: return p_do(e1);
kono
parents:
diff changeset
853 case ST_WHILE: return p_while(e1);
kono
parents:
diff changeset
854 case ST_FOR: return p_for(e1);
kono
parents:
diff changeset
855 case ST_SWITCH: return p_switch(e1);
kono
parents:
diff changeset
856 case ST_COMP: return p_comp(e1);
kono
parents:
diff changeset
857 case ST_BREAK: return p_break(e1);
kono
parents:
diff changeset
858 case ST_CONTINUE: return p_continue(e1);
kono
parents:
diff changeset
859 case ST_CASE: return p_case(e1);
kono
parents:
diff changeset
860 case ST_DEFAULT: return p_default(e1);
kono
parents:
diff changeset
861 case ST_RETURN: return p_return(e1);
kono
parents:
diff changeset
862 case ST_GOTO: return p_goto(e1);
kono
parents:
diff changeset
863 case ST_ASM: return p_asm(e1);
kono
parents:
diff changeset
864 case ST_LABEL: return p_label(e1);
kono
parents:
diff changeset
865 case ST_COMMENT: return p_comment(e1);
kono
parents:
diff changeset
866 default:
kono
parents:
diff changeset
867 return p_bool(e1);
kono
parents:
diff changeset
868 }
kono
parents:
diff changeset
869 return VOID;
kono
parents:
diff changeset
870 }
kono
parents:
diff changeset
871
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
872 #define round4(i) ((i+(SIZE_OF_INT-1))&~(SIZE_OF_INT-1))
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
873
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
874 extern int
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
875 gen_inline(int e)
462
kono
parents:
diff changeset
876 {
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
877 int svartable = pvartable;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
878 int sdisp = pdisp;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
879 int narg,arg;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
880 NMTBL *n = (NMTBL*)cadr(cadr(e));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
881 int e1 = attr_value(n,INLINE);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
882 int parse = car(e1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
883 int arg_disp = cadr(e1);
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
884 int e3,t;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
885
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
886 pvartable = p_vartable(e,pdisp=arg_disp,caddr(e1));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
887 /* inline function arguments */
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
888 narg = 0;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
889 for (e3 = e1 = reverse0(caddr(e)); e3; e3 = cadr(e3)) {
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
890 t=caddr(e3);
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
891 if (is_const(e3) /* ||(is_memory(e3)&&is_readonly(e3)) */ ) {
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
892 heap[pdisp+narg]=e3;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
893 } else {
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
894 arg = heap[pdisp+narg]=new_lvar(size(t));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
895 g_expr_u(assign_expr0(arg,e3,t,t));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
896 }
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
897 narg += (size(t)+3)/4;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
898 }
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
899 e = pexpr(parse);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
900 pdisp = sdisp;
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
901 pvartable = svartable;
462
kono
parents:
diff changeset
902 return e;
kono
parents:
diff changeset
903 }
kono
parents:
diff changeset
904
kono
parents:
diff changeset
905 /* end */