# HG changeset patch # User kono # Date 1083249182 -32400 # Node ID c575422d8b6ebcca3a858b00dbd8925b79b2e3a0 # Parent eccea7c904ee7d6b871df8ca22e6884311e6fb79 *** empty log message *** diff -r eccea7c904ee -r c575422d8b6e .gdbinit.ia32 --- a/.gdbinit.ia32 Thu Apr 29 19:40:43 2004 +0900 +++ b/.gdbinit.ia32 Thu Apr 29 23:33:02 2004 +0900 @@ -13,4 +13,5 @@ x/1i $eip end b errmsg -r -s mc-code-powerpc.c +r -s test/code-gen-all.c +# r -s mc-code-powerpc.c diff -r eccea7c904ee -r c575422d8b6e mc-code-ia32.c --- a/mc-code-ia32.c Thu Apr 29 19:40:43 2004 +0900 +++ b/mc-code-ia32.c Thu Apr 29 23:33:02 2004 +0900 @@ -147,8 +147,8 @@ static void use_register(int virt, int real, int move); static int virtual(int real); -static void shift(char *op, int reg); -static void ld_indexx(int byte, int n, int xreg,int sign); +static void shift(char *op, int reg,int creg); +static void ld_indexx(int byte, int n, int xreg,int reg,int sign); static void data_mode(char *name); static int edx_setup(); static void edx_cleanup(); @@ -161,6 +161,9 @@ #endif static void code_save_stacks(); +#define use_int(reg) if (reg==-1) reg=use_int0() +static int use_int0() { return creg; } + void code_init(void) { @@ -172,7 +175,8 @@ macro_define("__flexarr\n"); macro_define("__builtin_va_list int*\n"); macro_define("wchar_t int\n"); - macro_define("__THROW\n"); + // macro_define("__THROW\n"); + macro_define("__gnuc_va_list int*\n"); arg_offset = 8; func_disp_offset = -12; @@ -219,10 +223,12 @@ } } +/* int use_int(int i) { return i;} int use_float(int i) { return i;} int use_double(int i) { return i;} int use_longlong(int i) { return i; } + */ void @@ -451,7 +457,7 @@ get_register_var(NMTBL *nptr) { int i; - for(i=REG_ESI;inm,register_name(creg,0)); regv[creg]=1; } @@ -598,12 +605,16 @@ void code_rgvar(int e1,int creg) { + use_int(creg); printf("\tmovl %s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0)); regv[creg]=1; } + static char *cload(int sign,int sz) { return sz==1?(sign?"movsbl":"movzbl"):sz==size_of_short?(sign?"movswl":"movzwl"):"movl"; } + void code_crgvar(int e1,int creg,int sign,int sz){ + use_int(creg); printf("\t%s %s,%s\n",cload(sign,sz), ((NMTBL*)cadr(e1))->nm,register_name(creg,0)); regv[creg]=1; @@ -612,6 +623,7 @@ void code_lvar(int e2,int creg) { + use_int(creg); printf("\tlea %d(%%ebp),%s\n",lvar(e2),register_name(creg,0)); regv[creg]=1; } @@ -619,6 +631,7 @@ void code_register(int e2,int creg) { + use_int(creg); printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0)); regv[creg]=1; } @@ -626,6 +639,7 @@ void code_rlvar(int e2,int reg) { + use_int(reg); printf("\tmovl %d(%%ebp),%s\n",lvar(e2),register_name(reg,0)); regv[creg]=1; } @@ -633,6 +647,7 @@ void code_crlvar(int e2,int reg,int sign,int sz) { + use_int(reg); printf("\t%s %d(%%ebp),%s\n",cload(sign,sz),lvar(e2),register_name(reg,0)); regv[creg]=1; } @@ -640,6 +655,7 @@ void code_fname(NMTBL *n,int creg) { + use_int(creg); printf("\tmovl $%s,%s\n",n->nm,register_name(creg,0)); regv[creg]=1; } @@ -647,6 +663,7 @@ void code_const(int e2,int creg) { + use_int(creg); printf("\tmovl $%d,%s\n",e2,register_name(creg,0)); regv[creg]=1; } @@ -654,12 +671,14 @@ void code_neg(int creg) { + use_int(creg); printf("\tnegl %s\n", register_name(creg,0)); } void code_not(int creg) { + use_int(creg); printf("\tnotl %s\n", register_name(creg,0)); } @@ -667,6 +686,7 @@ void code_lnot(int creg) { char *xrn; + use_int(creg); use_data_reg(creg,1); xrn = register_name(creg,1); printf("\tcmpl $0,%s\n", register_name(creg,0)); @@ -678,6 +698,7 @@ code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) { char *xrn; 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)); regv[reg]=1; @@ -685,8 +706,9 @@ } 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(creg,0)); + printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0)); } @@ -694,6 +716,7 @@ code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) { char *xrn; if (car(e2)==REGISTER) { + use_int(reg); 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)); regv[reg]=1; @@ -702,7 +725,8 @@ g_expr(e2); emit_push(); xrn = register_name((e2=emit_pop(0)),0); - printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(creg,0)); + use_int(reg); + 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); } @@ -711,6 +735,7 @@ void code_return(int creg) { + use_int(creg); printf("\tleal _%d,%s\n",retcont,register_name(creg,0)); regv[creg]=1; } @@ -718,6 +743,7 @@ void code_environment(int creg) { + use_int(creg); printf("\tmovl %%ebp,%s\n",register_name(creg,0)); regv[creg]=1; } @@ -728,13 +754,14 @@ char *xrn; int e2,e3; b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */ - xrn = register_name(creg,0); + use_int(reg); + xrn = register_name(reg,0); printf("\txorl %s,%s\n",xrn,xrn); jmp(e3=fwdlabel()); fwddef(e2); printf("\tmovl $1,%s\n",xrn); fwddef(e3); - regv[creg]=1; + regv[reg]=1; } char * @@ -764,6 +791,7 @@ void code_cmp_crgvar(int e1,int reg,int sz) { + use_int(reg); if (sz==1) printf("\tcmpb $0,%s\n",((NMTBL*)cadr(e1))->nm); else if (sz==size_of_short) @@ -773,6 +801,7 @@ void code_cmp_crlvar(int e1,int reg,int sz) { + use_int(reg); if (sz==1) printf("\tcmpb $0,%d(%%ebp)\n",lvar(e1)); else if (sz==size_of_short) @@ -782,18 +811,21 @@ void code_cmp_rgvar(int e1,int reg) { + use_int(reg); printf("\tcmpl $0,%s\n",((NMTBL*)cadr(e1))->nm); } void code_cmp_rlvar(int e1,int reg) { + use_int(reg); printf("\tcmpl $0,%d(%%ebp)\n",lvar(e1)); } void code_cmp_register(int e2) { + use_int(e2); printf("\tcmpl $0,%s\n",register_name(e2,0)); } @@ -822,6 +854,7 @@ char *s; int i,lb; + use_int(creg); if (0) { s=(char *)cadr(e1); lb=fwdlabel(); @@ -853,6 +886,8 @@ { int fix = 0; /* length <0 means upward direction copy */ + use_int(from); + use_int(to); switch (length) { case 0: break; case 1: case -1: @@ -1070,6 +1105,7 @@ void code_frame_pointer(int e3) { + use_int(e3); printf("\tmovl %s,%%ebp\n",register_name(e3,0)); } @@ -1099,7 +1135,8 @@ g_expr(e1); byte = 0; op="movl"; crn = register_name(creg,0); - printf("\t%s %d(%s),%s\n",op,offset,crn,crn); + use_int(reg); + printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0)); return us?UNSIGNED:INT; } @@ -1111,7 +1148,8 @@ g_expr(e1); byte = 0; op=us?"movzbl":"movsbl"; crn = register_name(creg,0); - printf("\t%s %d(%s),%s\n",op,offset,crn,crn); + use_int(reg); + printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0)); return us?UCHAR:CHAR; } @@ -1123,7 +1161,8 @@ g_expr(e1); byte = 0; op=us?"movzwl":"movswl"; crn = register_name(creg,0); - printf("\t%s %d(%s),%s\n",op,offset,crn,crn); + use_int(reg); + printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0)); return us?USHORT:SHORT; } @@ -1153,23 +1192,28 @@ void code_assign_gvar(int e2,int creg,int byte) { + use_int(creg); if (byte) use_data_reg(creg,1); printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),((NMTBL*)cadr(e2))->nm); } void code_assign_lvar(int e2,int creg,int byte) { + use_int(creg); if (byte) use_data_reg(creg,1); printf("\t%s %s,%d(%%ebp)\n",move(byte),register_name(creg,byte),lvar(e2)); } void code_assign_register(int e2,int byte,int creg) { + use_int(creg); printf("\tmovl %s,%s\n",register_name(creg,0),register_name(e2,0)); } void code_assign(int e2,int byte,int creg) { + use_int(e2); + use_int(creg); if (byte) use_data_reg(creg,1); printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte),register_name(e2,0)); regv[creg]=1; @@ -1192,13 +1236,14 @@ char *xrn; int xreg; int edx = edx_setup(); + use_int(reg); xrn = register_name(xreg = emit_pop(0),0); /* pop e3 value */ regv[xreg]=regs[xreg]=1; - printf("\tmovl %s,%s # assop \n",register_name(creg,0),register_name(edx,0)); + printf("\tmovl %s,%s # assop \n",register_name(reg,0),register_name(edx,0)); regv[edx]=1; - ld_indexx(byte,0,edx,sign); + ld_indexx(byte,0,edx,reg,sign); tosop(op,reg,xreg); - printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte),register_name(edx,0)); + printf("\t%s %s,(%s)\n",move(byte),register_name(reg,byte),register_name(edx,0)); edx_cleanup(); emit_pop_free(xreg); regv[creg]=1; @@ -1210,19 +1255,20 @@ { int dx; char *orn,*crn; + use_int(reg); switch(op) { case LSHIFT: case ULSHIFT: - shift("sall",oreg); + shift("sall",oreg,reg); regv[creg]=1; return; case RSHIFT: - shift("sarl",oreg); + shift("sarl",oreg,reg); regv[creg]=1; return; case URSHIFT: - shift("shrl",oreg); + shift("shrl",oreg,reg); regv[creg]=1; return; } @@ -1275,7 +1321,7 @@ use_register(creg,REG_EAX,1); edx_setup(); orn = register_name(oreg,0); - if (op==DIV) + if (op==MOD) printf("\tcltd\n\tidivl %s\n",orn); else printf("\txor %%edx,%%edx\n\tdivl %s\n",orn); @@ -1303,7 +1349,9 @@ void oprtc(int op,int reg,int orn) { - char *crn = register_name(creg,0); + char *crn; + use_int(reg); + crn = register_name(reg,0); switch(op) { case LSHIFT: @@ -1373,8 +1421,9 @@ } void -shift(char *op, int reg) +shift(char *op, int reg,int creg) { + use_int(creg); if (reg>=0) { use_register(reg,REG_ECX,1); } else if (reg<= -REG_LVAR_OFFSET) { @@ -1391,17 +1440,18 @@ } void -ld_indexx(int byte, int n, int xreg,int sign) +ld_indexx(int byte, int n, int xreg,int reg,int sign) { char *op; + use_int(reg); op = byte ? (sign?"movsbl":"movzbl") : "movl"; if (n) printf("\t%s %d(%s),%s\n",op,n, - register_name(xreg,0),register_name(creg,byte)); + register_name(xreg,0),register_name(reg,byte)); else printf("\t%s (%s),%s\n",op, - register_name(xreg,0),register_name(creg,byte)); + register_name(xreg,0),register_name(reg,byte)); } int @@ -1844,8 +1894,9 @@ printf("\tfchs\n"); } -void code_d2i(int freg) +void code_d2i() { + use_int0(); printf("\tlea -%d(%%esp),%%esp\n",size_of_int*2); printf("\tfnstcw (%%esp)\n"); printf("\tmovl (%%esp), %s\n",register_name(creg,0)); @@ -1858,15 +1909,16 @@ printf("\tpopl %s\n",register_name(creg,0)); } -void code_i2d(int creg) +void code_i2d() { printf("\tpushl %s\n",register_name(creg,0)); printf("\tfildl (%%esp)\n"); printf("\tlea %d(%%esp),%%esp\n",size_of_int); } -void code_d2u(int freg) +void code_d2u() { + use_int0(); printf("\tlea -%d(%%esp),%%esp\n",size_of_int*3); printf("\tfnstcw (%%esp)\n"); printf("\tmovl (%%esp), %s\n",register_name(creg,0)); @@ -1879,7 +1931,7 @@ printf("\tlea %d(%%esp),%%esp\n",size_of_int*3); } -void code_u2d(int creg) +void code_u2d() { printf("\tpushl %s\n",register_name(creg,0)); printf("\tpushl %s\n",register_name(creg,0)); @@ -1888,12 +1940,12 @@ printf("\tlea %d(%%esp),%%esp\n",size_of_int*2); } -void code_d2f(int freg) { } -void code_f2d(int freg) { } -void code_f2i(int freg) { code_d2i(freg); } -void code_f2u(int freg) { code_d2u(freg); } -void code_i2f(int creg) { code_i2d(creg); } -void code_u2f(int creg) { code_u2d(creg); } +void code_d2f() { } +void code_f2d() { } +void code_f2i() { code_d2i(); } +void code_f2u() { code_d2u(); } +void code_i2f() { code_i2d(); } +void code_u2f() { code_u2d(); } void code_drgvar(int e2,int d,int freg) { @@ -2034,7 +2086,13 @@ void code_cmp_dregister(int e2,int d) { - error(-1); + if (e2!=USE_CREG) + error(-1); + printf("\tfldz\n"); return; + printf("\tfucompp\n"); + printf("\tfnstsw\t%%ax\n"); + printf("\tandb\t$69,%%ah\n"); + printf("\txorb\t$64,%%ah\n"); } int pop_fregister() @@ -2218,12 +2276,13 @@ void code_i2ll() { + use_int0(); } void code_i2ull() { - + code_i2ll(); } void code_u2ll() @@ -2233,7 +2292,7 @@ void code_u2ull() { - + code_u2ll(); } void code_ll2i() diff -r eccea7c904ee -r c575422d8b6e mc.h --- a/mc.h Thu Apr 29 19:40:43 2004 +0900 +++ b/mc.h Thu Apr 29 23:33:02 2004 +0900 @@ -11,7 +11,7 @@ #endif #define FLOAT_CODE 1 -#define LONGLONG_CODE 1 +#define LONGLONG_CODE 0 #define SIZE_INT 4 diff -r eccea7c904ee -r c575422d8b6e test/code-gen.c --- a/test/code-gen.c Thu Apr 29 19:40:43 2004 +0900 +++ b/test/code-gen.c Thu Apr 29 23:33:02 2004 +0900 @@ -2,7 +2,7 @@ /* $Id$ */ #define FLOAT_CODE 1 -#define LONGLONG_CODE 1 +#define LONGLONG_CODE 0 // code_lvar(int e2,int creg) @@ -68,15 +68,15 @@ { i1 = 1; i2 = -2; s1 = -1; s2 = -3; us1 = 65535; us2 = 65535; - printf("code_gvar %d %d %u %u %u %u\n",i1,i2,s1,s2,us1,us2); + printf("code_gvar a %d %d %u %u %u %u\n",i1,i2,s1,s2,us1,us2); c1 = -1; c2 = -3; uc1 = 200; uc2 = 202; - printf("code_gvar %d %d %u %u\n",c1,c2,uc1,uc2); + printf("code_gvar b %d %d %u %u\n",c1,c2,uc1,uc2); s_i1 = 1; s_i2 = 2; s_s1 = -1; s_s2 = -3; s_us1 = 65535; s_us2 = 65535; - printf("code_gvar %d %d %u %u %u %u\n",s_i1,s_i2,s1,s_s2,s_us1,s_us2); + printf("code_gvar c %d %d %u %u %u %u\n",s_i1,s_i2,s1,s_s2,s_us1,s_us2); s_c1 = -1; s_c2 = -3; s_uc1 = 200; s_uc2 = 202; - printf("code_gvar %d %d %u %u\n",s_c1,s_c2,s_uc1,s_uc2); + printf("code_gvar d %d %d %u %u\n",s_c1,s_c2,s_uc1,s_uc2); } // code_register(int e2,int creg) @@ -92,9 +92,9 @@ i1 = 1; i2 = -2; s1 = -1; s2 = -3; us1 = 65535; us2 = 65535; - printf("code_lvar %d %d %u %u %u %u\n",i1,i2,s1,s2,us1,us2); + printf("code_lvar r %d %d %u %u %u %u\n",i1,i2,s1,s2,us1,us2); c1 = -1; c2 = -3; uc1 = 200; uc2 = 202; - printf("code_gvar %d %d %u %u\n",c1,c2,uc1,uc2); + printf("code_gvar r %d %d %u %u\n",c1,c2,uc1,uc2); } // code_fname(NMTBL *n,int creg) diff -r eccea7c904ee -r c575422d8b6e test/code-gen.pl --- a/test/code-gen.pl Thu Apr 29 19:40:43 2004 +0900 +++ b/test/code-gen.pl Thu Apr 29 23:33:02 2004 +0900 @@ -7,6 +7,8 @@ { if (/^\w+\(/) { print "\t$&",");\n"; + } elsif (/^#/) { + print; } } print "return 1; }\n";