changeset 167:0197ca125567

mips short
author kono
date Mon, 24 Nov 2003 13:47:21 +0900
parents 9e55cc5551fb
children b1297c82e926
files mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-codegen.c
diffstat 5 files changed, 76 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-ia32.c	Mon Nov 24 13:09:14 2003 +0900
+++ b/mc-code-ia32.c	Mon Nov 24 13:47:21 2003 +0900
@@ -771,14 +771,20 @@
 }
 
 void
-code_cmp_crgvar(int e1) {
-    printf("\tcmpb $0,%s\n",((NMTBL*)cadr(e1))->nm);
+code_cmp_crgvar(int e1,int sz) {
+    if (sz==1)
+	printf("\tcmpb $0,%s\n",((NMTBL*)cadr(e1))->nm);
+    else if (sz==size_of_short)
+	printf("\tcmpw $0,%s\n",((NMTBL*)cadr(e1))->nm);
 }
 
 
 void
-code_cmp_crlvar(int e1) {
-    printf("\tcmpb $0,%d(%%ebp)\n",lvar(e1));
+code_cmp_crlvar(int e1,int sz) {
+    if (sz==1)
+	printf("\tcmpb $0,%d(%%ebp)\n",lvar(e1));
+    else if (sz==size_of_short)
+	printf("\tcmpw $0,%d(%%ebp)\n",lvar(e1));
 }
 
 
--- a/mc-code-mips.c	Mon Nov 24 13:09:14 2003 +0900
+++ b/mc-code-mips.c	Mon Nov 24 13:47:21 2003 +0900
@@ -817,10 +817,10 @@
     printf("\tlw %s,%s\n",register_name(creg),((NMTBL*)cadr(e1))->nm);
     regv[creg]=1;
 }
-
+char *cload(int sign,int sz) { return sz==1?(sign?"lbu":"lb"):(sz==size_of_short?(sign?"lhu":"lh"):"lw");}
 void
-code_crgvar(int e1,int creg,int sign){
-    printf("\t%s %s,%s\n",sign?"lbu":"lb",register_name(creg),((NMTBL*)cadr(e1))->nm);
+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);
     regv[creg]=1;
 }
 
@@ -842,8 +842,8 @@
 
 
 void
-code_crlvar(int e2,int reg,int sign) {
-    printf("\t%s %s,",sign?"lbu":"lb",register_name(reg));
+code_crlvar(int e2,int reg,int sign,int sz) {
+    printf("\t%s %s,",cload(sign,sz),register_name(reg));
     lvar(e2);
     regv[reg]=1;
 }
@@ -940,11 +940,11 @@
 
 
 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("\t%s %s,0(%s)\n",sign?"lbu":"lb",register_name(reg),register_name(cadr(e2)));
+        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));
         regv[reg]=1;
@@ -957,7 +957,7 @@
     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",sign?"lbu":"lb",nrn,xrn);
+    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; 
@@ -968,13 +968,13 @@
 
 
 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("\taddu %s,%s,%d\n", 
             register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1));
-        printf("\t%s %s,0(%s)\n",sign?"lbu":"lb",register_name(reg),register_name(cadr(e2)));
+        printf("\t%s %s,0(%s)\n",cload(sign,sz),register_name(reg),register_name(cadr(e2)));
         regv[reg]=1;
         return;
     } 
@@ -986,7 +986,7 @@
     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",sign?"lbu":"lb",nrn,xrn);
+    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; 
     free_register(nreg);
@@ -996,13 +996,13 @@
 
 
 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("\t%s %s,0(%s)\n",sign?"lbu":"lb",crn,xrn);
+        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;
@@ -1014,7 +1014,7 @@
     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",sign?"lbu":"lb",nrn,xrn);
+    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; 
@@ -1025,14 +1025,14 @@
 
 
 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("\taddu %s,%s,%d\n",xrn,xrn,caddr(e1));
-        printf("\t%s %s,%d(%s)\n",sign?"lbu":"lb",crn,caddr(e1),xrn);
+        printf("\t%s %s,%d(%s)\n",cload(sign,sz),crn,caddr(e1),xrn);
         regv[reg]=1;
         return;
     } 
@@ -1044,7 +1044,7 @@
     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",sign?"lbu":"lb",nrn,caddr(e1),xrn);
+    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);
@@ -1117,17 +1117,17 @@
 }
 
 void
