changeset 638:35014112c01d

multi dimentional array in functional arugments. (not yet fixed)
author kono
date Tue, 31 Oct 2006 22:40:19 +0900
parents 140b65f8ff03
children f3af9f3332f5
files Changes mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-codegen.c mc-parse.c test/ps2.c
diffstat 8 files changed, 35 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Tue Oct 31 20:42:42 2006 +0900
+++ b/Changes	Tue Oct 31 22:40:19 2006 +0900
@@ -9016,5 +9016,11 @@
 
 Tue Oct 31 20:16:16 JST 2006
 
-関数の引数に固定長の配列を渡すと破綻するらしい。
+関数の引数に固定長の配列を渡すと破綻するらしい。 (test/ps2.c)
 gcc には可変長配列ってのもあるにはあるんだよな。
+
+構造体と同じ扱いにしたが。
+
+いや、違うな... ARRAY は integral なんじゃないのか?
+単なるpointerだろ? 違うの?
+
--- a/mc-code-arm.c	Tue Oct 31 20:42:42 2006 +0900
+++ b/mc-code-arm.c	Tue Oct 31 22:40:19 2006 +0900
@@ -2440,7 +2440,7 @@
     } else if (t==FLOAT) {
 	reg_arg ++ ; freg_arg++;
 	nargs += size(t)/SIZE_OF_INT;
-    } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY)) {
+    } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) {
 	nargs += round4(size(t))/SIZE_OF_INT;
     } else {
 	error(TYERR);
@@ -2485,7 +2485,7 @@
 	    return list3(LVAR,caller_arg_offset_v(nargs),0);
 	} else
 	    return get_input_dregister_var(reg_arg,0,0,1);
-    } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY)) {
+    } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) {
 	if (mode==AS_SAVE) {
 	    return get_register_var(0);
 	} else
@@ -2565,12 +2565,12 @@
 	    pnargs=nargs;preg_arg=reg_arg;pfreg_arg=freg_arg;
 	    complex_ = e3;
 	}
-	if (t>=0&&(car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY)) {
+	if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) {
 	    // The struct should be pushed after complex arguments.
 	    if (e5) { // compute address only, complex_ is me now. Clear it.
 		complex_ = 0;
 		e4 = car(e3);
-		if (car(e4)!=RSTRUCT && car(e4)!=ARRAY) error(-1);
+		if (car(e4)!=RSTRUCT) error(-1);
 		if (!simple_arg(cadr(e4))) {
 		    // Calculate complex struct address here.
 		    // If simple, leave it.
@@ -3481,8 +3481,7 @@
 #endif
 	} else if (cadr(fnptr->ty)>0&&(
 	    car(cadr(fnptr->ty))==STRUCT ||
-	    car(cadr(fnptr->ty))==UNION ||
-	    car(cadr(fnptr->ty))==ARRAY)) {
+	    car(cadr(fnptr->ty))==UNION)) {
 	    sz = size(cadr(fnptr->ty));
 	    inc_inst(3);
 	    code_const(sz,REGISTER_OPERAND);
--- a/mc-code-ia32.c	Tue Oct 31 20:42:42 2006 +0900
+++ b/mc-code-ia32.c	Tue Oct 31 22:40:19 2006 +0900
@@ -1539,7 +1539,7 @@
 	} else if (t==FLOAT) {
 	    nargs += SIZE_OF_FLOAT/SIZE_OF_INT;
 	    continue;
-	} else if (car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY) {
+	} else if (car(t)==STRUCT||car(t)==UNION) {
 	    // struct must align 16 (but how?)
 	    length = size(t);
 	    if (length%SIZE_OF_INT)
@@ -1598,7 +1598,7 @@
 	    nargs += SIZE_OF_FLOAT/SIZE_OF_INT;
 	    stack_depth += SIZE_OF_FLOAT;
 	    continue;
-	} else if (car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY) {
+	} else if (car(t)==STRUCT||car(t)==UNION) {
 	    nargs += push_struct(e4,t);
 	    continue;
 	} else {
@@ -2243,8 +2243,7 @@
 	    printf("\tfldl %d(%%ebp)\n",-SIZE_OF_DOUBLE);
         } else if (cadr(fnptr->ty)>0&&(
             car(cadr(fnptr->ty))==STRUCT ||
-            car(cadr(fnptr->ty))==UNION ||
-            car(cadr(fnptr->ty))==ARRAY)) {
+            car(cadr(fnptr->ty))==UNION)) {
             sz = size(cadr(fnptr->ty));
 	    set_ireg(RET_REGISTER,0);
             printf("\tmovl %d(%%ebp),%s\n",disp-SIZE_OF_INT,
--- a/mc-code-mips.c	Tue Oct 31 20:42:42 2006 +0900
+++ b/mc-code-mips.c	Tue Oct 31 22:40:19 2006 +0900
@@ -2026,7 +2026,7 @@
     } else if (t==FLOAT) {
 	reg_arg ++ ; freg_arg++;
 	nargs += size(t)/SIZE_OF_INT;
-    } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY)) {
+    } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) {
 	nargs += round4(size(t))/SIZE_OF_INT;
     } else {
 	error(TYERR);
@@ -2075,7 +2075,7 @@
 	    return list3(LVAR,caller_arg_offset_v(nargs),0);
 	} else
 	    return get_input_dregister_var(reg_arg,0,0,1);
