Mercurial > hg > CbC > old > device
changeset 680:f536897fa3cb
*** empty log message ***
author | kono |
---|---|
date | Sun, 29 Jul 2007 23:09:38 +0900 |
parents | c62ba4e606ce |
children | e16b34f2b386 |
files | .gdbinit Changes Idea mc-code-spu.c mc-tree.c mc.h |
diffstat | 6 files changed, 770 insertions(+), 497 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Fri May 25 19:28:25 2007 +0900 +++ b/.gdbinit Sun Jul 29 23:09:38 2007 +0900 @@ -13,6 +13,6 @@ x/1i $eip end b errmsg -r -s test/tmp7.c -# r -s test/code-gen-all.c +# r -s test/tmp7.c + r -s test/code-gen-all.c # r -s mc-code-powerpc.c
--- a/Changes Fri May 25 19:28:25 2007 +0900 +++ b/Changes Sun Jul 29 23:09:38 2007 +0900 @@ -9410,3 +9410,17 @@ GC やるんだろうなぁ。変更的には、結構大きくなるが... +code_decl 用の pcode_decl を書く必要があるようだね。 + +Fri Jun 8 13:53:53 JST 2007 + +まぁ、それは置いておいて、mc-spu の方をやるか。is_int_reg とかが +あるので、 + REGS_MAX = 128*3 +ぐらいにする? + + + + + +
--- a/Idea Fri May 25 19:28:25 2007 +0900 +++ b/Idea Sun Jul 29 23:09:38 2007 +0900 @@ -2072,3 +2072,44 @@ 難しいね。きれいなsyntaxにならない。 +Wed Jul 25 14:48:16 JST 2007 + +inline code __goto みたいな形にすると、 + + __goto hoge(); + +goto を reflection 出来る。 + +meta な、interface はどうするの? + +デフォルトで、,.... が入っていると思う方が良い。 + + goto hoge(hoge.... , __code (*cont)(i) : meta ...); + + goto cont(i); -> goto cont(i: meta...); + +という感じか? これがないと、記述がかなり面倒。subroutine とは +違うの? + +env の切替えで明示出来ないの? 出来るけど、繁雑なのか。 + +gcc との相性が良くないのだが... + +__code の先行宣言つらすぎる。script で生成するか、compiler で +自動解決する方が良い。 + +tcc の方が goto f(); ではなくて、goto (*f)(); を +強制する。これは、けっこう、めんどくさい。 + + ... ってのは大域変数みたいなものだよね? ただ、stack scope がある。 +なので、sub routine と同じなのでは? + + + + + + + + + +
--- a/mc-code-spu.c Fri May 25 19:28:25 2007 +0900 +++ b/mc-code-spu.c Sun Jul 29 23:09:38 2007 +0900 @@ -91,6 +91,7 @@ static void dconst(int l,int h,double value); static void code_assign_input_double_long(int e1,int e2) ; +static void code_assign_input_double_reg(int e1,int e2) ; static void code_assign_input_float_int(int e1,int e2) ; #endif static void use_input_reg(int reg,int mode); @@ -483,23 +484,27 @@ lvar(int l,char *cext) { if (large_lvar) { - printf("[%s, 0]%s\n",register_name(large_lvar),cext); + //printf("[%s, 0]%s\n##lvar0\n",register_name(large_lvar),cext); + printf("0(%s)\n##lvar0\n",register_name(large_lvar)); free_register(large_lvar); return; } if (is_code(fnptr)) { if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("[sp, %d]%s\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET),cext); - } else - printf("[fp, %d]%s\n",CODE_LVAR(l),cext); - } else if (l<0) { /* local variable */ - //printf("[fp, #%d+.L%d]%s\n",FUNC_LVAR(l),lvar_offset_label,cext); + //printf("[sp, %d]%s\n##lvar1\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET),cext); + printf("%d($sp)\n##lvar1\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); + //} else + // printf("[fp, %d]%s\n",CODE_LVAR(l),cext); + printf("%d($sp)\n",CODE_LVAR(l)); + } + } else if (l<0) { /* local variable */ + //printf("[fp, #%d+.L%d]%s\n##lvar2\n",FUNC_LVAR(l),lvar_offset_label,cext); printf(".LC%d+%d($sp)\n",lvar_offset_label,FUNC_LVAR(l)); } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("[sp, %d]%s\n",CALLER_ARG(l-ARG_LVAR_OFFSET),cext); + printf("%d($sp)%s\n",CALLER_ARG(l-ARG_LVAR_OFFSET),cext); } else { /* callee's arguments */ - printf("[fp, %d]%s\n",CALLEE_ARG(l),cext); - } + printf("%d($sp)%s\n",CALLEE_ARG(l),cext); + } } static void @@ -518,8 +523,9 @@ // printf("\tsfi\t%s, fp, %d\n",register_name(creg), FUNC_LVAR(l)); trn = register_name(tmp = get_register()); //disp = search_const(LVAR,glist2(lvar_offset_label,FUNC_LVAR(l)),&label); - printf("\tlqd\t%s, %d($sp)\n",trn,(disp*4)); - printf("\tadd\t%s, fp, %s\n",register_name(creg),trn); + //printf("\tlqdhoge\t%s, %d($sp)\n",trn,(disp*4)); + printf("\tlqd\t%s, 64($sp)\n",trn); + printf("\ta\t%s, $sp, %s\n",register_name(creg),trn); } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ code_add(creg,CALLER_ARG(l-ARG_LVAR_OFFSET),REG_sp); } else { /* callee's arguments */ @@ -1246,7 +1252,7 @@ int disp; char *rrn = register_name(r); //disp = search_const(GVAR,(int)nptr,&label); - printf("\tlqd\t%s, %d($sp)\n",rrn,(disp*4)); + printf("\tlqd\t%s, %d($sp)\n",rrn,(nptr->sc)*16); } #define mask8(d,bit) (d & (255 << bit)) @@ -1362,8 +1368,8 @@ crn = register_name(reg); if ((s=make_const(e2,&p1,&p2,&p3,CONST))) { add = s>0?"a":"sf"; - mov = s>0?"il":"mvn"; - printf("\t%s\t%s, %d\n",mov,crn,p1); + mov = s>0?"il":"ori"; + printf("\t%s\t%s, %s, %d\n",mov,crn,crn,p1); if (p2) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p2); if (p3) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p3); } else { @@ -1397,17 +1403,17 @@ crn = register_name(reg); if (-32768<e2&&e2<32768) printf("\til %s,%d\n",crn,e2); - else if(32767<e2&&e2<262143) + else if(32767<e2&&e2<262144) printf("\tila %s,%d\n",crn,e2); else if(262143<e2) { - printf("\t ilhu %s,%d\n",crn,e2/16^4); - printf("\t iohl %s,%d\n",crn,e2%16^4); + printf("\t ilhu\t%s,%d\n",crn,e2/65536); + printf("\t iohl %s,%d\n",crn,e2%65536); } else { r = (~e2 >> 16) & 0xffff; r += 1; r = -r; - printf("\tilhu %s,%d\n",crn,r); - if(e2 > -262143) + printf("\tilhu\t%s,%d\n",crn,r); + if((e2&0xffff) > -262143) printf("\tiohl %s,%d\n",crn, (e2&0xffff)); else printf("\tori %s,%s,%d\n",crn,crn,(e2&0xffff)); @@ -1419,9 +1425,10 @@ { char *crn = register_name(reg); char *rrn = register_name(r); - char *drn; + char *rn2 = register_name(r+1); + char *drn; int dreg; - int s,p1,p2,p3; + int s,p1,p2,p3,h; char *add; //int label,disp; int disp; @@ -1429,10 +1436,30 @@ if(r!=reg) printf("\tori\t%s, %s, 0\n",crn,rrn); } else if ((s=make_const(offset,&p1,&p2,&p3,0))) { - add = s>0?"a":"sfi"; - printf("\t%s\t%s, %s, %d\n",add,crn,rrn,p1); - if (p2) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p2); - if (p3) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p3); + add = s>0?"a":"sf"; + //printf("\t%s\t%s, %s, %d\n",add,crn,rrn,p1); + if (-32768<(p1+p2+p3)&&(p1+p2+p3)<32768) + printf("\til\t%s,%d\n",rn2,(p1+p2+p3)); + else if( (p1+p2+p3) > 32767 && (p1+p2+p3) < 262144) + printf("\tila\t%s, %d\n",rn2,p1+p2+p3); + else if( (p1+p2+p3) > 262143) { + printf("\tilhu\t%s, %d\n",rn2,(p1+p2+p3)/65536); + printf("\tiohl\t%s, %d\n",rn2,(p1+p2+p3)%65536); + } else { + h = (~(p1+p2+p3) >> 16) & 0xffff; + h += 1; + h = -h; + printf("\tilhu\t%s,%d\n",crn,h); + if(((p1+p2)&0xffff) > -262143) + printf("\tiohl %s,%d\n",crn, ((p1+p2)&0xffff)); + else + printf("\tori %s,%s,%d\n",crn,crn,((p1+p2)&0xffff)); + + } + + printf("\t%s\t%s, %s, %s\n", add, crn, rrn ,rn2); + //if (p2) printf("\t%s\t%s, %s, %s\n",add,crn,rrn,rrn+1); + //if (p3) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p3); } else { //disp = search_const(CONST,offset,&label); drn = register_name(dreg = get_register()); @@ -1449,33 +1476,32 @@ char *crn = register_name(reg); char *rrn = register_name(r); if (-1024<offset&&offset<1024) { - printf("\t%s\t%s, [%s, %d]%s\n",ld,crn,rrn,offset,cext); + printf("\t%s\t%s, %d(%s)\n",ld,crn,offset,rrn); } else { code_add(reg,offset,r); - printf("\t%s\t%s, [%s, 0]%s\n",ld,crn,crn,cext); + printf("\t%s\t%s, 0(%s) %s\n",ld,crn,crn,cext); } } static void code_ldf(char *ld,char *crn,int offset,int r,char *cext) { - //char *rrn = register_name(r); + char *rrn = register_name(r); char *orn; int reg; if (-1024<offset&&offset<1024) { - printf("\t%s\t%s, %d(%s)\n",ld,crn,(offset*4),cext); + printf("\t%s\t%s, %d(%s)\n",ld,crn,(offset*4),rrn); } else { orn = register_name(reg=get_register()); code_add(reg,offset,r); //printf("\t%s\t%s, [%s, 0]%s\n",ld,crn,orn,cext); - printf("hoge\n"); free_register(reg); } } #define cload(sz,sign) \ - (sz==1?(sign?"lqx":"lqa"):sz==SIZE_OF_SHORT?(sign?"lqx":"lqa"):"lqd") + (sz==1?(sign?"lqd":"lqd"):sz==SIZE_OF_SHORT?(sign?"lqd":"lqd"):"lqd") #define cext(sign,sz,reg) @@ -1531,7 +1557,7 @@ lvar_intro(e2); printf("\tlqd\t%s, ",register_name(reg)); e2 *= 4; - lvar(e2,""); + lvar(e2,""); } extern void @@ -1548,15 +1574,21 @@ code_u2uc(int reg) { use_int(reg); - printf("and\t%s, %s, #255\n",register_name(reg),register_name(reg)); + printf("\tandbi\t%s, %s, 255\n",register_name(reg),register_name(reg)); } extern void code_u2us(int reg) -{ +{ + // &! 16711680篏帥cilhu16711680吾鴻帥主 + // and rt,rs,ra and茵域!鐚 use_int(reg); - printf("bic\t%s, %s, #16711680\n",register_name(reg),register_name(reg)); - printf("bic\t%s, %s, #-16777216\n",register_name(reg),register_name(reg)); + //printf("bic\t%s, %s, #16711680\n",register_name(reg),register_name(reg)); + printf("\tilhu\t%s,255\n", register_name(reg+1)); + printf("\tand\t%s,%s,%s\n",register_name(reg),register_name(reg),register_name(reg+1)); + //printf("bic\t%s, %s, #-16777216\n",register_name(reg),register_name(reg)); + printf("\tilhu\t%s,-256\n", register_name(reg+1)); + printf("\tand\t%s,%s,%s\n",register_name(reg),register_name(reg),register_name(reg+1)); } void @@ -1591,14 +1623,15 @@ void code_neg(int creg) { use_int(creg); - printf("\trsb\t%s, %s, #0\n", register_name(creg), register_name(creg)); + //printf("\trsb\t%s, %s, #0\n", register_name(creg), register_name(creg)); + printf("\tsfi\t%s, %s, 0\n", register_name(creg), register_name(creg)); } void code_not(int creg) { use_int(creg); - printf("\tmvn\t%s, %s\n", + printf("\tori\t%s, %s, 0\n", register_name(creg), register_name(creg)); } @@ -1607,9 +1640,10 @@ code_lnot(int creg) { use_int(creg); - printf("\tcmp\t%s, #0\n", register_name(creg)); - printf("\tmovne\t%s, #0\n", register_name(creg)); - printf("\tmoveq\t%s, #1\n", register_name(creg)); + //printf("\tcmp\t%s, #0\n", register_name(creg)); + printf("\tceqbi\t%s,%s,0\n",register_name(creg),register_name(creg)); + //printf("\tmovnehoge\t%s, #0\n", register_name(creg)); + //printf("\tmoveq\t%s, #1\n", register_name(creg)); } void @@ -1689,15 +1723,16 @@ /* save frame pointer */ if (is_code(fnptr)) { use_int(creg); - printf("\tmov\t%s, fp\n",register_name(creg)); - } else { + //printf("\tmov\t%s, fp\n",register_name(creg)); + printf("\tori\t%s, fp, 0\n",register_name(creg)); + } else { //int disp,label; int disp; char *trn = register_name(REG_ip); use_int(creg); //disp = search_const(LVAR,glist2(lvar_offset_label,FUNC_LVAR(0)),&label); printf("\tlqa\t%s, %d\n",trn,disp); - printf("\ta\t%s, fp, %s\n",register_name(creg),trn); + printf("\ta\t%s, $sp, %s\n",register_name(creg),trn); } } @@ -1718,10 +1753,12 @@ if (use) { use_int(reg); xrn = register_name(reg); - printf("\tmov\t%s, #0\n",xrn); + //printf("\tmov\t%s, #0\n",xrn); + printf("\til\t%s, 0\n",xrn); gen_jmp(e3=fwdlabel()); fwddef(e2); - printf("\tmov\t%s, #1\n",xrn); + //printf("\tmov\t%s, #1\n",xrn); + printf("\til\t%s, 1\n",xrn); fwddef(e3); } else { fwddef(e2); @@ -1735,7 +1772,7 @@ code_ld(cload(sz,0),reg,cadr(e1),get_ptr_cache((NMTBL*)caddr(e1)), cext_at(sz,0)); cext(0,sz,r); - printf("\tcmp\t%s, #0\n",register_name(reg)); + printf("\tceqi\t%s, %s, 0\n",register_name(reg), register_name(reg)); jcond(label,cond); } @@ -1746,7 +1783,7 @@ use_int(reg); crn = register_name(reg); lvar_intro(e2); - printf("\t%s\t%s, ",cload(sz,0),crn); + printf("\t%s\t%s,hoge2 ",cload(sz,0),crn); lvar(e2,cext_at(sz,0)); cext(0,sz,reg); code_cmp_register(reg,label,cond); @@ -1777,7 +1814,7 @@ void code_cmp_register(int e2,int label,int cond) { use_int(e2); - printf("\tcmp\t%s, #0\n",register_name(e2)); + printf("\tceqi\t%s, %s, 0\n",register_name(e2), register_name(e2)); jcond(label,cond); } @@ -1834,12 +1871,12 @@ printf("\tstqd\t%s,%d(%s)\n",drn,(offset*4),trn); break; case 2: case -2: - printf("\tlqx\t%s, [%s,#%d]\n",drn,frn,offset); - printf("\tstqx\t%s, [%s,#%d]\n",drn,trn,offset); + printf("\tlqd\t%s, %d(%s)\n",drn,(offset*4),trn); + printf("\tstqd\t%s,%d(%s)\n",drn,(offset*4),trn); break; case 4: case -4: - printf("\tlqa\t%s, [%s,#%d]\n",drn,frn,offset); - printf("\tstqa\t%s, [%s,#%d]\n",drn,trn,offset); + printf("\tlqd\t%s, %d(%s)\n",drn,(offset*4),trn); + printf("\tstqd\t%s,%d(%s)\n",drn,(offset*4),trn); break; default: if (length <0) { @@ -1867,7 +1904,7 @@ code_const(length>0?length:-length,3); /* overlap must be allowed */ // offset have to be ignored */ - printf("\thbra\t%s\n",memmove); + //printf("\thbra\t%s\n",memmove); extern_define(memmove,0,FUNCTION,1); set_ireg(RET_REGISTER,0); if (creg!=to) { @@ -1918,8 +1955,8 @@ srn = register_name(sreg); code_lvar(arg_disp,dreg); for(count=0;count<length;count+=SIZE_OF_INT) { - printf("\tlqd\t%s, [%s, #%d]\n",srn,crn,count+on_register*SIZE_OF_INT); - printf("\tstr\t%s, [%s, #%d]\n",srn,drn,count); + printf("\tlqd\t%s, %d(%s)\n",srn,count+on_register*SIZE_OF_INT,crn); + printf("\tstqd\t%s, %d(%s)\n",srn,count,drn); } free_register(sreg); if (on_register) { @@ -1947,8 +1984,8 @@ } for (count=0,arg_reg; on_register-->0; arg_reg++,count+=SIZE_OF_INT) { // len0 = (len0>2)?0:len0; - printf("\t%s\t%s, [%s, #%d]\n", cload(0,0), - register_name(arg_reg), crn,count); + printf("\t%s\t%s, %d(%s)\n", cload(0,0), + register_name(arg_reg), count,crn); use_input_reg(arg_reg,1); } return length/SIZE_OF_INT; @@ -2242,13 +2279,43 @@ reg = freg; case DREGISTER: if (car(e2)==DREGISTER) reg = cadr(e2); - printf("\tstqd\t%s, [sp, #-8]!\n",register_name(reg)); - printf("\tldmfd\tsp!, {%s, %s}\n",lregister_name_low(r),lregister_name_high(r)); + //printf("\tstqd\t%s, #sp, #-8]!\n",register_name(reg)); + //printf("\tstqd\t%s, #sp, #-8]!\n",register_name(reg)); + //printf("\tldmfd\tsp!, {%s, %s}\n",lregister_name_low(r),lregister_name_high(r)); + printf("\tstqd\t%s, -8($sp)\n",register_name(reg)); + printf("\tstqd\t%s, -8($sp)\n",register_name(reg)); + printf("\tlqx\t$sp,%s, %s\n",lregister_name_low(r),lregister_name_high(r)); } if (tmp!=-1) free_lvar(tmp); #endif } +static void +code_assign_input_double_reg(int e1,int e2) { +#if FLOAT_CODE + int r,tmp=-1,reg=0; + double value; + if(car(e1)!=REGISTER) { error(-1); return;} + r = cadr(e1); + switch(car(e2)) { + case DCONST: + value = dcadr(e2); + dconst(r,r,value); + break; + case DRGVAR: + code_lrgvar(e2,r); + break; + case DRLVAR: + code_lrlvar(cadr(e2),r); + break; + default: + g_expr(rvalue_t(e2,DOUBLE)); + reg = freg; + } + if(tmp!=-1) free_lvar(tmp); +#endif +} + static int compute_complex_arg(int e3,int reg_arg_list,int arg) { int t=caddr(e3); @@ -2341,8 +2408,9 @@ if (car(e2) == FNAME) { printf("\tbrsl\t$lr,%s\n",fn->nm); } else { - printf("\tmov\tlr, pc\n"); - printf("\tmov\tpc, %s\n",register_name(cadr(jmp))); + //printf("\tmov\tlr, pc\n"); + printf("\tori\t$sp,%s,0\n",register_name(cadr(jmp))); + printf("\tori\t$sp, %s,0\n",register_name(cadr(jmp))); } } @@ -2505,9 +2573,10 @@ g_expr_u(assign_expr0(arg,e4,t,t)); } else if (t==DOUBLE) { reg_arg_list = list2(arg,reg_arg_list); - if (car(arg)==LREGISTER) { - use_input_reg(cadr(arg),1); - code_assign_input_double_long(arg, e4); + if (car(arg)==REGISTER) { + use_input_reg(cadr(arg),1); + //code_assign_input_double_long(arg, e4); + code_assign_input_double_reg(arg, e4); } else { g_expr_u(assign_expr0(arg,e4,t,t)); } @@ -2567,16 +2636,17 @@ g_expr(list3(BAND,list3(ADD,e1,list2(CONST,15)),list2(CONST,~15))); use_int(reg); crn = register_name(reg); - printf("\trsb\tsp, %s, sp\n",crn); + //printf("\tsfi\t$sp, %s, $sp\n",crn); if (!max_func_arg_label) max_func_arg_label = fwdlabel(); code_label_value(max_func_arg_label ,REG_ip); - printf("\ta\t%s, sp, ip\n",crn); + printf("\ta\t%s, $sp, $sp\n",crn); } void code_frame_pointer(int e3) { use_int(e3); - printf("\tmov\tfp, %s\n",register_name(e3)); + //printf("\tmov\tfp, %s\n",register_name(e3)); + printf("\tori\t$sp,%s\n",register_name(e3)); } int @@ -2595,7 +2665,7 @@ trn = register_name(REG_ip); //disp = search_const(LVAR,glist2(lvar_offset_label,FUNC_LVAR(0)),&label); printf("\tlqd\t%s, %d($sp)\n",trn,disp); - printf("\ta\tfp, fp, %s\n",trn); + printf("\ta\t$sp, $sp, %s\n",trn); } } @@ -2618,7 +2688,7 @@ // jump to continuation means use all register variable max_reg_var = REG_VAR_MAX-REG_VAR_MIN; max_reg_var = FREG_VAR_MAX-FREG_VAR_MIN; - printf("\thogebr\t%s\n",s); + printf("\tbr\t%s\n",s); control=0; } @@ -2628,7 +2698,8 @@ max_reg_var = REG_VAR_MAX-REG_VAR_MIN; max_reg_var = FREG_VAR_MAX-FREG_VAR_MIN; use_int(e2); - printf("\tmov\tpc, %s @ indirect jump\n",register_name(e2)); // ?! + //printf("\tmov\tpc, %s @ indirect jump\n",register_name(e2)); // ?! + printf("\tbi\t%s\n",register_name(e2)); // ?! control=0; } @@ -2653,7 +2724,7 @@ if (!is_int_reg(creg)) error(-1); xreg = creg; use_float(d,reg); - code_ldf(d?"ldfd":"ldfs",register_name(reg),offset,xreg,""); + code_ldf(d?"lqd":"lqd",register_name(reg),offset,xreg,""); return d?DOUBLE:FLOAT; } #endif @@ -2666,19 +2737,19 @@ char *crn=register_name(creg); #if ENDIAN_L==0 if (creg!=reg) { - printf("\tldr\t%s, [%s, #%d]\n",lregister_name_low(reg),crn,offset); - printf("\tldr\t%s, [%s, #%d]\n",lregister_name_high(reg),crn,offset+SIZE_OF_INT); + printf("\tlqd\t%s, %d(%s)\n",lregister_name_low(reg),offset,crn); + //printf("\tldr\t%s, [%s, #%d]\n",lregister_name_high(reg),crn,offset+SIZE_OF_INT); } else { - printf("\tldr\t%s, [%s, #%d]\n",lregister_name_high(reg),crn,offset+SIZE_OF_INT); - printf("\tldr\t%s, [%s, #%d]\n",lregister_name_low(reg),crn,offset); + printf("\tlqd\t%s, %d(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); + //printf("\tldr\t%s, [%s, #%d]\n",lregister_name_low(reg),crn,offset); } #else if (creg!=reg) { - printf("\tldr\t%s, [%s, #%d]\n",lregister_name_low(reg),crn,offset+SIZE_OF_INT); - printf("\tldr\t%s, [%s, #%d]\n",lregister_name_high(reg),crn,offset); + printf("\tlqd\t%s, %d(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); + //printf("\tldr\t%s, [%s, #%d]\n",lregister_name_high(reg),crn,offset); } else { - printf("\tldr\t%s, [%s, #%d]\n",lregister_name_high(reg),crn,offset); - printf("\tldr\t%s, [%s, #%d]\n",lregister_name_low(reg),crn,offset+SIZE_OF_INT); + printf("\tlqd\t%s, %d(%s)\n",lregister_name_high(reg),offset,crn); + //printf("\tldr\t%s, [%s, #%d]\n",lregister_name_low(reg),crn,offset+SIZE_OF_INT); } #endif } @@ -2714,11 +2785,11 @@ crn_h = lregister_name_high(creg); crn_l = lregister_name_low(creg); #if ENDIAN_L==0 - printf("\tstr\t%s, [%s, #0]\n",crn_l,drn); - printf("\tstr\t%s, [%s, #%d]\n",crn_h,drn,SIZE_OF_INT); + printf("\tstqd\t%s, 0(%s)\n",crn_l,drn); + printf("\tstqd\t%s, %d(%s)\n",crn_h,SIZE_OF_INT,drn); #else - printf("\tstr\t%s, [%s, #0]\n",crn_h,drn); - printf("\tstr\t%s, [%s, #%d]\n",crn_l,drn,SIZE_OF_INT); + printf("\tstqd\t%s, 0(%s)\n",crn_h,drn); + printf("\tstqd\t%s, %d(%s)\n",crn_l,SIZE_OF_INT,drn); #endif } @@ -2740,8 +2811,8 @@ cstore(int sz) { switch(sz) { - case 1: return "stqx"; - case SIZE_OF_SHORT: return "stqa"; + case 1: return "stqd"; + case SIZE_OF_SHORT: return "stqd"; default: return "stqd"; } } @@ -2925,12 +2996,12 @@ v=ilog(v); case LSHIFT: case ULSHIFT: - printf("\tmov\t%s, %s, asl #%d\n",crn,crn,v); + printf("\troti\t%s, %s,-%d\n",crn,crn,v); break; case DIV: v=ilog(v); case RSHIFT: - printf("\trotmai\t%s, %s, %d\n",crn,crn,v); + printf("\troti\t%s, %s, -%d\n",crn,crn,v); break; case UDIV: v=ilog(v); @@ -2944,9 +3015,9 @@ code_add(creg,-v,creg); break; case CMP: printf("\tceq\t%s,%d\n",crn,v); break; - case BOR: printf("\tor\t%s, %s, #%d\n",crn,crn,v); break; - case EOR: printf("\txor\t%s, %s, #%d\n",crn,crn,v); break; - case BAND: printf("\tand\t%s, %s, #%d\n",crn,crn,v); break; + case BOR: printf("\tori\t%s, %s, %d\n",crn,crn,v); break; + case EOR: printf("\txori\t%s, %s, %d\n",crn,crn,v); break; + case BAND: printf("\tandi\t%s, %s, %d\n",crn,crn,v); break; default: error(-1); } @@ -3003,12 +3074,12 @@ switch(cond) { case -1: break; case 1: - printf("\tbne\t.LC%d\n",label); break; + printf("\tbr\t.LC%d\n",label); break; case 0: - printf("\tbeq\t.LC%d\n",label); break; + printf("\tbr\t.LC%d\n",label); break; case LT: - printf("\tblt\t.LC%d\n",label); break; - case GT: + printf("\tbra\t.LC%d\n",label); break; + case GT: printf("\tbgt\t.LC%d\n",label); break; default: error(-1); } @@ -3056,25 +3127,29 @@ } switch(op+(!cond)*BNOT) { - case GT: case LE+BNOT: cc="cgt"; ncc="le"; break; - case LE: case GT+BNOT: cc="le"; ncc="cgt"; break; - case GE: case LT+BNOT: cc="ge"; ncc="lt"; break; - case LT: case GE+BNOT: cc="lt"; ncc="ge"; break; - case UGT: case ULE+BNOT: cc="hi"; ncc="ls"; break; - case ULE: case UGT+BNOT: cc="ls"; ncc="hi"; break; - case UGE: case ULT+BNOT: cc="hs"; ncc="lo"; break; - case ULT: case UGE+BNOT: cc="lo"; ncc="hs"; break; - case EQ: case NEQ+BNOT: cc="eq"; ncc="ne"; break; - case NEQ: case EQ+BNOT: cc="ne"; ncc="eq"; break; + case GT: case LE+BNOT: cc="r"; ncc="r"; break; + case LE: case GT+BNOT: cc="r"; ncc="r"; break; + case GE: case LT+BNOT: cc="r"; ncc="r"; break; + case LT: case GE+BNOT: cc="r"; ncc="r"; break; + case UGT: case ULE+BNOT: cc="r"; ncc="r"; break; + case ULE: case UGT+BNOT: cc="r"; ncc="r"; break; + case UGE: case ULT+BNOT: cc="r"; ncc="r"; break; + case ULT: case UGE+BNOT: cc="r"; ncc="r"; break; + case EQ: case NEQ+BNOT: cc="r"; ncc="r"; break; + //case NEQ: case EQ+BNOT: cc="rnz"; ncc="r"; break; + case NEQ: case EQ+BNOT: cc="r"; ncc="r"; break; default: error(-1); } if (mode==COND_BRANCH||mode==COND_BRANCH_CONST) { - printf("\tb%s\t.LC%d\n",cc,l1); + printf("\tb%s\t.LC%d\n",cc,l1); + //printf("\tb%s\t%s, .LC%d\n",cc,rn1,l1); } else if (mode==COND_VALUE||mode==COND_VALUE_CONST) { rn0 = register_name(r0); - printf("\tmov%s\t%s, #0\n",ncc,rn0); - printf("\tmov%s\t%s, #1\n",cc,rn0); + // nccу絏< + printf("#####pcond##########\n"); + //printf("\tmovhoge%s\t%s, #0\n",ncc,rn0); + //printf("\tmovfuho%s\t%s, #1\n",cc,rn0); } else error(-1); } @@ -3131,7 +3206,7 @@ static void jcond(int l, int cond) { - printf("\tb%s\t.LC%d\n",cond?"ne":"eq",l); + printf("\tb%s\t.LC%d\n",cond?"r":"r",l); } void @@ -3172,12 +3247,15 @@ if (freg_save>0) { i=reg_save*SIZE_OF_INT+ freg_save*SIZE_OF_DOUBLE + 20; - printf("\tlfm\tf4, %d, [fp, #%d]\n",freg_save,-i); - } + //printf("\tlfm\tf4, %d, [fp, #%d]\n",freg_save,-i); + printf("\tlqd\t$sp,%d($sp)\n",i); + } //printf("\tldmea\tfp, {"); - for (i=reg_var_num(0);i<reg_var_num(reg_save);i++) { - printf("%s, ",register_name(i)); - } + for (i=reg_var_num(0);i<reg_var_num(reg_save);i++) { + //printf("%s, ",register_name(i)); + printf("\tlqd\t%s,-%d($sp)\n",register_name(i),-disp); + disp -= SIZE_OF_FLOAT*4; + } //printf("fp, sp, pc}\n"); return disp; } @@ -3198,7 +3276,7 @@ max_func_args = 0; printf("%s:\n",name); code_label_value(r1_offset_label,REG_ip); - printf("\ta\tsp, ip, fp\n"); + printf("\ta\t$sp, $sp, $fp\n"); clear_ptr_cache(); } @@ -3235,7 +3313,7 @@ if (stmode!=STATIC) printf("\t.globl\t%s\n",name); printf("%s:\n",name); - //printf("\tmov\tip, sp\n"); + //printf("\tmov\t$sp, $lr,0\n"); printf("\tstqd\t$lr,16($sp)\n"); printf("\tstqd\t$sp,-32($sp)\n"); printf("\tai\t$sp,$sp,-32\n"); @@ -3256,13 +3334,13 @@ void code_label_call(int l) { - printf("\tbl\tL_%d\n",l); + printf("\tbr\tL_%d\n",l); } void code_ret() { - printf("\tmov\tpc, lr\n"); + //printf("\tmov\tpc, lr\n"); control=0; } @@ -3295,8 +3373,8 @@ car(cadr(fnptr->ty))==UNION)) { sz = size(cadr(fnptr->ty)); code_const(sz,REGISTER_OPERAND); - printf("\tsf\tr1, r2, fp\n"); - printf("\tlqd\tr0, [fp, #%d]\n",(my_func_args-1)*SIZE_OF_INT); + printf("\tsf\t$1, $2, $sp\n"); + printf("\tlqd\t$1, %d($sp)\n",(my_func_args-1)*SIZE_OF_INT); emit_copy(6,3,sz,0,1,1); } else if (cadr(fnptr->ty)!=VOID) { creg = ireg = cadr(get_input_register_var(0,0,1)); @@ -3316,7 +3394,7 @@ fwddef(entry_label); if (arg_on_register>0) - printf("\tsfi\tsp, sp, %d\n",arg_on_register); + printf("\tsfi\t$sp, $sp, %d\n",arg_on_register); //code_register_save(max_reg_var,max_reg_var,0); //printf("\tsf\tfp, ip, #%d\n",4+arg_on_register); @@ -3557,7 +3635,7 @@ emit_label(int labelno) { data_mode(0); - printf("\t.word .L%d\n",labelno); + printf("\t.word .LC%d\n",labelno); } void @@ -3571,7 +3649,7 @@ #ifdef DOT_SIZE lb=fwdlabel(); printf(".LC%d:\n",lb); - printf("\t.size\t%s,.L%d-%s\n",n->nm,lb,n->nm); + printf("\t.size\t%s,.LC%d-%s\n",n->nm,lb,n->nm); #endif } } @@ -3580,9 +3658,9 @@ static void comm(NMTBL *n) { - printf(".comm %s,%d @ %d\n",n->nm,size(n->ty), - (n->ty==DOUBLE||n->ty==LONGLONG||n->ty==ULONGLONG)?8:4 - ); + //printf(".comm %s,%d @ %d\n",n->nm,size(n->ty), + //(n->ty==DOUBLE||n->ty==LONGLONG||n->ty==ULONGLONG)?8:4 + //); } void @@ -3675,7 +3753,7 @@ code_save_stacks(); clear_ptr_cache(); extern_define(conv,0,FUNCTION,1); - printf("\tbl\t%s\n",conv); + printf("\tbr\t%s\n",conv); lib_args(16); } #endif @@ -3690,7 +3768,7 @@ g = list3(REGISTER_OPERAND_1,g,oreg); parallel_rassign(g); extern_define(lib,0,FUNCTION,1); - printf("\tbl\t%s\n",lib); + printf("\tbr\t%s\n",lib); lib_args(16); set_ireg(RET_REGISTER,0); if (reg!=RET_REGISTER) { @@ -3720,14 +3798,14 @@ static char * movef(int d) { - return d?"mvfd":"mvfs"; + return d?"ori":"ori"; } static char * -fload(int d) { return d?"ldfd":"ldfs"; } +fload(int d) { return d?"lqd":"lqd"; } static char * -fstore(int d) { return d?"stfd":"stfs"; } +fstore(int d) { return d?"stqd":"stqd"; } void @@ -3736,7 +3814,7 @@ use_float(d,freg); if (freg!=e2) { if (is_int_reg(e2)) error(-1); - printf("\t%s\t%s, %s\n",movef(d), + printf("\t%s\t%s, %s, 0\n",movef(d), register_name(freg),register_name(e2)); } } @@ -3746,7 +3824,7 @@ { use_float(d,freg); code_ldf(fstore(d),register_name(freg),cadr(e2), - get_ptr_cache((NMTBL*)caddr(e2))," @ float"); + get_ptr_cache((NMTBL*)caddr(e2)),""); } void @@ -3755,14 +3833,15 @@ use_float(d,freg); lvar_intro(e2); printf("\t%s\t%s, ",fstore(d),register_name(freg)); - lvar(e2,"@ float"); + lvar(e2,""); } void code_dassign(int e2,int freg,int d) { use_float(d,freg); - printf("\t%s\t%s, [%s, #0] @ float\n",fstore(d), + //printf("\t%s\t%s, [%s, #0] @ float\n",fstore(d), + printf("\t%s\t%s, 0(%s)\n",fstore(d), register_name(freg),register_name(e2)); } @@ -3770,7 +3849,7 @@ code_dassign_dregister(int e2,int d,int freg) { use_float(d,freg); if (e2!=freg) { - printf("\t%s\t%s, %s\n",movef(d), + printf("\t%s\t%s, %s, 0\n",movef(d), register_name(e2),register_name(freg)); } } @@ -3802,13 +3881,7 @@ static void dconst(int l,int h,double value) { -#if ENDIAN_D==0 - code_const(code_d1(value),l); - code_const(code_d2(value),h); -#else - code_const(code_d1(value),h); - code_const(code_d2(value),l); -#endif + code_dconst(code_d2(value),h,1); } @@ -3823,9 +3896,9 @@ use_float(d,freg); frn = register_name(freg); if (value==0 || value==1 || value==10) { - printf("\t%s\t%s, #%d\n",movef(d),frn,(int)value); + printf("\t%s\t%s, %s, %d\n",movef(d),frn,frn,(int)value); } else if (value==-1 || value==-10) { - printf("\t%s\t%s, #%d\n",d?"mnfd":"mnfs",frn,(int)-value); + printf("\t%s\t%s, %d\n",d?"mnfd":"mnfs",frn,(int)-value); } else if (d) { #if ENDIAN_D==0 disp = search_double_const(DCONST, @@ -3834,10 +3907,10 @@ disp = search_double_const(DCONST, code_d2(value),code_d1(value),&label); #endif - printf("\tldfd\t%s, .LC%d+%d\n",frn,label,disp); + printf("\tlqd\t%s, .LC%d+%d($sp)\n",frn,label,disp); } else { //disp = search_const(CONST,*((int*)&f),&label); - printf("\tldfs\t%s, .LC%d+%d\n",frn,label,disp); + printf("\tlqd\t%s, .LC%d+%d($sp)\n",frn,label,disp); } } @@ -3874,7 +3947,7 @@ int lreg; use_float(d,reg); lreg = get_register(); - printf("\tfixz\t%s, %s\n",register_name(lreg),register_name(reg)); + //printf("\tfixz\t%s, %s\n",register_name(lreg),register_name(reg)); set_ireg(lreg,0); return; } @@ -3899,7 +3972,7 @@ // u = (d>2.1e9)?((int)(d-2.1e9)^2147483648):(int)d use_float(1,reg); frn = register_name(reg); - if (!d) printf("\tmvfd\t%s, %s\n",frn,frn); + if (!d) printf("\tori\t%s, %s, 0\n",frn,frn); emit_dpush(1); code_dconst(dlist2(DCONST,2.147483648e9),USE_CREG,1); lrn = register_name(lreg = emit_dpop(d)); @@ -3907,12 +3980,12 @@ set_ireg(reg0=get_register(),0); crn = register_name(reg0); printf("\tcmfe\t%s, %s\n",lrn,frn); - printf("\tbge\t1f\n"); - printf("\tfixz\t%s, %s\n",crn,lrn); + printf("\tbr\t1f\n"); + //printf("\tfixz\t%s, %s\n",crn,lrn); printf("\tb\t2f\n"); printf("1:\n"); printf("\tsufd\t%s, %s, %s\n",lrn,lrn,frn); - printf("\tfixz\t%s, %s\n",crn,lrn); + //printf("\tfixz\t%s, %s\n",crn,lrn); printf("\teor\t%s, %s, #-2147483648\n",crn,crn); printf("2:\n"); emit_dpop_free(lreg,d); @@ -3929,8 +4002,8 @@ set_dreg(reg=get_dregister(1),0); frn = register_name(reg); printf("\tfltd\t%s, %s\n",frn,crn); - printf("\tcmp\t%s, #0\n",crn); - printf("\tbge\t1f\n"); + printf("\tceqi\t%s, %s, 0\n",crn,crn); + printf("\tbr\t1f\n"); freg1 = get_dregister(1); code_dconst(dlist2(DCONST,4.29496729600000000000e9),freg1,1); frn = register_name(creg); @@ -3955,7 +4028,7 @@ code_f2d(int reg) { char *frn; frn = register_name(freg); - printf("\tmvfd\t%s, %s\n",frn,frn); + printf("\tori\t%s, %s, 0\n",frn,frn); return; } @@ -4220,14 +4293,14 @@ } } switch(op) { - case FOP+GT: op1=FOP+CMP; opn = "bgt"; break; - case FOP+GE: op1=FOP+CMPGE; opn = "bge"; break; - case FOP+EQ: op1=FOP+CMP; opn = "beq"; break; - case FOP+NEQ: op1=FOP+CMP; opn = "bne"; break; - case DOP+GT: op1=DOP+CMP; opn = "bgt"; break; - case DOP+GE: op1=DOP+CMPGE; opn = "bge"; break; - case DOP+EQ: op1=DOP+CMP; opn = "beq"; break; - case DOP+NEQ: op1=DOP+CMP; opn = "bne"; break; + case FOP+GT: op1=FOP+CMP; opn = "br"; break; + case FOP+GE: op1=FOP+CMPGE; opn = "br"; break; + case FOP+EQ: op1=FOP+CMP; opn = "br"; break; + case FOP+NEQ: op1=FOP+CMP; opn = "br"; break; + case DOP+GT: op1=DOP+CMP; opn = "br"; break; + case DOP+GE: op1=DOP+CMPGE; opn = "br"; break; + case DOP+EQ: op1=DOP+CMP; opn = "br"; break; + case DOP+NEQ: op1=DOP+CMP; opn = "br"; break; default: error(-1); } g_expr(list3(op1,e2,e1)); @@ -4321,7 +4394,7 @@ code_cmp_lregister(int reg,int label,int cond) { use_longlong(reg); - printf("\torr\t%s, %s, %s\n", + printf("\torc\t%s, %s, %s\n", lregister_name_low(reg), lregister_name_low(reg), lregister_name_high(reg)); @@ -4404,11 +4477,11 @@ crn_l = lregister_name_low(creg); lvar_intro(e2); #if ENDIAN_L==0 - printf("\tstr\t%s, ",crn_l);lvar(e2,""); - printf("\tstr\t%s, ",crn_h);lvar(e2+SIZE_OF_INT,""); + printf("\tstqd\t%s, ",crn_l);lvar(e2,""); + printf("\tstqd\t%s, ",crn_h);lvar(e2+SIZE_OF_INT,""); #else - printf("\tstr\t%s, ",crn_h);lvar(e2,""); - printf("\tstr\t%s, ",crn_l);lvar(e2+SIZE_OF_INT,""); + printf("\tstqd\t%s, ",crn_h);lvar(e2,""); + printf("\tstqd\t%s, ",crn_l);lvar(e2+SIZE_OF_INT,""); #endif } @@ -4450,11 +4523,11 @@ crn_l = lregister_name_low(creg); r = get_ptr_cache((NMTBL*)caddr(e1)); #if ENDIAN_L==0 - code_ldf("ldr",crn_l,cadr(e1),r,""); - code_ldf("ldr",crn_h,cadr(e1)+SIZE_OF_INT,r,""); + code_ldf("lqd",crn_l,cadr(e1),r,""); + //code_ldf("ldr",crn_h,cadr(e1)+SIZE_OF_INT,r,""); #else - code_ldf("ldr",crn_h,cadr(e1),r,""); - code_ldf("ldr",crn_l,cadr(e1)+SIZE_OF_INT,r,""); + code_ldf("lqd",crn_h,cadr(e1),r,""); + //code_ldf("ldr",crn_l,cadr(e1)+SIZE_OF_INT,r,""); #endif } @@ -4494,13 +4567,7 @@ code_lconst(int e1,int creg) { use_longlong(creg); -#if ENDIAN_L==0 - code_const(code_l1(lcadr(e1)),(creg)); code_const(code_l2(lcadr(e1)),(creg)); -#else - code_const(code_l1(lcadr(e1)),(creg)); - code_const(code_l2(lcadr(e1)),(creg)); -#endif } void @@ -4590,8 +4657,8 @@ printf("\teor\t%s, %s, %s\n",crn_h,crn_h,orn_h); break; case LBOR: - printf("\torr\t%s, %s, %s\n",crn_l,crn_l,orn_l); - printf("\torr\t%s, %s, %s\n",crn_h,crn_h,orn_h); + printf("\tor\t%s, %s, %s\n",crn_l,crn_l,orn_l); + printf("\tor\t%s, %s, %s\n",crn_h,crn_h,orn_h); break; case LMUL: case LUMUL: @@ -4678,16 +4745,18 @@ code_const(0,(creg)); return; } else if (v>31) { - printf("\tmov\t%s, %s, lsl #%d\n",crn_h,crn_l,v-32); - code_const(0,(creg)); + //printf("\tmov\t%s, %s, lsl #%d\n",crn_h,crn_l,v-32); + // 劻激 + printf("\troti\t%s,%s,%d\n",crn_h,crn_h,96-v); + code_const(0,(creg)); return; } greg = get_register(); grn = register_name(greg); - printf("\tmov\t%s, %s, lsl #%d\n",crn_h,crn_h,v); - printf("\tmov\t%s, %s, lsr #%d\n",grn,crn_l,32-v); - printf("\torr\t%s, %s,%s\n",crn_h,crn_h,grn); - printf("\tmov\t%s, %s, lsl #%d\n",crn_l,crn_l,v); + printf("\tshli\t%s, %s, %d\n",crn_h,crn_h,v); + printf("\troti\t%s, %s, -%d\n",grn,crn_l,32-v); + printf("\torc\t%s, %s,%s\n",crn_h,crn_h,grn); + printf("\tshli\t%s, %s,%d\n",crn_l,crn_l,v); free_register(greg); return; case LDIV: @@ -4696,19 +4765,19 @@ if (v==0) return; if (v==32) { code_register((creg),(creg)); - printf("\tmov\t%s, %s, asr #31\n",crn_h,crn_l); + printf("\tshli\t%s, %s, 31\n",crn_h,crn_l); return; } else if (v>31) { - printf("\tmov\t%s, %s, asr #%d\n",crn_l,crn_h,v-32); - printf("\tmov\t%s, %s, asr #31\n",crn_h,crn_l); + printf("\t\t%s, %s, asr #%d\n",crn_l,crn_h,v-32); + printf("\tshl\t%s, %s, 31\n",crn_h,crn_l); return; } greg = get_register(); grn = register_name(greg); - printf("\tmov\t%s, %s, lsr #%d\n",crn_l,crn_l,v); - printf("\tmov\t%s, %s, lsl #%d\n",grn,crn_h,32-v); - printf("\torr\t%s, %s,%s\n",crn_l,crn_l,grn); - printf("\tmov\t%s, %s, asr #%d\n",crn_h,crn_h,v); + printf("\troti \t%s, %s, %d\n",crn_l,crn_l,v); + printf("\troti\t%s, %s, %d\n",grn,crn_h,160-v); + printf("\tor\t%s, %s,%s\n",crn_l,crn_l,grn); + printf("\tshli\t%s, %s, %d\n",crn_h,crn_h,v); free_register(greg); return; case LUDIV: @@ -4726,10 +4795,10 @@ } greg = get_register(); grn = register_name(greg); - printf("\tmov\t%s, %s, lsl #%d\n",grn,crn_h,32-v); - printf("\tmov\t%s, %s, lsr #%d\n",crn_l,crn_l,v); - printf("\torr\t%s, %s,%s\n",crn_l,grn,crn_l); - printf("\tmov\t%s, %s, lsr #%d\n",crn_h,crn_h,v); + printf("\troti\t%s, %s, %d\n",grn,crn_h,96-v); + printf("\troti\t%s, %s, %d\n",crn_l,crn_l,v); + printf("\tor\t%s, %s,%s\n",crn_l,grn,crn_l); + printf("\troti\t%s, %s, %d\n",crn_h,crn_h,v); free_register(greg); return; case LADD: @@ -4741,16 +4810,16 @@ printf("\tsbc\t%s, %s, #%d\n",crn_h,crn_h,vh); break; case LBAND: - printf("\tand\t%s, %s, #%d\n",crn_l,crn_l,v); - printf("\tand\t%s, %s, #%d\n",crn_h,crn_h,vh); + printf("\tandi\t%s, %s, %d\n",crn_l,crn_l,v); + printf("\tandi\t%s, %s, %d\n",crn_h,crn_h,vh); break; case LEOR: printf("\teor\t%s, %s, #%d\n",crn_l,crn_l,v); printf("\teor\t%s, %s, #%d\n",crn_h,crn_h,vh); break; case LBOR: - printf("\torr\t%s, %s, #%d\n",crn_l,crn_l,v); - printf("\torr\t%s, %s, #%d\n",crn_h,crn_h,vh); + printf("\tori\t%s, %s, %d\n",crn_l,crn_l,v); + printf("\tori\t%s, %s, %d\n",crn_h,crn_h,vh); break; default: error(-1); @@ -4770,7 +4839,7 @@ crn_l = lregister_name_low(lreg); if (reg0!=(lreg)) printf("\tori\t%s, %s, 0\n",crn_l,crn); - printf("\tmov\t%s, %s, asr #31\n",crn_h,crn_l); + printf("\tshli\t%s, %s, 31\n",crn_h,crn_l); } void @@ -5104,13 +5173,13 @@ break; case 2: printf("\ttst\t%s, #1\n",trn); - printf("\tbne\t.L%d\n",dlabel); + printf("\tbr\t.L%d\n",dlabel); code_cmpdimm(max-min,t,dlabel,-1); printf("\tldrls\tpc, [pc, %s, asl #1]\n",trn); break; break; case 4: printf("\ttst\t%s, #3\n",trn); - printf("\tbne\t.L%d\n",dlabel); + printf("\tbr\t.L%d\n",dlabel); code_cmpdimm(max-min,t,dlabel,-1); printf("\tldrls\tpc, [pc, %s]\n",trn); break; break; @@ -5517,14 +5586,14 @@ { // printf("## mask 0x%08x ~0x%08x\n",mask,~mask); code_const(~mask,tmp); - printf("\torr\t%s, %s, %s\n",trn,crn,trn); + printf("\tor\t%s, %s, %s\n",trn,crn,trn); /* do conjunction */ printf("\tand\t%s, %s, %s\n",lrn,trn,lrn); /* make or-mask */ code_const(mask,tmp); printf("\tand\t%s, %s, %s\n",trn,crn,trn); /* do disjunction */ - printf("\torr\t%s, %s, %s\n",crn,trn,lrn); + printf("\tor\t%s, %s, %s\n",crn,trn,lrn); } extern void @@ -5649,7 +5718,7 @@ // printf("## mask 0x%08x ~0x%08x\n",mask,~mask); if ((m=(~mask|c))!=-1) { if (is_stage1_const(m,0)>0) { - printf("\tand\t%s, %s, #%d\n",crn,crn,m); + printf("\tandi\t%s, %s, %d\n",crn,crn,m); } else { trn = register_name(tmp=get_register()); code_const((~mask|c),tmp); @@ -5663,11 +5732,11 @@ if (c!=0) { /* do disjunction */ if (is_stage1_const(c,0)>0) { - printf("\torr\t%s, %s, #%d\n",crn,crn,c); + printf("\tori\t%s, %s, %d\n",crn,crn,c); } else { trn = register_name(tmp=get_register()); code_const(c,tmp); - printf("\torr\t%s, %s, %s\n",crn,trn,crn); + printf("\tor\t%s, %s, %s\n",crn,trn,crn); } } if (tmp!=-1) free_register(tmp);
--- a/mc-tree.c Fri May 25 19:28:25 2007 +0900 +++ b/mc-tree.c Sun Jul 29 23:09:38 2007 +0900 @@ -26,163 +26,196 @@ #include "mc-parse.h" #include "mc-codegen.h" +extern void tree_print(int e); +extern void tree_parse(int e); +extern void tree_print_t(int e,int t); +extern void type_print(int type,NMTBL *n,FILE *out); +extern void type_print1(int type,NMTBL *n,FILE *out,int cont); +extern void sym_print(int type,FILE *out); +static void print_function_call(int e, FILE *out); +static void print_operator(int e, FILE *vout); +static void print_statement(int e, FILE *vout); + +/* ascendant order for binary search */ + typedef struct tree_node { int tree_type; char *tree_name; char *tree_args; + int tree_order; } tree_node_type; -extern void tree_print(int e); -extern void tree_parse(int e); -extern void tree_print_t(int e,int t); -static tree_node_type * find_node(int e); -extern void type_print(int type,NMTBL *n,FILE *out); -extern void type_print1(int type,NMTBL *n,FILE *out,int cont); -extern void sym_print(int type,FILE *out); - -/* ascendant order for binary search */ - -static -tree_node_type tree_nodes[] = { - {DOTS,"...",""}, - {LMACRO,"lmacro",""}, - {FMACRO,"fmacro",""}, - {KONST,"const",""}, - {DEFINED,"defined",""}, - {ENVIRONMENT,"environment",""}, - {CODE,"code",""}, - {REGISTER,"register",""}, - {ASM,"__asm__",""}, - {VOID,"void",""}, - {EXTRN,"extern",""}, - {SHORT,"short",""}, - {USHORT,"unsigned short",""}, - {LONG,"long",""}, - {TYPE,"type",""}, - {VOLATILE,"volatile",""}, - {SIZEOF,"sizeof",""}, - {TYPEDEF,"typedef",""}, - {FLABEL,"flabel",""}, - {BLABEL,"blabel",""}, - {MACRO,"macro",""}, - {STRING,"string",""}, - {IDENT,"ident",""}, - {FIELD,"field",""}, - {TAG,"tag",""}, - {RESERVE,"reserve",""}, - {DEFAULT,"default",""}, - {ATTRIBUTE,"__attribute__",""}, - {CASE,"case",""}, - {SWITCH,"switch",""}, - {WHILE,"while",""}, - {DO,"do",""}, - {FOR,"for",""}, - {ELSE,"else",""}, - {IF,"if",""}, - {CONTINUE,"continue",""}, - {BREAK,"break",""}, - {RETURN,"return",""}, - {GOTO,"goto",""}, - {STATIC,"static",""}, - {EMPTY,"empty",""}, - {FUNCTION,"function","t"}, - {UNION,"union",""}, - {STRUCT,"struct","vt"}, - {ARRAY,"array","tv"}, - {POINTER,"*","t"}, - {UNSIGNED,"unsigned",""}, - {INLINE,"inline",""}, - {SIGNED,"signed",""}, - {CHAR,"char",""}, - {UCHAR,"unsigned char",""}, - {INT,"int",""}, - {FLOAT,"float",""}, - {DOUBLE,"double",""}, - {LONGLONG,"long long",""}, - {ULONGLONG,"unsigned long long",""}, +static int +tree_nodes(int id, char **name, char **args, int *order) { + int found = 1; + switch(id%SOP) { + case DOTS: *name = "..."; *args=""; *order=-1; break; + case LMACRO: *name = "lmacro"; *args=""; *order=-1; break; + case FMACRO: *name = "fmacro"; *args=""; *order=-1; break; + case KONST: *name = "const"; *args=""; *order=-1; break; + case DEFINED: *name = "defined"; *args=""; *order=14; break; + case ENVIRONMENT: *name = "environment"; *args=""; *order=14; break; + case CODE: *name = "code"; *args=""; *order=-1; break; + case C_FILE: *name = "__FILE__"; *args=""; *order=14; break; + case C_FUNCTION: *name = "__FUNCTION__"; *args=""; *order=14; break; + case C_LINE: *name = "__LINE__"; *args=""; *order=14; break; + case REGISTER: *name = "register"; *args=""; *order=-1; break; + case CAST: *name = "cast"; *args="e"; *order=14; break; + case ASM: *name = "__asm__"; *args="eeee"; *order=-1; break; + case ST_ASM: *name = "__asm__"; *args="eeee"; *order=-1; break; + case VOID: *name = "void"; *args=""; *order=-1; break; + case EXTRN: *name = "extern"; *args=""; *order=14; break; + case EXTRN1: *name = "extern"; *args=""; *order=14; break; + case SHORT: *name = "short"; *args=""; *order=-1; break; + case USHORT: *name = "unsigned short"; *args=""; *order=-1; break; + case LONG: *name = "long"; *args=""; *order=-1; break; + case TYPE: *name = "type"; *args=""; *order=-1; break; + case VOLATILE: *name = "volatile"; *args=""; *order=-1; break; + case SIZEOF: *name = "sizeof"; *args="e"; *order=13; break; + case TYPEDEF: *name = "typedef"; *args=""; *order=-1; break; + case FLABEL: *name = "flabel"; *args=""; *order=-1; break; + case BLABEL: *name = "blabel"; *args=""; *order=-1; break; + case LABEL: *name = "label"; *args="e"; *order=-1; break; + case ST_LABEL: *name = "label"; *args="e"; *order=-1; break; + case MACRO: *name = "macro"; *args=""; *order=-1; break; + case STRING: *name = "string"; *args=""; *order=14; break; + case IDENT: *name = "ident"; *args=""; *order=14; break; + case ENUM: *name = "enum"; *args=""; *order=14; break; + case FIELD: *name = "field"; *args=""; *order=-1; break; + case TAG: *name = "tag"; *args=""; *order=-1; break; + case RESERVE: *name = "reserve"; *args=""; *order=-1; break; + case ST_DEFAULT: *name = "default"; *args=""; *order=-1; break; + case ATTRIBUTE: *name = "__attribute__"; *args=""; *order=-1; break; + case ST_CASE: *name = "case"; *args=""; *order=-1; break; + case ST_SWITCH: *name = "switch"; *args=""; *order=-1; break; + case ST_WHILE: *name = "while"; *args=""; *order=-1; break; + case ST_DO: *name = "do"; *args=""; *order=-1; break; + case ST_FOR: *name = "for"; *args=""; *order=-1; break; + case ELSE: *name = "else"; *args=""; *order=-1; break; + case ST_IF: *name = "if"; *args=""; *order=-1; break; + case CONTINUE: *name = "continue"; *args=""; *order=-1; break; + case BREAK: *name = "break"; *args=""; *order=-1; break; + case ST_RETURN: *name = "return"; *args="e"; *order=-1; break; + case RETURN: *name = "return"; *args=""; *order=14; break; + case ST_GOTO: *name = "goto"; *args=""; *order=-1; break; + case JUMP: *name = "goto"; *args=""; *order=-1; break; + case STATIC: *name = "static"; *args=""; *order=14; break; + case EMPTY: *name = "empty"; *args=""; *order=-1; break; + case FUNCTION: *name = "function"; *args="t"; *order=15; break; + case UNION: *name = "union"; *args=""; *order=-1; break; + case STRUCT: *name = "struct"; *args="vt"; *order=-1; break; + case ARRAY: *name = "array"; *args="tv"; *order=16; break; + case POINTER: *name = "*"; *args="t"; *order=-1; break; + case UNSIGNED: *name = "unsigned"; *args=""; *order=-1; break; + case INLINE: *name = "inline"; *args=""; *order=-1; break; + case SIGNED: *name = "signed"; *args=""; *order=-1; break; + case CHAR: *name = "char"; *args=""; *order=-1; break; + case UCHAR: *name = "unsigned char"; *args=""; *order=-1; break; + case INT: *name = "int"; *args=""; *order=-1; break; + case FLOAT: *name = "float"; *args=""; *order=-1; break; + case DOUBLE: *name = "double"; *args=""; *order=-1; break; + case LONGLONG: *name = "long long"; *args=""; *order=-1; break; + case ULONGLONG: *name = "unsigned long long"; *args=""; *order=-1; break; - {GVAR,"gvar","vs"}, - {RGVAR,"rgvar","vs"}, - {CRGVAR,"crgvar","vs"}, - {LVAR,"lvar","v"}, - {RLVAR,"rlvar","v"}, - {CRLVAR,"crlvar","v"}, - {CONST,"const","v"}, - {FNAME,"fname","n"}, - {MUL,"*","e"}, - {RINDIRECT,"rindirect","e"}, - {CRINDIRECT,"crindirect","e"}, - {BAND,"&","e"}, - {MINUS,"-","e"}, - {LNOT,"!","e"}, - {BNOT,"~","e"}, - {INC,"++",""}, - {POSTINC,"postinc","e"}, - {PREINC,"preinc","e"}, - {CPOSTINC,"cpostinc","e"}, - {CPREINC,"cpreinc","e"}, - {DEC,"--",""}, - {DIV,"/","ee"}, - {UDIV,"/","ee"}, - {MUL,"*","ee"}, - {UMUL,"*","ee"}, - {MOD,"%","ee"}, - {UMOD,"%","ee"}, - {ADD,"+","ee"}, - {SUB,"-","ee"}, - {RSHIFT,">>","ee"}, - {URSHIFT,">>","ee"}, - {LSHIFT,"<<","ee"}, - {ULSHIFT,"<<","ee"}, - {GT,">","ee"}, - {UGT,">","ee"}, - {GE,">=","ee"}, - {UGE,">=","ee"}, - {LT,"<","ee"}, - {ULT,"<","ee"}, - {LE,"<=","ee"}, - {ULE,"<=","ee"}, - {EQ,"==","ee"}, - {NEQ,"!=","ee"}, - {BAND,"&","ee"}, - {EOR,"^","ee"}, - {BOR,"|","ee"}, - {LAND,"&&","ee"}, - {LOR,"||","ee"}, - {COND,"?","eee"}, - {ASS,"=","ee"}, - {ASSOP,"assop","eev"}, - {CASSOP,"cassop","eev"}, - {COMMA,",","ee"}, - {LPAR,"(",""}, - {RPAR,")",""}, - {LBRA,"[",""}, - {RBRA,"]",""}, - {LC,"{",""}, - {RC,"}",""}, - {COLON,":","ee"}, - {SM,";",""}, - {PERIOD,".",""}, - {ARROW,"->",""}, - {SASS,"sass",""}, - {RSTRUCT,"rstruct",""}, - {AS+MUL,"*=","ee"}, - {AS+UMUL,"*=","ee"}, - {AS+DIV,"/=","ee"}, - {AS+UDIV,"/=","ee"}, - {AS+MOD,"%=","ee"}, - {AS+UMOD,"%=","ee"}, - {AS+ADD,"+=","ee"}, - {AS+MINUS,"-=","ee"}, - {AS+RSHIFT,">>=","ee"}, - {AS+URSHIFT,">>=","ee"}, - {AS+LSHIFT,"<<=","ee"}, - {AS+ULSHIFT,"<<=","ee"}, - {AS+BAND,"&=","ee"}, - {AS+EOR,"^=","ee"}, - {AS+BOR,"|=","ee"}, -}; + case GVAR: *name = "gvar"; *args="vs"; *order=14; break; + case IVAR: *name = "ivar"; *args="vs"; *order=14; break; + case RGVAR: *name = "rgvar"; *args="vs"; *order=14; break; + case CRGVAR: *name = "crgvar"; *args="vs"; *order=14; break; + case LVAR: *name = "lvar"; *args="v"; *order=14; break; + case RLVAR: *name = "rlvar"; *args="v"; *order=14; break; + case CRLVAR: *name = "crlvar"; *args="v"; *order=14; break; + case CONST: *name = "const"; *args="v"; *order=14; break; + case FNAME: *name = "fname"; *args="n"; *order=14; break; + case MUL: *name = "*"; *args="e"; *order=-1; break; + case RINDIRECT: *name = "*"; *args="e"; *order=13; break; + case CRINDIRECT: *name = "*"; *args="e"; *order=13; break; + case ADDRESS: *name = "&"; *args="e"; *order=13; break; + case BAND: *name = "&"; *args="e"; *order=7; break; + case MINUS: *name = "-"; *args="e"; *order=13; break; + case LNOT: *name = "!"; *args="e"; *order=13; break; + case BNOT: *name = "~"; *args="e"; *order=13; break; + case INC: *name = "++"; *args=""; *order=13; break; + case ALLOCA: *name = "alloca"; *args="e"; *order=13; break; + case BUILTINP: *name = "__builtinp"; *args="e"; *order=13; break; + case BUILTIN_EXPECT: *name = "__builtin_expect"; *args="ee"; *order=13; break; + case BUILTIN_FABSF: *name = "__builtin_fabsf"; *args="e"; *order=13; break; + case BUILTIN_FABS: *name = "__builtin_fbas"; *args="e"; *order=13; break; + case BUILTIN_FABSL: *name = "__builtin_fbasl"; *args="e"; *order=13; break; + case BUILTIN_INFF: *name = "__builtin_inff"; *args=""; *order=13; break; + case BUILTIN_INF: *name = "__builtin_inf"; *args=""; *order=13; break; + case BUILTIN_INFL: *name = "__builtin_infl"; *args=""; *order=13; break; + case POSTINC: *name = "++"; *args="ee"; *order=13; break; + case BPOSTINC: *name = "++"; *args="ee"; *order=13; break; + case PREINC: *name = "++"; *args="ee"; *order=13; break; + case CPOSTINC: *name = "++"; *args="ee"; *order=13; break; + case CPREINC: *name = "++"; *args="ee"; *order=13; break; + case DEC: *name = "--"; *args="e"; *order=13; break; + case DIV: *name = "/"; *args="ee"; *order=12; break; + case UDIV: *name = "/"; *args="ee"; *order=12; break; + + case UMUL: *name = "*"; *args="ee"; *order=12; break; + case MOD: *name = "%"; *args="ee"; *order=12; break; + case UMOD: *name = "%"; *args="ee"; *order=12; break; + case ADD: *name = "+"; *args="ee"; *order=11; break; + case SUB: *name = "-"; *args="ee"; *order=11; break; + case RSHIFT: *name = ">>"; *args="ee"; *order=10; break; + case URSHIFT: *name = ">>"; *args="ee"; *order=10; break; + case LSHIFT: *name = "<<"; *args="ee"; *order=10; break; + case ULSHIFT: *name = "<<"; *args="ee"; *order=10; break; + case GT: *name = ">"; *args="ee"; *order=9; break; + case UGT: *name = ">"; *args="ee"; *order=9; break; + case GE: *name = ">="; *args="ee"; *order=9; break; + case UGE: *name = ">="; *args="ee"; *order=9; break; + case LT: *name = "<"; *args="ee"; *order=9; break; + case ULT: *name = "<"; *args="ee"; *order=9; break; + case LE: *name = "<="; *args="ee"; *order=9; break; + case ULE: *name = "<="; *args="ee"; *order=9; break; + case EQ: *name = "=="; *args="ee"; *order=8; break; + case NEQ: *name = "!="; *args="ee"; *order=8; break; + + case EOR: *name = "^"; *args="ee"; *order=6; break; + case BOR: *name = "|"; *args="ee"; *order=5; break; + case LAND: *name = "&&"; *args="ee"; *order=4; break; + case LOR: *name = "||"; *args="ee"; *order=-1; break; + case COND: *name = "?"; *args="eee"; *order=2; break; + case ASS: *name = "="; *args="ee"; *order=1; break; + case ASSOP: *name = "assop"; *args="eev"; *order=1; break; + case CASSOP: *name = "cassop"; *args="eev"; *order=1; break; + case COMMA: *name = "; *args=","ee"; *order=0; break; + case LPAR: *name = "("; *args=""; *order=-1; break; + case RPAR: *name = ")"; *args=""; *order=-1; break; + case LBRA: *name = "["; *args=""; *order=-1; break; + case RBRA: *name = "]"; *args=""; *order=-1; break; + case LC: *name = "{"; *args=""; *order=-1; break; + case RC: *name = "}"; *args=""; *order=-1; break; + case COLON: *name = ":"; *args="ee"; *order=-1; break; + case SM: *name = ";"; *args=""; *order=-1; break; + case PERIOD: *name = "."; *args=""; *order=16; break; + case ARROW: *name = "->"; *args=""; *order=16; break; + case SASS: *name = "sass"; *args=""; *order=-1; break; + case RSTRUCT: *name = "rstruct"; *args=""; *order=-1; break; + case AS+MUL: *name = "*="; *args="ee"; *order=1; break; + case AS+UMUL: *name = "*="; *args="ee"; *order=1; break; + case AS+DIV: *name = "/="; *args="ee"; *order=1; break; + case AS+UDIV: *name = "/="; *args="ee"; *order=1; break; + case AS+MOD: *name = "%="; *args="ee"; *order=1; break; + case AS+UMOD: *name = "%="; *args="ee"; *order=1; break; + case AS+ADD: *name = "+="; *args="ee"; *order=1; break; + case AS+MINUS: *name = "-="; *args="ee"; *order=1; break; + case AS+RSHIFT: *name = ">>="; *args="ee"; *order=1; break; + case AS+URSHIFT: *name = ">>="; *args="ee"; *order=1; break; + case AS+LSHIFT: *name = "<<="; *args="ee"; *order=1; break; + case AS+ULSHIFT: *name = "<<="; *args="ee"; *order=1; break; + case AS+BAND: *name = "&="; *args="ee"; *order=1; break; + case AS+EOR: *name = "^="; *args="ee"; *order=1; break; + case AS+BOR: *name = "|="; *args="ee"; *order=1; break; + default: found = 0; +fprintf(stderr,"Unknown ID %d [%d]in find node\n",id,OP(id)); + + } + return found; +} static int attr_print(int t) @@ -225,20 +258,20 @@ void tree_parse(int e) { - tree_node_type *t; + tree_node_type node_type,*t; int i,j; char *s; + t = &node_type; t->tree_type=e; + if(e<0) { - t=find_node(e); - if(t->tree_type==e) { + if (tree_nodes(e,&t->tree_name,&t->tree_args,&t->tree_order)) { for(j=0;j<tree_level;j++) putchar(' '); printf("list(%s)",t->tree_name); } } else { i = car(e); - t=find_node(e); - if(t->tree_type==i) { + if (tree_nodes(e,&t->tree_name,&t->tree_args,&t->tree_order)) { tree_level++; for(j=0;j<tree_level;j++) putchar(' '); printf("list(%s",t->tree_name); @@ -264,36 +297,6 @@ } } -tree_node_type * -find_node(int e) { - int e1,e2; - int first=0; - int last=sizeof(tree_nodes)/sizeof(tree_node_type); - // e2=-1; - e2=OP(e); - e1=0; - while (first!=last) { -#if 0 - e1 = (first+last)/2; - if(e2==e1) - return 0; - e2=e1; - if (tree_nodes[e1].tree_type>e) - last = e1; - else if (tree_nodes[e1].tree_type==e) - break; - else if (tree_nodes[e1].tree_type<e) - first = e1; -#else - if (tree_nodes[first].tree_type==e2) - return &tree_nodes[first]; - first++; -#endif - } -fprintf(stderr,"Unknown ID %d [%d]in find note\n",e2,e); - return &tree_nodes[e1]; -} - void struct_type_print(int type,FILE *out) { NMTBL *n; @@ -337,9 +340,9 @@ void sym_print(int sym,FILE *out) { - tree_node_type *tn; - if (!(tn=find_node(sym))) { error(-1); return; } - fprintf(out,"%s",tn->tree_name); + tree_node_type tn; + if (!(tree_nodes(sym,&tn.tree_name,&tn.tree_args,&tn.tree_order))) { error(-1); return; } + fprintf(out,"%s",tn.tree_name); } NMTBL * @@ -368,9 +371,10 @@ void type_print1(int type,NMTBL *n,FILE *out,int cont) { int t; - tree_node_type *tn; + tree_node_type *tn,tn0; NMTBL *td; int args; + tn = &tn0; if (n) { if (n->attr) n_attr_print(n->attr,out); @@ -385,11 +389,11 @@ fprintf(out,"%s ",td->nm); } else if (type<0) { t=type; - if (!(tn=find_node(t))) { error(-1); return; } + if (!(tree_nodes(t,&tn->tree_name,&tn->tree_args,&tn->tree_order))) { error(-1); return; } if (!cont) fprintf(out,"%s ",tn->tree_name); } else if ((t=car(type))) { - if (!(tn=find_node(t))) { error(-1); return; } + if (!(tree_nodes(t,&tn->tree_name,&tn->tree_args,&tn->tree_order))) { error(-1); return; } if(t==STRUCT||t==UNION) { if (!cont) { fprintf(out,"%s ",tn->tree_name); @@ -471,6 +475,9 @@ 罩c綣с篁≪眼冴筝... 茯帥篏ゅャ綽荀 + + 違cast 純<紊潟若紊c + cast */ void @@ -479,12 +486,14 @@ NMTBL *nptr,*n; if (e==0) { - fprintf(vout,"()"); + // can't happen in normal C language + fprintf(vout,"#"); return; } switch (car(e)%SOP) { case LVAR: case RLVAR: + case URLVAR: if ((nptr = (NMTBL*)caddr(e))) { fprintf(vout,"%s",nptr->nm); } else { @@ -494,6 +503,7 @@ break; case GVAR: case RGVAR: + case URGVAR: if ((nptr = (NMTBL*)caddr(e))) { fprintf(vout,"%s",nptr->nm); } else { @@ -576,6 +586,7 @@ break; case INDIRECT: case RINDIRECT: + case URINDIRECT: fprintf(vout,"*"); print_expr(cadr(e),vout); break; @@ -583,6 +594,10 @@ n = (NMTBL*)cadr(e); fprintf(vout,"%s",n->nm); break; + case FUNCTION: + print_function_call(e,vout); + break; +/* case ADD: fprintf(vout,"("); print_expr(cadr(e),vout); @@ -590,12 +605,151 @@ print_expr(caddr(e),vout); fprintf(vout,")"); break; + */ case RSTRUCT: print_expr(cadr(e),vout); break; default: - error(-1); + print_operator(e, vout); + } +} + +static void +print_expr_paren(int order,char *args,int e) +{ +} + +static void +print_operator(int e, FILE *vout) +{ + char *name; char *args; int order ; + if (tree_nodes(car(e), &name, &args, &order) ) { + if (order>0) { + int i = 0; + for(;*args;args++,i++) { + print_expr_paren(order,args,heap[e+i]); + } + } else { + print_statement(e, vout); + } } } +static void +print_decl(int e, FILE *vout) +{ + NMTBL *n = (NMTBL*)caddr(e); + int e1 = cadddr(e); + // int mode = car(e1); + int stmode = cadr(e1); + int ctmode = caddr(e1); + + if (n==&null_nptr) { + error(-1); // can't happen + return; + } + if (stmode==STATIC) { + fprintf(vout,"static ",nptr->nm); + } else if (stmode==EXTRN||stmode==EXTRN1) { + fprintf(vout,"extern ",nptr->nm); + } + type_print(n->ty,n,vout); + if (ctmode) { + fprintf(vout,"const ",nptr->nm); + } + fprintf(vout,"%s; ",nptr->nm); +} + +static void +print_statement(int e, FILE *vout) +{ + int e1; + NMTBL *n; + for (;e!=0; e = cadr(e)) { + switch (car(e)) { + case ST_DECL: + print_decl(e, vout); break; + case ST_IF: + fprintf(vout,"if "); break; + case ST_DO: + fprintf(vout,"do "); break; + case ST_WHILE: + fprintf(vout,"while "); break; + case ST_FOR: + fprintf(vout,"for "); break; + case ST_SWITCH: + fprintf(vout,"switch "); break; + case ST_COMP: + fprintf(vout,"{"); + fprintf(vout,"}"); + break; + case ST_BREAK: + fprintf(vout,"break; "); break; + case ST_CONTINUE: + fprintf(vout,"continue; "); break; + case ST_CASE: + for(e1 = caddr(e);e1;e1 = cadr(e1)) { + fprintf(vout,"case "); + fprintf(vout,"%d: ",car(e1)); + } + break; + case ST_DEFAULT: + fprintf(vout,"default: "); break; + case ST_RETURN: + fprintf(vout,"return "); + if (( e1 = caddr(e))) { + print_expr(e1,vout); + } + fprintf(vout,"; "); + break; + case ST_GOTO: + fprintf(vout,"goto "); break; + case ST_ASM: + fprintf(vout,"__asm__ "); break; + case ST_LABEL: + n = (NMTBL*)(caddr(caddr(e))); + fprintf(vout,"%s:", n->nm); break; + case ST_OP: + e1 = caddr(e); + print_expr(list3(cadr(e),car(e1),cadr(e1)),vout); + break; + case ST_COMMENT: + fprintf(vout,"\n# %s\n",(char*)caddr(e)); + break; + default: + fprintf(stderr,"Unknown Statement ID %d\n",car(e)); + } + } +} + +static void +print_function_call(int e1,FILE *vout) +{ + int e2,e3; + NMTBL *fn = 0; + + e2 = cadr(e1); + if (car(e2) == FNAME) { + fn=(NMTBL *)cadr(e2); + fprintf(vout,"%s",fn->nm); + } else { + if (car(e2)==INDIRECT) e2=cadr(e2); // (*func)(i) case + fprintf(vout,"("); + print_expr(e2,vout); + fprintf(vout,")"); + } + + fprintf(vout,"("); + for (e3 = e1 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) { + print_expr(car(e3),vout); + if (cadr(e3)) { + fprintf(vout,","); + } + } + fprintf(vout,")"); + reverse0(e1); // make it normal order + +} + + /* end */
--- a/mc.h Fri May 25 19:28:25 2007 +0900 +++ b/mc.h Sun Jul 29 23:09:38 2007 +0900 @@ -261,49 +261,50 @@ #define RBIT_FIELD 48 #define BPREINC 49 #define BPOSTINC 50 -#define CONV 51 +#define CAST 51 +#define CONV 52 #define UNARY_ARGS(i) (ADDRESS<=(i%SOP)&&(i%SOP)<=CONV) /* binary argments */ -#define MUL 52 -#define UMUL 53 -#define DIV 54 -#define UDIV 55 -#define MOD 56 -#define UMOD 57 -#define ADD 58 -#define SUB 59 -#define CMP 60 -#define RSHIFT 61 -#define URSHIFT 62 -#define LSHIFT 63 -#define ULSHIFT 64 -#define GT 65 -#define UGT 66 -#define GE 67 -#define UGE 68 -#define LT 69 -#define ULT 70 -#define LE 71 -#define ULE 72 -#define EQ 73 -#define NEQ 74 -#define BAND 75 -#define EOR 76 -#define BOR 77 -#define LAND 78 -#define LOR 79 -#define ASS 80 -#define UCMP 81 -#define UCMPGE 82 -#define CMPGE 83 -#define CMPEQ 84 -#define CMPNEQ 85 -#define ASSOP 86 -#define UASSOP 87 -#define COMMA 88 +#define MUL 53 +#define UMUL 54 +#define DIV 55 +#define UDIV 56 +#define MOD 57 +#define UMOD 58 +#define ADD 59 +#define SUB 60 +#define CMP 61 +#define RSHIFT 62 +#define URSHIFT 63 +#define LSHIFT 64 +#define ULSHIFT 65 +#define GT 66 +#define UGT 67 +#define GE 68 +#define UGE 69 +#define LT 70 +#define ULT 71 +#define LE 72 +#define ULE 73 +#define EQ 74 +#define NEQ 75 +#define BAND 76 +#define EOR 77 +#define BOR 78 +#define LAND 79 +#define LOR 80 +#define ASS 81 +#define UCMP 82 +#define UCMPGE 83 +#define CMPGE 84 +#define CMPEQ 85 +#define CMPNEQ 86 +#define ASSOP 87 +#define UASSOP 88 +#define COMMA 89 #define CASS (COP+ASS) #define CASSOP (COP+ASSOP) @@ -363,21 +364,21 @@ #define LEOR (LOP+EOR) #define LBOR (LOP+BOR) -#define BASS 89 -#define BASSOP 90 -#define BFD_REPL 91 +#define BASS 90 +#define BASSOP 91 +#define BFD_REPL 92 -#define JUMP 92 +#define JUMP 93 -#define STASS 93 +#define STASS 94 #define BINARY_ARGS(i) ((MUL<=(i%SOP)&&(i%SOP)<=STASS)||i==ARRAY) /* ternary argments */ -#define COND 94 -#define UCOND 95 +#define COND 95 +#define UCOND 96 #define SCOND (SOP+COND) #define SUCOND (SOP+UCOND) #define DCOND (DOP+COND) @@ -389,33 +390,33 @@ /* not appeared as tags */ -#define LPAR 96 -#define RPAR 97 -#define LBRA 98 -#define RBRA 99 -#define LC 100 -#define RC 101 -#define COLON 102 -#define SM 103 -#define CNAME 104 +#define LPAR 97 +#define RPAR 98 +#define LBRA 99 +#define RBRA 100 +#define LC 101 +#define RC 102 +#define COLON 103 +#define SM 104 +#define CNAME 105 -#define I2C 105 -#define I2S 106 -#define I2I 107 -#define I2U 108 -#define I2D 109 -#define I2F 110 -#define I2LL 111 -#define I2ULL 112 +#define I2C 106 +#define I2S 107 +#define I2I 108 +#define I2U 109 +#define I2D 110 +#define I2F 111 +#define I2LL 112 +#define I2ULL 113 -#define U2UC 113 -#define U2US 114 -#define U2I 115 -#define U2U 116 -#define U2D 117 -#define U2F 118 -#define U2LL 119 -#define U2ULL 120 +#define U2UC 114 +#define U2US 115 +#define U2I 116 +#define U2U 117 +#define U2D 118 +#define U2F 119 +#define U2LL 120 +#define U2ULL 121 #define D2I (DOP+I2I) @@ -450,27 +451,27 @@ /* statement start */ -#define ST_DECL 121 -#define ST_IF 122 -#define ST_DO 123 -#define ST_WHILE 124 -#define ST_FOR 125 -#define ST_SWITCH 126 -#define ST_COMP 127 -#define ST_BREAK 128 -#define ST_CONTINUE 129 -#define ST_CASE 130 -#define ST_DEFAULT 131 -#define ST_RETURN 132 -#define ST_GOTO 133 -#define ST_ASM 134 -#define ST_LABEL 135 -#define ST_OP 136 -#define ST_COMMENT 137 +#define ST_DECL 122 +#define ST_IF 123 +#define ST_DO 124 +#define ST_WHILE 125 +#define ST_FOR 126 +#define ST_SWITCH 127 +#define ST_COMP 128 +#define ST_BREAK 129 +#define ST_CONTINUE 130 +#define ST_CASE 131 +#define ST_DEFAULT 132 +#define ST_RETURN 133 +#define ST_GOTO 134 +#define ST_ASM 135 +#define ST_LABEL 136 +#define ST_OP 137 +#define ST_COMMENT 138 #define IS_STATEMENT(i) (i==INLINE||(ST_DECL<=i&&i<=ST_COMMENT)) -#define HAS_ADDRESS 138 +#define HAS_ADDRESS 139 /* statement end */ @@ -570,15 +571,9 @@ extern void print_expr(int e, FILE *vout); - #if 1 extern int heapsize; -#if 0 -int gdb(int a,int b,const char *c); -#define CHECK_HEAP(b) ({int _k=(int)(b);gdb(_k,__LINE__,__FUNCTION__);if(_k>heapsize||_k<=0)error(-1);_k;}) -#else #define CHECK_HEAP(b) ({int _k=(int)(b);if(_k>heapsize||_k<=0)error(-1);_k;}) -#endif #else #define CHECK_HEAP(b) (b) #endif