Mercurial > hg > CbC > old > device
changeset 461:2a49dfe59540
attribute
author | kono |
---|---|
date | Thu, 02 Dec 2004 19:38:00 +0900 |
parents | 2859bb9d5fb3 |
children | f7c87020e6fe |
files | Changes mc-code-powerpc.c mc-codegen.c mc-parse.c mc.h |
diffstat | 5 files changed, 183 insertions(+), 117 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Thu Dec 02 12:07:16 2004 +0900 +++ b/Changes Thu Dec 02 19:38:00 2004 +0900 @@ -6989,3 +6989,5 @@ Thu Dec 2 12:06:22 JST 2004 attribute ねぇ。見たくないねぇ。 + +inline は、あとは partial evaluator だけだね。
--- a/mc-code-powerpc.c Thu Dec 02 12:07:16 2004 +0900 +++ b/mc-code-powerpc.c Thu Dec 02 19:38:00 2004 +0900 @@ -12,7 +12,6 @@ 0 }; -// __builtin_expect(a,t) branch prediction static char *init_src0 = "\ @@ -23,8 +22,6 @@ #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\ "; #define TEXT_EMIT_MODE 0
--- a/mc-codegen.c Thu Dec 02 12:07:16 2004 +0900 +++ b/mc-codegen.c Thu Dec 02 19:38:00 2004 +0900 @@ -2647,6 +2647,14 @@ #endif +static void +set_ctmode(NMTBL *n,int ctmode) +{ + if (ctmode & KONST_BIT) set_attr(n,KONST,0); + if (ctmode & VOLATILE_BIT) set_attr(n,VOLATILE,0); + if (ctmode & RESTRICT_BIT) set_attr(n,RESTRICT,0); +} + /* define symbol name contents depending on stmode, mode @@ -2670,7 +2678,7 @@ if(type>0&&(car(type)==FUNCTION || car(type)==CODE)) { if ((mode==GDECL)) { fcheck(n); - if (ctmode) set_attr(n,KONST,0); + set_ctmode(n,ctmode); return n; /* function and code segment are defined using fdecl/code_decl */ /* in decl() */ @@ -2740,7 +2748,7 @@ } } gpc +=sz; - if (ctmode) set_attr(n,KONST,0); + set_ctmode(n,ctmode); return n; case GSDECL: case LSDECL: disp += sz; @@ -2794,7 +2802,7 @@ } else { n->ty = type; } - if (ctmode) set_attr(n,KONST,0); + set_ctmode(n,ctmode); return n; case STAT: /* return (struct hoge)f() case? */ case LDECL: @@ -2820,14 +2828,14 @@ } n->sc = nsc; n->dsp = ndsp; - if (ctmode) set_attr(n,KONST,0); + set_ctmode(n,ctmode); return n; default: error(DCERR); } n->sc = nsc; n->dsp = ndsp; - if (ctmode) set_attr(n,KONST,0); + set_ctmode(n,ctmode); if (stmode==EXTRN) n->sc = EXTRN; return n;
--- a/mc-parse.c Thu Dec 02 12:07:16 2004 +0900 +++ b/mc-parse.c Thu Dec 02 19:38:00 2004 +0900 @@ -37,6 +37,8 @@ static NMTBL *free_nptr_list; static int current_scope; +int attribute; + int inline_funcs; char linebuf[LBUFSIZE]; @@ -139,7 +141,8 @@ 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 void qualifiers(); +static void attributes(); static struct cheap * new_cheap(); @@ -229,7 +232,7 @@ top_init(); while(getsym(0)==SM) conv->sm_(); mode=GDECL; - stmode=0; inmode=0; + stmode=0; inmode=0; attribute = 0; args=0; decl(); } @@ -354,6 +357,7 @@ p=(s==RPAR) ? "')'": (s==RBRA) ? "']'": (s==SM) ? "';'": (s==LPAR) ? "'('": (s==WHILE) ? "'while'": (s==ASS) ? "'='": + (s==COMMA) ? "','": (s==COLON) ? "':'": "Identifier"; fprintf(stderr,"%d:%s expected.\n",lineno,p); errmsg(); @@ -453,10 +457,13 @@ reserve("enum",ENUM); reserve("volatile",VOLATILE); reserve("__volatile__",VOLATILE); + reserve("restrict",RESTRICT); reserve("typeof",TYPEOF); reserve("__typeof__",TYPEOF); reserve("__builtin_alloca",ALLOCA); reserve("__builtin_constant_p",BUILTINP); + reserve("__builtin_expect",BUILTIN_EXPECT); + reserve("__attribute__",ATTRIBUTE); reserve("__label__",LABEL); #if ASM_CODE reserve("asm",ASM); @@ -635,7 +642,7 @@ static void storage_class() { - const_volatile(); + qualifiers(); switch(sym) { case STATIC: if(mode==LDECL) { @@ -708,7 +715,8 @@ decl(void) { NMTBL *n; - int t,sd,ctmode=0; + int t,sd; + ctmode=0; if (mode==GDECL) { typedefed=0; } storage_class(); if((t=typespec())==0) return; @@ -725,6 +733,7 @@ error(DCERR); return; } } + while (sym==ATTRIBUTE) { getsym(0); attributes(); } if(sym==LC || ( sym!=SM && sym!=COMMA && sym!=ASS)) { /* function body */ if (mode!=GDECL) error(DCERR); @@ -773,17 +782,48 @@ } static void -const_volatile() +attributes() +{ + int sattribute; + checksym(LPAR); + while(sym!=RPAR) { + if (sym==LPAR) { + sattribute = attribute; + attribute = 0; + attributes(); + attribute = list3(ATTRIBUTE,sattribute,attribute); + } else if (sym==IDENT) { + attribute = list3(IDENT,attribute,(int)nptr); + getsym(0); + } else if (sym==STRING) { + attribute = list3(STRING,attribute,(int)nptr->nm); + getsym(0); + } else { + attribute = list3(sym,attribute,symval); + getsym(0); + } + } + getsym(0); +} + +static void +qualifiers() { for(;;) { switch (sym) { case KONST: - if (ctmode!=VOLATILE) - ctmode = KONST; + ctmode |= KONST_BIT; break; case VOLATILE: - ctmode = VOLATILE; + ctmode |= VOLATILE_BIT; + break; + case RESTRICT: + ctmode |= RESTRICT_BIT; break; + case ATTRIBUTE: + getsym(0); + attributes(); + continue; default: return; } @@ -803,7 +843,7 @@ int smode,stype; stypedecl = 0; - const_volatile(); + qualifiers(); switch(sym) { case VOID: case INT: @@ -911,7 +951,7 @@ if(mode==LDECL) return 0; // not a type t= INT; // empty typespec } - const_volatile(); + qualifiers(); return t; } @@ -925,7 +965,7 @@ NMTBL *n; if(sym==MUL) { getsym(0); - const_volatile(); + qualifiers(); n=decl0(); type=list2(POINTER,type); return n; @@ -2486,7 +2526,7 @@ if (!inmode) checkret(); getsym(0); - const_volatile(); + qualifiers(); checksym(LPAR); // asm string if (sym!=STRING) error(DCERR); @@ -2798,7 +2838,7 @@ static int expr13(void) { - int e,op,dir; + int e,op,dir,t; NMTBL *nptr1; switch (op = sym) { @@ -2933,7 +2973,7 @@ type=list2(POINTER,VOID); return list2(ALLOCA,e); case BUILTINP: - /* builtin___builtin_constant_p GNU extenstion */ + /* __builtin_constant_p GNU extenstion */ conv->prefix_(sym); getsym(0); checksym(LPAR); @@ -2944,6 +2984,18 @@ return list2(BUILTINP,rvalue(e)); /* evalue it later */ else return list2(CONST,is_const(e)); + case BUILTIN_EXPECT: + /* builtin_expect(x,c) used in branch. x is expectet to be c */ + conv->prefix_(sym); + getsym(0); + checksym(LPAR); + e=expr1(); + t=type; + checksym(COMMA); + expr0(); /* ingore */ + checksym(RPAR); + type=t; + return e; case SIZEOF: conv->prefix_(sym); if(getsym(0)==LPAR) { @@ -3195,7 +3247,7 @@ case LPAR: conv->lpar_(); getsym(0); - const_volatile(); + qualifiers(); /* type cast */
--- a/mc.h Thu Dec 02 12:07:16 2004 +0900 +++ b/mc.h Thu Dec 02 19:38:00 2004 +0900 @@ -67,8 +67,9 @@ #define LONGLONG (-55) #define ULONGLONG (-56) #define VOLATILE (-57) -#define TYPEOF (-58) -#define ASM (-59) +#define RESTRICT (-58) +#define TYPEOF (-59) +#define ASM (-60) /* reserved word end */ @@ -200,56 +201,58 @@ #define RSTRUCT 32 #define ALLOCA 33 #define BUILTINP 34 -#define BIT_FIELD 35 -#define RBIT_FIELD 36 -#define BPREINC 37 -#define BPOSTINC 38 -#define CONV 39 +#define BUILTIN_EXPECT 35 +#define ATTRIBUTE 36 +#define BIT_FIELD 37 +#define RBIT_FIELD 38 +#define BPREINC 39 +#define BPOSTINC 40 +#define CONV 41 #define UNARY_ARGS(i) (ADDRESS<=(i%SOP)&&(i%SOP)<=CONV) /* binary argments */ -#define MUL 40 -#define UMUL 41 -#define DIV 42 -#define UDIV 43 -#define MOD 44 -#define UMOD 45 -#define ADD 46 -#define SUB 47 -#define CMP 48 -#define RSHIFT 49 -#define URSHIFT 50 -#define LSHIFT 51 -#define ULSHIFT 52 -#define GT 53 -#define UGT 54 -#define GE 55 -#define UGE 56 -#define LT 57 -#define ULT 58 -#define LE 59 -#define ULE 60 -#define EQ 61 -#define NEQ 62 -#define BAND 63 -#define EOR 64 -#define BOR 65 -#define LAND 66 -#define LOR 67 -#define ASS 68 -#define UCMP 69 -#define UCMPGE 70 -#define CMPGE 71 -#define CMPEQ 72 -#define CMPNEQ 73 -#define ASSOP 74 -#define COMMA 75 +#define MUL 42 +#define UMUL 43 +#define DIV 44 +#define UDIV 45 +#define MOD 46 +#define UMOD 47 +#define ADD 48 +#define SUB 49 +#define CMP 50 +#define RSHIFT 51 +#define URSHIFT 52 +#define LSHIFT 53 +#define ULSHIFT 54 +#define GT 55 +#define UGT 56 +#define GE 57 +#define UGE 58 +#define LT 59 +#define ULT 60 +#define LE 61 +#define ULE 62 +#define EQ 63 +#define NEQ 64 +#define BAND 65 +#define EOR 66 +#define BOR 67 +#define LAND 68 +#define LOR 69 +#define ASS 70 +#define UCMP 71 +#define UCMPGE 72 +#define CMPGE 73 +#define CMPEQ 74 +#define CMPNEQ 75 +#define ASSOP 76 +#define COMMA 77 -#define CASS 76 -#define CASSOP 77 -#define CUASSOP 78 +#define CASS 78 +#define CASSOP 79 +#define CUASSOP 80 #define SASS (SOP+CASS) #define SASSOP (SOP+CASSOP) @@ -305,18 +308,18 @@ #define LEOR (LOP+EOR) #define LBOR (LOP+BOR) -#define BASS 79 -#define BASSOP 80 -#define BFD_REPL 81 +#define BASS 81 +#define BASSOP 82 +#define BFD_REPL 83 -#define STASS 82 +#define STASS 84 #define BINARY_ARGS(i) (MUL<=(i%SOP)&&(i%SOP)<=STASS) /* tarnary argments */ -#define COND 83 +#define COND 85 #define SCOND (SOP+COND) #define DCOND (DOP+COND) #define FCOND (FOP+COND) @@ -326,35 +329,35 @@ /* not appeared as tags */ -#define LPAR 84 -#define RPAR 85 -#define LBRA 86 -#define RBRA 87 -#define LC 88 -#define RC 89 -#define COLON 90 -#define SM 91 -#define PERIOD 92 -#define ARROW 93 -#define CNAME 94 +#define LPAR 86 +#define RPAR 87 +#define LBRA 88 +#define RBRA 89 +#define LC 90 +#define RC 91 +#define COLON 92 +#define SM 93 +#define PERIOD 94 +#define ARROW 95 +#define CNAME 96 -#define I2C 95 -#define I2S 96 -#define I2I 97 -#define I2U 98 -#define I2D 99 -#define I2F 100 -#define I2LL 101 -#define I2ULL 102 +#define I2C 97 +#define I2S 98 +#define I2I 99 +#define I2U 100 +#define I2D 101 +#define I2F 102 +#define I2LL 103 +#define I2ULL 104 -#define U2UC 103 -#define U2US 104 -#define U2I 105 -#define U2U 106 -#define U2D 107 -#define U2F 108 -#define U2LL 109 -#define U2ULL 110 +#define U2UC 105 +#define U2US 106 +#define U2I 107 +#define U2U 108 +#define U2D 109 +#define U2F 110 +#define U2LL 111 +#define U2ULL 112 #define D2I (DOP+I2I) @@ -389,22 +392,22 @@ /* statement start */ -#define ST_DECL 111 -#define ST_IF 112 -#define ST_DO 113 -#define ST_WHILE 114 -#define ST_FOR 115 -#define ST_SWITCH 116 -#define ST_COMP 117 -#define ST_BREAK 118 -#define ST_CONTINUE 119 -#define ST_CASE 120 -#define ST_DEFAULT 121 -#define ST_RETURN 122 -#define ST_GOTO 123 -#define ST_ASM 124 -#define ST_LABEL 125 -#define ST_COMMENT 126 +#define ST_DECL 113 +#define ST_IF 114 +#define ST_DO 115 +#define ST_WHILE 116 +#define ST_FOR 117 +#define ST_SWITCH 118 +#define ST_COMP 119 +#define ST_BREAK 120 +#define ST_CONTINUE 121 +#define ST_CASE 122 +#define ST_DEFAULT 123 +#define ST_RETURN 124 +#define ST_GOTO 125 +#define ST_ASM 126 +#define ST_LABEL 127 +#define ST_COMMENT 128 #define IS_STATEMENT(i) (ST_DECL<=i&&i<=ST_COMMENT) @@ -444,6 +447,10 @@ /* error number end */ +#define KONST_BIT 1 +#define VOLATILE_BIT 2 +#define RESTRICT_BIT 4 + #define FILES 10 #define MAX_INCLUDE_PATH_COUNT 10 /*