Mercurial > hg > CbC > old > device
diff mc-codegen.c @ 147:cb7aa0089681 creg-ireg-freg
creg/ireg done for powerpc.
author | kono |
---|---|
date | Wed, 11 Jun 2003 12:26:03 +0900 |
parents | 56211702f298 |
children | 81032a1b8a5d |
line wrap: on
line diff
--- a/mc-codegen.c Fri May 23 13:55:40 2003 +0900 +++ b/mc-codegen.c Wed Jun 11 12:26:03 2003 +0900 @@ -7,13 +7,11 @@ #include "mc-code.h" int creg; /* current register */ -int freg; /* current floating point register */ int use; /* generated value will be used */ /* creg currrent virtual register - freg current floating point register */ static void remove0(int *parent,int e) ; @@ -59,6 +57,8 @@ int t; int suse = use; use=0; t=g_expr0(e1); + code_gexpr(e1); + use=suse; return t; } @@ -69,6 +69,8 @@ int t; int suse = use; use=1; t=g_expr0(e1); + code_gexpr(e1); + use=suse; return t; } @@ -79,60 +81,80 @@ int e2,e3,t,d; NMTBL *n; + code_gexpr(e1); + e2 = cadr(e1); switch (car(e1)){ case GVAR: + creg=use_int(creg); code_gvar(e1,creg); return ADDRESS; case RGVAR: + creg=use_int(creg); code_rgvar(e1,creg); return INT; case CRGVAR: + creg=use_int(creg); code_crgvar(e1,creg); return CHAR; case LVAR: + creg=use_int(creg); code_lvar(e2,creg); return ADDRESS; case REGISTER: + creg=use_int(creg); code_register(e2,creg); return INT; case DREGISTER: - code_dregister(e2,freg,1); + creg=use_double(creg); + code_dregister(e2,creg,1); return DOUBLE; case FREGISTER: - code_dregister(e2,freg,0); + creg=use_float(creg); + code_dregister(e2,creg,0); return FLOAT; case RLVAR: + creg=use_int(creg); code_rlvar(e2,creg); return INT; case CRLVAR: + creg=use_int(creg); code_crlvar(e2,creg); return CHAR; case FRLVAR: - code_drlvar(e2,0,freg); + creg=use_float(creg); + code_drlvar(e2,0,creg); return FLOAT; case FRGVAR: - code_drgvar(e1,0,freg); + creg=use_float(creg); + code_drgvar(e1,0,creg); return FLOAT; case DRLVAR: - code_drlvar(e2,1,freg); + creg=use_double(creg); + code_drlvar(e2,1,creg); return DOUBLE; case DRGVAR: - code_drgvar(e1,1,freg); + creg=use_double(creg); + code_drgvar(e1,1,creg); return DOUBLE; case FNAME: + creg=use_int(creg); code_fname((NMTBL *)(e2),creg); return ADDRESS; case CONST: /* 代入する値が0でも特別な処理はしない */ + creg=use_int(creg); code_const(e2,creg); return INT; case DCONST: - code_dconst(e1,freg,1); + creg=use_double(creg); + code_dconst(e1,creg,1); return DOUBLE; case FCONST: - code_dconst(e1,freg,0); + creg=use_float(creg); + code_dconst(e1,creg,0); return FLOAT; case STRING: + creg=use_int(creg); code_string(e1,creg); return ADDRESS; case FUNCTION: @@ -155,24 +177,24 @@ g_expr0(e2); code_neg(creg); return INT; case DMINUS: - g_expr0(e2); code_dneg(freg,1); + g_expr0(e2); code_dneg(creg,1); return DOUBLE; case FMINUS: - g_expr0(e2); code_dneg(freg,0); + g_expr0(e2); code_dneg(creg,0); return FLOAT; case CONV: g_expr0(e2); switch(caddr(e1)) { - case I2D: code_i2d(creg,freg); return DOUBLE; - case D2I: code_d2i(freg,creg); return INT; - case U2D: code_u2d(creg,freg); return DOUBLE; - case F2U: code_f2u(freg,creg); return UNSIGNED; - case I2F: code_i2f(creg,freg); return FLOAT; - case F2I: code_f2i(freg,creg); return INT; - case U2F: code_u2f(creg,freg); return FLOAT; - case D2U: code_d2u(freg,creg); return UNSIGNED; - case D2F: code_d2f(freg); return FLOAT; - case F2D: code_f2d(freg); return DOUBLE; + case I2D: code_i2d(creg); return DOUBLE; + case D2I: code_d2i(creg); return INT; + case U2D: code_u2d(creg); return DOUBLE; + case F2U: code_f2u(creg); return UNSIGNED; + case I2F: code_i2f(creg); return FLOAT; + case F2I: code_f2i(creg); return INT; + case U2F: code_u2f(creg); return FLOAT; + case D2U: code_d2u(creg); return UNSIGNED; + case D2F: code_d2f(creg); return FLOAT; + case F2D: code_f2d(creg); return DOUBLE; default: error(-1); return INT; } @@ -183,34 +205,44 @@ g_expr0(e2); code_lnot(creg); return INT; case PREINC: + creg=use_int(creg); code_preinc(e1,e2,creg); return INT; case POSTINC: + creg=use_int(creg); code_postinc(e1,e2,creg); return INT; - case DPREINC: - code_dpreinc(e1,e2,1,freg); + case DPREINC: /* ++d */ + creg=use_double(creg); + code_dpreinc(e1,e2,1,creg); return DOUBLE; - case DPOSTINC: - code_dpostinc(e1,e2,1,freg); + case DPOSTINC: /* d++ */ + creg=use_double(creg); + code_dpostinc(e1,e2,1,creg); return DOUBLE; - case FPREINC: - code_dpreinc(e1,e2,0,freg); + case FPREINC: /* ++f */ + creg=use_float(creg); + code_dpreinc(e1,e2,0,creg); return FLOAT; - case FPOSTINC: - code_dpostinc(e1,e2,0,freg); + case FPOSTINC: /* f++ */ + creg=use_float(creg); + code_dpostinc(e1,e2,0,creg); return FLOAT; case CPOSTINC: /* char *p; *p++ */ + creg=use_int(creg); code_cpostinc(e1,e2,creg); return CHAR; case CPREINC: + creg=use_int(creg); code_cpreinc(e1,e2,creg); return CHAR; case CPOSTDEC: + creg=use_int(creg); code_cpostdec(e1,e2,creg); return CHAR; case CPREDEC: + creg=use_int(creg); code_cpredec(e1,e2,creg); return CHAR; case MUL: case UMUL: @@ -218,16 +250,19 @@ case MOD: case UMOD: case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT: case ADD: case SUB: case BAND: case EOR: case BOR: case CMP: + creg=use_int(creg); machinop(e1); return INT; case DMUL: case DDIV: case DADD: case DSUB: case DCMP: case DCMPGE: + creg=use_double(creg); dmachinop(e1,1); return DOUBLE; case FMUL: case FDIV: case FADD: case FSUB: case FCMP: case FCMPGE: + creg=use_float(creg); dmachinop(e1,0); return FLOAT; case COND: @@ -280,12 +315,14 @@ g_expr_u(e2); return g_expr0(caddr(e1)); case RETURN: + creg = use_int(creg); n = (NMTBL *)e2; if (retcont==0) retcont=fwdlabel(); code_return(creg); return VOID; case ENVIRONMENT: + creg = use_int(creg); code_environment(creg); return ADDRESS; default: @@ -428,46 +465,57 @@ if(!cond) fwddef(l2); return; case CRGVAR: + creg=use_int(creg); code_cmp_crgvar(e1); jcond(l1,cond); return; case CRLVAR: + creg=use_int(creg); code_cmp_crlvar(e2); jcond(l1,cond); return; case RGVAR: + creg=use_int(creg); code_cmp_rgvar(e1); jcond(l1,cond); return; case RLVAR: + creg=use_int(creg); code_cmp_rlvar(e2); jcond(l1,cond); return; case DRLVAR: + creg=use_double(creg); code_cmp_drlvar(e2,1); jcond(l1,cond); return; case FRLVAR: + creg=use_float(creg); code_cmp_drlvar(e2,0); jcond(l1,cond); return; case DRGVAR: + creg=use_double(creg); code_cmp_drgvar(e2,1); jcond(l1,cond); return; case FRGVAR: + creg=use_float(creg); code_cmp_drgvar(e2,0); jcond(l1,cond); return; case REGISTER: + creg=use_int(creg); code_cmp_register(e2); jcond(l1,cond); return; case FREGISTER: + creg=use_float(creg); code_cmp_dregister(e2,0); jcond(l1,cond); return; case DREGISTER: + creg=use_double(creg); code_cmp_dregister(e2,1); jcond(l1,cond); return; @@ -484,9 +532,9 @@ } t=g_expr(e1); if(t==FLOAT) - code_cmp_dregister(freg,0); + code_cmp_dregister(creg,0); else if(t==DOUBLE) - code_cmp_dregister(freg,1); + code_cmp_dregister(creg,1); else code_cmp_register(creg); jcond(l1,cond); @@ -536,13 +584,8 @@ n->sc = LVAR; lvar = list2(LVAR,n->dsp); g_expr_u(assign_expr0(list2(LVAR,n->dsp),list3(tag,reg,(int)n),t,t)); - if (tag==REGISTER) { + if (tag==REGISTER||tag==DREGISTER||tag==FREGISTER) { free_register(reg); - } else if (tag==DREGISTER) { - free_dregister(reg); - } else if (tag==FREGISTER) { - free_dregister(reg); - } return g_expr0(lvar); #endif } @@ -582,14 +625,12 @@ remove_target(int *target,int t,int *use) { int use0=*use; + int reg; while(use0) { if (car(use0)==t) { - if (car(caddr(use0))==REGISTER) + reg = car(caddr(use0)); + if (reg==REGISTER||reg==FREGISTER||reg==DREGISTER) free_register(cadr(caddr(use0))); - else if (car(caddr(use0))==FREGISTER) - free_dregister(cadr(caddr(use0))); - else if (car(caddr(use0))==DREGISTER) - free_dregister(cadr(caddr(use0))); break; } use0 = cadr(use0); @@ -755,7 +796,7 @@ jump(int e1, int env) { int e2,e3,e4,sz,arg_size,ty,regs,fregs; - int t0,s0,r; + int t0,s0,r,reg; NMTBL *code0 = 0; int target = 0; int source = 0; @@ -845,12 +886,9 @@ /* 並列代入を実行 */ parallel_assign(&target,&source,&processing,&use); while (use) { - if (car(caddr(use))==REGISTER) + reg = car(caddr(use)); + if (reg==REGISTER||reg==FREGISTER||reg==DREGISTER) free_register(cadr(caddr(use))); - else if (car(caddr(use))==FREGISTER) - free_dregister(cadr(caddr(use))); - else if (car(caddr(use))==DREGISTER) - free_dregister(cadr(caddr(use))); else if (car(caddr(use))==LVAR) free_lvar(cadr(caddr(use))); use=cadr(use); @@ -996,6 +1034,7 @@ e5== CONST || e5== FNAME || e5== STRING || (e5==ADDRESS&&car(cadr(e4))==STRING) || (e5==ADDRESS&&car(cadr(e4))==GVAR) )))) { + creg = use_int(creg); assign_opt(e5,e2,e4,byte); return; } @@ -1045,9 +1084,6 @@ default: error(-1); } - g_expr(e2); - code_dassign(e2,reg,d); - return; } /* e2 is register now */ if (car(e2)!=DREGISTER && car(e2)!=FREGISTER) error(-1); @@ -1079,30 +1115,33 @@ (car(e2)==DREGISTER&&(e5==DRGVAR||e5==DRLVAR||e5==DCONST))|| (car(e2)==DREGISTER&&(e5==FRGVAR||e5==FRLVAR||e5==FCONST)) )) { + creg = d?use_double(creg):use_float(creg); dassign_opt(e5,e2,e4,d); return; } switch(car(e2)) { case GVAR: g_expr(e4); - code_dassign_gvar(e2,freg,d); + code_dassign_gvar(e2,creg,d); return; case LVAR: g_expr(e4); - code_dassign_lvar(cadr(e2),freg,d); + code_dassign_lvar(cadr(e2),creg,d); return; case DREGISTER: case FREGISTER: g_expr(e4); - if (freg!=cadr(e2)) - code_dassign_dregister(cadr(e2),d,freg); + if (creg!=cadr(e2)) { + if (d) creg = use_double(creg); else creg = use_float(creg); + code_dassign_dregister(cadr(e2),d,creg); + } return; } g_expr(e2); emit_push(); g_expr(e4); e2 = emit_pop(0); - code_dassign(e2,freg,d); + code_dassign(e2,creg,d); emit_pop_free(e2); return; } @@ -1119,6 +1158,7 @@ e3 = caddr(e1); op = cadddr(e1); + creg = use_int(creg); g_expr(e3); if (car(e2)==REGISTER) { code_register_assop(cadr(e2),op,byte); @@ -1142,6 +1182,7 @@ e3 = caddr(e1); op = cadddr(e1); + creg = d?use_double(creg):use_float(creg); g_expr(e3); emit_dpush(d); g_expr(e2);