diff mc-codegen.c @ 420:efbd420386c5

non aligned bitfield (not yet finished)
author kono
date Thu, 28 Oct 2004 21:20:52 +0900
parents 5fafb50df9d4
children ab58eea5e032
line wrap: on
line diff
--- a/mc-codegen.c	Wed Oct 27 09:04:07 2004 +0900
+++ b/mc-codegen.c	Thu Oct 28 21:20:52 2004 +0900
@@ -1873,7 +1873,10 @@
 	}
 	switch(car(t)) {
 	case BIT_FIELD:
-	    e2 = correct_type(e2,cadr(t));
+            //        type = list4(BIT_FIELD,type,
+            //            list3(type /*store type*/,0 /*bit offset*/,symval));
+	    e2 = correct_type(e2,car(caddr(t))); /* store type */
+	    type = cadr(t); /* value type */
 	    return(list4(BASS,e1,e2,list2(BASS,t)));
 	case STRUCT:case UNION:
 	    if (size(t)!=size(type)) error(TYERR);
@@ -1971,7 +1974,10 @@
 	type= UNSIGNED; ass = ASSOP;  u=1; break;
     default:
 	if (t>0 && car(t)==BIT_FIELD) {
-	    e2 = correct_type(e2,cadr(t));
+            //        type = list4(BIT_FIELD,type,
+            //            list3(type /*store type*/,0 /*bit offset*/,symval));
+	    e2 = correct_type(e2,car(caddr(t))); /* store type */
+	    type = cadr(t); /* value type */
 	    return(list4(BASSOP,e1,e2,list2(op,t)));
 	}
     }
@@ -2412,8 +2418,9 @@
           /* Only name in the table is used. Do not set n->ty! */
 	if (car(type)==BIT_FIELD) {
 	    bit_field_disp=sbit_f;   // default is 0, recover only here.
-            // n->ty = list4(BIT_FIELD,type,bit_offset,bit_width);
-	    caddr(type) = code_bit_field_disp(
+            //        type = list4(BIT_FIELD,value type,
+            //            list3(store type,bit offset,bit_width));
+	    cadr(caddr(type)) = code_bit_field_disp(
 		type,&disp,&bit_field_disp,&sz);
 	    /* bit_field_disp is next bit posision */
 	}  else {
@@ -2423,7 +2430,7 @@
 	    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));
+	    cadr(caddr(type)) = 0; sz = size(cadr(type));
 	}  else {
 	    sz = size(type);
 	}
@@ -2677,7 +2684,7 @@
     }
     if (t>0&&car(t)==BIT_FIELD) {
 	sz = 0; 
-	bfd = caddr(t); /* bit_field_disp */
+	bfd = cadr(caddr(t)); /* bit_field_disp */
 	code_bit_field_disp(t,&offset,&bfd,&sz);
 	return offset+sz;
     }
@@ -2918,9 +2925,9 @@
 	case POINTER:
 	    break;
 	case BIT_FIELD:
-	    e =  list3(RBIT_FIELD,rvalue_t(cadr(e),cadr(type)),type);
-            /*                         byte rvalue,   type */
-	    type = cadr(type);
+	    e =  list3(RBIT_FIELD,rvalue_t(cadr(e),car(caddr(type))),type);
+            /*                         byte rvalue,   store type */
+	    type = cadr(type); /* value type */
 	    return e;
 	    break;
 	default:
@@ -3043,7 +3050,7 @@
     }
     if (type>0&&car(type)==BIT_FIELD) {
 	// n->ty = list4(BIT_FIELD,type,bit_offset, bit_size);
-	e=list3(BIT_FIELD,e,type);
+	e=list3(BIT_FIELD,e,type);  //  ???
     }
     return e;
 }
@@ -3479,7 +3486,7 @@
     e1 = cadr(e1);
 }
     g_expr(e1);
-    code_bit_field(t, caddr(t)  /* bit offset */, USE_CREG);
+    code_bit_field(t, cadr(caddr(t))  /* bit offset */, USE_CREG);
     return cadr(t);
 }
 
@@ -3487,18 +3494,18 @@
 bit_field_repl(int e1,int e2,int t)
 {
     /* e1 = e2 */
-    int lo = is_long_type(cadr(t));
+    int lo = is_long_type(car(caddr(t))); /* store type  */
     if ((car(e2)==CONST||car(e2)==LCONST)) {
 	g_expr(e1);
 	code_bit_replace_const(e2,USE_CREG,
-	    t /* type */,caddr(t) /* bit offset */);
+	    t /* type */,cadr(caddr(t)) /* bit offset */);
 	return cadr(t);
     }
     g_expr(e1);
     if (lo) emit_lpush(); else emit_push();
     g_expr(e2);
     code_bit_replace(USE_CREG,(e2=lo?emit_lpop():pop_register()),
-	t /* type */,caddr(t) /* bit offset */);
+	t /* type */,cadr(caddr(t)) /* bit offset */);
     if (lo) emit_lpop_free(e2); else emit_pop_free(e2);
     return cadr(t);
 }
