annotate mc-inline.c @ 519:b6eb97f0c11d

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