changeset 656:8320ae3ac186 strinit-expr

inlined strinit
author kono
date Mon, 15 Jan 2007 13:30:31 +0900
parents cddab906095e
children bb3a11f3f31d
files .gdbinit Makefile Makefile.powerpc mc-parse.c mc-parse.h test/strinit.c
diffstat 6 files changed, 134 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Sun Jan 14 20:30:31 2007 +0900
+++ b/.gdbinit	Mon Jan 15 13:30:31 2007 +0900
@@ -45,7 +45,7 @@
 # run -s test/code-gen-inline.c
 # run -s -DINLINE=inline test/basic.c
 # run -s test/too-long-argument.c
-run -s test/strinit.c
+run -s -DINLINE=inline test/strinit.c
 # run -DINLINE=inline test/scope.c
 # run -DINLINE=inline test/code-gen-all.c
 # run -DINLINE=inline test/bitfield1.c
--- a/Makefile	Sun Jan 14 20:30:31 2007 +0900
+++ b/Makefile	Mon Jan 15 13:30:31 2007 +0900
@@ -101,6 +101,7 @@
 	make check TARGET=test/tstdarg
 	make check TARGET=test/switch
 	make check TARGET=test/strinit
+	make check-inline TARGET=test/strinit
 	make check TARGET=test/code-gen-all
 	make check-inline TARGET=test/code-gen-all
 	make check TARGET=test/bitfield
--- a/Makefile.powerpc	Sun Jan 14 20:30:31 2007 +0900
+++ b/Makefile.powerpc	Mon Jan 15 13:30:31 2007 +0900
@@ -25,7 +25,9 @@
 #
 TARGET=test/simp
 
-all: mc-include.c mc mc-ia32 mc-powerpc mc-mips mc-arm
+all: mc-include.c mc
+
+allall: mc-include.c mc mc-ia32 mc-powerpc mc-mips mc-arm
 
 mc:  mc-$(ARCH)
 	cp mc-$(ARCH) mc
@@ -99,6 +101,7 @@
 	make check TARGET=test/tstdarg
 	make check TARGET=test/switch
 	make check TARGET=test/strinit
+	make check-inline TARGET=test/strinit
 	make check TARGET=test/code-gen-all
 	make check-inline TARGET=test/code-gen-all
 	make check TARGET=test/bitfield
@@ -255,3 +258,62 @@
 
 
 # DO NOT DELETE