-code_cmp_crgvar(int e1) {
+code_cmp_crgvar(int e1,int sz) {
     if (cmpreg==-1) cmpreg = get_register();
-    code_crgvar(cadr(e1),cmpreg,0);
+    code_crgvar(cadr(e1),cmpreg,1,sz);
     regv[cmpreg]=1;
 }
 
 
 void
-code_cmp_crlvar(int e2) {
+code_cmp_crlvar(int e2,int sz) {
     if (cmpreg==-1) cmpreg = get_register();
-    code_crlvar(e2,cmpreg,0);
+    code_crlvar(e2,cmpreg,1,sz);
     regv[cmpreg]=1;
 }
 
@@ -1634,6 +1634,12 @@
     case CURINDIRECT: 
         printf("\tlbu %s,%d(%s)\n",crn,offset,crn);
         return UCHAR;
+    case SRINDIRECT: 
+        printf("\tlh %s,%d(%s)\n",crn,offset,crn);
+        return SHORT;
+    case SURINDIRECT: 
+        printf("\tlhu %s,%d(%s)\n",crn,offset,crn);
+        return USHORT;
     case RINDIRECT:
         printf("\tlw %s,%d(%s)\n",crn,offset,crn);
         return INT;
@@ -1647,8 +1653,10 @@
 
     name = ((NMTBL*)cadr(e2))->nm;
     crn=register_name(creg);
-    if (byte) {
+    if (byte==1) {
         printf("\tsb %s,%s\n",crn,name);
+    } if (byte==size_of_short) {
+        printf("\tsh %s,%s\n",crn,name);
     } else {
         printf("\tsw %s,%s\n",crn,name);
     }
@@ -1658,11 +1666,14 @@
 code_assign_lvar(int e2,int creg,int byte) {
     char *crn;
     crn=register_name(creg);
-    if (byte) {
-        printf("\tsb %s,",crn); lvar(e2);
+    if (byte==1) {
+        printf("\tsb %s,",crn);
+    } else if (byte==size_of_short) {
+        printf("\tsh %s,",crn);
     } else {
-        printf("\tsw %s,",crn); lvar(e2);
+        printf("\tsw %s,",crn); 
     }
+    lvar(e2);
 }
 
 void
@@ -1676,8 +1687,10 @@
     char *drn=register_name(e2);
     char *crn=register_name(creg);
 
-    if (byte) {
+    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);
     }
@@ -1711,8 +1724,10 @@
     tosop(op,xreg);
     crn = register_name(creg);
     drn = register_name(edx);
-    if (byte) {
+    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);
     }
@@ -1811,9 +1826,12 @@
 ld_indexx(int byte, int n, int xreg,int sign)
 {	
     char *crn = register_name(creg);
-    if (byte) {
+    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));
--- a/mc-code-powerpc.c	Mon Nov 24 13:09:14 2003 +0900
+++ b/mc-code-powerpc.c	Mon Nov 24 13:47:21 2003 +0900
@@ -1114,31 +1114,21 @@
 }
 
 void
-code_cmp_crgvar(int e1) {
+code_cmp_crgvar(int e1,int sz) {
     int r;
     char *crn = register_name(creg);
     r = get_ptr_cache((NMTBL*)cadr(e1));
-    printf("\tlbz %s,0(%s)\n",crn,register_name(r));
+    printf("\t%s %s,0(%s)\n",cload(sz),crn,register_name(r));
     printf("\tcmpwi cr0,%s,0\n",crn);
     regv[creg]=0;
 }
 
 
 void
-code_cmp_crlvar(int e2) {
+code_cmp_crlvar(int e2,int sz) {
     char *crn = register_name(creg);
     lvar_intro(e2);
-    printf("\tlbz %s,",crn);
-    lvar(e2);
-    code_cmp_register(creg);
-    regv[creg]=0;
-}
-
-void
-code_cmp_srlvar(int e2) {
-    char *crn = register_name(creg);
-    lvar_intro(e2);
-    printf("\tlhz %s,",crn);
+    printf("\t%s %s,",cload(sz),crn);
     lvar(e2);
     code_cmp_register(creg);
     regv[creg]=0;
--- a/mc-code.h	Mon Nov 24 13:09:14 2003 +0900
+++ b/mc-code.h	Mon Nov 24 13:47:21 2003 +0900
@@ -63,8 +63,8 @@
 extern char *code_ge(int cond);
 extern char *code_uge(int cond);
 extern char *code_eq(int cond);
-extern void code_cmp_crgvar(int e1);
-extern void code_cmp_crlvar(int e1);
+extern void code_cmp_crgvar(int e1,int sz);
+extern void code_cmp_crlvar(int e1,int sz);
 extern void code_cmp_rgvar(int e1);
 extern void code_cmp_rlvar(int e1);
 extern void code_cmp_register(int e2);
--- a/mc-codegen.c	Mon Nov 24 13:09:14 2003 +0900
+++ b/mc-codegen.c	Mon Nov 24 13:47:21 2003 +0900
@@ -526,14 +526,24 @@
 	b_expr(caddr(e1),cond,l1,0);
 	if(!cond) fwddef(l2);
 	return;
-    case CRGVAR:
+    case CRGVAR: case CURGVAR:
 	creg=use_int(creg);
-	code_cmp_crgvar(e1);
+	code_cmp_crgvar(e1,1);
 	jcond(l1,cond);
 	return;
-    case CRLVAR:
+    case SRGVAR: case SURGVAR:
+	creg=use_int(creg);
+	code_cmp_crgvar(e1,size_of_short);
+	jcond(l1,cond);
+	return;
+    case CRLVAR: case CURLVAR:
 	creg=use_int(creg);
-	code_cmp_crlvar(e2);
+	code_cmp_crlvar(e2,1);
+	jcond(l1,cond);
+	return;
+    case SRLVAR: case SURLVAR:
+	creg=use_int(creg);
+	code_cmp_crlvar(e2,size_of_short);
 	jcond(l1,cond);
 	return;
     case RGVAR: