diff mc-codegen.c @ 353:41ed77cb9c67 nametbl-done

name table reogranization, extendable cheap done.
author kono
date Sat, 03 Jul 2004 13:53:37 +0900
parents 43099915f4c2
children 6188f66c0c0b
line wrap: on
line diff
--- a/mc-codegen.c	Sat Jul 03 02:13:11 2004 +0900
+++ b/mc-codegen.c	Sat Jul 03 13:53:37 2004 +0900
@@ -294,6 +294,10 @@
     case CONV: 
 	g_expr0(e2); 
 	switch(caddr(e1)) {
+	case I2C: code_i2c(USE_CREG); return INT;
+	case I2S: code_i2s(USE_CREG); return INT;
+	case U2UC: code_u2uc(USE_CREG); return UNSIGNED;
+	case U2US: code_u2us(USE_CREG); return UNSIGNED;
 #if FLOAT_CODE
 	case I2D: code_i2d(USE_CREG); return DOUBLE;
 	case D2I: code_d2i(USE_CREG); return INT;
@@ -1718,6 +1722,24 @@
 }
 
 static int
+char_value(int e2)
+{
+    if (type!=CHAR) { 
+	e2 = list3(CONV,int_value(rvalue(e2)),I2C); type = INT; 
+    }
+    return e2;
+}
+
+static int
+short_value(int e2)
+{
+    if (type!=SHORT) { 
+	e2 = list3(CONV,int_value(rvalue(e2)),I2S); type = INT; 
+    }
+    return e2;
+}
+
+static int
 unsigned_value(int e2)
 {
     if (type>0&&car(type)==BIT_FIELD) e2=rvalue(e2);
@@ -1744,6 +1766,24 @@
     return e2;
 }
 
+static int
+uchar_value(int e2)
+{
+    if (type!=UCHAR) { 
+	e2 = list3(CONV,unsigned_value(rvalue(e2)),U2UC); type = UNSIGNED; 
+    }
+    return e2;
+}
+
+static int
+ushort_value(int e2)
+{
+    if (type!=USHORT) { 
+	e2 = list3(CONV,unsigned_value(rvalue(e2)),U2US); type = UNSIGNED; 
+    }
+    return e2;
+}
+
 /* assign statement */
 
 /* keep type */
@@ -2600,6 +2640,7 @@
     emit_data_closing(n);
 }
 
+#define ARG_REORDER_DEBUG 0
 
 extern int
 arg_reorder(int arg,int new_arg)
@@ -2609,14 +2650,15 @@
     int dsp = 0;
     NMTBL *n,*n1;
 
-    /* f(a,b,c) { int c; short a; char* b;} case */
-
-// fprintf(stderr,"arg_reorder old:\n");
-//    for(j=new_arg;j;j=cadr(j)) {
-//	    n=(NMTBL *)caddr(j);
-// fprintf(stderr,"dsp %d %s sz %d type %d\n",n->dsp,n->nm,cadddr(j),car(j));
-//    }
-// fprintf(stderr,"arg_reorder new:\n");
+    /* f(a,b,c)  int c; short a; char* b; { } case */
+#if ARG_REORDER_DEBUG
+ fprintf(stderr,"arg_reorder old:\n");
+    for(j=new_arg;j;j=cadr(j)) {
+	    n=(NMTBL *)caddr(j);
+ fprintf(stderr,"dsp %d %s sz %d type %d\n",n->dsp,n->nm,cadddr(j),car(j));
+    }
+ fprintf(stderr,"arg_reorder new:\n");
+#endif
     for(j=arg;j;j=cadr(j)) {
 	n=(NMTBL *)caddr(j);
 	for(i=new_arg;i;i=cadr(i)) {
@@ -2624,21 +2666,29 @@
 	    if (!neqname(n1->nm,n->nm)) break;
 	    // if (n1==n) break;
 	}
-// fprintf(stderr,"dsp %d %s %s sz %d type %d\n",dsp,n->nm,n1->nm,cadddr(i),car(i));
+#if ARG_REORDER_DEBUG
+ fprintf(stderr,"dsp %d %s %s sz %d type %d\n",dsp,n->nm,n1->nm,cadddr(i),car(i));
+#endif
 	if (!i) {
-	    /* f(a,b,c) { int c; } case (what?!) */
+	    /* f(a,b,c) int c; { } case (what?!) */
 	    i = j;
+	    n1 = n;
 	}
 	if(n->sc==LVAR) {
 	    n->dsp = dsp;
 	    car(j)=car(i);
 	    caddr(j)=caddr(i);
+	    n1->dsp = n->dsp;
+	    n->ty =  n1->ty;
+	    n->sc =  n1->sc;
 	    cadddr(j)=sz= cadddr(i);
 	    if (sz==1||sz==size_of_short) sz = size_of_int;
 	    dsp += sz;
 	}
     }
-// fprintf(stderr,"arg_reorder end:\n");
+#if ARG_REORDER_DEBUG
+ fprintf(stderr,"arg_reorder end:\n");
+#endif
     return arg;
 }
 
@@ -3155,7 +3205,7 @@
 binop(int op, int e1, int e2, int t1, int t2)
 {
     int e=0;
-    int us = (t1==UNSIGNED&&t2==UNSIGNED);
+    int us = 0;
 
     if(t1>0&&car(t1)==POINTER) { type = t2; e2= int_value(e2); t2=INT; }
     else if(t2>0&&car(t2)==POINTER) { type = t1; e1= int_value(e1); t1=INT; }
@@ -3169,6 +3219,13 @@
     else if(t1==LONGLONG||t2==LONGLONG||t1==ULONGLONG||t2==ULONGLONG)
 	return lbinop(op,e1,e2,t1,t2);
 #endif
+    if (t1==UNSIGNED) {
+	if (t2==UNSIGNED || (car(e2)==CONST && cadr(e2)>0)) us = 1;
+    }
+    if (t2==UNSIGNED) {
+	if (t1==UNSIGNED || (car(e1)==CONST && cadr(e1)>0)) us = 1;
+    }
+
     if(car(e1)==CONST&&car(e2)==CONST) {
 	e1=cadr(e1);
 	e2=cadr(e2);
@@ -3323,7 +3380,11 @@
     if (type==FLOAT && t==DOTS) { t=DOUBLE;}  // fall thru
     if (type==CHAR  && t==DOTS) { t=INT;}     // fall thru
     if (t==DOTS) return e;
-    if (t==UNSIGNED)                 e = unsigned_value(e);
+    else if (t==UNSIGNED)                 e = unsigned_value(e);
+    else if (t==CHAR)      { e =      char_value(e); t = INT; }
+    else if (t==UCHAR)     { e =     uchar_value(e); t = UNSIGNED; }
+    else if (t==SHORT)     { e =     short_value(e); t = INT; }
+    else if (t==USHORT)    { e =    ushort_value(e); t = UNSIGNED; }
     else if (integral(t))            e = int_value(e);
 #if FLOAT_CODE
     else if (t==FLOAT)     e = float_value(e);