changeset 335:4f98dc4b5fd8

bit-field continue... code-generation debug
author kono
date Fri, 25 Jun 2004 01:01:41 +0900
parents dc81596066df
children d488b72254fb
files Changes mc-code-powerpc.c mc-codegen.c
diffstat 3 files changed, 44 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Thu Jun 24 20:50:17 2004 +0900
+++ b/Changes	Fri Jun 25 01:01:41 2004 +0900
@@ -5137,3 +5137,7 @@
 
 なんか、assign_expr の 引数 type が大域変数を上書きしてました。
 それが恥ずかしいバグの原因だったのか。
+
+Fri Jun 25 00:00:46 JST 2004
+
+なんか、Union のテストコードを書いてない気がする。
--- a/mc-code-powerpc.c	Thu Jun 24 20:50:17 2004 +0900
+++ b/mc-code-powerpc.c	Fri Jun 25 01:01:41 2004 +0900
@@ -5093,8 +5093,8 @@
     switch(cadr(type)) { 
     case INT:		sign=1; bitsz=32; align=4;break; 
     case UNSIGNED:		bitsz=32; align=4;break; 
-    case CHAR:          sign=1; bitsz=24; align=1;break; 
-    case UCHAR: 		bitsz=24; align=1;break; 
+    case CHAR:          sign=1; bitsz= 8; align=1;break; 
+    case UCHAR: 		bitsz= 8; align=1;break; 
     case SHORT:         sign=1; bitsz=16; align=2;break; 
     case USHORT:        sign=1; bitsz=16; align=2;break; 
     case LONGLONG:      sign=1; bitsz=64; align=4;l=1; break; 
@@ -5132,22 +5132,22 @@
 
 	i= offset-(bitpos+7)/8;
 
-	if ((i & (align-1)) && bitpos+bitsize < bitsz) {
-
-	    /* alignment is correct and space remains */
-
-	    *poffset=offset=i;
-	    i = bitpos+bitsize;
-	    *bfd = i;
-	    *sz = (i+7)/8;
-	    return bitpos;
-	} 
+	for(l = bitpos;l>0;l -= 8,i++) {
+	    if ((i & (align-1))==0 && l+bitsize < bitsz) {
+		/* alignment is correct and space remains */
+		*poffset=offset=i;
+		i = l+bitsize;
+		*bfd = i;
+		*sz = (i+7)/8;
+		return l;
+	    } 
+	}
     }
 
     /* first bit-field */
 
     if ((i=(offset & (align-1)))) {
-	*poffset = (offset += i);
+	*poffset = (offset += (align-i));
     }
     bitpos = 0;
     *bfd = bitsize;
@@ -5171,18 +5171,18 @@
 	use_longlong(reg);
 	/* shift left */
 	if (bitpos) 
-	    loprtc(LLSHIFT,reg,bitpos);
+	    loprtc(LLSHIFT,reg,list2(CONST,bitpos));
 	/* shift right */
 	if ((i=bitsz-bitsize)) 
-	    loprtc(sign?LRSHIFT:LURSHIFT,reg,i);
+	    loprtc(sign?LRSHIFT:LURSHIFT,reg,list2(CONST,i));
     } else {
 	use_int(reg);
 	/* shift left */
 	if (bitpos) 
-	    oprtc(LSHIFT,reg,bitpos);
+	    oprtc(LSHIFT,reg,list2(CONST,bitpos));
 	/* shift right */
 	if ((i=bitsz-bitsize)) 
-	    oprtc(sign?RSHIFT:URSHIFT,reg,i);
+	    oprtc(sign?RSHIFT:URSHIFT,reg,list2(CONST,i));
     }
 }
 
@@ -5233,7 +5233,7 @@
 	lrn = lregister_name_low(lvalue);
 	/* shift left */
 	if ((i=bitsz-bitsize-bitpos)) 
-	    loprtc(LLSHIFT,value,i);
+	    loprtc(LLSHIFT,value,list2(CONST,i));
 	trn = register_name(tmp = get_register());
 	if (bitpos+bitsize>32) {
 	    /* make and-mask lower */
@@ -5253,7 +5253,7 @@
 	lrn = register_name(lvalue);
 	/* shift left */
 	if ((i=bitsz-bitsize-bitpos)) 
-	    oprtc(LSHIFT,value,i);
+	    oprtc(LSHIFT,value,list2(CONST,i));
 	trn = register_name(tmp = get_register());
 	/* make and-mask */
 	mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize);
