Mercurial > hg > CbC > old > device
changeset 460:2859bb9d5fb3
volatile/const
author | kono |
---|---|
date | Thu, 02 Dec 2004 12:07:16 +0900 |
parents | 9fc266d4010f |
children | 2a49dfe59540 |
files | Changes mc-code-powerpc.c mc-parse.c test/inline.c |
diffstat | 4 files changed, 94 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Thu Dec 02 02:50:45 2004 +0900 +++ b/Changes Thu Dec 02 12:07:16 2004 +0900 @@ -6985,3 +6985,7 @@ を見つけた時点ではわかりえない。 pexpr では、もっと詳しい情報が得られるので、より簡単になる。 + +Thu Dec 2 12:06:22 JST 2004 + +attribute ねぇ。見たくないねぇ。
--- a/mc-code-powerpc.c Thu Dec 02 02:50:45 2004 +0900 +++ b/mc-code-powerpc.c Thu Dec 02 12:07:16 2004 +0900 @@ -23,6 +23,7 @@ #define __builtin_va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg))\n\ #define __builtin_va_arg(ap,type) (*((type *)ap)++)\n\ #define alloca __builtin_alloca\n\ +#define __attribute__(a)\n\ #define __builtin_expect(a,t) a\n\ ";
--- a/mc-parse.c Thu Dec 02 02:50:45 2004 +0900 +++ b/mc-parse.c Thu Dec 02 12:07:16 2004 +0900 @@ -104,7 +104,7 @@ static int adecl(NMTBL *n); static void code_decl(NMTBL *n); static void decl(void); -static int typespec(int *ctmode); +static int typespec(); static void docase(void); static void docomp(int); static void dodefault(void); @@ -139,6 +139,7 @@ static NMTBL * make_top_scope(NMTBL *nlist,NMTBL *nptr1,int sc); static void extrn_use(NMTBL *nptr); static void top_init(); +static void const_volatile(); static struct cheap * new_cheap(); @@ -267,6 +268,7 @@ extern void error(int n) { + char *file; if(n == EOFERR) { if(filep!=filestack) { fclose(filep->fcb); @@ -288,7 +290,8 @@ } } if (conv->error_(n)) return; - fprintf(stderr,"%s:%d:%s\n",filep->name0,lineno, + if (!filep) file = ""; else file = filep->name0; + fprintf(stderr,"%s:%d:%s\n",file,lineno, (n==FILERR) ? "Can't open specified file" : (n==DCERR) ? "Declaration syntax" : (n==RDERR) ? "Redefined" : @@ -417,6 +420,7 @@ reserve("void",VOID); reserve("char",CHAR); reserve("const",KONST); + reserve("__const__",KONST); reserve("struct",STRUCT); reserve("union",UNION); reserve("unsigned",UNSIGNED); @@ -631,10 +635,7 @@ static void storage_class() { - if(sym==VOLATILE) { - getsym(0); - ctmode=VOLATILE; - } + const_volatile(); switch(sym) { case STATIC: if(mode==LDECL) { @@ -710,7 +711,7 @@ int t,sd,ctmode=0; if (mode==GDECL) { typedefed=0; } storage_class(); - if((t=typespec(&ctmode))==0) return; + if((t=typespec())==0) return; if(sym==SM) { conv->return_type_(t,0,stypedecl); conv->sm_(); return; @@ -771,21 +772,38 @@ } } +static void +const_volatile() +{ + for(;;) { + switch (sym) { + case KONST: + if (ctmode!=VOLATILE) + ctmode = KONST; + break; + case VOLATILE: + ctmode = VOLATILE; + break; + default: + return; + } + getsym(0); + } + /* not reached */ +} + /* type specification */ static int -typespec(int *ctmode) +typespec() { int t = INT; int slfree; int smode,stype; stypedecl = 0; - while (sym==KONST) { - getsym(0); - *ctmode = KONST; - } + const_volatile(); switch(sym) { case VOID: case INT: @@ -868,7 +886,7 @@ smode = mode; mode = STAT; checksym(LPAR); mode = LDECL; // typespec required this - if((t=typespec(ctmode))==0) { + if((t=typespec())==0) { mode = STAT; // too late for expression expr(0); t = type; @@ -890,19 +908,10 @@ break; } } -if(0) { - while (sym==KONST) { - getsym(0); - *ctmode = KONST; - } -} if(mode==LDECL) return 0; // not a type t= INT; // empty typespec } - while (sym==KONST) { - getsym(0); - *ctmode = KONST; - } + const_volatile(); return t; } @@ -916,9 +925,7 @@ NMTBL *n; if(sym==MUL) { getsym(0); - while (sym==KONST) { - getsym(0); - } + const_volatile(); n=decl0(); type=list2(POINTER,type); return n; @@ -1035,7 +1042,8 @@ int t; int stype,smode,sd,sargs,sstmode; int argtypes; - int ctmode=0; + int sctmode = ctmode; + ctmode=0; sstmode=stmode; stmode=REGISTER; /* nobody use this? */ stype=type; @@ -1060,7 +1068,7 @@ getsym(0); break; } - if((t=typespec(&ctmode))==0) { + if((t=typespec())==0) { error(DCERR); break; } @@ -1079,6 +1087,7 @@ if(sym==RPAR) break; } if (sym!=COMMA) error(DCERR); + ctmode=0; getsym(0); } argtypes=reverse0(argtypes); @@ -1088,6 +1097,7 @@ fnptr=sfnptr; type=stype; sdecl_f = sd; + ctmode = sctmode; stmode=sstmode; return argtypes; } @@ -2476,7 +2486,7 @@ if (!inmode) checkret(); getsym(0); - if (sym==VOLATILE) getsym(0); + const_volatile(); checksym(LPAR); // asm string if (sym!=STRING) error(DCERR); @@ -3185,7 +3195,7 @@ case LPAR: conv->lpar_(); getsym(0); - if(sym==VOLATILE) getsym(0); + const_volatile(); /* type cast */ @@ -3381,7 +3391,7 @@ case CODE : case SHORT : case LONG : case STRUCT : case UNION : case ENUM : case LONGLONG : case FLOAT : case DOUBLE : case VOID : - case ULONGLONG : case TYPEOF : case KONST: + case ULONGLONG : case TYPEOF : case KONST: case VOLATILE: return 1; case IDENT: return nptr->sc==TYPE; } @@ -3392,9 +3402,11 @@ typename(void) { int t; - int ctmode=0; - - type=t=typespec(&ctmode); // undefine case? + int sctmode=ctmode; + ctmode=0; + + type=t=typespec(); // undefine case? + ctmode = sctmode; ndecl0(); reverse(t); return type; @@ -3498,6 +3510,7 @@ while(i-->0) { *to++ = *from++; } + cheap->next->ptr = to-1; } cheap = cheap->next; }
--- a/test/inline.c Thu Dec 02 02:50:45 2004 +0900 +++ b/test/inline.c Thu Dec 02 12:07:16 2004 +0900 @@ -5,6 +5,29 @@ static const char haa[] = "test"; static inline const int f(int k); +volatile const int i = 3; + +extern int printf(char *,...); +int +main0() +{ + volatile const int j = 3; + switch(i) { + case 1: printf("#0015:1\n"); break; + case 2: printf("#0016:2\n"); break; + case 3: printf("#0017:3\n"); break; + case 4: printf("#0018:4\n"); break; + } + switch(j) { + case 1: printf("#0021:1\n"); break; + case 2: printf("#0022:2\n"); break; + case 3: printf("#0023:3\n"); break; + case 4: printf("#0024:4\n"); break; + } + return 0; +} + + extern int printf(char *,...); static inline const int f(int k) @@ -21,7 +44,7 @@ static inline int ins(int i,int j) { - printf("#0023:%d %d\n",i,j); + printf("#0046:%d %d\n",i,j); if (f(i)>j) return j; else return i; } @@ -29,29 +52,29 @@ static inline int ins1(int i,int j) { - printf("#0023:%d %d\n",i,j); + printf("#0054:%d %d\n",i,j); if (f(i)>j) return j; else return i; } -inline int in2(int p,int i,int j) +inline __attribute__((always_inline)) int in2(int p,int i,int j) { int k = 0,m; do { k += 3; } while ( k < j); - printf("#0034: %d do %d\n",p,k); + printf("#0065: %d do %d\n",p,k); while (k < j) { k -= 3; } while ( k < j); - printf("#0039: %d while %d\n",p,k); + printf("#0070: %d while %d\n",p,k); m = 0; for(k=0;k<j;k++) { m += k; } - printf("#0045: %d for %d\n",p,m); + printf("#0076: %d for %d\n",p,m); switch(i) { case 1: k = 1; @@ -64,13 +87,13 @@ break; default: k = 5; } - printf("#0058: %d switch %d\n",p,k); + printf("#0089: %d switch %d\n",p,k); for(k=0;k<j;k++) { i += k; if (k<3) continue; } - printf("#0064: %d for %d\n",p,i); + printf("#0095: %d for %d\n",p,i); goto hoge; hage: goto hage; @@ -91,27 +114,27 @@ // a = 10; k1 = in1(a,b); - printf("#0081:%d %d %d\n",a,b,k1); + printf("#0116:%d %d %d\n",a,b,k1); j1 = in1(k,j-6)+f(k1); - printf("#0083:%d %d %s\n",k1,j1,hoo); + printf("#0118:%d %d %s\n",k1,j1,hoo); k1 = &v-&x>0? &v-&x : &x-&v; - printf("#0085:v-x: %d\n",k1); + printf("#0120:v-x: %d\n",k1); k1 = ins(a,b); j1 = ins(k,j-6)+f(k1); - printf("#0089:%d %d %s\n",k1,j1,haa); + printf("#0124:%d %d %s\n",k1,j1,haa); k1 = ins(as,bs); j1 = ins(k,j-6)+f(k1); - printf("#0093:%d %d %s\n",k1,j1,haa); + printf("#0128:%d %d %s\n",k1,j1,haa); k1 = ins(v,x); j1 = ins(k,j-6)+f(v); - printf("#0097:%d %d %s\n",k1,j1,haa); + printf("#0132:%d %d %s\n",k1,j1,haa); k1 = fnp(v,x); j1 = ins1(k,j-6)+f(v); - printf("#0097:%d %d %s\n",k1,j1,haa); + printf("#0136:%d %d %s\n",k1,j1,haa); } void @@ -123,17 +146,19 @@ in2(4,2,j); in2(5,2,1); in2(6,0,2); - fnp3(6,0,2); + in2(8,j*3,in2(7,k+3,10-j)); + fnp3(9,0,2); } int -main() +main(int ac,char *av[]) { fnp = ins1; a0(5,6); a0(-9,6); fnp3 = in2; a1(9,10); + main0(ac,av); return 0; }