Mercurial > hg > CbC > old > device
changeset 590:cc2a83f98188
ia32 reorganization etc.
author | kono |
---|---|
date | Thu, 19 Jan 2006 17:55:10 +0900 |
parents | f095b8507947 |
children | 0497fa2e2414 |
files | Changes Makefile.ia32 Makefile.linuxzaurus Makefile.mips Makefile.powerpc mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc.h test/tmpb.c test/tmpb.code-out |
diffstat | 12 files changed, 173 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Wed Jan 18 16:55:13 2006 +0900 +++ b/Changes Thu Jan 19 17:55:10 2006 +0900 @@ -8531,3 +8531,15 @@ register の順序を変えると動かなくなるってのは、コードの信頼性が 低いってことなんだよな.... + +Thu Jan 19 16:49:23 JST 2006 + +hoge() +#if +{ + +とかで、type が、おかしくなるらしい。ありそうな話だ。 + + + +
--- a/Makefile.ia32 Wed Jan 18 16:55:13 2006 +0900 +++ b/Makefile.ia32 Thu Jan 19 17:55:10 2006 +0900 @@ -116,6 +116,7 @@ make check-code$(MK) TARGET=test/tmp2 make check-code$(MK) TARGET=test/tmp4 make check-code$(MK) TARGET=test/tmp6 + make check-code$(MK) TARGET=test/tmpb make check-code$(MK) TARGET=test/scope make check-code$(MK) TARGET=test/throw make check-code$(MK) TARGET=test/too-long-argument
--- a/Makefile.linuxzaurus Wed Jan 18 16:55:13 2006 +0900 +++ b/Makefile.linuxzaurus Thu Jan 19 17:55:10 2006 +0900 @@ -117,6 +117,7 @@ make check-code$(MK) TARGET=test/tmp2 make check-code$(MK) TARGET=test/tmp4 make check-code$(MK) TARGET=test/tmp6 + make check-code$(MK) TARGET=test/tmpb make check-code$(MK) TARGET=test/scope make check-code$(MK) TARGET=test/throw make check-code$(MK) TARGET=test/too-long-argument
--- a/Makefile.mips Wed Jan 18 16:55:13 2006 +0900 +++ b/Makefile.mips Thu Jan 19 17:55:10 2006 +0900 @@ -115,6 +115,7 @@ make check-code$(MK) TARGET=test/tmp2 make check-code$(MK) TARGET=test/tmp4 make check-code$(MK) TARGET=test/tmp6 + make check-code$(MK) TARGET=test/tmpb make check-code$(MK) TARGET=test/scope make check-code$(MK) TARGET=test/throw make check-code$(MK) TARGET=test/too-long-argument
--- a/Makefile.powerpc Wed Jan 18 16:55:13 2006 +0900 +++ b/Makefile.powerpc Thu Jan 19 17:55:10 2006 +0900 @@ -119,6 +119,7 @@ make check-code$(MK) TARGET=test/tmp2 make check-code$(MK) TARGET=test/tmp4 make check-code$(MK) TARGET=test/tmp6 + make check-code$(MK) TARGET=test/tmpb make check-code$(MK) TARGET=test/scope make check-code$(MK) TARGET=test/throw make check-code$(MK) TARGET=test/too-long-argument
--- a/mc-code-arm.c Wed Jan 18 16:55:13 2006 +0900 +++ b/mc-code-arm.c Thu Jan 19 17:55:10 2006 +0900 @@ -1190,8 +1190,10 @@ if (!is_int_reg(creg)) error(-1); if (reg_sp>MAX_MAX) error(-1); new_reg = get_register(); /* 絶対に取れる */ + if (new_reg==creg) error(-1); /* who freed creg? */ reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */ ireg = creg = new_reg; + if (!regs[creg]) regs[creg]=USING_REG; return old; } @@ -2967,6 +2969,7 @@ } else if (oreg<= -REG_LVAR_OFFSET) { ox = get_register(); if (ox<0) error(-1); code_rlvar(oreg+REG_LVAR_OFFSET,ox); + free_lvar(oreg+REG_LVAR_OFFSET); oreg = ox; } @@ -3014,6 +3017,20 @@ break; case MUL: case UMUL: +#if 0 + inc_inst(1); + // drn = register_name(cadr(dx = get_register_var(0))); + drn = register_name(dx = get_register()); + // if (car(dx)!=REGISTER) error(-1); + printf("\tmul\t%s, %s, %s\n",drn,crn,orn); + if (creg0==USE_CREG) { + set_ireg(dx,0); dx = -1; + } else { + printf("\tmov\t%s, %s\n",crn,drn); + } + if (dx!=-1) free_register(dx); + break; +#else inc_inst(1); drn = register_name(cadr(dx = get_register_var(0))); if (car(dx)!=REGISTER) error(-1); @@ -3025,6 +3042,7 @@ } if (dx!=-1) free_register(cadr(dx)); break; +#endif case DIV: code_int_lib("__divsi3",creg,oreg); break; case UDIV:
--- a/mc-code-ia32.c Wed Jan 18 16:55:13 2006 +0900 +++ b/mc-code-ia32.c Thu Jan 19 17:55:10 2006 +0900 @@ -175,11 +175,13 @@ #define MAX_REGISTER 6 /* intel386のレジスタを6つまで使う*/ #define REAL_MAX_REGISTER 8 /* intel386のレジスタが8つということ*/ +static int MAX_DATA_REG=4; +static int MAX_POINTER=3; int MAX_REGISTER_VAR=2; // static int MAX_FREGISTER=1; #define MAX_FPU_STACK 7 -#define REG_VAR 3 +#define REG_VAR 2 // static int MAX_INPUT_REGISTER_VAR = 0; int MAX_CODE_INPUT_REGISTER_VAR = 2; @@ -263,8 +265,8 @@ // 0 for not ready // -1 use currrent register // 1 used -// 2 pointer cache (not used in ia32) -// 3 (REG_VAR) register variable +// 2 (REG_VAR) register variable +// 3 pointer cache (not used in ia32) #define REG_EAX 1 #define REG_EBX 2 @@ -451,6 +453,8 @@ arg_offset = 8; // MAX_REGISTER=6; + MAX_DATA_REG=4; + MAX_POINTER=3; MAX_REGISTER_VAR=2; reg_name[REG_EAX] = "%eax"; @@ -820,21 +824,13 @@ emit_push() { int new_reg,old; - new_reg = get_register(); + new_reg = get_register(); /* 絶対に取れる */ // who free new_reg? if (new_reg==creg) error(-1); old = creg; - if(new_reg<0) { /* もうレジスタがない */ - if (reg_sp>=MAX_MAX) error(-1); - reg_stack[reg_sp++] = -1; - printf("\tpushl %s\n",register_name(creg,0)); - stack_depth += SIZE_OF_INT; - /* creg is used soon, don't regv[creg]=0 */ - } else { - reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */ - ireg = creg = new_reg; - regs[creg]=1; - } + reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */ + ireg = creg = new_reg; + if (!regs[creg]) regs[creg]=USING_REG; return old; } @@ -910,6 +906,7 @@ void code_register(int e2,int creg) { use_int(creg); + if (e2!=creg) printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0)); } @@ -1596,6 +1593,7 @@ } else if (oreg<= -REG_LVAR_OFFSET) { ox = get_register(); if (ox<0) error(-1); code_rlvar(oreg+REG_LVAR_OFFSET,ox); + free_lvar(oreg+REG_LVAR_OFFSET); oreg = ox; } @@ -3755,7 +3753,7 @@ a = ~mask|c; if (a!=-1) { /* do conjunction */ - if (is_data_reg(reg) && ((a& ~0xffff)==~0xffff)) { + if (reg<MAX_DATA_REG && ((a& ~0xffff)==~0xffff)) { if ((a& ~0xff)==~0xff) printf("\tandb $%d,%s\n",a&0xff,register_name(reg,1)); else @@ -3767,7 +3765,7 @@ c = mask&c; if (c!=0) { /* do disjunction */ - if (is_data_reg(reg) && (!(c& ~0xffff))) { + if (reg<MAX_DATA_REG && (!(c& ~0xffff))) { if (!(c& ~0xff)) printf("\torb $%d,%s\n",c&0xff,register_name(reg,1)); else
--- a/mc-code-mips.c Wed Jan 18 16:55:13 2006 +0900 +++ b/mc-code-mips.c Thu Jan 19 17:55:10 2006 +0900 @@ -1147,8 +1147,10 @@ if (!is_int_reg(creg)) error(-1); if (reg_sp>MAX_MAX) error(-1); new_reg = get_register(); /* 絶対に取れる */ + if (creg==new_reg) error(-1); /* some one free creg */ reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */ ireg = creg = new_reg; + if (!regs[creg]) regs[creg]=USING_REG; return old; } @@ -2532,6 +2534,7 @@ } else if (oreg<= -REG_LVAR_OFFSET) { ox = get_register(); if (ox<0) error(-1); code_rlvar(oreg+REG_LVAR_OFFSET,ox); + free_lvar(oreg+REG_LVAR_OFFSET); oreg = ox; }
--- a/mc-code-powerpc.c Wed Jan 18 16:55:13 2006 +0900 +++ b/mc-code-powerpc.c Thu Jan 19 17:55:10 2006 +0900 @@ -91,6 +91,7 @@ #define MAX_TMP_REG 11 #define PTRC_REG 3 +#define REG_VAR 2 #define FREG_VAR_BASE 31 #define FREG_VAR_MIN 20 @@ -172,7 +173,7 @@ int use_int0() { int i = creg; if (!i||!ireg||!is_int_reg(i)) { - if (lreg) { free_register(lreg); lreg = 0; } + if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } if (!ireg) ireg = get_register(); // else if (ireg!=i) free_register(i); i = ireg; @@ -189,7 +190,7 @@ int use_longlong0() { int i = creg; if (!is_longlong_reg(i)) { - if (ireg) { free_register(ireg); ireg=0; } + if (ireg) { if (regs[ireg]!=REG_VAR) free_register(ireg); ireg=0; } if (!lreg||!regs[lreg]) lreg = get_lregister(); // else if (lreg!=i) free_register(i); i = lreg; @@ -211,9 +212,9 @@ int use_float0() { int i = creg; if (!is_float_reg(i)) { - if (lreg) { free_register(lreg); lreg = 0; } + if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } if (!freg) freg = get_dregister(0); - else if (freg!=i) free_register(i); + else if (freg!=i) if (regs[i]!=REG_VAR) free_register(i); i = freg; } if (!regs[i]) regs[i]=USING_REG; @@ -224,9 +225,9 @@ int use_double0() { int i = creg; if (!is_float_reg(i)) { - if (lreg) { free_register(lreg); lreg = 0; } + if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } if (!freg) freg = get_dregister(1); - else if (freg!=i) free_register(i); + else if (freg!=i) if (regs[i]!=REG_VAR) free_register(i); i = freg; } if (!regs[i]) regs[i]=USING_REG; @@ -471,8 +472,13 @@ void code_gexpr(int e){ - if (is_int_reg(creg) && creg!=ireg) error(-1); - // register_usage("code_gexpr"); + if ((is_int_reg(creg))&®s[creg]==REG_VAR) + creg = ireg = 0; + else if (is_float_reg(creg)&®s[creg]==REG_VAR) + creg = lreg = 0; + else if (is_longlong_reg(creg)&®s[creg]==REG_VAR) + creg = lreg = 0; + // if (is_int_reg(creg) && creg!=ireg) error(-1); } @@ -707,9 +713,13 @@ if (h==-1) return -1; regv_h(i) = h; l = get_register(); - if (l==-1) { free_register(h); free_register(i); return -1; } + if (l==-1) { + if (regs[h]!=REG_VAR) free_register(h); + if (regs[i]!=REG_VAR) free_register(i); + return -1; + } regv_l(i) = l; - regs[i]=USING_REG; + if (!regs[i]) regs[i]=USING_REG; // printf("## get_lregister %d %s %s\n",i, lregister_name_high(i), lregister_name_low(i)); return i; } @@ -731,10 +741,10 @@ if (! regs[REG_VAR_BASE-j]) { /* 使われていないなら */ /* そのレジスタを使うことを宣言し */ - regs[REG_VAR_BASE-j]=USING_REG; + regs[REG_VAR_BASE-j]=REG_VAR; if (j>max_reg_var) max_reg_var=j; /* その場所を表す番号を返す */ - regs[ll]=USING_REG; + regs[ll]=REG_VAR; regv_l(ll) = REG_VAR_BASE-j; regv_h(ll) = REG_VAR_BASE-i; return list3(LREGISTER,ll,(int)n); @@ -754,19 +764,17 @@ void emit_pop_free(int xreg) { - if (xreg>=0 && xreg!=creg) + if (xreg>=0 && xreg!=creg && regs[xreg]!=REG_VAR) free_register(xreg); } void free_register(int i) { /* いらなくなったレジスタを開放 */ -// printf("## free_register %d\n",i); + // printf("## free_register %d\n",i); if (is_longlong_reg(i)) { regs[regv_l(i)]=0; regs[regv_h(i)]=0; - //regv_l(i)=0; will erase input register... - //regv_h(i)=0; } regs[i]=0; } @@ -1056,7 +1064,7 @@ for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ /* そのレジスタを使うことを宣言し */ - regs[REG_VAR_BASE-i]=USING_REG; + regs[REG_VAR_BASE-i]=REG_VAR; if (i>max_reg_var) max_reg_var=i; /* その場所を表す番号を返す */ return list3(REGISTER,REG_VAR_BASE-i,(int)n); @@ -1071,7 +1079,7 @@ int i; for(i=0;i<FREG_VAR_BASE-FREG_VAR_MIN;i++) { if (! regs[FREG_VAR_BASE-i+FREG_OFFSET]) { /* 使われていないなら */ - regs[FREG_VAR_BASE-i+FREG_OFFSET]=USING_REG; /*そのレジスタを使うことを宣言し*/ + regs[FREG_VAR_BASE-i+FREG_OFFSET]=REG_VAR; /*そのレジスタを使うことを宣言し*/ if (i>max_freg_var) max_freg_var=i; /* その場所を表す番号を返す */ return list3(DREGISTER, @@ -1088,8 +1096,10 @@ if (!is_int_reg(creg)) error(-1); if (reg_sp>MAX_MAX) error(-1); new_reg = get_register(); /* 絶対に取れる */ + if (new_reg==creg) error(-1); // freed creg reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */ ireg = creg = new_reg; + if (!regs[creg]) regs[creg]=USING_REG; return old; } @@ -2430,6 +2440,22 @@ void code_assop(int op,int creg, int byte,int sign) { + int xreg; + // (*pop()) op = creg + // creg should be ecx + + use_int(creg); + xreg = emit_pop(0); /* pop e3 value */ + emit_push(); + ld_indexx(byte,0,creg,ireg,sign); + tosop(op,ireg,xreg); + emit_pop_free(xreg); + xreg = emit_pop(0); /* pop e3 value */ + printf("\t%s %s,0(%s)\n",cstore(byte), + register_name(ireg),register_name(xreg)); + emit_pop_free(xreg); + +#if 0 char *xrn,*crn,*drn; int xreg; int edx = get_register(); if(!edx) error(-1); @@ -2469,6 +2495,7 @@ free_register(edx); emit_pop_free(xreg); #endif +#endif } void @@ -2485,6 +2512,7 @@ } else if (oreg<= -REG_LVAR_OFFSET) { ox = get_register(); if (ox<0) error(-1); code_rlvar(oreg+REG_LVAR_OFFSET,ox); + free_lvar(oreg+REG_LVAR_OFFSET); oreg = ox; } @@ -3963,7 +3991,8 @@ void emit_dpop_free(int e1,int d) { - free_register(e1); + if (e1>=0 && e1!=creg && regs[e1]!=REG_VAR) + free_register(e1); } void @@ -4778,7 +4807,7 @@ void emit_lpop_free(int xreg) { - if (xreg>=0) + if (xreg>=0 && xreg!=creg && regs[xreg]!=REG_VAR) free_register(xreg); }
--- a/mc.h Wed Jan 18 16:55:13 2006 +0900 +++ b/mc.h Thu Jan 19 17:55:10 2006 +0900 @@ -526,7 +526,7 @@ extern void free_nptr(NMTBL *n); extern NMTBL *get_nptr(); -#if 0 +#if 1 extern int heapsize; #define CHECK_HEAP(b) ({int _k=(int)(b);if(_k>heapsize||_k<0)error(-1);_k;}) #else
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tmpb.c Thu Jan 19 17:55:10 2006 +0900 @@ -0,0 +1,69 @@ +extern int printf(const char *,...); + +#ifdef INLINE +#else +#define INLINE +#endif + +int hoge(); +void aho(); + +int +main() +{ + aho(); + return hoge(); +} + +INLINE void +aho() +{ + register int i = 0; + register int a0 = 0; + register int a1 = 0; + register int a2 = 0; + register int a3 = 0; + register int a4 = 0; + register int a5 = 0; + register int a6 = 0; + register int a7 = 0; + register int a8 = 0; + register int a9 = 0; + register int aa = 0; + register int ab = 0; + register int ac = 0; + register int ad = 0; + register int ae = 0; + + i= i+1; + int j; + j= i+1; + int k=3; + k = j+4; + k = ((((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3) + + ((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3)) + + (((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3) + + ((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3))) + + ((((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3) + + ((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3)) + + (((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3) + + ((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3))); + printf("%d %d %d\n",i,j,k); + int m=3; + k = ((((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3) + + ((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3)) + + (((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3) + + ((i+1)-((m*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3))) + + ((((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3) + + ((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3)) + + (((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3) + + ((i+1)-((j*(k+3))+2))-((j*3*(2+(2+(2+k))))+k*(2+(2+(2+k))))-((j*4)+k*3))); + printf("%d %d %d\n",i,j,k); +} + +int +hoge() +{ + aho(); + return 0; +}