--- a/mc-codegen.c	Thu Jun 24 20:50:17 2004 +0900
+++ b/mc-codegen.c	Fri Jun 25 01:01:41 2004 +0900
@@ -2259,7 +2259,7 @@
             /* in decl() */
 	}
     }
-    if (mode==GSDECL||mode==LSDECL|| mode==GUDECL||mode==LUDECL) {
+    if (mode==GSDECL||mode==LSDECL) {
           /* Struct fields name lists are in the struct type or tag. */
           /* Only name in the table is used. Do not set n->ty! */
 	if (car(type)==BIT_FIELD) {
@@ -2272,6 +2272,13 @@
 	    sz = size(type);
 	}
 	fields = list4(type,fields,(int)(n->nm),disp);
+    } else if (mode==GUDECL||mode==LUDECL) {
+	if (car(type)==BIT_FIELD) {
+	    caddr(type) = 0; sz = size(cadr(type));
+	}  else {
+	    sz = size(type);
+	}
+	fields = list4(type,fields,(int)(n->nm),0);
     } else {
 	if (n->sc!=EMPTY &&  !(n->sc==EXTRN||n->sc==EXTRN1||n->sc==STATIC)) {
 	  /* redefined case */
@@ -2661,9 +2668,10 @@
 	case POINTER:
 	    break;
 	case BIT_FIELD:
-	    return list3(RBIT_FIELD,rvalue_t(cadr(e),cadr(type)),type);
+	    e =  list3(RBIT_FIELD,rvalue_t(cadr(e),cadr(type)),type);
             /*                         byte rvalue,   type */
 	    type = cadr(type);
+	    return e;
 	    break;
 	default:
 	    error(TYERR);
@@ -3207,9 +3215,9 @@
 {
     /* e1 = e2 */
     int lo = is_long_type(cadr(t));
-    g_expr(e2);
+    g_expr(e1);
     if (lo) emit_lpush(); else emit_push();
-    g_expr(e1);
+    g_expr(e2);
     code_bit_replace(USE_CREG,(e2=lo?emit_lpop():pop_register()),
 	t /* type */,caddr(t) /* bit offset */);
     if (lo) emit_lpop_free(e2); else emit_pop_free(e2);
@@ -3219,24 +3227,28 @@
 static int
 bassop(int e2,int e3,int op,int t,int post)
 {
-    int n;
+    int n,e4;
     int type  = cadr(t);
     /* if op==NULL  e2 = e3 */
     /*  e2 = e2 op e3; */
     if (car(e2)==LREGISTER||car(e2)==REGISTER||car(e2)==LVAR||car(e2)==GVAR) {
+	e4 = rvalue_t(e2,type);
 	g_expr(assign_expr0(e2,
-	    list4(BFD_REPL,e2,op?list3(op,rvalue_t(e2,t),e3):e3,t),
+	    list4(BFD_REPL,e4,op?list3(op,e4,e3):e3,t),
 	    type,type));
 	return type;
     }
     /*  new = &e2 */
     /*  *new = *new op e3 */
-    n = list2(LVAR,new_lvar(size_of_int));
+    // n = list2(LVAR,new_lvar(size_of_int));
+    n = get_register_var(0);
     g_expr_u(assign_expr0(n,list2(ADDRESS,cadr(e2)),INT,INT));
+    e4 = rvalue_t(list2(INDIRECT,n),type);
     g_expr(assign_expr0(list2(INDIRECT,n),
-	list4(BFD_REPL,n,op?list3(op,rvalue_t(list2(INDIRECT,n),t),e3):e3,t),
+	list4(BFD_REPL,e4,op?list3(op,e4,e3):e3,t),
 	type,type));
-    free_lvar(cadr(n));
+    if (car(n)==LVAR) free_lvar(cadr(n));
+    else if (car(n)==REGISTER) free_register(cadr(n));
     return type;
 }