Mercurial > hg > CbC > old > device
changeset 628:c9b67b1c42f5
Intel Mac continue...
author | kono |
---|---|
date | Tue, 10 Oct 2006 16:53:54 +0900 |
parents | 65eb070e731c |
children | d3067773659c |
files | mc-code-ia32.c |
diffstat | 1 files changed, 158 insertions(+), 95 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-ia32.c Tue Oct 10 02:16:05 2006 +0900 +++ b/mc-code-ia32.c Tue Oct 10 16:53:54 2006 +0900 @@ -390,7 +390,7 @@ return i; } -#define is_data_reg(reg) (1<=reg&®<=4) +#define is_data_reg(reg) (REG_EAX<=reg&®<=REG_EDX) #define is_pointer_reg(reg) (REG_ESI<=reg&®<=REG_EBP) static int @@ -420,9 +420,14 @@ int i = creg; int ptreg =0; if (is_pointer_reg(creg)) { - free_register(ptreg=creg); creg = 0; + free_register(ptreg=creg); + creg = 0; } - if (!i||!ireg||!is_int_reg(i)) { + if (is_pointer_reg(ireg)) { + free_register(ireg); + ireg = 0; + } + if (!i||!ireg||!is_data_reg(i)) { if (lreg) { if (regs[lreg]) free_register(lreg); lreg = 0; } if (!ireg) { ireg = get_data_register(); @@ -430,7 +435,7 @@ i = ireg; } if (!regs[i]) regs[i]=USING_REG; - creg = i; + creg = ireg = i; if (ptreg && keep) { printf("\tmovl %s,%s\n",reg_name[ptreg],reg_name[creg]); } @@ -442,7 +447,9 @@ { if (!is_int_reg(reg)) error(-1); if (reg!=creg) { - // clear_ptr_cache_reg(reg); +#ifdef __APPLE__ + clear_ptr_cache_reg(reg); +#endif if (ireg && reg!=ireg ) { if (regs[ireg]!=REG_VAR) free_register(ireg); if (mode) { @@ -536,6 +543,9 @@ { /* called for each file */ output_mode = -1; +#ifdef __APPLE__ + init_ptr_cache(); +#endif } @@ -579,6 +589,14 @@ return i; /* その場所を表す番号を返す */ } } +#ifdef __APPLE__ + /* PTR_CACHE をつぶす */ + if ((i=last_ptr_cache())) { + clear_ptr_cache_reg(i); + regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ + return i; /* その場所を表す番号を返す */ + } +#endif /* search register stack */ for(i=0;i<reg_sp;i++) { if ((reg=reg_stack[i])>=0) { @@ -596,12 +614,22 @@ get_data_register(void) { /* 使われていないレジスタを調べる */ int i,reg,j; - for(i=1;i<=REG_EDX;i++) { + for(i=REG_EAX;i<=REG_EDX;i++) { if (! regs[i]) { /* 使われていないなら */ regs[i]=1; /* そのレジスタを使うことを宣言し */ return i; /* その場所を表す番号を返す */ } } +#ifdef __APPLE__ + /* PTR_CACHE をつぶす */ + while ((i=last_ptr_cache())) { + clear_ptr_cache_reg(i); + if (is_data_reg(i)) { + regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ + return i; /* その場所を表す番号を返す */ + } + } +#endif /* search register stack */ for(i=0;i<reg_sp;i++) { if (is_data_reg(i) && (reg=reg_stack[i])>=0) { @@ -630,13 +658,29 @@ extern void use_ptr_cache(int r) { +#ifdef __APPLE__ + regs[r]=PTRC_REG; +#else error(-1); +#endif } extern void code_ptr_cache_def(int r,NMTBL *nptr) { +#ifdef __APPLE__ + char *rrn = register_name(r,0); + if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { + printf("\tmovl _%s-_%d(%%ebx),%s\n",nptr->nm, + goffset_label,rrn); + } else { + printf("\tmovl L_%s$non_lazy_ptr-_%d(%%ebx),%s\n", + nptr->nm, + goffset_label,rrn); + } +#else error(-1); +#endif } /* @@ -907,6 +951,9 @@ void code_label(int labelno) { +#ifdef __APPLE__ + clear_ptr_cache(); +#endif printf("_%d:\n",labelno); } @@ -914,15 +961,12 @@ code_gvar(int e1,int creg) { use_int(creg); #ifdef __APPLE__ + int r = get_ptr_cache((NMTBL*)caddr(e1)); if (cadr(e1)) { - printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, - goffset_label, - register_name(creg,0)); - printf("\taddl $%d,%s\n", cadr(e1), + printf("\tleal %d(%s),%s\n", cadr(e1),register_name(r,0), register_name(creg,0)); } else { - printf("\tmovl _%s-_%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, - goffset_label,register_name(creg,0)); + printf("\tmovl %s,%s\n", register_name(r,0), register_name(creg,0)); } #else if (cadr(e1)) { @@ -939,20 +983,12 @@ code_rgvar(int e1,int creg) { use_int(creg); #ifdef __APPLE__ + int r = get_ptr_cache((NMTBL*)caddr(e1)); if (cadr(e1)) { - printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, - goffset_label, - register_name(creg,0)); - printf("\tmovl %d(%s),%s\n", - cadr(e1), register_name(creg,0), - register_name(creg,0)); + printf("\tmovl %d(%s),%s\n", cadr(e1),register_name(r,0), + register_name(creg,0)); } else { - printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, - goffset_label, - register_name(creg,0)); - printf("\tmovl %d(%s),%s\n", - cadr(e1), register_name(creg,0), - register_name(creg,0)); + printf("\tmovl (%s),%s\n", register_name(r,0), register_name(creg,0)); } #else if (cadr(e1)) { @@ -974,20 +1010,13 @@ code_crgvar(int e1,int creg,int sign,int sz){ use_int(creg); #ifdef __APPLE__ + int r = get_ptr_cache((NMTBL*)caddr(e1)); if (cadr(e1)) { - printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, - goffset_label, - register_name(creg,0)); - printf("\t%s %d(%s),%s\n",cload(sign,sz), - cadr(e1), register_name(creg,0), - register_name(creg,0)); + printf("\t%s %d(%s),%s\n", cload(sign,sz),cadr(e1),register_name(r,0), + register_name(creg,0)); } else { - printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, - goffset_label, - register_name(creg,0)); - printf("\t%s %d(%s),%s\n",cload(sign,sz), - cadr(e1), register_name(creg,0), - register_name(creg,0)); + printf("\t%s (%s),%s\n", cload(sign,sz), + register_name(r,0), register_name(creg,0)); } #else if (cadr(e1)) { @@ -1066,8 +1095,8 @@ code_fname(NMTBL *n,int creg) { use_int(creg); #ifdef __APPLE__ - printf("\tleal _%s-_%d(%%ebx),%s\n", - n->nm,goffset_label,register_name(creg,0)); + int r = get_ptr_cache(n); + printf("\tmovl %s,%s\n", register_name(r,0), register_name(creg,0)); #else printf("\tmovl $%s,%s\n",n->nm,register_name(creg,0)); #endif @@ -1226,19 +1255,17 @@ code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) { use_int(reg); #ifdef __APPLE__ - printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, - goffset_label, - register_name(reg,0)); + int r = get_ptr_cache((NMTBL*)caddr(e1)); if (cadr(e1)) { if (sz==1) - printf("\tcmpb $0,%d(%s)\n",cadr(e1),register_name(reg,0)); + printf("\tcmpb $0,%d(%s)\n",cadr(e1),register_name(r,0)); else if (sz==SIZE_OF_SHORT) - printf("\tcmpw $0,%d(%s)\n",cadr(e1),register_name(reg,0)); + printf("\tcmpw $0,%d(%s)\n",cadr(e1),register_name(r,0)); } else { if (sz==1) - printf("\tcmpb $0,(%s)\n",register_name(reg,0)); + printf("\tcmpb $0,(%s)\n",register_name(r,0)); else if (sz==SIZE_OF_SHORT) - printf("\tcmpw $0,(%s)\n",register_name(reg,0)); + printf("\tcmpw $0,(%s)\n",register_name(r,0)); } #else if (cadr(e1)) { @@ -1272,10 +1299,11 @@ code_cmp_rgvar(int e1,int reg,int label,int cond) { use_int(reg); #ifdef __APPLE + int r = get_ptr_cache((NMTBL*)caddr(e1)); if (cadr(e1)) - printf("\tcmpl $0,_%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1)); + printf("\tcmpl $0,%d(%s)\n",cadr(e1),register_name(r,0)); else - printf("\tcmpl $0,_%s\n",((NMTBL*)caddr(e1))->nm); + printf("\tcmpl $0,(%s)\n",register_name(r,0)); #else if (cadr(e1)) printf("\tcmpl $0,%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1)); @@ -1387,6 +1415,8 @@ break; } // should be parallel_rassign.... + // clear_ptr_cache(); + // code_save_stacks(); printf("\tpushl %%esi\n"); printf("\tpushl %%edi\n"); @@ -1534,7 +1564,9 @@ g_expr(e2); use_register(creg,REG_EAX,1); /* will be destroyed */ } - +#ifdef __APPLE__ + clear_ptr_cache(); +#endif if (car(e2) == FNAME) { #ifdef __APPLE__ printf("\tcall\tL_%s$stub\n",n->nm); @@ -1678,17 +1710,13 @@ if (byte) { use_data_reg(creg,1); } else { use_int(creg); } #ifdef __APPLE__ - int dreg = get_register(); - printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e2))->nm, - goffset_label, - register_name(dreg,0)); + int r = get_ptr_cache((NMTBL*)caddr(e2)); if (cadr(e2)) printf("\t%s %s,%d(%s)\n",move(byte),register_name(creg,byte), - cadr(e2),register_name(dreg,0)); + cadr(e2),register_name(r,0)); else printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte), - register_name(dreg,0)); - free_register(dreg); + register_name(r,0)); #else if (cadr(e2)) printf("\t%s %s,%s+%d\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm,cadr(e2)); @@ -2045,6 +2073,7 @@ if (stmode!=STATIC) printf(".globl _%s\n",name); printf("_%s:\n",name); + clear_ptr_cache(); #endif } @@ -2102,6 +2131,7 @@ goffset_label = labelno; labelno++; regs[REG_EBX] = 1; + clear_ptr_cache(); #endif control=1; @@ -2433,6 +2463,7 @@ } #endif +#ifndef __APPLE__ void global_table(void) { @@ -2449,15 +2480,51 @@ data_mode(0); init=1; } -#ifdef __APPLE__ - printf(".comm _%s,%d\n",n->nm,size(n->ty)); -#else printf(".comm %s,%d\n",n->nm,size(n->ty)); -#endif // .lcomm? } } -#ifdef __APPLE__ +} + +#else + +void +global_table(void) +{ + NMTBL *n; + int init; + init=0; + for(n=global_list;n;n = n->next) { + if (is_code(n) || is_function(n)) { + } + if ((n->sc == GVAR||n->sc == STATIC) && n->dsp != -1) { + if (is_code(n)||is_function(n)) continue; + /* n->dsp = -1 means initialized global */ + if (init==0) { + data_mode(0); + init=1; + } + printf(".comm _%s,%d\n",n->nm,size(n->ty)); + } else if ((n->sc==STATIC) && n->dsp != -1) { + /* n->dsp = -1 means initialized global */ + if (is_code(n)||is_function(n)) continue; + if (init==0) { + data_mode(0); + init=1; + } + printf(".lcomm _%s,%d\n",n->nm,size(n->ty)); + } + } + init=0; + for(n = global_list;n!=&null_nptr;n = n->next) { + if (n->sc == GVAR) { + if (init==0) { + printf(".data\n"); + init=1; + } +printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n",n->nm,n->nm); + } + } for(n = global_list;n!=&null_nptr;n = n->next) { if (is_code(n)||is_function(n)) { if (n->sc==EXTRN1) { @@ -2476,11 +2543,10 @@ printf("___i686.get_pc_thunk.bx:\n"); printf(" movl (%%esp), %%ebx\n"); printf(" ret\n"); +} #endif -} - void local_table(void) { @@ -3119,26 +3185,20 @@ void code_cmp_lrgvar(int e1,int e2,int label,int cond) { char *n,*crn; - n = ((NMTBL*)caddr(e1))->nm; use_int(e2); crn = register_name(e2,0); #ifdef __APPLE__ - int dreg; - char *drn; - dreg = get_register(); - drn = register_name(dreg,0); - printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e2))->nm, - goffset_label, drn); - + int r = get_ptr_cache((NMTBL*)caddr(e1)); + n = register_name(r,0); if (cadr(e1)) { - printf("\tmovl %d(%s),%s\n",cadr(e1),drn,crn); - printf("\torl %d(%s),%s\n",cadr(e1)+4,drn,crn); + printf("\tmovl %d(%s),%s\n",cadr(e1),n,crn); + printf("\torl %d(%s),%s\n",cadr(e1)+4,n,crn); } else { - printf("\tmovl (%s),%s\n",drn,crn); - printf("\torl 4(%s),%s\n",drn,crn); + printf("\tmovl (%s),%s\n",n,crn); + printf("\torl 4(%s),%s\n",n,crn); } - free_register(dreg); #else + n = ((NMTBL*)caddr(e1))->nm; if (cadr(e1)) { printf("\tmovl %s+%d,%s\n",n,cadr(e1),crn); printf("\torl %s+%d,%s\n",n,cadr(e1)+4,crn); @@ -3177,26 +3237,20 @@ void code_lassign_gvar(int e1,int e2) { char *n; - n = ((NMTBL*)caddr(e1))->nm; use_longlong(e2); #if ENDIAN_L==0 #ifdef __APPLE__ - int dreg; - char *drn; - dreg = get_register(); - drn = register_name(dreg,0); - printf("\tmovl _%s-%d(%%ebx),%s\n",n, - goffset_label, - register_name(dreg,0)); + int r = get_ptr_cache((NMTBL*)caddr(e1)); + n = register_name(r,0); if (cadr(e1)) { - printf("\tmovl %s,%d(%s)\n",l_eax(e2),cadr(e1),drn); - printf("\tmovl %s,%d(%s)\n",l_edx(e2),cadr(e1)+4,drn); + printf("\tmovl %s,%d(%s)\n",l_eax(e2),cadr(e1),n); + printf("\tmovl %s,%d(%s)\n",l_edx(e2),cadr(e1)+4,n); } else { - printf("\tmovl %s,(%s)\n",l_eax(e2),drn); - printf("\tmovl %s,4(%s)\n",l_edx(e2),drn); + printf("\tmovl %s,(%s)\n",l_eax(e2),n); + printf("\tmovl %s,4(%s)\n",l_edx(e2),n); } - free_register(dreg); #else + n = ((NMTBL*)caddr(e1))->nm; if (cadr(e1)) { printf("\tmovl %s,%s+%d\n",l_eax(e2),n,cadr(e1)); printf("\tmovl %s,%s+%d\n",l_edx(e2),n,cadr(e1)+4); @@ -3248,20 +3302,20 @@ void code_lrgvar(int e1,int e2) { char *n; - n = ((NMTBL*)caddr(e1))->nm; use_longlong(e2); #if ENDIAN_L==0 #ifdef __APPLE__ - printf("\tmovl _%s-%d(%%ebx),%s\n",n, - goffset_label,l_edx(e2)); + int r = get_ptr_cache((NMTBL*)caddr(e1)); + n = register_name(r,0); if (cadr(e1)) { - printf("\tmovl %d(%s),%s\n",cadr(e1),l_edx(e2),l_eax(e2)); - printf("\tmovl %d(%s),%s\n",cadr(e1)+4,l_edx(e2),l_edx(e2)); + printf("\tmovl %d(%s),%s\n",cadr(e1),n,l_eax(e2)); + printf("\tmovl %d(%s),%s\n",cadr(e1)+4,n,l_edx(e2)); } else { - printf("\tmovl (%s),%s\n",l_edx(e2),l_eax(e2)); - printf("\tmovl 4(%s),%s\n",l_edx(e2),l_edx(e2)); + printf("\tmovl (%s),%s\n",n,l_eax(e2)); + printf("\tmovl 4(%s),%s\n",n,l_edx(e2)); } #else + n = ((NMTBL*)caddr(e1))->nm; if (cadr(e1)) { printf("\tmovl %s+%d,%s\n",n,cadr(e1),l_eax(e2)); printf("\tmovl %s+%d,%s\n",n,cadr(e1)+4,l_edx(e2)); @@ -3375,6 +3429,9 @@ printf("\tlea 8(%%esp),%%esp\n"); check_lreg(reg); } else if (call) { +#ifdef __APPLE__ + clear_ptr_cache(); +#endif printf("\tpushl %%edx\n"); printf("\tpushl %%eax\n"); printf("\tcall %s\n",call); @@ -3587,6 +3644,9 @@ void code_d2ull(int reg) { use_longlong(reg); +#ifdef __APPLE__ + clear_ptr_cache(); +#endif printf("\tsubl $16,%%esp\n"); printf("\tfstpl (%%esp)\n"); printf("\tcall __fixunsdfdi\n"); @@ -3601,6 +3661,9 @@ void code_f2ull(int reg) { use_longlong(reg); +#ifdef __APPLE__ + clear_ptr_cache(); +#endif printf("\tsubl $16,%%esp\n"); printf("\tfstps (%%esp)\n"); printf("\tcall __fixunssfdi\n");