-    } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY)) {
+    } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) {
 	if (mode==AS_SAVE) {
 	    return get_register_var(0);
 	} else
@@ -2157,7 +2157,7 @@
 	    pnargs=nargs;preg_arg=reg_arg;pfreg_arg=freg_arg;
 	    complex_ = e3;
 	}
-	if (t>=0&&(car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY)) {
+	if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) {
 	    // The struct should be pushed after complex arguments.
 	    if (e5) { // compute address only, complex_ is me now. Clear it.
 		complex_ = 0;
--- a/mc-code-powerpc.c	Tue Oct 31 20:42:42 2006 +0900
+++ b/mc-code-powerpc.c	Tue Oct 31 22:40:19 2006 +0900
@@ -1970,7 +1970,7 @@
 	}
 	freg_arg++;
 	nargs += size(t)/SIZE_OF_INT;
-    } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY)) {
+    } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) {
 	nargs += round4(size(t))/SIZE_OF_INT;
     } else {
 	error(TYERR);
@@ -2024,11 +2024,6 @@
 	    return get_register_var(0);
 	} else
 	    return list3(LVAR,caller_arg_offset_v(nargs),0);
-    } else if (t>=0&&(car(t)==ARRAY)) {
-	if (mode==AS_SAVE) {
-	    return get_register_var(0);
-	} else
-	    return list3(LVAR,caller_arg_offset_v(nargs),0);
     } else {
 	error(-1);
 	return get_register_var(0);
@@ -2083,12 +2078,12 @@
 	    pnargs=nargs;preg_arg=reg_arg;pfreg_arg=freg_arg;
 	    complex_ = e3;
 	}
-	if (t>=0&&(car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY)) {
+	if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) {
 	    // The struct should be pushed after complex arguments.
 	    if (e5) { // compute address only, complex_ is me now. Clear it.
 		complex_ = 0;
 		e4 = car(e3);
-		if (car(e4)!=RSTRUCT && car(e4)!=ARRAY) error(-1);
+		if (car(e4)!=RSTRUCT) error(-1);
 		if (!simple_arg(cadr(e4))) {
 		    // Calculate complex struct address here.
 		    // If simple, leave it.
--- a/mc-codegen.c	Tue Oct 31 20:42:42 2006 +0900
+++ b/mc-codegen.c	Tue Oct 31 22:40:19 2006 +0900
@@ -2266,7 +2266,7 @@
             //            list3(type /*store type*/,0 /*bit offset*/,bitsize));
 	    e2 = correct_type(e2,cadr(t)); /* value type */
 	    return(list4(BASS,e1,e2,list2(BASS,t)));
-	case STRUCT:case UNION: case ARRAY:
+	case STRUCT:case UNION:
 	    if (size(t)!=size(type)) error(TYERR);
 	    type=t;    // dispose attr
 	    if(car(e2)==RSTRUCT && car(cadr(e2))==FUNCTION) {
@@ -3437,7 +3437,7 @@
 }
 
 //
-// local/global variable initialization
+// local variable initialization
 //
 
 extern int
@@ -3714,7 +3714,10 @@
 scalar(int t)
 {
     t = type_value(t);
-    return(integral(t)||(t>0 && car(t)==POINTER));
+    return(integral(t)
+	||(t>0 && (car(t)==POINTER ||
+		     car(t)==ARRAY))
+    );
 }
 
 extern int
--- a/mc-parse.c	Tue Oct 31 20:42:42 2006 +0900
+++ b/mc-parse.c	Tue Oct 31 22:40:19 2006 +0900
@@ -1120,6 +1120,10 @@
 	if(sym==IDENT) {
 	    if (nptr->sc==TYPE) {
 		t=nptr->ty;
+		if (mode==ADECL) {
+		    //   f(float a[4][4]) case
+		    t = list2(POINTER,t);
+		}
 		typedefed=glist2((int)nptr,typedefed);
 		getsym(0);
 		break;
@@ -4024,7 +4028,7 @@
 
     argtypes = caddr(type0);
     if (!argtypes) dots=1;
-    if ((t=type_value(cadr(type0)))>=0 && (car(t)==STRUCT||car(t)==UNION||car(t)==ARRAY)) {
+    if ((t=type_value(cadr(type0)))>=0 && (car(t)==STRUCT||car(t)==UNION)) {
 	/* skip return struct pointer */
 	if (argtypes==0) error(-1);
 	argtypes = cadr(argtypes);
@@ -4067,7 +4071,7 @@
     type0 = type_value(type);
     if(type0==CHAR||type0==SHORT) type=set_type_with_attr(INT,type);
     else if(type0==UCHAR||type0==USHORT) type=set_type_with_attr(UNSIGNED,type);
-    else if(type0>0 && (car(type0)==STRUCT||car(type0)==UNION||car(type0)==ARRAY)) {
+    else if(type0>0 && (car(type0)==STRUCT||car(type0)==UNION)) {
 
 	/* temporal struct is required */
 
--- a/test/ps2.c	Tue Oct 31 20:42:42 2006 +0900
+++ b/test/ps2.c	Tue Oct 31 22:40:19 2006 +0900
@@ -11,6 +11,7 @@
 void  ps2_vu0_unit_matrix(ps2_vu0_fmatrix m)
 {
     printf("%g\n",m[1][1]);
+    m[1][1] = -0.5;
 }
 
 int
@@ -20,4 +21,5 @@
 
     m[1][1] = 0.5;
     ps2_vu0_unit_matrix(m);
+    printf("%g\n",m[1][1]);
 }