diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2007-10-07 18:34:42 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2007-10-07 18:34:42 +0000 |
commit | 7a319b2ba0bc99a92dfe02a224db2c9c67626fda (patch) | |
tree | 336bf97a4986400b2440c59057dc42c57fff74dc /usr.bin/pcc/ccom/cgram.y | |
parent | 992ae3f64965e9753eec4344ef0f844a47b49626 (diff) |
Merge from ragge's repo:
Add initial support for packed/aligned/rename pragmas.
Still missing: Support for architectures with strict alignment.
TODO: Cleanup the rename stuff so that it's not depending on gcc
compat.
Diffstat (limited to 'usr.bin/pcc/ccom/cgram.y')
-rw-r--r-- | usr.bin/pcc/ccom/cgram.y | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/usr.bin/pcc/ccom/cgram.y b/usr.bin/pcc/ccom/cgram.y index d77193c2c8e..19622c53bbf 100644 --- a/usr.bin/pcc/ccom/cgram.y +++ b/usr.bin/pcc/ccom/cgram.y @@ -1,4 +1,4 @@ -/* $OpenBSD: cgram.y,v 1.1 2007/10/07 17:58:51 otto Exp $ */ +/* $OpenBSD: cgram.y,v 1.2 2007/10/07 18:34:41 otto Exp $ */ /* * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se). @@ -118,6 +118,13 @@ %token C_ASM /* + * These tokens are only used for pragmas; let yacc handle syntax check. + */ +%token PRAG_PACKED +%token PRAG_ALIGNED +%token PRAG_RENAMED + +/* * Precedence */ %left ',' @@ -190,7 +197,7 @@ struct savbc { %start ext_def_list %type <intval> con_e ifelprefix ifprefix whprefix forprefix doprefix switchpart - type_qualifier_list + type_qualifier_list str_attr %type <nodep> e .e term enum_dcl struct_dcl cast_type funct_idn declarator direct_declarator elist type_specifier merge_attribs parameter_declaration abstract_declarator initializer @@ -199,12 +206,14 @@ struct savbc { specifier_qualifier_list merge_specifiers nocon_e identifier_list arg_param_list arg_declaration arg_dcl_list designator_list designator -%type <strp> string wstring C_STRING C_WSTRING +%type <strp> string wstring C_STRING C_WSTRING PRAG_RENAMED %type <rp> enum_head str_head %type <symp> xnfdeclarator clbrace %type <intval> C_CLASS C_STRUCT C_RELOP C_DIVOP C_SHIFTOP C_ANDAND C_OROR C_STROP C_INCOP C_UNOP C_ASOP C_EQUOP + PRAG_PACKED PRAG_ALIGNED + %type <nodep> C_TYPE C_QUALIFIER C_ICON C_FCON %type <strp> C_NAME C_TYPENAME @@ -476,7 +485,7 @@ init_declarator_list: | init_declarator_list ',' { $<nodep>$ = $<nodep>0; } init_declarator ; -enum_dcl: enum_head '{' moe_list optcomma '}' { $$ = dclstruct($1); } +enum_dcl: enum_head '{' moe_list optcomma '}' { $$ = dclstruct($1, 0); } | C_ENUM C_NAME { $$ = rstruct($2,0); } | C_ENUM C_TYPENAME { $$ = rstruct($2,0); } ; @@ -494,17 +503,24 @@ moe: C_NAME { moedef( $1 ); } | C_NAME '=' con_e { strucoff = $3; moedef( $1 ); } ; -struct_dcl: str_head '{' struct_dcl_list '}' { $$ = dclstruct($1); } +struct_dcl: str_head '{' struct_dcl_list '}' str_attr { + $$ = dclstruct($1, $5); + } | C_STRUCT C_NAME { $$ = rstruct($2,$1); } | C_STRUCT C_TYPENAME { $$ = rstruct($2,$1); } | str_head '{' '}' { #ifndef GCC_COMPAT werror("gcc extension"); #endif - $$ = dclstruct($1); + $$ = dclstruct($1, 0); } ; +str_attr: { $$ = 0; /* nothing */ } + | PRAG_PACKED { $$ = PRAG_PACKED; } + | PRAG_ALIGNED { $$ = PRAG_ALIGNED; } + ; + str_head: C_STRUCT { $$ = bstruct(NULL, $1); } | C_STRUCT C_NAME { $$ = bstruct($2,$1); } | C_STRUCT C_TYPENAME { $$ = bstruct($2,$1); } @@ -573,6 +589,10 @@ xnfdeclarator: declarator { $$ = xnf = init_declarator($<nodep>0, $1, 1); } * Returns nothing. */ init_declarator: declarator { init_declarator($<nodep>0, $1, 0); } + | declarator PRAG_RENAMED { + renname = $2; /* XXX ugly */ + init_declarator($<nodep>0, $1, 0); + } | declarator C_ASM '(' string ')' { #ifdef GCC_COMPAT renname = $4; @@ -949,7 +969,7 @@ term: term C_INCOP { $$ = buildtree( $2, $1, bcon(1) ); } $$ = buildtree(CAST, $2, $4); nfree($$->n_left); nfree($$); - $$ = $$->n_right; + $$ = $$->n_right; /* XXX use after free */ } | C_SIZEOF '(' cast_type ')' %prec C_SIZEOF { $$ = doszof($3); @@ -1331,7 +1351,8 @@ structref(NODE *p, int f, char *name) p = buildtree(ADDROF, p, NIL); r = block(NAME, NIL, NIL, INT, 0, MKSUE(INT)); r->n_name = name; - return buildtree(STREF, p, r); + r = buildtree(STREF, p, r); + return r; } static void |