+
+mc-code-ia32.o: /usr/include/stdio.h /usr/include/_types.h
+mc-code-ia32.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+mc-code-ia32.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+mc-code-ia32.o: mc-parse.h mc-codegen.h mc-code.h mc-include.c
+mc-codegen.o: /usr/include/stdio.h /usr/include/_types.h
+mc-codegen.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+mc-codegen.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+mc-codegen.o: mc-parse.h mc-codegen.h mc-code.h mc-switch.h mc-inline.h
+mc-codegen.o: conv/conv.h
+mc-parse.o: /usr/include/stdio.h /usr/include/_types.h
+mc-parse.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+mc-parse.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+mc-parse.o: mc-parse.h mc-codegen.h mc-switch.h mc-macro.h mc-inline.h
+mc-parse.o: conv/conv.h
+mc-tree.o: /usr/include/stdio.h /usr/include/_types.h
+mc-tree.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+mc-tree.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+mc-tree.o: mc-parse.h mc-codegen.h
+mc-switch.o: /usr/include/stdio.h /usr/include/_types.h
+mc-switch.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+mc-switch.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+mc-switch.o: mc-parse.h mc-codegen.h mc-code.h
+mc-inline.o: /usr/include/stdio.h /usr/include/_types.h
+mc-inline.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+mc-inline.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+mc-inline.o: mc-parse.h mc-codegen.h mc-switch.h mc-code.h mc-inline.h
+mc-macro.o: /usr/include/stdio.h /usr/include/_types.h
+mc-macro.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+mc-macro.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+mc-macro.o: mc-parse.h mc-macro.h mc-codegen.h mc-code.h
+conv/c.o: /usr/include/stdio.h /usr/include/_types.h
+conv/c.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+conv/c.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+conv/c.o: mc-parse.h mc-codegen.h conv/conv.h conv/convdef.h conv/c.h
+conv/c2cbc.o: /usr/include/stdio.h /usr/include/_types.h
+conv/c2cbc.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+conv/c2cbc.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+conv/c2cbc.o: mc-parse.h mc-codegen.h conv/conv.h conv/convdef.h conv/c2cbc.h
+conv/cbc2c.o: /usr/include/stdio.h /usr/include/_types.h
+conv/cbc2c.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+conv/cbc2c.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+conv/cbc2c.o: mc-parse.h mc-codegen.h conv/conv.h conv/convdef.h conv/cbc2c.h
+conv/null.o: /usr/include/stdio.h /usr/include/_types.h
+conv/null.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+conv/null.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+conv/null.o: mc-parse.h conv/conv.h conv/convdef.h conv/null.h
+mc-code-arm.o: /usr/include/stdio.h /usr/include/_types.h
+mc-code-arm.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+mc-code-arm.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+mc-code-arm.o: mc-parse.h mc-code.h mc-codegen.h
+mc-code-powerpc.o: /usr/include/stdio.h /usr/include/_types.h
+mc-code-powerpc.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+mc-code-powerpc.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h
+mc-code-powerpc.o: mc.h mc-parse.h mc-code.h mc-codegen.h mc-include.c
+mc-code-mips.o: /usr/include/stdio.h /usr/include/_types.h
+mc-code-mips.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h
+mc-code-mips.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h
+mc-code-mips.o: mc-parse.h mc-code.h mc-codegen.h
--- a/mc-parse.c	Sun Jan 14 20:30:31 2007 +0900
+++ b/mc-parse.c	Mon Jan 15 13:30:31 2007 +0900
@@ -3913,21 +3913,24 @@
 		    decl_data_field(type,nptr0,0);
 		    e1 = list3(RSTRUCT,list3(GVAR,0,(int)nptr0),e1);
 		} else {
-		    NMTBL n;
-		    nptr0 = &n;
-		    type = t;
-		    nptr0->dsp=new_lvar(e1=size(type));
+		    nptr0 = get_nptr(); // should be freed in a scope?
+					// in case of inline, we cannot
 		    nptr0->nm = "";
-		    nptr0->ty = t;
+		    nptr0->sc = EMPTY;
 		    nptr0->attr = 0;
-		    nptr0->sc = LVAR;
+		    type = nptr0->ty = t;
+		    def(nptr0,0);
+		    if (inmode) { 
+			parse = list4(ST_DECL,parse,(int)nptr0,
+			    list3(mode,0,0));
+		    }
 #if LOCAL_STRUCT_INIT_STATIC 
 		    local_struct_static(nptr0); 
 #else
 		    decl_data_field(type,nptr0,0);
 #endif
 		    e1 = list3(RSTRUCT,list3(
-			inmode?IVAR:LVAR,nptr0->dsp,(int)nptr0),e1);
+			nptr0->sc,nptr0->dsp,(int)nptr0),e1);
 		}
 		if (init_vars && mode!=LDECL) {
 		    emit_init_vars();
--- a/mc-parse.h	Sun Jan 14 20:30:31 2007 +0900
+++ b/mc-parse.h	Mon Jan 15 13:30:31 2007 +0900
@@ -127,6 +127,7 @@
 extern int dlist2(int e1, double d1);
 #endif
 extern void error(int n);
+
 extern int glist2(int e1,int e2);
 extern int glist3(int e1,int e2,int e3);
 extern int glist4(int e1,int e2,int e3,int e4);
--- a/test/strinit.c	Sun Jan 14 20:30:31 2007 +0900
+++ b/test/strinit.c	Mon Jan 15 13:30:31 2007 +0900
@@ -1,7 +1,11 @@
 #include <stdio.h>
 
-void main7();
-int main8();
+#ifndef INLINE
+#define INLINE
+#endif
+
+INLINE void main7();
+INLINE int main8();
 
 int b[3] = {1,2,3};
 
@@ -41,7 +45,7 @@
 };
 #endif 
 
-void
+INLINE void
 linux_kernel();
 
 struct test{
@@ -50,50 +54,6 @@
     0,0,0,
 };
 
