Mercurial > hg > CbC > old > device
changeset 168:b1297c82e926 cpost-removal
cpostinc removal
author | kono |
---|---|
date | Mon, 24 Nov 2003 19:14:45 +0900 |
parents | 0197ca125567 |
children | b2a480be3c85 |
files | Changes mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-codegen.c mc-parse.c mc.h |
diffstat | 8 files changed, 201 insertions(+), 559 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Mon Nov 24 13:47:21 2003 +0900 +++ b/Changes Mon Nov 24 19:14:45 2003 +0900 @@ -3509,3 +3509,8 @@ typedef struct { char a[4]; } long long みたいな感じ? それはできないが、コンパイラ内部ではそうするという 手もある。 + +Mon Nov 24 18:59:30 JST 2003 + +うーん、こんなエラー残っているのか。code_cpostint とか +はぜんぜん使われないわけ?
--- a/mc-code-ia32.c Mon Nov 24 13:47:21 2003 +0900 +++ b/mc-code-ia32.c Mon Nov 24 19:14:45 2003 +0900 @@ -191,7 +191,7 @@ } else if (byte==size_of_short && rname[i] <= REG_EDX) { return reg_name_w[rname[i]]; } else { - return reg_name[rname[i]]; /* should be error */ + return reg_name[rname[i]]; /* 0 or 4 means int */ } } @@ -617,105 +617,39 @@ } void -code_preinc(int e1,int e2,int reg) { +code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) { char *xrn; if (car(e2)==REGISTER) { - printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0)); + printf("\taddl $%d,%s\n",dir,register_name(cadr(e2),0)); printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0)); regv[reg]=1; return; } g_expr(e2); xrn = register_name(creg,0); - printf("\taddl $%d,(%s)\n",caddr(e1),xrn); - printf("\tmovl (%s),%s\n",xrn,xrn); + printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==size_of_short)?"addw":"addl",dir,xrn); + printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(creg,0)); } void -code_postinc(int e1,int e2,int reg) { +code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) { char *xrn; if (car(e2)==REGISTER) { printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(reg,0)); - printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0)); + printf("\taddl $%d,%s\n",dir,register_name(cadr(e2),0)); regv[reg]=1; return; } g_expr(e2); emit_push(); xrn = register_name((e2=emit_pop(0)),0); - printf("\tmovl (%s),%s\n",xrn,register_name(creg,0)); - printf("\taddl $%d,(%s)\n",caddr(e1),xrn); - emit_pop_free(e2); -} - - -void -code_cpostinc(int e1,int e2,int reg,int sign,int sz) { - char *xrn; - if (car(e2)==REGISTER) { - printf("\t%s (%s),%s\n",cload(sign,sz),register_name(cadr(e2),0), - register_name(reg,0)); - printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0)); - regv[reg]=1; - return; - } - g_expr(e2); - emit_push(); - xrn = register_name((e2=emit_pop(0)),1); printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(creg,0)); - printf("\taddl $%d,(%s)\n",sz,xrn); + printf("\t%s $%d,(%s)\n",(sz==1)?"addb":(sz==size_of_short)?"addw":"addl",dir,xrn); emit_pop_free(e2); } -void -code_cpreinc(int e1,int e2,int reg,int sign,int sz) { - if (car(e2)==REGISTER) { - printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0)); - printf("\t%s (%s),%s\n",cload(sign,sz),register_name(cadr(e2),0), - register_name(reg,0)); - regv[reg]=1; - return; - } - g_expr(e2); - printf("\taddl $%d,(%s)\n",sz,register_name(creg,0)); - printf("\t%s (%s),%s\n",cload(sign,sz),register_name(creg,0),register_name(creg,0)); -} - - -void -code_cpostdec(int e1,int e2,int reg,int sign,int sz) { - if (car(e2)==REGISTER) { - printf("\t%s (%s),%s\n",cload(sign,sz),register_name(cadr(e2),0), - register_name(reg,0)); - printf("\tsubl $%d,(%s)\n",sz,register_name(cadr(e2),0)); - regv[reg]=1; - return; - } - g_expr(e2); - printf("\t%s (%s),%s\n",sign?"movsbl":"movzbl",register_name(creg,0),register_name(creg,0)); - printf("\tsubl $%d,(%s)\n",sz,register_name(creg,0)); -} - - -void -code_cpredec(int e1,int e2,int reg,int sign,int sz) { - if (car(e2)==REGISTER) { - printf("\tsubl $%d,(%s)\n",sz,register_name(cadr(e2),0)); - printf("\t%s (%s),%s\n",cload(sign,sz),register_name(cadr(e2),0), - register_name(reg,0)); - regv[reg]=1; - return; - } - g_expr(e2); - emit_push(); - e2 = emit_pop(0); - printf("\tsubl $%d,(%s)\n",sz,register_name(e2,0)); - printf("\t%s (%s),%s\n",cload(sign,sz),register_name(e2,0),register_name(creg,0)); - emit_pop_free(e2); -} - void code_return(int creg) { @@ -1566,15 +1500,15 @@ data_mode(0); } if(car(e)==CONST) { - if (t==CHAR) { + if (t==CHAR||t==UCHAR) { printf("\t.byte %d\n",cadr(e)); if (data_alignment>0) data_alignment++; gpc += 1; - } else if (t==SHORT) { - printf("\t.word %d\n",cadr(e)); + } else if (t==SHORT||t==USHORT) { + printf("\t.short %d\n",cadr(e)); if (data_alignment>0) data_alignment++; - gpc += 2; + gpc += size_of_short; } else { printf("\t.long %d\n",cadr(e)); gpc += size_of_int; @@ -1603,7 +1537,7 @@ } ascii((char *)cadr(e)); } else error(TYERR); - } + } else error(TYERR); } void
--- a/mc-code-mips.c Mon Nov 24 13:47:21 2003 +0900 +++ b/mc-code-mips.c Mon Nov 24 19:14:45 2003 +0900 @@ -818,6 +818,7 @@ regv[creg]=1; } char *cload(int sign,int sz) { return sz==1?(sign?"lbu":"lb"):(sz==size_of_short?(sign?"lhu":"lh"):"lw");} +char *cstore(int sz) { return sz==1?"sb":(sz==size_of_short)?"sh":"sw";} void code_crgvar(int e1,int creg,int sign,int sz){ printf("\t%s %s,%s\n",cload(sign,sz),register_name(creg),((NMTBL*)cadr(e1))->nm); @@ -888,12 +889,12 @@ } void -code_preinc(int e1,int e2,int reg) { +code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) { char *xrn,*drn; int i,dreg; if (car(e2)==REGISTER) { printf("\taddu %s,%s,%d\n", - register_name(cadr(e2)),register_name(cadr(e2)), caddr(e1)); + register_name(cadr(e2)),register_name(cadr(e2)), dir); if (cadr(reg)!=e2) printf("\tmove %s,%s\n",register_name(cadr(reg)),register_name(e2)); regv[reg]=1; @@ -903,9 +904,9 @@ xrn = register_name(creg); dreg=get_register(); if (!dreg) error(-1); drn = register_name(dreg); - printf("\tlw %s,0(%s)\n",drn,xrn); - printf("\taddu %s,%s,%d\n",drn,drn,caddr(e1)); - printf("\tsw %s,0(%s)\n",drn,xrn); + printf("\t%s %s,0(%s)\n",cload(sign,sz),drn,xrn); + printf("\taddu %s,%s,%d\n",drn,drn,dir); + printf("\t%s %s,0(%s)\n",cstore(sz),drn,xrn); i=creg;creg=dreg;dreg=i; regv[creg]=1; ireg=creg; free_register(dreg); @@ -913,40 +914,13 @@ void -code_postinc(int e1,int e2,int reg) { +code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) { char *xrn,*crn,*nrn; int dreg,nreg,i; if (car(e2)==REGISTER) { printf("\tmove %s,%s\n",register_name(reg),register_name(cadr(e2))); printf("\taddu %s,%s,%d\n", - register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1)); - regv[reg]=1; - return; - } - g_expr(e2); - crn = register_name(creg); - dreg=get_register(); if (!dreg) error(-1); - xrn = register_name(dreg); - nreg=get_register(); if (!nreg) error(-1); - nrn = register_name(nreg); - printf("\tlw %s,0(%s)\n",xrn,crn); - printf("\taddu %s,%s,%d\n",nrn,xrn,caddr(e1)); - printf("\tsw %s,0(%s)\n",nrn,crn); - i=creg;creg=dreg;dreg=i; - free_register(nreg); - free_register(dreg); - regv[creg]=1; ireg=creg; -} - - -void -code_cpostinc(int e1,int e2,int reg,int sign,int sz) { - char *xrn,*crn,*nrn; - int i,nreg,dreg; - if (car(e2)==REGISTER) { - printf("\t%s %s,0(%s)\n",cload(sign,sz),register_name(reg),register_name(cadr(e2))); - printf("\taddu %s,%s,%d\n", - register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1)); + register_name(cadr(e2)),register_name(cadr(e2)),dir); regv[reg]=1; return; } @@ -956,102 +930,16 @@ xrn = register_name(dreg); nreg=get_register(); if (!nreg) error(-1); nrn = register_name(nreg); - printf("\tlw %s,0(%s)\n",xrn,crn); - printf("\t%s %s,0(%s)\n",cload(sign,sz),nrn,xrn); - printf("\taddu %s,%s,%d\n", xrn,xrn,caddr(e1)); - printf("\tsw %s,0(%s)\n",xrn,crn); - i=creg;creg=nreg;nreg=i; - free_register(nreg); - free_register(dreg); - regv[creg]=1; ireg=creg; -} - - -void -code_cpreinc(int e1,int e2,int reg,int sign,int sz) { - char *xrn,*crn,*nrn; - int i,nreg,dreg; - if (car(e2)==REGISTER) { - printf("\taddu %s,%s,%d\n", - register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1)); - printf("\t%s %s,0(%s)\n",cload(sign,sz),register_name(reg),register_name(cadr(e2))); - regv[reg]=1; - return; - } - g_expr(e2); - crn = register_name(creg); - dreg=get_register(); if (!dreg) error(-1); - xrn = register_name(dreg); - nreg=get_register(); if (!nreg) error(-1); - nrn = register_name(nreg); - printf("\tlw %s,0(%s)\n",xrn,crn); - printf("\taddu %s,%s,%d\n", nrn,xrn,caddr(e1)); - printf("\t%s %s,0(%s)\n",cload(sign,sz),nrn,xrn); - printf("\tsw %s,0(%s)\n",xrn,crn); - i=creg;creg=nreg;nreg=i; + printf("\t%s %s,0(%s)\n",cload(sign,sz),xrn,crn); + printf("\taddu %s,%s,%d\n",nrn,xrn,dir); + printf("\t%s %s,0(%s)\n",cstore(sz),nrn,crn); + i=creg;creg=dreg;dreg=i; free_register(nreg); free_register(dreg); regv[creg]=1; ireg=creg; } -void -code_cpostdec(int e1,int e2,int reg,int sign,int sz) { - char *xrn,*crn,*nrn; - int i,nreg,dreg; - if (car(e2)==REGISTER) { - crn=register_name(reg); - xrn=register_name(cadr(e2)); - printf("\t%s %s,0(%s)\n",cload(sign,sz),crn,xrn); - printf("\taddu %s,%s,%d\n",xrn,xrn,caddr(e1)); - regv[reg]=1; - return; - } - g_expr(e2); - crn = register_name(creg); - dreg=get_register(); if (!dreg) error(-1); - xrn = register_name(dreg); - nreg=get_register(); if (!nreg) error(-1); - nrn = register_name(nreg); - printf("\tlw %s,0(%s)\n",xrn,crn); - printf("\t%s %s,0(%s)\n",cload(sign,sz),nrn,xrn); - printf("\taddu %s,%s,%d\n",xrn,xrn,caddr(e1)); - printf("\tsw %s,0(%s)\n",xrn,crn); - i=creg;creg=nreg;nreg=i; - free_register(nreg); - free_register(dreg); - regv[creg]=1; ireg=creg; -} - - -void -code_cpredec(int e1,int e2,int reg,int sign,int sz) { - char *xrn,*crn,*nrn; - int i,nreg,dreg; - if (car(e2)==REGISTER) { - crn=register_name(reg); - xrn=register_name(cadr(e2)); - printf("\taddu %s,%s,%d\n",xrn,xrn,caddr(e1)); - printf("\t%s %s,%d(%s)\n",cload(sign,sz),crn,caddr(e1),xrn); - regv[reg]=1; - return; - } - g_expr(e2); - crn = register_name(creg); - dreg=get_register(); if (!dreg) error(-1); - xrn = register_name(dreg); - nreg=get_register(); if (!nreg) error(-1); - nrn = register_name(nreg); - printf("\tlw %s,0(%s)\n",xrn,crn); - printf("\taddu %s,%s,%d\n",xrn,xrn,caddr(e1)); - printf("\t%s %s,%d(%s)\n",cload(sign,sz),nrn,caddr(e1),xrn); - printf("\tsw %s,0(%s)\n",xrn,crn); - i=creg;creg=nreg;nreg=i; - free_register(nreg); - free_register(dreg); - regv[creg]=1; ireg=creg; -} - void code_return(int creg) { @@ -1724,13 +1612,7 @@ tosop(op,xreg); crn = register_name(creg); drn = register_name(edx); - if (byte==1) { - printf("\tsb %s,0(%s)\n",crn,drn); - } else if (byte==size_of_short) { - printf("\tsh %s,0(%s)\n",crn,drn); - } else { - printf("\tsw %s,0(%s)\n",crn,drn); - } + printf("\t%s %s,0(%s)\n",cstore(byte),crn,drn); free_register(edx); emit_pop_free(xreg); regv[creg]=1; @@ -1826,15 +1708,8 @@ ld_indexx(int byte, int n, int xreg,int sign) { char *crn = register_name(creg); - if (byte==1) { - printf("\t%s %s,%d(%s)\n",sign?"lbu":"lb",crn,n, - register_name(xreg)); - } else if (byte==size_of_short) { - printf("\t%s %s,%d(%s)\n",sign?"lhu":"lh",crn,n, - register_name(xreg)); - } else - printf("\tlw %s,%d(%s)\n",crn,n, - register_name(xreg)); + printf("\t%s %s,%d(%s)\n",cload(sign,byte),crn,n, + register_name(xreg)); } int @@ -2203,13 +2078,13 @@ data_mode(0); } if(car(e)==CONST) { - if (t==CHAR) { + if (t==CHAR||t==UCHAR) { printf("\t.byte %d\n",cadr(e)); if (data_alignment>0) data_alignment++; gpc += 1; - } else if (t==SHORT) { - printf("\t.word %d\n",cadr(e)); + } else if (t==SHORT||t==USHORT) { + printf("\t.short %d\n",cadr(e)); if (data_alignment>0) data_alignment++; gpc += 2; } else { @@ -2240,7 +2115,7 @@ } ascii((char *)cadr(e)); } else error(TYERR); - } + } else error(TYERR); } void
--- a/mc-code-powerpc.c Mon Nov 24 13:47:21 2003 +0900 +++ b/mc-code-powerpc.c Mon Nov 24 19:14:45 2003 +0900 @@ -753,6 +753,10 @@ return r; } +static char *cload(int sz) { return sz==1?"lbz":sz==size_of_short?"lhz":"lwz"; } +static char *cstore(int sz) { return sz==1?"stb":sz==size_of_short?"sth":"stw"; } +static char *cext(int sz) { return sz==size_of_short?"extsh":"extsb"; } + void code_label(int labelno) { @@ -781,23 +785,15 @@ void code_crgvar(int e1,int creg,int sign,int sz){ char *crn = register_name(creg); - printf("\t%s %s,0(%s)\n",(sz==size_of_short?"lhz":"lbz"),crn, + printf("\t%s %s,0(%s)\n",cload(sz),crn, register_name(get_ptr_cache((NMTBL*)cadr(e1)))); if (sign) - printf("\t%s %s,%s\n",(sz==size_of_short?"extsh":"extsb"),crn,crn); + printf("\t%s %s,%s\n",cext(sz),crn,crn); regv[creg]=1; } - - - - - - - - void code_register(int e2,int creg) { if (creg!=e2) @@ -815,9 +811,6 @@ regv[creg]=1; } -static char *cload(int sz) { return sz==size_of_short?"lhz":"lbz"; } -static char *cext(int sz) { return sz==size_of_short?"extsh":"extsb"; } - void code_crlvar(int e2,int reg,int sign,int sz) { lvar_intro(e2); @@ -876,12 +869,12 @@ } void -code_preinc(int e1,int e2,int reg) { +code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) { char *xrn,*drn; int i,dreg; if (car(e2)==REGISTER) { printf("\taddi %s,%s,%d\n", - register_name(cadr(e2)),register_name(cadr(e2)), caddr(e1)); + register_name(cadr(e2)),register_name(cadr(e2)), dir); if (cadr(reg)!=e2) printf("\tmr %s,%s\n",register_name(cadr(reg)),register_name(e2)); regv[reg]=1; @@ -891,9 +884,11 @@ xrn = register_name(creg); dreg=get_register(); if (!dreg) error(-1); drn = register_name(dreg); - printf("\tlwz %s,0(%s)\n",drn,xrn); - printf("\taddi %s,%s,%d\n",drn,drn,caddr(e1)); - printf("\tstw %s,0(%s)\n",drn,xrn); + printf("\t%s %s,0(%s)\n",cload(sz),drn,xrn); + if (sign && sz!=size_of_int) + printf("\t%s %s,%s\n",cext(sz),drn,drn); + printf("\taddi %s,%s,%d\n",drn,drn,dir); + printf("\t%s %s,0(%s)\n",cstore(sz),drn,xrn); i=creg;creg=dreg;dreg=i; regv[creg]=1; ireg=creg; free_register(dreg); @@ -901,42 +896,13 @@ void -code_postinc(int e1,int e2,int reg) { +code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) { char *xrn,*crn,*nrn; int dreg,nreg,i; if (car(e2)==REGISTER) { printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); printf("\taddi %s,%s,%d\n", - register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1)); - regv[reg]=1; - return; - } - g_expr(e2); - crn = register_name(creg); - dreg=get_register(); if (!dreg) error(-1); - xrn = register_name(dreg); - nreg=get_register(); if (!nreg) error(-1); - nrn = register_name(nreg); - printf("\tlwz %s,0(%s)\n",xrn,crn); - printf("\taddi %s,%s,%d\n",nrn,xrn,caddr(e1)); - printf("\tstw %s,0(%s)\n",nrn,crn); - i=creg;creg=dreg;dreg=i; - free_register(nreg); - free_register(dreg); - regv[creg]=1; ireg=creg; -} - - -void -code_cpostinc(int e1,int e2,int reg,int sign,int sz) { - char *xrn,*crn,*nrn; - int i,nreg,dreg; - if (car(e2)==REGISTER) { - printf("\t%s %s,0(%s)\n",cload(sz),register_name(reg),register_name(cadr(e2))); - if (sign) - printf("\t%s %s,%s\n",cext(sz),register_name(reg),register_name(reg)); - printf("\taddi %s,%s,%d\n", - register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1)); + register_name(cadr(e2)),register_name(cadr(e2)),dir); regv[reg]=1; return; } @@ -946,107 +912,12 @@ xrn = register_name(dreg); nreg=get_register(); if (!nreg) error(-1); nrn = register_name(nreg); - printf("\tlwz %s,0(%s)\n",xrn,crn); - printf("\t%s %s,0(%s)\n",cload(sz),nrn,xrn); - if (sign) - printf("\t%s %s,%s\n",cext(sz),nrn,nrn); - printf("\taddi %s,%s,%d\n", xrn,xrn,sz); - printf("\tstw %s,0(%s)\n",xrn,crn); - i=creg;creg=nreg;nreg=i; - free_register(nreg); - free_register(dreg); - regv[creg]=1; ireg=creg; -} - -static char *cloadu(int sz) { return sz==size_of_short?"lhzu":"lbzu"; } - -void -code_cpreinc(int e1,int e2,int reg,int sign,int sz) { - char *xrn,*crn,*nrn; - int i,nreg,dreg; - if (car(e2)==REGISTER) { - printf("\t%s %s,%d(%s)\n",cloadu(sz),register_name(reg),caddr(e1),register_name(cadr(e2))); - if (sign) - printf("\t%s %s,%s\n",cext(sz),register_name(reg),register_name(reg)); - regv[reg]=1; - return; - } - g_expr(e2); - crn = register_name(creg); - dreg=get_register(); if (!dreg) error(-1); - xrn = register_name(dreg); - nreg=get_register(); if (!nreg) error(-1); - nrn = register_name(nreg); - printf("\tlwz %s,0(%s)\n",xrn,crn); - printf("\t%s %s,%d(%s)\n",cloadu(sz),nrn,caddr(e1),xrn); - printf("\tstw %s,0(%s)\n",xrn,crn); - if (sign) - printf("\t%s %s,%s\n",cext(sz),nrn,nrn); - i=creg;creg=nreg;nreg=i; - free_register(nreg); - free_register(dreg); - regv[creg]=1; ireg=creg; -} - - -void -code_cpostdec(int e1,int e2,int reg,int sign,int sz) { - char *xrn,*crn,*nrn; - int i,nreg,dreg; - if (car(e2)==REGISTER) { - crn=register_name(reg); - xrn=register_name(cadr(e2)); - printf("\t%s %s,0(%s)\n",cload(sz),crn,xrn); - printf("\taddi %s,%s,%d\n",xrn,xrn,caddr(e1)); - if (sign) - printf("\t%s %s,%s\n",cext(sz),crn,crn); - regv[reg]=1; - return; - } - g_expr(e2); - crn = register_name(creg); - dreg=get_register(); if (!dreg) error(-1); - xrn = register_name(dreg); - nreg=get_register(); if (!nreg) error(-1); - nrn = register_name(nreg); - printf("\tlwz %s,0(%s)\n",xrn,crn); - printf("\t%s %s,0(%s)\n",cload(sz),nrn,xrn); - printf("\taddi %s,%s,%d\n",xrn,xrn,-sz); - printf("\tstw %s,0(%s)\n",xrn,crn); - if (sign) - printf("\t%s %s,%s\n",cext(sz),nrn,nrn); - i=creg;creg=nreg;nreg=i; - free_register(nreg); - free_register(dreg); - regv[creg]=1; ireg=creg; -} - - -void -code_cpredec(int e1,int e2,int reg,int sign,int sz) { - char *xrn,*crn,*nrn; - int i,nreg,dreg; - if (car(e2)==REGISTER) { - crn=register_name(reg); - xrn=register_name(cadr(e2)); - printf("\t%s %s,%d(%s)\n",cloadu(sz),crn,caddr(e1),xrn); - if (sign) - printf("\t%s %s,%s\n",cext(sz),crn,crn); - regv[reg]=1; - return; - } - g_expr(e2); - crn = register_name(creg); - dreg=get_register(); if (!dreg) error(-1); - xrn = register_name(dreg); - nreg=get_register(); if (!nreg) error(-1); - nrn = register_name(nreg); - printf("\tlwz %s,0(%s)\n",xrn,crn); - printf("\t%s %s,%d(%s)\n",cloadu(sz),nrn,caddr(e1),xrn); - printf("\tstw %s,0(%s)\n",xrn,crn); - if (sign) - printf("\t%s %s,%s\n",cext(sz),nrn,nrn); - i=creg;creg=nreg;nreg=i; + printf("\t%s %s,0(%s)\n",cload(sz),xrn,crn); + if (sign && sz!=size_of_int) + printf("\t%s %s,%s\n",cext(sz),xrn,xrn); + printf("\taddi %s,%s,%d\n",nrn,xrn,dir); + printf("\t%s %s,0(%s)\n",cstore(sz),nrn,crn); + i=creg;creg=dreg;dreg=i; free_register(nreg); free_register(dreg); regv[creg]=1; ireg=creg; @@ -2137,15 +2008,15 @@ data_mode(0); } if(car(e)==CONST) { - if (t==CHAR) { + if (t==CHAR||t==UCHAR) { printf("\t.byte %d\n",cadr(e)); if (data_alignment>0) data_alignment++; gpc += 1; - } else if (t==SHORT) { - printf("\t.word %d\n",cadr(e)); + } else if (t==SHORT||t==USHORT) { + printf("\t.short %d\n",cadr(e)); if (data_alignment>0) data_alignment++; - gpc += 2; + gpc += size_of_short; } else { printf("\t.long %d\n",cadr(e)); gpc += size_of_int; @@ -2174,7 +2045,7 @@ } ascii((char *)cadr(e)); } else error(TYERR); - } + } else error(TYERR); } void
--- a/mc-code.h Mon Nov 24 13:47:21 2003 +0900 +++ b/mc-code.h Mon Nov 24 19:14:45 2003 +0900 @@ -49,12 +49,8 @@ extern void code_neg(int reg); extern void code_not(int reg); extern void code_lnot(int reg); -extern void code_preinc(int e1,int e2,int reg); -extern void code_postinc(int e1,int e2,int reg); -extern void code_cpostinc(int e1,int e2,int reg,int sign,int sz); -extern void code_cpreinc(int e1,int e2,int reg,int sign,int sz); -extern void code_cpostdec(int e1,int e2,int reg,int sign,int sz); -extern void code_cpredec(int e1,int e2,int reg,int sign,int sz); +extern void code_preinc(int e1,int e2,int dir,int sign,int sz,int reg); +extern void code_postinc(int e1,int e2,int dir,int sign,int sz,int reg); extern void code_return(int reg); extern void code_environment(int reg); extern void code_bool(int e1);
--- a/mc-codegen.c Mon Nov 24 13:47:21 2003 +0900 +++ b/mc-codegen.c Mon Nov 24 19:14:45 2003 +0900 @@ -231,11 +231,19 @@ return INT; case PREINC: creg=use_int(creg); - code_preinc(e1,e2,creg); + code_preinc(e1,e2,caddr(e1),1,cadddr(e1),creg); + return INT; + case UPREINC: + creg=use_int(creg); + code_preinc(e1,e2,caddr(e1),0,cadddr(e1),creg); return INT; case POSTINC: creg=use_int(creg); - code_postinc(e1,e2,creg); + code_postinc(e1,e2,caddr(e1),1,cadddr(e1),creg); + return INT; + case UPOSTINC: + creg=use_int(creg); + code_postinc(e1,e2,caddr(e1),0,cadddr(e1),creg); return INT; case DPREINC: /* ++d */ creg=use_double(creg); @@ -253,72 +261,6 @@ creg=use_float(creg); code_dpostinc(e1,e2,0,creg); return FLOAT; - case CPOSTINC: - /* char *p; *p++ */ - creg=use_int(creg); - code_cpostinc(e1,e2,creg,1,1); - return CHAR; - case CPREINC: - creg=use_int(creg); - code_cpreinc(e1,e2,creg,1,1); - return CHAR; - case CPOSTDEC: - creg=use_int(creg); - code_cpostdec(e1,e2,creg,1,1); - return CHAR; - case CPREDEC: - creg=use_int(creg); - code_cpredec(e1,e2,creg,1,1); - return CHAR; - case CUPOSTINC: - creg=use_int(creg); - code_cpostinc(e1,e2,creg,0,1); - return UCHAR; - case CUPREINC: - creg=use_int(creg); - code_cpreinc(e1,e2,creg,0,1); - return UCHAR; - case CUPOSTDEC: - creg=use_int(creg); - code_cpostdec(e1,e2,creg,0,1); - return UCHAR; - case CUPREDEC: - creg=use_int(creg); - code_cpredec(e1,e2,creg,0,1); - return UCHAR; - case SPOSTINC: - /* short *p; *p++ */ - creg=use_int(creg); - code_cpostinc(e1,e2,creg,1,size_of_short); - return CHAR; - case SPREINC: - creg=use_int(creg); - code_cpreinc(e1,e2,creg,1,size_of_short); - return SHORT; - case SPOSTDEC: - creg=use_int(creg); - code_cpostdec(e1,e2,creg,1,size_of_short); - return SHORT; - case SPREDEC: - creg=use_int(creg); - code_cpredec(e1,e2,creg,1,size_of_short); - return SHORT; - case SUPOSTINC: - creg=use_int(creg); - code_cpostinc(e1,e2,creg,0,size_of_short); - return USHORT; - case SUPREINC: - creg=use_int(creg); - code_cpreinc(e1,e2,creg,0,size_of_short); - return USHORT; - case SUPOSTDEC: - creg=use_int(creg); - code_cpostdec(e1,e2,creg,0,size_of_short); - return USHORT; - case SUPREDEC: - creg=use_int(creg); - code_cpredec(e1,e2,creg,0,size_of_short); - return USHORT; case MUL: case UMUL: case DIV: case UDIV: case MOD: case UMOD:
--- a/mc-parse.c Mon Nov 24 13:47:21 2003 +0900 +++ b/mc-parse.c Mon Nov 24 19:14:45 2003 +0900 @@ -95,6 +95,7 @@ static int struct_return = 0; static int sdecl_f = 1; static int stypedecl; +static int fields; static Converter *conv = &null_converter; /* Converter *conv = &c_converter; */ @@ -860,13 +861,11 @@ gpc +=sz; return n; case GSDECL: - nsc = FIELD; - ndsp = disp; + fields = list4(type,fields,(int)(n->nm),disp); disp += sz; break; case GUDECL: - nsc = FIELD; - ndsp = 0; + fields = list4(type,fields,(int)(n->nm),disp); if (disp < sz) disp = sz; break; case GTDECL: @@ -923,13 +922,11 @@ } return n; case LSDECL: - nsc = FIELD; - ndsp = disp; + fields = list4(type,fields,(int)(n->nm),disp); disp += sz; break; case LUDECL: - nsc = FIELD; - ndsp = 0; + fields = list4(type,fields,(int)(n->nm),disp); if (disp < sz) disp = sz; break; case LTDECL: @@ -1069,18 +1066,15 @@ return offset; /* not reached */ } -static int +static void sdecl_field() { - int fields = 0; while (getsym() != RC) { decl(); - fields = list4(type,fields,(int)(nptr->nm),nptr->dsp); - nptr->sc = nptr->ty = 0; nptr->nm = 0; } if (sdecl_f) conv->rc_(); getsym(); - return reverse0(fields); + fields = reverse0(fields); } #if 0 @@ -1098,8 +1092,9 @@ { int smode,sdisp,type0=0; NMTBL *nptr0,*gnptr0; - int fields; + int sfields = fields; + fields = 0; smode=mode; if (mode==GDECL || mode==GSDECL || mode==GUDECL || mode==GTDECL) mode=(s==STRUCT?GSDECL:GUDECL); @@ -1117,7 +1112,7 @@ if (nptr0->sc != EMPTY) error(DCERR); nptr0->sc = TAG; nptr0->ty = list4(s,-1,0,(int)nptr0); - fields = sdecl_field(); + sdecl_field(); heap[nptr0->ty+2]=fields; rplacad(type0 = nptr0->ty,disp); /* type0 = list4(s,disp,fields,0); now ... */ @@ -1133,7 +1128,7 @@ type0 = list4(s,disp,fields,(int)nptr0); } else if(sym==LC) { if (sdecl_f) conv->lc_(); - fields = sdecl_field(); + sdecl_field(); type0 = list4(s,disp,fields,0); } else error(DCERR); @@ -1142,6 +1137,7 @@ stypedecl=1; disp=sdisp; mode=smode; + fields = sfields; return type0; } @@ -2181,27 +2177,35 @@ static int expr13(void) { - int e,op; + int e,op,dir; switch (op = sym) { case INC: case DEC: conv->prefix_(sym); getsym(); lcheck(e=expr13()); + dir = op==INC?1:-1; if(type==CHAR) { - type= INT; - return(list2(op==INC?CPREINC:CPREDEC,e)); + type= INT; return(list4(PREINC,e,dir,1)); + } else if(type==UCHAR) { + type= UNSIGNED; return(list4(UPREINC,e,dir,1)); + } else if(type==SHORT) { + type= INT; return(list4(PREINC,e,dir,size_of_short)); + } else if(type==USHORT) { + type= UNSIGNED; return(list4(UPREINC,e,dir,size_of_short)); + } else if(type==INT) { + type= INT; return(list4(PREINC,e,dir,size_of_int)); } if(integral(type)) - return(list3(PREINC,e,op==INC?1:-1)); + return(list4(PREINC,e,dir,size_of_int)); if(type==FLOAT) - return(list3(FPREINC,e,op==INC?1:-1)); + return(list3(FPREINC,e,dir)); if(type==DOUBLE) - return(list3(DPREINC,e,op==INC?1:-1)); + return(list3(DPREINC,e,dir)); if(car(type)!=POINTER) error(TYERR); - return(list3(PREINC,e, - op==INC?size(cadr(type)):-size(cadr(type)) )); + return(list4(UPREINC,e, + op==INC?size(cadr(type)):-size(cadr(type)),size_of_int )); case MUL: /* *p */ conv->prefix_(sym); getsym(); @@ -2267,9 +2271,13 @@ e=expr0(); checksym(RPAR); expr16(e); - if(sym==INC||sym==DEC) { /* ??? */ + if(sym==INC||sym==DEC) { + /* after this operation, type is extended */ getsym(); if(type==CHAR) type=INT; + else if(type==SHORT) type=INT; + else if(type==UCHAR) type=UNSIGNED; + else if(type==USHORT) type=UNSIGNED; else if(!scalar(type)&&type!=FLOAT&&type!=DOUBLE) error(TYERR); } @@ -2285,20 +2293,29 @@ conv->postfix_(sym); lcheck(e); getsym(); + + dir = op==INC?1:-1; if(type==CHAR) { - type= INT; - return(list2(op==INC?CPOSTINC:CPOSTDEC,e)); + type= INT; return(list4(POSTINC,e,dir,1)); + } else if(type==UCHAR) { + type= UNSIGNED; return(list4(UPOSTINC,e,dir,1)); + } else if(type==SHORT) { + type= INT; return(list4(POSTINC,e,dir,size_of_short)); + } else if(type==USHORT) { + type= UNSIGNED; return(list4(UPOSTINC,e,dir,size_of_short)); + } else if(type==INT) { + type= INT; return(list4(POSTINC,e,dir,size_of_int)); } if(integral(type)) - return(list3(POSTINC,e,op==INC?1:-1)); + return(list4(POSTINC,e,dir,size_of_int)); if(type==FLOAT) - return(list3(FPOSTINC,e,op==INC?1:-1)); + return(list3(FPOSTINC,e,dir)); if(type==DOUBLE) - return(list3(DPOSTINC,e,op==INC?1:-1)); + return(list3(DPOSTINC,e,dir)); if(car(type)!=POINTER) error(TYERR); - return (list3(POSTINC,e, - op == INC ? size(cadr(type)): -size(cadr(type)) )); + return(list4(UPOSTINC,e, + op==INC?size(cadr(type)):-size(cadr(type)),size_of_int )); } return e; }
--- a/mc.h Mon Nov 24 13:47:21 2003 +0900 +++ b/mc.h Mon Nov 24 19:14:45 2003 +0900 @@ -141,16 +141,18 @@ #define BNOT 15 #define INC 16 #define POSTINC 17 -#define PREINC 18 -#define DEC 19 -#define CPOSTINC 20 -#define CPREINC 21 -#define CPOSTDEC 22 -#define CPREDEC 23 -#define CUPOSTINC 24 -#define CUPREINC 25 -#define CUPOSTDEC 26 -#define CUPREDEC 27 +#define UPOSTINC 18 +#define PREINC 19 +#define UPREINC 20 +#define DEC 21 +#define CPOSTINC 22 +#define CPREINC 23 +#define CPOSTDEC 24 +#define CPREDEC 25 +#define CUPOSTINC 26 +#define CUPREINC 27 +#define CUPOSTDEC 28 +#define CUPREDEC 29 #define SPOSTINC (SOP+CPOSTINC) #define SPREINC (SOP+CPREINC) #define SPOSTDEC (SOP+CPOSTDEC) @@ -167,58 +169,58 @@ #define LPREINC (LOP+CPREINC) #define LUPOSTINC (LOP+CUPOSTINC) #define LUPREINC (LOP+CUPREINC) -#define INDIRECT 28 -#define RINDIRECT 29 -#define CRINDIRECT 30 -#define CURINDIRECT 31 +#define INDIRECT 30 +#define RINDIRECT 31 +#define CRINDIRECT 32 +#define CURINDIRECT 33 #define SRINDIRECT (SOP+CRINDIRECT) #define SURINDIRECT (SOP+CURINDIRECT) #define FRINDIRECT (FOP+RINDIRECT) #define DRINDIRECT (DOP+RINDIRECT) #define LRINDIRECT (DOP+CRINDIRECT) -#define RSTRUCT 32 -#define CONV 33 +#define RSTRUCT 34 +#define CONV 35 #define UNARY_ARGS(i) (ADDRESS<=(i%SOP)&&(i%SOP)<=CONV) /* binary argments */ -#define MUL 34 -#define UMUL 35 -#define DIV 36 -#define UDIV 37 -#define MOD 38 -#define UMOD 39 -#define ADD 40 -#define SUB 41 -#define CMP 42 -#define RSHIFT 43 -#define URSHIFT 44 -#define LSHIFT 45 -#define ULSHIFT 46 -#define GT 47 -#define UGT 48 -#define GE 49 -#define UGE 50 -#define LT 51 -#define ULT 52 -#define LE 53 -#define ULE 54 -#define EQ 55 -#define NEQ 56 -#define BAND 57 -#define EOR 58 -#define BOR 59 -#define LAND 60 -#define LOR 61 -#define ASS 62 -#define CMPGE 63 -#define ASSOP 64 -#define COMMA 65 +#define MUL 36 +#define UMUL 37 +#define DIV 38 +#define UDIV 39 +#define MOD 40 +#define UMOD 41 +#define ADD 42 +#define SUB 43 +#define CMP 44 +#define RSHIFT 45 +#define URSHIFT 46 +#define LSHIFT 47 +#define ULSHIFT 48 +#define GT 49 +#define UGT 50 +#define GE 51 +#define UGE 52 +#define LT 53 +#define ULT 54 +#define LE 55 +#define ULE 56 +#define EQ 57 +#define NEQ 58 +#define BAND 59 +#define EOR 60 +#define BOR 61 +#define LAND 62 +#define LOR 63 +#define ASS 64 +#define CMPGE 65 +#define ASSOP 66 +#define COMMA 67 -#define CASS 66 -#define CASSOP 67 -#define CUASSOP 68 +#define CASS 68 +#define CASSOP 69 +#define CUASSOP 70 #define SASS (SOP+CASS) #define SASSOP (SOP+CASSOP) @@ -255,13 +257,13 @@ #define LADD (LOP+ADD) #define LSUB (LOP+SUB) -#define STASS 69 +#define STASS 71 #define BINARY_ARGS(i) (MUL<=(i%SOP)&&(i%SOP)<=STASS) /* tarnary argments */ -#define COND 70 +#define COND 72 #define SCOND (SOP+COND) #define DCOND (DOP+COND) #define FCOND (FOP+COND) @@ -271,28 +273,28 @@ /* not appeared as tags */ -#define I2D 71 -#define D2I 72 -#define U2D 73 -#define D2U 74 -#define F2D 75 -#define D2F 76 -#define I2F 77 -#define F2I 78 -#define U2F 79 -#define F2U 80 +#define I2D 73 +#define D2I 74 +#define U2D 75 +#define D2U 76 +#define F2D 77 +#define D2F 78 +#define I2F 79 +#define F2I 80 +#define U2F 81 +#define F2U 82 -#define LPAR 81 -#define RPAR 82 -#define LBRA 83 -#define RBRA 84 -#define LC 85 -#define RC 86 -#define COLON 87 -#define SM 88 -#define PERIOD 89 -#define ARROW 90 -#define CNAME 91 +#define LPAR 83 +#define RPAR 84 +#define LBRA 85 +#define RBRA 86 +#define LC 87 +#define RC 88 +#define COLON 89 +#define SM 90 +#define PERIOD 91 +#define ARROW 92 +#define CNAME 93 /* tree node tags end */ @@ -355,7 +357,7 @@ EXTERN FILE *obuf; -#if 0 +#if 1 typedef struct nametable { char *nm; int sc,ty,dsp; } NMTBL;