diff mc-codegen.c @ 716:21f770a3b298

*** empty log message ***
author kono
date Fri, 16 Nov 2007 21:46:20 +0900
parents 83e18db76c96
children d12029c499df
line wrap: on
line diff
--- a/mc-codegen.c	Wed Nov 14 19:36:55 2007 +0900
+++ b/mc-codegen.c	Fri Nov 16 21:46:20 2007 +0900
@@ -43,6 +43,7 @@
 int size_of_longlong;
 int bit_of_byte;
 int endian;
+int struct_align;
 
 #define STRUCT_ALIGN 1
 
@@ -3224,7 +3225,7 @@
 extern NMTBL *
 def(NMTBL *n,int ctmode)
 {
-    int sz,nsc,ndsp,align;
+    int sz,nsc,ndsp,align0;
     int sbit_f = bit_field_disp;
     int type0 = type_value(type);
     int attr = attribute;
@@ -3275,17 +3276,17 @@
 		strtype=1;
 	    sz = size(type0);
             if ((sz%size_of_int==0)||strtype) {
-                disp = ((disp+(size_of_int-1))&~(size_of_int-1));
+		disp = align(disp,struct_align);
             }
 #endif
-	    if ((align=attr_value_in_list(attr,ALIGNED))) {
+	    if ((align0=attr_value_in_list(attr,ALIGNED))) {
 int hoge = disp;
-		if (car(align)!=CONST) error(-1);
+		if (car(align0)!=CONST) error(-1);
 		// align have to be 2^n
-		align = caddr(align);
-                disp = ((disp+(align-1))&~(align-1));
+		align0 = caddr(align0);
+                disp = align(disp,align0);
 if (lsrc && hoge!=disp)
-printf("# field %s %d->%d (align %d)\n",n->nm,hoge,disp,align);
+printf("# field %s %d->%d (align %d)\n",n->nm,hoge,disp,align0);
 
 	    }
 	}
@@ -3445,6 +3446,8 @@
     return n;
 }
 
+// standard 32bit alignment 
+
 extern int
 code_arg_alignment0(int args,NMTBL *n, int type0,int sz)
 {
@@ -3465,7 +3468,7 @@
         /* should be GCD of member alignment */
         /* __attribute(alignment(16)) is ignored in argments */
         n->dsp = args;
-        args += ((sz+(size_of_int-1))&~(size_of_int-1));
+        args += align(sz,size_of_int);
     } else {
         /* if (n->dsp==0) (argument list in ADECL is useless, type
            list can be found in type ) */
@@ -3475,6 +3478,8 @@
     return args;
 }
 
+// standard 32bit alignment for local variable
+
 extern int
 code_lvar_alignment0(int disp0,NMTBL *n,int type0,int sz) {
     int align;
@@ -3493,7 +3498,7 @@
 
 // for mc-parse.c
 extern int
-arg_alignment0(int args,NMTBL *n, int type0,int sz)
+arg_alignment(int args,NMTBL *n, int type0,int sz)
 {
     return code_arg_alignment(args,n, type0,sz);
 }
@@ -3770,7 +3775,7 @@
 	nptr0->sc = LVAR;
 	nptr0->attr = 0;
 	nptr0->ty = t;
-	nptr0->dsp = new_lvar_align(sz,16);
+	nptr0->dsp = new_lvar_align(sz,16); // ?!
 	e1 = list3(RSTRUCT,list3n(
 	    nptr0->sc,nptr0->dsp,nptr0),sz);
 	v = list3n(nptr0->sc,nptr0->dsp,nptr0);
@@ -3806,7 +3811,7 @@
 	    strtype=1;
 	sz = size(t);
 	if (sz%size_of_int==0||strtype) {
-	    offset = ((offset+(size_of_int-1))&~(size_of_int-1));
+	    offset = align(offset,struct_align);
 	}
     }
 #endif
@@ -5179,7 +5184,7 @@
 }
 
 extern int
-new_lvar(int size) {
+new_lvar(int size) {  // system dependent?
     return new_lvar_align(size,0);
 }
 
@@ -5188,6 +5193,20 @@
  */
 
 extern void
+free_register_var(int reg_arg_list)
+{
+    int arg;
+    for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) {
+        arg = car(reg_arg_list);
+        if (car(arg)==REGISTER||car(arg)==DREGISTER||car(arg)==FREGISTER
+                ||car(arg)==LREGISTER)  {
+            free_register(cadr(arg));
+        } else if (car(arg)==LVAR&&cadr(arg)<0) free_lvar(cadr(arg));
+    }
+}
+
+
+extern void
 free_lvar(int disp)
 {
     int lvar,plvar;