changeset 896:d712ee10feb7

local_nptr for locally defined struct
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 06 Apr 2014 19:20:58 +0900
parents e9ba80b0827d
children 66f32d0af4d2
files mc-parse.c test/cext.c test/cloop.c test/obsf.c test/obsf2.c test/strinit.c test/tmp11.c test/tmp7.c test/tstdarg.c
diffstat 9 files changed, 88 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/mc-parse.c	Sun Apr 06 17:11:44 2014 +0900
+++ b/mc-parse.c	Sun Apr 06 19:20:58 2014 +0900
@@ -967,6 +967,7 @@
         v = list3n(n->sc,n->dsp,n);
         if (sym==ASS && n!=&null_nptr) { 
             conv->op_(sym);
+            local_nptr = n; local_struct_offset = 0;
             init = decl_data(type,v,0,0); data_closing(v); 
         }
         if (inmode && (mode==LDECL||mode==LLDECL||mode==STADECL)) { 
@@ -989,6 +990,7 @@
             v = list3n(n->sc,n->dsp,n);
             if (sym==ASS && n!=&null_nptr) {
                 conv->op_(sym);
+                local_nptr = n; local_struct_offset = 0;
                 init = decl_data(type,v,0,0);data_closing(v);
             }
             if (inmode && mode==LDECL) {
@@ -4135,13 +4137,12 @@
         //    initializer
         //             q->lock = (spinlock_t) { };
         conv->lc_();
-        nptr0 = get_nptr(); // should be freed in a scope?
-                            // in case of inline, we cannot
+        nptr0 = get_nptr(); 
         nptr0->nm = "";
         nptr0->sc = EMPTY;
         nptr0->attr = 0;
         type = nptr0->ty = t;
-        def(nptr0,0);
+        int local_offset;
         if (mode==GDECL||inmode) {
             int e2,e3;
             e1 = size(type);
@@ -4155,14 +4156,27 @@
                 e1 = list4(CAST,e1,t,t); // only for cast syntax
             }
         } else {
-            e1 = list3n(nptr0->sc,nptr0->dsp,nptr0);
+            if (!local_nptr) {
+                local_nptr = nptr0;
+                int smode = mode; mode = LDECL;
+                def(nptr0,0);
+                mode = smode;
+                local_struct_offset = 0;
+            }
+            e1 = list3n(local_nptr->sc,local_nptr->dsp,local_nptr);
 #if LOCAL_STRUCT_INIT_STATIC 
             local_struct_static(e1); 
 #else
-            decl_data_field(type,e1,0);
+            local_offset = local_struct_offset;
+            int offset = decl_data_field(type,e1,local_struct_offset);
+            if (offset==local_struct_offset) {
+                int sz = size(type);
+                zfill(e1,offset,sz);
+                local_struct_offset = offset + sz;
+            }
 #endif
         }
-        if (mode==STAT && decl_str_init) gen_delayed_decl_data(e1,0);
+        if (mode==STAT && decl_str_init) gen_delayed_decl_data(e1,local_offset);
         if (init_vars && mode!=LDECL) {
             emit_init_vars();
         }
--- a/test/cext.c	Sun Apr 06 17:11:44 2014 +0900
+++ b/test/cext.c	Sun Apr 06 19:20:58 2014 +0900
@@ -8,7 +8,7 @@
 {
     char *s = name;
     char *q = current_file_dir;
-    printf("%s and %s\n",s,q);
+    printf("#0010:%s and %s\n",s,q);
 }
 
 main()
@@ -16,19 +16,19 @@
     int i,k; unsigned uk;
 
     char c = -3;
-    printf("char is %ssigned\n", c==256-3? "un":"");
+    printf("#0018:char is %ssigned\n", c==256-3? "un":"");
 
     for(i=-3;i<4;i++) {  
         k = (char) i; 
         uk = (unsigned char) i; 
-        printf("#0011:%d %u\n",k,uk);
+        printf("#0023:%d %u\n",k,uk);
         k = (short) i; 
         uk = (unsigned short) i; 
-        printf("#0014:%d %u\n",k,uk);
+        printf("#0026:%d %u\n",k,uk);
     }
     u = (unsigned) -23432;
 
-    printf("#0018:%d\n",u/(8048+5));
+    printf("#0030:%d\n",u/(8048+5));
 
     current_file_dir[0]  = 'k';
     current_file_dir[1]  = 'a';
--- a/test/cloop.c	Sun Apr 06 17:11:44 2014 +0900
+++ b/test/cloop.c	Sun Apr 06 19:20:58 2014 +0900
@@ -10,18 +10,18 @@
 {
     int i;
     for( i = 0;i<10;i++) {
-        printf("%d ",c[i]);
+        printf("#0012:%d ",c[i]);
     }
     for( i = 0;i<10;i++) {
-        printf("%d ",s[i]);
+        printf("#0015:%d ",s[i]);
     }
     for( i = 0;i<10;i++) {
-        printf("%d ",j[i]);
+        printf("#0018:%d ",j[i]);
     }
     for( i = 0;i<10;i++) {
-        printf("%lld ",l[i]);
+        printf("#0021:%lld ",l[i]);
     }
-    printf("\n");
+    printf("#0023:\n");
 }
 
 void
@@ -30,19 +30,19 @@
     int i;
     for( i = 0;i<10;i++) {
         c[i] = i;
-        printf("\n");
+        printf("#0032:\n");
     }
     for( i = 0;i<10;i++) {
         s[i] = i;
-        printf("\n");
+        printf("#0036:\n");
     }
     for( i = 0;i<10;i++) {
         j[i] = i;
-        printf("\n");
+        printf("#0040:\n");
     }
     for( i = 0;i<10;i++) {
         l[i] = i;
-        printf("\n");
+        printf("#0044:\n");
     }
 }
 
