Mercurial > hg > CbC > old > device
changeset 245:8a72b0afccfc
*** empty log message ***
author | kono |
---|---|
date | Thu, 06 May 2004 11:38:56 +0900 |
parents | 39e28d6cfa56 |
children | 0dcc0ec81ed2 |
files | Changes Idea Makefile README README.jp mc-code-ia32.c mc-code-powerpc.c mc-codegen.c test/code-gen.pl |
diffstat | 9 files changed, 210 insertions(+), 166 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Thu May 06 01:02:06 2004 +0900 +++ b/Changes Thu May 06 11:38:56 2004 +0900 @@ -4100,3 +4100,21 @@ やっぱり LREGISTER なんて作るんじゃなかった。code_lconst とかで edx,eda と dsi,edi pair の切替えをやらないと。 + +Thu May 6 08:33:23 JST 2004 + +ia32, powerpc とも long long まで、通りました。ia32 も一週間 +かかったか。次は、MIPS, ARM ですな。 + +大域変数+オフセット ( heap[3] みたいなの) で、 +heap+24 とか出ない。もともとは offset,y だったから +いらなかったんだけどね。 + +互換性を捨ててしまえば、大域変数ポインタを導入しても +いいんだけど。だだ、32bit 以上のオフセットだとRISC +命令だとまずい。 + +オブジェクト指向だとそのあたりは解決するんだけどね。 + +longlong/float のregressionはいいんだけど、もう少し +整合性があった方がいいかもね。
--- a/Idea Thu May 06 01:02:06 2004 +0900 +++ b/Idea Thu May 06 11:38:56 2004 +0900 @@ -1630,3 +1630,10 @@ cbc2c とする。なるほど。 + +Thu May 6 08:32:05 JST 2004 + +やっぱり library も自分で作らないとね。そうすれば、 +CbC only で作れるから。 + +conv は、あんまり良いアイデアではないみたい。取るか。。。
--- a/Makefile Thu May 06 01:02:06 2004 +0900 +++ b/Makefile Thu May 06 11:38:56 2004 +0900 @@ -94,7 +94,7 @@ # -./$(MC) -Itest/ -s $(TARGET).c -check: $(MC) +check: $(MC) $(TARGET).c -gcc $(TARGET).c -o b.out $(MLIB) -./b.out > $(TARGET).gcc.out -./$(MC) -s $(TARGET).c @@ -112,6 +112,9 @@ -gcc $(TARGET).s $(MLIB) -./a.out > $(TARGET).code-out +test/code-gen-all.c: test/code-gen.pl test/code-gen.c + perl test/code-gen.pl < test/code-gen.c > test/code-gen-all.c + tags: tags-$(ARCH) tags-$(ARCH):
--- a/README Thu May 06 01:02:06 2004 +0900 +++ b/README Thu May 06 11:38:56 2004 +0900 @@ -2,7 +2,6 @@ $Id$ Shinji Kono University of the Ryukyus - 2003 December 0. What is this. @@ -106,7 +105,7 @@ -s comments in assembler source. -c check only. -oname output file names - -Idir add library include directory + -Idir/ add library include directory. / is necessary Some examples can be fond in test directory. @@ -114,18 +113,19 @@ Mips version is not ready. -long long, long double, unsigned long long can be used as type, -but no operation (including assignment) are no allowed. - -Long long value (0LL) can be used but it gives long value. -Long is equal to an int and a pointer (32bit). +64bit long long is now supported +// long long, long double, unsigned long long can be used as type, +// but no operation (including assignment) are no allowed. +// Long long value (0LL) can be used but it gives long value. +// Long is equal to an int and a pointer (32bit). Only Mac OS X and Red hat Linux is supported. Inline directive is ignored and gives normal function definition. -Register float arguments does no accepts assignment operation such as - *=, /=, +=. +Register float is supported in Power PC +// Register float arguments does no accepts assignment operation such as +// *=, /=, +=. No built-in alloca. @@ -144,6 +144,7 @@ No runtime driver for CbC. - #include does not search, sources current directory. +// #include does not search, sources current directory. + #include does search, sources current directory.
--- a/README.jp Thu May 06 01:02:06 2004 +0900 +++ b/README.jp Thu May 06 11:38:56 2004 +0900 @@ -2,7 +2,6 @@ $Id$ 河野 真治 琉球大学情報工学科 - 2003 December 0. What is this. @@ -126,18 +125,18 @@ Mips コンパイラはまだ動きません。 -long long, long double は型として使うことはできますが、 -演算はできません。変数の定義もできないと思う。 - -Long long value (0LL) は使えますが、単なるlongを返します。 -long は32bit. int もpointerも同じ。 +64 bit long long が動きます。 +// long long, long double は型として使うことはできますが、 +// 演算はできません。変数の定義もできないと思う。 +// Long long value (0LL) は使えますが、単なるlongを返します。 +// long は32bit. int もpointerも同じ。 Mac OS X と Red hat Linux だけでテストしてあります。 -Inline 無視され、普通の関数にコンパイルされます。 +Inline は無視され、普通のstatic関数にコンパイルされます。 -浮動小数点レジスタへの代入計算はできません。 - *=, /=, +=. +//浮動小数点レジスタへの代入計算はできません。 +// *=, /=, +=. built-in allocaはありません。 @@ -145,7 +144,7 @@ Switch 文は、分岐にコンパイルされます。テーブルは生成されません。 -マクロの機能、連結とかは動きません。 +マクロの機能のうち連結とかは動きません。 マクロはコルーチンで、プリプロセッサではありません。振舞いがcppと 少し異なります。 @@ -154,8 +153,8 @@ CbC のcode segment から実行を始めることはできません。 - #include は、呼び出したソースコードのカレントディレクトリを -サーチしません。 +// #include は、呼び出したソースコードのカレントディレクトリをサーチしません。 + #include は、呼び出したソースコードのカレントディレクトリをサーチします。 その他、たくさん。ANSI コンパチを目指しているわけではないので...
--- a/mc-code-ia32.c Thu May 06 01:02:06 2004 +0900 +++ b/mc-code-ia32.c Thu May 06 11:38:56 2004 +0900 @@ -16,6 +16,20 @@ }; +#define SIZE_OF_INT 4 +#define SIZE_OF_SHORT 2 +#define SIZE_OF_FLOAT 4 +#define SIZE_OF_DOUBLE 8 +#define SIZE_OF_LONGLONG 8 +#define ENDIAN 0 + +int size_of_int; +int size_of_short; +int size_of_float; +int size_of_double; +int size_of_longlong; +int endian; + #define SAVE_STACKS 1 #define TEXT_EMIT_MODE 0 @@ -215,12 +229,12 @@ arg_offset = 8; // func_disp_offset = -12; disp_offset = -12; - size_of_int = 4; - size_of_short = 2; - size_of_float = 4; - size_of_double = 8; - size_of_longlong = 8; - endian = 0; + size_of_int = SIZE_OF_INT; + size_of_short = SIZE_OF_SHORT; + size_of_float = SIZE_OF_FLOAT; + size_of_double = SIZE_OF_DOUBLE; + size_of_longlong = SIZE_OF_LONGLONG; + endian = ENDIAN; MAX_REGISTER=6; MAX_DATA_REG=4; MAX_POINTER=3; @@ -254,7 +268,7 @@ } if (byte==1 && rname[i] <= REG_EDX) { return reg_name_l[rname[i]]; - } else if (byte==size_of_short && rname[i] <= REG_EDX) { + } else if (byte==SIZE_OF_SHORT && rname[i] <= REG_EDX) { return reg_name_w[rname[i]]; } else { return reg_name[rname[i]]; /* 0 or 4 means int */ @@ -339,7 +353,7 @@ reg_var=2; regvar[0]=h; regvar[1]=l; return list2(LREGISTER,REG_L); } - return list2(LVAR,new_lvar(size_of_longlong)); + return list2(LVAR,new_lvar(SIZE_OF_LONGLONG)); } int @@ -433,7 +447,7 @@ regv[n->dsp]= 1; regs[n->dsp]= INPUT_REG; reg_var++; - cadddr(args)=size_of_int; /* why we need this? */ + cadddr(args)=SIZE_OF_INT; /* why we need this? */ } } else if (type==FLOAT||type==DOUBLE) { if ((reg = get_input_dregister_var(freg_var,n,is_code0,1))) { @@ -517,13 +531,13 @@ return list3(REGISTER,i,(int)nptr); /* その場所を表す番号を返す */ } } - return list2(LVAR,new_lvar(size_of_int)); + return list2(LVAR,new_lvar(SIZE_OF_INT)); } int get_dregister_var(NMTBL *nptr,int d) { - return list2(LVAR,new_lvar(d?size_of_double:size_of_float)); + return list2(LVAR,new_lvar(d?SIZE_OF_DOUBLE:SIZE_OF_FLOAT)); } void @@ -663,7 +677,7 @@ regv[creg]=1; } -static char *cload(int sign,int sz) { return sz==1?(sign?"movsbl":"movzbl"):sz==size_of_short?(sign?"movswl":"movzwl"):"movl"; } +static char *cload(int sign,int sz) { return sz==1?(sign?"movsbl":"movzbl"):sz==SIZE_OF_SHORT?(sign?"movswl":"movzwl"):"movl"; } void code_crgvar(int e1,int creg,int sign,int sz){ @@ -760,7 +774,7 @@ g_expr(e2); xrn = register_name(creg,0); use_int(reg); - printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==size_of_short)?"addw":"addl",dir,xrn); + printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==SIZE_OF_SHORT)?"addw":"addl",dir,xrn); printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0)); } @@ -780,7 +794,7 @@ xrn = register_name((e2=emit_pop(0)),0); use_int(reg); printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(reg,0)); - printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==size_of_short)?"addw":"addl",dir,xrn); + printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==SIZE_OF_SHORT)?"addw":"addl",dir,xrn); emit_pop_free(e2); } @@ -847,7 +861,7 @@ use_int(reg); if (sz==1) printf("\tcmpb $0,%s\n",((NMTBL*)cadr(e1))->nm); - else if (sz==size_of_short) + else if (sz==SIZE_OF_SHORT) printf("\tcmpw $0,%s\n",((NMTBL*)cadr(e1))->nm); } @@ -857,7 +871,7 @@ use_int(reg); if (sz==1) printf("\tcmpb $0,%d(%%ebp)\n",lvar(e1)); - else if (sz==size_of_short) + else if (sz==SIZE_OF_SHORT) printf("\tcmpw $0,%d(%%ebp)\n",lvar(e1)); } @@ -1029,14 +1043,14 @@ int length,xreg,save,lreg,count; g_expr(e4); length=size(t); - if(length%size_of_int) { - length += size_of_int - (length%size_of_int); + if(length%SIZE_OF_INT) { + length += SIZE_OF_INT - (length%SIZE_OF_INT); } - for(count=0;length<MAX_COPY_LEN;count++,length-=size_of_int) { + for(count=0;length<MAX_COPY_LEN;count++,length-=SIZE_OF_INT) { if (length==0) return count; else { printf("\tpushl %d(%s)\n", - length-size_of_int,register_name(creg,0)); + length-SIZE_OF_INT,register_name(creg,0)); } } printf("\tsubl $%d,%%esp\n",length); @@ -1050,7 +1064,7 @@ xreg = get_register(); } if (save) - printf("\tlea %d(%%esp),%s\n",size_of_int,register_name(xreg,0)); + printf("\tlea %d(%%esp),%s\n",SIZE_OF_INT,register_name(xreg,0)); else printf("\tmovl %%esp,%s\n",register_name(xreg,0)); regv[xreg]=1; @@ -1065,7 +1079,7 @@ regv[xreg]=1; } else free_register(xreg); - return length/size_of_int; + return length/SIZE_OF_INT; } int @@ -1115,13 +1129,13 @@ } else if (t==DOUBLE) { g_expr(e4); printf("\tleal\t-8(%%esp),%%esp\n\tfstpl\t(%%esp)\n"); - nargs += size_of_double/size_of_int; + nargs += SIZE_OF_DOUBLE/SIZE_OF_INT; fregv[freg]=0; continue; } else if (t==FLOAT) { g_expr(e4); printf("\tleal\t-4(%%esp),%%esp\n\tfstps\t(%%esp)\n"); - nargs += size_of_float/size_of_int; + nargs += SIZE_OF_FLOAT/SIZE_OF_INT; fregv[freg]=0; continue; } else if (car(t)==STRUCT||car(t)==UNION) { @@ -1154,7 +1168,7 @@ } else { printf("\tcall\t*%s\n",register_name(creg,0)); } - if (nargs) printf("\taddl $%d,%%esp\n",size_of_int*nargs); + if (nargs) printf("\taddl $%d,%%esp\n",SIZE_OF_INT*nargs); if (saved) { printf("\tpopl %s\n",register_name(save,0)); } else { @@ -1199,7 +1213,7 @@ } int -code_rindirect(int e1, int reg,int offset, int us) +code_rindirect(int e1, int reg,int offset, int sign) { char *crn,*op; int byte; @@ -1212,12 +1226,12 @@ } int -code_crindirect(int e1, int reg,int offset, int us) +code_crindirect(int e1, int reg,int offset, int sign) { char *crn,*op; int byte; g_expr(e1); - byte = 0; op=us?"movzbl":"movsbl"; + byte = 0; op=sign?"movsbl":"movzbl"; crn = register_name(creg,0); use_int(reg); printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0)); @@ -1225,12 +1239,12 @@ } int -code_srindirect(int e1, int reg,int offset, int us) +code_srindirect(int e1, int reg,int offset, int sign) { char *crn,*op; int byte; g_expr(e1); - byte = 0; op=us?"movzwl":"movswl"; + byte = 0; op=sign?"movswl":"movzwl"; crn = register_name(creg,0); use_int(reg); printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0)); @@ -1255,11 +1269,11 @@ char *crn = register_name(creg,0); use_longlong(reg); if((reg==REG_L&&rname[creg]==REG_ESI)||(rname[creg]==REG_EAX)) { - printf("\tmovl %d(%s),%s\n",offset+size_of_int,crn,l_edx(reg)); + printf("\tmovl %d(%s),%s\n",offset+SIZE_OF_INT,crn,l_edx(reg)); printf("\tmovl %d(%s),%s\n",offset,crn,l_eax(reg)); } else { printf("\tmovl %d(%s),%s\n",offset,crn,l_eax(reg)); - printf("\tmovl %d(%s),%s\n",offset+size_of_int,crn,l_edx(reg)); + printf("\tmovl %d(%s),%s\n",offset+SIZE_OF_INT,crn,l_edx(reg)); } } @@ -1278,7 +1292,7 @@ char * move(int byte) { - return byte==1?"movb":byte==size_of_short?"movw":"movl"; + return byte==1?"movb":byte==SIZE_OF_SHORT?"movw":"movl"; } void @@ -1640,7 +1654,7 @@ void code_leave(char *name) { - disp &= -size_of_int; + disp &= -SIZE_OF_INT; printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset); printf("_%d:\n",labelno); printf("\t.size\t%s,_%d-%s\n",name,labelno,name); @@ -1678,7 +1692,7 @@ { int sz; - disp &= -size_of_int; + disp &= -SIZE_OF_INT; if (control) code_set_return_register(1); if (retcont) { @@ -1686,13 +1700,13 @@ jmp(retlabel); fwddef(retcont); if (cadr(fnptr->ty)==FLOAT||cadr(fnptr->ty)==DOUBLE) { - printf("\tfldl %d(%%ebp)\n",-size_of_double); + printf("\tfldl %d(%%ebp)\n",-SIZE_OF_DOUBLE); } else if (cadr(fnptr->ty)>0&&( car(cadr(fnptr->ty))==STRUCT || car(cadr(fnptr->ty))==UNION)) { sz = size(cadr(fnptr->ty)); printf("\tlea %d(%%ebp),%s\n",-sz,register_name(dreg,0)); - printf("\tmovl %d(%%ebp),%s\n",disp-size_of_int, + printf("\tmovl %d(%%ebp),%s\n",disp-SIZE_OF_INT, register_name(creg,0)); emit_copy(dreg,creg,sz,0,1,1); } else if (cadr(fnptr->ty)!=VOID) { @@ -1820,10 +1834,10 @@ } else if (t==SHORT||t==USHORT) { printf("\t.short %d\n",cadr(e)); if (data_alignment>0) data_alignment++; - gpc += size_of_short; + gpc += SIZE_OF_SHORT; } else { printf("\t.long %d\n",cadr(e)); - gpc += size_of_int; + gpc += SIZE_OF_INT; } #if LONGLONG_CODE } else if(t==LONGLONG||t==ULONGLONG) { @@ -1839,7 +1853,7 @@ printf("\t.long\t0x%x\n",*(int *)&f); #endif } else if(t!=CHAR) { - gpc += size_of_int; + gpc += SIZE_OF_INT; if(car(e)==ADDRESS&&car(cadr(e))==GVAR) { printf("\t.long %s\n",((NMTBL *)cadr(cadr(e)))->nm); } else if(car(e)==GVAR) { @@ -2024,12 +2038,12 @@ void code_d2i(int reg) { use_int(reg); - printf("\tlea -%d(%%esp),%%esp\n",size_of_int*2); + printf("\tlea -%d(%%esp),%%esp\n",SIZE_OF_INT*2); printf("\tfnstcw (%%esp)\n"); printf("\tmovl (%%esp), %s\n",register_name(creg,0)); printf("\tmovb $12, 1(%%esp)\n"); printf("\tfldcw (%%esp)\n"); - printf("\tfistpl %d(%%esp)\n",size_of_int); + printf("\tfistpl %d(%%esp)\n",SIZE_OF_INT); printf("\tmovl %s, (%%esp)\n",register_name(creg,0)); printf("\tfldcw (%%esp)\n"); printf("\tpopl %s\n",register_name(creg,0)); @@ -2040,31 +2054,31 @@ { printf("\tpushl %s\n",register_name(creg,0)); printf("\tfildl (%%esp)\n"); - printf("\tlea %d(%%esp),%%esp\n",size_of_int); + printf("\tlea %d(%%esp),%%esp\n",SIZE_OF_INT); } void code_d2u(int reg) { use_int(reg); - printf("\tlea -%d(%%esp),%%esp\n",size_of_int*3); + printf("\tlea -%d(%%esp),%%esp\n",SIZE_OF_INT*3); printf("\tfnstcw (%%esp)\n"); printf("\tmovl (%%esp), %s\n",register_name(reg,0)); printf("\tmovb $12, 1(%%esp)\n"); printf("\tfldcw (%%esp)\n"); printf("\tmovl %s, (%%esp)\n",register_name(reg,0)); - printf("\tfistpll %d(%%esp)\n",size_of_int); + printf("\tfistpll %d(%%esp)\n",SIZE_OF_INT); printf("\tfldcw (%%esp)\n"); - printf("\tmovl %d(%%esp),%s\n",size_of_int,register_name(reg,0)); - printf("\tlea %d(%%esp),%%esp\n",size_of_int*3); + printf("\tmovl %d(%%esp),%s\n",SIZE_OF_INT,register_name(reg,0)); + printf("\tlea %d(%%esp),%%esp\n",SIZE_OF_INT*3); } void code_u2d(int reg) { printf("\tpushl %s\n",register_name(creg,0)); printf("\tpushl %s\n",register_name(creg,0)); - printf("\tmovl $0, %d(%%esp)\n",size_of_int); + printf("\tmovl $0, %d(%%esp)\n",SIZE_OF_INT); printf("\tfildll (%%esp)\n"); - printf("\tlea %d(%%esp),%%esp\n",size_of_int*2); + printf("\tlea %d(%%esp),%%esp\n",SIZE_OF_INT*2); } void code_d2f(int reg) { } @@ -2274,7 +2288,7 @@ creg = xreg; } code_assign_lvar( - (reg_stack[sp]=new_lvar(size_of_int)),creg,0); + (reg_stack[sp]=new_lvar(SIZE_OF_INT)),creg,0); reg_stack[sp]= reg_stack[sp]-REG_LVAR_OFFSET; regv[xreg]=0; creg=screg; @@ -2292,7 +2306,7 @@ while(sp-->0) { if ((xreg=freg_stack[sp])==-1) { code_dassign_lvar( - (freg_stack[sp]=new_lvar(size_of_double)),freg,1); + (freg_stack[sp]=new_lvar(SIZE_OF_DOUBLE)),freg,1); freg_stack[sp]= freg_stack[sp]-REG_LVAR_OFFSET; } }
--- a/mc-code-powerpc.c Thu May 06 01:02:06 2004 +0900 +++ b/mc-code-powerpc.c Thu May 06 11:38:56 2004 +0900 @@ -39,12 +39,19 @@ int code_lassop_p = 1; -int size_of_int = 4; -int size_of_short = 2; -int size_of_float = 4; -int size_of_double = 8; -int size_of_longlong = 8; -int endian = 1; +#define SIZE_OF_INT 4 +#define SIZE_OF_SHORT 2 +#define SIZE_OF_FLOAT 4 +#define SIZE_OF_DOUBLE 8 +#define SIZE_OF_LONGLONG 8 +#define ENDIAN 1 + +int size_of_int = SIZE_OF_INT; +int size_of_short = SIZE_OF_SHORT; +int size_of_float = SIZE_OF_FLOAT; +int size_of_double = SIZE_OF_DOUBLE; +int size_of_longlong = SIZE_OF_LONGLONG; +int endian = ENDIAN; static int reg_sp; /* REGister Stack-Pointer */ static int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ @@ -248,7 +255,7 @@ <------------lvar_offset-------> r+ +------------+---+---------------+----------+--------------+----+ - callee arg xx register save local caller arg xx - reg_save disp max_func_args*size_of_int + reg_save disp max_func_args*SIZE_OF_INT lvar>0 lvar<0 lvar>0x1000 0000 code segment stack frame @@ -259,7 +266,7 @@ cousin arg xx reg save !callee arg !code local caller arg xx r20-r29 lvar>0 lvar<0 lvar>0x1000 000 f20-f31 <-my_func_args--><--disp-----><-max_func_arg-> - *size_of_int *size_of_int + *SIZE_OF_INT *SIZE_OF_INT */ int arg_offset = 24; int arg_offset1 = 24; int disp_offset = -12; @@ -279,16 +286,16 @@ #if 0 int l; #endif - int lvar_offsetv = -disp+max_func_args*size_of_int+func_disp_offset; - int r1_offsetv = -disp+max_func_args*size_of_int-reg_save+r1_offset; + int lvar_offsetv = -disp+max_func_args*SIZE_OF_INT+func_disp_offset; + int r1_offsetv = -disp+max_func_args*SIZE_OF_INT-reg_save+r1_offset; printf(".set L_%d,%d\n",lvar_offset_label,lvar_offsetv); printf(".set L_%d,%d\n",r1_offset_label,r1_offsetv); #if 0 printf("# function %s\n",fnptr->nm); l = ARG_LVAR_OFFSET; printf("# offset call0\t%d\n",CALLER_ARG); - l = ARG_LVAR_OFFSET+max_func_args*size_of_int; -printf("# offset calln\t%d %d\n",CALLER_ARG,max_func_args*size_of_int); + l = ARG_LVAR_OFFSET+max_func_args*SIZE_OF_INT; +printf("# offset calln\t%d %d\n",CALLER_ARG,max_func_args*SIZE_OF_INT); l = disp; printf("# offset lvarn\t%d %d\n",FUNC_LVAR+lvar_offsetv,disp); l = 0; @@ -443,7 +450,7 @@ n->dsp = cadr(reg); regs[n->dsp]= INPUT_REG; reg_var++; - cadddr(args)=size_of_int; + cadddr(args)=SIZE_OF_INT; } } else if (type==FLOAT) { if ((reg = get_input_dregister_var(freg_var,n,is_code0,0))) { @@ -501,7 +508,7 @@ for(i=0;i<reg_sp;i++) { if ((reg=reg_stack[i])>=0) { code_assign_lvar( - (j=new_lvar(size_of_int)),reg,0); + (j=new_lvar(SIZE_OF_INT)),reg,0); reg_stack[i]= j-REG_LVAR_OFFSET; return reg; } @@ -511,7 +518,7 @@ for(i=0;i<lreg_sp;i++) { if ((reg=lreg_stack[i])>=0) { code_lassign_lvar( - (j=new_lvar(size_of_longlong)),reg); + (j=new_lvar(SIZE_OF_LONGLONG)),reg); lreg_stack[i]= j-REG_LVAR_OFFSET; free_register(reg); return get_register(); @@ -560,7 +567,7 @@ for(i=0;i<freg_sp;i++) { if ((reg=freg_stack[i])>=0) { code_dassign_lvar( - (freg_stack[i]=new_lvar(size_of_double)),reg,1); + (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET; return reg; } @@ -657,7 +664,7 @@ } } not_found: - return list2(LVAR,new_lvar(size_of_longlong)); + return list2(LVAR,new_lvar(SIZE_OF_LONGLONG)); } void @@ -879,7 +886,7 @@ return list3(REGISTER,REG_VAR_BASE-i,(int)n); } } - return list2(LVAR,new_lvar(size_of_int)); + return list2(LVAR,new_lvar(SIZE_OF_INT)); } int @@ -895,7 +902,7 @@ FREG_VAR_BASE-i+FREG_OFFSET,(int)n); } } - return list2(LVAR,new_lvar(size_of_double)); + return list2(LVAR,new_lvar(SIZE_OF_DOUBLE)); } void @@ -1012,8 +1019,8 @@ return r; } -static char *cload(int sz) { return sz==1?"lbz":sz==size_of_short?"lhz":"lwz"; } -static char *cstore(int sz) { return sz==1?"stb":sz==size_of_short?"sth":"stw"; } +static char *cload(int sz) { return sz==1?"lbz":sz==SIZE_OF_SHORT?"lhz":"lwz"; } +static char *cstore(int sz) { return sz==1?"stb":sz==SIZE_OF_SHORT?"sth":"stw"; } static void cext(int sign,int sz,int reg) @@ -1022,12 +1029,12 @@ if (sign) { if (sz==1) printf("\textsb %s,%s\n",crn,crn); - else if (sz==size_of_short) + else if (sz==SIZE_OF_SHORT) printf("\textsh %s,%s\n",crn,crn); } else { if (sz==1) printf("\trlwinm %s,%s,0,0xff\n",crn,crn); - else if (sz==size_of_short) + else if (sz==SIZE_OF_SHORT) printf("\trlwinm %s,%s,0,0xffff\n",crn,crn); } } @@ -1450,8 +1457,8 @@ g_expr(e4); if (!is_int_reg(creg)) error(-1); length=size(t); - if(length%size_of_int) { - length += size_of_int - (length%size_of_int); + if(length%SIZE_OF_INT) { + length += SIZE_OF_INT - (length%SIZE_OF_INT); } dreg = get_register(); if (!dreg) error(-1); drn = register_name(dreg); @@ -1460,14 +1467,14 @@ sreg = get_register(); if (!sreg) error(-1); srn = register_name(sreg); code_lvar(cadr(arg),sreg); - for(count=0;length<MAX_COPY_LEN;count++,length-=size_of_int) { + for(count=0;length<MAX_COPY_LEN;count++,length-=SIZE_OF_INT) { if (length==0) { free_register(sreg); free_register(dreg); return count; } else { - printf("\tlwz %s,%d(%s)\n",drn,length-size_of_int,crn); - printf("\tstwu %s,%d(%s)\n",drn,-size_of_int,srn); + printf("\tlwz %s,%d(%s)\n",drn,length-SIZE_OF_INT,crn); + printf("\tstwu %s,%d(%s)\n",drn,-SIZE_OF_INT,srn); } } } @@ -1475,7 +1482,7 @@ /* downward direction copy */ emit_copy(creg,dreg,length,0,0,1); if (dreg) free_register(dreg); - return length/size_of_int; + return length/SIZE_OF_INT; } void @@ -1591,21 +1598,21 @@ if (tag==REGISTER) { /* regs[reg]==INPUT_REG case should be considered */ n->dsp = offset; - offset+=size_of_int; + offset+=SIZE_OF_INT; t = INT; reg += reg_offset; /* for duplicated floating point argument */ } else if (tag==DREGISTER) { /* regs[reg]==INPUT_REG case should be considered */ n->dsp = offset; t = n->ty; - if(t==FLOAT) { offset+=size_of_float; reg_offset+=1; } - else if(t==DOUBLE) { offset+=size_of_double; reg_offset+=2; } + if(t==FLOAT) { offset+=SIZE_OF_FLOAT; reg_offset+=1; } + else if(t==DOUBLE) { offset+=SIZE_OF_DOUBLE; reg_offset+=2; } else error(-1); } else if (tag==LREGISTER) { /* regs[reg]==INPUT_REG case should be considered */ n->dsp = offset; t = n->ty; - offset+=size_of_longlong; reg_offset+=2; + offset+=SIZE_OF_LONGLONG; reg_offset+=2; } else { offset += size(n->ty); continue; @@ -1636,7 +1643,7 @@ int caller_arg_offset_v(int arg) { - return ARG_LVAR_OFFSET+arg*size_of_int; + return ARG_LVAR_OFFSET+arg*SIZE_OF_INT; } void @@ -1781,7 +1788,7 @@ special_lvar = cadr(e4); e5 = list2(LVAR,special_lvar); } else { - special_lvar = new_lvar(size_of_double); + special_lvar = new_lvar(SIZE_OF_DOUBLE); g_expr(assign_expr0( (e5=list2(LVAR,special_lvar)),e4,DOUBLE,t)); reg_arg_list = list2(e5,reg_arg_list); @@ -1800,7 +1807,7 @@ reg_arg_list = list2(r1,reg_arg_list); arg_assign = list2( assign_expr0(r0,e5,INT,INT), arg_assign); arg_assign = list2( assign_expr0(r1, - list2(LVAR,special_lvar+size_of_int), + list2(LVAR,special_lvar+SIZE_OF_INT), INT,INT), arg_assign); } reg_arg += 2; @@ -1831,7 +1838,7 @@ use_input_reg(cadr(arg),1); /* protect from input register free */ g_expr_u(assign_expr0(arg,e4,t,t)); /* XXX */ freg_arg++; - nargs += size(t)/size_of_int; + nargs += size(t)/SIZE_OF_INT; continue; } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { arg = list2(LVAR,caller_arg_offset_v(nargs)); @@ -1922,7 +1929,7 @@ } int -code_crindirect(int e1, int reg,int offset, int us) +code_crindirect(int e1, int reg,int offset, int sign) { char *crn,*rrn; g_expr(e1); @@ -1930,19 +1937,16 @@ crn=register_name(creg); use_int(reg); rrn=register_name(reg); - - if (us) { - printf("\tlbz %s,%d(%s)\n",rrn,offset,crn); - return UCHAR; - } else { - printf("\tlbz %s,%d(%s)\n",rrn,offset,crn); - printf("\textsb %s,%s\n",rrn,rrn); + printf("\tlbz %s,%d(%s)\n",rrn,offset,crn); + if (sign) { + cext(sign,1,reg); return CHAR; } + return UCHAR; } int -code_srindirect(int e1, int reg,int offset, int us) +code_srindirect(int e1, int reg,int offset, int sign) { char *crn,*rrn; g_expr(e1); @@ -1950,14 +1954,12 @@ crn=register_name(creg); use_int(reg); rrn = register_name(reg); - if (us) { - printf("\tlhz %s,%d(%s)\n",rrn,offset,crn); - return USHORT; - } else { - printf("\tlhz %s,%d(%s)\n",rrn,offset,crn); - printf("\textsh %s,%s\n",rrn,rrn); + printf("\tlhz %s,%d(%s)\n",rrn,offset,crn); + if (sign) { + cext(sign,SIZE_OF_SHORT,reg); return SHORT; } + return USHORT; } #if FLOAT_CODE @@ -1988,9 +1990,9 @@ use_longlong(reg); if (creg0!=regv_h(reg)) { printf("\tlwz %s,%d(%s)\n",lregister_name_high(reg),offset,crn); - printf("\tlwz %s,%d(%s)\n",lregister_name_low(reg),offset+size_of_int,crn); + printf("\tlwz %s,%d(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); } else { - printf("\tlwz %s,%d(%s)\n",lregister_name_low(reg),offset+size_of_int,crn); + printf("\tlwz %s,%d(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); printf("\tlwz %s,%d(%s)\n",lregister_name_high(reg),offset,crn); } return us?ULONGLONG:LONGLONG; @@ -2014,7 +2016,7 @@ lvar_intro(e2); if (byte==1) { printf("\tstb %s,",crn); - } else if (byte==size_of_short) { + } else if (byte==SIZE_OF_SHORT) { printf("\tsth %s,",crn); } else { printf("\tstw %s,",crn); @@ -2040,7 +2042,7 @@ if (byte==1) { printf("\tstb %s,0(%s)\n",crn,drn); - } else if (byte==size_of_short) { + } else if (byte==SIZE_OF_SHORT) { printf("\tsth %s,0(%s)\n",crn,drn); } else { printf("\tstw %s,0(%s)\n",crn,drn); @@ -2071,7 +2073,7 @@ drn = register_name(edx); if (byte==1) { printf("\tstb %s,0(%s)\n",crn,drn); - } else if (byte==size_of_short) { + } else if (byte==SIZE_OF_SHORT) { printf("\tsth %s,0(%s)\n",crn,drn); } else { printf("\tstw %s,0(%s)\n",crn,drn); @@ -2237,7 +2239,7 @@ register_name(xreg)); if (sign) printf("\textsb %s,%s\n",crn,crn); - } else if (byte==size_of_short) { + } else if (byte==SIZE_OF_SHORT) { printf("\tlhz %s,%d(%s)\n",register_name(creg),n, register_name(xreg)); if (sign) @@ -2334,8 +2336,8 @@ code_leave(char *name) { int r1_offsetv; - disp&= -size_of_int; - r1_offsetv = -disp+max_func_args*size_of_int+code_disp_offset; + disp&= -SIZE_OF_INT; + r1_offsetv = -disp+max_func_args*SIZE_OF_INT+code_disp_offset; printf(".set L_%d,%d\n",code_disp_label,-r1_offsetv); local_table(); @@ -2381,8 +2383,8 @@ reg_save_offset() { return -( - (REAL_MAX_REGISTER-(REG_VAR_BASE-max_reg_var))*size_of_int+ - (REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*size_of_double + (REAL_MAX_REGISTER-(REG_VAR_BASE-max_reg_var))*SIZE_OF_INT+ + (REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*SIZE_OF_DOUBLE ); } @@ -2409,14 +2411,14 @@ sz = size(cadr(fnptr->ty)); printf("\tli r7,%d\n",sz); printf("\tsubl r6,r7,r30\n"); - printf("\tlwz r3,lo16(%d)(r30)\n",(my_func_args-1)*size_of_int); + printf("\tlwz r3,lo16(%d)(r30)\n",(my_func_args-1)*SIZE_OF_INT); emit_copy(6,3,sz,0,1,1); } else if (cadr(fnptr->ty)!=VOID) { printf("\tmr r3,r29\n"); } #if !R1SAVE printf("\tla r1,lo16(%d)(r30)\n", - -reg_save+my_func_args*size_of_int); + -reg_save+my_func_args*SIZE_OF_INT); #endif printf("\tb L_%d\n",retcont1); } @@ -2440,7 +2442,7 @@ printf("\tblr\n"); } - disp &= -size_of_int; + disp &= -SIZE_OF_INT; fwddef(code_setup); printf("\tstmw r%d,%d(r1)\n", REG_VAR_BASE-max_reg_var,reg_save); @@ -2544,10 +2546,10 @@ } else if (t==SHORT||t==USHORT) { printf("\t.short %d\n",cadr(e)); if (data_alignment>0) data_alignment++; - gpc += size_of_short; + gpc += SIZE_OF_SHORT; } else { printf("\t.long %d\n",cadr(e)); - gpc += size_of_int; + gpc += SIZE_OF_INT; } #if LONGLONG_CODE } else if(t==LONGLONG||t==ULONGLONG) { @@ -2563,7 +2565,7 @@ printf("\t.long\t0x%x\n",*(int *)&f); #endif } else if(t!=CHAR) { - gpc += size_of_int; + gpc += SIZE_OF_INT; if(car(e)==ADDRESS&&car(cadr(e))==GVAR) { printf("\t.long _%s\n",((NMTBL *)cadr(cadr(e)))->nm); } else if(car(e)==FNAME) { @@ -2911,7 +2913,7 @@ { char *frn; char *crn; - int e2 = new_lvar(size_of_double); + int e2 = new_lvar(SIZE_OF_DOUBLE); use_double0(); frn = fregister_name(freg); @@ -2922,8 +2924,8 @@ printf("\tfctiwz %s,%s\n",frn,frn); lvar_intro(e2); 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); + lvar_intro(e2+SIZE_OF_DOUBLE-SIZE_OF_INT); + printf("\tlwz %s,",crn); lvar(e2+SIZE_OF_DOUBLE-SIZE_OF_INT); } static int i2d_lib_used=0; @@ -3475,11 +3477,11 @@ crn_l = lregister_name_low(creg); if (e2==regv_h(creg)) { - printf("\tstw %s,%d(%s)\n",crn_l,size_of_int,drn); + printf("\tstw %s,%d(%s)\n",crn_l,SIZE_OF_INT,drn); printf("\tstw %s,0(%s)\n",crn_h,drn); } else { printf("\tstw %s,0(%s)\n",crn_h,drn); - printf("\tstw %s,%d(%s)\n",crn_l,size_of_int,drn); + printf("\tstw %s,%d(%s)\n",crn_l,SIZE_OF_INT,drn); } } @@ -3502,7 +3504,7 @@ crn_l = lregister_name_low(creg); lvar_intro(e2); printf("\tstw %s,",crn_h);lvar(e2); - printf("\tstw %s,",crn_l);lvar(e2+size_of_int); + printf("\tstw %s,",crn_l);lvar(e2+SIZE_OF_INT); } void @@ -3559,7 +3561,7 @@ crn_l = lregister_name_low(creg); r = get_ptr_cache((NMTBL*)cadr(e1)); printf("\tlwz %s,0(%s)\n",crn_h,register_name(r)); - printf("\tlwz %s,%d(%s)\n",crn_l,size_of_int,register_name(r)); + printf("\tlwz %s,%d(%s)\n",crn_l,SIZE_OF_INT,register_name(r)); } void @@ -3572,7 +3574,7 @@ crn_l = lregister_name_low(creg); lvar_intro(e1); printf("\tlwz %s,",crn_h); lvar(e1); - printf("\tlwz %s,",crn_l); lvar(e1+size_of_int); + printf("\tlwz %s,",crn_l); lvar(e1+SIZE_OF_INT); } #if 0 @@ -4211,11 +4213,11 @@ } xreg = emit_pop(0); xrn = register_name(xreg); - printf("\tlwz %s,%d(%s)\n",drn_l,size_of_int,xrn); + printf("\tlwz %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn); printf("\tlwz %s,0(%s)\n",drn_h,xrn); printf("\taddic %s,%s,%d\n",drn_l,drn_l,dir); printf("\tadd%s %s,%s\n",addze(dir),drn_h,drn_h); - printf("\tstw %s,%d(%s)\n",drn_l,size_of_int,xrn); + printf("\tstw %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn); printf("\tstw %s,0(%s)\n",drn_h,xrn); emit_pop_free(xreg); } @@ -4253,11 +4255,11 @@ } xreg = emit_pop(0); xrn = register_name(xreg); - printf("\tlwz %s,%d(%s)\n",drn_l,size_of_int,xrn); + printf("\tlwz %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn); printf("\tlwz %s,0(%s)\n",drn_h,xrn); printf("\taddic %s,%s,%d\n",nrn_l,drn_l,dir); printf("\tadd%s %s,%s\n",addze(dir),nrn_h,drn_h); - printf("\tstw %s,%d(%s)\n",nrn_l,size_of_int,xrn); + printf("\tstw %s,%d(%s)\n",nrn_l,SIZE_OF_INT,xrn); printf("\tstw %s,0(%s)\n",nrn_h,xrn); emit_pop_free(xreg); free_register(nreg); @@ -4283,14 +4285,14 @@ printf("\tlwz %s,0(%s)\n",lregister_name_high(reg), register_name(edx)); printf("\tlwz %s,%d(%s)\n",lregister_name_low(reg), - size_of_int,register_name(edx)); + SIZE_OF_INT,register_name(edx)); free_register(edx); ltosop(op,reg,xreg); edx = emit_pop(0); printf("\tstw %s,0(%s)\n",lregister_name_high(reg), register_name(edx)); printf("\tstw %s,%d(%s)\n",lregister_name_low(reg), - size_of_int,register_name(edx)); + SIZE_OF_INT,register_name(edx)); free_register(edx); emit_lpop_free(xreg); } @@ -4313,7 +4315,7 @@ for(i=0;i<reg_sp;i++) { if ((reg=reg_stack[i])>=0) { code_assign_lvar( - (reg_stack[i]=new_lvar(size_of_int)),reg,0); + (reg_stack[i]=new_lvar(SIZE_OF_INT)),reg,0); reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET; } } @@ -4321,7 +4323,7 @@ for(i=0;i<freg_sp;i++) { if ((reg=freg_stack[i])>=0) { code_dassign_lvar( - (freg_stack[i]=new_lvar(size_of_double)),reg,1); + (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET; } } @@ -4330,7 +4332,7 @@ for(i=0;i<lreg_sp;i++) { if ((reg=lreg_stack[i])>=0) { code_lassign_lvar( - (lreg_stack[i]=new_lvar(size_of_longlong)),reg); + (lreg_stack[i]=new_lvar(SIZE_OF_LONGLONG)),reg); lreg_stack[i]= lreg_stack[i]-REG_LVAR_OFFSET; } }
--- a/mc-codegen.c Thu May 06 01:02:06 2004 +0900 +++ b/mc-codegen.c Thu May 06 11:38:56 2004 +0900 @@ -206,17 +206,17 @@ case INDIRECT: return g_expr0(e2); case RINDIRECT: - return code_rindirect(e2,USE_CREG,caddr(e1),0); + return code_rindirect(e2,USE_CREG,caddr(e1),1); case URINDIRECT: - return code_rindirect(e2,USE_CREG,caddr(e1),1); + return code_rindirect(e2,USE_CREG,caddr(e1),0); case CRINDIRECT: - return code_crindirect(e2,USE_CREG,caddr(e1),0); + return code_crindirect(e2,USE_CREG,caddr(e1),1); case CURINDIRECT: - return code_crindirect(e2,USE_CREG,caddr(e1),1); + return code_crindirect(e2,USE_CREG,caddr(e1),0); case SRINDIRECT: + return code_srindirect(e2,USE_CREG,caddr(e1),1); + case SURINDIRECT: return code_srindirect(e2,USE_CREG,caddr(e1),0); - case SURINDIRECT: - return code_srindirect(e2,USE_CREG,caddr(e1),1); #if FLOAT_CODE case FRINDIRECT: return code_drindirect(e2,USE_CREG,caddr(e1),0);