annotate mc-inline.c @ 505:5d4112735c5c

*** empty log message ***
author kono
date Sat, 24 Dec 2005 12:58:20 +0900
parents 48e4f6e6178c
children 96af6754acd3
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;
504
48e4f6e6178c *** empty log message ***
kono
parents: 503
diff changeset
277 g_expr_u(cadr(e1));
462
kono
parents:
diff changeset
278 return;
kono
parents:
diff changeset
279 }
kono
parents:
diff changeset
280 // conv->return_();
kono
parents:
diff changeset
281 if (struct_return) {
kono
parents:
diff changeset
282 if ((car(type)==STRUCT || car(type)==UNION)&&
kono
parents:
diff changeset
283 size(type)==cadr(struct_return)) {
kono
parents:
diff changeset
284 if(car(e)==RSTRUCT && car(cadr(e))==FUNCTION) {
kono
parents:
diff changeset
285 /* pass the return pointer to the called function */
kono
parents:
diff changeset
286 replace_return_struct(cadr(e),
kono
parents:
diff changeset
287 rvalue_t(car(struct_return),caddr(struct_return)));
kono
parents:
diff changeset
288 replace_return_struct(cadr(e),
kono
parents:
diff changeset
289 rvalue_t(car(struct_return),caddr(struct_return)));
kono
parents:
diff changeset
290 gexpr(cadr(e),0);
kono
parents:
diff changeset
291 } else {
kono
parents:
diff changeset
292 type = caddr(struct_return);
kono
parents:
diff changeset
293 // e1 = rvalue_t(cadr(struct_return),INT); /* size */
kono
parents:
diff changeset
294 e1 = cadr(struct_return); /* size */
kono
parents:
diff changeset
295 gexpr(list4(STASS,rvalue(car(struct_return)),e,e1),0);
kono
parents:
diff changeset
296 }
kono
parents:
diff changeset
297 } else {
kono
parents:
diff changeset
298 error(TYERR); /* should check compatible */
kono
parents:
diff changeset
299 }
kono
parents:
diff changeset
300 } else {
kono
parents:
diff changeset
301 gexpr(correct_type(e,cadr(fnptr->ty)),1);
kono
parents:
diff changeset
302 }
kono
parents:
diff changeset
303 // conv->return_end_();
kono
parents:
diff changeset
304 retpending = 1;
kono
parents:
diff changeset
305 }
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 extern void
kono
parents:
diff changeset
309 st_goto(int e){
kono
parents:
diff changeset
310 NMTBL *nlist,*nptr0;
kono
parents:
diff changeset
311 int t,e1,e2,env;
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 checkret();
kono
parents:
diff changeset
314 // conv->goto_();
kono
parents:
diff changeset
315 e1 = caddr(e);
kono
parents:
diff changeset
316 if (car(e1)==RINDIRECT) {
kono
parents:
diff changeset
317 gen_indirect_goto(cadr(e1));
505
5d4112735c5c *** empty log message ***
kono
parents: 504
diff changeset
318 return ;
462
kono
parents:
diff changeset
319 } else if (car(e1)==FLABEL) {
kono
parents:
diff changeset
320 nlist = (NMTBL *)cadr(e1);
kono
parents:
diff changeset
321 nptr0 = name_space_search(nlist,0);
kono
parents:
diff changeset
322 t = nptr0->sc;
kono
parents:
diff changeset
323 if (t==EMPTY||t==EXTRN1||t==EXTRN) {
kono
parents:
diff changeset
324 nptr0 = make_local_scope(nlist,nptr0,0);
kono
parents:
diff changeset
325 nptr0->sc = FLABEL;
kono
parents:
diff changeset
326 nptr0->dsp = fwdlabel();
kono
parents:
diff changeset
327 } else if (!(t==FLABEL||t==BLABEL)) {
kono
parents:
diff changeset
328 error(STERR);
kono
parents:
diff changeset
329 }
kono
parents:
diff changeset
330 gen_jmp(nptr0->dsp);
kono
parents:
diff changeset
331 control=0;
kono
parents:
diff changeset
332 // conv->sm_();
kono
parents:
diff changeset
333 // conv->goto_label_(nptr0);
505
5d4112735c5c *** empty log message ***
kono
parents: 504
diff changeset
334 return ;
462
kono
parents:
diff changeset
335 } else {
kono
parents:
diff changeset
336 /* CbC continuation */
kono
parents:
diff changeset
337 // conv->jump_(env);
kono
parents:
diff changeset
338 e2 = cadr(e1);
kono
parents:
diff changeset
339 env = caddr(e1);
kono
parents:
diff changeset
340 if (car(e2) == FNAME) {
kono
parents:
diff changeset
341 nptr0=(NMTBL *)cadr(e2);
kono
parents:
diff changeset
342 if (nptr0->sc==EMPTY)
kono
parents:
diff changeset
343 nptr0->sc = EXTRN1;
kono
parents:
diff changeset
344 else if(nptr0->sc==FUNCTION)
kono
parents:
diff changeset
345 nptr0->sc = CODE;
kono
parents:
diff changeset
346 if (nptr0->ty>0&&car(nptr0->ty)==FUNCTION)
kono
parents:
diff changeset
347 car(nptr0->ty)=CODE;
kono
parents:
diff changeset
348 }
kono
parents:
diff changeset
349 gexpr(list3(CODE,e1,env),0);
kono
parents:
diff changeset
350 control=0;
kono
parents:
diff changeset
351 // conv->sm_();
505
5d4112735c5c *** empty log message ***
kono
parents: 504
diff changeset
352 return ;
462
kono
parents:
diff changeset
353 }
kono
parents:
diff changeset
354 }
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 #if ASM_CODE
kono
parents:
diff changeset
358 extern void
kono
parents:
diff changeset
359 st_asm(int e1){
kono
parents:
diff changeset
360 checkret();
kono
parents:
diff changeset
361 g_expr_u(list3(ASM,caddr(e1),cadddr(e1)));
kono
parents:
diff changeset
362 }
kono
parents:
diff changeset
363 #endif
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 extern void
kono
parents:
diff changeset
367 st_label(int e1){
kono
parents:
diff changeset
368 NMTBL *nptr,*nlist;
kono
parents:
diff changeset
369 nlist = (NMTBL *)caddr(e1);
kono
parents:
diff changeset
370 nptr = name_space_search(nlist,0);
kono
parents:
diff changeset
371 control=1;
kono
parents:
diff changeset
372 checkret();
kono
parents:
diff changeset
373 if(nptr->sc == FLABEL) {
kono
parents:
diff changeset
374 fwddef(nptr->dsp);
kono
parents:
diff changeset
375 } else if(nptr->sc != EMPTY && nptr->sc != EXTRN1 && nptr->sc !=BLABEL) {
kono
parents:
diff changeset
376 error(TYERR);
kono
parents:
diff changeset
377 } else {
kono
parents:
diff changeset
378 nptr->sc=EMPTY;
kono
parents:
diff changeset
379 nptr = make_local_scope(nlist,nptr,0);
kono
parents:
diff changeset
380 nptr->sc = BLABEL;
kono
parents:
diff changeset
381 nptr->dsp = backdef();
kono
parents:
diff changeset
382 }
kono
parents:
diff changeset
383 // conv->label_();
kono
parents:
diff changeset
384 }
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 extern void
kono
parents:
diff changeset
387 st_comment(int e1){
kono
parents:
diff changeset
388 gen_comment((char *)caddr(e1));
kono
parents:
diff changeset
389 }
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 /*
kono
parents:
diff changeset
392 partial evaluator
kono
parents:
diff changeset
393 */
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 static int
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
396 p_vartable(int e,int adisp,int ldisp)
462
kono
parents:
diff changeset
397 {
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
398 int i;
505
5d4112735c5c *** empty log message ***
kono
parents: 504
diff changeset
399 int pvartable = getfree(adisp-ldisp); // have to be local heap
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
400 pdisp = pvartable+adisp;
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
401 for(i=adisp-ldisp;i>=0;i--) {
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
402 heap[pvartable+i] = 0;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
403 }
505
5d4112735c5c *** empty log message ***
kono
parents: 504
diff changeset
404 return pvartable;
462
kono
parents:
diff changeset
405 }
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 static int
kono
parents:
diff changeset
408 p_lvar(int e1)
kono
parents:
diff changeset
409 {
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
410 int sz = is_memory(e1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
411 int d = cadr(e1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
412 int d1;
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
413 if ((d1=(heap[pdisp+d]))) return d1;
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
414 return (heap[pdisp+d]=list3(LVAR,new_lvar(sz),0));
462
kono
parents:
diff changeset
415 }
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 static int
kono
parents:
diff changeset
418 pfunction(int e)
kono
parents:
diff changeset
419 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
420 // list4(INLINE,e1,arglist,ftype);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
421 // include code segement case
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
422 int e1 = pexpr(cadr(e));
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
423 int arglist = caddr(e);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
424 int newargs = 0;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
425 int ftype = cadddr(e);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
426 int e3;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
427 for (e3 = arglist; e3; e3 = cadr(e3)) {
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
428 newargs = list3( pexpr(car(e3)), cadr(e3), caddr(e3));
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
429 }
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
430 newargs = reverse0(newargs);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
431 return list4(INLINE,e1,newargs,ftype);
462
kono
parents:
diff changeset
432 }
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 static int
kono
parents:
diff changeset
435 prindirect(int e)
kono
parents:
diff changeset
436 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
437 return list3(car(e),pexpr(cadr(e)),caddr(e));
462
kono
parents:
diff changeset
438 }
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 static int
kono
parents:
diff changeset
441 paddress(int e)
kono
parents:
diff changeset
442 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
443 return list2(car(e),pexpr(cadr(e)));
462
kono
parents:
diff changeset
444 }
kono
parents:
diff changeset
445
kono
parents:
diff changeset
446 static int
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
447 p_conv(int e1,int e2)
462
kono
parents:
diff changeset
448 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
449 return list3(CONV,pexpr(e1),e2);
462
kono
parents:
diff changeset
450 }
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 static int
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
453 pbinop(int op,int e1,int e2)
462
kono
parents:
diff changeset
454 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
455 return list3(op,pexpr(e1),pexpr(e2));
462
kono
parents:
diff changeset
456 }
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 static int
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
459 prexpr(int op,int e1,int e2)
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
460 {
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
461 return list3(op,pexpr(e1),pexpr(e2));
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
462 }
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
463
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
464 static int
462
kono
parents:
diff changeset
465 psassign(int e)
kono
parents:
diff changeset
466 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
467 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
468 }
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 static int
kono
parents:
diff changeset
471 passign(int e)
kono
parents:
diff changeset
472 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
473 return list3(car(e),pexpr(cadr(e)),pexpr(caddr(e)));
462
kono
parents:
diff changeset
474 }
kono
parents:
diff changeset
475
kono
parents:
diff changeset
476 static int
kono
parents:
diff changeset
477 passop(int e)
kono
parents:
diff changeset
478 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
479 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
480 }
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 static int
kono
parents:
diff changeset
483 pdassign(int e)
kono
parents:
diff changeset
484 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
485 return list3(car(e),pexpr(cadr(e)),pexpr(caddr(e)));
462
kono
parents:
diff changeset
486 }
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 static int
kono
parents:
diff changeset
489 pdassop(int e)
kono
parents:
diff changeset
490 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
491 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
492 }
kono
parents:
diff changeset
493
kono
parents:
diff changeset
494 static int
kono
parents:
diff changeset
495 plassign(int e)
kono
parents:
diff changeset
496 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
497 return list3(car(e),pexpr(cadr(e)),pexpr(caddr(e)));
462
kono
parents:
diff changeset
498 }
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 static int
kono
parents:
diff changeset
501 plassop(int e)
kono
parents:
diff changeset
502 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
503 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
504 }
kono
parents:
diff changeset
505
kono
parents:
diff changeset
506 static int
kono
parents:
diff changeset
507 palloc(int e)
kono
parents:
diff changeset
508 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
509 return list2(car(e),pexpr(cadr(e)));
462
kono
parents:
diff changeset
510 }
kono
parents:
diff changeset
511
kono
parents:
diff changeset
512 static int
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
513 pcomma(int e1,int e2)
462
kono
parents:
diff changeset
514 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
515 return list3(COMMA,pexpr(e1),pexpr(e2));
462
kono
parents:
diff changeset
516 }
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 static int
kono
parents:
diff changeset
519 prbit_field(int e)
kono
parents:
diff changeset
520 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
521 return list3(car(e),pexpr(cadr(e)),caddr(e));
462
kono
parents:
diff changeset
522 }
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 static int
kono
parents:
diff changeset
525 pbassign(int e)
kono
parents:
diff changeset
526 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
527 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
528 }
kono
parents:
diff changeset
529
kono
parents:
diff changeset
530 static int
kono
parents:
diff changeset
531 pbassop(int e)
kono
parents:
diff changeset
532 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
533 return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e));
462
kono
parents:
diff changeset
534 }
kono
parents:
diff changeset
535
kono
parents:
diff changeset
536 static int
kono
parents:
diff changeset
537 p_decl(int e)
kono
parents:
diff changeset
538 {
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
539 // list4(ST_DECL,parse,(int)n,stmode);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
540 int stmode=cadddr(e);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
541 NMTBL *n=(NMTBL*)caddr(e);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
542 int dsp = n->dsp;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
543 int v;
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
544 // in real partial evaluation, we have to check whether this variable
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
545 // is used or not.
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
546 switch(stmode) {
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
547 case REGISTER:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
548 switch(n->ty) {
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
549 case ULONGLONG: case LONGLONG:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
550 v = get_lregister_var(n); break;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
551 case FLOAT:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
552 v = get_dregister_var(n,0); break;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
553 case DOUBLE:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
554 v = get_dregister_var(n,1); break;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
555 default:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
556 if (scalar(n->ty))
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
557 v = get_dregister_var(n,1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
558 else
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
559 error(TYERR);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
560 }
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
561 case EXTRN: case EXTRN1: case STATIC:
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
562 return pexpr(cadr(e));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
563 default:
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
564 v = list3(LVAR,new_lvar(size(n->dsp)),(int)n);
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
565 }
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
566 if (heap[pdisp+dsp]) error(-1);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
567 heap[pdisp+dsp]=v;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
568 return pexpr(cadr(e));
462
kono
parents:
diff changeset
569 }
kono
parents:
diff changeset
570
kono
parents:
diff changeset
571 static int
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
572 p_if(int e1)
462
kono
parents:
diff changeset
573 {
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
574 int cond,l1,l2;
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
575 int e2=caddr(e1),e3;
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
576 cond = pexpr(car(e2));
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
577 // conv->if_then_();
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
578 l1 = pexpr(cadr(e2));
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
579 if ((e3=caddr(e2))) { // else
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
580 l2 = pexpr(e3);
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
581 } else {
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
582 l2 = 0;
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
583 }
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
584 return list3(ST_IF,pexpr(cadr(e1)),list3(cond,l1,l2));
462
kono
parents:
diff changeset
585 }
kono
parents:
diff changeset
586
kono
parents:
diff changeset
587 static int
kono
parents:
diff changeset
588 p_do(int e)
kono
parents:
diff changeset
589 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
590 return list4(ST_DO,pexpr(cadr(e)),pexpr(caddr(e)),pexpr(cadddr(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_while(int e)
kono
parents:
diff changeset
595 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
596 return list4(ST_WHILE,pexpr(cadr(e)),pexpr(caddr(e)),pexpr(cadddr(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_for(int e)
kono
parents:
diff changeset
601 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
602 int e1=caddr(e);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
603 int p0=car(e1);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
604 int p1=cadr(e1);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
605 int p2=caddr(e1);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
606 int p3=cadddr(e1);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
607 return list3(ST_FOR,pexpr(cadr(e)),
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
608 list4(pexpr(p0),pexpr(p1),pexpr(p2),pexpr(p3)));
462
kono
parents:
diff changeset
609 }
kono
parents:
diff changeset
610
kono
parents:
diff changeset
611 static int
kono
parents:
diff changeset
612 p_switch(int e)
kono
parents:
diff changeset
613 {
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
614 return list4(ST_SWITCH,pexpr(cadr(e)),pexpr(caddr(e)),pexpr(cadddr(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_comp(int e)
kono
parents:
diff changeset
619 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
620 return list3(ST_COMP,pexpr(cadr(e)),pexpr(caddr(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_break(int e)
kono
parents:
diff changeset
625 {
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
626 return list2(ST_BREAK,pexpr(cadr(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_continue(int e)
kono
parents:
diff changeset
631 {
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
632 return list2(ST_CONTINUE,pexpr(cadr(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_case(int e)
kono
parents:
diff changeset
637 {
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
638 return list3(ST_CASE,pexpr(cadr(e)),caddr(e));
462
kono
parents:
diff changeset
639 }
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 static int
kono
parents:
diff changeset
642 p_default(int e)
kono
parents:
diff changeset
643 {
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
644 return list2(ST_DEFAULT,pexpr(cadr(e)));
462
kono
parents:
diff changeset
645 }
kono
parents:
diff changeset
646
kono
parents:
diff changeset
647 static int
kono
parents:
diff changeset
648 p_return(int e)
kono
parents:
diff changeset
649 {
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
650 return list3(ST_RETURN,pexpr(cadr(e)),pexpr(caddr(e)));
462
kono
parents:
diff changeset
651 }
kono
parents:
diff changeset
652
kono
parents:
diff changeset
653 static int
kono
parents:
diff changeset
654 p_goto(int e)
kono
parents:
diff changeset
655 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
656 int e1;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
657 if ((e1=caddr(e))) {
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
658 switch(car(e1)) {
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
659 case RINDIRECT: e1=pexpr(e1); break;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
660 case CODE: e1=list3(CODE,pexpr(cadr(e1)),pexpr(caddr(e1))); break;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
661 case FLABEL: break;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
662 }
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
663 }
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
664 return list3(ST_GOTO,pexpr(cadr(e)),e1);
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
665 }
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
666
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
667 static int
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
668 p_list_expr(int e)
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
669 {
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
670 int e3,new = 0;
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
671 for (e3 = e; e3; e3 = cadr(e3)) {
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
672 new= list2( pexpr(car(e3)), new);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
673 }
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
674 return reverse0(new);
462
kono
parents:
diff changeset
675 }
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 static int
kono
parents:
diff changeset
678 p_asm(int e)
kono
parents:
diff changeset
679 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
680 int param=caddr(e);
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
681 int e1 = p_list_expr(cadddr(e));
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
682 return list4(ST_ASM,pexpr(cadr(e)),param,e1);
462
kono
parents:
diff changeset
683 }
kono
parents:
diff changeset
684
kono
parents:
diff changeset
685 static int
kono
parents:
diff changeset
686 p_label(int e)
kono
parents:
diff changeset
687 {
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
688 return list3(ST_LABEL,pexpr(cadr(e)),caddr(e));
462
kono
parents:
diff changeset
689 }
kono
parents:
diff changeset
690
kono
parents:
diff changeset
691 static int
kono
parents:
diff changeset
692 p_bool(int e)
kono
parents:
diff changeset
693 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
694 error(-1);
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
695 return e;
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
696 }
462
kono
parents:
diff changeset
697
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
698 static int
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
699 p_comment(int e)
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
700 {
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
701 return list3(ST_COMMENT,pexpr(cadr(e)),caddr(e));
462
kono
parents:
diff changeset
702 }
kono
parents:
diff changeset
703
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
704 extern int
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
705 pexpr(int e1)
462
kono
parents:
diff changeset
706 {
kono
parents:
diff changeset
707 int e2,e3;
kono
parents:
diff changeset
708
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
709 // if (inmode) error(-1);
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
710 if (e1==0) return 0;
462
kono
parents:
diff changeset
711 e2 = cadr(e1);
kono
parents:
diff changeset
712 switch (car(e1)){
kono
parents:
diff changeset
713 case GVAR: case RGVAR: case CRGVAR: case CURGVAR: case SRGVAR:
kono
parents:
diff changeset
714 case SURGVAR: case REGISTER:
kono
parents:
diff changeset
715 #if FLOAT_CODE
kono
parents:
diff changeset
716 case DREGISTER: case FREGISTER:
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
717 case FRGVAR: case DRGVAR:
462
kono
parents:
diff changeset
718 #endif
kono
parents:
diff changeset
719 #if LONGLONG_CODE
kono
parents:
diff changeset
720 case LREGISTER:
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
721 case LRGVAR: case LURGVAR:
462
kono
parents:
diff changeset
722 #endif
kono
parents:
diff changeset
723 case LABEL: case CONST:
kono
parents:
diff changeset
724 #if FLOAT_CODE
kono
parents:
diff changeset
725 case DCONST: case FCONST:
kono
parents:
diff changeset
726 #endif
kono
parents:
diff changeset
727 #if LONGLONG_CODE
kono
parents:
diff changeset
728 case LCONST:
kono
parents:
diff changeset
729 #endif
kono
parents:
diff changeset
730 case STRING:
kono
parents:
diff changeset
731 case FNAME:
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
732 case FLABEL:
462
kono
parents:
diff changeset
733 case RSTRUCT:
kono
parents:
diff changeset
734 return e1;
kono
parents:
diff changeset
735 case LVAR:
kono
parents:
diff changeset
736 case RLVAR: case CRLVAR: case CURLVAR: case SRLVAR: case SURLVAR:
kono
parents:
diff changeset
737 #if FLOAT_CODE
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
738 case FRLVAR: case DRLVAR:
462
kono
parents:
diff changeset
739 #endif
kono
parents:
diff changeset
740 #if LONGLONG_CODE
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
741 case LRLVAR: case LURLVAR:
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
742 #endif
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
743 return e1;
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
744 case IVAR:
462
kono
parents:
diff changeset
745 return p_lvar(e1);
kono
parents:
diff changeset
746 case FUNCTION:
kono
parents:
diff changeset
747 return pfunction(e1);
kono
parents:
diff changeset
748 case CODE:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
749 return list2(car(e1),pexpr(e2));
462
kono
parents:
diff changeset
750 case INLINE:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
751 return gen_inline(e1);
462
kono
parents:
diff changeset
752 case INDIRECT:
kono
parents:
diff changeset
753 return prindirect(e1);
kono
parents:
diff changeset
754 case RINDIRECT: case URINDIRECT:
kono
parents:
diff changeset
755 case CRINDIRECT: case CURINDIRECT:
kono
parents:
diff changeset
756 case SRINDIRECT: case SURINDIRECT:
kono
parents:
diff changeset
757 #if FLOAT_CODE
kono
parents:
diff changeset
758 case FRINDIRECT: case DRINDIRECT:
kono
parents:
diff changeset
759 #endif
kono
parents:
diff changeset
760 #if LONGLONG_CODE
kono
parents:
diff changeset
761 case LRINDIRECT: case LURINDIRECT:
kono
parents:
diff changeset
762 #endif
kono
parents:
diff changeset
763 return prindirect(e1);
kono
parents:
diff changeset
764 case ADDRESS:
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
765 return paddress(e1);
462
kono
parents:
diff changeset
766 case MINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
767 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
768 if (car(e3)==CONST) return list2(CONST,-cadr(e3));
kono
parents:
diff changeset
769 return list2(car(e1),e3);
kono
parents:
diff changeset
770 #if LONGLONG_CODE
kono
parents:
diff changeset
771 case LMINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
772 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
773 if (car(e3)==LCONST) return llist2(LCONST,-lcadr(e3));
kono
parents:
diff changeset
774 return list2(car(e1),e3);
kono
parents:
diff changeset
775 #endif
kono
parents:
diff changeset
776 #if FLOAT_CODE
kono
parents:
diff changeset
777 case DMINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
778 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
779 if (car(e3)==DCONST) return dlist2(DCONST,-dcadr(e3));
kono
parents:
diff changeset
780 if (car(e3)==FCONST) return dlist2(FCONST,-dcadr(e3));
kono
parents:
diff changeset
781 return list2(car(e1),e3);
kono
parents:
diff changeset
782 case FMINUS:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
783 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
784 if (car(e3)==DCONST) return dlist2(DCONST,-dcadr(e3));
kono
parents:
diff changeset
785 if (car(e3)==FCONST) return dlist2(FCONST,-dcadr(e3));
kono
parents:
diff changeset
786 return list2(car(e1),e3);
kono
parents:
diff changeset
787 #endif
kono
parents:
diff changeset
788 case CONV:
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
789 return p_conv(caddr(e1),e2);
462
kono
parents:
diff changeset
790 case BNOT: /* ~ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
791 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
792 if (car(e3)==CONST) return list2(CONST,~cadr(e3));
kono
parents:
diff changeset
793 return list2(BNOT,e3);
kono
parents:
diff changeset
794 case LNOT: /* ! */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
795 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
796 if (car(e3)==CONST) return list2(CONST,!cadr(e3));
kono
parents:
diff changeset
797 return list2(LNOT,e3);
kono
parents:
diff changeset
798 case PREINC:
kono
parents:
diff changeset
799 case UPREINC:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
800 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
801 if (car(e3)==CONST) return list2(CONST,cadr(e3)+1);
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
802 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
803 case POSTINC:
kono
parents:
diff changeset
804 case UPOSTINC:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
805 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
806 if (car(e3)==CONST) return e3;
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
807 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
808 #if FLOAT_CODE
kono
parents:
diff changeset
809 case DPREINC: /* ++d */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
810 if ((e3 = pexpr(e2))==e2) return e1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
811 if (car(e3)==FCONST) return dlist2(FCONST,dcadr(e3)+cadr(e2));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
812 if (car(e3)==DCONST) return dlist2(DCONST,dcadr(e3)+cadr(e2));
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
813 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
814 case DPOSTINC: /* d++ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
815 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
816 if (car(e3)==FCONST||car(e3)==DCONST) return e3;
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
817 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
818 case FPREINC: /* ++f */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
819 if ((e3 = pexpr(e2))==e2) return e1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
820 if (car(e3)==FCONST) return dlist2(FCONST,dcadr(e3)+cadr(e2));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
821 if (car(e3)==DCONST) return dlist2(DCONST,dcadr(e3)+cadr(e2));
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
822 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
823 case FPOSTINC: /* f++ */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
824 if ((e3 = pexpr(e2))==e2) return e1;
462
kono
parents:
diff changeset
825 if (car(e3)==FCONST||car(e3)==DCONST) return e3;
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
826 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
827 #endif
kono
parents:
diff changeset
828 #if LONGLONG_CODE
kono
parents:
diff changeset
829 case LPREINC: /* ++d */
kono
parents:
diff changeset
830 case LUPREINC: /* ++d */
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
831 if ((e3 = pexpr(e2))==e2) return e1;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
832 if (car(e3)==LCONST) return llist2(LCONST,lcadr(e3)+cadr(e2));
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
833 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
834 case LPOSTINC: /* d++ */
kono
parents:
diff changeset
835 case LUPOSTINC: /* d++ */
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)==LCONST) return e3;
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
838 return list4(car(e1),e3,caddr(e1),cadddr(e1));
462
kono
parents:
diff changeset
839 #endif
kono
parents:
diff changeset
840 case MUL: case UMUL:
kono
parents:
diff changeset
841 case DIV: case UDIV:
kono
parents:
diff changeset
842 case MOD: case UMOD:
kono
parents:
diff changeset
843 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT:
kono
parents:
diff changeset
844 case ADD: case SUB: case BAND: case EOR: case BOR: case CMP: case CMPGE:
kono
parents:
diff changeset
845 case UCMP: case CMPEQ: case CMPNEQ: case UCMPGE:
kono
parents:
diff changeset
846 #if FLOAT_CODE
kono
parents:
diff changeset
847 case DMUL: case DDIV:
kono
parents:
diff changeset
848 case DADD: case DSUB:
kono
parents:
diff changeset
849 case DCMP: case DCMPGE: case DCMPEQ: case DCMPNEQ:
kono
parents:
diff changeset
850 case FMUL: case FDIV:
kono
parents:
diff changeset
851 case FADD: case FSUB:
kono
parents:
diff changeset
852 case FCMP: case FCMPGE: case FCMPEQ: case FCMPNEQ:
kono
parents:
diff changeset
853 #endif
kono
parents:
diff changeset
854 #if LONGLONG_CODE
kono
parents:
diff changeset
855 case LMUL: case LUMUL:
kono
parents:
diff changeset
856 case LDIV: case LUDIV:
kono
parents:
diff changeset
857 case LMOD: case LUMOD:
kono
parents:
diff changeset
858 case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT:
kono
parents:
diff changeset
859 case LADD: case LSUB: case LBAND: case LEOR: case LBOR: case LCMP:
kono
parents:
diff changeset
860 #endif
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
861 return pbinop(car(e1),e2,caddr(e1));
462
kono
parents:
diff changeset
862 case LCOND: case DCOND: case FCOND: case COND:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
863 e3 = pexpr(e2);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
864 if (car(e3)==CONST) return pexpr(cadr(e3)?caddr(e1):cadddr(e1));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
865 return list4(car(e1),e3,pexpr(cadr(e1)),pexpr(cadr(e2)));
462
kono
parents:
diff changeset
866 case STASS:
kono
parents:
diff changeset
867 return psassign(e1);
kono
parents:
diff changeset
868 case ASS: case CASS: case SASS:
kono
parents:
diff changeset
869 return passign(e1);
kono
parents:
diff changeset
870 case SASSOP: case SUASSOP:
kono
parents:
diff changeset
871 case ASSOP: case CASSOP: case CUASSOP:
kono
parents:
diff changeset
872 return passop(e1);
kono
parents:
diff changeset
873 #if FLOAT_CODE
kono
parents:
diff changeset
874 case FASS: case DASS:
kono
parents:
diff changeset
875 return pdassign(e1);
kono
parents:
diff changeset
876 case DASSOP: case FASSOP:
kono
parents:
diff changeset
877 return pdassop(e1);
kono
parents:
diff changeset
878 #endif
kono
parents:
diff changeset
879 #if LONGLONG_CODE
kono
parents:
diff changeset
880 case LASS:
kono
parents:
diff changeset
881 return plassign(e1);
kono
parents:
diff changeset
882 case LASSOP: case LUASSOP:
kono
parents:
diff changeset
883 return plassop(e1);
kono
parents:
diff changeset
884 #endif
kono
parents:
diff changeset
885 case ALLOCA:
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
886 return palloc(e2);
462
kono
parents:
diff changeset
887 case BUILTINP:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
888 return list2(CONST,is_const(pexpr(e2)));
462
kono
parents:
diff changeset
889 case COMMA:
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
890 return pcomma(pexpr(e2),pexpr(caddr(e1)));
462
kono
parents:
diff changeset
891 case RETURN:
kono
parents:
diff changeset
892 case ENVIRONMENT:
kono
parents:
diff changeset
893 case LCALL:
kono
parents:
diff changeset
894 return e1;
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
895 // relational operator
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
896 case GT: case UGT: case GE: case UGE: case LT:
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
897 case ULT: case LE: case ULE:
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
898 case DOP+GT: case DOP+GE: case DOP+LT: case DOP+LE:
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
899 case FOP+GT: case FOP+GE: case FOP+LT: case FOP+LE:
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
900 case FOP+EQ: case FOP+NEQ:
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
901 case EQ: case NEQ: case DOP+EQ: case DOP+NEQ:
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
902 return prexpr(car(e1),cadr(e1),caddr(e1));
462
kono
parents:
diff changeset
903 #if BIT_FIELD_CODE
kono
parents:
diff changeset
904 case RBIT_FIELD:
kono
parents:
diff changeset
905 return prbit_field(e1);
kono
parents:
diff changeset
906 case BASS:
kono
parents:
diff changeset
907 return pbassign(e1);
kono
parents:
diff changeset
908 case BPREINC:
kono
parents:
diff changeset
909 case BPOSTINC:
kono
parents:
diff changeset
910 case BASSOP:
kono
parents:
diff changeset
911 return pbassop(e1);
kono
parents:
diff changeset
912 #endif
kono
parents:
diff changeset
913 #if ASM_CODE
kono
parents:
diff changeset
914 case ASM:
kono
parents:
diff changeset
915 return list3(ASM,list4(
501
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
916 car(e2),cadr(e2),caddr(e2),cadddr(e2)),
a63eb2319d11 inline continue...
kono
parents: 500
diff changeset
917 caddr(e1));
462
kono
parents:
diff changeset
918 #endif
kono
parents:
diff changeset
919 case ST_DECL: return p_decl(e1);
kono
parents:
diff changeset
920 case ST_IF: return p_if(e1);
kono
parents:
diff changeset
921 case ST_DO: return p_do(e1);
kono
parents:
diff changeset
922 case ST_WHILE: return p_while(e1);
kono
parents:
diff changeset
923 case ST_FOR: return p_for(e1);
kono
parents:
diff changeset
924 case ST_SWITCH: return p_switch(e1);
kono
parents:
diff changeset
925 case ST_COMP: return p_comp(e1);
kono
parents:
diff changeset
926 case ST_BREAK: return p_break(e1);
kono
parents:
diff changeset
927 case ST_CONTINUE: return p_continue(e1);
kono
parents:
diff changeset
928 case ST_CASE: return p_case(e1);
kono
parents:
diff changeset
929 case ST_DEFAULT: return p_default(e1);
kono
parents:
diff changeset
930 case ST_RETURN: return p_return(e1);
kono
parents:
diff changeset
931 case ST_GOTO: return p_goto(e1);
kono
parents:
diff changeset
932 case ST_ASM: return p_asm(e1);
kono
parents:
diff changeset
933 case ST_LABEL: return p_label(e1);
kono
parents:
diff changeset
934 case ST_COMMENT: return p_comment(e1);
kono
parents:
diff changeset
935 default:
kono
parents:
diff changeset
936 return p_bool(e1);
kono
parents:
diff changeset
937 }
kono
parents:
diff changeset
938 return VOID;
kono
parents:
diff changeset
939 }
kono
parents:
diff changeset
940
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
941 #define round4(i) ((i+(SIZE_OF_INT-1))&~(SIZE_OF_INT-1))
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
942
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
943 extern int
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
944 gen_inline(int e)
462
kono
parents:
diff changeset
945 {
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
946 int svartable = pvartable;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
947 int sdisp = pdisp;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
948 int narg,arg;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
949 NMTBL *n = (NMTBL*)cadr(cadr(e));
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
950 int e1 = attr_value(n,INLINE);
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
951 int parse = car(e1); // inline parse tree
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
952 int arg_disp = cadr(e1); // size of local variable
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
953 int e3,t,e4;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
954
503
3c95c69aa80e *** empty log message ***
kono
parents: 502
diff changeset
955 pvartable = p_vartable(e,arg_disp,caddr(e1));
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
956 /* inline function arguments */
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
957 narg = 0;
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
958 for (e3 = e1 = reverse0(caddr(e)); e3; e3 = cadr(e3)) {
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
959 t=caddr(e3); // type
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
960 e4 = car(e3);
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
961 if (is_const(e4) /* ||(is_memory(e3)&&is_readonly(e3)) */ ) {
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
962 heap[pdisp+narg]=e4;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
963 } else {
502
bc66e49e25a2 inline continue...
kono
parents: 501
diff changeset
964 arg = heap[pdisp+narg]=list3(LVAR,new_lvar(size(t)),cadddr(e3));
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
965 g_expr_u(assign_expr0(arg,e4,t,t));
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
966 }
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
967 narg ++;
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
968 }
500
0a4ca939f403 inline continue...
kono
parents: 464
diff changeset
969 caddr(e) = reverse0(caddr(e)); // make it normal
463
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
970 e = pexpr(parse);
50a59dfb4606 inline continue...
kono
parents: 462
diff changeset
971 pdisp = sdisp;
464
d88f08d81bba inline continue....
kono
parents: 463
diff changeset
972 pvartable = svartable;
462
kono
parents:
diff changeset
973 return e;
kono
parents:
diff changeset
974 }
kono
parents:
diff changeset
975
kono
parents:
diff changeset
976 /* end */