changeset 608:c3ba27861c83

fix struct alignment in local init.
author kono
date Sat, 18 Feb 2006 21:33:43 +0900
parents e055df7c1082
children af6b9ae79583
files Changes mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-codegen.c mc-parse.c test/strinit.c
diffstat 7 files changed, 82 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Mon Feb 06 16:01:32 2006 +0900
+++ b/Changes	Sat Feb 18 21:33:43 2006 +0900
@@ -8654,3 +8654,33 @@
 で、expr のconvert ですが、どうするの? inmode 入れちゃって、
 一気にプリントが簡単ですが.... statement level? なんか、
 構造がまったく変わっちゃうな。時間かかるかも。
+
+Mon Feb  6 20:31:48 JST 2006
+
+statement expression とかがあるので、結局は、全部
+印刷しないとだめ。ってことは、tree_parse を書き直さない
+とだめだね。
+
+cast とかが落ちる可能性もあるので、正確には元に戻せない。
+
+あと、type_print mode との切替えをするかどうかだな。
+切替えはするんだと思うんだけど.... うまく出来るかどうか
+が問題。しない方が簡単だが、そうすると、conv/*.c の
+整合性が良くないか。それもいいけどさ。
+
+gen_inline なんかで、
+
+
+Fri Feb 10 21:18:41 JST 2006
+
+gcc のinclude path を Makefile (じゃなくて、mc-code-*.c か)
+に取り込む仕組みが必要だね。
+
+Sat Feb 18 20:45:46 JST 2006
+
+そうか local_struct_init だけど、式での初期化があるから、
+memcpy で実装するのは良くないわけね。もちろん、式があった
+どうかを判断することは出来るんだけど...
+
+
+
--- a/mc-code-arm.c	Mon Feb 06 16:01:32 2006 +0900
+++ b/mc-code-arm.c	Sat Feb 18 21:33:43 2006 +0900
@@ -1,6 +1,5 @@
 /* Micro-C Code Generation Part for Linux Zaurus and GameBoy Advance */
-/*
-************************************************************************
+/* ************************************************************************
 ** Copyright (C) 2006 Shinji Kono
 ** 連絡先: 琉球大学情報工学科 河野 真治  
 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
@@ -20,7 +19,6 @@
 **    You don't have to ask before copying, redistribution or publishing.
 **    THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
 ***********************************************************************/
- */
 
 
 #include <stdio.h>
--- a/mc-code-ia32.c	Mon Feb 06 16:01:32 2006 +0900
+++ b/mc-code-ia32.c	Sat Feb 18 21:33:43 2006 +0900
@@ -1,6 +1,6 @@
 /* Micro-C Code Generation Part for intel386 */
-/*
-************************************************************************
+
+/************************************************************************
 ** Copyright (C) 2006 Shinji Kono
 ** 連絡先: 琉球大学情報工学科 河野 真治  
 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
@@ -20,7 +20,7 @@
 **    You don't have to ask before copying, redistribution or publishing.
 **    THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
 ***********************************************************************/
- */
+
 
 
 #include <stdio.h>
@@ -32,8 +32,10 @@
 #if defined(__GNUC__) && __GNUC__ >= 4
 
 char *l_include_path[] = {
+    "/usr/include/linux/",
     "/usr/local/include",
     "/usr/lib/gcc/i486-linux-gnu/4.0.3/include",
+    "/usr/lib/gcc/i386-redhat-linux/4.0.2/include/",
     "/usr/include/",
     0
 };
@@ -127,6 +129,7 @@
 #define __PTRDIFF_TYPE__ int\n\
 #define __LDBL_MIN_10_EXP__ (-4931)\n\
 #define __LDBL_DIG__ 18\n\
+#define size_t int\n\
 ";
 
 #else
--- a/mc-code-mips.c	Mon Feb 06 16:01:32 2006 +0900
+++ b/mc-code-mips.c	Sat Feb 18 21:33:43 2006 +0900
@@ -21,7 +21,7 @@
 **    You don't have to ask before copying, redistribution or publishing.
 **    THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
 ***********************************************************************/
- */
+
 
 #include <stdio.h>
 #include "mc.h"
--- a/mc-codegen.c	Mon Feb 06 16:01:32 2006 +0900
+++ b/mc-codegen.c	Sat Feb 18 21:33:43 2006 +0900
@@ -2964,8 +2964,11 @@
 #endif
 	}  else {
 #if STRUCT_ALIGN 
+	    int strtype=0;
+	    if (type0>0 && (car(type0)==STRUCT||car(type0)==UNION))
+		strtype=1;
 	    sz = size(type0);
-            if (sz%size_of_int==0) {
+            if ((sz%size_of_int==0)||strtype) {
                 disp = ((disp+(size_of_int-1))&~(size_of_int-1));
             }
 #endif
@@ -3248,8 +3251,11 @@
 
 #if STRUCT_ALIGN
     if (t!=-99) {
+	int strtype=0;
+	if (t>0 && (car(t)==STRUCT||car(t)==UNION))
+	    strtype=1;
 	sz = size(t);
-	if (sz%size_of_int==0) {
+	if (sz%size_of_int==0||strtype) {
 	    offset = ((offset+(size_of_int-1))&~(size_of_int-1));
 	}
     }
--- a/mc-parse.c	Mon Feb 06 16:01:32 2006 +0900
+++ b/mc-parse.c	Sat Feb 18 21:33:43 2006 +0900
@@ -1468,7 +1468,7 @@
 {
     int t1,t2,period=0;
     int foffset;
-    int offset0 = offset+size(type);
+    // int offset0 = offset+size(type);
     int mode_save=mode;
     int type0=type_value(type);
 
@@ -1519,7 +1519,7 @@
 	if (sym==RC) break; // premature end
     }
     mode = mode_save;
-    return offset0;
+    return offset;
 }
 
 
--- a/test/strinit.c	Mon Feb 06 16:01:32 2006 +0900
+++ b/test/strinit.c	Sat Feb 18 21:33:43 2006 +0900
@@ -1,5 +1,7 @@
 #include <stdio.h>
 
+void main7();
+
 int b[3] = {1,2,3};
 
 struct temp {
@@ -85,6 +87,7 @@
     printf("#0084:2: %d\n",temp11.c==(int)&b);
     printf("#0085:2: %d\n",temp8.e);
     printf("#0086:2: %d\n",temp6.e);
+    main7();
     linux_kernel();
     return 0;
 }
@@ -194,4 +197,35 @@
     ip_route_connect(11,12,13,14,15,16,17);
 }
 
+struct st_child {
+  int a,b;
+  char c;
+};
+
+struct st_parent{
+  char ch;
+  struct st_child s1;
+  int i,j;
+};
+
+void
+main7()
+{
+  struct st_parent st1 = {'A',{1,2,'E'},5,6};
+  struct st_child st2 = {10,11,'F'};
+  printf("st1.ch   = %c\n",st1.ch);
+  printf("st1.s1.a = %d\n",st1.s1.a);
+  printf("st1.s1.b = %d\n",st1.s1.b);
+  printf("st1.s1.c = %c\n",st1.s1.c);
+  printf("st1.i    = %d\n",st1.i);
+  printf("st1.j    = %d\n\n",st1.j);
+
+  printf("st2.a = %d\n",st2.a);
+  printf("st2.b = %d\n",st2.b);
+  printf("st2.c = %c\n",st2.c);
+  
+  return;
+
+}
+
 // end