--- a/test/obsf.c	Sun Apr 06 17:11:44 2014 +0900
+++ b/test/obsf.c	Sun Apr 06 19:20:58 2014 +0900
@@ -4,7 +4,7 @@
 char **_a; char **aa;
 {
 long _ = (long)_a; char *a = (char *)aa;
-// printf("#0005:%d %d %d\n",t,_,a);
+// printf("#0006:%d %d %d\n",t,_,a);
 return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
 main(-86, 0, a+1 )+a)):1,t<_?main(t+1, _, a ):3,main ( -94, -27+t, a
 )&&t == 2 ?_<13 ?main ( 2, _+1, "%s %d %d\n" ):9:16:t<0?t<-72?main(_,
--- a/test/obsf2.c	Sun Apr 06 17:11:44 2014 +0900
+++ b/test/obsf2.c	Sun Apr 06 19:20:58 2014 +0900
@@ -86,21 +86,21 @@
     j=(i+1)%10;
     e=0;
     l(P[j],Q[j]);
-printf("#0087:main0: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[j].x,Q[j].y);
+printf("#0088:main0: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[j].x,Q[j].y);
     if(--k<=0){
       r(&R,P[i]);
       r(&S,Q[i ]);
-printf("#0091:main1: R.x %02x R.y %02x S.x %02x S.y %02x\n",R.x,R.y,S.x,S.y);
+printf("#0092:main1: R.x %02x R.y %02x S.x %02x S.y %02x\n",R.x,R.y,S.x,S.y);
       k=10;
     }
     d(&P[j],P[i],R);
-printf("#0095:main2: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[i].x,Q[i].y);
+printf("#0096:main2: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[i].x,Q[i].y);
     d(&Q[j],Q[i],S);
-printf("#0097:main3: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[i].x,Q[i].y);
+printf("#0098:main3: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[i].x,Q[i].y);
     i=j;
     e=1;
     l(P[j],Q[j]);
-printf("#0101:main4: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[i].x,Q[i].y);
+printf("#0102:main4: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[i].x,Q[i].y);
     b=83;
 if (0)
     for (a=0; a<sizeof M; a++){
--- a/test/strinit.c	Sun Apr 06 17:11:44 2014 +0900
+++ b/test/strinit.c	Sun Apr 06 19:20:58 2014 +0900
@@ -236,10 +236,10 @@
      f(5,(struct arg){.fuga = 3,.aho=5});
      f(6,(struct arg){.hage = 3});
      f(7,(struct arg){});
-     printf("#0226:%d %d\n",a.aho,((struct arg){.aho=120, .hage=55}).aho); 
-     printf("#0227:%d %d\n",a.aho,((struct arg){.aho=120, .hage=55}).fuga); 
+     printf("#0238:%d %d\n",a.aho,((struct arg){.aho=120, .hage=55}).aho); 
+     printf("#0239:%d %d\n",a.aho,((struct arg){.aho=120, .hage=55}).fuga); 
      return 0;
-     printf("#0229:%d %d\n",a.aho,((struct arg){.aho=120, .hage=55}).fuga);   // unexecuted code
+     printf("#0241:%d %d\n",a.aho,((struct arg){.aho=120, .hage=55}).fuga);   // unexecuted code
 }
 
 int
@@ -264,45 +264,45 @@
     };
     int c[3] = {1,2,3};
 
-    printf("#0251:1: %ld\n",temp1.a);
-    printf("#0252:1: %ld\n",temp1.e);
-    printf("#0253:1: %ld\n",temp1.b);
-    printf("#0254:2: %ld\n",temp2.c);
-    printf("#0255:2: %ld\n",temp2.e);
-    printf("#0256:2: %ld\n",temp2.b); // non explict initialized  value
-    printf("#0257:2: %d\n",(void*)temp3.c==b);
-    printf("#0258:2: %d\n",temp3.c==(long)b);
-    printf("#0259:2: %d\n",temp3.a==(long)&b);
-    printf("#0260:2: %ld\n",temp4.m.j);
-    printf("#0261:2: %ld\n",temp5.m.j);
-    printf("#0262:2: %ld\n",temp11.m.j);
-    printf("#0263:2: %ld\n",temp12.m.k);
-    printf("#0264:2: %ld\n",temp12.m.j);
-    printf("#0265:2: %d\n",temp11.c==(long)&b);
-    printf("#0266:2: %ld\n",temp8.e);
-    printf("#0267:2: %ld\n",temp6.e);
+    printf("#0266:1: %ld\n",temp1.a);
+    printf("#0267:1: %ld\n",temp1.e);
+    printf("#0268:1: %ld\n",temp1.b);
+    printf("#0269:2: %ld\n",temp2.c);
+    printf("#0270:2: %ld\n",temp2.e);
+    printf("#0271:2: %ld\n",temp2.b); // non explict initialized  value
+    printf("#0272:2: %d\n",(void*)temp3.c==b);
+    printf("#0273:2: %d\n",temp3.c==(long)b);
+    printf("#0274:2: %d\n",temp3.a==(long)&b);
+    printf("#0275:2: %ld\n",temp4.m.j);
+    printf("#0276:2: %ld\n",temp5.m.j);
+    printf("#0277:2: %ld\n",temp11.m.j);
+    printf("#0278:2: %ld\n",temp12.m.k);
+    printf("#0279:2: %ld\n",temp12.m.j);
+    printf("#0280:2: %d\n",temp11.c==(long)&b);
+    printf("#0281:2: %ld\n",temp8.e);
+    printf("#0282:2: %ld\n",temp6.e);
     main7();
     main8();
     linux_kernel();
     int i=1,j=2;
-    printf("#0272:%d %d\n",i,j);
+    printf("#0287:%d %d\n",i,j);
 
-    printf("#0274:b %d %d %d\n",b[0],b[1],b[2]);
-    printf("#0275:c %d %d %d\n",c[0],c[1],c[2]);
+    printf("#0289:b %d %d %d\n",b[0],b[1],b[2]);
+    printf("#0290:c %d %d %d\n",c[0],c[1],c[2]);
 
     struct test t = {1,2,3};
-    printf("#0278:t %d %d %d\n",t.a,t.b,t.c);
+    printf("#0293:t %d %d %d\n",t.a,t.b,t.c);
 
     struct test3 {
         int a,b,c;
     } *p, q, d = {
         1,2,3,
     };
-    printf("#0285:d %d %d %d\n",d.a,d.b,d.c);
+    printf("#0300:d %d %d %d\n",d.a,d.b,d.c);
     p = & (struct test3) {1,2,3};
-    printf("#0287:p %d %d %d\n",p->a,p->b,p->c);
+    printf("#0302:p %d %d %d\n",p->a,p->b,p->c);
     q =  (struct test3) {1,2,3};
-    printf("#0289:q %d %d %d\n",q.a,q.b,q.c);
+    printf("#0304:q %d %d %d\n",q.a,q.b,q.c);
 
     struct test4 {
         struct test5 {
@@ -311,14 +311,14 @@
     } u = { .d = {1,2,3} };
     struct test4 v = { .d = (struct test5){1,2,3} };
     
-    printf("#0298:u %d %d %d\n",u.d.a,u.d.b,u.d.c);
+    printf("#0313:u %d %d %d\n",u.d.a,u.d.b,u.d.c);
 
-    printf("#0300:v %d %d %d\n",v.d.a,v.d.b,v.d.c);
+    printf("#0315:v %d %d %d\n",v.d.a,v.d.b,v.d.c);
 
-    printf("#0300:v %ld\n",temp10.a);
-    printf("#0300:v %ld\n",temp10.m.k);
-    printf("#0300:v %ld\n",temp10.m.j);
-    printf("#0300:v %ld\n",temp10.e);
+    printf("#0317:v %ld\n",temp10.a);
+    printf("#0318:v %ld\n",temp10.m.k);
+    printf("#0319:v %ld\n",temp10.m.j);
+    printf("#0320:v %ld\n",temp10.e);
 
 
     return 0;
--- a/test/tmp11.c	Sun Apr 06 17:11:44 2014 +0900
+++ b/test/tmp11.c	Sun Apr 06 19:20:58 2014 +0900
@@ -8,13 +8,13 @@
 
 NMTBL *
 test2(char *n) {
-    printf("#0009:s %s\n",n);
+    printf("#0010:s %s\n",n);
     return a;
 }
 
 int
 test0(int a,int b,int c) {
-    printf("#0015:a %d b %d c %d\n",a,b,c);
+    printf("#0016:a %d b %d c %d\n",a,b,c);
     return 0;
 }
 
@@ -38,16 +38,16 @@
     a = &f;
     b = test2("test");
     d = test1(1,2,3);
-    printf("#0033:return %d\n",d);
+    printf("#0040:return %d\n",d);
 
     NMTBL **p = (NMTBL**)&heap[2];
     *p = &f;
     b = &f;
     int e = 0;
-    printf("f.nm          %s\n",f.nm);
-    printf("b->nm         %s\n",b->nm);
-    printf("(*p)->nm      %s\n",(*p)->nm);
-    printf("ncaddr(e)->nm %s\n",ncaddr(e)->nm);
+    printf("#0046:f.nm          %s\n",f.nm);
+    printf("#0047:b->nm         %s\n",b->nm);
+    printf("#0048:(*p)->nm      %s\n",(*p)->nm);
+    printf("#0049:ncaddr(e)->nm %s\n",ncaddr(e)->nm);
 
     return d;
 }
--- a/test/tmp7.c	Sun Apr 06 17:11:44 2014 +0900
+++ b/test/tmp7.c	Sun Apr 06 19:20:58 2014 +0900
@@ -146,7 +146,7 @@
 
 static void
 l(s p, s q){
-    printf("%d %d\n", p.x, p.y);
+    printf("#0148:%d %d\n", p.x, p.y);
 }
 
 INLINE void
@@ -171,6 +171,6 @@
 main7(struct aa a1)
 {
     struct aa b = main0(0xff);
-    printf("#0065:main7 b.a[55] %d\n",b.a[55]);
+    printf("#0173:main7 b.a[55] %d\n",b.a[55]);
 }
 
--- a/test/tstdarg.c	Sun Apr 06 17:11:44 2014 +0900
+++ b/test/tstdarg.c	Sun Apr 06 19:20:58 2014 +0900
@@ -43,29 +43,29 @@
     while((t= *numtypes++)) {
         if (t=='i') {
             i = va_arg(ap,int);
-            printf("#0020:int arg: %d\n",i);
+            printf("#0045:int arg: %d\n",i);
 print(&ap);
 
 #if 0        /*  ‘float’ is promoted to ‘double’ when passed through ‘...’ */
         } else if (t=='f') {
             f = va_arg(ap,float);
-            printf("#0025:float arg: %g\n",f);
+            printf("#0051:float arg: %g\n",f);
 #endif
         } else if (t=='d') {
             d = va_arg(ap,double);
-            printf("#0029:double arg: %g\n",d);
+            printf("#0055:double arg: %g\n",d);
 print(&ap);
         } else if (t=='l') {
             l = va_arg(ap,long long);
-            printf("#0032:long long arg: %lld\n",l);
+            printf("#0059:long long arg: %lld\n",l);
 print(&ap);
         } else if (t=='s') {
             s = va_arg(ap,char *);
-            printf("#0035:char *arg: %s\n",s);
+            printf("#0063:char *arg: %s\n",s);
 print(&ap);
         } else {
             s = va_arg(ap,char *);
-            printf("#0038:arg: error\n");
+            printf("#0067:arg: error\n");
 print(&ap);
         }
     }