Mercurial > hg > CbC > old > device
changeset 770:b674d8421430
i64 inline ( indirect call )
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 18 Nov 2010 04:29:03 +0900 |
parents | 74701505c42d |
children | 5e07b9804aea |
files | .gdbinit Makefile mc-code-i64.c mc-codegen.c mc-inline.c test/strinit.c |
diffstat | 6 files changed, 59 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Thu Nov 18 01:47:03 2010 +0900 +++ b/.gdbinit Thu Nov 18 04:29:03 2010 +0900 @@ -13,8 +13,8 @@ x/1i $rip end b errmsg -# r -s test/tmp7.c -r -s test/int.c +r -s test/tmp7.c +# r -s test/int.c # r -s test/tmp6.c # r -s test/call.c # r -s test/static.c @@ -26,5 +26,7 @@ # r -s test/float.c # r -s test/strinit.c # r -s test/arg.c +# r -s test/putenemy.c +# r -s -DINLINE=inline test/code-gen-all.c # r -s -DINLINE=inline test/strinit.c # r -s test/fact-a.c
--- a/Makefile Thu Nov 18 01:47:03 2010 +0900 +++ b/Makefile Thu Nov 18 04:29:03 2010 +0900 @@ -1,4 +1,4 @@ -CC = gcc -std=c99 $(CCEXT) $(M) +CC = gcc -std=c99 $(CCEXT) $(M) -fgnu89-inline # -O3 # MCFLAGS = -DUSE_CODE_KEYWORD CFLAGS = -g -Wall -I. $(MCFLAGS) # -O
--- a/mc-code-i64.c Thu Nov 18 01:47:03 2010 +0900 +++ b/mc-code-i64.c Thu Nov 18 04:29:03 2010 +0900 @@ -42,6 +42,10 @@ char *init_src0 = "\ typedef long __builtin_va_list;\n\ #define __inline inline \n\ +#define __inline__ inline \n\ +#define __DARWIN_1050(x) \n\ +#define __AVAILABILITY_INTERNAL1000_DEP1050\n\ +#define __OSX_AVAILABLE_BUT_DEPRECATED(a,b,c,d) \n\ #define __DBL_MIN_EXP__ (-1021) \n\ #define __FLT_MIN__ 1.17549435e-38F \n\ #define __DEC64_DEN__ 0.000000000000001E-383DD \n\ @@ -269,8 +273,8 @@ int MAX_DREGISTER_VAR=0; /* 保存される xmm register はない */ -#define MIN_TMP_FREG 6 -#define MAX_TMP_FREG 9 +#define MIN_TMP_FREG 8 +#define MAX_TMP_FREG 15 int MAX_INPUT_REGISTER_VAR = 6; int MAX_CODE_INPUT_REGISTER_VAR = 6; @@ -349,6 +353,7 @@ */ static int ia32regs[1+REAL_MAX_REGISTER+REAL_MAX_DREGISTER]; +static int regs_line[1+REAL_MAX_REGISTER+REAL_MAX_DREGISTER]; static int *regs = ia32regs; @@ -858,6 +863,7 @@ int i,reg,j; for(i=REG_EDI;i<MAX_REGISTER+1;i++) { if (! regs[i]) { /* 使われていないなら */ + regs_line[i]=glineno; regs[i]=1; /* そのレジスタを使うことを宣言し */ return i; /* その場所を表す番号を返す */ } @@ -867,6 +873,7 @@ if ((i=last_ptr_cache())) { clear_ptr_cache_reg(i); regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ + regs_line[i]=glineno; return i; /* その場所を表す番号を返す */ } #endif @@ -876,6 +883,7 @@ code_assign_lvar( (j=new_lvar(SIZE_OF_INT)),reg,0); reg_stack[i]= j-REG_LVAR_OFFSET; + regs_line[reg]=glineno; return reg; } } @@ -890,6 +898,7 @@ for(i=REG_EDI; i<MAX_REGISTER+1;i++) { if (is_data_reg(i) && ! regs[i]) { /* 使われていないなら */ regs[i]=1; /* そのレジスタを使うことを宣言し */ + regs_line[i]=glineno; return i; /* その場所を表す番号を返す */ } } @@ -899,6 +908,7 @@ clear_ptr_cache_reg(i); if (is_data_reg(i)) { regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ + regs_line[i]=glineno; return i; /* その場所を表す番号を返す */ } } @@ -909,6 +919,7 @@ code_assign_lvar( (j=new_lvar(SIZE_OF_INT)),reg,0); reg_stack[i]= j-REG_LVAR_OFFSET; + regs_line[reg]=glineno; return reg; } } @@ -995,6 +1006,7 @@ for(i=MAX_TMP_FREG+FREG_OFFSET;i>MIN_TMP_FREG+FREG_OFFSET;i--) { if (regs[i]) continue; /* 使われている */ regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ + regs_line[i]=glineno; return i; /* その場所を表す番号を返す */ } /* search register stack */ @@ -1003,10 +1015,13 @@ code_dassign_lvar( (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET; + regs_line[reg]=glineno; return reg; } } - for(i=0;i<FREG_VAR_BASE-REG_VAR_MIN;i++) { +#if 0 + // float register と言うのはない + for(i=0;i<FREG_VAR_BASE-FREG_VAR_MIN;i++) { reg =FREG_VAR_BASE-i+FREG_OFFSET; if (! regs[reg]) { /* 使われていないなら */ regs[reg]=USING_REG; /* そのレジスタを使うことを宣言し */ @@ -1014,6 +1029,7 @@ return reg; /* その場所を表す番号を返す */ } } +#endif /* 空いている場所がないなら、エラー (いったい誰が使ってるの?) */ error(REG_ERR); return freg; } @@ -2106,7 +2122,7 @@ if (car(e2) == FNAME) { printf("\tcall\t_%s\n",fn->nm); } else { - printf("\tcall\t*%s\n",register_name(REG_EAX,0)); + printf("\tcall\t*%s\n",register_name(REG_EBX,0)); } } @@ -2140,7 +2156,7 @@ fn=ncaddr(e2); } else { if (car(e2)==INDIRECT) e2=cadr(e2); // (*func)(i) case - jmp = list3(REGISTER,REG_EAX,0); + jmp = list3(REGISTER,REG_EBX,0); if (!simple_arg(e2)) { e3=get_register_var(0); @@ -4113,6 +4129,7 @@ printf("\txorp%s %s,%s\n",sd,n,n); printf("\tucomis%s %s,%s\n",sd,c,n); jcond(label,cond); + free_register(tmp); } int emit_dpop(int d)
--- a/mc-codegen.c Thu Nov 18 01:47:03 2010 +0900 +++ b/mc-codegen.c Thu Nov 18 04:29:03 2010 +0900 @@ -2626,7 +2626,7 @@ case CASSOP: byte = 1; sign = 1; size = 1; break; case SUASSOP: byte = size_of_short; sign = 0; size = size_of_short; break; case SASSOP: byte = size_of_short; sign = 1; size = size_of_short; break; - default: byte = 0; sign = 1; size = size_of_int; + default: byte = lp64?size_of_int:0; sign = 1; size = size_of_int; } e2 = cadr(e1); e3 = caddr(e1); @@ -4191,7 +4191,8 @@ { t = type_value(t); return(t==INT||t==SIGNED||t==CHAR||t==UNSIGNED|| - t==UCHAR||t==SHORT||t==USHORT||t==ENUM); + t==UCHAR||t==SHORT||t==USHORT||t==ENUM || + (lp64 && (t==LONGLONG||t==ULONGLONG))); } /*
--- a/mc-inline.c Thu Nov 18 01:47:03 2010 +0900 +++ b/mc-inline.c Thu Nov 18 04:29:03 2010 +0900 @@ -726,7 +726,8 @@ */ ass = assign_expr0( offset? - list3(ADD,var,list2(CONST,offset)): + lp64?list3(LADD,var,llist2(LCONST,offset)): // binop? + list3(ADD,var,list2(CONST,offset)): var, e,target_type,t); // already correct_typed init_vars = list2(ass,init_vars);
--- a/test/strinit.c Thu Nov 18 01:47:03 2010 +0900 +++ b/test/strinit.c Thu Nov 18 04:29:03 2010 +0900 @@ -10,15 +10,15 @@ int b[3] = {1,2,3}; struct temp { - int a; - int b; - int c; - int d; + long a; + long b; + long c; + long d; struct hoge { - int k; - int j; + long k; + long j; } m; - int e; + long e; } temp1 = { // 101, // 102, @@ -30,9 +30,9 @@ }; struct temp temp3 = { - .c = (int)&b, + .c = (long)&b, .d = -10, - .a = (int)b + .a = (long)b }; struct temp temp4 = { 1,2,3,4,5,6,7}; @@ -241,31 +241,31 @@ #endif struct temp temp11 = { .m = (struct hoge){}, - .c = (int)&b, + .c = (long)&b, }; struct temp temp12 = { .m = (struct hoge){1,3}, - .c = (int)&temp4, + .c = (long)&temp4, }; int c[3] = {1,2,3}; - printf("#0251:1: %d\n",temp1.a); - printf("#0252:1: %d\n",temp1.e); - printf("#0253:1: %d\n",temp1.b); - printf("#0254:2: %d\n",temp2.c); - printf("#0255:2: %d\n",temp2.e); - printf("#0256:2: %d\n",temp2.b); + printf("#0251:1: %ld\n",temp1.a); + printf("#0252:1: %ld\n",temp1.e); + printf("#0253:1: %ld\n",temp1.b); + printf("#0254:2: %ld\n",temp2.c); + printf("#0255:2: %ld\n",temp2.e); + printf("#0256:2: %ld\n",temp2.b); printf("#0257:2: %d\n",(void*)temp3.c==b); - printf("#0258:2: %d\n",temp3.c==(int)b); - printf("#0259:2: %d\n",temp3.a==(int)&b); - printf("#0260:2: %d\n",temp4.m.j); - printf("#0261:2: %d\n",temp5.m.j); - printf("#0262:2: %d\n",temp11.m.j); - printf("#0263:2: %d\n",temp12.m.k); - printf("#0264:2: %d\n",temp12.m.j); - printf("#0265:2: %d\n",temp11.c==(int)&b); - printf("#0266:2: %d\n",temp8.e); - printf("#0267:2: %d\n",temp6.e); + printf("#0258:2: %d\n",temp3.c==(long)b); + printf("#0259:2: %d\n",temp3.a==(long)&b); + printf("#0260:2: %ld\n",temp4.m.j); + printf("#0261:2: %ld\n",temp5.m.j); + printf("#0262:2: %ld\n",temp11.m.j); + printf("#0263:2: %ld\n",temp12.m.k); + printf("#0264:2: %ld\n",temp12.m.j); + printf("#0265:2: %d\n",temp11.c==(long)&b); + printf("#0266:2: %ld\n",temp8.e); + printf("#0267:2: %ld\n",temp6.e); main7(); main8(); linux_kernel();