changeset 285:912b54949344

register assop const ( int/long )
author kono
date Tue, 01 Jun 2004 12:42:36 +0900
parents ec1a68133f6a
children 179e22f166ef
files Changes mc-code-mips.c mc-code-powerpc.c mc-codegen.c mc-parse.c test/tstdarg.c
diffstat 6 files changed, 295 insertions(+), 133 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Mon May 24 19:59:50 2004 +0900
+++ b/Changes	Tue Jun 01 12:42:36 2004 +0900
@@ -4553,3 +4553,40 @@
 leave で、control が必ず on になるのは何故?
 
 次は、やっぱり、c2cbc でしょう。
+
+(float) f == 1.0  で double に変換しているな。
+
+register oprtc が、
+        move $4,$20
+        addu $4,$4,16
+        move $20,$4
+とかなるのは悲しくない?
+
+Tue May 25 05:14:30 JST 2004
+
+indirect jump で、$25 に代入するんだけど、
+後ろに廻せば必ず simple になるから、そこでは
+$25 に直接代入できるね。move 一つ減るだけだけど。
+
+pcond は、pcond_const を持つべき。
+
+cmp/jcond は、一つで処理した方が良い。switch 文も bne $6,1,$L_11 
+とかできた方が良いよね。
+
+struct proto tcp_prot = {
+        .name           =       "TCP",
+        .close          =       tcp_close,
+        .connect        =       tcp_v4_connect,
+        .disconnect     =       tcp_disconnect,
+        .accept         =       tcp_accept,
+        .ioctl          =       tcp_ioctl,
+        .init           =       tcp_v4_init_sock,
+
+は、便利だよね。あった方がいいよな。(そんなに難しくないし)
+ただ、一旦全部リストにしないと格納できないか。混在した場合は
+どうなるんだろう? 文句言えばいいの?
+
+Mon May 31 19:08:57 JST 2004
+
+register_assop は、いいんだけど、register_assop_const の
+コードが良くないね。
--- a/mc-code-mips.c	Mon May 24 19:59:50 2004 +0900
+++ b/mc-code-mips.c	Tue Jun 01 12:42:36 2004 +0900
@@ -1968,13 +1968,13 @@
 static void
 code_call(int e2,NMTBL *fn,int jmp)
 {
-    char *jrn;
+    // char *jrn;
     if (fnptr->sc==CODE) {
 	if (car(e2) == FNAME) {
 	    printf("\tla\t$25,%s\n",fn->nm);
 	} else {
-	    jrn = register_name(cadr(jmp));
-	    printf("\tmove\t$25,%s\n",jrn);
+	    // jrn = register_name(cadr(jmp));
+	    // printf("\tmove\t$25,%s\n",jrn);
 	}
 	printf("\tjalr\t$25\n");
 	printf("\tlw\t$gp,$L_%d($sp)\n",cprestore_label);
@@ -1982,8 +1982,8 @@
 	if (car(e2) == FNAME) {
 	    printf("\tjal\t%s\n",fn->nm);
 	} else {
-	    jrn = register_name(cadr(jmp));
-	    printf("\tmove $25,%s\n",jrn);
+	    // jrn = register_name(cadr(jmp));
+	    // printf("\tmove $25,%s\n",jrn);
 	    printf("\tjal\t$31,$25\n");
 	}
     }
@@ -2016,17 +2016,19 @@
 	}
     }
 
+    arg_assign = 0;
     e2 = cadr(e1);
     if (car(e2) == FNAME) {	
 	fn=(NMTBL *)cadr(e2);
     } else {	
-	jmp = get_register_var(0);
-	if (car(jmp)!=REGISTER) error(-1);
-	reg_arg_list = list2(jmp,reg_arg_list);
-	g_expr(e2);
-	if (!is_int_reg(creg)) error(-1);
-	code_register(creg,cadr(jmp));
-        /* g_expr(assign_expr0(jmp,e2,INT,INT)); functions are lvalue */
+	if (car(e2)==INDIRECT) e2=cadr(e2); // (*func)(i) case
+	jmp = list2(REGISTER,25);
+	if (!simple_arg(e2)) {
+	    e3=get_register_var(0);
+	    g_expr_u(assign_expr0(e3,e2,INT,INT));
+	    e2=e3;
+	}
+	arg_assign = list2(assign_expr0(jmp,e2,INT,INT),arg_assign);
     }
     /* First we execute complex argument to avoid interaction with
        input variables. Remain the last complex argument in complex_. */
