changeset 701:bf4fd39737e9

fix static in parse mode
author kono
date Tue, 23 Oct 2007 09:58:37 +0900
parents 22e0330a6d5b
children 8eadf0db2970
files .gdbinit Makefile mc-codegen.c mc-codegen.h mc-inline.c mc-parse.c
diffstat 6 files changed, 41 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Mon Oct 22 01:47:28 2007 +0900
+++ b/.gdbinit	Tue Oct 23 09:58:37 2007 +0900
@@ -16,7 +16,8 @@
 # r -s test/tmp7.c
 # r -s test/tmp6.c
 # r -s test/call.c
-r -s test/code-gen-all.c
+r -s test/static.c
+# r -s test/code-gen-all.c
 # r -s mc-code-powerpc.c
 # r -s test/strinit.c
 # r -s test/arg.c
--- a/Makefile	Mon Oct 22 01:47:28 2007 +0900
+++ b/Makefile	Tue Oct 23 09:58:37 2007 +0900
@@ -91,6 +91,7 @@
 	make check TARGET=test/tmp12
 	make check TARGET=test/tmp5
 	make check TARGET=test/tmp7
+	make check-inline TARGET=test/tmp7
 	make check TARGET=test/tmp8
 	make check TARGET=test/tmp9
 	make check TARGET=test/enum
--- a/mc-codegen.c	Mon Oct 22 01:47:28 2007 +0900
+++ b/mc-codegen.c	Tue Oct 23 09:58:37 2007 +0900
@@ -59,7 +59,6 @@
 static int register_to_lvar(int e);
 static void remove0(int *parent,int e) ;
 static void sassign(int e1);
-static int gen_decl_data(int e);
 static int gen_decl_data0(int v,int target_type,int init,int offset);
 
 #if FLOAT_CODE
@@ -609,7 +608,7 @@
 	e2 = correct_type(e2,caddr(e1));
 	continue;
     case DECL_DATA:
-	e1 =  gen_decl_data(e1);
+	e1 =  gen_decl_data(e1,0);
 	return e1;
     case ST_DECL:         st_decl(e1);	break;
     case ST_IF:           st_if(e1);	break;
@@ -3710,8 +3709,8 @@
     return offset;
 }
 
-static int
-gen_decl_data(int e)
+extern int
+gen_decl_data(int e,int v)
 {
     NMTBL *nptr0;
     int t = caddr(e);
@@ -3720,18 +3719,24 @@
     int sinit_vars = init_vars;
     init_vars = 0;
 
-    nptr0 = get_nptr(); 
-    nptr0->nm = "";
-    nptr0->sc = LVAR;
-    nptr0->attr = 0;
-    type = nptr0->ty = t;
+    type = t;
     sz = size(type);
-    nptr0->dsp = new_lvar_align(sz,16);
-
-    e1 = list3(RSTRUCT,list3(
-	nptr0->sc,nptr0->dsp,(int)nptr0),sz);
-
-    gen_decl_data0(list3(nptr0->sc,nptr0->dsp,(int)nptr0),t,e,offset);
+
+    if (v==0) {
+	nptr0 = get_nptr(); 
+	nptr0->nm = "";
+	nptr0->sc = LVAR;
+	nptr0->attr = 0;
+	nptr0->ty = t;
+	nptr0->dsp = new_lvar_align(sz,16);
+	e1 = list3(RSTRUCT,list3(
+	    nptr0->sc,nptr0->dsp,(int)nptr0),sz);
+	v = list3(nptr0->sc,nptr0->dsp,(int)nptr0);
+    } else {
+	e1 = 0;
+    }
+
+    gen_decl_data0(v,t,e,offset);
 
     if (init_vars) emit_init_vars();
     g_expr0(e1);
--- a/mc-codegen.h	Mon Oct 22 01:47:28 2007 +0900
+++ b/mc-codegen.h	Tue Oct 23 09:58:37 2007 +0900
@@ -107,6 +107,7 @@
 extern int type_of_bop(int op);
 extern int type_of_conv(int op);
 extern int type_compatible(int t1, int t2);
+extern int gen_decl_data(int e,int v);
 
 /* used by mc-code-* */
 
--- a/mc-inline.c	Mon Oct 22 01:47:28 2007 +0900
+++ b/mc-inline.c	Tue Oct 23 09:58:37 2007 +0900
@@ -915,8 +915,6 @@
 	mode = smode;
 	init_vars = save_init_vars;
 	return pexpr(cadr(e));
-//    case LLDECL:          LLDECL is mode, not stmode (bad design)
-//	v = list2(FLABEL,fwdlabel()); break;
 #if 1
     case REGISTER:
 	switch(n->ty) {
@@ -934,7 +932,19 @@
 	}
 	break;
 #endif
+//    case LLDECL:          LLDECL is mode, not stmode (bad design)
+//	v = list2(FLABEL,fwdlabel()); break;
     default:
+	if (mode==STADECL) {
+	    if (init) {
+		v = list3(GVAR,0,(int)n);
+		gen_decl_data(init,v);
+	    }
+	    stmode = sstmode;
+	    mode = smode;
+	    init_vars = save_init_vars;
+	    return pexpr(cadr(e));
+	}
 	if (n->sc==FLABEL)
 	    v = list3(LVAR,fwdlabel(),(int)n);
 	else
--- a/mc-parse.c	Mon Oct 22 01:47:28 2007 +0900
+++ b/mc-parse.c	Tue Oct 23 09:58:37 2007 +0900
@@ -941,9 +941,7 @@
 	    conv->op_(sym);
 	    init = decl_data(type,v,0,0); data_closing(v); 
 	}
-	if (inmode && (mode==LDECL||mode==LLDECL)) { 
-	    // NMTBL *n1 = get_nptr();
-	    // *n1 = *n; // to prevent rewind in leave scope
+	if (inmode && (mode==LDECL||mode==LLDECL||mode==STADECL)) { 
 	    parse = list5(ST_DECL,parse,(int)n,list3(mode,stmode,ctmode),init);
 	}
 	while(sym==COMMA) {
@@ -1626,6 +1624,7 @@
     NMTBL *nptr0,*n = (NMTBL*)caddr(v);
     int sz = size(type),offset=0;
     int smode = mode;
+    int v0;
     // uninitialized part should be 0.
     // local var init cannot postponed because of assign_expr0/type
     //  if initialization contains expressions,
@@ -1639,11 +1638,11 @@
     nptr0=new_static_name("__lstruct",'_');
     def(nptr0,0);
     mode=smode;
-    v = list3(GVAR,0,(int)nptr0);
+    v0 = list3(GVAR,0,(int)nptr0);
     //nptr0->next = local_static_list; local_static_list = nptr0;
     //nptr0->sc = STATIC;
     //nptr0->ty = t = type;
-    decl_data_field(type,v,offset);
+    decl_data_field(type,v0,offset);
     // do struct assignment before flushed assignment expression
     init_vars = list2(
 	list4(STASS,
@@ -1652,7 +1651,7 @@
 		    list3(ADD,list3(IVAR,n->dsp,0),list2(CONST,offset)):
 		    list3(IVAR,n->dsp,0)):
 		list3(LVAR,n->dsp+offset,0),
-	    list3(RSTRUCT,v,sz),sz),
+	    list3(RSTRUCT,v0,sz),sz),
 	init_vars);
     mode=STADECL;
     flush_delayed_decl_data(v);