diff mc-code-ia32.c @ 165:6409ff6bc219 short-support-first

short
author kono
date Mon, 24 Nov 2003 10:42:03 +0900
parents fc8514c9d685
children 9e55cc5551fb
line wrap: on
line diff
--- 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;