@@ -3508,15 +3515,16 @@
 {
     int n,e4;
     int type  = cadr(t);
+    int stype  = car(caddr(t));
     /*  e2 = e3 */
     if (car(e2)==BIT_FIELD) {
 	e2 = cadr(e2);
     }
     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,e4,e3,t), type,type));
+	e4 = rvalue_t(e2,stype);
+	g_expr(assign_expr0(e2, list4(BFD_REPL,e4,e3,t), stype,stype));
 	if (use)
-	    code_bit_field(t, caddr(t)  /* bit offset */, USE_CREG);
+	    code_bit_field(t, cadr(caddr(t))  /* bit offset */, USE_CREG);
 	return type;
     }
     /*  new = &e2 */
@@ -3524,13 +3532,13 @@
     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,rvalue_t(n,INT)),type);
+    e4 = rvalue_t(list2(INDIRECT,rvalue_t(n,INT)),stype);
     g_expr(assign_expr0(list2(INDIRECT,rvalue_t(n,INT)),
 	list4(BFD_REPL,e4,e3,t),
-	type,type));
+	stype,stype));
     free_lvar(cadr(n));
     if (use)
-	code_bit_field(t, caddr(t)  /* bit offset */, USE_CREG);
+	code_bit_field(t, cadr(caddr(t))  /* bit offset */, USE_CREG);
     return type;
 }
 
@@ -3557,7 +3565,9 @@
 
     int n=-1,n1=-1,n2=-1,adr=-1,e4;
     int type  = cadr(t);
+    int stype  = car(caddr(t));
     int byte;
+    int bit_offset = cadr(caddr(t));
     byte = size(type); if (byte==4) byte = 0;
 
     n = list2(LVAR,new_lvar(size(type)));
@@ -3568,22 +3578,28 @@
 	e2 = cadr(e2);
     }
     if (!(car(e2)==LREGISTER||car(e2)==REGISTER||car(e2)==LVAR||car(e2)==GVAR)) {
-	adr = list2(LVAR,new_lvar(size(type)));
+	adr = list2(LVAR,new_lvar(size(stype)));
 	g_expr_u(assign_expr0(adr,list2(ADDRESS,cadr(e2)),INT,INT));
-	e4 = rvalue_t(list2(INDIRECT,rvalue_t(adr,INT)),type);
+	e4 = rvalue_t(list2(INDIRECT,rvalue_t(adr,INT)),stype);
 	e2 = list2(INDIRECT,rvalue_t(adr,INT));
     } else {
-	e4 = rvalue_t(e2,type);
+	e4 = rvalue_t(e2,stype);
     }
-    g_expr(e4);
-    if (type==ULONGLONG||type==LONGLONG) {
+    if (stype==ULONGLONG||stype==LONGLONG) {
+	g_expr(e4);
 	code_lassign_lvar(cadr(n1),USE_CREG);
-	code_bit_field(t, caddr(t)  /* bit offset */, USE_CREG);
+	code_bit_field(t, bit_offset, USE_CREG);
+	code_lassign_lvar(cadr(n),USE_CREG);
+	if (post) code_lassign_lvar(cadr(n2),USE_CREG);
+    } else if (stype==STRUCT) {
+	g_expr0(assign_expr0(n1,e4,stype,stype));
+	code_bit_field(t, bit_offset, USE_CREG);
 	code_lassign_lvar(cadr(n),USE_CREG);
 	if (post) code_lassign_lvar(cadr(n2),USE_CREG);
     } else {
+	g_expr(e4);
 	code_assign_lvar(cadr(n1),USE_CREG,byte);
-	code_bit_field(t, caddr(t)  /* bit offset */, USE_CREG);
+	code_bit_field(t, bit_offset, USE_CREG);
 	code_assign_lvar(cadr(n),USE_CREG,byte);
 	if (post) code_assign_lvar(cadr(n2),USE_CREG,byte);
     }
@@ -3601,11 +3617,11 @@
     }
 
     g_expr(assign_expr0(e2,
-	    list4(BFD_REPL,rvalue_t(n1,type),rvalue_t(n,type),t),type,type));
+	    list4(BFD_REPL,rvalue_t(n1,type),rvalue_t(n,type),t),stype,stype));
 
     if (post) { g_expr(rvalue_t(n2,type)); free_lvar(cadr(n2)); }
     else if (use)  { 
-	code_bit_field(t, caddr(t)  /* bit offset */, USE_CREG);
+	code_bit_field(t, bit_offset, USE_CREG);
     }
     if (adr!=-1) free_lvar(cadr(adr));
     free_lvar(cadr(n));