Mercurial > hg > CbC > old > device
changeset 145:fb61020a9b48
fix macro
creg and freg unify
author | kono |
---|---|
date | Fri, 23 May 2003 13:27:48 +0900 |
parents | 56211702f298 |
children | af841e8d739d |
files | Changes mc-code-mips.c mc-code-powerpc.c mc-parse.c |
diffstat | 4 files changed, 97 insertions(+), 69 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Wed May 21 21:41:06 2003 +0900 +++ b/Changes Fri May 23 13:27:48 2003 +0900 @@ -3014,3 +3014,27 @@ いずれにせよ、fregv を追放することからはじめるんじゃない? それはできました。 + +Thu May 22 23:40:13 JST 2003 + +3808 macro = (char *)car(nptrm->dsp); +3809 if (nptrm->sc==MACRO) { +3810 while((*macropp++ = *macro++)); +3811 macropp[-1]=c; +(gdb) +3812 } else if (nptrm->sc==FMACRO) { +3813 if(c!='(') error(MCERR); +3814 *macropp++=0; +3815 macrop = macro_function(macrop,&body,nptrm, +3816 list2((int)macro,history)); + +MACRO の場合のrecursive な処理を忘れいているみたいだけど。 +それでも良かったはずなんだけど、macro_buf がstatic なので +不都合が出ているみたいね。 + +recursive に処理すると、 + #deifne car(e) heap[e] + car(e) +みたいな時にまずい。これは、どうするんだっけ? + +LMACRO ってのがあったみたいね。
--- a/mc-code-mips.c Wed May 21 21:41:06 2003 +0900 +++ b/mc-code-mips.c Fri May 23 13:27:48 2003 +0900 @@ -66,6 +66,8 @@ #define CREG_REGISTER MAX_TMP_REG #define FREG_FREGISTER MAX_TMP_FREG +int dreg; + int reg_sp; /* REGister Stack-Pointer */ int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ @@ -2095,7 +2097,7 @@ if (freg!=e2) { if (d) { printf("\tmove %s,%s\n", - fregister_name0(freg)), + fregister_name0(freg), fregister_name0(e2)); printf("\tmove %s,%s\n", fregister_name1(freg), @@ -2150,7 +2152,7 @@ if (e2!=freg) { if (d) { printf("\tmove %s,%s\n", - fregister_name0(freg)), + fregister_name0(freg), fregister_name0(e2)); printf("\tmove %s,%s\n", fregister_name1(freg),
--- a/mc-code-powerpc.c Wed May 21 21:41:06 2003 +0900 +++ b/mc-code-powerpc.c Fri May 23 13:27:48 2003 +0900 @@ -57,13 +57,15 @@ #define MAX_TMP_FREG 14 #define RET_REGISTER 3 -#define RET_FREGISTER 1 +#define RET_FREGISTER (1+FREG_OFFSET) int MAX_REGISTER=30; /* PowerPCのレジスタを10個まで使う*/ int MAX_FREGISTER=31; #define REAL_MAX_REGISTER 32 /* PowerPCのレジスタが32ということ*/ #define REAL_MAX_FREGISTER 32 /* PowerPCのレジスタが32ということ*/ +#define FREG_OFFSET REAL_MAX_REGISTER + int MAX_INPUT_REGISTER_VAR = 11-MIN_TMP_REG; int MAX_CODE_INPUT_REGISTER_VAR = 11-MIN_TMP_REG; int MAX_INPUT_DREGISTER_VAR = 14-MIN_TMP_FREG; @@ -72,20 +74,14 @@ int MAX_CODE_INPUT_FREGISTER_VAR = 14-MIN_TMP_FREG; #define CREG_REGISTER MAX_TMP_REG -#define FREG_FREGISTER MAX_TMP_FREG +#define FREG_FREGISTER (MAX_TMP_FREG+FREG_OFFSET) -int powerpc_regs[REAL_MAX_REGISTER]; -int powerpc_regv[REAL_MAX_REGISTER]; +int powerpc_regs[REAL_MAX_REGISTER+REAL_MAX_FREGISTER]; +int powerpc_regv[REAL_MAX_REGISTER+REAL_MAX_FREGISTER]; int *regv = powerpc_regv; int *regs = powerpc_regs; -int powerpc_fregs[REAL_MAX_FREGISTER]; -int powerpc_fregv[REAL_MAX_FREGISTER]; - -int *fregv = powerpc_fregv; -int *fregs = powerpc_fregs; - static int max_reg_var, max_freg_var; static int cond_reg=-1,cond_freg=-1; @@ -93,10 +89,7 @@ "r0","r1","r2","r3","r4","r5","r6","r7","r8","r9", "r10","r11","r12","r13","r14","r15","r16","r17","r18","r19", "r20","r21","r22","r23","r24","r25","r26","r27","r28","r29", - "r30","r31" -}; - -static char *freg_name[] = { + "r30","r31", "f0","f1","f2","f3","f4","f5","f6","f7","f8","f9", "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19", "f20","f21","f22","f23","f24","f25","f26","f27","f28","f29", @@ -104,7 +97,7 @@ }; #define register_name(i) reg_name[i] -#define fregister_name(i) freg_name[i] +#define fregister_name(i) reg_name[i] static NMTBL float_zero = {"_float_zero",STATIC,FLOAT,0}; @@ -283,7 +276,7 @@ void gexpr_code_init(void){ regv[creg]=0; - fregv[freg]=0; + regv[freg]=0; } @@ -315,8 +308,8 @@ if ((reg = get_input_dregister_var(freg_var,n,is_code0,0))) { n->sc = DREGISTER; n->dsp = cadr(reg); - fregv[n->dsp]= 1; - fregs[n->dsp]= INPUT_REG; + regv[n->dsp]= 1; + regs[n->dsp]= INPUT_REG; freg_var++; cadddr(args)=size(type); /* why we need this? */ } @@ -324,8 +317,8 @@ if ((reg = get_input_dregister_var(freg_var,n,is_code0,1))) { n->sc = DREGISTER; n->dsp = cadr(reg); - fregv[n->dsp]= 1; - fregs[n->dsp]= INPUT_REG; + regv[n->dsp]= 1; + regs[n->dsp]= INPUT_REG; freg_var++; cadddr(args)=size(type); /* why we need this? */ } @@ -386,9 +379,9 @@ get_dregister(int d) { /* 使われていないレジスタを調べる */ int i,reg; - for(i=MAX_TMP_FREG;i>MIN_TMP_FREG;i--) { - if (fregs[i]) continue; /* 使われている */ - fregs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ + for(i=MAX_TMP_FREG+FREG_OFFSET;i>MIN_TMP_FREG+FREG_OFFSET;i--) { + if (regs[i]) continue; /* 使われている */ + regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ return i; /* その場所を表す番号を返す */ } /* search register stack */ @@ -401,10 +394,10 @@ } } for(i=0;i<FREG_VAR_BASE-REG_VAR_MIN;i++) { - reg =FREG_VAR_BASE-i; - if (! fregs[reg]) { /* 使われていないなら */ - fregs[reg]=USING_REG; /* そのレジスタを使うことを宣言し */ - fregv[reg]=0; + reg =FREG_VAR_BASE-i+FREG_OFFSET; + if (! regs[reg]) { /* 使われていないなら */ + regs[reg]=USING_REG; /* そのレジスタを使うことを宣言し */ + regv[reg]=0; if (i>max_freg_var) max_freg_var=i; return reg; } @@ -434,8 +427,8 @@ void free_dregister(int i) { /* いらなくなったレジスタを開放 */ - if (i<0||MAX_FREGISTER<i) error(-1); - fregv[i]=fregs[i]=0; + if (i<FREG_OFFSET||MAX_FREGISTER+FREG_OFFSET<i) error(-1); + regv[i]=regs[i]=0; } int @@ -443,10 +436,10 @@ { if (is_code) { if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; - i = REG_VAR_BASE-i; + i = REG_VAR_BASE-i+FREG_OFFSET; } else { if (i<0||i>=MAX_INPUT_DREGISTER_VAR) return 0; - i = i+MIN_TMP_FREG; + i = i+MIN_TMP_FREG+FREG_OFFSET; } return list3(DREGISTER,i,(int)n); } @@ -464,6 +457,8 @@ return list3(REGISTER,i,(int)n); } +/* double register case? */ + int get_input_register_var_1(int i,NMTBL *n,int is_code) { @@ -486,7 +481,7 @@ if (! regs[i] && ! regv[i]) count++; } for(i=0;i<MAX_FREGISTER;i++) { - if (! fregs[i] && ! fregv[i]) fcount++; + if (! regs[i+FREG_OFFSET] && ! regv[i+FREG_OFFSET]) fcount++; } printf("# free reg %d freg %d\n",count,fcount); return d?fcount:count; @@ -509,7 +504,7 @@ { int i; for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; regv[i]=0; } - for(i=0;i<MAX_FREGISTER;i++) { fregs[i]=0; fregv[i]=0; } + for(i=0;i<MAX_FREGISTER;i++) { regs[i+FREG_OFFSET]=0; regv[i+FREG_OFFSET]=0; } creg = get_register(); freg = get_dregister(1); set_creg(CREG_REGISTER,0); @@ -533,7 +528,7 @@ printf(":"); for(i=0;i<MAX_REGISTER;i++) { printf("%d",regs[i]); } printf("\n# freg:"); - for(i=0;i<MAX_FREGISTER;i++) { printf("%d",fregs[i]); } + for(i=0;i<MAX_FREGISTER;i++) { printf("%d",regs[i+FREG_OFFSET]); } for(i=reg_sp;i>=0;i--) { if(reg_stack[i]>=0) printf(" %s",register_name(reg_stack[i])); @@ -606,12 +601,12 @@ { int i; for(i=0;i<FREG_VAR_BASE-REG_VAR_MIN;i++) { - if (! fregs[FREG_VAR_BASE-i]) { /* 使われていないなら */ - fregs[FREG_VAR_BASE-i]=USING_REG; /*そのレジスタを使うことを宣言し*/ - fregv[FREG_VAR_BASE-i]=0; + if (! regs[FREG_VAR_BASE-i+FREG_OFFSET]) { /* 使われていないなら */ + regs[FREG_VAR_BASE-i+FREG_OFFSET]=USING_REG; /*そのレジスタを使うことを宣言し*/ + regv[FREG_VAR_BASE-i+FREG_OFFSET]=0; if (i>max_freg_var) max_freg_var=i; /* その場所を表す番号を返す */ - return list3(DREGISTER,FREG_VAR_BASE-i,(int)n); + return list3(DREGISTER,FREG_VAR_BASE-i+FREG_OFFSET,(int)n); } } return list2(LVAR,new_lvar(size_of_double)); @@ -1285,7 +1280,7 @@ printf("\tfmr %s,%s\n",fregister_name(reg),fregister_name(freg)); free_dregister(freg); freg = reg; - fregs[freg]=1; + regs[freg]=1; } } @@ -1295,7 +1290,7 @@ if (car(arg)==REGISTER) regs[cadr(arg)]=USING_REG; else if (car(arg)==DREGISTER) - fregs[cadr(arg)]=USING_REG; + regs[cadr(arg)]=USING_REG; } void @@ -1323,7 +1318,7 @@ t = INT; reg += reg_offset; /* for duplicated floating point argument */ } else if (tag==DREGISTER) { - /* fregs[reg]==INPUT_REG case should be considered */ + /* regs[reg]==INPUT_REG case should be considered */ n->dsp = offset; t = n->ty; if(t==FLOAT) { offset+=size_of_float; reg_offset+=1; } @@ -1518,12 +1513,12 @@ } if (ret_type==DOUBLE||ret_type==FLOAT) { set_freg(RET_FREGISTER,0); - fregv[freg]=1; regv[creg]=0; + regv[freg]=1; regv[creg]=0; } else if (ret_type==VOID) { - fregv[freg]=0; regv[creg]=0; + regv[freg]=0; regv[creg]=0; } else { set_creg(RET_REGISTER,0); - fregv[freg]=0; regv[creg]=1; + regv[freg]=0; regv[creg]=1; } return ret_type; } @@ -2301,7 +2296,7 @@ { if (freg!=e2) printf("\tfmr %s,%s\n",fregister_name(freg),fregister_name(e2)); - fregv[freg]=1; + regv[freg]=1; } void code_dassign_gvar(int e2,int freg,int d) @@ -2309,7 +2304,7 @@ int r; r = get_ptr_cache((NMTBL*)cadr(e2)); printf("\t%s %s,0(%s)\n",fstore(d),fregister_name(freg),register_name(r)); - fregv[freg]=1; + regv[freg]=1; } void code_dassign_lvar(int e2,int freg,int d) @@ -2317,13 +2312,13 @@ lvar_intro(e2); printf("\t%s %s,",fstore(d),fregister_name(freg)); lvar(e2); - fregv[freg]=1; + regv[freg]=1; } void code_dassign(int e2,int freg,int d) { printf("\t%s %s,0(%s)\n",fstore(d),fregister_name(freg),register_name(e2)); - fregv[freg]=1; + regv[freg]=1; } void @@ -2400,7 +2395,7 @@ printf("\tlfs %s,0(%s)\n",frn,rrn); } free_register(r); - fregv[freg]=1; + regv[freg]=1; } @@ -2421,7 +2416,7 @@ printf("\tstfd %s,",frn); lvar(e2); lvar_intro(e2+size_of_double-size_of_int); printf("\tlwz %s,",crn); lvar(e2+size_of_double-size_of_int); - fregs[freg]=0; + regs[freg]=0; regs[creg]=1; } @@ -2461,7 +2456,7 @@ set_creg(RET_REGISTER,1); printf("\tbl i2d_\n"); set_freg(RET_FREGISTER,0); - fregs[freg]=1; + regs[freg]=1; regs[creg]=0; } @@ -2509,7 +2504,7 @@ set_freg(RET_FREGISTER,1); printf("\tbl d2u_\n"); set_creg(RET_REGISTER,0); - fregs[freg]=1; + regs[freg]=1; regs[creg]=0; } @@ -2553,7 +2548,7 @@ printf("\tmr r3,%s\n",crn); printf("\tbl u2d_\n"); printf("\tfmr %s,f1\n",frn); - fregs[freg]=1; + regs[freg]=1; regs[creg]=0; } @@ -2569,7 +2564,7 @@ int r; r = get_ptr_cache((NMTBL*)cadr(e2)); printf("\t%s %s,0(%s)\n",fload(d),fregister_name(freg),register_name(r)); - fregv[freg]=1; + regv[freg]=1; } @@ -2577,7 +2572,7 @@ { lvar_intro(e2); printf("\t%s %s,",fload(d),fregister_name(freg)); lvar(e2); - fregv[freg]=1; + regv[freg]=1; } void code_cmp_drgvar(int e2,int d) @@ -2590,7 +2585,7 @@ printf("\t%s %s,0(%s)\n",fload(1),grn,register_name(r)); printf("\tfcmpu cr0,%s,%s\n",frn,grn); free_dregister(g); - fregv[freg]=0; + regv[freg]=0; } void code_cmp_drlvar(int e2,int d) @@ -2603,7 +2598,7 @@ printf("\t%s %s,",fload(1),grn); lvar(e2); printf("\tfcmpu cr0,%s,%s\n",frn,grn); free_dregister(g); - fregv[freg]=0; + regv[freg]=0; } void dtosop(int op,int e1) @@ -2611,7 +2606,7 @@ char *opn=""; char *frn=fregister_name(freg); char *grn=fregister_name(e1); - fregv[freg]=1; + regv[freg]=1; switch(op) { case FADD: case DADD: opn="fadd"; break; @@ -2635,7 +2630,7 @@ error(-1); return; } printf("\t%s %s,%s,%s\n",opn,frn,frn,grn); - fregv[freg]=1; + regv[freg]=1; free_dregister(e1); } @@ -2650,7 +2645,7 @@ dtosop(op,xreg); printf("\t%s %s,0(%s)\n",fstore(d),frn,crn); emit_dpop_free(xreg,d); - fregv[freg]=1; + regv[freg]=1; } @@ -2682,7 +2677,7 @@ printf("\tfsub %s,%s,%s\n",frn,frn,grn); printf("\t%s %s,0(%s)\n",fstore(d),frn,crn); free_dregister(g); - fregv[freg]=1; + regv[freg]=1; } void @@ -2713,7 +2708,7 @@ printf("\tfsub %s,%s,%s\n",grn,frn,grn); printf("\t%s %s,0(%s)\n",fstore(d),grn,crn); free_dregister(g); - fregv[freg]=1; + regv[freg]=1; } void @@ -2749,7 +2744,7 @@ reg = get_dregister(d); code_drlvar(REG_LVAR_OFFSET+xreg,1,reg); free_lvar(REG_LVAR_OFFSET+xreg); - fregv[reg]=1; xreg=reg; + regv[reg]=1; xreg=reg; } return xreg; } @@ -2766,7 +2761,7 @@ new_reg = get_dregister(1); freg_stack[freg_sp++] = freg; /* push するかわりにレジスタを使う */ freg = new_reg; - fregv[freg]=1; + regv[freg]=1; } void
--- a/mc-parse.c Wed May 21 21:41:06 2003 +0900 +++ b/mc-parse.c Fri May 23 13:27:48 2003 +0900 @@ -3754,7 +3754,7 @@ NMTBL *nptr0; nptr0 = msearch0(macro); nptr0->ty=list3(nptr0->sc,nptr0->ty,nptr0->dsp); - nptr0->sc=MACRO; + nptr0->sc=LMACRO; nptr0->dsp=list2((int)value,0); } @@ -3806,15 +3806,22 @@ namebuf[i]=0; nptrm = msearch0(namebuf); macro = (char *)car(nptrm->dsp); - if (nptrm->sc==MACRO) { + if (nptrm->sc==LMACRO) { while((*macropp++ = *macro++)); macropp[-1]=c; + } else if (nptrm->sc==MACRO) { + *macropp++=0; + macrop=macro_eval(macrop,macro,list2((int)macro,history)); + if (c) { + *macropp++=c; + macrop = list2((int)macropp-1,macrop); + } } else if (nptrm->sc==FMACRO) { if(c!='(') error(MCERR); *macropp++=0; macrop = macro_function(macrop,&body,nptrm, list2((int)macro,history)); - if (ch) { + if (ch) { /*?*/ *macropp++=ch; *macropp++=0; macrop = list2((int)macropp-2,macrop);