Mercurial > hg > CbC > old > device
diff mc-codegen.c @ 83:f3f75911d62c
*** empty log message ***
author | kono |
---|---|
date | Wed, 05 Mar 2003 03:41:08 +0900 |
parents | 25654dc29ecc |
children | 1a723130a2c7 |
line wrap: on
line diff
--- a/mc-codegen.c Wed Mar 05 00:39:39 2003 +0900 +++ b/mc-codegen.c Wed Mar 05 03:41:08 2003 +0900 @@ -10,7 +10,23 @@ int dreg; /* temporary register */ int reg_sp; /* REGister Stack-Pointer */ +int rname[MAX_MAX]; +int regs[MAX_MAX]; /* 使われているレジスタを示すフラグ */ +int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ +int regv[MAX_MAX]; /* 値が入っているかどうか */ + +/* floating point registers */ + int freg; /* current floating point register */ +int greg; /* current floating point register */ +int freg_sp; /* floating point REGister Stack-Pointer */ + +int frname[MAX_MAX]; +int fregs[MAX_MAX]; /* 使われているレジスタを示すフラグ */ +int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ +int fregv[MAX_MAX]; /* 値が入っているかどうか */ + +int use; /* generated value will be used */ /* creg currrent virtual register @@ -23,6 +39,9 @@ regv[] value in virtual register flag reg_name[rname[creg]] + + freg current floating point register + fregv calue in floating point register */ void remove0(int *parent,int e) ; @@ -33,6 +52,7 @@ void sassign(int e1); void assign(int e1); void assop(int e1); +void g_expr0(int e1); int get_register(void) @@ -119,24 +139,6 @@ arg_register0(fnptr->dsp); } - -int creg_regvar = -1; -static int creg_regvar_back; -static int creg_back; - -void -creg_destroy() { - creg_back = creg; creg_regvar_back = creg_regvar; - if (creg_regvar>=0) - creg = creg_regvar; - creg_regvar=-1; -} - -void -creg_un_destroy() { - creg = creg_back; creg_regvar = creg_regvar_back; -} - void register_usage(char *s) { @@ -219,17 +221,18 @@ } void -gexpr(int e1) +gexpr(int e1,int use0) { if (chk) return; gexpr_init(); + use = use0; #if 0 if(lineno==2862) { - g_expr(e1); /*break here*/ + g_expr0(e1); /*break here*/ return; } #endif - g_expr(e1); + g_expr0(e1); } int @@ -239,9 +242,25 @@ } void +g_expr_u(int e1) +{ + int suse = use; use=0; + g_expr0(e1); + use=suse; +} + +void g_expr(int e1) { - int e2,e3/*,e4*/; + int suse = use; use=1; + g_expr0(e1); + use=suse; +} + +void +g_expr0(int e1) +{ + int e2,e3; NMTBL *n; e2 = cadr(e1); @@ -279,19 +298,19 @@ return; case FRLVAR: code_drlvar(lvar(e2),0); - regv[freg]=1; + fregv[freg]=1; return; case FRGVAR: code_drgvar(e1,0); - regv[freg]=1; + fregv[freg]=1; return; case DRLVAR: code_drlvar(lvar(e2),1); - regv[freg]=1; + fregv[freg]=1; return; case DRGVAR: code_drgvar(e1,1); - regv[freg]=1; + fregv[freg]=1; return; case FNAME: code_fname(((NMTBL *)(e2))->nm); @@ -303,7 +322,7 @@ return; case DCONST: code_dconst(e1); - regv[freg]=1; + fregv[freg]=1; return; case STRING: string(e1); @@ -317,37 +336,37 @@ jump(e2,caddr(e1)); return; case INDIRECT: - g_expr(e2); + g_expr0(e2); return; case RINDIRECT: case CRINDIRECT: case DRINDIRECT: case FRINDIRECT: rindirect(e1); return; case ADDRESS: - g_expr(e2); + g_expr0(e2); return; case MINUS: /* レジスタに対し、neglを実行すれば実現可能 */ - g_expr(e2); + g_expr0(e2); code_neg(); return; case DMINUS: - g_expr(e2); + g_expr0(e2); code_dneg(); return; case I2D: - g_expr(e2); + g_expr0(e2); code_i2d(); return; case D2I: - g_expr(e2); + g_expr0(e2); code_d2i(); return; case BNOT: /* ~ */ - g_expr(e2); + g_expr0(e2); code_not(); return; case LNOT: /* ! */ - g_expr(e2); + g_expr0(e2); code_lnot(); return; case PREINC: @@ -356,6 +375,18 @@ case POSTINC: code_postinc(e1,e2); return; + case DPREINC: + code_dpreinc(e1,e2,1); + return; + case DPOSTINC: + code_dpostinc(e1,e2,1); + return; + case FPREINC: + code_dpreinc(e1,e2,0); + return; + case FPOSTINC: + code_dpostinc(e1,e2,0); + return; case CPOSTINC: /* char *p; *p++ */ code_cpostinc(e1,e2); @@ -385,13 +416,13 @@ e2=fwdlabel(); b_expr(cadr(e1),0,e2,0); code_set_fixed_creg(0); - g_expr(caddr(e1)); + g_expr0(caddr(e1)); /* e4 = rname[creg]; this is a bad idea */ code_set_fixed_creg(1); jmp(e3=fwdlabel()); fwddef(e2); code_set_fixed_creg(0); - g_expr(cadddr(e1)); + g_expr0(cadddr(e1)); code_set_fixed_creg(1); fwddef(e3); return; @@ -411,11 +442,11 @@ dassop(e1); return; case RSTRUCT: - g_expr(e2); + g_expr0(e2); return; case COMMA: - g_expr(e2); - g_expr(caddr(e1)); + g_expr_u(e2); + g_expr0(caddr(e1)); return; case RETURN: n = (NMTBL *)e2; @@ -546,10 +577,9 @@ if((dcadr(e2)!=0.0)^cond) jmp(l1); return; default: - /* type ? */ if(err) { error(-1); return; /* recursive g_expr/b_expr */ - } + } /* type ? */ g_expr(e1); code_cmp_register(creg); jcond(l1,cond); @@ -611,11 +641,11 @@ if (sz==size_of_int && (e1=get_register())!=-1) { *use=list3(t,*use,e1); e1=list2(REGISTER,e1); - g_expr(assign_expr0(e1,s,ty,ty)); + g_expr_u(assign_expr0(e1,s,ty,ty)); *target = append4(*target,t,ty,e1); } else { disp-=sz; - g_expr(assign_expr0((e1=list2(LVAR,disp)),s,ty,ty)); + g_expr_u(assign_expr0((e1=list2(LVAR,disp)),s,ty,ty)); *target = append4(*target,t,ty,e1); } } @@ -667,7 +697,7 @@ #if DEBUG_PARALLEL_ASSIGN printf("# normal assign %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz); #endif - g_expr(assign_expr0(t,s,ty,ty)); + g_expr_u(assign_expr0(t,s,ty,ty)); remove_target(target,t,use); remove0(source,s); } else { if(circular_dependency(t,s1,target,source)) { @@ -791,7 +821,7 @@ } if (!is_simple(car(s0))) { disp-=sz; - g_expr(assign_expr0((e4=list2(LVAR,disp)),s0,ty,ty)); + g_expr_u(assign_expr0((e4=list2(LVAR,disp)),s0,ty,ty)); cadddr(e2)=e4; s0=e4; } else if (is_same_type(t0,s0)) { @@ -884,7 +914,7 @@ g_expr(e2); dtosop(car(e1),(e2=dpop_register())); emit_dpop_free(e2); - regv[freg]=1; + fregv[freg]=1; return; } @@ -1014,11 +1044,21 @@ void dassop(int e1) { -} + int e2,e3,op,d; -void -fassop(int e1) -{ + /* e2 op= e3 */ + d = (car(e1) == DASSOP); + e2 = cadr(e1); + if (car(e2)==INDIRECT) e2=cadr(e2); + e3 = caddr(e1); + op = cadddr(e1); + + g_expr(e3); + emit_dpush(); + g_expr(e2); + code_dassop(op,d); + regv[creg]=1; + return; } int