-int
-main()
-{
-    struct temp temp2 = { .c = 5, .e=99 };
-#ifdef WRONG
-    struct temp temp5 = { 1,2,3,4,5,6,7,8};
-    struct temp temp6 = { 1,2,3,4,5,6};
-#else
-    struct temp temp5 = { 1,2,3,4,5,6,7};
-    struct temp temp6 = { 1,2,3,4,5,6,7};
-    struct temp temp8 = { 1,2,3,4,{5,6},7};
-#endif
-    struct temp temp11 = {
-       .m = (struct hoge){},
-       .c = (int)&b,
-    };
-    struct temp temp12 = {
-       .m = (struct hoge){1,3},
-       .c = (int)&temp4,
-    };
-
-    printf("#0070:1: %d\n",temp1.a);
-    printf("#0071:1: %d\n",temp1.e);
-    printf("#0072:1: %d\n",temp1.b);
-    printf("#0073:2: %d\n",temp2.c);
-    printf("#0074:2: %d\n",temp2.e);
-    printf("#0075:2: %d\n",temp2.b);
-    printf("#0076:2: %d\n",(void*)temp3.c==b);
-    printf("#0077:2: %d\n",temp3.c==(int)b);
-    printf("#0078:2: %d\n",temp3.a==(int)&b);
-    printf("#0079:2: %d\n",temp4.m.j);
-    printf("#0080:2: %d\n",temp5.m.j);
-    printf("#0081:2: %d\n",temp11.m.j);
-    printf("#0082:2: %d\n",temp12.m.k);
-    printf("#0083:2: %d\n",temp12.m.j);
-    printf("#0084:2: %d\n",temp11.c==(int)&b);
-    printf("#0085:2: %d\n",temp8.e);
-    printf("#0086:2: %d\n",temp6.e);
-    main7();
-    main8();
-    linux_kernel();
-    return 0;
-}
-
 typedef unsigned int __u32;
 typedef unsigned short __u16;
 typedef unsigned char __u8;
@@ -155,7 +115,7 @@
 } __attribute__((__aligned__(32/8)));
 
 
-static __inline__ __attribute__((always_inline)) __attribute__((always_inline)) 
+INLINE static __inline__ __attribute__((always_inline)) __attribute__((always_inline)) 
 void ip_route_connect(/* struct rtable **rp, */ u32 dst,
                                    u32 src, u32 tos, int oif, u8 protocol,
                                    u16 sport, u16 dport /*, struct sock *sk */)
@@ -172,7 +132,7 @@
 	printf("#0166:%d %d\n",fl.oif,fl.uli_u.ports.dport);
 }
 
-static 
+INLINE static 
 void ip_route_connect0(/* struct rtable **rp, */ u32 dst,
                                    u32 src, u32 tos, int oif, u8 protocol,
                                    u16 sport, u16 dport /*, struct sock *sk */)
@@ -191,7 +151,7 @@
 	printf("#0185:%d %d\n",fl.iif,fl.nl_u.ip4_u.saddr);
 }
 
-void
+INLINE void
 linux_kernel()
 {
     ip_route_connect0(1,2,3,4,5,6,7);
@@ -210,7 +170,7 @@
   int i,j;
 };
 
-void
+INLINE void
 main7()
 {
   struct st_parent st1 = {'A',{1,2,'E'},5,6};
@@ -234,12 +194,57 @@
 
 struct arg { int hage, fuga; int aho; };
 
-void f(struct arg h) {
+INLINE void f(struct arg h) {
     printf("%d %d %d\n",h.hage,h.fuga,h.aho);
 }
 
-int main8() {
+INLINE int main8() {
      f((struct arg){.fuga = 3,.aho=5});
+     printf("%d\n",((struct arg){.aho=120, .hage=55}).aho);
+}
+
+int
+main()
+{
+    struct temp temp2 = { .c = 5, .e=99 };
+#ifdef WRONG
+    struct temp temp5 = { 1,2,3,4,5,6,7,8};
+    struct temp temp6 = { 1,2,3,4,5,6};
+#else
+    struct temp temp5 = { 1,2,3,4,5,6,7};
+    struct temp temp6 = { 1,2,3,4,5,6,7};
+    struct temp temp8 = { 1,2,3,4,{5,6},7};
+#endif
+    struct temp temp11 = {
+       .m = (struct hoge){},
+       .c = (int)&b,
+    };
+    struct temp temp12 = {
+       .m = (struct hoge){1,3},
+       .c = (int)&temp4,
+    };
+
+    printf("#0070:1: %d\n",temp1.a);
+    printf("#0071:1: %d\n",temp1.e);
+    printf("#0072:1: %d\n",temp1.b);
+    printf("#0073:2: %d\n",temp2.c);
+    printf("#0074:2: %d\n",temp2.e);
+    printf("#0075:2: %d\n",temp2.b);
+    printf("#0076:2: %d\n",(void*)temp3.c==b);
+    printf("#0077:2: %d\n",temp3.c==(int)b);
+    printf("#0078:2: %d\n",temp3.a==(int)&b);
+    printf("#0079:2: %d\n",temp4.m.j);
+    printf("#0080:2: %d\n",temp5.m.j);
+    printf("#0081:2: %d\n",temp11.m.j);
+    printf("#0082:2: %d\n",temp12.m.k);
+    printf("#0083:2: %d\n",temp12.m.j);
+    printf("#0084:2: %d\n",temp11.c==(int)&b);
+    printf("#0085:2: %d\n",temp8.e);
+    printf("#0086:2: %d\n",temp6.e);
+    main7();
+    main8();
+    linux_kernel();
+    return 0;
 }