Mercurial > hg > CbC > old > device
changeset 587:c991b82e6849
*** empty log message ***
author | kono |
---|---|
date | Wed, 18 Jan 2006 15:40:44 +0900 |
parents | 3fb4081164bd |
children | 82718dc9f758 |
files | Changes mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-codegen.c |
diffstat | 5 files changed, 53 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Wed Jan 18 13:36:50 2006 +0900 +++ b/Changes Wed Jan 18 15:40:44 2006 +0900 @@ -8527,4 +8527,7 @@ 他のも、これにする方が正しそう。 - +Wed Jan 18 14:47:39 JST 2006 + +register の順序を変えると動かなくなるってのは、コードの信頼性が +低いってことなんだよな....
--- a/mc-code-ia32.c Wed Jan 18 13:36:50 2006 +0900 +++ b/mc-code-ia32.c Wed Jan 18 15:40:44 2006 +0900 @@ -270,13 +270,13 @@ #define REG_EAX 1 #define REG_EBX 2 -#define REG_ECX 3 +#define REG_ECX 3 // for strange reason (code_assop) #define REG_EDX 4 #define REG_ESI 5 #define REG_EDI 6 #define REG_EBP 7 #define REG_ESP 8 -#define is_int_reg(reg) (REG_EAX<=reg&®<REG_EBP) +#define is_int_reg(reg) (1<=reg&®<REG_EBP) #define REG_LCREG 9 #define REG_L 10 #define REG_fp REG_EBP @@ -288,7 +288,7 @@ #define RET_REGISTER REG_EAX // defalut current register -#define CREG_REGISTER REG_EAX +#define CREG_REGISTER REG_ECX static char *reg_name[8+1]; static char *reg_name_l[4+1]; @@ -325,7 +325,9 @@ int i = creg; if (!i||!ireg||!is_int_reg(i)) { if (lreg) { if (regs[lreg]) free_register(lreg); lreg = 0; } - if (!ireg) ireg = get_register(); + if (!ireg) { + ireg = get_register(); + } i = ireg; } if (!regs[i]) regs[i]=USING_REG; @@ -333,7 +335,7 @@ return i; } -#define is_data_reg(reg) (REG_EAX<=reg&®<=REG_EDX) +#define is_data_reg(reg) (1<=reg&®<=4) #define is_pointer_reg(reg) (REG_ESI<=reg&®<=REG_EBP) static int @@ -347,7 +349,7 @@ char *move_op; code_clear_stack_reg(reg1); move_op = (regs[reg1]||regs[reg1])?"\txchg %s,%s\n":"\tmovl %s,%s\n"; - if (move) { + if (move && reg0!=reg1) { printf(move_op,reg_name[reg0],reg_name[reg1]); if (!regs[reg1]) regs[reg1]=USING_REG; } @@ -367,8 +369,9 @@ } if (!i||!ireg||!is_int_reg(i)) { if (lreg) { if (regs[lreg]) free_register(lreg); lreg = 0; } - if (!ireg) ireg = get_data_register(); - // else if (ireg!=i) free_register(i); + if (!ireg) { + ireg = get_data_register(); + } i = ireg; } if (!regs[i]) regs[i]=USING_REG; @@ -499,7 +502,7 @@ void gexpr_code_init(void){ // use_register(creg,REG_EAX,0); - set_ireg(REG_EAX,0); + set_ireg(CREG_REGISTER,0); } void @@ -1010,14 +1013,16 @@ if (car(e2)==REGISTER) { use_int(reg); printf("\taddl $%d,%s\n",dir,register_name(cadr(e2),0)); - printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0)); + if (use) + printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0)); return; } g_expr(e2); xrn = register_name(creg,0); use_int(reg); printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==SIZE_OF_SHORT)?"addw":"addl",dir,xrn); - printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0)); + if (use) + printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0)); } @@ -1026,7 +1031,8 @@ char *xrn; if (car(e2)==REGISTER) { use_int(reg); - printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0)); + if (use) + printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0)); printf("\taddl $%d,%s\n",dir,register_name(cadr(e2),0)); return; @@ -1035,7 +1041,8 @@ emit_push(); xrn = register_name((e2=emit_pop(0)),0); use_int(reg); - printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0)); + if (use) + printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0)); printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==SIZE_OF_SHORT)?"addw":"addl",dir,xrn); emit_pop_free(e2); } @@ -1384,7 +1391,7 @@ } if (car(e2) == FNAME) { n=(NMTBL *)cadr(e2); - use_register(creg,REG_EAX,0); /* will be destroyed */ + // use_register(creg,REG_EAX,0); /* will be destroyed */ } else { g_expr(e2); use_register(creg,REG_EAX,1); /* will be destroyed */ @@ -1393,7 +1400,7 @@ if (car(e2) == FNAME) { printf("\tcall\t%s\n",n->nm); } else { - printf("\tcall\t*%s\n",register_name(creg,0)); + printf("\tcall\t*%s\n",register_name(REG_EAX,0)); } if (nargs) printf("\taddl $%d,%%esp\n",SIZE_OF_INT*nargs); if (ret_type==DOUBLE||ret_type==FLOAT) { @@ -1401,7 +1408,10 @@ use_longlong0(USE_CREG); } else if (ret_type==VOID) { } else { - set_ireg(RET_REGISTER,0); + if (use) + set_ireg(RET_REGISTER,0); + else + set_ireg(CREG_REGISTER,0); } stack_depth = stack_depth_save; return ret_type; @@ -1559,7 +1569,8 @@ void code_assop(int op,int creg,int byte,int sign) { int xreg; - // (*creg) op = pop() + // (*pop()) op = creg + // creg should be ecx use_int(creg); xreg = emit_pop(0); /* pop e3 value */ @@ -1933,11 +1944,12 @@ car(cadr(fnptr->ty))==STRUCT || car(cadr(fnptr->ty))==UNION)) { sz = size(cadr(fnptr->ty)); + set_ireg(RET_REGISTER,0); printf("\tmovl %d(%%ebp),%s\n",disp-SIZE_OF_INT, register_name(creg,0)); // emit_copy(dreg,creg,sz,0,1,1); } else if (cadr(fnptr->ty)!=VOID) { - use_register(creg,REG_EAX,0); + set_ireg(RET_REGISTER,0); printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0)); } } @@ -3257,7 +3269,7 @@ use_longlong(reg); printf("\taddl $%d,%%esi\n",dir); printf("\tadcl $%d,%%edi\n",dir>0?0:-1); - if (reg!=REG_L) { + if (use && reg!=REG_L) { code_lregister(REG_L,reg); } return; @@ -3277,7 +3289,7 @@ char *crn; if (car(e2)==LREGISTER) { use_longlong(reg); - if (reg!=REG_L) { + if (use && reg!=REG_L) { code_lregister(REG_L,reg); } printf("\taddl $%d,%%esi\n",dir); @@ -3288,10 +3300,12 @@ crn = register_name(creg0=creg,0); printf("\taddl $%d,(%s)\n",dir,crn); printf("\tadcl $%d,4(%s)\n",dir>0?0:-1,crn); - use_longlong(reg); - lload(creg0,0,reg); - printf("\taddl $%d,%s\n",-dir,l_eax(reg)); - printf("\tadcl $%d,%s\n",-dir>0?0:-1,l_edx(reg)); + if (use) { + use_longlong(reg); + lload(creg0,0,reg); + printf("\taddl $%d,%s\n",-dir,l_eax(reg)); + printf("\tadcl $%d,%s\n",-dir>0?0:-1,l_edx(reg)); + } } void code_lassop(int op,int reg)
--- a/mc-code-mips.c Wed Jan 18 13:36:50 2006 +0900 +++ b/mc-code-mips.c Wed Jan 18 15:40:44 2006 +0900 @@ -1363,7 +1363,7 @@ use_int(reg); printf("\taddu %s,%s,%d\n", register_name(cadr(e2)),register_name(cadr(e2)), dir); - if (cadr(e2)!=reg) + if (use && cadr(e2)!=reg) printf("\tmove %s,%s\n",register_name(reg),register_name(cadr(e2))); return; } @@ -1390,7 +1390,8 @@ int nreg; if (car(e2)==REGISTER) { use_int(reg); - printf("\tmove %s,%s\n",register_name(reg),register_name(cadr(e2))); + if (use) + printf("\tmove %s,%s\n",register_name(reg),register_name(cadr(e2))); printf("\taddu %s,%s,%d\n", register_name(cadr(e2)),register_name(cadr(e2)),dir); return; @@ -5171,7 +5172,7 @@ if (car(e2)==LREGISTER) { use_longlong(reg); ladd(cadr(e2),cadr(e2),dir); - if (reg!=cadr(e2)) { + if (use && reg!=cadr(e2)) { lmove(reg,cadr(e2)); } return; @@ -5200,7 +5201,7 @@ int dir=caddr(e1); if (car(e2)==LREGISTER) { use_longlong(reg); - lmove(reg,cadr(e2)); + if (use) lmove(reg,cadr(e2)); ladd(cadr(e2),cadr(e2),dir); return; }
--- a/mc-code-powerpc.c Wed Jan 18 13:36:50 2006 +0900 +++ b/mc-code-powerpc.c Wed Jan 18 15:40:44 2006 +0900 @@ -1334,7 +1334,7 @@ use_int(reg); printf("\taddi %s,%s,%d\n", register_name(cadr(e2)),register_name(cadr(e2)), dir); - if (cadr(e2)!=reg) + if (use && cadr(e2)!=reg) printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); return; } @@ -1361,7 +1361,8 @@ int nreg; if (car(e2)==REGISTER) { use_int(reg); - printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); + if (use) + printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); printf("\taddi %s,%s,%d\n", register_name(cadr(e2)),register_name(cadr(e2)),dir); return; @@ -4984,7 +4985,7 @@ int dir=caddr(e1); if (car(e2)==LREGISTER) { use_longlong(reg); - if (reg!=cadr(e2)) + if (use && reg!=cadr(e2)) lmove(reg,cadr(e2)); ladd(cadr(e2),cadr(e2),dir); return;
--- a/mc-codegen.c Wed Jan 18 13:36:50 2006 +0900 +++ b/mc-codegen.c Wed Jan 18 15:40:44 2006 +0900 @@ -104,7 +104,7 @@ int t; int suse = use; use=0; t=g_expr0(e1); - code_gexpr(e1); + //code_gexpr(e1); use=suse; return t; @@ -118,7 +118,7 @@ int t; int suse = use; use=1; t=g_expr0(e1); - code_gexpr(e1); + //code_gexpr(e1); use=suse; return t;