Mercurial > hg > CbC > old > device
changeset 249:8313c965c0e2
*** empty log message ***
author | kono |
---|---|
date | Tue, 11 May 2004 16:50:05 +0900 |
parents | b4a57dd14801 |
children | 7637295c4fb8 |
files | .gdbinit Changes Makefile mc-code-mips.c mc-codegen.c test/simp1.c |
diffstat | 6 files changed, 295 insertions(+), 79 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Tue May 11 02:26:10 2004 +0900 +++ b/.gdbinit Tue May 11 16:50:05 2004 +0900 @@ -1,7 +1,7 @@ tb main # run -s -ob00.s test/int.c # run -s -ob00.s mc-parse.c -run -s -Itest/ test/code-gen-all.c +run -s test/code-gen-all.c define regs printf "pc =%08x lr =%08x r0 =%08x r1 =%08x r3= %08x r4= %08x\n",$pc,$lr,$r0,$r1,$r3,$r4 printf "r10=%08x r11=%08x r12=%08x r13=%08x r14=%08x r15=%08x\n",$r10,$r11,$r12,$r13,$r14,$r15
--- a/Changes Tue May 11 02:26:10 2004 +0900 +++ b/Changes Tue May 11 16:50:05 2004 +0900 @@ -4136,3 +4136,36 @@ 浮動小数点やlong longの代入で同じ値は一つにまとめるべきだよね。 連想 list を一つ持てば良いだけだし。 + +string をまとめるかどうかは、const かどうかによるわけだが... + +RETURN register あたりの処理がダサイ。ま、しょうがないか。 + +MIPS のdebugにかかるんだけど、今は時期が悪いよな。なんで、 +もっと早くできなかったのか。gcc modification はどうした? + +だから register を 0 で入ってないとするのはまずいって +言っているのに... + +float は normal register に積むのか。 + + s.s $f4,16($sp) + mov.s $f12,$f0 + mov.s $f14,$f1 + mfc1 $6,$f2 + mfc1 $7,$f3 + jal f + +ま、いいんだけどさ。(でも、なんで$4,$5 を使わないんだ?) + +long long も4,5,6,7 しかレジスタに積まない。ま、正解だけど。 + +げ、レジスタのセーブって自分でやるのか。(じゃ、mask ってなん +だよ...) ってことはentry はあとで出力しないとだめだね。 + +まぁ、いちいち驚かないけど... 細かいエラーが残っているな。 + +やっぱり codegen の拡張法を作っておかないとダメだね。 + +関数呼び出しパートをCbC自身で書けないのかなぁ。 +あまりにめんどくさすぎ。
--- a/Makefile Tue May 11 02:26:10 2004 +0900 +++ b/Makefile Tue May 11 16:50:05 2004 +0900 @@ -58,6 +58,7 @@ make check TARGET=test/short make check TARGET=test/simp make check TARGET=test/simp0 + make check TARGET=test/simp1 make check TARGET=test/static make check TARGET=test/tmp make check TARGET=test/tmp10
--- a/mc-code-mips.c Tue May 11 02:26:10 2004 +0900 +++ b/mc-code-mips.c Tue May 11 16:50:05 2004 +0900 @@ -49,7 +49,7 @@ #define SIZE_OF_FLOAT 4 #define SIZE_OF_DOUBLE 8 #define SIZE_OF_LONGLONG 8 -#define ENDIAN 1 +#define ENDIAN 0 int size_of_int = SIZE_OF_INT; int size_of_short = SIZE_OF_SHORT; @@ -92,44 +92,50 @@ #define FREG_OFFSET REAL_MAX_REGISTER #define LREG_OFFSET (REAL_MAX_REGISTER+REAL_MAX_FREGISTER) -#define RET_REGISTER 3 -#define RET_FREGISTER (1+FREG_OFFSET) -#define RET_LREGISTER_H 3 /* high word */ -#define RET_LREGISTER_L 4 /* low word */ -#define RET_LREGISTER LREG_OFFSET -#define RET_DREGISTER LREG_OFFSET -#define LREGISTER_OPERAND LREG_OFFSET-1 -#define LREGISTER_OPERAND_H 4 /* high word */ -#define LREGISTER_OPERAND_L 5 /* low word */ -#define LREGISTER_OPERAND_1 LREG_OFFSET-2 -#define LREGISTER_OPERAND_1_H 6 /* high word */ -#define LREGISTER_OPERAND_1_L 7 /* low word */ -#define DREGISTER_OPERAND LREG_OFFSET-1 -#define DREGISTER_OPERAND_H 4 /* high word */ -#define DREGISTER_OPERAND_L 5 /* low word */ -#define DREGISTER_OPERAND_1 LREG_OFFSET-2 -#define DREGISTER_OPERAND_1_H 6 /* high word */ -#define DREGISTER_OPERAND_1_L 7 /* low word */ - int MAX_INPUT_REGISTER_VAR = 7-MIN_TMP_REG; int MAX_CODE_INPUT_REGISTER_VAR = 7-MIN_TMP_REG; -int MAX_INPUT_DREGISTER_VAR = 14-MIN_TMP_FREG; -int MAX_INPUT_FREGISTER_VAR = 14-MIN_TMP_FREG; +int MAX_INPUT_DREGISTER_VAR = 2; +int MAX_INPUT_FREGISTER_VAR = 1; int MAX_CODE_INPUT_DREGISTER_VAR = 14-MIN_TMP_FREG; int MAX_CODE_INPUT_FREGISTER_VAR = 14-MIN_TMP_FREG; static int mips_regs[REAL_MAX_REGISTER+REAL_MAX_FREGISTER+ REAL_MAX_LREGISTER]; -static int regv_h0[REAL_MAX_LREGISTER]; -static int regv_l0[REAL_MAX_LREGISTER]; +#define LREG_V 3 /* for virtual long long/double register */ +static int regv_h0[REAL_MAX_LREGISTER+LREG_V]; +static int regv_l0[REAL_MAX_LREGISTER+LREG_V]; #define regv_h(i) regv_h0[(i)-LREG_OFFSET] #define regv_l(i) regv_l0[(i)-LREG_OFFSET] +#define RET_REGISTER 2 +#define RET_FREGISTER FREG_OFFSET + +#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_L 2 /* high word */ +#define RET_LREGISTER_H 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_DREGISTER RET_LREGISTER +#define DREGISTER_OPERAND LREGISTER_OPERAND +#define DREGISTER_OPERAND_1 LREGISTER_OPERAND_1 +#define RET_DREGISTER_L RET_LREGISTER_L +#define RET_DREGISTER_H RET_LREGISTER_H +#define DREGISTER_OPERAND_H LREGISTER_OPERAND_H +#define DREGISTER_OPERAND_L LREGISTER_OPERAND_L +#define DREGISTER_OPERAND_1_L LREGISTER_OPERAND_1_L +#define DREGISTER_OPERAND_1_H LREGISTER_OPERAND_1_H + static int *regs = mips_regs; #define CREG_REGISTER (MAX_TMP_REG) #define FREG_FREGISTER (MAX_TMP_FREG+FREG_OFFSET) #define LREG_LREGISTER (MAX_TMP_REG+LREG_OFFSET) +#define DREG_DREGISTER LREG_LREGISTER #define CMP_C1T (-1) @@ -159,8 +165,8 @@ #define is_int_reg(i) (0<=i&&i<REAL_MAX_REGISTER) #define is_float_reg(i) (REAL_MAX_REGISTER<=i&&i<REAL_MAX_FREGISTER+REAL_MAX_REGISTER) -#define is_double_reg(i) (LREG_OFFSET<=i&&i<LREG_OFFSET+REAL_MAX_LREGISTER&®s[i]==USING_DREG) -#define is_longlong_reg(i) (LREG_OFFSET<=i&&i<LREG_OFFSET+REAL_MAX_LREGISTER&®s[i]==USING_REG) +#define is_longlong_reg(i) (LREG_OFFSET<=i&&i<LREG_OFFSET+REAL_MAX_LREGISTER+LREG_V) +#define is_double_reg(i) is_longlong_reg(i) #define use_int(reg) if (reg==USE_CREG) reg=use_int0() static @@ -223,15 +229,9 @@ static int use_double0() { - int i = creg; - if (!is_double_reg(i)) { - if (ireg) { free_register(ireg); ireg=0; } - if (!lreg||!regs[lreg]) lreg = get_lregister(); - // else if (lreg!=i) free_register(i); - i = lreg; - } - if (!regv_l(i)) regv_l(i) = get_register(); - if (!regv_h(i)) regv_h(i) = get_register(); + int i; + use_longlong0(); + i = lreg; if (!regs[i]) regs[i]=USING_DREG; if (!regs[regv_l(i)]) regs[regv_l(i)]=USING_REG; if (!regs[regv_h(i)]) regs[regv_h(i)]=USING_REG; @@ -256,6 +256,7 @@ static void code_save_input_registers(); static void clear_ptr_cache_reg(int r); static void set_ireg(int,int); +static void set_dreg(int,int); static void set_freg(int,int); static void set_lreg(int,int); @@ -393,11 +394,19 @@ void code_init(void) { + int reg; // macro_define("__BIG_ENDIAN__ 1\n"); macro_define("__STDC__ 1\n"); init_ptr_cache(); - regv_l(RET_LREGISTER) = RET_LREGISTER_L; - regv_h(RET_LREGISTER) = RET_LREGISTER_H; + reg=RET_LREGISTER; + regv_l(reg) = RET_LREGISTER_L; + regv_h(reg) = RET_LREGISTER_H; + reg=LREGISTER_OPERAND; + regv_l(reg) = LREGISTER_OPERAND_L; + regv_h(reg) = LREGISTER_OPERAND_H; + reg=LREGISTER_OPERAND_1; + regv_l(reg) = LREGISTER_OPERAND_1_L; + regv_h(reg) = LREGISTER_OPERAND_1_H; } @@ -596,7 +605,7 @@ get_lregister0() { int i; - for(i=LREG_OFFSET+1;i<REAL_MAX_LREGISTER+LREG_OFFSET;i++) { + for(i=LREG_OFFSET;i<REAL_MAX_LREGISTER+LREG_OFFSET;i++) { if (regs[i]==0) { // printf("# get_lregister %d\n",i); return i; @@ -683,6 +692,7 @@ { int j; if (d) { + if (i<0||i>=MAX_INPUT_DREGISTER_VAR) return 0; j = get_input_lregister_var(i,n,is_code); if (car(j)==LREGISTER) { if (regs[cadr(j)]==INPUT_REG) regs[cadr(j)]=INPUT_DREG; @@ -694,8 +704,11 @@ if(!(i<FREG_VAR_BASE-FREG_VAR_MIN)) return 0; i = FREG_VAR_BASE-i+FREG_OFFSET; } else { - if (i<0||i>=MAX_INPUT_DREGISTER_VAR) return 0; - i = i+MIN_TMP_FREG+FREG_OFFSET; + if (i<0||i>=MAX_INPUT_FREGISTER_VAR) return 0; + if (i==1) i = 6; + else if (i==2) i = 7; + else + i = i+MIN_TMP_FREG+FREG_OFFSET; } return list3(FREGISTER,i,(int)n); } @@ -781,18 +794,16 @@ { int i; // printf("# free_all register\n"); -#if LONGLONG_CODE +#if LONGLONG_CODE||FLOAT_CODE for(i=0;i<REAL_MAX_LREGISTER;i++) { regs[i+LREG_OFFSET]=0; - regv_l(i+LREG_OFFSET) = 0; - regv_h(i+LREG_OFFSET) = 0; } lreg = 0; // set_lreg(LREG_LREGISTER,0); #endif for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; } +#if FLOAT_CODE for(i=0;i<MAX_FREGISTER;i++) { regs[i+FREG_OFFSET]=0; } -#if FLOAT_CODE freg = get_dregister(1); set_freg(FREG_FREGISTER,0); #endif @@ -1509,13 +1520,8 @@ } void -set_lreg(int reg,int mode) +set_lreg0(int reg,int mode) { - if (reg==RET_LREGISTER) { - regv_l(reg) = RET_LREGISTER_L; - regv_h(reg) = RET_LREGISTER_H; - } - if (!is_longlong_reg(reg)) error(-1); if (reg!=creg) { if (lreg && reg!=lreg) { if (mode) { @@ -1537,12 +1543,28 @@ } void +set_lreg(int reg,int mode) +{ + if (!is_longlong_reg(reg)) error(-1); + set_lreg0(reg,mode); +} + +void set_dreg(int reg,int mode) { - set_lreg(reg,mode); - regs[regv_l(reg)]=USING_DREG; - clear_ptr_cache_reg(regv_h(reg)); - regs[regv_h(reg)]=USING_DREG; + if (reg==RET_DREGISTER) { + regv_l(reg) = RET_DREGISTER_L; + regv_h(reg) = RET_DREGISTER_H; + } else if (reg==DREGISTER_OPERAND) { + regv_l(reg) = DREGISTER_OPERAND_L; + regv_h(reg) = DREGISTER_OPERAND_H; + } else if (reg==DREGISTER_OPERAND_1) { + regv_l(reg) = DREGISTER_OPERAND_1_L; + regv_h(reg) = DREGISTER_OPERAND_1_H; + } + set_lreg0(reg,mode); + regs[regv_l(reg)]=USING_DREG; + regs[regv_h(reg)]=USING_DREG; } void @@ -1705,6 +1727,37 @@ if (mode) use_reg(reg); } +#define FASS_INPUT (FOP+199) + +static void +code_assign_input_float_int(int e0) { + int e1 = cadr(e0); + int e2 = caddr(e0); + int r; + double value; + char *frn; + // e2 = e3; + if (car(e1)!=REGISTER) { error(-1); return; } + frn = register_name(cadr(e1)); + switch(car(e2)) { + case FCONST: + value = dcadr(e2); + printf("\t.lis %s,%g\n",frn,value); + break; + case FRGVAR: + r = get_ptr_cache((NMTBL*)cadr(e2)); + printf("\tlw %s,0(%s)\n",frn,register_name(r)); + break; + case FRLVAR: + lvar_intro(cadr(e2)); + printf("\tlw %s,",fregister_name(freg)); lvar(cadr(e2)); + default: + g_expr(e2); + case FREGISTER: + printf("\tmfc1 %s,%s\n",frn,fregister_name(freg)); + } +} + int function(int e1) { @@ -1787,7 +1840,10 @@ arg_assign); use_input_reg(cadr(r0),1); } else { - arg = get_input_lregister_var(reg_arg,0,0); + if (t==DOUBLE) + arg=get_input_dregister_var(reg_arg,0,0,1); + else + arg=get_input_lregister_var(reg_arg,0,0); use_input_reg(cadr(arg),1); } reg_arg_list = list2(arg,reg_arg_list); @@ -1800,17 +1856,29 @@ arg = list2(LVAR,caller_arg_offset_v(nargs)); } else if (!simple_args(e3) && cadr(e3)) { arg = get_dregister_var(0,1); - arg_assign = list2( + if (freg_arg<2) { + arg_assign = list2( + list3(FASS_INPUT, + get_input_dregister_var(freg_arg,0,0,1),arg), + arg_assign); + } else { + arg_assign = list2( assign_expr0(get_input_dregister_var(freg_arg,0,0,1), arg,t,t), arg_assign); + } } else { arg = get_input_dregister_var(freg_arg,0,0,1); } reg_arg_list = list2(arg,reg_arg_list); - if (car(arg)==FREGISTER) - use_input_reg(cadr(arg),1); /* protect from input register free */ - g_expr_u(assign_expr0(arg,e4,t,t)); /* XXX */ + if (car(arg)==FREGISTER) { + use_input_reg(cadr(arg),1);/* protect from input register free */ + g_expr_u(assign_expr0(arg,e4,t,t)); /* XXX */ + } else if (car(arg)==REGISTER) { + code_assign_input_float_int(list3(FASS_INPUT, arg, e4)); + } else { + g_expr_u(assign_expr0(arg,e4,t,t)); /* XXX */ + } freg_arg++; nargs += size(t)/SIZE_OF_INT; continue; @@ -1825,7 +1893,11 @@ } if (max_func_args<nargs) max_func_args=nargs; for(;arg_assign;arg_assign=cadr(arg_assign)) { - g_expr_u(car(arg_assign)); + if (car(car(arg_assign))==FASS_INPUT) { + code_assign_input_float_int(car(arg_assign)); + } else { + g_expr_u(car(arg_assign)); + } } clear_ptr_cache(); if (car(e2) == FNAME) { @@ -2233,7 +2305,7 @@ { /* this is called once per file */ char *p=cheapp; - char *s; + char *s,*t; printf("\t.file \"%s\"\n",filename); printf(".abicalls\n"); printf(".text\n"); @@ -2241,13 +2313,17 @@ fclose(asi); asi = 0; } - while ((*cheapp++ = *s++)) { + for (t=0,s=p;(*cheapp++ = *s++);) { if (*s=='.') { - *cheapp++=*s++; *cheapp++='i'; - *cheapp++=0; - break; + t=s; } } + if (!t) { + s[-1]='i'; *cheapp++ = 0; + } else { + t[1]='i'; + if (t==s-1) *cheapp++ = 0; + } asi = fopen(p,"w"); printf(".include \"%s\"\n",p); if (!asi) error(-1); @@ -2810,14 +2886,12 @@ code_dconst(int e2,int freg,int d) { double value = dcadr(e2); - int r; char *frn; use_float(d,freg); if (d) { printf("\t.li %s,0x%x\n",lregister_name_high(freg),code_d2(value)); printf("\t.li %s,0x%x\n",lregister_name_low(freg),code_d1(value)); - free_register(r); } else { frn = fregister_name(freg); printf("\t.lis %s,%g\n",frn,value); @@ -3082,16 +3156,10 @@ use_longlong(reg); code_save_stacks(); clear_ptr_cache(); - if (reg!=LREGISTER_OPERAND) { - lmove(LREGISTER_OPERAND,reg); - } + set_lreg(LREGISTER_OPERAND,1); if (e1!=-1) { - if (regv_h(e1)!=6) { - printf("move $6,%s\n",lregister_name_high(e1)); - } - if (regv_h(e1)!=7) { - printf("move $7,%s\n",lregister_name_high(e1)); - } + set_lreg(e1,0); + set_lreg(LREGISTER_OPERAND_1,1); } set_lreg(RET_LREGISTER,0); extern_define(opc,0,FUNCTION,1);
--- a/mc-codegen.c Tue May 11 02:26:10 2004 +0900 +++ b/mc-codegen.c Tue May 11 16:50:05 2004 +0900 @@ -1293,11 +1293,13 @@ e2 = cadr(e1); e3 = cadr(e2); e4 = caddr(e1); e5=car(e4); - d = (car(e1)==LASS)?2:(car(e1)==DASS)?1:0; + if (car(e1)==DASS) d=1; + else if (car(e1)==FASS) d=0; + else error(-1); if (!use && ( (e5==DREGISTER) || (e5==FREGISTER) || (car(e2)==DREGISTER&&(e5==DRGVAR||e5==DRLVAR||e5==DCONST))|| - (car(e2)==DREGISTER&&(e5==FRGVAR||e5==FRLVAR||e5==FCONST)) + (car(e2)==FREGISTER&&(e5==FRGVAR||e5==FRLVAR||e5==FCONST)) )) { dassign_opt(e5,e2,e4,d); return;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/simp1.c Tue May 11 16:50:05 2004 +0900 @@ -0,0 +1,112 @@ +int +i(int a,int b,int c,int d,int f) +{ + return a+b+c+d+f; +} + +short +s(short a,short b,short c,short d,short f) +{ + return a+b+c+d+f; +} + +char +c(char a,char b,char c,char d,char f) +{ + return a+b+c+d+f; +} + + +float +f(float a,float b,float c,float d,float f) +{ + return a+b+c+d+f; +} + +double +d(double a,double b,double c,double d,double f) +{ + return a+b+c+d+f; +} + +long long +l(long long a,long long b,long long c,long long d,long long f) +{ + return a+b+c+d+f; +} + + +int +i0() +{ + int a,b,c; + a=3; + b=-3; + c=5; + c = i(a*3,b*c,b+c,b/c,b-c); + printf("int: %d\n",c); +} + +int +g() +{ + float a,b,c; + a=3.0; + b=-3.0; + c=5.0; + c = f(a*3,b*c,b+c,b/c,b-c); + printf("float: %g\n",c); +} + +int +h() +{ + double a,b,c; + a=3.0; + b=-3.0; + c=5.0; + c = d(a*3,b*c,b+c,b/c,b-c); + printf("double: %g\n",c); +} + +int +h1() +{ + long long a,b,c; + a=3; + b=-3; + c=5; + c = l(a*3,b*c,b+c,b/c,b-c); + printf("long long: %lld\n",c); +} + +int +c1() +{ + char a,b,c; + a=3; + b=-3; + c=5; + c = c(a*3,b*c,b+c,b/c,b-c); + printf("char: %d\n",c); +} + +int +s1() +{ + short a,b,c; + a=3; + b=-3; + c=5; + c = s(a*3,b*c,b+c,b/c,b-c); + printf("short: %d\n",c); +} + +main() +{ + i0(); + g(); + h(); + h1(); + return 0; +}