annotate mc-inline.c @ 606:1e29742ea9a6

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