Mercurial > hg > CbC > old > device
changeset 820:9598ecec0af5
rvalue, RSTRUCT, non parse mode
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 26 Nov 2010 19:38:40 +0900 |
parents | dc8df3977c17 |
children | fe751ca164a2 |
files | Changes mc-codegen.c mc-parse.c test/bitfield.c test/bitfield1.c test/code-gen.c test/tmp7.c |
diffstat | 7 files changed, 85 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Fri Nov 26 16:32:33 2010 +0900 +++ b/Changes Fri Nov 26 19:38:40 2010 +0900 @@ -9952,4 +9952,10 @@ prindirect でも、同じ混乱があるらしい。それで、lvar の最適化ができなくなっている。 - +あぁ、やっぱり、rvalue が mc-inline に現れるのは変なのね。たとえ、LVAR/RLVAR +最適化のためであっても。 + +ravlue が、indirect を付加してしまうので、動作がが変。 non parse mode の整合性が +取れない。 + +
--- a/mc-codegen.c Fri Nov 26 16:32:33 2010 +0900 +++ b/mc-codegen.c Fri Nov 26 19:38:40 2010 +0900 @@ -3332,6 +3332,21 @@ if (ctmode & RESTRICT_BIT) set_attr(n,RESTRICT,0); } +static int +struct_align_offset(int t,int offset) +{ + int strtype=0; + if (t>0 && (car(t)==STRUCT||car(t)==UNION)) + strtype=1; + int sz = size(t); + if (lp64 && (sz%size_of_longlong==0)) { + offset = align(offset,size_of_longlong); + } else if (sz%size_of_int==0||strtype) { + offset = align(offset,struct_align); + } + return offset; +} + /* define symbol name contents depending on stmode, mode @@ -3386,16 +3401,9 @@ error(-1); #endif } else { + sz = size(type0); #if STRUCT_ALIGN - int strtype=0; - if (type0>0 && (car(type0)==STRUCT||car(type0)==UNION)) - strtype=1; - sz = size(type0); - if (lp64 && (sz%size_of_longlong==0)) { - disp = align(disp,size_of_longlong); - } else if ((sz%size_of_int==0)||strtype) { - disp = align(disp,struct_align); - } + disp = struct_align_offset(type0,disp); #endif if ((align0=attr_value_in_list(attr,ALIGNED))) { int hoge = disp; @@ -3405,7 +3413,6 @@ disp = align(disp,align0); if (lsrc && hoge!=disp) printf("# field %s %d->%d (align %d)\n",n->nm,hoge,disp,align0); - } } if (n!=&null_nptr) @@ -3943,21 +3950,14 @@ extern int assign_data(int e, int t, int v,int offset) { - int ass,sz,bfd; + int ass,bfd; int v0 = car(v); NMTBL *n = ncaddr(v); if (inmode) error(-1); #if STRUCT_ALIGN - if (t!=EMPTY) { - int strtype=0; - if (t>0 && (car(t)==STRUCT||car(t)==UNION)) - strtype=1; - sz = size(t); - if (sz%size_of_int==0||strtype) { - offset = align(offset,struct_align); - } - } + if (t!=EMPTY) + offset = struct_align_offset(t,offset); #endif if (car(e)==ADDRESS||car(e)==GVAR) { if (scalar(t)) { @@ -4003,7 +4003,7 @@ return offset; } if (t>0&&car(t)==BIT_FIELD) { - sz = 0; + int sz = 0; bfd = cadr(caddr(t)); /* bit_field_disp */ #if BIT_FIELD_CODE code_bit_field_disp(t,&offset,&bfd,&sz); @@ -4379,8 +4379,8 @@ if(car(e)==INDIRECT) return cadr(e); return list2(ADDRESS,e); case STRUCT: case UNION: - // RINDIRECT がいいのかも - if(car(e)==RSTRUCT) return e; /* ??? */ + if(car(e)==RSTRUCT) return e; /* to make idempotent */ + if(car(e)==INDIRECT) return cadr(e); return list3(RSTRUCT,e,cadr(type) /* size */); case FUNCTION: type=set_type_with_attr(cadr(type0),type); @@ -4472,7 +4472,7 @@ indop(int e) { int type0 = type_value(type); - if(type0!=INT&&type0!=UNSIGNED) { + if(type0!=INT&&type0!=UNSIGNED&&type0!=LONGLONG&&type0!=ULONGLONG) { if(car(type0)==POINTER) type=set_type_with_attr(cadr(type),type); else if(car(type0)==CODE || car(type0)==FUNCTION) {
--- a/mc-parse.c Fri Nov 26 16:32:33 2010 +0900 +++ b/mc-parse.c Fri Nov 26 19:38:40 2010 +0900 @@ -2224,6 +2224,9 @@ args = 0; disp=0; arg_register(fnptr,inmode); + // arg_register changes first arguments offset, we have to follow. + // In inmode case, we don't have to do this, because it was IVAR. + if (!inmode && struct_return) { cadr(car(struct_return)) = ncadddr(fnptr->dsp)->dsp;} typedefed=0; conv->function_(fnptr,sd); conv->lc_(); @@ -4276,13 +4279,15 @@ type = t; return e1; } - e1=expr13(); + e1=expr13(); // (type) expr if (inmode) { e1 = list4(CAST,e1,t,type); type = t; return e1; - } else + } else { + e1 = rvalue(e1); return correct_type(e1,t); + } } else if (sym==LC) { // statement in expression (GNU extension) // a = {hoge(); 1;}
--- a/test/bitfield.c Fri Nov 26 16:32:33 2010 +0900 +++ b/test/bitfield.c Fri Nov 26 19:38:40 2010 +0900 @@ -1,5 +1,5 @@ int printf(const char *format, ...); - +typedef unsigned long long ULL; typedef union { struct _PTE { @@ -556,21 +556,21 @@ printf("#0555:m5c-00:%d\n",ii.b.a); ll1.b.v = 0x123456defLL; - printf("#0558:m5c-01:%llx\n",ll1.b.v); + printf("#0558:m5c-01:%llx\n",(ULL)ll1.b.v); printf("#0559:m5c-02:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll1.a[0],ll1.a[1],ll1.a[2],ll1.a[3], ll1.a[4],ll1.a[5],ll1.a[6],ll1.a[7] ); ll1.b.v = 0; printf("#0564:m5c-01:%llx\n", - ll1.b.w = 0x123456defLL); + (ULL)(ll1.b.w = 0x123456defLL)); printf("#0566:m5c-02:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll1.a[0],ll1.a[1],ll1.a[2],ll1.a[3], ll1.a[4],ll1.a[5],ll1.a[6],ll1.a[7] ); ll1.b.w = 0; printf("#0571:m5c-01:%llx\n", - ll1.b.x = -0x12456defLL); + (ULL)(ll1.b.x = -0x12456defLL)); printf("#0573:m5c-02:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll1.a[0],ll1.a[1],ll1.a[2],ll1.a[3], ll1.a[4],ll1.a[5],ll1.a[6],ll1.a[7] @@ -578,22 +578,22 @@ ll1.b.x = 0; printf("#0579:m5c-01:%llx\n", - ll0.b.v = 0x123457cdefLL); - printf("#0581:m5c-01:%llx\n",ll0.b.v); + (ULL)(ll0.b.v = 0x123457cdefLL)); + printf("#0581:m5c-01:%llx\n",(ULL)ll0.b.v); printf("#0582:m5c-02:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll0.a[0],ll0.a[1],ll0.a[2],ll0.a[3], ll0.a[4],ll0.a[5],ll0.a[6],ll0.a[7] ); ll0.b.v = 0; printf("#0587:m5c-01:%llx\n", - ll0.b.w = 0x1234abcdefLL); + (ULL)(ll0.b.w = 0x1234abcdefLL)); printf("#0589:m5c-02:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll0.a[0],ll0.a[1],ll0.a[2],ll0.a[3], ll0.a[4],ll0.a[5],ll0.a[6],ll0.a[7] ); ll0.b.w = 0; printf("#0594:m5c-01:%llx\n", - ll0.b.x = 0x1234abcdefLL); + (ULL)(ll0.b.x = 0x1234abcdefLL)); printf("#0596:m5c-02:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll0.a[0],ll0.a[1],ll0.a[2],ll0.a[3], ll0.a[4],ll0.a[5],ll0.a[6],ll0.a[7] @@ -601,22 +601,22 @@ ll0.b.x = 0; printf("#0602:m5c-01:%llx\n", - ll.b.v = 0x12389abcdefLL); - printf("#0604:m5c-1:%llx\n",ll.b.v); + (ULL)(ll.b.v = 0x12389abcdefLL)); + printf("#0604:m5c-1:%llx\n",(ULL)ll.b.v); printf("#0605:m5c-2:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll.a[0],ll.a[1],ll.a[2],ll.a[3], ll.a[4],ll.a[5],ll.a[6],ll.a[7] ); ll.b.v = 0; printf("#0610:m5c-01:%llx\n", - ll.b.w = 0x12389abcdefLL); + (ULL)(ll.b.w = 0x12389abcdefLL)); printf("#0612:m5c-2:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll.a[0],ll.a[1],ll.a[2],ll.a[3], ll.a[4],ll.a[5],ll.a[6],ll.a[7] ); ll.b.w = 0; printf("#0617:m5c-01:%llx\n", - ll.b.x = 0x12389abcdefLL); + (ULL)(ll.b.x = 0x12389abcdefLL)); printf("#0619:m5c-2:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll.a[0],ll.a[1],ll.a[2],ll.a[3], ll.a[4],ll.a[5],ll.a[6],ll.a[7] @@ -698,7 +698,7 @@ printf("#0697:00:%d\n",ii.b.a); ll1.b.v = m1; - printf("#0700:01:%llx\n",ll1.b.v); + printf("#0700:01:%llx\n",(ULL)ll1.b.v); printf("#0701:02:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll1.a[0],ll1.a[1],ll1.a[2],ll1.a[3], ll1.a[4],ll1.a[5],ll1.a[6],ll1.a[7] @@ -718,7 +718,7 @@ ll1.b.x = zero; ll0.b.v = m1; - printf("#0720:01:%llx\n",ll0.b.v); + printf("#0720:01:%llx\n",(ULL)ll0.b.v); printf("#0721:02:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll0.a[0],ll0.a[1],ll0.a[2],ll0.a[3], ll0.a[4],ll0.a[5],ll0.a[6],ll0.a[7] @@ -738,7 +738,7 @@ ll0.b.x = zero; ll.b.v = m1; - printf("#0740:1:%llx\n",ll.b.v); + printf("#0740:1:%llx\n",(ULL)ll.b.v); printf("#0741:2:%16x %16x %16x %16x %16x %16x %16x %16x\n", ll.a[0],ll.a[1],ll.a[2],ll.a[3], ll.a[4],ll.a[5],ll.a[6],ll.a[7]
--- a/test/bitfield1.c Fri Nov 26 16:32:33 2010 +0900 +++ b/test/bitfield1.c Fri Nov 26 19:38:40 2010 +0900 @@ -1,5 +1,5 @@ int printf(const char *format, ...); - +typedef long long unsigned LLU; #ifndef INLINE #define INLINE #endif @@ -84,7 +84,7 @@ printf("#0083:%d\n",a.i); ll1.b.v = -1; - printf("#0086:01:%llx\n",ll1.b.v); + printf("#0086:01:%llx\n",(LLU)ll1.b.v); printf("#0087:02:"); for(i=0;i<32;i++) printf("#0082:%02x",ll1.a[i]); printf("#0082:\n"); ll1.b.v = 0; ll1.b.w = -1; @@ -94,7 +94,7 @@ printf("#0093:02:"); for(i=0;i<32;i++) printf("#0088:%02x",ll1.a[i]); printf("#0088:\n"); ll0.b.v = -1; - printf("#0096:01:%llx\n",ll0.b.v); + printf("#0096:01:%llx\n",(LLU)ll0.b.v); printf("#0097:02:"); for(i=0;i<32;i++) printf("#0092:%02x",ll0.a[i]); printf("#0092:\n"); ll0.b.v = 0; ll0.b.w = -1; @@ -104,7 +104,7 @@ printf("#0103:02:"); for(i=0;i<32;i++) printf("#0098:%02x",ll0.a[i]); printf("#0098:\n"); ll.b.v = -1; - printf("#0106:1:%llx\n",ll.b.v); + printf("#0106:1:%llx\n",(LLU)ll.b.v); printf("#0107:02:"); for(i=0;i<32;i++) printf("#0102:%02x",ll.a[i]); printf("#0102:\n"); ll.b.v = 0; ll.b.w = -1; @@ -208,7 +208,7 @@ ll.a[0],ll.a[1],ll.a[2],ll.a[3], ll.a[4],ll.a[5],ll.a[6],ll.a[7] ); - printf("#0210: ll.b.v=%lld ll.b.w=%lld ll.b.x=%lld\n",ll.b.v,ll.b.w,ll.b.x); + printf("#0210: ll.b.v=%lld ll.b.w=%lld ll.b.x=%lld\n",(LLU)ll.b.v,(LLU)ll.b.w,(LLU)ll.b.x); } ll.a[i]=0; }
--- a/test/code-gen.c Fri Nov 26 16:32:33 2010 +0900 +++ b/test/code-gen.c Fri Nov 26 19:38:40 2010 +0900 @@ -3528,7 +3528,7 @@ return (float)d; } -INLINE static float +INLINE static double f2d(float d) { return (double)d; }
--- a/test/tmp7.c Fri Nov 26 16:32:33 2010 +0900 +++ b/test/tmp7.c Fri Nov 26 19:38:40 2010 +0900 @@ -56,7 +56,7 @@ a2.b[1]=555; return a2; } - +INLINE void main6(); INLINE void main1(struct aa a1) @@ -132,9 +132,34 @@ main5(bbb,bbb1).b[0]); printf("#0132:main5-1 %d\n", main5(bbb,main5(aaa,aaa1)).b[0]); + + main6(); return 0; } +typedef struct { + char x,y; +} s; + +s P[15],Q[15]; + +static void +l(s p, s q){ + printf("%d %d\n", p.x, p.y); +} + +INLINE void +main6() +{ + int j = 0; + P[j].x = Q[j].x = 10; + P[j].y = Q[j].y = -7; + + l(P[j],Q[j]); +} + + + INLINE void tmp() {