61
|
1 /* Micro-C Code Generatation Part for intel386 */
|
|
2 /* $Id$ */
|
|
3
|
|
4 #define EXTERN extern
|
|
5 #include "mc.h"
|
|
6 #include "mc-codegen.h"
|
|
7
|
|
8 #define TEXT_EMIT_MODE 0
|
|
9 #define DATA_EMIT_MODE 1
|
|
10 #define RODATA_EMIT_MODE 2
|
|
11
|
|
12 static int output_mode = TEXT_EMIT_MODE;
|
|
13 static int data_alignment = 0;
|
|
14
|
|
15 static int code_disp_label;
|
|
16 static int func_disp_label;
|
|
17
|
|
18 /*
|
|
19 -16 -8 local2
|
|
20 -12 -4 local1
|
|
21 -8 8 arg3
|
|
22 -4 4 arg2
|
|
23 0 0 arg1
|
|
24 local2 -20 4 0 (%edi)
|
|
25 local1 <-- -16 0 local variable 0 (%esi)
|
|
26 %edi -12 <- disp_offset %ebp
|
|
27 %esi -8
|
|
28 %ebx -4
|
|
29 %ebp = %esp 0
|
|
30 %eip 4 <- arg_offset
|
|
31 arg1 8 0
|
|
32 arg2 12 4
|
|
33 see enter/enter1/leave see code_enter
|
|
34 */
|
|
35 int arg_offset = 8;
|
|
36 int disp_offset = -12;
|
|
37 int func_disp_offset = -12;
|
|
38 int code_disp_offset = 0;
|
|
39 int jump_offset = 0;
|
|
40
|
|
41 int size_of_int = 4;
|
81
|
42 int size_of_float = 4;
|
|
43 int size_of_dobule = 8;
|
|
44 int size_of_longlong = 8;
|
61
|
45 int endian = 0;
|
|
46 int MAX_REGISTER=6; /* intel386のレジスタを4つまで使う*/
|
|
47 int REAL_MAX_REGISTER=8; /* intel386のレジスタが8つということ*/
|
|
48 int MAX_DATA_REG=4;
|
|
49 int MAX_POINTER=3;
|
|
50 int MAX_REGISTGER_VAR=2;
|
|
51
|
|
52 EXTERN int creg; /* current register */
|
|
53 EXTERN int dreg; /* temporary register */
|
|
54 EXTERN int reg_sp; /* REGister Stack-Pointer */
|
|
55
|
|
56
|
|
57 #define REG_EAX 0
|
|
58 #define REG_EBX 1
|
|
59 #define REG_ECX 2
|
|
60 #define REG_EDX 3
|
|
61 #define REG_ESI 4
|
|
62 #define REG_EDI 5
|
|
63 #define REG_EBP 6
|
|
64 #define REG_ESP 7
|
|
65
|
|
66
|
|
67 #define DATA_REG 0
|
|
68 #define POINTER_REG 3
|
|
69 static char *reg_name[8];
|
|
70 static char *reg_name_l[4];
|
|
71 static char *reg_name_w[4];
|
|
72
|
|
73 extern int creg; /* current register */
|
|
74 extern int dreg; /* temporary register */
|
|
75 extern int reg_sp; /* REGister Stack-Pointer */
|
|
76
|
|
77 #define MAX_MAX 10
|
|
78 int rname[MAX_MAX];
|
|
79 int regs[MAX_MAX]; /* 使われているレジスタを示すフラグ */
|
|
80 int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
|
|
81 int regv[MAX_MAX]; /* 値が入っているかどうか */
|
|
82
|
|
83
|
|
84 void use_register(int virt, int real, int move);
|
|
85 void code_preinc(int e1,int e2) ;
|
|
86 void code_cmp_register(int e2) ;
|
|
87 void code_assign_gvar(int e2,int byte) ;
|
|
88 void tosop(int op,int oreg);
|
|
89 void edx_cleanup();
|
|
90 void shift(char *op, int reg);
|
|
91 void ld_indexx(int byte, int n, int xreg);
|
|
92 void jmp(int l);
|
|
93 void local_table(void);
|
|
94 void text_mode(void);
|
|
95 void data_mode(char *name);
|
|
96
|
|
97 char *register_name(int i,int byte);
|
|
98 int register_var(int r);
|
|
99 int get_register_var(void);
|
|
100 void emit_push(void);
|
|
101 int emit_pop(int type);
|
|
102 void code_crlvar(int e2);
|
|
103 void code_preinc(int e1,int e2);
|
|
104 void code_postinc(int e1,int e2);
|
|
105 void code_bool(int e1);
|
|
106 void string(int e1);
|
|
107 void emit_copy(int from,int to,int length,int offset,int value,int det);
|
|
108 int struct_push(int e4,int t);
|
|
109 void function(int e1);
|
|
110 void code_assop(int op,int byte);
|
|
111 int edx_setup();
|
66
|
112 void code_opening(char *filename);
|
|
113 void code_closing();
|
61
|
114 void code_leave(char *name);
|
|
115 int lvar(int l);
|
78
|
116 void global_table(void);
|
61
|
117
|
|
118 void
|
|
119 code_init(void)
|
|
120 {
|
|
121 arg_offset = 8;
|
|
122 func_disp_offset = -12;
|
|
123 disp_offset = -12;
|
|
124 size_of_int = 4;
|
|
125 endian = 0;
|
|
126 MAX_REGISTER=6;
|
|
127 MAX_DATA_REG=4;
|
|
128 MAX_POINTER=3;
|
|
129 MAX_REGISTER_VAR=2;
|
|
130
|
|
131 reg_name[REG_EAX] = "%eax";
|
|
132 reg_name[REG_EBX] = "%ebx";
|
|
133 reg_name[REG_ECX] = "%ecx";
|
|
134 reg_name[REG_EDX] = "%edx";
|
|
135 reg_name[REG_ESI] = "%esi";
|
|
136 reg_name[REG_EDI] = "%edi";
|
|
137 reg_name[REG_EBP] = "%ebp";
|
|
138 reg_name[REG_ESP] = "%esp";
|
|
139 reg_name_l[REG_EAX] = "%al";
|
|
140 reg_name_l[REG_EBX] = "%bl";
|
|
141 reg_name_l[REG_ECX] = "%cl";
|
|
142 reg_name_l[REG_EDX] = "%dl";
|
|
143 reg_name_w[REG_EAX] = "%ax";
|
|
144 reg_name_w[REG_EBX] = "%bx";
|
|
145 reg_name_w[REG_ECX] = "%cx";
|
|
146 reg_name_w[REG_EDX] = "%dx";
|
|
147
|
|
148 }
|
|
149
|
|
150 char *
|
|
151 register_name(int i,int byte)
|
|
152 {
|
|
153 if (i<0) {
|
|
154 error(REG_ERR);
|
|
155 return "%eax";
|
|
156 }
|
|
157 if (byte && rname[i] <= REG_EDX) {
|
|
158 return reg_name_l[rname[i]];
|
|
159 } else {
|
|
160 return reg_name[rname[i]]; /* should be error */
|
|
161 }
|
|
162 }
|
|
163
|
|
164 extern int creg_regvar;
|
|
165
|
|
166 void
|
|
167 gexpr_code_init(void){
|
|
168 use_register(creg,REG_EAX,0);
|
|
169 regv[dreg]=0;
|
|
170 creg_regvar = -1;
|
|
171 }
|
|
172
|
|
173 int
|
|
174 register_var(int r) {
|
|
175 return virtual(r+REG_ESI);
|
|
176 }
|
|
177
|
|
178 int
|
|
179 get_register_var(void)
|
|
180 {
|
|
181 int i;
|
|
182 for(i=REG_ESI;i<REG_ESP;i++) {
|
|
183 if (! regs[i]) { /* 使われていないなら */
|
|
184 regs[i]=1; /* そのレジスタを使うことを宣言し */
|
|
185 regv[i]=0;
|
|
186 return i; /* その場所を表す番号を返す */
|
|
187 }
|
|
188 }
|
|
189 return -1;
|
|
190 }
|
|
191
|
|
192 void
|
|
193 use_register(int virt, int real, int move)
|
|
194 {
|
|
195 int real_v;
|
|
196 char *move_op;
|
|
197 if (rname[virt]==real)
|
|
198 return;
|
|
199 real_v = virtual(real);
|
|
200 move_op = regs[real_v]?"\txchg %s,%s\n":"\tmovl %s,%s\n";
|
|
201 if (move || (regv[real_v])) {
|
|
202 printf(move_op,reg_name[rname[virt]],reg_name[real]);
|
|
203 }
|
|
204 rname[real_v] = rname[virt];
|
|
205 rname[virt] = real;
|
|
206 }
|
|
207
|
|
208 void
|
|
209 use_pointer(int virt, int move)
|
|
210 {
|
|
211 int i;
|
|
212 if (rname[virt]>=POINTER_REG)
|
|
213 return;
|
|
214 for(i=POINTER_REG;i<MAX_REGISTER;i++) {
|
|
215 if (!regs[virtual(i)]) {
|
|
216 use_register(virt,i,move);
|
|
217 return;
|
|
218 }
|
|
219 }
|
|
220 /* we prefer EBX */
|
|
221 use_register(virt,REG_EBX,move);
|
|
222 }
|
|
223
|
|
224 void
|
|
225 use_data_reg(int virt, int move)
|
|
226 {
|
|
227 int i;
|
|
228 if (rname[virt]<MAX_DATA_REG)
|
|
229 return;
|
|
230 for(i=0;i<MAX_DATA_REG;i++) {
|
|
231 if (!regs[virtual(i)]) {
|
|
232 use_register(virt,i,move);
|
|
233 return;
|
|
234 }
|
|
235 }
|
|
236 /* we prefer EBX */
|
|
237 use_register(virt,REG_EBX,move);
|
|
238 }
|
|
239
|
|
240
|
|
241 void
|
|
242 emit_push(void)
|
|
243 {
|
|
244 int new_reg;
|
|
245 new_reg = get_register();
|
|
246 if(new_reg<0) { /* もうレジスタがない */
|
|
247 reg_stack[reg_sp++] = -1;
|
|
248 printf("\tpushl %s\n",register_name(creg,0));
|
|
249 /* creg is used soon, don't regv[creg]=0 */
|
|
250 } else {
|
|
251 reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */
|
|
252 creg = new_reg;
|
|
253 regv[creg]=1;
|
|
254 }
|
|
255 }
|
|
256
|
|
257 int
|
|
258 emit_pop(int type)
|
|
259 {
|
|
260 int xreg;
|
|
261 if ((xreg=pop_register())==-1) {
|
|
262 if (type==POINTER_REG)
|
|
263 use_pointer(dreg,0);
|
|
264 else if (type==DATA_REG)
|
|
265 use_data_reg(dreg,0);
|
|
266 if (regv[dreg]) {
|
|
267 printf("# emit_pop dreg conflict\n");
|
|
268 }
|
|
269 printf("\tpopl %s\n",register_name(dreg,0));
|
|
270 xreg = dreg;
|
|
271 regv[xreg]=1;
|
|
272 }
|
|
273 return xreg;
|
|
274 }
|
|
275
|
|
276
|
|
277 void
|
|
278 code_gvar(int e1) {
|
|
279 printf("\tmovl $%s,%s\n",(char *)caddr(e1),register_name(creg,0));
|
|
280 }
|
|
281
|
|
282
|
|
283 void
|
|
284 code_rgvar(int e1) {
|
|
285 printf("\tmovl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
|
|
286 }
|
|
287
|
|
288 void
|
|
289 code_crgvar(e1){
|
|
290 printf("\tmovsbl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
|
|
291 }
|
|
292
|
|
293
|
|
294 void
|
|
295 code_lvar(int e2) {
|
|
296 printf("\tlea %d(%%ebp),%s\n",e2,register_name(creg,0));
|
|
297 }
|
|
298
|
|
299
|
|
300 void
|
|
301 code_register(int e2) {
|
|
302 printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0));
|
|
303 }
|
|
304
|
|
305
|
|
306 void
|
|
307 code_rlvar(int e2) {
|
|
308 printf("\tmovl %d(%%ebp),%s\n",e2,register_name(creg,0));
|
|
309 }
|
|
310
|
|
311
|
|
312 void
|
|
313 code_crlvar(int e2) {
|
62
|
314 printf("\tmovsbl %d(%%ebp),%s\n",e2,register_name(creg,0));
|
61
|
315 }
|
|
316
|
|
317
|
|
318 void
|
|
319 code_fname(char *e2) {
|
|
320 printf("\tmovl $%s,%s\n",e2,register_name(creg,0));
|
|
321 }
|
|
322
|
|
323
|
|
324 void
|
|
325 code_const(int e2) {
|
|
326 printf("\tmovl $%d,%s\n",e2,register_name(creg,0));
|
|
327 }
|
|
328
|
|
329
|
|
330 void
|
|
331 code_neg() {
|
|
332 printf("\tnegl %s\n", register_name(creg,0));
|
|
333 }
|
|
334
|
|
335
|
|
336 void
|
|
337 code_not() {
|
|
338 printf("\tnotl %s\n", register_name(creg,0));
|
|
339 }
|
|
340
|
|
341
|
|
342 void
|
|
343 code_lnot() {
|
|
344 char *xrn;
|
|
345 use_data_reg(creg,1);
|
|
346 xrn = register_name(creg,1);
|
|
347 printf("\tcmpl $0,%s\n", register_name(creg,0));
|
|
348 printf("\tsete %s\n", xrn);
|
|
349 printf("\tmovzbl %s,%s\n", xrn,register_name(creg,0));
|
|
350 }
|
|
351
|
|
352 void
|
|
353 code_preinc(int e1,int e2) {
|
|
354 char *xrn;
|
|
355 if (car(e2)==REGISTER) {
|
|
356 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
|
|
357 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
|
358 return;
|
|
359 }
|
|
360 g_expr(e2);
|
|
361 xrn = register_name(creg,0);
|
|
362 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
|
|
363 printf("\tmovl (%s),%s\n",xrn,xrn);
|
|
364 }
|
|
365
|
|
366
|
|
367 void
|
|
368 code_postinc(int e1,int e2) {
|
|
369 char *xrn;
|
|
370 if (car(e2)==REGISTER) {
|
|
371 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
|
372 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
|
|
373 return;
|
|
374 }
|
|
375 g_expr(e2);
|
|
376 emit_push();
|
|
377 xrn = register_name((e2=emit_pop(0)),0);
|
|
378 printf("\tmovl (%s),%s\n",xrn,register_name(creg,0));
|
|
379 printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
|
|
380 emit_pop_free(e2);
|
|
381 }
|
|
382
|
|
383
|
|
384 void
|
|
385 code_cpostinc(int e1,int e2) {
|
|
386 char *xrn;
|
|
387 if (car(e2)==REGISTER) {
|
|
388 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
|
389 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
|
|
390 return;
|
|
391 }
|
|
392 g_expr(e2);
|
|
393 emit_push();
|
|
394 xrn = register_name((e2=emit_pop(0)),1);
|
|
395 printf("\tmovsbl (%s),%s\n",xrn,register_name(creg,0));
|
|
396 printf("\tincl (%s)\n",xrn);
|
|
397 emit_pop_free(e2);
|
|
398 }
|
|
399
|
|
400
|
|
401 void
|
|
402 code_cpreinc(int e1,int e2) {
|
|
403 if (car(e2)==REGISTER) {
|
|
404 printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
|
|
405 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
|
406 return;
|
|
407 }
|
|
408 g_expr(e2);
|
|
409 printf("\tincl (%s)\n",register_name(creg,0));
|
|
410 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
|
|
411 }
|
|
412
|
|
413
|
|
414 void
|
|
415 code_cpostdec(int e1,int e2) {
|
|
416 if (car(e2)==REGISTER) {
|
|
417 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
|
418 printf("\tdecl %s\n",register_name(cadr(e2),0));
|
|
419 return;
|
|
420 }
|
|
421 g_expr(e2);
|
|
422 printf("\tmovsbl (%s),%s\n",register_name(creg,0),register_name(creg,0));
|
|
423 printf("\tdecl (%s)\n",register_name(creg,0));
|
|
424 }
|
|
425
|
|
426
|
|
427 void
|
|
428 code_cpredec(int e1,int e2) {
|
|
429 if (car(e2)==REGISTER) {
|
|
430 printf("\tdecl %s\n",register_name(cadr(e2),0));
|
|
431 printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
|
|
432 return;
|
|
433 }
|
|
434 g_expr(e2);
|
|
435 emit_push();
|
|
436 e2 = emit_pop(0);
|
|
437 printf("\tdecl (%s)\n",register_name(e2,0));
|
|
438 printf("\tmovsbl (%s),%s\n",register_name(e2,0),register_name(creg,0));
|
|
439 emit_pop_free(e2);
|
|
440 }
|
|
441
|
|
442
|
|
443 void
|
|
444 code_return() {
|
|
445 printf("\tleal _%d,%s\n",retcont,register_name(creg,0));
|
|
446 }
|
|
447
|
|
448
|
|
449 void
|
|
450 code_environment() {
|
|
451 printf("\tmovl %%ebp,%s\n",register_name(creg,0));
|
|
452 }
|
|
453
|
|
454
|
|
455 void
|
|
456 code_bool(int e1) {
|
|
457 char *xrn;
|
|
458 int e2,e3;
|
|
459 b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */
|
|
460 xrn = register_name(creg,0);
|
|
461 printf("\txorl %s,%s\n",xrn,xrn);
|
|
462 jmp(e3=fwdlabel());
|
|
463 fwddef(e2);
|
|
464 printf("\tmovl $1,%s\n",xrn);
|
|
465 fwddef(e3);
|
|
466 }
|
|
467
|
|
468 char *
|
|
469 code_gt(int cond) {
|
|
470 return (cond?"g":"le");
|
|
471 }
|
|
472
|
|
473 char *
|
|
474 code_ugt(int cond) {
|
|
475 return (cond?"a":"be");
|
|
476 }
|
|
477
|
|
478 char *
|
|
479 code_ge(int cond) {
|
|
480 return (cond?"ge":"l");
|
|
481 }
|
|
482
|
|
483 char *
|
|
484 code_uge(int cond) {
|
|
485 return (cond?"ae":"b");
|
|
486 }
|
|
487
|
|
488 char *
|
|
489 code_eq(int cond) {
|
|
490 return (cond?"e":"ne");
|
|
491 }
|
|
492
|
|
493 void
|
|
494 code_cmp_crgvar(int e1) {
|
|
495 printf("\tcmpb $0,%s\n",(char *)caddr(e1));
|
|
496 }
|
|
497
|
|
498
|
|
499 void
|
|
500 code_cmp_crlvar(int e1) {
|
|
501 printf("\tcmpb $0,%d(%%ebp)\n",e1);
|
|
502 }
|
|
503
|
|
504
|
|
505 void
|
|
506 code_cmp_rgvar(int e1) {
|
|
507 printf("\tcmpl $0,%s\n",(char *)caddr(e1));
|
|
508 }
|
|
509
|
|
510
|
|
511 void
|
|
512 code_cmp_rlvar(int e1) {
|
|
513 printf("\tcmpl $0,%d(%%ebp)\n",e1);
|
|
514 }
|
|
515
|
|
516
|
|
517 void
|
|
518 code_cmp_register(int e2) {
|
|
519 printf("\tcmpl $0,%s\n",register_name(e2,0));
|
|
520 }
|
|
521
|
|
522
|
|
523 void
|
|
524 ascii(char *s)
|
|
525 {
|
|
526 printf("\t.string \"");
|
|
527 while(*s) {
|
|
528 if (*s=='\n')
|
|
529 printf("%cn",92);
|
|
530 else if (*s<' ')
|
|
531 printf("%c%03o",92,*s);
|
|
532 else if (*s==34)
|
|
533 printf("%c%c",92,34);
|
|
534 else
|
|
535 printf("%c",*s);
|
|
536 s++;
|
|
537 }
|
|
538 printf("%c\n",34);
|
|
539 }
|
|
540
|
|
541 void
|
|
542 string(int e1)
|
|
543 {
|
|
544 char *s;
|
|
545 int i,lb;
|
|
546
|
|
547 if (0) {
|
|
548 s=(char *)cadr(e1);
|
|
549 lb=fwdlabel();
|
|
550 printf("\tjmp _%d\n",lb);
|
|
551 i=backdef();
|
|
552 ascii(s);
|
|
553 printf("\t.align 2\n");
|
|
554 fwddef(lb);
|
|
555 printf("\tlea _%d,%s\n",i,register_name(creg,0));
|
|
556 } else {
|
|
557 s=(char *)cadr(e1);
|
|
558 printf(".section\t.rodata\n");
|
|
559 lb=fwdlabel();
|
|
560 printf("_%d:\n",lb);
|
|
561 ascii(s);
|
|
562 if (output_mode==TEXT_EMIT_MODE) {
|
|
563 printf(".text\n");
|
|
564 } else {
|
|
565 text_mode();
|
|
566 }
|
|
567 printf("\tlea _%d,%s\n",lb,register_name(creg,0));
|
|
568 }
|
|
569 }
|
|
570
|
|
571 #define MAX_COPY_LEN 20
|
|
572
|
|
573 void
|
|
574 emit_copy(int from,int to,int length,int offset,int value,int det)
|
|
575 {
|
|
576 int fix = 0;
|
|
577 /* length <0 means upward direction copy */
|
|
578 switch (length) {
|
|
579 case 0: break;
|
|
580 case 1: case -1:
|
|
581 printf("\tmovb %d(%s),%s\n",offset,
|
|
582 register_name(from,0), reg_name_l[rname[dreg]] );
|
|
583 printf("\tmovb %s,%d(%s)\n",reg_name_l[rname[dreg]] ,offset,
|
|
584 register_name(to,0));
|
|
585 break;
|
|
586 case 2: case -2:
|
|
587 printf("\tmovw %d(%s),%s\n",offset,
|
|
588 register_name(from,0), reg_name_w[rname[dreg]] );
|
|
589 printf("\tmovw %s,%d(%s)\n",reg_name_w[rname[dreg]] ,offset,
|
|
590 register_name(to,0));
|
|
591 break;
|
|
592 case 4: case -4:
|
|
593 printf("\tmovl %d(%s),%s\n",offset,
|
|
594 register_name(from,0), register_name(dreg,0));
|
|
595 printf("\tmovl %s,%d(%s)\n",register_name(dreg,0), offset,
|
|
596 register_name(to,0));
|
|
597 break;
|
|
598 default:
|
|
599 if (-MAX_COPY_LEN<length && length <0) {
|
|
600 for(;length<=4;length+=4,offset-=4)
|
|
601 emit_copy(from,to,4,offset,0,det);
|
|
602 for(;length<=2;length+=2,offset-=2)
|
|
603 emit_copy(from,to,2,offset,0,det);
|
|
604 if(length>0)
|
|
605 emit_copy(from,to,length,offset,0,det);
|
|
606 break;
|
|
607 } else if (length <=MAX_COPY_LEN) {
|
|
608 for(;length>=4;length-=4,offset+=4)
|
|
609 emit_copy(from,to,4,offset,0,det);
|
|
610 for(;length>=2;length-=2,offset+=2)
|
|
611 emit_copy(from,to,2,offset,0,det);
|
|
612 if(length>0)
|
|
613 emit_copy(from,to,length,offset,0,det);
|
|
614 break;
|
|
615 }
|
|
616 if (det) {
|
|
617 /*
|
|
618 call bcopy
|
|
619 g_expr(list3(FUNCTION,,);
|
|
620 break;
|
|
621 */
|
|
622 }
|
|
623 use_register(from,REG_ESI,1);
|
|
624 use_register(to, REG_EDI,1);
|
|
625 use_register(dreg,REG_ECX,0);
|
|
626 if (length<0) {
|
|
627 printf("\tmovl $%d,%%ecx\n",-length/4);
|
|
628 printf("\taddl $%d,%%esi\n",-length);
|
|
629 printf("\taddl $%d,%%edi\n",-length);
|
|
630 printf("\tstd\n\trep\n\tmovsl\n");
|
|
631 if(length%4) {
|
|
632 emit_copy(from,to,length,offset+length/4,0,det);
|
|
633 }
|
|
634 } else {
|
|
635 printf("\tmovl $%d,%%ecx\n",length/4);
|
|
636 fix = (length/4)*4;
|
|
637 printf("\tcld\n\trep\n\tmovsl\n");
|
|
638 if(length%4) {
|
|
639 emit_copy(from,to,length,offset+length/4,0,det);
|
|
640 }
|
|
641 }
|
|
642 }
|
|
643 if (value) {
|
|
644 /* creg must point top of the destination data */
|
|
645 /* this code is necessary for the value of assignment or function call */
|
|
646 /* otherwise we don't need this */
|
|
647 if (fix) printf("\tsubl $%d,%s\n",fix,register_name(to,0));
|
|
648 if(creg!=to) {
|
|
649 if (to==dreg)
|
|
650 printf("\tmovl %s,%s\n",register_name(to,0),register_name(creg,0));
|
|
651 else {
|
|
652 free_register(creg); creg=to;
|
|
653 }
|
|
654 }
|
|
655 }
|
|
656 regv[from]=regv[to]=regv[dreg]=0;
|
|
657 regv[creg]=1;
|
|
658 }
|
|
659
|
|
660 int
|
|
661 struct_push(int e4,int t)
|
|
662 {
|
81
|
663 int length,xreg,save,lreg,count;
|
61
|
664 g_expr(e4);
|
|
665 length=size(t);
|
|
666 if(length%size_of_int) {
|
|
667 length += size_of_int - (length%size_of_int);
|
|
668 }
|
81
|
669 for(count=0;length<MAX_COPY_LEN;count++,length-=size_of_int) {
|
|
670 if (length==0) return count;
|
|
671 else {
|
|
672 printf("\tpushl %d(%s)\n",
|
|
673 length-size_of_int,register_name(creg,0));
|
|
674 }
|
61
|
675 }
|
|
676 printf("\tsubl $%d,%%esp\n",length);
|
|
677 if (register_full()) {
|
|
678 save = 1;
|
|
679 for(lreg=0;lreg==creg||lreg==dreg;lreg++);
|
|
680 printf("\tpushl %s\n",register_name(lreg,0));
|
|
681 xreg = lreg; regv[xreg]=0;
|
|
682 } else {
|
|
683 save=0;
|
|
684 xreg = get_register();
|
|
685 }
|
|
686 if (save)
|
|
687 printf("\tlea %d(%%esp),%s\n",size_of_int,register_name(xreg,0));
|
|
688 else
|
|
689 printf("\tmovl %%esp,%s\n",register_name(xreg,0));
|
|
690 regv[xreg]=1;
|
|
691 /* downward direction copy */
|
|
692 emit_copy(creg,xreg,length,0,0,1);
|
|
693 /* we have value in creg, it may be changed */
|
|
694 if (save) {
|
|
695 if(creg==xreg) {
|
|
696 creg = get_register(); /* creg is freed in emit_copy */
|
|
697 }
|
|
698 printf("\tpopl %s\n",register_name(xreg,0));
|
|
699 regv[xreg]=1;
|
|
700 } else
|
|
701 free_register(xreg);
|
|
702 return length/size_of_int;
|
|
703 }
|
|
704
|
|
705 void
|
|
706 function(int e1)
|
|
707 {
|
|
708 int e2,e3,e4,e5,nargs,t;
|
|
709 NMTBL *n;
|
|
710 int save,saved;
|
|
711 if (free_register_count()<1) {
|
|
712 for(save = 0;save==dreg||save==creg;save++);
|
|
713 printf("\tpushl %s\n",register_name(save,0));
|
|
714 saved = 1;
|
|
715 } else {
|
|
716 save = get_register();
|
|
717 saved = 0;
|
|
718 }
|
|
719 regv[save]=0;
|
|
720 e2 = cadr(e1);
|
|
721 nargs = 0;
|
|
722 for (e3 = caddr(e1); e3; e3 = cadr(e3)) {
|
|
723 t=caddr(e3);
|
|
724 n=(NMTBL *)(e5=(cadr(e4 = car(e3))));
|
|
725 if(scalar(t)) {
|
|
726 g_expr(e4);
|
|
727 printf("\tpushl %s\n",register_name(creg,0));
|
|
728 } else if (car(t)==STRUCT||car(t)==UNION) {
|
|
729 nargs += struct_push(e4,t);
|
|
730 continue;
|
|
731 } else {
|
|
732 error(TYERR);
|
|
733 }
|
|
734 ++nargs;
|
|
735 }
|
|
736 if (car(e2) == FNAME) {
|
|
737 n=(NMTBL *)cadr(e2);
|
78
|
738 regv[creg]=0;
|
|
739 use_register(creg,REG_EAX,0); /* will be destroyed */
|
61
|
740 } else {
|
|
741 g_expr(e2);
|
78
|
742 regv[creg]=1;
|
|
743 use_register(creg,REG_EAX,1); /* will be destroyed */
|
61
|
744 }
|
|
745
|
|
746 /* we don't have to save creg nor dreg */
|
|
747 regs[creg]=0; regs[dreg]=0;
|
78
|
748 regv[dreg]= regv[save]= 0;
|
61
|
749 use_register(dreg,REG_EDX,0); /* will be destroyed */
|
|
750 use_register(save,REG_ECX,0); /* will be destroyed */
|
|
751 regs[creg]=1; regs[dreg]=1;
|
|
752
|
|
753 if (car(e2) == FNAME) {
|
|
754 printf("\tcall\t%s\n",n->nm);
|
|
755 } else {
|
|
756 printf("\tcall\t*%s\n",register_name(creg,0));
|
|
757 }
|
|
758 if (nargs) printf("\taddl $%d,%%esp\n",size_of_int*nargs);
|
|
759 if (saved) {
|
|
760 printf("\tpopl %s\n",register_name(save,0));
|
|
761 } else {
|
|
762 free_register(save);
|
|
763 }
|
|
764 regv[save]=0;
|
|
765 regv[creg]=1;
|
|
766 }
|
|
767
|
|
768 void
|
|
769 code_frame_pointer(int e3) {
|
|
770 printf("\tmovl %s,%%ebp\n",register_name(e3,0));
|
|
771 }
|
|
772
|
|
773
|
|
774 void
|
62
|
775 code_fix_frame_pointer(int disp_offset) {
|
61
|
776 printf("\tlea %d(%%ebp),%%ebp\n",disp_offset);
|
|
777 }
|
|
778
|
|
779
|
|
780 void
|
|
781 code_jmp(char *s) {
|
|
782 printf("\tjmp %s\n",s);
|
|
783 }
|
|
784
|
|
785
|
|
786 void
|
|
787 code_indirect_jmp(int e2) {
|
|
788 printf("\tjmp *%s\n",register_name(e2,0));
|
|
789 }
|
|
790
|
|
791 void
|
|
792 rindirect(int e1) /* *(p +5 ) */
|
|
793 {
|
|
794 char *op;
|
|
795 int e2,e3,byte;
|
|
796
|
|
797 op = ((byte = (car(e1) == CRINDIRECT)) ? "movsbl" : "movl");
|
|
798 e3 = cadr(e2 = cadr(e1));
|
|
799 g_expr(e2);
|
|
800 printf("\t%s (%s),%s\n",op,register_name(creg,0),register_name(creg,0));
|
|
801 }
|
|
802
|
|
803 char *
|
|
804 move(int byte)
|
|
805 {
|
|
806 return byte?"movb":"movl";
|
|
807 }
|
|
808
|
|
809 void
|
|
810 code_assign_gvar(int e2,int byte) {
|
|
811 if (byte) use_data_reg(creg,1);
|
|
812 printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),(char *)caddr(e2));
|
|
813 }
|
|
814
|
|
815 void
|
|
816 code_assign_lvar(int e2,int byte) {
|
|
817 if (byte) use_data_reg(creg,1);
|
|
818 printf("\t%s %s,%d(%%ebp)\n",move(byte),register_name(creg,byte),e2);
|
|
819 }
|
|
820
|
|
821 void
|
|
822 code_assign_register(int e2,int byte) {
|
|
823 printf("\tmovl %s,%s\n",register_name(creg,0),register_name(e2,0));
|
|
824 }
|
|
825
|
|
826 void
|
|
827 code_assign(int e2,int byte) {
|
|
828 printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte),register_name(e2,0));
|
|
829 }
|
|
830
|
|
831
|
|
832 void
|
|
833 code_register_assop(int e2,int op,int byte) {
|
|
834 int reg;
|
|
835 int xreg = creg;
|
|
836 creg = reg = e2;
|
|
837 tosop(op,xreg);
|
|
838 creg = xreg;
|
|
839 printf("\tmovl %s,%s\n",register_name(reg,0),register_name(creg,0));
|
|
840 }
|
|
841
|
|
842
|
|
843 void
|
|
844 code_assop(int op,int byte) {
|
|
845 char *xrn;
|
|
846 int xreg;
|
|
847 int edx = edx_setup();
|
|
848 xrn = register_name(xreg = emit_pop(0),0); /* pop e3 value */
|
|
849 regv[xreg]=regs[xreg]=1;
|
|
850 printf("\tmovl %s,%s # assop \n",register_name(creg,0),register_name(edx,0));
|
|
851 regv[edx]=1;
|
|
852 ld_indexx(byte,0,edx);
|
|
853 tosop(op,xreg);
|
|
854 printf("\t%s %s,(%s)\n",byte ? "movb" : "movl",register_name(creg,byte),register_name(edx,0));
|
|
855 edx_cleanup();
|
|
856 emit_pop_free(xreg);
|
|
857 }
|
|
858
|
|
859
|
|
860 void
|
|
861 tosop(int op,int oreg)
|
|
862 {
|
|
863 int dx;
|
|
864 char *orn,*crn;
|
|
865
|
|
866 switch(op) {
|
|
867 case LSHIFT:
|
|
868 case ULSHIFT:
|
|
869 shift("sall",oreg);
|
|
870 return;
|
|
871 case RSHIFT:
|
|
872 shift("sarl",oreg);
|
|
873 return;
|
|
874 case URSHIFT:
|
|
875 shift("shrl",oreg);
|
|
876 return;
|
|
877 }
|
|
878 if(oreg==-1) {
|
|
879 printf("\tpopl %s\n",register_name(dreg,0));
|
|
880 oreg = dreg;
|
|
881 regv[dreg]=1;
|
|
882 }
|
|
883 regv[oreg]=1; regs[oreg]=1;
|
|
884 orn = register_name(oreg,0);
|
|
885 crn = register_name(creg,0);
|
|
886 switch(op) {
|
|
887 case ADD:
|
|
888 printf("\taddl %s,%s\n",orn,crn);
|
|
889 break;
|
|
890 case SUB:
|
|
891 printf("\tsubl %s,%s\n",orn,crn);
|
|
892 break;
|
|
893 case BAND:
|
|
894 printf("\tandl %s,%s\n",orn,crn);
|
|
895 break;
|
|
896 case EOR:
|
|
897 printf("\txorl %s,%s\n",orn,crn);
|
|
898 break;
|
|
899 case BOR:
|
|
900 printf("\torl %s,%s\n",orn,crn);
|
|
901 break;
|
|
902 case MUL:
|
|
903 case UMUL:
|
|
904 printf("\t%s %s,%s\n","imull",orn,crn);
|
|
905 break;
|
|
906 case DIV:
|
|
907 case UDIV:
|
|
908 use_register(creg,REG_EAX,1);
|
|
909 edx_setup();
|
|
910 orn = register_name(oreg,0);
|
|
911 if (op==DIV)
|
|
912 printf("\tcltd\n\tdivl %s\n",orn);
|
|
913 else
|
|
914 printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
|
|
915 edx_cleanup();
|
|
916 break;
|
|
917 case MOD:
|
|
918 case UMOD:
|
|
919 use_register(creg,REG_EAX,1);
|
|
920 edx_setup();
|
|
921 orn = register_name(oreg,0);
|
|
922 if (op==DIV)
|
|
923 printf("\tcltd\n\tdivl %s\n",orn);
|
|
924 else
|
|
925 printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
|
|
926 dx = virtual(REG_EDX);
|
|
927 if (dx!=creg) {
|
|
928 rname[dx]=rname[creg];
|
|
929 rname[creg]=REG_EDX;
|
|
930 }
|
|
931 edx_cleanup();
|
|
932 break;
|
|
933 }
|
|
934 if (oreg!=dreg&&oreg>=0)
|
|
935 free_register(oreg);
|
|
936 }
|
|
937
|
|
938 static int edx_stack=0;
|
|
939
|
|
940 int
|
|
941 edx_setup()
|
|
942 {
|
|
943 int edx_save;
|
|
944 /* make real EDX register empty */
|
|
945 if (free_register_count()<1) {
|
|
946 for(edx_save = 0;edx_save==dreg||edx_save==creg;edx_save++);
|
|
947 printf("\tpushl %s\n",register_name(edx_save,0));
|
|
948 edx_stack = list3(edx_save,edx_stack,0);
|
|
949 } else {
|
|
950 edx_save = get_register();
|
|
951 edx_stack = list3(edx_save,edx_stack,1);
|
|
952 }
|
|
953 regv[edx_save]=0;
|
|
954 use_register(edx_save,REG_EDX,0);
|
|
955 return edx_save;
|
|
956 }
|
|
957
|
|
958
|
|
959 void
|
|
960 edx_cleanup()
|
|
961 {
|
|
962 if (caddr(edx_stack)==0) {
|
|
963 printf("\tpopl %s\n",register_name(car(edx_stack),0));
|
|
964 } else
|
|
965 free_register(car(edx_stack));
|
|
966 edx_stack = cadr(edx_stack);
|
|
967 }
|
|
968
|
|
969 void
|
|
970 shift(char *op, int reg)
|
|
971 {
|
|
972 if (reg>=0) {
|
|
973 use_register(reg,REG_ECX,1);
|
|
974 } else {
|
|
975 use_register(dreg,REG_ECX,0);
|
|
976 printf("\tpopl %%ecx\n");
|
|
977 }
|
|
978 printf("\t%s %%cl,%s\n",op,register_name(creg,0));
|
|
979 }
|
|
980
|
|
981 void
|
|
982 ld_indexx(int byte, int n, int xreg)
|
|
983 {
|
|
984 char *op;
|
|
985
|
|
986 op = byte ? "movsbl" : "movl";
|
|
987 if (n)
|
|
988 printf("\t%s %d(%s),%s\n",op,n,register_name(xreg,0),register_name(creg,byte));
|
|
989 else
|
|
990 printf("\t%s (%s),%s\n",op,register_name(xreg,0),register_name(creg,byte));
|
|
991 }
|
|
992
|
|
993 void
|
|
994 cmpdimm(int e, int csreg)
|
|
995 {
|
|
996 /* used in dosiwtch() */
|
66
|
997 if(chk) return;
|
61
|
998 use_register(creg,csreg,0);
|
|
999 printf("\tcmpl $%d,%s\n",e,register_name(creg,0));
|
|
1000 }
|
|
1001
|
|
1002 void
|
66
|
1003 code_opening(char *filename)
|
61
|
1004 {
|
|
1005 printf("\t.file \"%s\"\n",filename);
|
|
1006 printf("\t.version\t\"01.01\"\n");
|
66
|
1007 /* printf("gcc2_compiled.:\n"); */
|
61
|
1008 printf(".text\n");
|
|
1009 }
|
|
1010
|
|
1011 void
|
66
|
1012 code_closing()
|
61
|
1013 {
|
78
|
1014 global_table();
|
61
|
1015 printf("\t.ident \"Micro-C compiled\"\n");
|
|
1016 }
|
|
1017
|
|
1018 void
|
|
1019 rexpr(int e1, int l1, char *s)
|
|
1020 {
|
|
1021 g_expr(list3(SUB,cadr(e1),caddr(e1)));
|
|
1022 printf("\tj%s\t_%d\n",s,l1);
|
|
1023 }
|
|
1024
|
|
1025 void
|
|
1026 jcond(int l, char cond)
|
|
1027 {
|
66
|
1028 if (chk) return;
|
61
|
1029 printf("\tj%s\t_%d\n",cond?"ne":"e",l);
|
|
1030 }
|
|
1031
|
|
1032 void
|
|
1033 jmp(int l)
|
|
1034 {
|
|
1035 control=0;
|
66
|
1036 if (chk) return;
|
61
|
1037 printf("\tjmp\t_%d\n",l);
|
|
1038 /* align? */
|
|
1039 /*
|
|
1040 this is not allowed because of ? operator
|
|
1041 regv[creg]=regv[dreg]=0;
|
|
1042 use_register(creg,REG_EAX,0);
|
|
1043 use_register(dreg,REG_EBX,0);
|
|
1044 */
|
|
1045 }
|
|
1046
|
|
1047 void
|
|
1048 gen_comment(char *s)
|
|
1049 {
|
66
|
1050 if (chk) return;
|
|
1051 printf("## %s",s);
|
61
|
1052 }
|
|
1053
|
|
1054
|
|
1055 void
|
|
1056 code_enter(char *name)
|
|
1057 {
|
|
1058 printf("\t.align 4\n");
|
|
1059 if (stmode!=STATIC)
|
|
1060 printf(".globl %s\n",name);
|
|
1061 printf("\t.type\t%s,@function\n",name);
|
|
1062 printf("%s:\n",name);
|
|
1063 }
|
|
1064
|
77
|
1065
|
61
|
1066 void
|
|
1067 code_enter1(int args)
|
|
1068 {
|
|
1069 code_disp_label=fwdlabel();
|
|
1070 printf("\tlea _%d(%%ebp),%%esp\n",code_disp_label);
|
|
1071
|
|
1072 printf("## args %d disp %d code_arg_offset=%d code_disp_offset=%d\n",args,disp,code_arg_offset,code_disp_offset);
|
|
1073 }
|
|
1074
|
|
1075 void
|
|
1076 code_leave(char *name)
|
|
1077 {
|
63
|
1078 disp&= -size_of_int;
|
61
|
1079 printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset);
|
|
1080 printf("_%d:\n",labelno);
|
|
1081 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
|
|
1082 local_table();
|
|
1083 labelno++;
|
|
1084 free_all_register();
|
|
1085 }
|
|
1086
|
|
1087 void
|
|
1088 enter(char *name)
|
|
1089 {
|
|
1090 printf("\t.align 2\n");
|
|
1091 if (stmode!=STATIC)
|
|
1092 printf(".globl %s\n",name);
|
|
1093 printf("%s:\n",name);
|
|
1094 printf("\t.type\t%s,@function\n",name);
|
|
1095 printf("\tpushl %%ebp\n");
|
|
1096 printf("\tmovl %%esp,%%ebp\n");
|
|
1097 printf("\tpushl %%ebx\n");
|
|
1098 printf("\tpushl %%esi\n");
|
|
1099 printf("\tpushl %%edi\n");
|
|
1100 }
|
|
1101
|
|
1102 void
|
|
1103 enter1()
|
|
1104 {
|
|
1105 func_disp_label=fwdlabel();
|
|
1106 printf("\tlea _%d(%%ebp),%%esp\n",func_disp_label);
|
|
1107 /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
|
|
1108 }
|
|
1109
|
|
1110 void
|
|
1111 leave(int control, char *name)
|
|
1112 {
|
|
1113 if (control)
|
|
1114 use_register(creg,REG_EAX,1);
|
|
1115 if (retcont) {
|
|
1116 if (control)
|
|
1117 jmp(retlabel);
|
|
1118 fwddef(retcont);
|
|
1119 use_register(creg,REG_EAX,0);
|
|
1120 printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0));
|
|
1121 /* printf("\tleave\n"); */
|
|
1122 }
|
|
1123 fwddef(retlabel);
|
|
1124 /* use_register(creg,REG_EAX,0); too late */
|
|
1125 /* if(disp) printf("\taddl $%d,%%esp\n",-disp); */
|
63
|
1126 disp&= -size_of_int;
|
|
1127
|
61
|
1128 printf("\tlea %d(%%ebp),%%esp\n",disp_offset);
|
|
1129 printf("\tpopl %%edi\n");
|
|
1130 printf("\tpopl %%esi\n");
|
|
1131 printf("\tpopl %%ebx\n");
|
|
1132 printf("\tleave\n");
|
|
1133 printf("\tret\n");
|
|
1134 printf("\t.set _%d,%d\n",func_disp_label,disp+disp_offset);
|
|
1135 printf("_%d:\n",labelno);
|
|
1136 printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
|
|
1137 local_table();
|
|
1138 labelno++;
|
|
1139 free_all_register();
|
|
1140 }
|
|
1141
|
|
1142
|
|
1143 void
|
|
1144 code_set_fixed_creg(int mode) {
|
|
1145 use_register(creg,REG_EAX,mode);
|
|
1146 }
|
|
1147
|
|
1148 void
|
|
1149 gen_gdecl(char *n, int gpc)
|
|
1150 {
|
|
1151 /*
|
|
1152 if (stmode!=STATIC)
|
|
1153 printf(".globl %s\n",n);
|
|
1154 */
|
|
1155 }
|
|
1156
|
|
1157 void
|
|
1158 align(int t)
|
|
1159 {
|
|
1160 if (t!=CHAR) {
|
|
1161 if (data_alignment & 1)
|
|
1162 printf("\t.align 2\n");
|
|
1163 data_alignment = 0;
|
|
1164 }
|
|
1165 }
|
|
1166
|
|
1167 void
|
|
1168 emit_data(int e, int t, NMTBL *n)
|
|
1169 {
|
|
1170 int l;
|
|
1171 char *name;
|
|
1172 name = n->nm;
|
|
1173 if(mode!=GDECL) {
|
|
1174 error(-1); return;
|
|
1175 }
|
66
|
1176 if (chk) return;
|
61
|
1177 if (n->dsp != -1) {
|
|
1178 n->dsp = -1; /* initiallized flag */
|
|
1179 printf(".globl\t%s\n",name);
|
|
1180 data_mode(name);
|
|
1181 align(t);
|
|
1182 printf("%s:\n",name);
|
|
1183 } else {
|
|
1184 data_mode(0);
|
|
1185 }
|
|
1186 if(car(e)==CONST) {
|
|
1187 if (t==CHAR) {
|
|
1188 printf("\t.byte %d\n",cadr(e));
|
|
1189 if (data_alignment>0)
|
|
1190 data_alignment++;
|
|
1191 gpc += 1;
|
|
1192 } else {
|
|
1193 printf("\t.long %d\n",cadr(e));
|
|
1194 gpc += size_of_int;
|
|
1195 }
|
|
1196 } else if(t!=CHAR) {
|
|
1197 gpc += size_of_int;
|
|
1198 if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
|
|
1199 printf("\t.long %s\n",(char *)caddr(cadr(e)));
|
|
1200 } else if(car(e)==FNAME) {
|
|
1201 printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
|
|
1202 } else if(car(e)==STRING) {
|
|
1203 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) {
|
|
1204 l = fwdlabel();
|
|
1205 printf("\t.long _%d\n",l);
|
|
1206 printf(".section\t.rodata\n");
|
|
1207 printf("_%d:\n",l);
|
|
1208 output_mode = RODATA_EMIT_MODE;
|
|
1209 }
|
|
1210 ascii((char *)cadr(e));
|
|
1211 } else error(TYERR);
|
|
1212 }
|
|
1213 }
|
|
1214
|
|
1215 void
|
|
1216 emit_data_closing(NMTBL *n)
|
|
1217 {
|
|
1218 int lb;
|
66
|
1219 if (chk) return;
|
61
|
1220 if (mode==GDECL) {
|
|
1221 data_mode(0);
|
|
1222 lb=fwdlabel();
|
|
1223 printf("_%d:\n",lb);
|
|
1224 printf("\t.size\t%s,_%d-%s\n",n->nm,lb,n->nm);
|
|
1225 }
|
|
1226 }
|
|
1227
|
|
1228 void
|
|
1229 global_table(void)
|
|
1230 {
|
|
1231 NMTBL *n;
|
|
1232 int init;
|
|
1233 init=0;
|
|
1234 for(n=ntable;n < &ntable[GSYMS];n++) {
|
|
1235 if (n->sc == GVAR && n->dsp != -1) {
|
|
1236 /* n->dsp = -1 means initialized global */
|
|
1237 if (init==0) {
|
|
1238 data_mode(0);
|
|
1239 init=1;
|
|
1240 }
|
|
1241 printf(".comm %s,%d\n",n->nm,size(n->ty));
|
|
1242 }
|
|
1243 }
|
|
1244 }
|
|
1245
|
|
1246 void
|
|
1247 local_table(void)
|
|
1248 {
|
|
1249 NMTBL *n;
|
|
1250 int init;
|
|
1251 init=0;
|
|
1252 /* static local variables */
|
|
1253 for(n=ntable+GSYMS;n < &ntable[GSYMS+LSYMS];n++) {
|
|
1254 if (n->sc == GVAR) {
|
|
1255 if (init==0) {
|
|
1256 data_mode(0);
|
|
1257 init=1;
|
|
1258 }
|
|
1259 printf(".lcomm %s,%d\n",n->nm,size(n->ty));
|
|
1260 }
|
|
1261 }
|
|
1262 }
|
|
1263
|
|
1264 void
|
|
1265 text_mode(void)
|
|
1266 {
|
|
1267 if (output_mode!=TEXT_EMIT_MODE) {
|
|
1268 printf(".text\n");
|
|
1269 printf("\t.align 2\n");
|
|
1270 output_mode = TEXT_EMIT_MODE;
|
|
1271 }
|
|
1272 }
|
|
1273
|
|
1274 void
|
|
1275 data_mode(char *name)
|
|
1276 {
|
|
1277 if (output_mode!=DATA_EMIT_MODE) {
|
|
1278 printf(".data\n");
|
|
1279 output_mode = DATA_EMIT_MODE;
|
|
1280 }
|
|
1281 if (name)
|
|
1282 printf("\t.type\t%s,@object\n",name);
|
|
1283 }
|
|
1284
|
|
1285 int
|
|
1286 lvar(int l)
|
|
1287 {
|
|
1288 if (fnptr->sc==CODE) {
|
|
1289 return l+code_disp_offset;
|
|
1290 } else if (l<0) {
|
|
1291 return l+disp_offset;
|
|
1292 } else {
|
|
1293 return l+arg_offset;
|
|
1294 }
|
|
1295 }
|
|
1296
|
81
|
1297 /* floating point */
|
|
1298
|
|
1299
|
|
1300 void code_cmp_drgvar(int e)
|
|
1301 { }
|
|
1302
|
|
1303
|
|
1304 void code_cmp_drlvar(int e)
|
|
1305 { }
|
|
1306
|
|
1307
|
|
1308 void code_dassign_gvar(int e2,int byte)
|
|
1309 { }
|
|
1310
|
|
1311
|
|
1312 void code_dassign_lvar(int e,int byte)
|
|
1313 { }
|
|
1314
|
|
1315 void code_dassign(int e)
|
|
1316 { }
|
|
1317
|
|
1318
|
|
1319 void code_dconst(int e2)
|
|
1320 { }
|
|
1321
|
|
1322
|
|
1323 void code_dneg()
|
|
1324 { }
|
|
1325
|
|
1326
|
|
1327 void code_drgvar(int e1)
|
|
1328 { }
|
|
1329
|
|
1330
|
|
1331 void code_drlvar(int e1)
|
|
1332 { }
|
|
1333
|
|
1334
|
|
1335 void code_frgvar(int e1)
|
|
1336 { }
|
|
1337
|
|
1338
|
|
1339 void code_frlvar(int e1)
|
|
1340 { }
|
|
1341
|
|
1342
|
|
1343 void dtosop(int e,int e1)
|
|
1344 { }
|
|
1345
|
|
1346 int dpop_register()
|
|
1347 { return 1;}
|
|
1348
|
|
1349 int emit_dpop(int e1)
|
|
1350 { return 1;}
|
|
1351
|
|
1352 void emit_dpop_free(int e1)
|
|
1353 { }
|
|
1354
|
|
1355 void emit_dpush()
|
|
1356 { }
|
|
1357
|
|
1358
|
|
1359
|
61
|
1360 /* end */
|