0
|
1 /* Micro-C Code Generatation Part for intel386 */
|
1
|
2 /* $Id$ */
|
0
|
3
|
|
4 #define EXTERN extern
|
|
5 #include "mc.h"
|
|
6
|
18
|
7 extern int get_register_var(void);
|
|
8 extern void bexpr(int e1, char cond, int l1);
|
|
9 extern void closing(void);
|
|
10 extern void cmpdimm(int e, int csreg);
|
|
11 extern void code_enter(char *name) ;
|
|
12 extern void code_enter1(int disp0,int args);
|
|
13 extern void code_init(void);
|
36
|
14 extern void code_leave(char *name,int disp) ;
|
|
15 extern void leave(int control,char *name,int disp0) ;
|
18
|
16 extern void def_label(int cslabel, int dlabel) ;
|
|
17 extern void emit_data(int e, int t, NMTBL *n);
|
|
18 extern void emit_init(void);
|
|
19 extern void enter(char *name) ;
|
|
20 extern void enter1(int disp) ;
|
|
21 extern void g_expr(int e1);
|
|
22 extern void gen_comment(char *s);
|
|
23 extern void gen_gdecl(char *n, int gpc) ;
|
|
24 extern void gen_source(char *s);
|
|
25 extern void gexpr(int e1);
|
|
26 extern void jcond(int l, char cond);
|
|
27 extern void jmp(int l);
|
|
28 extern void opening(char *filename);
|
|
29 extern void ret(void);
|
0
|
30
|
18
|
31 static char *div_setup(int oreg) ;
|
|
32 static int lvar(int l);
|
|
33 static void jump(int e1, int env);
|
|
34 static void data_mode(char *name);
|
|
35 static void text_mode(void);
|
|
36 static void assign(int e1);
|
|
37 static void assop(int e1);
|
|
38 static void b_expr(int e1, char cond, int l1);
|
|
39 static void emit_push(void);
|
|
40 static void free_register(int i);
|
|
41 static void function(int e1);
|
|
42 static void global_table(void) ;
|
|
43 /* static void indexy(char *op, char *gvar); */
|
|
44 /* static void jmp_eq_label(int l); */
|
|
45 /* static void jmp_label(int l); */
|
|
46 static void ld_indexx(int byte, int n, int xreg);
|
|
47 static void local_table(void) ;
|
|
48 static void machinop(int e1);
|
|
49 static void rexpr(int e1, int l1, char *s);
|
|
50 static void rindirect(int e1);
|
|
51 static void sassign(int e1);
|
|
52 static void shift(char *op, int xreg) ;
|
|
53 /* static void st_indexx(int byte, int n, int xreg); */
|
|
54 static void string(int e1);
|
|
55 static void tosop(int op);
|
26
|
56 static void div_cleanup(char *orn);
|
|
57 static void use_register(int virt, int real, int move);
|
38
|
58 static void emit_copy(int from,int to,int length,int offset);
|
18
|
59
|
|
60 extern int error(int n);
|
|
61 extern int fwdlabel(void);
|
|
62 extern void fwddef(int l);
|
|
63 extern int backdef(void);
|
|
64 extern int size(int t);
|
|
65 extern int list3(int e1, int e2, int e3);
|
2
|
66 extern int scalar(int);
|
|
67 extern int reverse0(int);
|
0
|
68
|
|
69 #define TEXT_EMIT_MODE 0
|
|
70 #define DATA_EMIT_MODE 1
|
|
71 #define RODATA_EMIT_MODE 2
|
|
72
|
18
|
73 static int output_mode = TEXT_EMIT_MODE;
|
|
74 static int data_alignment = 0;
|
0
|
75
|
36
|
76 static int code_disp_label;
|
|
77 static int func_disp_label;
|
|
78
|
0
|
79 /*
|
|
80 local1 <----24 local variable
|
|
81 %esi -20 <- disp_offset
|
|
82 %edi -16
|
|
83 %edx -12
|
|
84 %ecx -8
|
|
85 %ebx -4
|
|
86 %ebp = %esp 0
|
|
87 %eip 4 <- arg_offset
|
|
88 arg1 8
|
|
89 see enter/enter1/leave
|
|
90 */
|
|
91 int arg_offset = 8;
|
6
|
92 int code_arg_offset = -4;
|
3
|
93 int disp_offset = -12;
|
|
94 int func_disp_offset = -12;
|
|
95 int code_disp_offset = -4;
|
|
96 int size_of_int = 4;
|
0
|
97 int endian = 0;
|
|
98 int MAX_REGISTER=6; /* intel386のレジスタを4つまで使う*/
|
|
99 int REAL_MAX_REGISTER=8; /* intel386のレジスタが8つということ*/
|
|
100 int MAX_DATA_REG=4;
|
|
101 int MAX_POINTER=3;
|
|
102 int MAX_REGISTGER_VAR=2;
|
|
103
|
|
104 static int creg; /* current register */
|
|
105 static int lreg; /* operand register */
|
|
106 static int dreg; /* temporary register */
|
|
107 static int reg_sp; /* REGister Stack-Pointer */
|
|
108
|
|
109
|
|
110 #define REG_EAX 0
|
|
111 #define REG_EBX 1
|
|
112 #define REG_ECX 2
|
|
113 #define REG_EDX 3
|
|
114 #define REG_ESI 4
|
|
115 #define REG_EDI 5
|
|
116 #define REG_EBP 6
|
|
117 #define REG_ESP 7
|
|
118
|
|
119
|
|
120 #define DATA_REG 0
|
|
121 #define POINTER_REG 3
|
|
122 static char *reg_name[8];
|
|
123 static char *reg_name_l[4];
|
13
|
124 static char *reg_name_w[4];
|
0
|
125
|
|
126 /*
|
|
127 creg currrent virtual register
|
|
128 lreg operand virtual register
|
|
129 dreg spare virtual register
|
|
130
|
|
131 rname[creg] currrent real register
|
|
132 rname[lreg] operand real register
|
|
133 rname[dreg] spare real register
|
|
134
|
|
135 regs[] virtual register usage
|
40
|
136 regv[] value in virtual register flag
|
0
|
137
|
|
138 reg_name[rname[creg]]
|
|
139 */
|
|
140
|
|
141 #define MAX_MAX 10
|
|
142 static int rname[MAX_MAX];
|
|
143 static int regs[MAX_MAX]; /* 使われているレジスタを示すフラグ */
|
|
144 static int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
|
40
|
145 static int regv[MAX_MAX]; /* 値が入っているかどうか */
|
0
|
146
|
|
147 void
|
|
148 code_init(void)
|
|
149 {
|
24
|
150 arg_offset = 8;
|
|
151 func_disp_offset = -12;
|
|
152 disp_offset = -12;
|
|
153 size_of_int = 4;
|
|
154 endian = 0;
|
|
155 MAX_REGISTER=6;
|
|
156 MAX_DATA_REG=4;
|
|
157 MAX_POINTER=3;
|
0
|
158 MAX_REGISTER_VAR=2;
|
|
159
|
|
160 reg_name[REG_EAX] = "%eax";
|
|
161 reg_name[REG_EBX] = "%ebx";
|
|
162 reg_name[REG_ECX] = "%ecx";
|
|
163 reg_name[REG_EDX] = "%edx";
|
|
164 reg_name[REG_ESI] = "%esi";
|
|
165 reg_name[REG_EDI] = "%edi";
|
|
166 reg_name[REG_EBP] = "%ebp";
|
|
167 reg_name[REG_ESP] = "%esp";
|
|
168 reg_name_l[REG_EAX] = "%al";
|
|
169 reg_name_l[REG_EBX] = "%bl";
|
|
170 reg_name_l[REG_ECX] = "%cl";
|
|
171 reg_name_l[REG_EDX] = "%dl";
|
13
|
172 reg_name_w[REG_EAX] = "%ax";
|
|
173 reg_name_w[REG_EBX] = "%bx";
|
|
174 reg_name_w[REG_ECX] = "%cx";
|
|
175 reg_name_w[REG_EDX] = "%dx";
|
0
|
176
|
|
177 }
|
|
178
|
|
179 char *
|
18
|
180 register_name(int i,int byte)
|
0
|
181 {
|
38
|
182 if (i<0) {
|
|
183 error(REG_ERR);
|
|
184 return "%eax";
|
|
185 }
|
24
|
186 if (byte && rname[i] <= REG_EDX) {
|
18
|
187 return reg_name_l[rname[i]];
|
|
188 } else {
|
24
|
189 return reg_name[rname[i]]; /* should be error */
|
18
|
190 }
|
0
|
191 }
|
|
192
|
|
193 int
|
|
194 get_register(void)
|
|
195 { /* 使われていないレジスタを調べる */
|
|
196 int i;
|
|
197 for(i=0;i<MAX_REGISTER;i++) {
|
|
198 if (! regs[i]) { /* 使われていないなら */
|
|
199 regs[i]=1; /* そのレジスタを使うことを宣言し */
|
|
200 return i; /* その場所を表す番号を返す */
|
|
201 }
|
|
202 }
|
|
203 return -1; /* 空いている場所がないなら、それを表す -1 を返す */
|
|
204 }
|
|
205
|
|
206 void
|
|
207 free_register(int i) { /* いらなくなったレジスタを開放 */
|
40
|
208 regv[i]=regs[i]=0;
|
0
|
209 }
|
|
210
|
|
211 int
|
|
212 register_full(void)
|
|
213 {
|
|
214 int i;
|
|
215 for(i=0;i<MAX_REGISTER;i++) {
|
|
216 if (! regs[i]) {
|
|
217 return 0;
|
|
218 }
|
|
219 }
|
|
220 return 1;
|
|
221 }
|
|
222
|
23
|
223 static
|
|
224 int
|
|
225 free_register_count(void)
|
|
226 {
|
|
227 int i,count;
|
|
228 count = 0;
|
|
229 for(i=0;i<MAX_REGISTER;i++) {
|
|
230 if (! regs[i]) count++;
|
|
231 }
|
|
232 return count;
|
|
233 }
|
|
234
|
40
|
235 void
|
|
236 use_register_var(int i) {
|
|
237 regv[i]=1;
|
|
238 }
|
|
239
|
|
240 static int creg_regvar = -1;
|
|
241 static int creg_regvar_back;
|
|
242 static int creg_back;
|
|
243
|
|
244 void
|
|
245 creg_destroy() {
|
|
246 creg_back = creg; creg_regvar_back = creg_regvar;
|
|
247 if (creg_regvar>=0)
|
|
248 creg = creg_regvar;
|
|
249 creg_regvar=-1;
|
|
250 }
|
|
251
|
|
252 void
|
|
253 creg_un_destroy() {
|
|
254 creg = creg_back; creg_regvar = creg_regvar_back;
|
|
255 }
|
|
256
|
23
|
257
|
0
|
258 void
|
|
259 gexpr_init(void)
|
|
260 {
|
|
261 while(reg_sp > 0) {
|
|
262 free_register(reg_stack[--reg_sp]);
|
|
263 }
|
|
264 text_mode();
|
26
|
265 use_register(creg,REG_EAX,0);
|
40
|
266 /* use_register(dreg,REG_EDX,0); */
|
|
267 creg_regvar = -1;
|
0
|
268 }
|
|
269
|
|
270 void
|
|
271 emit_init(void)
|
|
272 {
|
|
273 int i;
|
40
|
274 for(i=0;i<REAL_MAX_REGISTER;i++) { regs[i]=0; regv[i]=0;rname[i]=i;}
|
|
275 creg = get_register(); /* must be EAX */
|
|
276 dreg = get_register(); /* must be EBX */
|
0
|
277 reg_sp = 0;
|
|
278 text_mode();
|
|
279 }
|
|
280
|
|
281 int
|
|
282 virtual(int real)
|
|
283 {
|
|
284 int real_v,i;
|
|
285 real_v = -1;
|
|
286 for(i=0;i<MAX_REGISTER;i++) {
|
|
287 if (rname[i]==real) {
|
|
288 real_v=i;
|
|
289 break;
|
|
290 }
|
|
291 }
|
23
|
292 /* if (real_v == -1)
|
|
293 error(-1); */
|
0
|
294 return real_v;
|
|
295 }
|
|
296
|
|
297 void
|
|
298 use_register(int virt, int real, int move)
|
|
299 {
|
|
300 int real_v;
|
|
301 char *move_op;
|
|
302 if (rname[virt]==real)
|
|
303 return;
|
|
304 real_v = virtual(real);
|
|
305 move_op = regs[real_v]?"\txchg %s,%s\n":"\tmovl %s,%s\n";
|
41
|
306 #ifdef REGFLOW
|
|
307 if (move || (regv[real_v])) {
|
0
|
308 printf(move_op,reg_name[rname[virt]],reg_name[real]);
|
|
309 }
|
41
|
310 #else
|
|
311 if (move || (regs[real_v])) {
|
|
312 printf(move_op,reg_name[rname[virt]],reg_name[real]);
|
|
313 }
|
|
314 #endif
|
0
|
315 rname[real_v] = rname[virt];
|
|
316 rname[virt] = real;
|
|
317 }
|
|
318
|
|
319 void
|
|
320 use_pointer(int virt, int move)
|
|
321 {
|
|
322 int i;
|
|
323 if (rname[virt]>=POINTER_REG)
|
|
324 return;
|
|
325 for(i=POINTER_REG;i<MAX_REGISTER;i++) {
|
|
326 if (!regs[virtual(i)]) {
|
|
327 use_register(virt,i,move);
|
|
328 return;
|
|
329 }
|
|
330 }
|
|
331 /* we prefer EBX */
|
|
332 use_register(virt,REG_EBX,move);
|
|
333 }
|
|
334
|
|
335 void
|
|
336 use_data_reg(int virt, int move)
|
|
337 {
|
|
338 int i;
|
|
339 if (rname[virt]<MAX_DATA_REG)
|
|
340 return;
|
|
341 for(i=0;i<MAX_DATA_REG;i++) {
|
|
342 if (!regs[virtual(i)]) {
|
|
343 use_register(virt,i,move);
|
|
344 return;
|
|
345 }
|
|
346 }
|
|
347 /* we prefer EBX */
|
|
348 use_register(virt,REG_EBX,move);
|
|
349 }
|
|
350
|
|
351 int
|
|
352 pop_register(void)
|
|
353 { /* レジスタから値を取り出す */
|
|
354 int i,j;
|
|
355
|
|
356 j = creg;
|
|
357 i = reg_stack[--reg_sp];
|
|
358
|
|
359 if(i<0) {
|
|
360 return i;
|
|
361 } else {
|
|
362 free_register(i);
|
|
363 lreg = i;
|
|
364 regs[i]=0;
|
41
|
365 regv[i]=1;
|
0
|
366 return lreg;
|
|
367 }
|
|
368 }
|
|
369
|
|
370 int
|
|
371 stack_used(void) {
|
|
372 return reg_stack[--reg_sp]<0;
|
|
373 }
|
|
374
|
|
375 void
|
|
376 emit_push(void)
|
|
377 {
|
|
378 int new_reg;
|
|
379 new_reg = get_register();
|
|
380 if(new_reg<0) { /* もうレジスタがない */
|
|
381 reg_stack[reg_sp++] = -1;
|
18
|
382 printf("\tpushl %s\n",register_name(creg,0));
|
0
|
383 } else {
|
|
384 reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */
|
18
|
385 creg = new_reg;
|
0
|
386 }
|
41
|
387 regv[creg]=0;
|
0
|
388 }
|
|
389
|
18
|
390 int
|
0
|
391 emit_pop(int type)
|
|
392 {
|
18
|
393 int xreg;
|
0
|
394 if (pop_register()==-1) {
|
|
395 if (type==POINTER_REG)
|
|
396 use_pointer(dreg,0);
|
|
397 else if (type==DATA_REG)
|
|
398 use_data_reg(dreg,0);
|
18
|
399 printf("\tpopl %s\n",register_name(dreg,0));
|
0
|
400 xreg = dreg;
|
|
401 } else {
|
|
402 xreg = lreg;
|
|
403 }
|
41
|
404 regv[xreg]=1;
|
18
|
405 return xreg;
|
0
|
406 }
|
|
407
|
|
408 int
|
|
409 get_register_var(void)
|
|
410 {
|
|
411 int i;
|
|
412 for(i=REG_ESI;i<REG_ESP;i++) {
|
|
413 if (! regs[i]) { /* 使われていないなら */
|
|
414 regs[i]=1; /* そのレジスタを使うことを宣言し */
|
41
|
415 regv[i]=0;
|
0
|
416 return i; /* その場所を表す番号を返す */
|
|
417 }
|
|
418 }
|
|
419 return -1;
|
|
420 }
|
|
421
|
|
422 void
|
|
423 gexpr(int e1)
|
|
424 {
|
|
425 gexpr_init();
|
24
|
426 #if 0
|
32
|
427 if(lineno==2862) {
|
24
|
428 g_expr(e1); /*break here*/
|
|
429 csvalue = rname[creg]; /* for siwtch value */
|
|
430 return;
|
|
431 }
|
|
432 #endif
|
0
|
433 g_expr(e1);
|
|
434 csvalue = rname[creg]; /* for siwtch value */
|
|
435 }
|
|
436
|
|
437 void
|
|
438 g_expr(int e1)
|
|
439 {
|
22
|
440 int e2,e3/*,e4*/;
|
0
|
441 char *xrn;
|
|
442 NMTBL *n;
|
|
443
|
|
444 if (chk) return;
|
|
445 e2 = cadr(e1);
|
|
446 switch (car(e1)){
|
|
447 case GVAR:
|
|
448 /* use_pointer(creg,0); */
|
18
|
449 printf("\tmovl $%s,%s\n",(char *)caddr(e1),register_name(creg,0));
|
0
|
450 return;
|
|
451 case RGVAR:
|
|
452 /* use_pointer(creg,0); */
|
18
|
453 printf("\tmovl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
|
0
|
454 return;
|
|
455 case CRGVAR:
|
27
|
456 printf("\tmovsbl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
|
0
|
457 return;
|
|
458 case LVAR:
|
|
459 /* use_pointer(creg,0); */
|
18
|
460 printf("\tlea %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
|
0
|
461 return;
|
|
462 case REGISTER:
|
|
463 /* this is of course redundant... */
|
18
|
464 /* we can use rname for this? */
|
|
465 /* or why not creg=e2? */
|
|
466 printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0));
|
0
|
467 return;
|
|
468 case RLVAR:
|
18
|
469 printf("\tmovl %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
|
0
|
470 return;
|
|
471 case CRLVAR:
|
21
|
472 printf("\tmovsbl %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
|
0
|
473 return;
|
|
474 case FNAME:
|
18
|
475 printf("\tmovl $%s,%s\n",((NMTBL *)e2)->nm,register_name(creg,0));
|
0
|
476 return;
|
|
477 case CONST: /* 代入する値が0でも特別な処理はしない */
|
18
|
478 printf("\tmovl $%d,%s\n",e2,register_name(creg,0));
|
0
|
479 return;
|
|
480 case STRING:
|
|
481 string(e1);
|
|
482 return;
|
|
483 case FUNCTION:
|
|
484 function(e1);
|
|
485 return;
|
|
486 case CODE:
|
|
487 jump(e2,caddr(e1));
|
|
488 return;
|
|
489 case INDIRECT:
|
|
490 g_expr(e2);
|
|
491 return;
|
|
492 case RINDIRECT: case CRINDIRECT:
|
|
493 rindirect(e1);
|
|
494 return;
|
|
495 case ADDRESS:
|
|
496 g_expr(e2);
|
|
497 return;
|
|
498 case MINUS: /* レジスタに対し、neglを実行すれば実現可能 */
|
|
499 g_expr(e2);
|
|
500 /* use_data_reg(creg,1); */
|
18
|
501 printf("\tnegl %s\n", register_name(creg,0));
|
0
|
502 return;
|
|
503 case BNOT: /* ~ */
|
|
504 g_expr(e2);
|
|
505 /* use_data_reg(creg,1); */
|
18
|
506 printf("\tnotl %s\n", register_name(creg,0));
|
0
|
507 return;
|
|
508 case LNOT: /* ! */
|
|
509 g_expr(e2);
|
|
510 use_data_reg(creg,1);
|
18
|
511 xrn = register_name(creg,1);
|
|
512 printf("\tcmpl $0,%s\n", register_name(creg,0));
|
|
513 printf("\tsete %s\n", xrn);
|
|
514 printf("\tmovzbl %s,%s\n", xrn,register_name(creg,0));
|
0
|
515 return;
|
|
516 case PREINC:
|
|
517 if (car(e2)==REGISTER) {
|
18
|
518 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
|
|
519 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
0
|
520 return;
|
|
521 }
|
|
522 g_expr(e2);
|
18
|
523 xrn = register_name(creg,0);
|
|
524 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
|
|
525 printf("\tmovl (%s),%s\n",xrn,xrn);
|
0
|
526 return;
|
|
527 case POSTINC:
|
|
528 if (car(e2)==REGISTER) {
|
18
|
529 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
|
530 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
|
0
|
531 return;
|
|
532 }
|
|
533 g_expr(e2);
|
|
534 emit_push();
|
18
|
535 /* in case of register full we should copy creg to dreg */
|
41
|
536 xrn = register_name((e2=emit_pop(0)),0);
|
18
|
537 printf("\tmovl (%s),%s\n",xrn,register_name(creg,0));
|
0
|
538 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
|
41
|
539 regv[e2]=0;
|
0
|
540 return;
|
|
541 case CPOSTINC:
|
|
542 /* char *p; *p++ */
|
|
543 if (car(e2)==REGISTER) {
|
18
|
544 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
|
545 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
|
0
|
546 return;
|
|
547 }
|
|
548 g_expr(e2);
|
18
|
549 emit_push(); /* in case of register full we should copy creg to dreg */
|
41
|
550 xrn = register_name((e2=emit_pop(0)),1);
|
18
|
551 printf("\tmovsbl (%s),%s\n",xrn,register_name(creg,0));
|
0
|
552 printf("\tincl (%s)\n",xrn);
|
41
|
553 regv[e2]=0;
|
0
|
554 return;
|
|
555 case CPREINC:
|
|
556 if (car(e2)==REGISTER) {
|
18
|
557 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
|
|
558 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
0
|
559 return;
|
|
560 }
|
|
561 g_expr(e2);
|
18
|
562 printf("\tincl (%s)\n",register_name(creg,0));
|
21
|
563 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
|
0
|
564 return;
|
|
565 case CPOSTDEC:
|
|
566 if (car(e2)==REGISTER) {
|
18
|
567 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
|
568 printf("\tdecl %s\n",register_name(cadr(e2),0));
|
0
|
569 return;
|
|
570 }
|
|
571 g_expr(e2);
|
21
|
572 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
|
18
|
573 printf("\tdecl (%s)\n",register_name(creg,0));
|
0
|
574 return;
|
|
575 case CPREDEC:
|
|
576 if (car(e2)==REGISTER) {
|
18
|
577 printf("\tdecl %s\n",register_name(cadr(e2),0));
|
|
578 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
0
|
579 return;
|
|
580 }
|
|
581 g_expr(e2);
|
|
582 emit_push();
|
18
|
583 e2 = emit_pop(0);
|
|
584 printf("\tdecl (%s)\n",register_name(e2,0));
|
21
|
585 printf("\tmovsbl (%s),%s\n",register_name(e2,0),register_name(creg,0));
|
41
|
586 regv[e2]=0;
|
0
|
587 return;
|
|
588 case MUL: case UMUL:
|
|
589 case DIV: case UDIV:
|
|
590 case MOD: case UMOD:
|
|
591 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT:
|
|
592 case ADD: case SUB: case BAND: case EOR: case BOR:
|
|
593 machinop(e1);
|
|
594 return;
|
|
595 case COND:
|
|
596 e2=fwdlabel();
|
|
597 b_expr(cadr(e1),0,e2);
|
22
|
598 use_register(creg,REG_EAX,0);
|
0
|
599 g_expr(caddr(e1));
|
22
|
600 /* e4 = rname[creg]; this is a bad idea */
|
|
601 use_register(creg,REG_EAX,1);
|
0
|
602 jmp(e3=fwdlabel());
|
|
603 fwddef(e2);
|
22
|
604 use_register(creg,REG_EAX,0);
|
0
|
605 g_expr(cadddr(e1));
|
22
|
606 /* use_register(creg,e4,1); */
|
|
607 use_register(creg,REG_EAX,1);
|
0
|
608 fwddef(e3);
|
|
609 return;
|
37
|
610 case RSTRUCT:
|
|
611 g_expr(e2);
|
|
612 return;
|
0
|
613 case SASS:
|
|
614 sassign(e1);
|
|
615 return;
|
|
616 case ASS: case CASS:
|
|
617 assign(e1);
|
|
618 return;
|
|
619 case ASSOP: case CASSOP:
|
|
620 assop(e1);
|
|
621 return;
|
|
622 case COMMA:
|
|
623 g_expr(e2);
|
|
624 g_expr(caddr(e1));
|
|
625 return;
|
|
626 case RETURN:
|
|
627 n = (NMTBL *)e2;
|
|
628 if (retcont==0)
|
|
629 retcont=fwdlabel();
|
18
|
630 printf("\tleal _%d,%s\n",retcont,register_name(creg,0));
|
0
|
631 return;
|
|
632 case ENVIRONMENT:
|
18
|
633 printf("\tmovl %%ebp,%s\n",register_name(creg,0));
|
0
|
634 return;
|
|
635 default:
|
|
636 b_expr(e1,1,e2=fwdlabel()); /* including > < ... */
|
18
|
637 xrn = register_name(creg,0);
|
|
638 printf("\txorl %s,%s\n",xrn,xrn);
|
0
|
639 jmp(e3=fwdlabel());
|
|
640 fwddef(e2);
|
18
|
641 printf("\tmovl $1,%s\n",xrn);
|
0
|
642 fwddef(e3);
|
|
643 }
|
|
644 }
|
|
645
|
|
646 void
|
|
647 bexpr(int e1, char cond, int l1)
|
|
648 {
|
|
649 gexpr_init();
|
|
650 b_expr(e1,cond,l1);
|
|
651 }
|
|
652
|
|
653 void
|
|
654 b_expr(int e1, char cond, int l1)
|
|
655 {
|
|
656 int e2,l2;
|
|
657 if (chk) return;
|
|
658 e2=cadr(e1);
|
|
659 switch(car(e1)) {
|
|
660 case LNOT:
|
|
661 b_expr(e2,!cond,l1);
|
|
662 return;
|
|
663 case GT:
|
|
664 rexpr(e1,l1,cond?"g":"le");
|
|
665 return;
|
|
666 case UGT:
|
|
667 rexpr(e1,l1,cond?"a":"be");
|
|
668 return;
|
|
669 case GE:
|
|
670 rexpr(e1,l1,cond?"ge":"l");
|
|
671 return;
|
|
672 case UGE:
|
|
673 rexpr(e1,l1,cond?"ae":"b");
|
|
674 return;
|
|
675 case LT:
|
|
676 rexpr(e1,l1,cond?"l":"ge");
|
|
677 return;
|
|
678 case ULT:
|
|
679 rexpr(e1,l1,cond?"b":"ae");
|
|
680 return;
|
|
681 case LE:
|
|
682 rexpr(e1,l1,cond?"le":"g");
|
|
683 return;
|
|
684 case ULE:
|
|
685 rexpr(e1,l1,cond?"be":"a");
|
|
686 return;
|
|
687 case EQ:
|
|
688 rexpr(e1,l1,cond?"e":"ne");
|
|
689 return;
|
|
690 case NEQ:
|
|
691 rexpr(e1,l1,cond?"ne":"e");
|
|
692 return;
|
|
693 case LAND:
|
|
694 b_expr(e2,0,cond?(l2=fwdlabel()):l1);
|
|
695 b_expr(caddr(e1),cond,l1);
|
|
696 if(cond) fwddef(l2);
|
|
697 return;
|
|
698 case LOR:
|
|
699 b_expr(e2,1,cond?l1:(l2=fwdlabel()));
|
|
700 b_expr(caddr(e1),cond,l1);
|
|
701 if(!cond) fwddef(l2);
|
|
702 return;
|
|
703 case CRGVAR:
|
18
|
704 printf("\tcmpb $0,%s\n",(char *)caddr(e1));
|
0
|
705 jcond(l1,cond);
|
|
706 return;
|
|
707 case CRLVAR:
|
|
708 printf("\tcmpb $0,%d(%%ebp)\n",lvar(e2));
|
|
709 jcond(l1,cond);
|
|
710 return;
|
|
711 case RGVAR:
|
18
|
712 printf("\tcmpl $0,%s\n",(char *)caddr(e1));
|
0
|
713 jcond(l1,cond);
|
|
714 return;
|
|
715 case RLVAR:
|
|
716 printf("\tcmpl $0,%d(%%ebp)\n",lvar(e2));
|
|
717 jcond(l1,cond);
|
|
718 return;
|
|
719 case REGISTER:
|
18
|
720 printf("\tcmpl $0,%s\n",register_name(e2,0));
|
0
|
721 jcond(l1,cond);
|
|
722 return;
|
|
723 case CONST:
|
|
724 if((cond&&e2)||(!cond&&!e2)) jmp(l1);
|
|
725 return;
|
|
726 default:
|
|
727 g_expr(e1);
|
18
|
728 printf("\tcmpl $0,%s\n",register_name(creg,0));
|
0
|
729 jcond(l1,cond);
|
|
730 return;
|
|
731 }
|
|
732 }
|
|
733
|
|
734 void
|
|
735 ascii(char *s)
|
|
736 {
|
|
737 printf("\t.string \"");
|
|
738 while(*s) {
|
|
739 if (*s=='\n')
|
|
740 printf("%cn",92);
|
|
741 else if (*s<' ')
|
|
742 printf("%c%03o",92,*s);
|
|
743 else if (*s==34)
|
|
744 printf("%c%c",92,34);
|
|
745 else
|
|
746 printf("%c",*s);
|
|
747 s++;
|
|
748 }
|
|
749 printf("%c\n",34);
|
|
750 }
|
|
751
|
|
752 void
|
|
753 string(int e1)
|
|
754 {
|
|
755 char *s;
|
|
756 int i,lb;
|
|
757
|
|
758 if (0) {
|
|
759 s=(char *)cadr(e1);
|
|
760 lb=fwdlabel();
|
|
761 printf("\tjmp _%d\n",lb);
|
|
762 i=backdef();
|
|
763 ascii(s);
|
|
764 printf("\t.align 2\n");
|
|
765 fwddef(lb);
|
18
|
766 printf("\tlea _%d,%s\n",i,register_name(creg,0));
|
0
|
767 } else {
|
|
768 s=(char *)cadr(e1);
|
|
769 printf(".section\t.rodata\n");
|
|
770 lb=fwdlabel();
|
|
771 printf("_%d:\n",lb);
|
|
772 ascii(s);
|
|
773 if (output_mode==TEXT_EMIT_MODE) {
|
|
774 printf(".text\n");
|
|
775 } else {
|
|
776 text_mode();
|
|
777 }
|
18
|
778 printf("\tlea _%d,%s\n",lb,register_name(creg,0));
|
0
|
779 }
|
|
780 }
|
|
781
|
13
|
782 #define MAX_COPY_LEN 20
|
|
783
|
|
784 void
|
38
|
785 emit_copy(int from,int to,int length,int offset)
|
13
|
786 {
|
39
|
787 int fix = 0;
|
|
788 if (length<=0) return;
|
13
|
789 switch (length) {
|
|
790 case 0: break;
|
|
791 case 1:
|
38
|
792 printf("\tmovb %d(%s),%s\n",offset,register_name(from,0), reg_name_l[rname[dreg]] );
|
|
793 printf("\tmovb %s,%d(%s)\n",reg_name_l[rname[dreg]] ,offset,register_name(to,0));
|
13
|
794 break;
|
|
795 case 2:
|
38
|
796 printf("\tmovw %d(%s),%s\n",offset,register_name(from,0), reg_name_w[rname[dreg]] );
|
|
797 printf("\tmovw %s,%d(%s)\n",reg_name_w[rname[dreg]] ,offset,register_name(to,0));
|
13
|
798 break;
|
|
799 case 4:
|
38
|
800 printf("\tmovl %d(%s),%s\n",offset,register_name(from,0), register_name(dreg,0));
|
|
801 printf("\tmovl %s,%d(%s)\n",register_name(dreg,0), offset,register_name(to,0));
|
13
|
802 break;
|
|
803 default:
|
|
804 if (length <=MAX_COPY_LEN) {
|
14
|
805 for(;length>=4;length-=4,offset+=4)
|
13
|
806 emit_copy(from,to,4,offset);
|
14
|
807 for(;length>=2;length-=2,offset+=2)
|
13
|
808 emit_copy(from,to,2,offset);
|
|
809 if(length>0)
|
|
810 emit_copy(from,to,length,offset);
|
39
|
811 break;
|
13
|
812 }
|
39
|
813 use_register(from,REG_ESI,1);
|
|
814 use_register(to, REG_EDI,1);
|
|
815 use_register(dreg,REG_ECX,0);
|
14
|
816 printf("\tmovl $%d,%%ecx\n",length/4);
|
39
|
817 fix = (length/4)*4;
|
13
|
818 printf("\tcld\n\trep\n\tmovsl\n");
|
14
|
819 if(length%4) {
|
38
|
820 emit_copy(from,to,length,offset+length/4);
|
14
|
821 }
|
13
|
822 }
|
39
|
823 /* this code is necessary for the value of assignment or function call */
|
|
824 /* otherwise we don't need this */
|
|
825 if (fix) printf("\tsubl $%d,%s\n",fix,register_name(to,0));
|
|
826 if(creg!=to) {
|
|
827 free_register(creg); creg=to;
|
|
828 }
|
41
|
829 regv[from]=regv[to]=regv[dreg]=0;
|
13
|
830 }
|
|
831
|
|
832 int
|
|
833 struct_push(int e4,int t)
|
|
834 {
|
38
|
835 int length,xreg,save;
|
13
|
836 g_expr(e4);
|
14
|
837 length=size(t);
|
|
838 if(length%size_of_int) {
|
|
839 length += size_of_int - (length%size_of_int);
|
13
|
840 }
|
40
|
841 if (length==4) {
|
|
842 printf("\tpushl (%s)\n",register_name(creg,0)); return 1;
|
|
843 }
|
|
844 if (length==8) {
|
|
845 printf("\tpushl 4(%s)\n",register_name(creg,0));
|
|
846 printf("\tpushl (%s)\n",register_name(creg,0)); return 2;
|
|
847 }
|
38
|
848 /* I think, after g_expr, at least two registers are free */
|
14
|
849 printf("\tsubl $%d,%%esp\n",length);
|
38
|
850 if (register_full()) {
|
|
851 /* this is wrong assumption */
|
|
852 save = 1;
|
|
853 printf("\tpushl %s\n",register_name(lreg,0));
|
|
854 xreg = lreg;
|
|
855 } else {
|
|
856 save=0;
|
|
857 xreg = get_register();
|
13
|
858 }
|
38
|
859 printf("\tmovl %%esp,%s\n",register_name(xreg,0));
|
41
|
860 regv[xreg]=1;
|
38
|
861 emit_copy(creg,xreg,length,0);
|
|
862 if (save) {
|
|
863 printf("\tpopl %s\n",register_name(lreg,0));
|
|
864 } else
|
|
865 free_register(xreg);
|
41
|
866 regv[xreg]=0;
|
14
|
867 return length/size_of_int;
|
13
|
868 }
|
|
869
|
0
|
870 void
|
|
871 function(int e1)
|
|
872 {
|
13
|
873 int e2,e3,e4,e5,nargs,t;
|
0
|
874 NMTBL *n;
|
23
|
875 int save,saved;
|
|
876 if (free_register_count()<1) {
|
|
877 for(save = 0;save==dreg||save==creg;save++);
|
|
878 printf("\tpushl %s\n",register_name(save,0));
|
|
879 saved = 1;
|
|
880 } else {
|
|
881 save = get_register();
|
|
882 saved = 0;
|
|
883 }
|
41
|
884 regv[save]=0;
|
0
|
885 e2 = cadr(e1);
|
|
886 nargs = 0;
|
|
887 for (e3 = caddr(e1); e3; e3 = cadr(e3)) {
|
13
|
888 t=caddr(e3);
|
0
|
889 n=(NMTBL *)(e5=(cadr(e4 = car(e3))));
|
|
890 switch(car(e4)) {
|
|
891 case FNAME:
|
18
|
892 printf("\tlea %s,%s\n",n->nm,register_name(creg,0));
|
|
893 printf("\tpushl %s\n",register_name(creg,0));
|
0
|
894 break;
|
|
895 case ADDRESS:
|
|
896 g_expr(e5);
|
18
|
897 printf("\tpushl %s\n",register_name(creg,0));
|
0
|
898 break;
|
13
|
899 default:
|
|
900 if(scalar(t)) {
|
|
901 g_expr(e4);
|
18
|
902 printf("\tpushl %s\n",register_name(creg,0));
|
13
|
903 } else if (car(t)==STRUCT||car(t)==UNION) {
|
|
904 nargs += struct_push(e4,t);
|
|
905 continue;
|
|
906 } else {
|
|
907 error(TYERR);
|
|
908 }
|
0
|
909 }
|
|
910 ++nargs;
|
|
911 }
|
|
912 if (car(e2) == FNAME) {
|
|
913 n=(NMTBL *)cadr(e2);
|
23
|
914 } else {
|
|
915 use_register(creg,REG_ECX,0);
|
|
916 g_expr(e2);
|
|
917 }
|
|
918
|
26
|
919 /* we don't have to save creg nor dreg */
|
41
|
920 regs[creg]=0; regs[dreg]=0;
|
|
921 regv[creg]= regv[dreg]= regv[save]= 0;
|
23
|
922 use_register(creg,REG_EAX,0);
|
|
923 use_register(dreg,REG_EDX,0); /* will be destroyed */
|
|
924 use_register(save,REG_ECX,0); /* will be destroyed */
|
41
|
925 regs[creg]=1; regs[dreg]=1;
|
23
|
926
|
|
927 if (car(e2) == FNAME) {
|
0
|
928 printf("\tcall\t%s\n",n->nm);
|
23
|
929 } else {
|
18
|
930 printf("\tcall\t*%s\n",register_name(creg,0));
|
0
|
931 }
|
6
|
932 if (nargs) printf("\taddl $%d,%%esp\n",size_of_int*nargs);
|
23
|
933 if (saved) {
|
|
934 printf("\tpopl %s\n",register_name(save,0));
|
|
935 } else {
|
|
936 free_register(save);
|
|
937 }
|
41
|
938 regv[save]=0;
|
|
939 regv[creg]=1;
|
0
|
940 }
|
|
941
|
2
|
942 int
|
3
|
943 arg_size(int e3,int *nargs0)
|
2
|
944 {
|
|
945 int i,nargs,offset_list,e,t;
|
|
946
|
|
947 offset_list = 0;
|
|
948 /* we should use prototypes's type */
|
|
949 for (i = nargs = 0; e3;e3 =cadr(e3)) {
|
|
950 e = car(e3); t = caddr(e3);
|
3
|
951 if (i < MAX_REGISTER_VAR && scalar(t)) {
|
5
|
952 offset_list = list3(-(REG_ESI+i++),offset_list,e);
|
2
|
953 } else {
|
|
954 offset_list =
|
5
|
955 list3(nargs,offset_list,e);
|
3
|
956 nargs += (car(e3)==CHAR?size_of_int:size(t));
|
2
|
957 }
|
|
958 }
|
3
|
959 *nargs0 = -nargs;
|
2
|
960 return offset_list;
|
|
961 }
|
|
962
|
18
|
963 int
|
|
964 is_simple(int e1)
|
|
965 {
|
|
966 int e2 = car(e1);
|
|
967 return (
|
|
968 e2==FNAME || e2==LVAR || e2==CRLVAR || e2==REGISTER
|
|
969 );
|
|
970 }
|
|
971
|
|
972 void
|
|
973 jump_new(int e1, int env)
|
|
974 {
|
|
975 int e2;
|
|
976 NMTBL *code0;
|
|
977 /*
|
|
978 jump アドレスを計算する
|
|
979 */
|
|
980 /* compute jump address */
|
|
981 e2 = cadr(e1);
|
|
982 if (car(e2) == FNAME) {
|
|
983 code0=(NMTBL *)cadr(e2);
|
|
984 if (code0->sc!=CODE) {
|
|
985 error(STERR); return;
|
|
986 }
|
|
987 } else { /* indirect */
|
|
988 g_expr(e2);
|
|
989 emit_push();
|
|
990 }
|
|
991 /*
|
|
992 まず、複雑な式を前もって単純な式に落す。
|
|
993 必要なら局所変数を用いる。
|
|
994 局所変数へのオフセットを覚えておく
|
|
995 */
|
|
996 /*
|
|
997 スタックの位置を修正する
|
|
998 */
|
|
999 /*
|
|
1000 オフセットを用いて、
|
|
1001 並べ変えを行う
|
|
1002 */
|
|
1003 /*
|
|
1004 スタックの位置を修正する
|
|
1005 */
|
|
1006 /*
|
|
1007 jump code を生成する
|
|
1008 */
|
|
1009 }
|
|
1010
|
0
|
1011 void
|
|
1012 jump(int e1, int env)
|
|
1013 {
|
18
|
1014 int i,args,e2,e3,e4,e5,nargs,regs;
|
0
|
1015 NMTBL *n,*code0;
|
6
|
1016 int new_disp,scode,disp1;
|
0
|
1017 char *xrn;
|
|
1018
|
2
|
1019 /* We need three passes. Compute Stack size, Compute Arg, Copy it. */
|
0
|
1020 /* count number of args */
|
2
|
1021 args = caddr(e1);
|
3
|
1022 args = reverse0(args);
|
|
1023 nargs = arg_size(args,&new_disp); /* compute in normal order */
|
5
|
1024 disp1 = (fnptr->sc==CODE)?0:-size_of_int;
|
|
1025 if (new_disp+disp1 < disp) { /* have to extend stack */
|
6
|
1026 if (fnptr->sc==CODE)
|
|
1027 printf("\tleal %d(%%ebp),%%esp\n",new_disp-size_of_int);
|
|
1028 else
|
|
1029 printf("\tleal %d(%%ebp),%%esp\n",new_disp+disp_offset);
|
0
|
1030 }
|
|
1031 /* compute jump address */
|
|
1032 e2 = cadr(e1);
|
|
1033 if (car(e2) == FNAME) {
|
|
1034 code0=(NMTBL *)cadr(e2);
|
|
1035 if (code0->sc!=CODE) {
|
|
1036 error(STERR); return;
|
|
1037 }
|
|
1038 } else { /* indirect */
|
|
1039 g_expr(e2);
|
|
1040 emit_push();
|
|
1041 }
|
2
|
1042 /* compute arguments in reverse order */
|
21
|
1043 /* printf("## jump code_arg_offset=%d code_disp_offset=%d\n",code_arg_offset,code_disp_offset); */
|
2
|
1044 regs = 0;
|
4
|
1045 i=MAX_REGISTER_VAR;
|
2
|
1046 for (e3=nargs; e3;e3 =cadr(e3)) {
|
|
1047 n=(NMTBL *)(e5=(cadr(e4 = caddr(e3))));
|
0
|
1048 switch(car(e4)) {
|
|
1049 case FNAME:
|
18
|
1050 printf("\tlea %s,%s\n",n->nm,register_name(creg,0));
|
0
|
1051 emit_push();
|
|
1052 break;
|
|
1053 case ADDRESS:
|
|
1054 g_expr(e5);
|
|
1055 emit_push();
|
|
1056 break;
|
|
1057 case RLVAR:
|
|
1058 case CRLVAR:
|
4
|
1059 if (env==0 && fnptr->sc==CODE) {
|
21
|
1060 /* printf("## e5=%d car(e3)=%d\n",e5,car(e3)); */
|
5
|
1061 if (e5>=0 && e5==car(e3)) {
|
2
|
1062 /* The same positioned local variable. No need to copy */
|
|
1063 reg_stack[reg_sp++] = -2;
|
|
1064 }
|
4
|
1065 break;
|
0
|
1066 }
|
3
|
1067 g_expr(e4);
|
|
1068 emit_push();
|
|
1069 break;
|
0
|
1070 case REGISTER:
|
21
|
1071 /* printf("## i=%d rname[e5]=%d\n",i,rname[e5]); */
|
4
|
1072 if (i>0 && rname[e5]==REG_ESI+ --i) {
|
3
|
1073 /* The same register variable. No need to copy */
|
2
|
1074 reg_stack[reg_sp++] = e5;
|
4
|
1075 break;
|
0
|
1076 }
|
|
1077 default:
|
|
1078 g_expr(e4);
|
|
1079 emit_push();
|
|
1080 }
|
2
|
1081 regs++;
|
0
|
1082 }
|
|
1083 if (env) {
|
2
|
1084 /* change the frame pointer */
|
0
|
1085 g_expr(env);
|
18
|
1086 printf("\tmovl %s,%%ebp\n",register_name(creg,0));
|
3
|
1087 } else if (fnptr->sc==FUNCTION) {
|
|
1088 printf("\tlea %d(%%ebp),%%ebp\n",disp_offset);
|
|
1089 }
|
|
1090 /* force lvar offset mode to CODE */
|
|
1091 scode = fnptr->sc; fnptr->sc = CODE;
|
21
|
1092 /* printf("## jump2 code_arg_offset=%d code_disp_offset=%d\n",code_arg_offset,code_disp_offset); */
|
0
|
1093 /* copy arguments to destination environment if necessary */
|
3
|
1094 nargs = reverse0(nargs); /* pop in normal order */
|
|
1095 i=0;
|
|
1096 for (e3=nargs; e3;e3 =cadr(e3)) {
|
5
|
1097 if ((e4=car(e3))<0) {
|
2
|
1098 /* register case */
|
|
1099 if (reg_stack[--reg_sp]>=REG_ESI) {
|
|
1100 /* the same registger */
|
|
1101 } else {
|
|
1102 if(reg_stack[reg_sp]<0) {
|
5
|
1103 printf("\tpopl %s\n",reg_name[rname[REG_ESI+i]]); /* e4? */
|
2
|
1104 } else {
|
|
1105 printf("\tmovl %s,%s\n",
|
|
1106 reg_name[rname[reg_stack[reg_sp]]],
|
5
|
1107 reg_name[rname[REG_ESI+i]]); /* e4? */
|
2
|
1108 free_register(reg_stack[reg_sp]);
|
|
1109 }
|
3
|
1110 i++;
|
2
|
1111 }
|
|
1112 } else {
|
|
1113 /* local variable case */
|
0
|
1114 if (reg_stack[reg_sp-1]== -2) {
|
|
1115 /* same positioned variable */
|
|
1116 reg_sp--;
|
|
1117 } else {
|
18
|
1118 printf("\tmovl %s,%d(%%ebp)\n",register_name(emit_pop(0),0), lvar(e4));
|
0
|
1119 }
|
|
1120 }
|
|
1121 }
|
|
1122 if (car(e2) != FNAME) {
|
18
|
1123 xrn=register_name(emit_pop(0),0);
|
0
|
1124 }
|
6
|
1125 if (!env && new_disp+disp1>disp) {
|
0
|
1126 /* shrink stack if necessary */
|
5
|
1127 printf("\tleal %d(%%ebp),%%esp\n",new_disp-size_of_int);
|
0
|
1128 }
|
|
1129 if (car(e2) == FNAME) {
|
|
1130 printf("\tjmp %s\n",code0->nm);
|
|
1131 } else {
|
|
1132 printf("\tjmp *%s\n",xrn);
|
|
1133 }
|
3
|
1134 fnptr->sc = scode;
|
0
|
1135 }
|
|
1136
|
|
1137
|
|
1138 void
|
|
1139 machinop(int e1)
|
|
1140 {
|
|
1141 int e2,e3,op;
|
|
1142
|
|
1143 e2 = cadr(e1);
|
|
1144 op = car(e1);
|
|
1145 e3 = caddr(e1);
|
|
1146 g_expr(e3);
|
|
1147 emit_push();
|
|
1148 g_expr(e2);
|
|
1149 tosop(car(e1));
|
|
1150 return;
|
|
1151 }
|
|
1152
|
|
1153
|
|
1154 void
|
|
1155 rindirect(int e1) /* *(p +5 ) */
|
|
1156
|
|
1157 {
|
|
1158 char *op;
|
|
1159 int e2,e3,byte;
|
|
1160
|
|
1161 op = ((byte = (car(e1) == CRINDIRECT)) ? "movsbl" : "movl");
|
|
1162 e3 = cadr(e2 = cadr(e1));
|
|
1163 g_expr(e2);
|
21
|
1164 printf("\t%s (%s),%s\n",op,register_name(creg,0),register_name(creg,0));
|
0
|
1165 }
|
|
1166
|
|
1167 void
|
|
1168 sassign(int e1)
|
|
1169 {
|
38
|
1170 int e2,e3,e4,sz,xreg;
|
0
|
1171
|
18
|
1172 /* structure assignment */
|
37
|
1173 e2 = cadr(e1); /* pointer variable to the struct */
|
|
1174 e3 = cadr(e2); /* offset of the variable (distination) */
|
39
|
1175 e4 = caddr(e1); /* right value (source) */
|
37
|
1176 sz = cadddr(e1); /* size of struct or union */
|
0
|
1177 g_expr(e4);
|
|
1178 emit_push();
|
|
1179 g_expr(e2);
|
38
|
1180 xreg = emit_pop(0);
|
|
1181 emit_copy(xreg,creg,sz,0);
|
41
|
1182 regv[xreg]=0;
|
0
|
1183 return;
|
|
1184 }
|
|
1185
|
|
1186 void
|
|
1187 assign(int e1)
|
|
1188 {
|
|
1189 char *op;
|
|
1190 int e2,e3,e4,byte;
|
|
1191
|
|
1192 op = ((byte=(car(e1) == CASS))? "movb" : "movl");
|
|
1193 /* e2=e4 */
|
|
1194 e2 = cadr(e1);
|
|
1195 e3 = cadr(e2);
|
|
1196 e4 = caddr(e1);
|
|
1197 switch(car(e2)) {
|
|
1198 case GVAR: /* i=3 */
|
|
1199 g_expr(e4);
|
|
1200 if (byte) use_data_reg(creg,1);
|
18
|
1201 printf("\t%s %s,%s\n",op,register_name(creg,byte),(char *)caddr(e2));
|
0
|
1202 return;
|
|
1203 case LVAR:
|
|
1204 g_expr(e4);
|
|
1205 if (byte) use_data_reg(creg,1);
|
18
|
1206 printf("\t%s %s,%d(%%ebp)\n",op,register_name(creg,byte),lvar(cadr(e2)));
|
0
|
1207 return;
|
|
1208 case REGISTER:
|
|
1209 g_expr(e4);
|
|
1210 if (creg!=cadr(e2))
|
23
|
1211 printf("\tmovl %s,%s\n",register_name(creg,0),register_name(cadr(e2),0));
|
0
|
1212 return;
|
|
1213 }
|
23
|
1214 g_expr(e2);
|
0
|
1215 emit_push();
|
23
|
1216 use_data_reg(creg,0);
|
|
1217 g_expr(e4);
|
0
|
1218 if (byte) use_data_reg(creg,1);
|
23
|
1219 e2 = emit_pop(0);
|
|
1220 printf("\t%s %s,(%s)\n",op,register_name(creg,byte),register_name(e2,0));
|
41
|
1221 regv[e2]=0;
|
0
|
1222 return;
|
|
1223 }
|
|
1224
|
|
1225 void
|
|
1226 assop(int e1)
|
|
1227 {
|
|
1228 int e2,e3,byte,op,new_reg;
|
|
1229 char *xrn;
|
18
|
1230 int xreg;
|
0
|
1231
|
|
1232 /* e2 op= e3 */
|
|
1233 byte = (car(e1) == CASSOP);
|
|
1234 e2 = cadr(e1);
|
|
1235 if (car(e2)==INDIRECT) e2=cadr(e2);
|
|
1236 e3 = caddr(e1);
|
|
1237 op = cadddr(e1);
|
|
1238
|
|
1239 g_expr(e3);
|
|
1240 emit_push();
|
|
1241 if (car(e2)==REGISTER) {
|
|
1242 new_reg=creg;
|
18
|
1243 creg = cadr(e2);
|
0
|
1244 tosop(op);
|
18
|
1245 creg = new_reg;
|
|
1246 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
0
|
1247 return;
|
|
1248 }
|
|
1249 g_expr(e2);
|
18
|
1250 xrn = register_name(xreg = emit_pop(0),0); /* pop e3 value */
|
|
1251 printf("\tpushl %s # assop \n",register_name(creg,0)); /* push e2 address */
|
|
1252 ld_indexx(byte,0,creg);
|
0
|
1253 new_reg = get_register();
|
|
1254 /* push e3 value */
|
|
1255 if(new_reg<0) { /* もうレジスタがない */
|
|
1256 reg_stack[reg_sp++] = -1;
|
|
1257 printf("\tpushl %s\n",xrn);
|
|
1258 } else {
|
|
1259 reg_stack[reg_sp++] = xreg; /* push するかわりにレジスタを使う */
|
|
1260 }
|
41
|
1261 regv[xreg]=0;
|
0
|
1262 tosop(op);
|
|
1263 if(new_reg>=0) free_register(new_reg);
|
18
|
1264 printf("\tpopl %s # assop \n",register_name(dreg,0));
|
21
|
1265 printf("\t%s %s,(%s)\n",byte ? "movb" : "movl",register_name(creg,byte),register_name(dreg,0));
|
41
|
1266 regv[dreg]=0;
|
0
|
1267 return;
|
|
1268
|
|
1269 }
|
|
1270
|
|
1271
|
|
1272 void
|
|
1273 tosop(int op)
|
|
1274 {
|
|
1275 int oreg;
|
18
|
1276 char *orn,*crn;
|
0
|
1277
|
|
1278 oreg = pop_register();
|
|
1279 switch(op) {
|
|
1280 case LSHIFT:
|
|
1281 case ULSHIFT:
|
|
1282 shift("sall",oreg);
|
|
1283 return;
|
|
1284 case RSHIFT:
|
|
1285 shift("sarl",oreg);
|
|
1286 return;
|
|
1287 case URSHIFT:
|
|
1288 shift("shrl",oreg);
|
|
1289 return;
|
|
1290 }
|
|
1291 if(oreg==-1) {
|
18
|
1292 printf("\tpopl %s\n",register_name(dreg,0));
|
0
|
1293 oreg = dreg;
|
41
|
1294 regv[oreg]=1;
|
0
|
1295 }
|
18
|
1296 orn = register_name(oreg,0);
|
|
1297 crn = register_name(creg,0);
|
0
|
1298 switch(op) {
|
|
1299 case ADD:
|
|
1300 printf("\taddl %s,%s\n",orn,crn);
|
41
|
1301 break;
|
0
|
1302 case SUB:
|
|
1303 printf("\tsubl %s,%s\n",orn,crn);
|
41
|
1304 break;
|
0
|
1305 case BAND:
|
|
1306 printf("\tandl %s,%s\n",orn,crn);
|
41
|
1307 break;
|
0
|
1308 case EOR:
|
|
1309 printf("\txorl %s,%s\n",orn,crn);
|
41
|
1310 break;
|
0
|
1311 case BOR:
|
|
1312 printf("\torl %s,%s\n",orn,crn);
|
41
|
1313 break;
|
0
|
1314 case MUL:
|
|
1315 case UMUL:
|
|
1316 /* use_register(dreg,REG_EDX,0); */
|
|
1317 printf("\t%s %s,%s\n","imull",orn,crn);
|
41
|
1318 break;
|
0
|
1319 case DIV:
|
|
1320 case UDIV:
|
|
1321 orn = div_setup(oreg);
|
|
1322 if (op==DIV)
|
|
1323 printf("\tcltd\n\tdivl %s\n",orn);
|
|
1324 else
|
|
1325 printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
|
|
1326 div_cleanup(orn);
|
41
|
1327 break;
|
0
|
1328 case MOD:
|
|
1329 case UMOD:
|
|
1330 orn = div_setup(oreg);
|
|
1331 if (op==DIV)
|
|
1332 printf("\tcltd\n\tdivl %s\n",orn);
|
|
1333 else
|
|
1334 printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
|
|
1335 rname[creg]=REG_EDX;
|
|
1336 rname[dreg]=REG_EAX;
|
|
1337 div_cleanup(orn);
|
41
|
1338 break;
|
0
|
1339 }
|
41
|
1340 if (oreg>=0) regv[oreg]=0;
|
|
1341 regv[dreg]=0;
|
0
|
1342 }
|
|
1343
|
|
1344 static char *dvi_push = "(%esp)";
|
|
1345
|
|
1346 char *
|
|
1347 div_setup(int oreg)
|
|
1348 {
|
|
1349 if (oreg<0) {
|
|
1350 use_register(creg,REG_EAX,1);
|
|
1351 use_register(dreg,REG_EDX,0);
|
|
1352 return 0;
|
|
1353 }
|
|
1354 if (register_full()) {
|
18
|
1355 printf("\tpushl %s\n",register_name(oreg,0));
|
0
|
1356 use_register(creg,REG_EAX,1);
|
|
1357 use_register(oreg,REG_EDX,0);
|
|
1358 return dvi_push;
|
|
1359 }
|
|
1360 regs[oreg]=1;
|
|
1361 use_register(creg,REG_EAX,1);
|
|
1362 use_register(dreg,REG_EDX,0);
|
|
1363 regs[oreg]=0;
|
18
|
1364 return register_name(oreg,0);
|
0
|
1365 }
|
|
1366
|
18
|
1367
|
|
1368 void
|
0
|
1369 div_cleanup(char *orn)
|
|
1370 {
|
|
1371 if (orn==dvi_push)
|
|
1372 printf("\taddl $4,%%esp\n");
|
|
1373 }
|
|
1374
|
|
1375 void
|
|
1376 shift(char *op, int reg)
|
|
1377 {
|
|
1378 if (reg>=0) {
|
|
1379 use_register(lreg,REG_ECX,1);
|
|
1380 } else {
|
|
1381 use_register(dreg,REG_ECX,0);
|
|
1382 printf("\tpopl %%ecx\n");
|
|
1383 }
|
18
|
1384 printf("\t%s %%cl,%s\n",op,register_name(creg,0));
|
0
|
1385 }
|
|
1386
|
|
1387 void
|
18
|
1388 ld_indexx(int byte, int n, int xreg)
|
0
|
1389 {
|
|
1390 char *op;
|
|
1391
|
|
1392 op = byte ? "movsbl" : "movl";
|
|
1393 if (n)
|
18
|
1394 printf("\t%s %d(%s),%s\n",op,n,register_name(xreg,0),register_name(creg,byte));
|
0
|
1395 else
|
18
|
1396 printf("\t%s (%s),%s\n",op,register_name(xreg,0),register_name(creg,byte));
|
0
|
1397 }
|
|
1398
|
18
|
1399 /*
|
0
|
1400 void
|
18
|
1401 st_indexx(int byte, int n, int xreg)
|
0
|
1402 {
|
|
1403 char *op;
|
|
1404
|
|
1405 op = byte ? "movb" : "movl";
|
|
1406 if (n)
|
18
|
1407 printf("\t%s %s,%d(%s)\n",op,register_name(creg,byte),n,register_name(xreg,0));
|
0
|
1408 else
|
18
|
1409 printf("\t%s %s,(%s)\n",op,register_name(creg,byte),register_name(xreg,0));
|
0
|
1410 }
|
|
1411
|
|
1412 void
|
|
1413 indexy(char *op, char *gvar)
|
|
1414 {
|
18
|
1415 printf("\t%s %s,%s\n",op,register_name(creg,0),gvar);
|
0
|
1416 }
|
18
|
1417 */
|
0
|
1418
|
|
1419 void
|
|
1420 cmpdimm(int e, int csreg)
|
|
1421 {
|
|
1422 /* used in dosiwtch() */
|
|
1423 use_register(creg,csreg,0);
|
18
|
1424 printf("\tcmpl $%d,%s\n",e,register_name(creg,0));
|
0
|
1425 }
|
|
1426
|
|
1427 void
|
|
1428 opening(char *filename)
|
|
1429 {
|
|
1430 printf("\t.file \"%s\"\n",filename);
|
|
1431 printf("\t.version\t\"01.01\"\n");
|
|
1432 printf("gcc2_compiled.:\n");
|
|
1433 printf(".text\n");
|
|
1434 emit_init();
|
|
1435 }
|
|
1436
|
|
1437 void
|
|
1438 closing(void)
|
|
1439 {
|
|
1440 global_table();
|
|
1441 printf("\t.ident \"Micro-C compiled\"\n");
|
|
1442 }
|
|
1443
|
18
|
1444 /*
|
0
|
1445 void
|
|
1446 jmp_label(int l)
|
|
1447 {
|
|
1448 printf("\tjmp\t_%d\n",l);
|
|
1449 }
|
18
|
1450 */
|
0
|
1451
|
18
|
1452 /*
|
0
|
1453 void
|
|
1454 jmp_eq_label(int l)
|
|
1455 {
|
|
1456 printf("\tje\t_%d\n",l);
|
|
1457 }
|
18
|
1458 */
|
0
|
1459
|
|
1460 void
|
|
1461 rexpr(int e1, int l1, char *s)
|
|
1462 {
|
|
1463 g_expr(list3(SUB,cadr(e1),caddr(e1)));
|
|
1464 printf("\tj%s\t_%d\n",s,l1);
|
|
1465 }
|
|
1466
|
|
1467 void
|
|
1468 jcond(int l, char cond)
|
|
1469 {
|
|
1470 printf("\tj%s\t_%d\n",cond?"ne":"e",l);
|
|
1471 }
|
|
1472
|
|
1473 void
|
|
1474 jmp(int l)
|
|
1475 {
|
|
1476 control=0;
|
|
1477 printf("\tjmp\t_%d\n",l);
|
|
1478 /* align? */
|
|
1479 }
|
|
1480
|
|
1481 int
|
|
1482 fwdlabel(void)
|
|
1483 {
|
|
1484 return labelno++;
|
|
1485 }
|
|
1486
|
|
1487 void
|
|
1488 fwddef(int l)
|
|
1489 {
|
|
1490 control=1;
|
|
1491 printf("_%d:\n",l);
|
|
1492 }
|
|
1493
|
|
1494 int
|
|
1495 backdef(void)
|
|
1496 {
|
|
1497 control=1;
|
|
1498 printf("_%d:\n",labelno);
|
|
1499 return labelno++;
|
|
1500 }
|
|
1501
|
|
1502 void
|
|
1503 def_label(int cslabel, int dlabel)
|
|
1504 {
|
|
1505 int fl;
|
|
1506
|
|
1507 fl = 0;
|
|
1508 if (control) {
|
|
1509 jmp(fl=fwdlabel());
|
|
1510 }
|
|
1511 fwddef(cslabel);
|
|
1512 if (dlabel)
|
|
1513 jmp(dlabel);
|
|
1514 if (fl) {
|
|
1515 fwddef(fl);
|
|
1516 }
|
|
1517 }
|
|
1518
|
|
1519 void
|
|
1520 gen_comment(char *s)
|
|
1521 {
|
21
|
1522 printf("## %s",s);
|
0
|
1523 }
|
|
1524
|
|
1525 void
|
|
1526 gen_source(char *s)
|
|
1527 {
|
|
1528 printf("%s",s);
|
|
1529 }
|
|
1530
|
|
1531 void
|
|
1532 code_enter(char *name)
|
|
1533 {
|
|
1534 printf("\t.align 4\n");
|
|
1535 if (stmode!=STATIC)
|
|
1536 printf(".globl %s\n",name);
|
|
1537 printf("\t.type\t%s,@function\n",name);
|
|
1538 printf("%s:\n",name);
|
|
1539 }
|
|
1540
|
|
1541 void
|
6
|
1542 code_enter1(int disp0,int args)
|
0
|
1543 {
|
36
|
1544 code_disp_label=fwdlabel();
|
|
1545 printf("\tsubl $_%d,%%esp\n",code_disp_label);
|
|
1546 /*
|
6
|
1547 if(disp0) {
|
|
1548 printf("\tsubl $%d,%%esp\n",-disp0);
|
0
|
1549 }
|
36
|
1550 */
|
21
|
1551 printf("## args %d disp %d code_arg_offset=%d code_disp_offset=%d\n",args,disp,code_arg_offset,code_disp_offset);
|
0
|
1552 }
|
|
1553
|
|
1554 void
|
36
|
1555 code_leave(char *name,int disp0)
|
0
|
1556 {
|
36
|
1557 printf("\t.set _%d,%d\n",code_disp_label,-disp0);
|
0
|
1558 printf("_%d:\n",labelno);
|
|
1559 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
|
12
|
1560 local_table();
|
0
|
1561 labelno++;
|
|
1562 }
|
|
1563
|
|
1564 void
|
|
1565 enter(char *name)
|
|
1566 {
|
|
1567 printf("\t.align 2\n");
|
|
1568 if (stmode!=STATIC)
|
|
1569 printf(".globl %s\n",name);
|
|
1570 printf("%s:\n",name);
|
|
1571 printf("\t.type\t%s,@function\n",name);
|
|
1572 printf("\tpushl %%ebp\n");
|
|
1573 printf("\tmovl %%esp,%%ebp\n");
|
|
1574 printf("\tpushl %%ebx\n");
|
24
|
1575 printf("\tpushl %%esi\n");
|
|
1576 printf("\tpushl %%edi\n");
|
0
|
1577 }
|
|
1578
|
|
1579 void
|
|
1580 enter1(int disp)
|
|
1581 {
|
36
|
1582 func_disp_label=fwdlabel();
|
|
1583 printf("\tsubl $_%d,%%esp\n",func_disp_label);
|
|
1584 /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
|
0
|
1585 }
|
|
1586
|
|
1587 void
|
36
|
1588 leave(int control, char *name,int disp)
|
0
|
1589 {
|
|
1590 if (control)
|
|
1591 use_register(creg,REG_EAX,1);
|
|
1592 if (retcont) {
|
|
1593 if (control)
|
|
1594 jmp(retlabel);
|
|
1595 fwddef(retcont);
|
|
1596 use_register(creg,REG_EAX,0);
|
18
|
1597 printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0));
|
0
|
1598 /* printf("\tleave\n"); */
|
|
1599 }
|
|
1600 fwddef(retlabel);
|
|
1601 use_register(creg,REG_EAX,0);
|
|
1602 /* if(disp) printf("\taddl $%d,%%esp\n",-disp); */
|
|
1603 printf("\tlea %d(%%ebp),%%esp\n",disp_offset);
|
24
|
1604 printf("\tpopl %%edi\n");
|
|
1605 printf("\tpopl %%esi\n");
|
0
|
1606 printf("\tpopl %%ebx\n");
|
|
1607 printf("\tleave\n");
|
|
1608 printf("\tret\n");
|
36
|
1609 printf("\t.set _%d,%d\n",func_disp_label,-disp);
|
0
|
1610 printf("_%d:\n",labelno);
|
|
1611 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
|
12
|
1612 local_table();
|
0
|
1613 labelno++;
|
|
1614 }
|
|
1615
|
|
1616
|
|
1617 void
|
|
1618 ret(void)
|
|
1619 {
|
|
1620 use_register(creg,REG_EAX,1);
|
|
1621 jmp(retlabel);
|
|
1622 }
|
|
1623
|
|
1624 void
|
|
1625 gen_gdecl(char *n, int gpc)
|
|
1626 {
|
|
1627 /*
|
|
1628 if (stmode!=STATIC)
|
|
1629 printf(".globl %s\n",n);
|
|
1630 */
|
|
1631 }
|
|
1632
|
|
1633 void
|
|
1634 align(int t)
|
|
1635 {
|
|
1636 if (t!=CHAR) {
|
|
1637 if (data_alignment & 1)
|
|
1638 printf("\t.align 2\n");
|
|
1639 data_alignment = 0;
|
|
1640 }
|
|
1641 }
|
|
1642
|
|
1643 void
|
|
1644 emit_data(int e, int t, NMTBL *n)
|
|
1645 {
|
|
1646 int l;
|
|
1647 char *name;
|
|
1648 name = n->nm;
|
13
|
1649 if(mode!=GDECL) {
|
|
1650 error(-1); return;
|
|
1651 }
|
|
1652 if (n->dsp != -1) {
|
|
1653 n->dsp = -1; /* initiallized flag */
|
|
1654 printf(".globl\t%s\n",name);
|
|
1655 data_mode(name);
|
|
1656 align(t);
|
|
1657 printf("%s:\n",name);
|
|
1658 } else {
|
|
1659 data_mode(0);
|
|
1660 }
|
|
1661 if(car(e)==CONST) {
|
|
1662 if (t==CHAR) {
|
|
1663 printf("\t.byte %d\n",cadr(e));
|
|
1664 if (data_alignment>0)
|
|
1665 data_alignment++;
|
|
1666 gpc += 1;
|
0
|
1667 } else {
|
13
|
1668 printf("\t.long %d\n",cadr(e));
|
3
|
1669 gpc += size_of_int;
|
13
|
1670 }
|
|
1671 } else if(t!=CHAR) {
|
|
1672 gpc += size_of_int;
|
|
1673 if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
|
18
|
1674 printf("\t.long %s\n",(char *)caddr(cadr(e)));
|
13
|
1675 } else if(car(e)==FNAME) {
|
|
1676 printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
|
|
1677 } else if(car(e)==STRING) {
|
|
1678 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) {
|
|
1679 l = fwdlabel();
|
|
1680 printf("\t.long _%d\n",l);
|
|
1681 printf(".section\t.rodata\n");
|
|
1682 printf("_%d:\n",l);
|
|
1683 output_mode = RODATA_EMIT_MODE;
|
|
1684 }
|
|
1685 ascii((char *)cadr(e));
|
|
1686 } else error(TYERR);
|
0
|
1687 }
|
|
1688 }
|
|
1689
|
|
1690 void
|
|
1691 emit_data_closing(NMTBL *n)
|
|
1692 {
|
|
1693 int lb;
|
18
|
1694 if (mode==GDECL) {
|
0
|
1695 data_mode(0);
|
|
1696 lb=fwdlabel();
|
|
1697 printf("_%d:\n",lb);
|
|
1698 printf("\t.size\t%s,_%d-%s\n",n->nm,lb,n->nm);
|
|
1699 }
|
|
1700 }
|
|
1701
|
|
1702 void
|
|
1703 global_table(void)
|
|
1704 {
|
|
1705 NMTBL *n;
|
12
|
1706 int init;
|
|
1707 init=0;
|
0
|
1708 for(n=ntable;n < &ntable[GSYMS];n++) {
|
|
1709 if (n->sc == GVAR && n->dsp != -1) {
|
|
1710 /* n->dsp = -1 means initialized global */
|
12
|
1711 if (init==0) {
|
|
1712 data_mode(0);
|
|
1713 init=1;
|
|
1714 }
|
0
|
1715 printf(".comm %s,%d\n",n->nm,size(n->ty));
|
|
1716 }
|
|
1717 }
|
|
1718 }
|
|
1719
|
|
1720 void
|
|
1721 local_table(void)
|
|
1722 {
|
|
1723 NMTBL *n;
|
12
|
1724 int init;
|
|
1725 init=0;
|
0
|
1726 /* static local variables */
|
|
1727 for(n=ntable+GSYMS;n < &ntable[GSYMS+LSYMS];n++) {
|
|
1728 if (n->sc == GVAR) {
|
12
|
1729 if (init==0) {
|
|
1730 data_mode(0);
|
|
1731 init=1;
|
|
1732 }
|
0
|
1733 printf(".lcomm %s,%d\n",n->nm,size(n->ty));
|
|
1734 }
|
|
1735 }
|
|
1736 }
|
|
1737
|
|
1738 void
|
|
1739 text_mode(void)
|
|
1740 {
|
|
1741 if (output_mode!=TEXT_EMIT_MODE) {
|
|
1742 printf(".text\n");
|
|
1743 printf("\t.align 2\n");
|
|
1744 output_mode = TEXT_EMIT_MODE;
|
|
1745 }
|
|
1746 }
|
|
1747
|
|
1748 void
|
|
1749 data_mode(char *name)
|
|
1750 {
|
|
1751 if (output_mode!=DATA_EMIT_MODE) {
|
|
1752 printf(".data\n");
|
|
1753 output_mode = DATA_EMIT_MODE;
|
|
1754 }
|
|
1755 if (name)
|
|
1756 printf("\t.type\t%s,@object\n",name);
|
|
1757 }
|
|
1758
|
|
1759 int
|
|
1760 lvar(int l)
|
|
1761 {
|
|
1762 if (l<0) {
|
|
1763 if (fnptr->sc==CODE)
|
|
1764 return l+code_disp_offset;
|
|
1765 else
|
|
1766 return l+disp_offset;
|
|
1767 } else {
|
3
|
1768 if (fnptr->sc==CODE)
|
5
|
1769 return -l+code_arg_offset;
|
3
|
1770 else
|
|
1771 return l+arg_offset;
|
0
|
1772 }
|
|
1773 }
|
|
1774
|
|
1775 /* end */
|