Mercurial > hg > CbC > old > device
changeset 255:8cd8d72286ae
PowerPC long long complex function call fix.
MIPS entry frame calc.
author | kono |
---|---|
date | Fri, 14 May 2004 20:57:52 +0900 |
parents | 5aaca4f9d96b |
children | d80e6387c539 |
files | .gdbinit Changes Idea mc-code-mips.c mc-code-powerpc.c mc-codegen.c stdio.h test/code-gen.c test/simp1.c |
diffstat | 9 files changed, 543 insertions(+), 197 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Wed May 12 21:44:45 2004 +0900 +++ b/.gdbinit Fri May 14 20:57:52 2004 +0900 @@ -1,7 +1,7 @@ tb main -run -s -ob00.s test/basic.c +# run -s -ob00.s test/basic.c # run -s -ob00.s mc-parse.c -# run -s 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 Wed May 12 21:44:45 2004 +0900 +++ b/Changes Fri May 14 20:57:52 2004 +0900 @@ -4189,3 +4189,21 @@ int endian; extern int endian; も通す必要があるのね。まぁ、フラグの扱いだけだけど.... + +Thu May 13 12:58:58 JST 2004 + + .frame の数字には input variable のsave分も入るんじゃないの? + + code_l1 の ll0 がおかしくなるのは、strtoll がintに宣言されてるから。 + +function のargumentは複雑なものから計算して行くのがルールなのね。 +ま、そうだよな。できないことはない.... + +そうなのか。最初にループを廻して複雑なものをレジスタなり変数なり +に代入して、引数リストを置き換えてしまえば良い。ついでに、 +代入するべき変数はそこで計算しておいて... (って、これって、 +parallel_assignment でやっていることと同じか) + +その部分はcodegen でやってもいいんだけど... ia32 のような場合は +むしろ不要なのか。 +
--- a/Idea Wed May 12 21:44:45 2004 +0900 +++ b/Idea Fri May 14 20:57:52 2004 +0900 @@ -1637,3 +1637,11 @@ CbC only で作れるから。 conv は、あんまり良いアイデアではないみたい。取るか。。。 + +Thu May 13 12:59:16 JST 2004 + +byte code interpreter を CbC 自身で書いたら? + +それでもやっぱり動かないから、あんまり意味はないんだけど... + +C で書いてもいいか。
--- a/mc-code-mips.c Wed May 12 21:44:45 2004 +0900 +++ b/mc-code-mips.c Fri May 14 20:57:52 2004 +0900 @@ -35,7 +35,6 @@ static int lvar_offset_label; // static int cprestore_label; static int max_func_args = 0; -static int max_func_iargs = 0; static int reg_save; @@ -884,27 +883,31 @@ text_mode(); } +#define reg_var_num(i) (REG_VAR_BASE-i) int get_register_var(NMTBL *n) { - int i; + int i,j; for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { - if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ + j = reg_var_num(i); + if (! regs[j]) { /* 使われていないなら */ /* そのレジスタを使うことを宣言し */ - regs[REG_VAR_BASE-i]=USING_REG; - if (i>max_reg_var) max_reg_var=i; + regs[j]=USING_REG; + if (i>=max_reg_var) max_reg_var=i+1; /* その場所を表す番号を返す */ - return list3(REGISTER,REG_VAR_BASE-i,(int)n); + return list3(REGISTER,j,(int)n); } } return list2(LVAR,new_lvar(SIZE_OF_INT)); } +#define freg_var_num(i) (FREG_VAR_BASE-i+FREG_OFFSET) + int get_dregister_var(NMTBL *n,int d) { - int i; + int i,j; if (d) { i = get_lregister_var(n); if (car(i)==LREGISTER) { @@ -915,12 +918,12 @@ } for(i=0;i<FREG_VAR_BASE-FREG_VAR_MIN;i++) { - if (! regs[FREG_VAR_BASE-i+FREG_OFFSET]) { /* 使われていないなら */ - regs[FREG_VAR_BASE-i+FREG_OFFSET]=USING_REG; /*そのレジスタを使うことを宣言し*/ - if (i>max_freg_var) max_freg_var=i; + j = freg_var_num(i); + if (! regs[j]) { /* 使われていないなら */ + regs[j]=USING_REG; /*そのレジスタを使うことを宣言し*/ + if (i>=max_freg_var) max_freg_var=i+1; /* その場所を表す番号を返す */ - return list3(FREGISTER, - FREG_VAR_BASE-i+FREG_OFFSET,(int)n); + return list3(FREGISTER,j,(int)n); } } return list2(LVAR,new_lvar(SIZE_OF_DOUBLE)); @@ -1700,7 +1703,7 @@ { free_register(regv_h(lreg)); } - if (creg==lreg) creg = 0; + if (creg==lreg) creg = ireg; lreg = 0; } else if (regv_h(lreg)==reg) { regs[lreg]=0; @@ -1710,7 +1713,7 @@ { free_register(regv_l(lreg)); } - if (creg==lreg) creg = 0; + if (creg==lreg) creg = ireg; lreg = 0; } } @@ -1832,15 +1835,28 @@ arg = list2(LVAR,caller_arg_offset_v(nargs)); } else if (!simple_args(e3) && cadr(e3)) { arg = t==DOUBLE?get_dregister_var(0,1):get_lregister_var(0); - arg_assign = list2( - assign_expr0(r0= - (t==DOUBLE? - get_input_dregister_var(reg_arg,0,0,1): - get_input_lregister_var(reg_arg,0,0) - ), - arg,t,t), - arg_assign); - use_input_reg(cadr(r0),1); + if (car(arg)==LREGISTER||car(arg)==DREGISTER) { + // r0=get_input_lregiste... is not preserved + // we cannot mark r0 used, it consumes unused register + // but get_input_register is preserved. + // Beware endian. + arg_assign = list2( + assign_expr0(get_input_register_var(reg_arg,0,0), + list2(REGISTER,regv_l(cadr(arg))),INT,INT), + list2( + assign_expr0(get_input_register_var(reg_arg+1,0,0), + list2(REGISTER,regv_h(cadr(arg))),INT,INT), + arg_assign)); + } else { + arg_assign = list2( + assign_expr0(get_input_register_var(reg_arg,0,0), + list2(LVAR,cadr(arg)),INT,INT), + list2( + assign_expr0(get_input_register_var(reg_arg+1,0,0), + list2(LVAR,cadr(arg)+SIZE_OF_INT),INT,INT), + arg_assign)); + } + } else { arg = t==DOUBLE?get_input_dregister_var(reg_arg,0,0,1): get_input_lregister_var(reg_arg,0,0); @@ -1948,16 +1964,16 @@ void code_jmp(char *s) { - max_reg_var = REG_VAR_BASE-REG_VAR_MIN; - max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN; + // max_reg_var = REG_VAR_BASE-REG_VAR_MIN; + // max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN; printf("\tj $L_%s\n",s); } void code_indirect_jmp(int e2) { - max_reg_var = REG_VAR_BASE-REG_VAR_MIN; - max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN; + // max_reg_var = REG_VAR_BASE-REG_VAR_MIN; + // max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN; use_int(e2); printf("\tj %s\n",register_name(e2)); } @@ -2381,32 +2397,115 @@ printf("## %s",s); } +static int +code_mask_offset() +{ + /* used regsister var */ + int i; + int offset=0; + for(i=0;i<32;i++) { + if (i==28||i==31||(reg_var_num(0)>i&&i>reg_var_num(max_reg_var))) { + offset++; + } + } + if (offset>2) offset-=1; + return -offset*SIZE_OF_INT; +} + static unsigned int code_mask() { + /* used regsister var */ int i; unsigned int mask=0; for(i=0;i<32;i++) { - if (i==28||i==31||(REG_VAR_MIN<=i&&i<=REG_VAR_MIN+max_reg_var)) { + if (i==28||i==31||(reg_var_num(0)>i&&i>reg_var_num(max_reg_var))) { mask |= (1<<i); } } return mask; } +static int +code_register_save(reg_save,freg_save,disp) +{ + int i; + for(i=0;i<32;i++) { + if (reg_var_num(0)>i&&i>reg_var_num(max_reg_var)) { + printf("\tsw %s,%d($sp)\n",register_name(i),disp); + disp += SIZE_OF_INT; + } + } + return disp; +} + +static int +code_register_restore(reg_save,freg_save,disp) +{ + int i; + for(i=0;i<32;i++) { + if (reg_var_num(0)>i&&i>reg_var_num(max_reg_var)) { + printf("\tlw %s,%d($sp)\n",register_name(i),disp); + disp += SIZE_OF_INT; + } + } + return disp; +} + +static int +code_fmask_offset() +{ + int i; + int offset=0; + for(i=0;i<32;i++) { + if (freg_var_num(0)>i&&i>freg_var_num(max_reg_var)) { + offset++; + } + } + if (offset>2) offset-=1; + return -offset*SIZE_OF_FLOAT; +} + static unsigned int code_fmask() { int i; unsigned int mask=0; + /* used fregsister var */ for(i=0;i<32;i++) { - if (FREG_VAR_MIN<=i&&i<=FREG_VAR_MIN+max_freg_var) { + if (freg_var_num(0)>i&&i>freg_var_num(max_reg_var)) { mask |= (1<<i); } } return mask; } +static int +code_fregister_save(reg_save,freg_save,disp) +{ + int i; + for(i=0;i<32;i++) { + if (freg_var_num(0)>i&&i>freg_var_num(max_reg_var)) { + printf("\tsw %s,%d($sp)\n",register_name(i),disp); + disp += SIZE_OF_FLOAT; + } + } + return disp; +} + +static int +code_fregister_restore(reg_save,freg_save,disp) +{ + int i; + for(i=0;i<32;i++) { + if (freg_var_num(0)>i&&i>freg_var_num(max_reg_var)) { + printf("\tsw %s,%d($sp)\n",register_name(i),disp); + disp += SIZE_OF_FLOAT; + } + } + return disp; +} + void code_enter(char *name) { @@ -2424,7 +2523,6 @@ lvar_offset_label = 0; max_func_args = 0; - max_func_iargs = 0; } @@ -2455,7 +2553,7 @@ printf("\t.cpload $25\n"); printf("\t.set reorder\n"); printf("\tsubu $sp,$sp,$L_%d\n",-r1_offsetv); - printf("\t.cprestore %d\n",max_func_iargs); + printf("\t.cprestore %d\n",max_func_args); printf("\tj $L_%d\n",code_top_label); @@ -2471,14 +2569,12 @@ text_mode(); else printf("\t.align 2\n"); - printf(".ent %s\n",name); code_top_label = backdef(); r1_offset_label = fwdlabel(); lvar_offset_label = fwdlabel(); max_func_args = 0; - max_func_iargs = 0; } void @@ -2490,34 +2586,6 @@ set_freg(FREG_FREGISTER,0); } -static void -code_register_save(reg_save,freg_save,disp) -{ - int i; - for(i=REG_VAR_MIN;i<=max_reg_var;i++) { - printf("\tsw %s,%d($sp)\n",register_name(i),disp); - disp += SIZE_OF_INT; - } - for(i=FREG_VAR_MIN;i<=max_freg_var;i++) { - printf("\ts.s %s,%d($sp)\n",register_name(i),disp); - disp += SIZE_OF_FLOAT; - } -} - -static void -code_register_restore(reg_save,freg_save,disp) -{ - int i; - for(i=REG_VAR_MIN;i<=max_reg_var;i++) { - printf("\tlw %s,%d($sp)\n",register_name(i),disp); - disp += SIZE_OF_INT; - } - for(i=FREG_VAR_MIN;i<=max_freg_var;i++) { - printf("\tl.s %s,%d($sp)\n",register_name(i),disp); - disp += SIZE_OF_FLOAT; - } -} - #define round16(i) ((i+0xf)&~0xf) void @@ -2526,7 +2594,6 @@ int retcont1=0,sz; int r1_offsetv; int lvar_offsetv; - int nireg,nfreg; // if (max_freg_var>=0 && max_freg_var<=3) max_freg_var=3; reg_save = @@ -2566,9 +2633,6 @@ if (retcont) { fwddef(retcont1); } - if (max_freg_var>=0) { - } else { - } #if 0 fprintf(asi,"$L_%d=%d\n",r1_offset_label,0); fprintf(asi,"$L_%d=%d\n",lvar_offset_label,0); @@ -2576,41 +2640,44 @@ fprintf(asi,"$L_%d=%d\n",mask1_label,0); fprintf(asi,"$L_%d=0x%x\n",fmask_label ,code_fmask_label()); fprintf(asi,"$L_%d=%d\n",fmask1_label,0); - fprintf(asi,"$L_%d=%d\n",cprestore_label ,max_func_iargs); + fprintf(asi,"$L_%d=%d\n",cprestore_label ,max_func_args); #endif disp &= -SIZE_OF_INT; - r1_offsetv = disp; + r1_offsetv = round16(-disp) + + max_reg_var*SIZE_OF_INT+max_freg_var*SIZE_OF_FLOAT+ + round16(max_func_args); + printf(".set L_%d,%d\n",r1_offset_label,r1_offsetv); printf(".set L_%d,%d\n",lvar_offset_label,lvar_offsetv); - printf("\tmove $sp,$fp\n"); - code_register_restore(reg_save,freg_save,disp); + code_fregister_restore(code_register_restore(disp)); printf("\tlw $31,%d($sp)\n",-disp); printf("\tlw $fp,%d($sp)\n",-disp-4); printf("\taddu $sp,$sp,%d\n",r1_offsetv); printf("\tj $31\n"); printf("\t.align 2\n"); + printf(".ent %s\n",name); printf("%s:\n",name); - printf("\t.frame $fp,%d,$31\t",0); + printf("\t.frame $fp,%d,$31\t",r1_offsetv); printf("# vars= %d, regs= %d/%d, args= %d, extra= %d\n", round16(-disp), max_reg_var+2, max_freg_var, - round16(max_func_args*SIZE_OF_INT), + round16(max_func_args), 0 ); - printf("\t.mask 0x%x,%d\n",code_mask(),0); - printf("\t.fmask 0x%x,%d\n",code_fmask(),0); + printf("\t.mask 0x%x,%d\n",code_mask(),code_mask_offset()); + printf("\t.fmask 0x%x,%d\n",code_fmask(),code_fmask_offset()); printf("\t.set noreorder\n"); printf("\t.cpload $25\n"); printf("\t.set reorder\n"); - printf("\tsubu $sp,$sp,$L_%d\n",-r1_offsetv); - printf("\t.cprestore %d\n",max_func_args*SIZE_OF_INT); - code_register_save(reg_save,freg_save,disp); + printf("\tsubu $sp,$sp,%d\n",r1_offsetv); + printf("\t.cprestore %d\n",round16(max_func_args)); + code_fregister_save(code_register_save(disp)); printf("\tj $L_%d\n",code_top_label); local_table(); @@ -2640,8 +2707,10 @@ void code_set_fixed_creg(int reg,int mode,int type) { - if (type==FLOAT||type==DOUBLE) { + if (type==FLOAT) { set_freg(reg,mode); + } else if (type==DOUBLE) { + set_dreg(reg,mode); } else if (type==LONGLONG||type==ULONGLONG) { set_lreg(reg,mode); // use_reg(reg); @@ -2826,6 +2895,8 @@ printf("\t.type\t%s,@object\n",name); } +#define lib_args(max) if (max_func_args<max) max_func_args=max + static void extern_conv(char *conv) { @@ -2833,7 +2904,7 @@ clear_ptr_cache(); extern_define(conv,0,FUNCTION,1); printf("\tjal %s\n",conv); - if (max_func_iargs<16) max_func_iargs=16; + lib_args(16); } #if FLOAT_CODE @@ -3228,7 +3299,7 @@ set_lreg(RET_LREGISTER,0); extern_define(opc,0,FUNCTION,1); printf("\tjal %s\n",opc); - if (max_func_iargs<16) max_func_iargs=16; + lib_args(16); } static void @@ -3346,11 +3417,12 @@ } } + static void double_lib_c(char *opc,double value) { extern_define(opc,0,FUNCTION,1); - if (max_func_iargs<16) max_func_iargs=16; + lib_args(16); printf("\tli.d $6,%g\n",value); printf("\tjal %s\n",opc); } @@ -4472,8 +4544,6 @@ } xreg = emit_pop(0); xrn = register_name(xreg); - dreg = get_register(); - drn_l = register_name(dreg); printf("\tlz %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn); printf("\tlz %s,0(%s)\n",drn_h,xrn); ladd(dreg,dir);
--- a/mc-code-powerpc.c Wed May 12 21:44:45 2004 +0900 +++ b/mc-code-powerpc.c Fri May 14 20:57:52 2004 +0900 @@ -636,7 +636,7 @@ int i,j,ll; int max_reg_var_save=max_reg_var; ll = get_lregister0(); - if (ll==-1) return -1; + if (ll==-1) goto not_found; if (regs[ll]==0) { for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ @@ -1554,6 +1554,19 @@ // save_stack,clear_ptr_cache is assmued if (!is_longlong_reg(reg)) { error(-1); return; } if (mode) { + if (regv_l(reg)!=3) + printf("\tmr r3,%s\n", lregister_name_high(reg)); + if (regv_l(reg)!=4) + printf("\tmr r4,%s\n", lregister_name_low(reg)); + } +} + +void +set_lreg_operand1(int reg,int mode) +{ + // save_stack,clear_ptr_cache is assmued + if (!is_longlong_reg(reg)) { error(-1); return; } + if (mode) { if (regv_l(reg)!=5) printf("\tmr r5,%s\n", lregister_name_high(reg)); if (regv_l(reg)!=6) @@ -1630,8 +1643,9 @@ static int not_simple_p(int e3) { - return (e3==FUNCTION||e3==CONV||e3==RSTRUCT||e3==STASS|| - (((e3/100)==LOP)&&(e3!=LREGISTER||e3!=LADD||e3!=LSUB))); + return e3==FUNCTION||e3==CONV||e3==RSTRUCT||e3==STASS|| + e3==LLSHIFT||e3==LULSHIFT||e3==LRSHIFT||e3==LURSHIFT|| + e3==LDIV||e3==LUDIV||e3==LMOD||e3==LUMOD; } int @@ -1764,11 +1778,26 @@ use_input_reg(cadr(r0),1); } else if (!simple_args(e3) && cadr(e3)) { arg = get_lregister_var(0); - arg_assign = list2( - assign_expr0(r0=get_input_lregister_var(reg_arg,0,0), - arg,t,t), - arg_assign); - use_input_reg(cadr(r0),1); + if (car(arg)==LREGISTER) { + // r0=get_input_lregiste... is not preserved + // we cannot mark r0 used, it consumes unused register + // but get_input_register is preserved. + arg_assign = list2( + assign_expr0(get_input_register_var(reg_arg,0,0), + list2(REGISTER,regv_h(cadr(arg))),INT,INT), + list2( + assign_expr0(get_input_register_var(reg_arg+1,0,0), + list2(REGISTER,regv_l(cadr(arg))),INT,INT), + arg_assign)); + } else { + arg_assign = list2( + assign_expr0(get_input_register_var(reg_arg,0,0), + list2(LVAR,cadr(arg)+SIZE_OF_INT),INT,INT), + list2( + assign_expr0(get_input_register_var(reg_arg+1,0,0), + list2(LVAR,cadr(arg)),INT,INT), + arg_assign)); + } } else { arg = get_input_lregister_var(reg_arg,0,0); use_input_reg(cadr(arg),1); @@ -3724,12 +3753,13 @@ #endif static void -code_asld_lib(int oreg) +code_asld_lib(int reg,int oreg) { code_save_stacks(); clear_ptr_cache(); asld_lib_used = 1; - set_lreg(RET_LREGISTER,1); + set_lreg_operand(reg,1); + set_lreg(RET_LREGISTER,0); if (regv_l(oreg)!=5) { printf("\tmr r5,%s\n", lregister_name_low(oreg)); } @@ -3737,12 +3767,13 @@ } static void -code_asrd_lib(int oreg) // ___ashrdi3$stub +code_asrd_lib(int reg,int oreg) // ___ashrdi3$stub { code_save_stacks(); clear_ptr_cache(); asrd_lib_used = 1; - set_lreg(RET_LREGISTER,1); + set_lreg_operand(reg,1); + set_lreg(RET_LREGISTER,0); if (regv_l(oreg)!=5) { printf("\tmr r5,%s\n", lregister_name_low(oreg)); } @@ -3750,12 +3781,13 @@ } static void -code_lsrd_lib(int oreg) // ___lshrdi3$stub +code_lsrd_lib(int reg,int oreg) // ___lshrdi3$stub { code_save_stacks(); clear_ptr_cache(); lsrd_lib_used = 1; - set_lreg(RET_LREGISTER,1); + set_lreg_operand(reg,1); + set_lreg(RET_LREGISTER,0); if (regv_l(oreg)!=5) { printf("\tmr r5,%s\n", lregister_name_low(oreg)); } @@ -3763,42 +3795,46 @@ } static void -code_ldiv_lib(int oreg) // ___divdi3$stub +code_ldiv_lib(int reg,int oreg) // ___divdi3$stub { code_save_stacks(); clear_ptr_cache(); - set_lreg(RET_LREGISTER,1); - set_lreg_operand(oreg,1); + set_lreg_operand(reg,1); + set_lreg(RET_LREGISTER,0); + set_lreg_operand1(oreg,1); extern_conv("__divdi3"); } static void -code_ludiv_lib(int oreg) // ___udivdi3$stub +code_ludiv_lib(int reg,int oreg) // ___udivdi3$stub { code_save_stacks(); clear_ptr_cache(); - set_lreg(RET_LREGISTER,1); - set_lreg_operand(oreg,1); + set_lreg_operand(reg,1); + set_lreg(RET_LREGISTER,0); + set_lreg_operand1(oreg,1); extern_conv("__udivdi3"); } static void -code_lmod_lib(int oreg) // ___moddi3$stub +code_lmod_lib(int reg,int oreg) // ___moddi3$stub { code_save_stacks(); clear_ptr_cache(); - set_lreg(RET_LREGISTER,1); - set_lreg_operand(oreg,1); + set_lreg_operand(reg,1); + set_lreg(RET_LREGISTER,0); + set_lreg_operand1(oreg,1); extern_conv("__moddi3"); } static void -code_lumod_lib(int oreg) // ___umoddi3$stub +code_lumod_lib(int reg,int oreg) // ___umoddi3$stub { code_save_stacks(); clear_ptr_cache(); - set_lreg(RET_LREGISTER,1); - set_lreg_operand(oreg,1); + set_lreg(RET_LREGISTER,0); + set_lreg_operand(reg,1); + set_lreg_operand1(oreg,1); extern_conv("__umoddi3"); } @@ -3826,17 +3862,17 @@ switch(op) { case LLSHIFT: case LULSHIFT: - code_asld_lib(oreg); // ___ashldi3$stub + code_asld_lib(reg,oreg); // ___ashldi3$stub check_lreg(reg); if(ox!=-1) free_register(ox); return; case LRSHIFT: - code_asrd_lib(oreg); // ___ashrdi3$stub + code_asrd_lib(reg,oreg); // ___ashrdi3$stub check_lreg(reg); if(ox!=-1) free_register(ox); return; case LURSHIFT: - code_lsrd_lib(oreg); // ___lshrdi3$stub + code_lsrd_lib(reg,oreg); // ___lshrdi3$stub check_lreg(reg); if(ox!=-1) free_register(ox); return; @@ -3895,19 +3931,19 @@ printf("\tmr %s,%s\n", crn_l,drn_l); break; case LDIV: - code_ldiv_lib(oreg); // ___divdi3$stub + code_ldiv_lib(reg,oreg); // ___divdi3$stub check_lreg(reg); break; case LUDIV: - code_ludiv_lib(oreg); // ___udivdi3$stub + code_ludiv_lib(reg,oreg); // ___udivdi3$stub check_lreg(reg); break; case LMOD: - code_lmod_lib(oreg); // ___moddi3$stub + code_lmod_lib(reg,oreg); // ___moddi3$stub check_lreg(reg); break; case LUMOD: - code_lumod_lib(oreg); // ___umoddi3$stub + code_lumod_lib(reg,oreg); // ___umoddi3$stub check_lreg(reg); break; default:
--- a/mc-codegen.c Wed May 12 21:44:45 2004 +0900 +++ b/mc-codegen.c Fri May 14 20:57:52 2004 +0900 @@ -1411,6 +1411,7 @@ assop(int e1) { int e2,e3,byte,op,sign,size; + int n,t; /* e2 op= e3 */ if (car(e1) == CUASSOP) { @@ -1429,6 +1430,22 @@ e3 = caddr(e1); op = cadddr(e1); + if (car(e3)==CONST) { + /* e2 = e2 op e3; */ + t = sign?INT:UNSIGNED; + if (car(e2)==REGISTER||car(e2)==LVAR||car(e2)==GVAR) { + g_expr(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); + return; + } + /* new = &e2 */ + /* *new = *new op e3 */ + n = list2(LVAR,new_lvar(size_of_int)); + g_expr_u(assign_expr0(n,list2(ADDRESS,e2),INT,INT)); + g_expr(assign_expr0(list2(INDIRECT,n),list3(op,n,e3),t,t)); + free_lvar(cadr(n)); + return; + } + g_expr(e3); if (car(e2)==REGISTER) { code_register_assop(cadr(e2),USE_CREG,op,byte); @@ -1509,6 +1526,7 @@ g_expr(e3); if (car(e2)==LREGISTER) { + emit_lpush(); code_register_lassop(cadr(e2),op); if (use) code_lregister(cadr(e2),USE_CREG);
--- a/stdio.h Wed May 12 21:44:45 2004 +0900 +++ b/stdio.h Fri May 14 20:57:52 2004 +0900 @@ -1,8 +1,9 @@ -#ifndef __micro_c__ +#ifndef __micro_c__aaa #include "/usr/include/stdio.h" long long strtoll(const char *, char **, int); #else +long long strtoll(const char *, char **, int); #ifdef __APPLE__
--- a/test/code-gen.c Wed May 12 21:44:45 2004 +0900 +++ b/test/code-gen.c Fri May 14 20:57:52 2004 +0900 @@ -526,45 +526,46 @@ { register int i1; register unsigned int ui1; + int a = 3; i1 = -555; ui1 = 632423423; - i1 += 3; + i1 += a; printf("code_assop 1 %d\n",i1); - i1 -= 3; + i1 -= a; printf("code_assop 2 %d\n",i1); - i1 /= 3; + i1 /= a; printf("code_assop 3 %d\n",i1); - i1 *= 3; + i1 *= a; printf("code_assop 4 %d\n",i1); - i1 |= 234; + i1 |= a; printf("code_assop 5 %d\n",i1); - i1 &= 23244234; + i1 &= a; printf("code_assop 6 %d\n",i1); - i1 ^= 55244234; + i1 ^= a; printf("code_assop 7 %d\n",i1); - i1 <<= 3; + i1 <<= a; printf("code_assop 8 %d\n",i1); - i1 >>= 3; + i1 >>= a; printf("code_assop 9 %d\n",i1); - ui1 += 3; + ui1 += a; printf("code_assop 1 %u\n",ui1); - ui1 -= 3; + ui1 -= a; printf("code_assop 2 %u\n",ui1); - ui1 /= 3; + ui1 /= a; printf("code_assop 3 %u\n",ui1); - ui1 *= 3; + ui1 *= a; printf("code_assop 4 %u\n",ui1); - ui1 |= 234; + ui1 |= a; printf("code_assop 5 %u\n",ui1); - ui1 &= 23234234; + ui1 &= a; printf("code_assop 6 %u\n",ui1); - ui1 ^= 55234234; + ui1 ^= a; printf("code_assop 7 %u\n",ui1); - ui1 <<= 3; + ui1 <<= a; printf("code_assop 8 %u\n",ui1); - ui1 >>= 3; + ui1 >>= a; printf("code_assop 9 %u\n",ui1); } @@ -574,46 +575,144 @@ { int i1,i2; unsigned int ui1,ui2; + int a = 3; + i1 = -555; i2= 555; + ui1 = 632423423; ui2= 32394234; + + i1 += a; + printf("code_assop 1 %d\n",i1); + i1 -= a; + printf("code_assop 2 %d\n",i1); + i1 /= a; + printf("code_assop 3 %d\n",i1); + i1 *= a; + printf("code_assop 4 %d\n",i1); + i1 |= a; + printf("code_assop 5 %d\n",i1); + i1 &= a; + printf("code_assop 6 %d\n",i1); + i1 ^= a; + printf("code_assop 7 %d\n",i1); + i1 <<= a; + printf("code_assop 8 %d\n",i1); + i1 >>= a; + printf("code_assop 9 %d\n",i1); + + ui1 += a; + printf("code_assop 1 %u\n",ui1); + ui1 -= a; + printf("code_assop 2 %u\n",ui1); + ui1 /= a; + printf("code_assop 3 %u\n",ui1); + ui1 *= a; + printf("code_assop 4 %u\n",ui1); + ui1 |= a; + printf("code_assop 5 %u\n",ui1); + ui1 &= a; + printf("code_assop 6 %u\n",ui1); + ui1 ^= a; + printf("code_assop 7 %u\n",ui1); + ui1 <<= a; + printf("code_assop 8 %u\n",ui1); + ui1 >>= a; + printf("code_assop 9 %u\n",ui1); +} + + +// code_register_assop(int e2,int op,int byte) +void +code_register_assop_const() +{ + register int i1; + register unsigned int ui1; + i1 = -555; + ui1 = 632423423; + + i1 += 3; + printf("code_assop c 1 %d\n",i1); + i1 -= 3; + printf("code_assop c 2 %d\n",i1); + i1 /= 3; + printf("code_assop c 3 %d\n",i1); + i1 *= 3; + printf("code_assop c 4 %d\n",i1); + i1 |= 234; + printf("code_assop c 5 %d\n",i1); + i1 &= 23244234; + printf("code_assop c 6 %d\n",i1); + i1 ^= 55244234; + printf("code_assop c 7 %d\n",i1); + i1 <<= 3; + printf("code_assop c 8 %d\n",i1); + i1 >>= 3; + printf("code_assop c 9 %d\n",i1); + + ui1 += 3; + printf("code_assop c 1 %u\n",ui1); + ui1 -= 3; + printf("code_assop c 2 %u\n",ui1); + ui1 /= 3; + printf("code_assop c 3 %u\n",ui1); + ui1 *= 3; + printf("code_assop c 4 %u\n",ui1); + ui1 |= 234; + printf("code_assop c 5 %u\n",ui1); + ui1 &= 23234234; + printf("code_assop c 6 %u\n",ui1); + ui1 ^= 55234234; + printf("code_assop c 7 %u\n",ui1); + ui1 <<= 3; + printf("code_assop c 8 %u\n",ui1); + ui1 >>= 3; + printf("code_assop c 9 %u\n",ui1); +} + +// code_assop(int op,int byte,int sign) +void +code_assop_const() +{ + int i1,i2; + unsigned int ui1,ui2; i1 = -555; i2= 555; ui1 = 632423423; ui2= 32394234; i1 += 3; - printf("code_assop 1 %d\n",i1); + printf("code_assop c 1 %d\n",i1); i1 -= 3; - printf("code_assop 2 %d\n",i1); + printf("code_assop c 2 %d\n",i1); i1 /= 3; - printf("code_assop 3 %d\n",i1); + printf("code_assop c 3 %d\n",i1); i1 *= 3; - printf("code_assop 4 %d\n",i1); + printf("code_assop c 4 %d\n",i1); i1 |= 234; - printf("code_assop 5 %d\n",i1); + printf("code_assop c 5 %d\n",i1); i1 &= 23234234; - printf("code_assop 6 %d\n",i1); + printf("code_assop c 6 %d\n",i1); i1 ^= 55444234; - printf("code_assop 7 %d\n",i1); + printf("code_assop c 7 %d\n",i1); i1 <<= 3; - printf("code_assop 8 %d\n",i1); + printf("code_assop c 8 %d\n",i1); i1 >>= 3; - printf("code_assop 9 %d\n",i1); + printf("code_assop c 9 %d\n",i1); ui1 += 3; - printf("code_assop 1 %u\n",ui1); + printf("code_assop c 1 %u\n",ui1); ui1 -= 3; - printf("code_assop 2 %u\n",ui1); + printf("code_assop c 2 %u\n",ui1); ui1 /= 3; - printf("code_assop 3 %u\n",ui1); + printf("code_assop c 3 %u\n",ui1); ui1 *= 3; - printf("code_assop 4 %u\n",ui1); + printf("code_assop c 4 %u\n",ui1); ui1 |= 234; - printf("code_assop 5 %u\n",ui1); + printf("code_assop c 5 %u\n",ui1); ui1 &= 23234234; - printf("code_assop 6 %u\n",ui1); + printf("code_assop c 6 %u\n",ui1); ui1 ^= 54234234; - printf("code_assop 7 %u\n",ui1); + printf("code_assop c 7 %u\n",ui1); ui1 <<= 3; - printf("code_assop 8 %u\n",ui1); + printf("code_assop c 8 %u\n",ui1); ui1 >>= 3; - printf("code_assop 9 %u\n",ui1); + printf("code_assop c 9 %u\n",ui1); } @@ -1248,23 +1347,17 @@ printf("ltosop 6 %lld\n",i); i = i1 ^ i2; printf("ltosop 7 %lld\n",i); - printf("ltosop uuu -2 %llu=%llu/%llu\n",u,u1,u2); i = i1 << i2; printf("ltosop 8 %lld\n",i); - printf("ltosop uuu -1 %llu=%llu/%llu\n",u,u1,u2); i = i1 >> i2; - printf("ltosop uuu 0 %llu=%llu/%llu\n",u,u1,u2); printf("ltosop 9 %lld\n",i); i = i1 % i2; - printf("ltosop uuu 0.0 %llu=%llu/%llu\n",u,u1,u2); printf("ltosop 10 %lld\n",i); - printf("ltosop uuu 1 %llu=%llu/%llu\n",u,u1,u2); u = u1 + u2; printf("ltosop u 1 %llu\n",u); u = u1 - u2; printf("ltosop u 2 %llu\n",u); - printf("ltosop uuu 2 %llu=%llu/%llu\n",u,u1,u2); u = u1 / u2; printf("ltosop u 3 %llu\n",u); u = u1 * u2; @@ -1303,7 +1396,6 @@ i = i1 % ii2; printf("litosop 10 %lld\n",i); - printf("litosop uuu %llu=%llu+%u\n",u,u1,uu2); u = u1 + uu2; printf("litosop u 1 %llu\n",u); u = u1 - uu2; @@ -1586,45 +1678,46 @@ { register long long i1; register unsigned long long ui1; + long long a = 3; i1 = -555; ui1 = 632423423; - i1 += 3; + i1 += a; printf("code_register_lassop 1 %lld\n",i1); - i1 -= 3; + i1 -= a; printf("code_register_lassop 2 %lld\n",i1); - i1 /= 3; + i1 /= a; printf("code_register_lassop 3 %lld\n",i1); - i1 *= 3; + i1 *= a; printf("code_register_lassop 4 %lld\n",i1); - i1 |= 234; + i1 |= a; printf("code_register_lassop 5 %lld\n",i1); - i1 &= 2324234234234234LL; + i1 &= a; printf("code_register_lassop 6 %lld\n",i1); - i1 ^= 5523234234234234LL; + i1 ^= a; printf("code_register_lassop 7 %lld\n",i1); - i1 <<= 3; + i1 <<= a; printf("code_register_lassop 8 %lld\n",i1); - i1 >>= 3; + i1 >>= a; printf("code_register_lassop 9 %lld\n",i1); - ui1 += 3; + ui1 += a; printf("code_register_lassop 1 %llu\n",ui1); - ui1 -= 3; + ui1 -= a; printf("code_register_lassop 2 %llu\n",ui1); - ui1 /= 3; + ui1 /= a; printf("code_register_lassop 3 %llu\n",ui1); - ui1 *= 3; + ui1 *= a; printf("code_register_lassop 4 %llu\n",ui1); - ui1 |= 234; + ui1 |= a; printf("code_register_lassop 5 %llu\n",ui1); - ui1 &= 2324234234234234LL; + ui1 &= a; printf("code_register_lassop 6 %llu\n",ui1); - ui1 ^= 5523234234234234LL; + ui1 ^= a; printf("code_register_lassop 7 %llu\n",ui1); - ui1 <<= 3; + ui1 <<= a; printf("code_register_lassop 8 %llu\n",ui1); - ui1 >>= 3; + ui1 >>= a; printf("code_register_lassop 9 %llu\n",ui1); } @@ -1634,46 +1727,143 @@ { long long i1,i2; unsigned long long ui1,ui2; + long long a = 3; + i1 = -555; i2= 555; + ui1 = 632423423; ui2= 32394234; + + i1 += a; + printf("code_lassop 1 %lld\n",i1); + i1 -= a; + printf("code_lassop 2 %lld\n",i1); + i1 /= a; + printf("code_lassop 3 %lld\n",i1); + i1 *= a; + printf("code_lassop 4 %lld\n",i1); + i1 |= a; + printf("code_lassop 5 %lld\n",i1); + i1 &= a; + printf("code_lassop 6 %lld\n",i1); + i1 ^= a; + printf("code_lassop 7 %lld\n",i1); + i1 <<= a; + printf("code_lassop 8 %lld\n",i1); + i1 >>= a; + printf("code_lassop 9 %lld\n",i1); + + ui1 += a; + printf("code_lassop 1 %llu\n",ui1); + ui1 -= a; + printf("code_lassop 2 %llu\n",ui1); + ui1 /= a; + printf("code_lassop 3 %llu\n",ui1); + ui1 *= a; + printf("code_lassop 4 %llu\n",ui1); + ui1 |= a; + printf("code_lassop 5 %llu\n",ui1); + ui1 &= a; + printf("code_lassop 6 %llu\n",ui1); + ui1 ^= a; + printf("code_lassop 7 %llu\n",ui1); + ui1 <<= a; + printf("code_lassop 8 %llu\n",ui1); + ui1 >>= a; + printf("code_lassop 9 %llu\n",ui1); +} + +// code_register_assop(int e2,int op,int byte) +void +code_register_lassop_const() +{ + register long long i1; + register unsigned long long ui1; + i1 = -555; + ui1 = 632423423; + + i1 += 3; + printf("code_register_lassop c 1 %lld\n",i1); + i1 -= 3; + printf("code_register_lassop c 2 %lld\n",i1); + i1 /= 3; + printf("code_register_lassop c 3 %lld\n",i1); + i1 *= 3; + printf("code_register_lassop c 4 %lld\n",i1); + i1 |= 234; + printf("code_register_lassop c 5 %lld\n",i1); + i1 &= 2324234234234234LL; + printf("code_register_lassop c 6 %lld\n",i1); + i1 ^= 5523234234234234LL; + printf("code_register_lassop c 7 %lld\n",i1); + i1 <<= 3; + printf("code_register_lassop c 8 %lld\n",i1); + i1 >>= 3; + printf("code_register_lassop c 9 %lld\n",i1); + + ui1 += 3; + printf("code_register_lassop c 1 %llu\n",ui1); + ui1 -= 3; + printf("code_register_lassop c 2 %llu\n",ui1); + ui1 /= 3; + printf("code_register_lassop c 3 %llu\n",ui1); + ui1 *= 3; + printf("code_register_lassop c 4 %llu\n",ui1); + ui1 |= 234; + printf("code_register_lassop c 5 %llu\n",ui1); + ui1 &= 2324234234234234LL; + printf("code_register_lassop c 6 %llu\n",ui1); + ui1 ^= 5523234234234234LL; + printf("code_register_lassop c 7 %llu\n",ui1); + ui1 <<= 3; + printf("code_register_lassop c 8 %llu\n",ui1); + ui1 >>= 3; + printf("code_register_lassop c 9 %llu\n",ui1); +} + +// code_lassop(int op,int byte,int sign) +void +code_lassop_const() +{ + long long i1,i2; + unsigned long long ui1,ui2; i1 = -555; i2= 555; ui1 = 632423423; ui2= 32394234; i1 += 3; - printf("code_lassop 1 %lld\n",i1); + printf("code_lassop c 1 %lld\n",i1); i1 -= 3; - printf("code_lassop 2 %lld\n",i1); + printf("code_lassop c 2 %lld\n",i1); i1 /= 3; - printf("code_lassop 3 %lld\n",i1); + printf("code_lassop c 3 %lld\n",i1); i1 *= 3; - printf("code_lassop 4 %lld\n",i1); + printf("code_lassop c 4 %lld\n",i1); i1 |= 234; - printf("code_lassop 5 %lld\n",i1); + printf("code_lassop c 5 %lld\n",i1); i1 &= 2324234234234234LL; - printf("code_lassop 6 %lld\n",i1); + printf("code_lassop c 6 %lld\n",i1); i1 ^= 5523234234234234LL; - printf("code_lassop 7 %lld\n",i1); + printf("code_lassop c 7 %lld\n",i1); i1 <<= 3; - printf("code_lassop 8 %lld\n",i1); + printf("code_lassop c 8 %lld\n",i1); i1 >>= 3; - printf("code_lassop 9 %lld\n",i1); + printf("code_lassop c 9 %lld\n",i1); ui1 += 3; - printf("code_lassop 1 %llu\n",ui1); + printf("code_lassop c 1 %llu\n",ui1); ui1 -= 3; - printf("code_lassop 2 %llu\n",ui1); + printf("code_lassop c 2 %llu\n",ui1); ui1 /= 3; - printf("code_lassop 3 %llu\n",ui1); + printf("code_lassop c 3 %llu\n",ui1); ui1 *= 3; - printf("code_lassop 4 %llu\n",ui1); + printf("code_lassop c 4 %llu\n",ui1); ui1 |= 234; - printf("code_lassop 5 %llu\n",ui1); + printf("code_lassop c 5 %llu\n",ui1); ui1 &= 2324234234234234LL; - printf("code_lassop 6 %llu\n",ui1); + printf("code_lassop c 6 %llu\n",ui1); ui1 ^= 5523234234234234LL; - printf("code_lassop 7 %llu\n",ui1); + printf("code_lassop c 7 %llu\n",ui1); ui1 <<= 3; - printf("code_lassop 8 %llu\n",ui1); + printf("code_lassop c 8 %llu\n",ui1); ui1 >>= 3; - printf("code_lassop 9 %llu\n",ui1); + printf("code_lassop c 9 %llu\n",ui1); } // code_lgt(int cond)
--- a/test/simp1.c Wed May 12 21:44:45 2004 +0900 +++ b/test/simp1.c Fri May 14 20:57:52 2004 +0900 @@ -7,12 +7,14 @@ short s(short a,short b,short c,short d,short f) { + printf("s(%d,%d,%d,%d,%d)\n",a,b,c,d,f); return a+b+c+d+f; } char ch(char a,char b,char c,char d,char f) { + printf("ch(%d,%d,%d,%d,%d)\n",a,b,c,d,f); return a+b+c+d+f; } @@ -20,18 +22,21 @@ float f(float a,float b,float c,float d,float f) { + printf("f(%g,%g,%g,%g,%g)\n",a,b,c,d,f); return a+b+c+d+f; } double d(double a,double b,double c,double d,double f) { + printf("d(%g,%g,%g,%g,%g)\n",a,b,c,d,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) { + printf("l(%lld,%lld,%lld,%lld,%lld)\n",a,b,c,d,f); return a+b+c+d+f; }