# HG changeset patch # User kono # Date 1069638123 -32400 # Node ID 6409ff6bc21929c8707f27df9c56f51a6003cdc2 # Parent 1c2a9232ea9342bee42a25fd2f980afc9b8eccfc short diff -r 1c2a9232ea93 -r 6409ff6bc219 mc-code-ia32.c --- a/mc-code-ia32.c Mon Nov 24 09:29:06 2003 +0900 +++ b/mc-code-ia32.c Mon Nov 24 10:42:03 2003 +0900 @@ -16,6 +16,7 @@ static int data_alignment = 0; int size_of_int = 4; +int size_of_short = 2; int size_of_float = 4; int size_of_double = 8; int size_of_longlong = 8; @@ -185,8 +186,10 @@ error(REG_ERR); return "%eax"; } - if (byte && rname[i] <= REG_EDX) { + if (byte==1 && rname[i] <= REG_EDX) { return reg_name_l[rname[i]]; + } 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 */ } @@ -540,10 +543,10 @@ printf("\tmovl %s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0)); regv[creg]=1; } - +static char *cload(int sign,int sz) { return sz==1?(sign?"movsbl":"movbl"):sz==size_of_short?(sign?"movswl":"movwl"):"movl"; } void -code_crgvar(int e1,int creg,int sign){ - printf("\t%s %s,%s\n",sign?"movsbl":"movbl", +code_crgvar(int e1,int creg,int sign,int sz){ + printf("\t%s %s,%s\n",cload(sign,sz), ((NMTBL*)cadr(e1))->nm,register_name(creg,0)); regv[creg]=1; } @@ -571,8 +574,8 @@ void -code_crlvar(int e2,int reg,int sign) { - printf("\t%s %d(%%ebp),%s\n",sign?"movsbl":"movbl",lvar(e2),register_name(reg,0)); +code_crlvar(int e2,int reg,int sign,int sz) { + printf("\t%s %d(%%ebp),%s\n",cload(sign,sz),lvar(e2),register_name(reg,0)); regv[creg]=1; } @@ -648,10 +651,10 @@ void -code_cpostinc(int e1,int e2,int reg,int sign) { +code_cpostinc(int e1,int e2,int reg,int sign,int sz) { char *xrn; if (car(e2)==REGISTER) { - printf("\t%s (%s),%s\n",sign?"movsbl":"movbl",register_name(cadr(e2),0), + 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; @@ -660,47 +663,47 @@ g_expr(e2); emit_push(); xrn = register_name((e2=emit_pop(0)),1); - printf("\t%s (%s),%s\n",sign?"movsbl":"movbl",xrn,register_name(creg,0)); - printf("\tincl (%s)\n",xrn); + printf("\t%s (%s),%s\n",cload(sign,sz),xrn,register_name(creg,0)); + printf("\taddl $%d,(%s)\n",sz,xrn); emit_pop_free(e2); } void -code_cpreinc(int e1,int e2,int reg,int sign) { +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",sign?"movsbl":"movbl",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("\tincl (%s)\n",register_name(creg,0)); - printf("\t%s (%s),%s\n",sign?"movsbl":"movbl",register_name(creg,0),register_name(creg,0)); + 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) { +code_cpostdec(int e1,int e2,int reg,int sign,int sz) { if (car(e2)==REGISTER) { - printf("\t%s (%s),%s\n",sign?"movsbl":"movbl",register_name(cadr(e2),0), + printf("\t%s (%s),%s\n",cload(sign,sz),register_name(cadr(e2),0), register_name(reg,0)); - printf("\tdecl %s\n",register_name(cadr(e2),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":"movbl",register_name(creg,0),register_name(creg,0)); - printf("\tdecl (%s)\n",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) { +code_cpredec(int e1,int e2,int reg,int sign,int sz) { if (car(e2)==REGISTER) { - printf("\tdecl %s\n",register_name(cadr(e2),0)); - printf("\t%s (%s),%s\n",sign?"movsbl":"movbl",register_name(cadr(e2),0), + 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; @@ -708,8 +711,8 @@ g_expr(e2); emit_push(); e2 = emit_pop(0); - printf("\tdecl (%s)\n",register_name(e2,0)); - printf("\t%s (%s),%s\n",sign?"movsbl":"movbl",register_name(e2,0),register_name(creg,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); } @@ -1107,6 +1110,10 @@ byte = 1; op="movsbl";t=CHAR; case CURINDIRECT: byte = 1; op="movbl";t=UCHAR; + case SRINDIRECT: + byte = 1; op="movswl";t=SHORT; + case SURINDIRECT: + byte = 1; op="movwl";t=USHORT; case RINDIRECT: default: byte = 0; op="movl";t=INT; } @@ -1117,7 +1124,7 @@ char * move(int byte) { - return byte?"movb":"movl"; + return byte==1?"movb":byte==size_of_short?"movw":"movl"; } void @@ -1167,7 +1174,7 @@ regv[edx]=1; ld_indexx(byte,0,edx,sign); tosop(op,xreg); - printf("\t%s %s,(%s)\n",byte ? "movb" : "movl",register_name(creg,byte),register_name(edx,0)); + printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte),register_name(edx,0)); edx_cleanup(); emit_pop_free(xreg); regv[creg]=1; diff -r 1c2a9232ea93 -r 6409ff6bc219 mc-code-powerpc.c --- a/mc-code-powerpc.c Mon Nov 24 09:29:06 2003 +0900 +++ b/mc-code-powerpc.c Mon Nov 24 10:42:03 2003 +0900 @@ -31,6 +31,7 @@ static int freg,ireg; int size_of_int = 4; +int size_of_short = 2; int size_of_float = 4; int size_of_double = 8; int size_of_longlong = 8; @@ -778,23 +779,23 @@ } void -code_crgvar(int e1,int creg,int sign){ +code_crgvar(int e1,int creg,int sign,int sz){ char *crn = register_name(creg); - printf("\tlbz %s,0(%s)\n",crn, + printf("\t%s %s,0(%s)\n",(sz==size_of_short?"lhz":"lbz"),crn, register_name(get_ptr_cache((NMTBL*)cadr(e1)))); if (sign) - printf("\textsb %s,%s\n",crn,crn); + printf("\t%s %s,%s\n",(sz==size_of_short?"extsh":"extsb"),crn,crn); regv[creg]=1; } -void -code_srgvar(int e1,int creg,int sign){ - char *crn = register_name(creg); - printf("\tlhz %s,0(%s)\n",crn, - register_name(get_ptr_cache((NMTBL*)cadr(e1)))); - printf("\textsh %s,%s\n",crn,crn); - regv[creg]=1; -} + + + + + + + + void @@ -814,26 +815,21 @@ 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) { +code_crlvar(int e2,int reg,int sign,int sz) { lvar_intro(e2); - printf("\tlbz %s,",register_name(reg)); + printf("\t%s %s,",cload(sz),register_name(reg)); lvar(e2); if (sign) - printf("\textsb %s,%s\n",register_name(reg),register_name(reg)); + printf("\t%s %s,%s\n",cext(sz),register_name(reg),register_name(reg)); regv[creg]=1; } -void -code_srlvar(int e2,int reg,int sign) { - lvar_intro(e2); - printf("\tlhz %s,",register_name(reg)); - lvar(e2); - if (sign) - printf("\textsh %s,%s\n",register_name(reg),register_name(reg)); - regv[creg]=1; -} + + void @@ -932,13 +928,13 @@ void -code_cpostinc(int e1,int e2,int reg,int sign) { +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("\tlbz %s,0(%s)\n",register_name(reg),register_name(cadr(e2))); + printf("\t%s %s,0(%s)\n",cload(sz),register_name(reg),register_name(cadr(e2))); if (sign) - printf("\textsb %s,%s\n",register_name(reg),register_name(reg)); + 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)); regv[reg]=1; @@ -951,10 +947,10 @@ nreg=get_register(); if (!nreg) error(-1); nrn = register_name(nreg); printf("\tlwz %s,0(%s)\n",xrn,crn); - printf("\tlbz %s,0(%s)\n",nrn,xrn); + printf("\t%s %s,0(%s)\n",cload(sz),nrn,xrn); if (sign) - printf("\textsb %s,%s\n",nrn,nrn); - printf("\taddi %s,%s,%d\n", xrn,xrn,caddr(e1)); + 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); @@ -962,15 +958,16 @@ 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) { +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("\tlbzu %s,%d(%s)\n",register_name(reg),caddr(e1),register_name(cadr(e2))); + printf("\t%s %s,%d(%s)\n",cloadu(sz),register_name(reg),caddr(e1),register_name(cadr(e2))); if (sign) - printf("\textsb %s,%s\n",register_name(reg),register_name(reg)); + printf("\t%s %s,%s\n",cext(sz),register_name(reg),register_name(reg)); regv[reg]=1; return; } @@ -981,10 +978,10 @@ nreg=get_register(); if (!nreg) error(-1); nrn = register_name(nreg); printf("\tlwz %s,0(%s)\n",xrn,crn); - printf("\tlbzu %s,%d(%s)\n",nrn,caddr(e1),xrn); + printf("\t%s %s,%d(%s)\n",cloadu(sz),nrn,caddr(e1),xrn); printf("\tstw %s,0(%s)\n",xrn,crn); if (sign) - printf("\textsb %s,%s\n",nrn,nrn); + printf("\t%s %s,%s\n",cext(sz),nrn,nrn); i=creg;creg=nreg;nreg=i; free_register(nreg); free_register(dreg); @@ -993,16 +990,16 @@ void -code_cpostdec(int e1,int e2,int reg,int sign) { +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("\tlbz %s,0(%s)\n",crn,xrn); + printf("\t%s %s,0(%s)\n",cload(sz),crn,xrn); printf("\taddi %s,%s,%d\n",xrn,xrn,caddr(e1)); if (sign) - printf("\textsb %s,%s\n",crn,crn); + printf("\t%s %s,%s\n",cext(sz),crn,crn); regv[reg]=1; return; } @@ -1013,11 +1010,11 @@ nreg=get_register(); if (!nreg) error(-1); nrn = register_name(nreg); printf("\tlwz %s,0(%s)\n",xrn,crn); - printf("\tlbz %s,0(%s)\n",nrn,xrn); - printf("\taddi %s,%s,%d\n",xrn,xrn,caddr(e1)); + 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("\textsb %s,%s\n",nrn,nrn); + printf("\t%s %s,%s\n",cext(sz),nrn,nrn); i=creg;creg=nreg;nreg=i; free_register(nreg); free_register(dreg); @@ -1026,15 +1023,15 @@ void -code_cpredec(int e1,int e2,int reg,int sign) { +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("\tlbzu %s,%d(%s)\n",crn,caddr(e1),xrn); + printf("\t%s %s,%d(%s)\n",cloadu(sz),crn,caddr(e1),xrn); if (sign) - printf("\textsb %s,%s\n",crn,crn); + printf("\t%s %s,%s\n",cext(sz),crn,crn); regv[reg]=1; return; } @@ -1045,10 +1042,10 @@ nreg=get_register(); if (!nreg) error(-1); nrn = register_name(nreg); printf("\tlwz %s,0(%s)\n",xrn,crn); - printf("\tlbzu %s,%d(%s)\n",nrn,caddr(e1),xrn); + printf("\t%s %s,%d(%s)\n",cloadu(sz),nrn,caddr(e1),xrn); printf("\tstw %s,0(%s)\n",xrn,crn); if (sign) - printf("\textsb %s,%s\n",nrn,nrn); + printf("\t%s %s,%s\n",cext(sz),nrn,nrn); i=creg;creg=nreg;nreg=i; free_register(nreg); free_register(dreg); @@ -1652,6 +1649,13 @@ case CURINDIRECT: printf("\tlbz %s,%d(%s)\n",crn,offset,crn); return UCHAR; + case SRINDIRECT: + printf("\tlhz %s,%d(%s)\n",crn,offset,crn); + printf("\textsh %s,%s\n",crn,crn); + return SHORT; + case SURINDIRECT: + printf("\tlhz %s,%d(%s)\n",crn,offset,crn); + return USHORT; case RINDIRECT: printf("\tlwz %s,%d(%s)\n",crn,offset,crn); return INT; @@ -1666,8 +1670,10 @@ r = get_ptr_cache((NMTBL*)cadr(e2)); rrn=register_name(r); crn=register_name(creg); - if (byte) { + if (byte==1) { printf("\tstb %s,0(%s)\n",crn,rrn); + } else if (byte==size_of_short) { + printf("\tsth %s,0(%s)\n",crn,rrn); } else { printf("\tstw %s,0(%s)\n",crn,rrn); } @@ -1678,11 +1684,14 @@ char *crn; crn=register_name(creg); lvar_intro(e2); - if (byte) { - printf("\tstb %s,",crn); lvar(e2); + if (byte==1) { + printf("\tstb %s,",crn); + } else if (byte==size_of_short) { + printf("\tsth %s,",crn); } else { - printf("\tstw %s,",crn); lvar(e2); + printf("\tstw %s,",crn); } + lvar(e2); } void @@ -1696,8 +1705,10 @@ char *drn=register_name(e2); char *crn=register_name(creg); - if (byte) { + if (byte==1) { printf("\tstb %s,0(%s)\n",crn,drn); + } else if (byte==size_of_short) { + printf("\tsth %s,0(%s)\n",crn,drn); } else { printf("\tstw %s,0(%s)\n",crn,drn); } @@ -1731,8 +1742,10 @@ tosop(op,xreg); crn = register_name(creg); drn = register_name(edx); - if (byte) { + if (byte==1) { printf("\tstb %s,0(%s)\n",crn,drn); + } else if (byte==size_of_short) { + printf("\tsth %s,0(%s)\n",crn,drn); } else { printf("\tstw %s,0(%s)\n",crn,drn); } @@ -1841,11 +1854,16 @@ ld_indexx(int byte, int n, int xreg,int sign) { char *crn = register_name(creg); - if (byte) { + if (byte==1) { printf("\tlbz %s,%d(%s)\n",register_name(creg),n, register_name(xreg)); if (sign) printf("\textsb %s,%s\n",crn,crn); + } else if (byte==size_of_short) { + printf("\tlhz %s,%d(%s)\n",register_name(creg),n, + register_name(xreg)); + if (sign) + printf("\textsh %s,%s\n",crn,crn); } else printf("\tlwz %s,%d(%s)\n",register_name(creg),n, register_name(xreg)); diff -r 1c2a9232ea93 -r 6409ff6bc219 mc-code.h --- a/mc-code.h Mon Nov 24 09:29:06 2003 +0900 +++ b/mc-code.h Mon Nov 24 10:42:03 2003 +0900 @@ -7,6 +7,7 @@ #define USING_REG 1 /* unreusable register usage */ extern int size_of_int; +extern int size_of_short; extern int size_of_float; extern int size_of_double; extern int size_of_longlong; @@ -38,11 +39,11 @@ extern void code_cmpdimm(int e, int csreg); extern void code_gvar(int e1,int reg); extern void code_rgvar(int e1,int reg); -extern void code_crgvar(int e1,int reg,int sign); +extern void code_crgvar(int e1,int reg,int sign,int sz); extern void code_lvar(int e2,int reg); extern void code_register(int e2,int reg); extern void code_rlvar(int e2,int reg); -extern void code_crlvar(int e2,int reg,int sign); +extern void code_crlvar(int e2,int reg,int sign,int sz); extern void code_fname(NMTBL *n,int reg); extern void code_const(int e2,int reg); extern void code_neg(int reg); @@ -50,10 +51,10 @@ 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); -extern void code_cpreinc(int e1,int e2,int reg,int sign); -extern void code_cpostdec(int e1,int e2,int reg,int sign); -extern void code_cpredec(int e1,int e2,int reg,int sign); +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_return(int reg); extern void code_environment(int reg); extern void code_bool(int e1); diff -r 1c2a9232ea93 -r 6409ff6bc219 mc-codegen.c --- a/mc-codegen.c Mon Nov 24 09:29:06 2003 +0900 +++ b/mc-codegen.c Mon Nov 24 10:42:03 2003 +0900 @@ -95,11 +95,19 @@ return INT; case CRGVAR: creg=use_int(creg); - code_crgvar(e1,creg,1); + code_crgvar(e1,creg,1,1); return CHAR; case CURGVAR: creg=use_int(creg); - code_crgvar(e1,creg,0); + code_crgvar(e1,creg,0,1); + return UCHAR; + case SRGVAR: + creg=use_int(creg); + code_crgvar(e1,creg,1,size_of_short); + return CHAR; + case SURGVAR: + creg=use_int(creg); + code_crgvar(e1,creg,0,size_of_short); return UCHAR; case LVAR: creg=use_int(creg); @@ -123,11 +131,19 @@ return INT; case CRLVAR: creg=use_int(creg); - code_crlvar(e2,creg,1); + code_crlvar(e2,creg,1,1); return CHAR; case CURLVAR: creg=use_int(creg); - code_crlvar(e2,creg,0); + code_crlvar(e2,creg,0,1); + return UCHAR; + case SRLVAR: + creg=use_int(creg); + code_crlvar(e2,creg,1,size_of_short); + return CHAR; + case SURLVAR: + creg=use_int(creg); + code_crlvar(e2,creg,0,size_of_short); return UCHAR; case FRLVAR: creg=use_float(creg); @@ -174,6 +190,7 @@ case INDIRECT: return g_expr0(e2); case RINDIRECT: case CRINDIRECT: case CURINDIRECT: + case SRINDIRECT: case SURINDIRECT: case DRINDIRECT: case FRINDIRECT: return rindirect(e1); case ADDRESS: @@ -239,36 +256,69 @@ case CPOSTINC: /* char *p; *p++ */ creg=use_int(creg); - code_cpostinc(e1,e2,creg,1); + code_cpostinc(e1,e2,creg,1,1); return CHAR; case CPREINC: creg=use_int(creg); - code_cpreinc(e1,e2,creg,1); + code_cpreinc(e1,e2,creg,1,1); return CHAR; case CPOSTDEC: creg=use_int(creg); - code_cpostdec(e1,e2,creg,1); + code_cpostdec(e1,e2,creg,1,1); return CHAR; case CPREDEC: creg=use_int(creg); - code_cpredec(e1,e2,creg,1); + code_cpredec(e1,e2,creg,1,1); return CHAR; case CUPOSTINC: creg=use_int(creg); - code_cpostinc(e1,e2,creg,0); + code_cpostinc(e1,e2,creg,0,1); return UCHAR; case CUPREINC: creg=use_int(creg); - code_cpreinc(e1,e2,creg,0); + code_cpreinc(e1,e2,creg,0,1); return UCHAR; case CUPOSTDEC: creg=use_int(creg); - code_cpostdec(e1,e2,creg,0); + code_cpostdec(e1,e2,creg,0,1); return UCHAR; case CUPREDEC: creg=use_int(creg); - code_cpredec(e1,e2,creg,0); + 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: @@ -308,7 +358,7 @@ case STASS: sassign(e1); return RSTRUCT; - case ASS: case CASS: + case ASS: case CASS: case SASS: assign(e1); return INT; case FASS: case DASS: case LASS: @@ -775,7 +825,8 @@ e1==CONST || e1==FNAME || e1==LVAR || e1==REGISTER ||e1==DREGISTER || e1==FREGISTER || e1==GVAR || e1==RGVAR || e1==RLVAR || e1==CRLVAR || e1==CRGVAR || - e1==DRLVAR || e1==FRLVAR + e1==DRLVAR || e1==FRLVAR || + e1==CURLVAR || e1==SURLVAR || e1==CURGVAR || e1==SURGVAR ); } @@ -786,9 +837,13 @@ int ce2=car(e2); return ( (ce1==LVAR && (ce2==RLVAR||ce2==CRLVAR||ce2==FRLVAR||ce2==DRLVAR)) + || (ce1==LVAR && (ce2==SRLVAR||ce2==SURLVAR||ce2==CURLVAR)) || (ce2==LVAR && (ce1==RLVAR||ce1==CRLVAR||ce1==FRLVAR||ce1==DRLVAR)) + || (ce2==LVAR && (ce1==SRLVAR||ce1==SURLVAR||ce1==CURLVAR)) || (ce1==GVAR && (ce2==RGVAR||ce2==CRGVAR||ce2==FRGVAR||ce2==DRGVAR)) + || (ce1==GVAR && (ce2==SRGVAR||ce2==SURGVAR||ce2==CURGVAR)) || (ce2==GVAR && (ce1==RGVAR||ce1==CRGVAR||ce1==FRGVAR||ce1==DRGVAR)) + || (ce2==GVAR && (ce1==SRGVAR||ce1==SURGVAR||ce1==CURGVAR)) ); } @@ -799,6 +854,7 @@ return ( ce1==LVAR ||ce1==RLVAR||ce1==CRLVAR || ce1==DRLVAR || ce1==GVAR ||ce1==RGVAR||ce1==CRGVAR || ce1==DRGVAR || + ce1==CURGVAR ||ce1==SURGVAR||ce1==SRGVAR || ce1==REGISTER|| ce1==DREGISTER || ce1==FREGISTER ); } @@ -1013,10 +1069,14 @@ reg = cadr(e2); switch(e5) { case CRGVAR: - case CURGVAR: code_crgvar(e4,reg,e5==CRGVAR); return; + case CURGVAR: code_crgvar(e4,reg,e5==CRGVAR,1); return; + case SRGVAR: + case SURGVAR: code_crgvar(e4,reg,e5==SRGVAR,size_of_short); return; case RGVAR: code_rgvar(e4,reg); return; case CRLVAR: - case CURLVAR: code_crlvar(cadr(e4),reg,e5==CRLVAR); return; + case CURLVAR: code_crlvar(cadr(e4),reg,e5==CRLVAR,1); return; + case SRLVAR: + case SURLVAR: code_crlvar(cadr(e4),reg,e5==SRLVAR,size_of_short); return; case RLVAR: code_rlvar(cadr(e4),reg); return; case GVAR: code_gvar(e4,reg); return; case LVAR: code_lvar(cadr(e4),reg); return; @@ -1036,7 +1096,7 @@ { int e2,e4,byte,e5; - byte=(car(e1) == CASS); + byte=(car(e1) == CASS)?1:(car(e1) == SASS)?size_of_int:0; /* e2=e4 */ e2 = cadr(e1); e4 = caddr(e1);e5=car(e4); @@ -1045,6 +1105,7 @@ (car(e2)==REGISTER&&( e5== CRGVAR || e5== CRLVAR || e5== RGVAR || e5== RLVAR || e5== CURGVAR || e5== CURLVAR || + e5== SURGVAR || e5== SURLVAR || e5== GVAR || e5== LVAR || e5== CONST || e5== FNAME || e5== STRING || (e5==ADDRESS&&car(cadr(e4))==STRING) || @@ -1166,15 +1227,19 @@ void assop(int e1) { - int e2,e3,byte,op,sign; + int e2,e3,byte,op,sign,size; /* e2 op= e3 */ if (car(e1) == CUASSOP) { - byte = 1; sign = 0; + byte = 1; sign = 0; size = 1; } else if (car(e1) == CASSOP) { - byte = 1; sign = 1; + byte = 1; sign = 1; size = 1; + } else if (car(e1) == SUASSOP) { + byte = size_of_short; sign = 0; size = size_of_short; + } else if (car(e1) == SASSOP) { + byte = size_of_short; sign = 1; size = size_of_short; } else { - byte = 0; sign = 1; + byte = 0; sign = 1; size = size_of_int; } e2 = cadr(e1); if (car(e2)==INDIRECT) e2=cadr(e2); diff -r 1c2a9232ea93 -r 6409ff6bc219 mc-parse.c --- a/mc-parse.c Mon Nov 24 09:29:06 2003 +0900 +++ b/mc-parse.c Mon Nov 24 10:42:03 2003 +0900 @@ -1328,7 +1328,7 @@ int integral(int t) { - return(t==INT||t==CHAR||t==UNSIGNED); + return(t==INT||t==CHAR||t==UNSIGNED||t==UCHAR||t==SHORT||t==USHORT); } static void @@ -1831,7 +1831,7 @@ assign_expr(int e1,int e2,int t,int type) { if(t==VOID) error(TYERR); - if(t==CHAR) { + if(t==CHAR||t==UCHAR) { e2=int_value(e2,type); if (!integral(type)) error(TYERR); type= INT;return(list3(CASS,e1,e2)); @@ -2464,61 +2464,42 @@ static int rvalue(int e) { - int t; - if(type==CHAR) { - type= INT; + int t,op; + if(type==CHAR||type==SHORT||type==LONGLONG) { + op = (type==SHORT?SOP:type==LONGLONG?LOP:0); + if(type!=LONGLONG) type= INT; switch(car(e)) { case GVAR: - return(list2(CRGVAR,cadr(e))); + return(list2(CRGVAR+op,cadr(e))); case LVAR: - return(list2(CRLVAR,cadr(e))); + return(list2(CRLVAR+op,cadr(e))); case INDIRECT: - return(list2(CRINDIRECT,cadr(e))); - default:return(e); - } - } - if(type==UCHAR) { - type= UNSIGNED; - switch(car(e)) { - case GVAR: - return(list2(CURGVAR,cadr(e))); - case LVAR: - return(list2(CURLVAR,cadr(e))); - case INDIRECT: - return(list2(CURINDIRECT,cadr(e))); + return(list2(CRINDIRECT+op,cadr(e))); default:return(e); } } - if(type==FLOAT) { + if(type==UCHAR||type==USHORT||type==ULONGLONG) { + op = (type==USHORT?SOP:type==ULONGLONG?LOP:0); + if(type!=LONGLONG) type= UNSIGNED; switch(car(e)) { case GVAR: - return(list2(FRGVAR,cadr(e))); + return(list2(CURGVAR+op,cadr(e))); case LVAR: - return(list2(FRLVAR,cadr(e))); + return(list2(CURLVAR+op,cadr(e))); case INDIRECT: - return(list2(FRINDIRECT,cadr(e))); + return(list2(CURINDIRECT+op,cadr(e))); default:return(e); } } - if(type==DOUBLE) { + if(type==FLOAT||type==DOUBLE) { + op = type==FLOAT?FOP:type==DOUBLE?DOP:0; switch(car(e)) { case GVAR: - return(list2(DRGVAR,cadr(e))); + return(list2(RGVAR+op,cadr(e))); case LVAR: - return(list2(DRLVAR,cadr(e))); + return(list2(RLVAR+op,cadr(e))); case INDIRECT: - return(list2(DRINDIRECT,cadr(e))); - default:return(e); - } - } - if(type==LONGLONG) { - switch(car(e)) { - case GVAR: - return(list2(LRGVAR,cadr(e))); - case LVAR: - return(list2(LRLVAR,cadr(e))); - case INDIRECT: - return(list2(LRINDIRECT,cadr(e))); + return(list2(RINDIRECT+op,cadr(e))); default:return(e); } } diff -r 1c2a9232ea93 -r 6409ff6bc219 mc.h --- a/mc.h Mon Nov 24 09:29:06 2003 +0900 +++ b/mc.h Mon Nov 24 10:42:03 2003 +0900 @@ -64,10 +64,8 @@ #define FLOAT (-48) #define DOUBLE (-49) -#define FREGISTER (-50) -#define DREGISTER (-51) -#define LONGLONG (-52) -#define ULONGLONG (-53) +#define LONGLONG (-50) +#define ULONGLONG (-51) /* reserved word end */ @@ -115,42 +113,44 @@ #define FRLVAR (FOP+RLVAR) #define DRGVAR (DOP+RGVAR) #define DRLVAR (DOP+RLVAR) -#define SRGVAR (SOP+RGVAR) -#define SRLVAR (SOP+RLVAR) +#define SRGVAR (SOP+CRGVAR) +#define SRLVAR (SOP+CRLVAR) #define SURGVAR (SOP+CURGVAR) #define SURLVAR (SOP+CURLVAR) -#define LRGVAR (LOP+RGVAR) -#define LRLVAR (LOP+RLVAR) +#define LRGVAR (LOP+CRGVAR) +#define LRLVAR (LOP+CRLVAR) #define LURGVAR (LOP+CURGVAR) #define LURLVAR (LOP+CURLVAR) +#define FREGISTER 9 +#define DREGISTER 10 -#define CONST 9 +#define CONST 11 #define DCONST (DOP+CONST) #define FCONST (FOP+CONST) #define LCONST (LOP+CONST) -#define STRING 10 -#define FNAME 11 +#define STRING 12 +#define FNAME 13 -#define NULLARY_ARGS(i) (GVAR<=(i%SOP)&&(i%SOP)<=FNAME) +#define NULLARY_ARGS(i) (i==REGISTER||(GVAR<=(i%SOP)&&(i%SOP)<=FNAME)) /* unary argments */ -#define ADDRESS 12 -#define MINUS 13 -#define LNOT 14 -#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 ADDRESS 14 +#define MINUS 15 +#define LNOT 16 +#define BNOT 17 +#define INC 18 +#define POSTINC 19 +#define PREINC 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) @@ -163,64 +163,64 @@ #define FPREINC (FOP+PREINC) #define DPOSTINC (DOP+POSTINC) #define DPREINC (DOP+PREINC) -#define LPOSTINC (LOP+POSTINC) -#define LPREINC (LOP+PREINC) +#define LPOSTINC (LOP+CPOSTINC) +#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+RINDIRECT) -#define RSTRUCT 32 -#define CONV 33 +#define LRINDIRECT (DOP+CRINDIRECT) +#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+ASS) +#define SASS (SOP+CASS) #define SASSOP (SOP+CASSOP) #define SUASSOP (SOP+CUASSOP) @@ -244,7 +244,7 @@ #define FADD (FOP+ADD) #define FSUB (FOP+SUB) -#define LASS (LOP+ASS) +#define LASS (LOP+CASS) #define LCMPGE (LOP+CMPGE) #define LASSOP (LOP+CASSOP) #define LUASSOP (LOP+CUASSOP) @@ -255,13 +255,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 +271,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 */