Mercurial > hg > CbC > old > device
changeset 135:4cfd24d1b929 power-pc-fix
fix power-pc basic test
author | kono |
---|---|
date | Sun, 04 May 2003 10:30:52 +0900 |
parents | 7a55819b0482 |
children | 069960078249 |
files | Changes mc-code-powerpc.c mc-codegen.c mc-parse.c |
diffstat | 4 files changed, 109 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sat May 03 15:27:00 2003 +0900 +++ b/Changes Sun May 04 10:30:52 2003 +0900 @@ -2876,3 +2876,27 @@ あと、引数の引渡しだけど、printf (...) だけ特別扱いしたら? プロトタイプがあるのを特別扱いする必要はないんじゃない? + +Sat May 3 18:38:57 JST 2003 + +わかりました。contains_in_list を修正するのを忘れているね。 +あと、get_register は、どうせ足りなくなるわけだろ? その +時はどうするの? 足りなくなるのは関数呼び出しの時だけ? +(かな?) + +だとすれば、関数呼び出しのsaveの変数を局所変数も使えるように +すれば良いだけだね。 + +Sun May 4 09:18:32 JST 2003 + +関数呼び出し時の浮動小数点を格納する、r8,r9 の扱いが +おかしい。 + +emit_push / tosop で局所変数だけは特別扱い +した方がいいんじゃない? register full だと、 + + register にload (emit_push) + register full でそれを局所変数に代入 + 演算時にregisterに再代入 + +なんかr10までなのか。何故奇数個? 整数はr8までなの?
--- a/mc-code-powerpc.c Sat May 03 15:27:00 2003 +0900 +++ b/mc-code-powerpc.c Sun May 04 10:30:52 2003 +0900 @@ -294,7 +294,7 @@ regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ return i; /* その場所を表す番号を返す */ } - /* INPUT_REG か PTR_CACHE をつぶす */ + /* PTR_CACHE をつぶす */ for(i=MAX_TMP_REG;i>MIN_TMP_REG;i--) { if (regs[i]==PTRC_REG) { clear_ptr_cache_reg(i); @@ -395,8 +395,7 @@ if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; i = REG_VAR_BASE-i; } else { - if (i<0||MAX_FREGISTER<i+MIN_TMP_FREG) return 0; - return list3(DREGISTER,i+MIN_TMP_FREG,(int)n); + if (i<0||i>=MAX_INPUT_DREGISTER_VAR) return 0; i = i+MIN_TMP_FREG; } return list3(DREGISTER,i,(int)n); @@ -409,7 +408,20 @@ if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; i = REG_VAR_BASE-i; } else { - if (i<0||MAX_REGISTER<i+MIN_TMP_REG) return 0; + if (i<0||i>=MAX_INPUT_REGISTER_VAR) return 0; + i = i+MIN_TMP_REG; + } + return list3(REGISTER,i,(int)n); +} + +int +get_input_register_var_1(int i,NMTBL *n,int is_code) +{ + if (is_code) { + if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; + i = REG_VAR_BASE-i; + } else { + if (i<0||i>=MAX_INPUT_REGISTER_VAR+1) return 0; i = i+MIN_TMP_REG; } return list3(REGISTER,i,(int)n); @@ -1237,44 +1249,6 @@ void code_save_input_registers() { -#if 0 - int args; - NMTBL *n; - int reg; - int tag; - int lvar; - int t; - /* fnptr->dsp=list4(type,fnptr->dsp,(int)n,0); */ - int reg_offset = 0; - - for(args = fnptr->dsp;args;args = cadr(args)) { - n = (NMTBL *)caddr(args); - tag = n->sc; - reg = n->dsp; - if (!n||n==&null_nptr) error(REG_ERR); - if (tag==REGISTER) { - /* regs[reg]==INPUT_REG case should be considered */ - n->dsp = new_lvar(size_of_int); - t = INT; - reg += reg_offset; /* for duplicated floating point argument */ - } else if (tag==DREGISTER) { - /* fregs[reg]==INPUT_REG case should be considered */ - n->dsp = new_lvar(size_of_double); - t = DOUBLE; - reg_offset+=2; - } else - continue; - n->sc = LVAR; - lvar = list2(LVAR,n->dsp); - g_expr_u(assign_expr0(list2(LVAR,n->dsp),list3(tag,reg,(int)n),n->ty,t)); - if (tag==REGISTER) { - free_register(reg); - } else if (tag==DREGISTER) { - free_fregister(reg); - } - } - my_func_args = 0; -#else int args; NMTBL *n; int reg; @@ -1317,7 +1291,6 @@ } } my_func_args = offset; -#endif } int @@ -1398,13 +1371,17 @@ } else { special_lvar = new_lvar(size_of_double); g_expr(assign_expr0( - (e5=list2(LVAR,special_lvar)),e4,t,t)); + (e5=list2(LVAR,special_lvar)),e4,DOUBLE,t)); reg_arg_list = list2(e5,reg_arg_list); e4 = list2(DREGISTER,freg); /* freg should not change until XXX */ } r0=get_input_register_var(reg_arg,0,0); - r1=get_input_register_var(reg_arg+1,0,0); + r1 = reg_arg+1+MIN_TMP_REG; + if (regs[r1]==PTRC_REG) clear_ptr_cache_reg(r1); + /* else if (regs[r1]) error(-1); */ + r1=get_input_register_var_1(reg_arg+1,0,0); + use_var(r0); /* protect from input register free */ use_var(r1); /* protect from input register free */ reg_arg_list = list2(r0,reg_arg_list);
--- a/mc-codegen.c Sat May 03 15:27:00 2003 +0900 +++ b/mc-codegen.c Sun May 04 10:30:52 2003 +0900 @@ -299,7 +299,9 @@ (op==GT|| op==UGT|| op==GE|| op==UGE|| op==LT|| \ op==ULT|| op==LE|| op==ULE|| \ op==DOP+GT|| op==DOP+GE|| op==DOP+LT|| op==DOP+LE || \ - op==EQ|| op==NEQ|| op==DOP+EQ|| op==DOP+NEQ) + op==FOP+GT|| op==FOP+GE|| op==FOP+LT|| op==FOP+LE || \ + op==FOP+EQ|| op==FOP+NEQ || \ + op==EQ|| op==NEQ|| op==DOP+EQ|| op==DOP+NEQ) int rop_dual(op) @@ -316,6 +318,10 @@ if (op==DOP+GE) return DOP+LE; if (op==DOP+LT) return DOP+GT; if (op==DOP+LE) return DOP+GE; + if (op==FOP+GT) return FOP+LT; + if (op==FOP+GE) return FOP+LE; + if (op==FOP+LT) return FOP+GT; + if (op==FOP+LE) return FOP+GE; return op; } @@ -392,6 +398,26 @@ drexpr(cadr(e1),caddr(e1),l1,DOP+NEQ); return; + case FOP+GT: + drexpr(cadr(e1),caddr(e1),l1,FOP+GT); + return; + case FOP+GE: + drexpr(cadr(e1),caddr(e1),l1,FOP+GE); + return; + case FOP+LT: + drexpr(caddr(e1),cadr(e1),l1,FOP+GT); + return; + case FOP+LE: + drexpr(caddr(e1),cadr(e1),l1,FOP+GE); + return; + case FOP+EQ: + drexpr(cadr(e1),caddr(e1),l1,FOP+EQ); + return; + case FOP+NEQ: + drexpr(cadr(e1),caddr(e1),l1,FOP+NEQ); + return; + + case LAND: b_expr(e2,0,cond?(l2=fwdlabel()):l1,0); b_expr(caddr(e1),cond,l1,0); @@ -965,7 +991,7 @@ return; case FNAME: code_fname((NMTBL*)cadr(e4),reg); return; case STRING: code_string(e4,reg); return; - case DEFAULT: error(-1); + default: error(-1); } } @@ -1032,6 +1058,8 @@ if (reg!=cadr(e2)) code_dassign_fregister(cadr(e2),d,reg); return; + default: + error(-1); } g_expr(e2); code_dassign(e2,reg,d); @@ -1041,10 +1069,13 @@ if (car(e2)!=DREGISTER) error(-1); reg = cadr(e2); switch(e5) { + case FRGVAR: case DRGVAR: code_drgvar(e4,d,reg); return; + case FRLVAR: case DRLVAR: code_drlvar(cadr(e4),d,reg); return; + case FCONST: case DCONST: code_dconst(e4,reg); return; - case DEFAULT: + default: error(-1); } } @@ -1239,11 +1270,13 @@ /* unary operators */ case INDIRECT: case RINDIRECT: case CRINDIRECT: case DRINDIRECT: case FRINDIRECT: case ADDRESS: case MINUS: case DMINUS: - case I2D: case D2I: case U2D: case D2U: case BNOT: case LNOT: + case BNOT: case LNOT: case PREINC: case POSTINC: case DPREINC: case DPOSTINC: case FPREINC: case FPOSTINC: case CPOSTINC: case CPREINC: case CPOSTDEC: case CPREDEC: case RSTRUCT: + /* case I2D: case D2I: case U2D: case D2U: */ + case CONV: e = cadr(e); continue; /* biary operators */ @@ -1254,6 +1287,13 @@ case FMUL: case FDIV: case FADD: case FSUB: case FCMP: case FCMPGE: case SASS: case ASS: case CASS: case FASS: case DASS: case LASS: case ASSOP: case CASSOP: case DASSOP: case FASSOP: case COMMA: + case EQ: case NEQ: + case DOP+EQ: case DOP+NEQ: + case FOP+EQ: case FOP+NEQ: + case LT: case ULT: case LE: case ULE: + case GT: case UGT: case GE: case UGE: + case DOP+LT: case DOP+LE: case DOP+GT: case DOP+GE: + case FOP+LT: case FOP+LE: case FOP+GT: case FOP+GE: if (contains(cadr(e),type)) return 1; e = caddr(e); continue; @@ -1263,14 +1303,17 @@ if (contains(caddr(e),type)) return 1; e = cadddr(e); continue; - default: - /* nullary operators + /* nullary operators */ case GVAR: case RGVAR: case CRGVAR: case LVAR: case REGISTER: case DREGISTER: case RLVAR: case CRLVAR: case FRLVAR: case FRGVAR: case DRLVAR: case DRGVAR: - case FNAME: case CONST: case DCONST: case STRING: - case RETURN: case ENVIRONMENT: */ + case FNAME: case CONST: case DCONST: case FCONST: case STRING: + case RETURN: case ENVIRONMENT: + return 0; + default: + fprintf(stderr,"Unknown Tree ID %d\n",car(e)); + error(-1); return 0; } }
--- a/mc-parse.c Sat May 03 15:27:00 2003 +0900 +++ b/mc-parse.c Sun May 04 10:30:52 2003 +0900 @@ -1723,6 +1723,7 @@ double_value(int e2,int type) { if (car(e2)==CONST) return dlist2(DCONST,(double)cadr(e2)); + if (car(e2)==FCONST) return dlist2(DCONST,dcadr(e2)); if(type==DOUBLE) return e2; if(type==FLOAT) return list3(CONV,rvalue_t(e2,type),F2D); if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2D); @@ -1734,6 +1735,7 @@ float_value(int e2,int type) { if (car(e2)==CONST) return dlist2(FCONST,(double)cadr(e2)); + if (car(e2)==DCONST) return dlist2(FCONST,dcadr(e2)); if(type==FLOAT) return e2; if(type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2F); if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2D); @@ -1828,8 +1830,9 @@ static int expr1(void) { - int e1,e2,t,op; + int e1,e2,t,op,no_float; e1=expr2(); + no_float = 0; switch (sym) { case ASS: conv->op_(sym); @@ -1838,8 +1841,9 @@ getsym(); e2=rvalue(expr1()); return assign_expr(e1,e2,t,type); - case ADD+AS: case SUB+AS: case MUL+AS: case DIV+AS: case MOD+AS: - case RSHIFT+AS: case LSHIFT+AS: case BAND+AS: case EOR+AS: case BOR+AS: + case RSHIFT+AS: case LSHIFT+AS: case BAND+AS: case EOR+AS: case BOR+AS: case MOD+AS: + no_float = 1; + case ADD+AS: case SUB+AS: case MUL+AS: case DIV+AS: conv->op_(sym); op = sym-AS; lcheck(e1); @@ -1849,10 +1853,12 @@ if(!(integral(type)||type==FLOAT||type==DOUBLE)) error(TYERR); if (t==FLOAT) { + if (no_float) error(TYERR); e2=float_value(e2,type); type=t; - return(list4(FASSOP,e1,e2,op+DOP)); + return(list4(FASSOP,e1,e2,op+FOP)); } if (t==DOUBLE) { + if (no_float) error(TYERR); e2=double_value(e2,type); type=t; return(list4(DASSOP,e1,e2,op+DOP)); } @@ -2172,7 +2178,7 @@ e=rvalue(expr13()); if(type==FLOAT||type==DOUBLE) return(car(e)==DCONST?list2(CONST,!dcadr(e)): - list3(DOP+NEQ,list2(CONST,0),e)); + list3((type==DOUBLE?DOP:FOP)+NEQ,list2(CONST,0),e)); if(!scalar(type)) error(TYERR); return(car(e)==CONST?list2(CONST,!cadr(e)):list2(LNOT,e)); @@ -2617,7 +2623,7 @@ } if(op==GT||op==GE||op==LT||op==LE||op==EQ||op==NEQ) { type=INT; - return(list3(op+DOP,e1,e2)); + return(list3(op+dop,e1,e2)); } else if(op==ADD||op==SUB||op==MUL||op==DIV) return(list3(op+dop,e1,e2)); else {