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

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