Mercurial > hg > CbC > old > device
changeset 252:1452eb0eab20
*** empty log message ***
author | kono |
---|---|
date | Wed, 12 May 2004 19:13:19 +0900 |
parents | fb6efe8ff816 |
children | 7b2762739df6 |
files | .gdbinit Changes mc-code-mips.c mc-code-powerpc.c mc-parse.c stdio.h test/simp1.c |
diffstat | 7 files changed, 146 insertions(+), 107 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Wed May 12 11:26:01 2004 +0900 +++ b/.gdbinit Wed May 12 19:13:19 2004 +0900 @@ -1,7 +1,7 @@ tb main # run -s -ob00.s test/int.c -# run -s -ob00.s mc-parse.c -run -s test/code-gen-all.c +run -s -ob00.s mc-parse.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 11:26:01 2004 +0900 +++ b/Changes Wed May 12 19:13:19 2004 +0900 @@ -4175,3 +4175,5 @@ なんかのフラグを壊さないようにするための処理みたい。 だとすれば、code segement 側でstackを頻繁に移動するのはまずい? + +float/double のフローは mc-parse では、少し、齟齬があるみたい。
--- a/mc-code-mips.c Wed May 12 11:26:01 2004 +0900 +++ b/mc-code-mips.c Wed May 12 19:13:19 2004 +0900 @@ -27,11 +27,11 @@ static int output_mode = TEXT_EMIT_MODE; static int data_alignment = 0; -static int code_disp_label; +// static int code_disp_label; // static int disp_label; int code_top_label; -// static int r1_offset_label; +static int r1_offset_label; static int lvar_offset_label; // static int cprestore_label; static int max_func_args = 0; @@ -290,18 +290,20 @@ <------------lvar_offset-------> r+ +------------+---+---------------+----------+--------------+----+ - callee arg xx register save local caller arg xx - reg_save disp max_func_args*SIZE_OF_INT + ($fp) reg_save disp max_func_args*SIZE_OF_INT lvar>0 lvar<0 lvar>0x1000 0000 - + prev $sp=$fp $sp=$fp + code segment stack frame * gotoを呼び出した関数のr1 ! r1(goto前のr1) # * r30 <---r1_offset---------> r1 r+ +----------+--+----------+----------------+-----------+----------+----+ cousin arg xx reg save !callee arg !code local caller arg xx - r20-r29 lvar>0 lvar<0 lvar>0x1000 000 + ($fp)r20-r29 lvar>0 lvar<0 lvar>0x1000 000 f20-f31 <-my_func_args--><--disp-----><-max_func_arg-> *SIZE_OF_INT *SIZE_OF_INT + prev $sp=$fp $fp $sp */ int arg_offset = 24; int arg_offset1 = 24; int disp_offset = -12; @@ -356,11 +358,11 @@ } else printf("%d($fp)\n",CODE_LVAR); } else if (l<0) { /* local variable */ - printf("%d($fp)\n",FUNC_LVAR); + printf("%d+$L_%d($fp)\n",FUNC_LVAR,lvar_offset_label); } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ printf("%d($fp)\n",CALLER_ARG); } else { /* callee's arguments */ - printf("%d($fp)\n",CALLEE_ARG); + printf("%d+$L_%d($fp)\n",CALLEE_ARG,r1_offset_label); } } @@ -373,11 +375,11 @@ } else printf("\taddu\t%s,$fp,%d\n",register_name(creg),CODE_LVAR); } else if (l<0) { /* local variable */ - printf("\taddu\t%s,$fp,%d\n",register_name(creg),FUNC_LVAR); + printf("\taddu\t%s,$fp,%d+$L_%d\n",register_name(creg),FUNC_LVAR,lvar_offset_label); } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ printf("\taddu\t%s,$fp,%d\n",register_name(creg),CALLER_ARG); } else { /* callee's arguments */ - printf("\taddu\t%s,$fp,%d\n",register_name(creg),CALLEE_ARG); + printf("\taddu\t%s,$fp,%d+$L_%d\n",register_name(creg),CALLEE_ARG,r1_offset_label); } } @@ -2139,6 +2141,7 @@ tosop(int op,int creg,int oreg) { int dx = -1; + int ox = -1; char *orn,*crn; // creg = creg op oreg @@ -2146,21 +2149,24 @@ if(oreg==-1) { error(-1); } else if (oreg<= -REG_LVAR_OFFSET) { - dx = get_register(); if (dx<0) error(-1); - code_rlvar(oreg+REG_LVAR_OFFSET,dx); - oreg = dx; + ox = get_register(); if (ox<0) error(-1); + code_rlvar(oreg+REG_LVAR_OFFSET,ox); + oreg = ox; } switch(op) { case LSHIFT: case ULSHIFT: shift("sll",creg,oreg); + if(ox!=-1) free_register(ox); return; case RSHIFT: shift("sra",creg,oreg); + if(ox!=-1) free_register(ox); return; case URSHIFT: shift("srl",creg,oreg); + if(ox!=-1) free_register(ox); return; } orn = register_name(oreg); @@ -2214,13 +2220,14 @@ error(-1); } if(dx!=-1) free_register(dx); + if(ox!=-1) free_register(ox); } int code_const_op_p(int op,int v) { if (car(v)!=CONST) return 0; - if (op==BAND||op==DIV||op==UDIV||op==MOD||op==UMOD||op==EOR||op==MUL||op==UMUL) return 0; + if (!(op==LSHIFT|| op==ULSHIFT|| op==RSHIFT|| op==URSHIFT|| op==ADD|| op==SUB|| op==CMP|| op==BOR)) return 0; v = cadr(v); return (-32766<v&&v<32767); } @@ -2297,6 +2304,7 @@ rn = register_name(reg = get_register()); printf("\tli %s,%d\n",rn,e); printf("\tsltu %s,%s,%s\n",rn,register_name(csreg),rn); + free_register(reg); } void @@ -2374,73 +2382,6 @@ printf("## %s",s); } -void -code_enter(char *name) -{ - if (output_mode!=TEXT_EMIT_MODE) - text_mode(); - else - printf("\t.align 3\n"); - if (stmode!=STATIC) - printf(".globl _%s\n",name); -#ifdef DOT_SIZE - printf("\t.type\t%s,@function\n",name); -#endif - // printf("\t.set noreorder\n"); - // printf("\t.cpload $25\n"); - // printf("\t.set reorder\n"); - printf("\tsubu $sp,$sp,$L_%d\n",code_disp_label); - // printf("\t.cprestore $L_%d\n",cprestore_label); - - max_func_args = 0; - max_func_iargs = 0; -} - - -void -code_enter1(int args) -{ - // set_lreg(LREG_LREGISTER,0); - set_ireg(CREG_REGISTER,0); - set_freg(FREG_FREGISTER,0); -} - -void -code_leave(char *name) -{ - int r1_offsetv; - 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(); - printf("\t.end %s\n",name); - // free_all_register(); -} - -void -enter(char *name) -{ - if (output_mode!=TEXT_EMIT_MODE) - text_mode(); - else - printf("\t.align 2\n"); - printf(".ent %s\n",name); - code_top_label = backdef(); - - max_func_args = 0; - max_func_iargs = 0; -} - -void -enter1() -{ - text_mode(); - // set_lreg(LREG_LREGISTER,0); - set_ireg(CREG_REGISTER,0); - set_freg(FREG_FREGISTER,0); -} - static unsigned int code_mask() { @@ -2467,6 +2408,89 @@ return mask; } +void +code_enter(char *name) +{ + if (output_mode!=TEXT_EMIT_MODE) + text_mode(); + else + printf("\t.align 3\n"); + if (stmode!=STATIC) + printf(".globl _%s\n",name); +#ifdef DOT_SIZE + printf("\t.type\t%s,@function\n",name); +#endif + code_top_label = backdef(); + r1_offset_label = fwdlabel(); + lvar_offset_label = 0; + + max_func_args = 0; + max_func_iargs = 0; +} + + +void +code_enter1(int args) +{ + // set_lreg(LREG_LREGISTER,0); + set_ireg(CREG_REGISTER,0); + set_freg(FREG_FREGISTER,0); +} + +void +code_leave(char *name) +{ + int r1_offsetv; + disp&= -SIZE_OF_INT; + r1_offsetv = -disp+max_func_args*SIZE_OF_INT+code_disp_offset; + + printf(".set L_%d,%d\n",r1_offset_label,r1_offsetv); + + printf("\t.align 2\n"); + printf("%s:\n",name); + printf("\t.frame $fp,%d,$31\n",0); + printf("\t.mask 0x%x,%d\n",code_mask(),0); + printf("\t.fmask 0x%x,%d\n",code_fmask(),0); + + 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_iargs); + printf("\tj $L_%d\n",code_top_label); + + + local_table(); + printf("\t.end %s\n",name); + // free_all_register(); +} + +void +enter(char *name) +{ + if (output_mode!=TEXT_EMIT_MODE) + 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 +enter1() +{ + text_mode(); + // set_lreg(LREG_LREGISTER,0); + set_ireg(CREG_REGISTER,0); + set_freg(FREG_FREGISTER,0); +} + static void code_register_save(reg_save,freg_save,disp) { @@ -2501,6 +2525,7 @@ { int retcont1=0,sz; int r1_offsetv; + int lvar_offsetv; if (max_freg_var>=0 && max_freg_var<=3) max_freg_var=3; reg_save = @@ -2555,6 +2580,9 @@ disp &= -size_of_int; r1_offsetv = disp; + 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); @@ -4006,6 +4034,7 @@ ltosop(int op,int reg,int oreg) { int dx = -1; + int ox = -1; char *orn_h,*crn_h,*drn_h; char *orn_l,*crn_l,*drn_l; char *drn; @@ -4015,10 +4044,10 @@ if(oreg==-1) { error(-1); } else if (oreg<= -REG_LVAR_OFFSET) { - dx = get_lregister(); if (dx<0) error(-1); - use_reg(dx); - code_rlvar(oreg+REG_LVAR_OFFSET,dx); - oreg = dx; + ox = get_lregister(); if (ox<0) error(-1); + use_reg(ox); + code_rlvar(oreg+REG_LVAR_OFFSET,ox); + oreg = ox; } switch(op) { @@ -4026,14 +4055,17 @@ case LULSHIFT: code_asld_lib(oreg); // ___ashldi3$stub check_lreg(reg); + if(ox!=-1) free_register(ox); return; case LRSHIFT: code_asrd_lib(oreg); // ___ashrdi3$stub check_lreg(reg); + if(ox!=-1) free_register(ox); return; case LURSHIFT: code_lsrd_lib(oreg); // ___lshrdi3$stub check_lreg(reg); + if(ox!=-1) free_register(ox); return; } orn_h = lregister_name_high(oreg); @@ -4116,6 +4148,7 @@ default: error(-1); } + if(ox!=-1) free_register(ox); if(dx!=-1) free_register(dx); }
--- a/mc-code-powerpc.c Wed May 12 11:26:01 2004 +0900 +++ b/mc-code-powerpc.c Wed May 12 19:13:19 2004 +0900 @@ -2087,6 +2087,7 @@ tosop(int op,int creg,int oreg) { int dx = -1; + int ox = -1; char *orn,*crn,*drn; // creg = creg op oreg @@ -2094,21 +2095,24 @@ if(oreg==-1) { error(-1); } else if (oreg<= -REG_LVAR_OFFSET) { - dx = get_register(); if (dx<0) error(-1); - code_rlvar(oreg+REG_LVAR_OFFSET,dx); - oreg = dx; + ox = get_register(); if (ox<0) error(-1); + code_rlvar(oreg+REG_LVAR_OFFSET,ox); + oreg = ox; } switch(op) { case LSHIFT: case ULSHIFT: shift("slw",creg,oreg); + if(ox!=-1) free_register(ox); return; case RSHIFT: shift("sraw",creg,oreg); + if(ox!=-1) free_register(ox); return; case URSHIFT: shift("srw",creg,oreg); + if(ox!=-1) free_register(ox); return; } orn = register_name(oreg); @@ -2162,6 +2166,7 @@ error(-1); } if(dx!=-1) free_register(dx); + if(ox!=-1) free_register(ox); } int @@ -3803,6 +3808,7 @@ ltosop(int op,int reg,int oreg) { int dx = -1; + int ox = -1; char *orn_h,*crn_h,*drn_h; char *orn_l,*crn_l,*drn_l; // creg = creg op oreg @@ -3811,10 +3817,10 @@ if(oreg==-1) { error(-1); } else if (oreg<= -REG_LVAR_OFFSET) { - dx = get_lregister(); if (dx<0) error(-1); - use_reg(dx); - code_rlvar(oreg+REG_LVAR_OFFSET,dx); - oreg = dx; + ox = get_lregister(); if (ox<0) error(-1); + use_reg(ox); + code_rlvar(oreg+REG_LVAR_OFFSET,ox); + oreg = ox; } switch(op) { @@ -3822,14 +3828,17 @@ case LULSHIFT: code_asld_lib(oreg); // ___ashldi3$stub check_lreg(reg); + if(ox!=-1) free_register(ox); return; case LRSHIFT: code_asrd_lib(oreg); // ___ashrdi3$stub check_lreg(reg); + if(ox!=-1) free_register(ox); return; case LURSHIFT: code_lsrd_lib(oreg); // ___lshrdi3$stub check_lreg(reg); + if(ox!=-1) free_register(ox); return; } orn_h = lregister_name_high(oreg); @@ -3904,6 +3913,7 @@ default: error(-1); } + if(ox!=-1) free_register(dx); if(dx!=-1) free_register(dx); }
--- a/mc-parse.c Wed May 12 11:26:01 2004 +0900 +++ b/mc-parse.c Wed May 12 19:13:19 2004 +0900 @@ -2626,23 +2626,17 @@ conv->prefix_(sym); getsym(0); e=rvalue(expr13()); + type=INT; #if FLOAT_CODE - if(type==FLOAT||type==DOUBLE) { - type=INT; - return(car(e)==DCONST?list2(CONST,!dcadr(e)): - list3((type==DOUBLE?DOP:FOP)+NEQ,dlist2(DCONST,0.0),e)); - } + if (car(e)==DCONST) return list2(CONST,!dcadr(e)); #endif #if LONGLONG_CODE - if(type==LONGLONG||type==ULONGLONG) { - type=INT; - return(car(e)==LCONST?list2(LCONST,!lcadr(e)): - list3(LOP+NEQ,llist2(LCONST,0LL),e)); - } + if (car(e)==LCONST) return list2(CONST,!lcadr(e)); #endif + if (car(e)==CONST) return list2(CONST,!cadr(e)); if(!scalar(type)) error(TYERR); - return(car(e)==CONST?list2(CONST,!cadr(e)):list2(LNOT,e)); + return list2(LNOT,e); case SIZEOF: conv->prefix_(sym); if(getsym(0)==LPAR) {
--- a/stdio.h Wed May 12 11:26:01 2004 +0900 +++ b/stdio.h Wed May 12 19:13:19 2004 +0900 @@ -1,4 +1,4 @@ -#ifndef __micro_c__aaa +#ifndef __micro_c__aaa #include "/usr/include/stdio.h" long long strtoll(const char *, char **, int); #else
--- a/test/simp1.c Wed May 12 11:26:01 2004 +0900 +++ b/test/simp1.c Wed May 12 19:13:19 2004 +0900 @@ -11,7 +11,7 @@ } char -c(char a,char b,char c,char d,char f) +ch(char a,char b,char c,char d,char f) { return a+b+c+d+f; } @@ -87,7 +87,7 @@ a=3; b=-3; c=5; - c = c(a*3,b*c,b+c,b/c,b-c); + c = ch(a*3,b*c,b+c,b/c,b-c); printf("char: %d\n",c); }