@@ -2100,7 +2102,7 @@
 	}
     }
 
-    nargs = reg_arg = freg_arg = arg_assign = 0;
+    nargs = reg_arg = freg_arg = 0;
     // calc stack arguments first, it may requires extra registers,
     // and we can still use input registers now.
     for (e3 = e1; e3; 
@@ -2433,6 +2435,22 @@
 
     use_int(creg);
     xrn = register_name(xreg = emit_pop(0));       /* pop e3 value */
+#if 1
+    set_ireg(edx,0);
+    ld_indexx(byte,0,creg,ireg,sign);
+    tosop(op,ireg,xreg);
+    crn = register_name(ireg);
+    drn = register_name(creg);
+    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);
+    }
+    free_register(edx);
+    emit_pop_free(xreg);
+#else
     printf("# assop\n\tmove %s,%s\n",register_name(edx),register_name(creg));
     ld_indexx(byte,0,edx,creg,sign);
     tosop(op,creg,xreg);
@@ -2447,6 +2465,7 @@
     }
     free_register(edx);
     emit_pop_free(xreg);
+#endif
 }
 
 
@@ -2694,6 +2713,8 @@
     if (!asi) error(-1);
 }
 
+// should have pcond_const
+
 static void
 pcond(int op, int r2,int r1,int r0,int cond,int l1)
 {
--- a/mc-code-powerpc.c	Mon May 24 19:59:50 2004 +0900
+++ b/mc-code-powerpc.c	Tue Jun 01 12:42:36 2004 +0900
@@ -1885,10 +1885,12 @@
 	}
     }
 
+    arg_assign = 0;
     e2 = cadr(e1);
     if (car(e2) == FNAME) {	
 	fn=(NMTBL *)cadr(e2);
     } else {	
+#if 0
 	jmp = get_register_var(0);
 	if (car(jmp)!=REGISTER) error(-1);
 	reg_arg_list = list2(jmp,reg_arg_list);
@@ -1896,6 +1898,16 @@
 	if (!is_int_reg(creg)) error(-1);
 	code_register(creg,cadr(jmp));
         /* g_expr(assign_expr0(jmp,e2,INT,INT)); functions are lvalue */
+#else
+        if (car(e2)==INDIRECT) e2=cadr(e2); // (*func)(i) case
+	jmp = get_register_var(0);
+	if (car(jmp)!=REGISTER) error(-1);
+	reg_arg_list = list2(jmp,reg_arg_list);
+        if (!simple_arg(e2)) {
+            g_expr_u(assign_expr0(jmp,e2,INT,INT));
+        } else
+	    arg_assign = list2(assign_expr0(jmp,e2,INT,INT),arg_assign);
+#endif
     }
     /* first we execute complex argument to avoid interaction with
        input variables */
@@ -1968,7 +1980,7 @@
 	}
     }
 
-    nargs = reg_arg = freg_arg = arg_assign = 0;
+    nargs = reg_arg = freg_arg = 0;
     // calc stack arguments first, it may requires extra registers,
     // and we can still use input registers now.
     for (e3 = e1; e3; 
@@ -2295,6 +2307,22 @@
 
     use_int(creg);
     xrn = register_name(xreg = emit_pop(0));       /* pop e3 value */
+#if 1
+    set_ireg(edx,0);
+    ld_indexx(byte,0,creg,ireg,sign);
+    tosop(op,ireg,xreg);
+    crn = register_name(ireg);
+    drn = register_name(creg);
+    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);
+    }
+    free_register(creg);
+    emit_pop_free(xreg);
+#else
     printf("# assop\n\tmr %s,%s\n",register_name(edx),register_name(creg));
     ld_indexx(byte,0,edx,creg,sign);
     tosop(op,creg,xreg);
