diff mc-codegen.c @ 820:9598ecec0af5

rvalue, RSTRUCT, non parse mode
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 26 Nov 2010 19:38:40 +0900
parents c59753132812
children fe751ca164a2
line wrap: on
line diff
--- a/mc-codegen.c	Fri Nov 26 16:32:33 2010 +0900
+++ b/mc-codegen.c	Fri Nov 26 19:38:40 2010 +0900
@@ -3332,6 +3332,21 @@
     if (ctmode & RESTRICT_BIT) set_attr(n,RESTRICT,0);
 }
 
+static int 
+struct_align_offset(int t,int offset)
+{
+    int strtype=0;
+    if (t>0 && (car(t)==STRUCT||car(t)==UNION))
+	strtype=1;
+    int sz = size(t);
+    if (lp64 && (sz%size_of_longlong==0)) {
+	offset = align(offset,size_of_longlong);
+    } else if (sz%size_of_int==0||strtype) {
+	offset = align(offset,struct_align);
+    }
+    return offset;
+}
+
 /*
     define symbol name contents 
       depending on stmode, mode
@@ -3386,16 +3401,9 @@
 	    error(-1);
 #endif
 	}  else {
+	    sz = size(type0);
 #if STRUCT_ALIGN 
-	    int strtype=0;
-	    if (type0>0 && (car(type0)==STRUCT||car(type0)==UNION))
-		strtype=1;
-	    sz = size(type0);
-            if (lp64 && (sz%size_of_longlong==0)) {
-		disp = align(disp,size_of_longlong);
-            } else if ((sz%size_of_int==0)||strtype) {
-		disp = align(disp,struct_align);
-            }
+	    disp = struct_align_offset(type0,disp);
 #endif
 	    if ((align0=attr_value_in_list(attr,ALIGNED))) {
 int hoge = disp;
@@ -3405,7 +3413,6 @@
                 disp = align(disp,align0);
 if (lsrc && hoge!=disp)
 printf("# field %s %d->%d (align %d)\n",n->nm,hoge,disp,align0);
-
 	    }
 	}
 	if (n!=&null_nptr)
@@ -3943,21 +3950,14 @@
 extern int
 assign_data(int e, int t, int v,int offset)
 {
-    int ass,sz,bfd;
+    int ass,bfd;
     int v0 = car(v);
     NMTBL *n = ncaddr(v);
 
     if (inmode) error(-1);
 #if STRUCT_ALIGN
-    if (t!=EMPTY) {
-	int strtype=0;
-	if (t>0 && (car(t)==STRUCT||car(t)==UNION))
-	    strtype=1;
-	sz = size(t);
-	if (sz%size_of_int==0||strtype) {
-	    offset = align(offset,struct_align);
-	}
-    }
+    if (t!=EMPTY) 
+	offset = struct_align_offset(t,offset);
 #endif
     if (car(e)==ADDRESS||car(e)==GVAR) {
 	if (scalar(t)) {
@@ -4003,7 +4003,7 @@
 	return offset;
     }
     if (t>0&&car(t)==BIT_FIELD) {
-	sz = 0; 
+	int sz = 0; 
 	bfd = cadr(caddr(t)); /* bit_field_disp */
 #if BIT_FIELD_CODE
 	code_bit_field_disp(t,&offset,&bfd,&sz);
@@ -4379,8 +4379,8 @@
 	    if(car(e)==INDIRECT) return cadr(e);
 	    return list2(ADDRESS,e);
 	case STRUCT: case UNION:
-	    // RINDIRECT がいいのかも
-	    if(car(e)==RSTRUCT) return e; /* ??? */
+	    if(car(e)==RSTRUCT) return e; /* to make idempotent */
+	    if(car(e)==INDIRECT) return cadr(e);
 	    return list3(RSTRUCT,e,cadr(type) /* size */);
 	case FUNCTION:
 	    type=set_type_with_attr(cadr(type0),type);
@@ -4472,7 +4472,7 @@
 indop(int e)
 {
     int type0 = type_value(type);
-    if(type0!=INT&&type0!=UNSIGNED) {
+    if(type0!=INT&&type0!=UNSIGNED&&type0!=LONGLONG&&type0!=ULONGLONG) {
 	if(car(type0)==POINTER)
 	    type=set_type_with_attr(cadr(type),type);
 	else if(car(type0)==CODE || car(type0)==FUNCTION) {