Mercurial > hg > CbC > old > device
changeset 271:e1a96bdbe527
MIPS continue...
author | kono |
---|---|
date | Wed, 19 May 2004 21:15:04 +0900 |
parents | 0c6bf0e3e475 |
children | 40266d044d97 |
files | .gdbinit.mips Changes mc-code-mips.c mc-code-powerpc.c mc-parse.c test/ifdef.c |
diffstat | 6 files changed, 157 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit.mips Wed May 19 12:13:00 2004 +0900 +++ b/.gdbinit.mips Wed May 19 21:15:04 2004 +0900 @@ -4,7 +4,7 @@ run -s test/code-gen-all.c define regs printf "pc =%08x fp =%08x r2 =%08x r3 =%08x r4= %08x r5= %08x\n",$pc,$fp,$v0,$v1,$a0,$a1 -printf "r5 =%08x r6 =%08x r7 =%08x r8 =%08x r9 =%08x r10=%08x\n",$a2,$a3,$t0,$t1,$t2,$t3 +printf "r6 =%08x r7 =%08x r8 =%08x r9 =%08x r10=%08x r11=%08x\n",$a2,$a3,$t0,$t1,$t2,$t3 end define fregs printf "f0=%g f1=%g f2=%g f3=%g f4=%g f5=%g f6=%g\n",$f0,$f1,$f2,$f3,$f4,$f5,$f6
--- a/Changes Wed May 19 12:13:00 2004 +0900 +++ b/Changes Wed May 19 21:15:04 2004 +0900 @@ -4319,3 +4319,23 @@ なんかレジスタセーブがぼろぼろじゃん。max_reg_var とかが、 ちゃんとレジスタの個数を表すようにしろよ。 + +Wed May 19 13:49:40 JST 2004 + +endian に関するコードは、ちゃんとソースにそう書いた方が良いね。 + +やぁ、なんかEndianが合わないよ。ぜんぜん。 + +printf に $6,$7 と同じ値を渡しているのに、 + + diff test/code-gen-all.gcc.out test/code-gen-all.mc-mips.out + 53,54c53,54 + < code_lrindirect ffffffffffffffc9 37 c8 80 + < code_lrindirect -55 55 200 128 + --- + > code_lrindirect 37ffffffc9 37 c8 80 + > code_lrindirect 240518168521 55 200 128 + +となるのはなんでだろう? 37 が overwrite されているのか。 +でも、37のポジションは正しいんだよな。37自体はレジスタには +乗ってないし。
--- a/mc-code-mips.c Wed May 19 12:13:00 2004 +0900 +++ b/mc-code-mips.c Wed May 19 21:15:04 2004 +0900 @@ -121,12 +121,12 @@ #define RET_LREGISTER (LREG_OFFSET+REAL_MAX_LREGISTER) #define LREGISTER_OPERAND (LREG_OFFSET +REAL_MAX_LREGISTER +1) #define LREGISTER_OPERAND_1 (LREG_OFFSET +REAL_MAX_LREGISTER +2) -#define RET_LREGISTER_H 2 /* high word */ -#define RET_LREGISTER_L 3 /* low word */ -#define LREGISTER_OPERAND_H 4 /* high word */ -#define LREGISTER_OPERAND_L 5 /* low word */ -#define LREGISTER_OPERAND_1_H 6 /* high word */ -#define LREGISTER_OPERAND_1_L 7 /* low word */ +#define RET_LREGISTER_L 2 /* low word */ +#define RET_LREGISTER_H 3 /* high word */ +#define LREGISTER_OPERAND_L 4 /* low word */ +#define LREGISTER_OPERAND_H 5 /* high word */ +#define LREGISTER_OPERAND_1_L 6 /* low word */ +#define LREGISTER_OPERAND_1_H 7 /* high word */ #define RET_DREGISTER RET_LREGISTER #define DREGISTER_OPERAND LREGISTER_OPERAND @@ -304,7 +304,7 @@ */ #define arg_offset 8 #define arg_offset1 0 -#define disp_offset 8 +#define disp_offset 0 #define func_disp_offset 8 #define code_disp_offset 0 @@ -400,14 +400,13 @@ { int reg; macro_define("__STDC__ 1\n"); - macro_define("size_t int\n"); + macro_define("__SIZE_TYPE__ int\n"); + macro_define("__WCHAR_TYPE__ int\n"); macro_define("__mips__ 1\n"); macro_define("__LITTLE_ENDIAN__ 1\n"); macro_define("__externsion__\n"); macro_define("__flexarr\n"); macro_define("__builtin_va_list int*\n"); - macro_define("wchar_t int\n"); - macro_define("__gnuc_va_list int*\n"); init_ptr_cache(); reg=RET_LREGISTER; @@ -738,8 +737,13 @@ if (i<0||i>=MAX_INPUT_REGISTER_VAR) return 0; i = i+MIN_TMP_REG; } +#if ENDIAN==0 + regv_l(ll)=i; + regv_h(ll)=i+1; +#else regv_h(ll)=i; regv_l(ll)=i+1; +#endif } else { error(-1); ll=LREG_OFFSET+2; } return list3(LREGISTER,ll,(int)n); } @@ -1595,10 +1599,14 @@ // save_stack,clear_ptr_cache is assumed if (!is_longlong_reg(reg)) { error(-1); return; } if (mode) { - if (regv_l(reg)!=6) - printf("\tmove $6,%s\n", lregister_name_high(reg)); - if (regv_l(reg)!=7) - printf("\tmove $7,%s\n", lregister_name_low(reg)); + if (regv_h(reg)!=DREGISTER_OPERAND_1_H) { + printf("\tmove %s,%s\n", + lregister_name_high(DREGISTER_OPERAND_1),lregister_name_high(reg)); + } + if (regv_l(reg)!=DREGISTER_OPERAND_1_L) { + printf("\tmove %s,%s\n", + lregister_name_low(DREGISTER_OPERAND_1),lregister_name_low(reg)); + } } } @@ -1693,7 +1701,7 @@ return (e3==FUNCTION||e3==CONV||e3==RSTRUCT||e3==STASS|| ((e3/100==LOP/100)&&(e3==LDIV||e3==LUDIV||e3==LMOD||e3==LUMOD|| e3==LLSHIFT||e3==LULSHIFT||e3==LRSHIFT||e3==LURSHIFT))|| - ((e3/100==DOP/100)&&(e3==DDIV||e3==DADD||e3==DSUB||e3==DMUL|| + ((e3/100==DOP/100)&&(e3==DDIV||e3==DADD||e3==DSUB||e3==DMUL||e3==DMINUS|| e3== DPOSTINC || e3==DPREINC || e3==DASSOP || e3== DOP+LT || e3== DOP+LE || e3== DOP+GT || e3== DOP+GE || e3== DOP+EQ || e3== DOP+NEQ))); @@ -1788,7 +1796,7 @@ } } -static void +static int compute_complex_arg(int e3,int reg_arg_list,int arg) { int t=caddr(e3); int e4 = car(e3); @@ -1798,6 +1806,7 @@ car(arg)==FREGISTER||car(arg)==LREGISTER) use_input_reg(cadr(arg),1); car(e3) = arg; + return reg_arg_list; } #define round4(i) ((i+(SIZE_OF_INT-1))&~(SIZE_OF_INT-1)) @@ -1820,12 +1829,6 @@ error(TYERR); nargs ++ ; } - if (*preg_arg==0 && cadr(e3)) { // MIPS oddy - t=caddr(cadr(e3)); - if (t==LONGLONG||t==ULONGLONG||t==DOUBLE) { - reg_arg++; - } - } *pnargs += nargs; *preg_arg += reg_arg; *pfreg_arg += freg_arg; @@ -1845,7 +1848,8 @@ } else return get_input_register_var(reg_arg,0,0); } else if (t==LONGLONG||t==ULONGLONG) { - if (reg_arg==1) reg_arg=2; // MIPS oddy + if (reg_arg%2==1) reg_arg++; // alignment + if (nargs%2==1) nargs++; // alignment if (mode==AS_SAVE) { return get_lregister_var(0); } else if (reg_arg+1>=MAX_INPUT_REGISTER_VAR) { @@ -1860,7 +1864,8 @@ } else return get_input_dregister_var(freg_arg,0,0,0); } else if (t==DOUBLE) { - if (reg_arg==1) reg_arg=2; // MIPS oddy + if (reg_arg%2==1) reg_arg++; // alignment + if (nargs%2==1) nargs++; // alignment if (mode==AS_SAVE) { return get_dregister_var(0,1); } else if (reg_arg+1>=MAX_INPUT_DREGISTER_VAR) { @@ -1929,7 +1934,7 @@ if (complex_) { arg = get_input_arg(caddr(complex_),AS_SAVE, pnargs,preg_arg,pfreg_arg); - compute_complex_arg(complex_,reg_arg_list,arg); + reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); } pnargs=nargs;preg_arg=reg_arg;pfreg_arg=freg_arg; complex_ = e3; @@ -1971,7 +1976,7 @@ if (complex_) { arg = get_input_arg(caddr(complex_),AS_SAVE, pnargs,preg_arg,pfreg_arg); - compute_complex_arg(complex_,reg_arg_list,arg); + reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); } for(stargs=reverse0(stargs);stargs;stargs = cadr(stargs)) { e3 = car(stargs); @@ -1985,7 +1990,7 @@ // last complex argument can use input register if (complex_) { arg = get_input_arg(caddr(complex_),AS_ARG,pnargs,preg_arg,pfreg_arg); - compute_complex_arg(complex_,reg_arg_list,arg); + reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); car(complex_) = 0; // done. } } @@ -2045,6 +2050,7 @@ reg_arg_list = list2(arg,reg_arg_list); if (car(arg)==DREGISTER) use_input_reg(cadr(arg),1); + g_expr_u(assign_expr0(arg,e4,t,t)); } else if (t==FLOAT) { reg_arg_list = list2(arg,reg_arg_list); if (car(arg)==FREGISTER) { @@ -2197,6 +2203,15 @@ lload(int creg,int reg,int offset) { char *crn=register_name(creg); +#if ENDIAN==0 + if (creg!=regv_l(reg)) { + printf("\tlw %s,%d(%s)\n",lregister_name_low(reg),offset,crn); + printf("\tlw %s,%d(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); + } else { + printf("\tlw %s,%d(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); + printf("\tlw %s,%d(%s)\n",lregister_name_low(reg),offset,crn); + } +#else if (creg!=regv_h(reg)) { printf("\tlw %s,%d(%s)\n",lregister_name_high(reg),offset,crn); printf("\tlw %s,%d(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); @@ -2204,6 +2219,7 @@ printf("\tlw %s,%d(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); printf("\tlw %s,%d(%s)\n",lregister_name_high(reg),offset,crn); } +#endif } #if LONGLONG_CODE @@ -2800,9 +2816,10 @@ disp &= -SIZE_OF_INT; lvar_offsetv = round16(-disp) + - round16((max_func_args<2?2:max_func_args)*SIZE_OF_INT); + round16((max_func_args<2?2:max_func_args)*SIZE_OF_INT) + + 2*SIZE_OF_INT; r1_offsetv = lvar_offsetv + arg_offset + SIZE_OF_INT*2 + - max_reg_var*SIZE_OF_INT+max_freg_var*SIZE_OF_FLOAT+2*SIZE_OF_INT; + max_reg_var*SIZE_OF_INT+max_freg_var*SIZE_OF_FLOAT+2*SIZE_OF_INT ; fprintf(asi,"$L_%d=%d\n",r1_offset_label,r1_offsetv); fprintf(asi,"$L_%d=%d\n",lvar_offset_label,lvar_offsetv); @@ -3214,8 +3231,13 @@ use_float(d,freg); if (d) { +#if ENDIAN==0 + printf("\tli %s,0x%x\n",lregister_name_low(freg),code_d1(value)); + printf("\tli %s,0x%x\n",lregister_name_high(freg),code_d2(value)); +#else printf("\tli %s,0x%x\n",lregister_name_high(freg),code_d1(value)); printf("\tli %s,0x%x\n",lregister_name_low(freg),code_d2(value)); +#endif } else { frn = fregister_name(freg); printf("\tli.s %s,%g\n",frn,value); @@ -3236,10 +3258,11 @@ printf("\tmove $5,$0\n"); /// set_dreg_operand(oreg,1); extern_conv("dpsub"); + set_dreg(RET_DREGISTER,0); return; } frn = fregister_name(freg); - printf("\tfneg %s,%s\n",frn,frn); + printf("\tneg.s %s,%s\n",frn,frn); } void @@ -3798,12 +3821,12 @@ switch(op) { case DOP+GT: printf("\tbgez\t$2,$L_%d\n",l1);break; case FOP+GT: printf("\tbc1t\t$L_%d\n",l1);break; - case DOP+GE: printf("\tbltz\t$2,$L_%d\n",l1);break; + case DOP+GE: printf("\tbgtz\t$2,$L_%d\n",l1);break; case FOP+GE: printf("\tbc1t\t$L_%d\n",l1);break; case DOP+EQ: printf("\tbeq\t$2,$0,$L_%d\n",l1);break; case FOP+EQ: printf("\tbc1t\t$L_%d\n",l1);break; case DOP+NEQ: printf("\tbne\t$2,$0,$L_%d\n",l1);break; - case FOP+NEQ: printf("\tbc1t\t$L_%d\n",l1);break; + case FOP+NEQ: printf("\tbc1f\t$L_%d\n",l1);break; } } @@ -3933,7 +3956,7 @@ case LOP+GT: pcond(op,code_gt(cond),l1); break; case LOP+GE: - pcond(op,code_ge(cond),l1); break; + pcond(op,code_ge(!cond),l1); break; case LOP+EQ: pcond(op,code_eq(cond),l1); break; case LOP+NEQ: @@ -3954,7 +3977,7 @@ case LOP+GT: pcond(op,code_gt(cond),l1); break; case LOP+GE: - pcond(op,code_ge(cond),l1); break; + pcond(op,code_ge(!cond),l1); break; case LOP+EQ: pcond(op,code_eq(cond),l1); break; case LOP+NEQ: @@ -4051,14 +4074,13 @@ use_longlong(creg); crn_h = lregister_name_high(creg); crn_l = lregister_name_low(creg); - - if (e2==regv_h(creg)) { - printf("\tsw %s,%d(%s)\n",crn_l,SIZE_OF_INT,drn); - printf("\tsw %s,0(%s)\n",crn_h,drn); - } else { - printf("\tsw %s,0(%s)\n",crn_h,drn); - printf("\tsw %s,%d(%s)\n",crn_l,SIZE_OF_INT,drn); - } +#if ENDIAN==0 + printf("\tsw %s,0(%s)\n",crn_l,drn); + printf("\tsw %s,%d(%s)\n",crn_h,SIZE_OF_INT,drn); +#else + printf("\tsw %s,0(%s)\n",crn_h,drn); + printf("\tsw %s,%d(%s)\n",crn_l,SIZE_OF_INT,drn); +#endif } void @@ -4079,8 +4101,13 @@ crn_h = lregister_name_high(creg); crn_l = lregister_name_low(creg); lvar_intro(e2); +#if ENDIAN==0 + printf("\tsw %s,",crn_l);lvar(e2); + printf("\tsw %s,",crn_h);lvar(e2+SIZE_OF_INT); +#else printf("\tsw %s,",crn_h);lvar(e2); printf("\tsw %s,",crn_l);lvar(e2+SIZE_OF_INT); +#endif } void @@ -4112,8 +4139,13 @@ code_lconst(int e1,int creg) { use_longlong(creg); +#if ENDIAN==0 + code_const(code_l1(lcadr(e1)),regv_l(creg)); + code_const(code_l2(lcadr(e1)),regv_h(creg)); +#else code_const(code_l1(lcadr(e1)),regv_h(creg)); code_const(code_l2(lcadr(e1)),regv_l(creg)); +#endif } void @@ -4158,8 +4190,8 @@ crn_h = lregister_name_high(creg); crn_l = lregister_name_low(creg); lvar_intro(e1); - printf("\tlw %s,",crn_h); lvar(e1); - printf("\tlw %s,",crn_l); lvar(e1+SIZE_OF_INT); + printf("\tlw %s,",crn_l); lvar(e1); + printf("\tlw %s,",crn_h); lvar(e1+SIZE_OF_INT); }
--- a/mc-code-powerpc.c Wed May 19 12:13:00 2004 +0900 +++ b/mc-code-powerpc.c Wed May 19 21:15:04 2004 +0900 @@ -1700,7 +1700,7 @@ if (mode) use_reg(reg); } -static void +static int compute_complex_arg(int e3,int reg_arg_list,int arg) { int t=caddr(e3); int e4 = car(e3); @@ -1710,6 +1710,7 @@ car(arg)==FREGISTER||car(arg)==LREGISTER) use_input_reg(cadr(arg),1); car(e3) = arg; + return reg_arg_list; } static void @@ -1834,7 +1835,7 @@ if (complex_) { arg = get_input_arg(caddr(complex_),AS_SAVE, pnargs,preg_arg,pfreg_arg); - compute_complex_arg(complex_,reg_arg_list,arg); + reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); } pnargs=nargs;preg_arg=reg_arg;pfreg_arg=freg_arg; complex_ = e3; @@ -1876,7 +1877,7 @@ if (complex_) { arg = get_input_arg(caddr(complex_),AS_SAVE, pnargs,preg_arg,pfreg_arg); - compute_complex_arg(complex_,reg_arg_list,arg); + reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); } for(stargs=reverse0(stargs);stargs;stargs = cadr(stargs)) { e3 = car(stargs); @@ -1890,7 +1891,7 @@ // last complex argument can use input register if (complex_) { arg = get_input_arg(caddr(complex_),AS_ARG,pnargs,preg_arg,pfreg_arg); - compute_complex_arg(complex_,reg_arg_list,arg); + reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); } } @@ -3624,13 +3625,8 @@ crn_h = lregister_name_high(creg); crn_l = lregister_name_low(creg); - if (e2==regv_h(creg)) { - printf("\tstw %s,%d(%s)\n",crn_l,SIZE_OF_INT,drn); - printf("\tstw %s,0(%s)\n",crn_h,drn); - } else { - printf("\tstw %s,0(%s)\n",crn_h,drn); - printf("\tstw %s,%d(%s)\n",crn_l,SIZE_OF_INT,drn); - } + printf("\tstw %s,0(%s)\n",crn_h,drn); + printf("\tstw %s,%d(%s)\n",crn_l,SIZE_OF_INT,drn); } void
--- a/mc-parse.c Wed May 19 12:13:00 2004 +0900 +++ b/mc-parse.c Wed May 19 21:15:04 2004 +0900 @@ -82,7 +82,7 @@ static void local_define(); static void local_undef(); static void macro_define0(); -static void macro_processing(); +static int macro_processing(); static void check_macro_eof(); static void newfile(void); static void replace_return_struct(int func,int left); @@ -2605,8 +2605,9 @@ getsym(0); e=rvalue(expr13()); #if FLOAT_CODE - if(type==FLOAT||type==DOUBLE) { - // return list2(DMINUS,e); + if(type==FLOAT) { + return(car(e)==DCONST?dlist2(DCONST,-dcadr(e)):list2(FMINUS,e)); + } else if(type==DOUBLE) { return(car(e)==DCONST?dlist2(DCONST,-dcadr(e)):list2(DMINUS,e)); } #endif @@ -4232,6 +4233,36 @@ static int macro_if_current ; static int macro_if_skip ; +static int +skip_rest_of_line() +{ + getch(); + do { + while(ch!='\n'&&ch!='\r') { + if (!in_comment) { + if (ch=='/') { + getch(); + if (ch=='/') in_comment=2; + else if (ch=='*') { + in_comment=1; + } else continue; + } + } else if (ch=='*') { + getch(); + if (ch=='/') { + in_comment=0; + return macro_if_skip?0:1; + } + else continue; + } + getch(); + } + if (in_comment==1) { getline(); getch(); } + } while(in_comment==1); + in_comment=0; + return 0; +} + static void getline(void) { @@ -4253,7 +4284,7 @@ *chptr = '\0'; if (lsrc && !asmf && !macro_if_skip) gen_comment(linebuf); if (*(chptr = linebuf) == '#' && !in_comment) { - macro_processing(); + if (macro_processing()) return; } } while(macro_if_skip || linebuf[0] == '#'); } @@ -4305,7 +4336,7 @@ macro_if_skip = !i; } -static void +static int macro_processing() { int i; @@ -4325,37 +4356,37 @@ macro_if_depth = macro_if_current; macro_if_skip = (!i)^c; } - return; + return 0; } else if (macroeq("elif")) { if (macro_if_current==0) { error(MCERR); /* extra #else */ - return; + return 0; } if (macro_if_current == macro_if_depth) { if (!macro_if_skip || macro_if_skip==2) { macro_if_skip=2; - return; + return 0; } macro_if(); } - return; + return 0; } else if (macroeq("if")) { macro_if_current++; if (!macro_if_skip) { macro_if(); } - return; + return 0; } else if (macroeq("else")) { if (macro_if_current==0) { error(MCERR); /* extra #else */ - return; + return 0; } if (macro_if_current == macro_if_depth) { if (macro_if_skip==2) ; else if (macro_if_skip) macro_if_skip=0; else macro_if_skip=1; } - return; + return skip_rest_of_line(); } else if (macroeq("endif")) { if (macro_if_current == macro_if_depth) { macro_if_skip = 0; @@ -4363,13 +4394,13 @@ } else { if (macro_if_current<=0) { error(MCERR); /* extra #if */ - return; + return 0; } macro_if_current--; } - return; + return skip_rest_of_line(); } - if (macro_if_skip) return; + if (macro_if_skip) return 0; if (macroeq("define")) { ch= *chptr; macro_define0(); @@ -4408,6 +4439,7 @@ } else if (macroeq(" ")) getline(); else error(MCERR); + return 0; } static int