@@ -2309,6 +2337,7 @@
     }
     free_register(edx);
     emit_pop_free(xreg);
+#endif
 }
 
 void
@@ -4531,6 +4560,7 @@
     emit_push();
     use_longlong(reg);
     if (regv_l(lreg)==edx || regv_h(lreg)==edx) {
+	// this can't happen
 	edx0 = get_register(); if(!edx0) error(-1);
 	printf("# lassop\n\tmr %s,%s\n",register_name(edx0),register_name(edx));
 	edx = edx0;
--- a/mc-codegen.c	Mon May 24 19:59:50 2004 +0900
+++ b/mc-codegen.c	Tue Jun 01 12:42:36 2004 +0900
@@ -1469,10 +1469,23 @@
     e3 = caddr(e1);
     op = cadddr(e1);
 
+    if (car(e2)==REGISTER) {
+	if (code_const_op_p(op,e3)) {
+	    oprtc(op,cadr(e2),e3);
+	} else {
+	    g_expr(e3);
+	    code_register_assop(cadr(e2),USE_CREG,op,byte);
+	}
+	if (use) {
+	    code_register(cadr(e2),USE_CREG);
+	}
+	return;
+    }
     if (car(e3)==CONST) {
 	/*  e2 = e2 op e3; */
 	t = sign?INT:UNSIGNED;
-	if (car(e2)==REGISTER||car(e2)==LVAR||car(e2)==GVAR) {
+	// oprtc expected
+	if (car(e2)==LVAR||car(e2)==GVAR) {
 	    g_expr(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t));
 	    return;
 	}
@@ -1484,14 +1497,7 @@
 	free_lvar(cadr(n));
 	return;
     }
-
     g_expr(e3);
-    if (car(e2)==REGISTER) {
-	code_register_assop(cadr(e2),USE_CREG,op,byte);
-	if (use)
-	    code_register(cadr(e2),USE_CREG);
-	return;
-    }
     emit_push();
     g_expr(e2);
     code_assop(op,USE_CREG,byte,sign);
@@ -1548,10 +1554,23 @@
     e3 = caddr(e1);
     op = cadddr(e1);
 
+    if (code_lassop_p && car(e2)==LREGISTER) {
+        if (code_lconst_op_p(op,e3)) {
+            loprtc(op,cadr(e2),e3);
+        } else {
+            g_expr(e3);
+	    emit_lpush();
+            code_register_lassop(cadr(e2),op);
+        }
+        if (use) {
+            code_lregister(cadr(e2),USE_CREG);
+        }
+        return;
+    }
     if (!code_lassop_p||car(e3)==LCONST) {
 	/*  e2 = e2 op e3; */
 	t = long_sign(op);
-	if (car(e2)==LREGISTER||car(e2)==LVAR||car(e2)==GVAR) {
+	if (car(e2)==LVAR||car(e2)==GVAR) {
 	    g_expr(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t));
 	    return;
 	}
@@ -1565,13 +1584,6 @@
     }
 
     g_expr(e3);
-    if (car(e2)==LREGISTER) {
-	emit_lpush();
-	code_register_lassop(cadr(e2),op);
-	if (use)
-	    code_lregister(cadr(e2),USE_CREG);
-	return;
-    }
     emit_lpush();
     g_expr(e2);
     code_lassop(op,USE_CREG);
--- a/mc-parse.c	Mon May 24 19:59:50 2004 +0900
+++ b/mc-parse.c	Tue Jun 01 12:42:36 2004 +0900
@@ -1513,7 +1513,7 @@
 NMTBL str_ret;
 
 /*
-    If function has structure return value, it has extra
+    If function has structure return value, it has an extra
     argument for where to write the structure. It have to be
     a first argument. We add it here and we have to fix all arguments'
     offset. If it is the last value, we don't have to fix, but
@@ -3695,11 +3695,116 @@
 }
 
 static int
+get_numerical()
+{
+    int d;
+    char *scheapp;
+    /* numerical */
+
+    symval=0; d=0;
+    scheapp = cheapp;
+    if(ch=='.') {
+	getch();
+	if(ch=='.') {
+	    getch();
+	    if (ch=='.') {
+		getch();
+		return sym=DOTS;
+	    }
+	    error(CHERR);
+	    return getsym(0);
+	} else if (!digit(ch))
+	    return sym=PERIOD;
+	d=1;
+	*cheapp++ = '.'; /* .0 case */
+    } else if (ch == '0') {
+	if (getch() == 'x' || ch == 'X') {
+	    /* hexadicimal */
+	    while(1) {
+		if(digit(getch()))
+		    symval=symval*16+ch-'0';
+		else if('a'<=ch&&ch<='f')
+		    symval=symval*16+ch-'a'+10;
+		else if('A'<=ch&&ch<='F')
+		    symval=symval*16+ch-'A'+10;
+		else break;
+	    }
+	    return sym=CONST;
+	} else if (ch!='.'&&ch!='L') {
+	    /* octal */
+	    while (digit(ch)) {
+		symval=symval*8+ch-'0';getch();
+	    }
+	    return sym=CONST;
+	} else if (ch=='L') {  /* 0L or 0LL case */
+	    if (getch()=='L') {
+#if LONGLONG_CODE
+		getch();
+		lsymval = 0;
+		return sym=LCONST;
+#else
+		symval = 0;
+		return sym=CONST;
+#endif
+	    } else {
+		symval = 0;
+		return sym=CONST;
+	    }
+	}
+	d=1;
+	*cheapp++ = '0'; /* 0. case */
+    } else {
+	while(digit(ch)) {
+	    *cheapp++ = ch;
+	    symval=symval*10+ch-'0';getch();
+	}
+	if (!(ch=='.'||ch=='e'||ch=='L')) {
+	    cheapp=scheapp;
+	    return sym=CONST;
+	}
+    }
+    if (!d && ch=='L') {
+	getch();
+	if (ch=='L') {
+#if LONGLONG_CODE
+	    getch(); /*LONGLONG*/
+	    *cheapp++ = 0;
+	    lsymval = strtoll(scheapp,0,0);
+	    cheapp=scheapp;
+	    return sym=LCONST;
+#else
+	    error(CHERR);
+	    symval = 0;
+	    return sym=CONST;
+#endif
+	}
+	return sym=CONST;
+    }
+#if FLOAT_CODE
+    /* floating point case */
+    while(digit(ch)|| ch=='.'||ch=='e') {
+	*cheapp++ = ch;
+	getch();
+	if (ch=='-' && cheapp[-1]=='e') {
+	    *cheapp++ = ch; getch();
+	} else if (ch=='+' && cheapp[-1]=='e') {
+	    *cheapp++ = ch; getch();
+	}
+    }
+    *cheapp++ = 0;
+    dsymval = strtod(scheapp,0);
+    cheapp=scheapp;
+    return sym=DCONST;
+#else
+    symval = 0;
+    return sym=CONST;
+#endif
+}
+
+static int
 getsym(int sc)
 {
     NMTBL *nptr0,*nptr1,*nptrm;
-    int d;
-    char *scheapp;
     char c;
 
     if (alpha(skipspc())) {
@@ -3743,106 +3848,7 @@
 	return sym;
 
     } else if (digit(ch)||ch=='.') {
-        /* numerical */
-
-	symval=0; d=0;
-	scheapp = cheapp;
-	if(ch=='.') {
-	    getch();
-	    if(ch=='.') {
-		getch();
-		if (ch=='.') {
-		    getch();
-		    return sym=DOTS;
-		}
-		error(CHERR);
-		return getsym(0);
-	    } else if (!digit(ch))
-		return sym=PERIOD;
-	    d=1;
-	    *cheapp++ = '.'; /* .0 case */
-	} else if (ch == '0') {
-	    if (getch() == 'x' || ch == 'X') {
-		/* hexadicimal */
-		while(1) {
-		    if(digit(getch()))
-			symval=symval*16+ch-'0';
-		    else if('a'<=ch&&ch<='f')
-			symval=symval*16+ch-'a'+10;
-		    else if('A'<=ch&&ch<='F')
-			symval=symval*16+ch-'A'+10;
-		    else break;
-		}
-		return sym=CONST;
-	    } else if (ch!='.'&&ch!='L') {
-		/* octal */
-		while (digit(ch)) {
-		    symval=symval*8+ch-'0';getch();
-		}
-		return sym=CONST;
-	    } else if (ch=='L') {  /* 0L or 0LL case */
-		if (getch()=='L') {
-#if LONGLONG_CODE
-		    getch();
-		    lsymval = 0;
-		    return sym=LCONST;
-#else
-		    symval = 0;
-		    return sym=CONST;
-#endif
-		} else {
-		    symval = 0;
-		    return sym=CONST;
-		}
-	    }
-	    d=1;
-	    *cheapp++ = '0'; /* 0. case */
-	} else {
-	    while(digit(ch)) {
-		*cheapp++ = ch;
-		symval=symval*10+ch-'0';getch();
-	    }
-	    if (!(ch=='.'||ch=='e'||ch=='L')) {
-		cheapp=scheapp;
-		return sym=CONST;
-	    }
-	}
-	if (!d && ch=='L') {
-	    getch();
-	    if (ch=='L') {
-#if LONGLONG_CODE
-		getch(); /*LONGLONG*/
-		*cheapp++ = 0;
-		lsymval = strtoll(scheapp,0,0);
-		cheapp=scheapp;
-		return sym=LCONST;
-#else
-		error(CHERR);
-		symval = 0;
-		return sym=CONST;
-#endif
-	    }
-	    return sym=CONST;
-	}
-#if FLOAT_CODE
-	/* floating point case */
-	while(digit(ch)|| ch=='.'||ch=='e') {
-	    *cheapp++ = ch;
-	    getch();
-	    if (ch=='-' && cheapp[-1]=='e') {
-		*cheapp++ = ch; getch();
-	    } else if (ch=='+' && cheapp[-1]=='e') {
-		*cheapp++ = ch; getch();
-	    }
-	}
-	*cheapp++ = 0;
-	dsymval = strtod(scheapp,0);
-	cheapp=scheapp;
-	return sym=DCONST;
-#else
-	symval = 0;
-	return sym=CONST;
-#endif
+	return get_numerical();
     } else if(ch=='\'') {
 	getch();
 	symval=escape();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tstdarg.c	Tue Jun 01 12:42:36 2004 +0900
@@ -0,0 +1,56 @@
+
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int
+var_args(char *numtypes, ...)
+{
+    int t;
+    int i;
+    float f;
+    double d;
+    long long l;
+    char *s;
+    va_list ap;
+
+    va_start(ap,numtypes);
+
+    while((t= *numtypes++)) {
+	if (t=='i') {
+	    i = va_arg(ap,int);
+	    printf("int arg: %d\n",i);
+	} else if (t=='f') {
+#if 0
+	    f = va_arg(ap,float);
+#ele
+	    f = va_arg(ap,double);
+#endif
+	    printf("float arg: %g\n",f);
+	} else if (t=='d') {
+	    d = va_arg(ap,double);
+	    printf("double arg: %g\n",d);
+	} else if (t=='l') {
+	    l = va_arg(ap,long long);
+	    printf("long long arg: %lld\n",l);
+	} else if (t=='s') {
+	    s = va_arg(ap,char *);
+	    printf("char *arg: %s\n",s);
+	} else {
+	    s = va_arg(ap,char *);
+	    printf("arg: error\n");
+	}
+    }
+}
+
+
+main()
+{
+
+    var_args("iiiiii",1,2,3,4,5,6);
+    var_args("llllll",(long long)1,(long long)2,(long long)3,(long long)4,(long long)5,(long long)6);
+    var_args("ffffff",(float)1,(float)2,(float)3,(float)4,(float)5,(float)6);
+    var_args("dddddd",(double)1,(double)2,(double)3,(double)4,(double)5,(double)6);
+    var_args("ssssss","1","2","3","4","5","6");
+    
+}