diff options
author | Ben Elliston <bje@au.ibm.com> | 2008-07-14 05:09:48 +0000 |
---|---|---|
committer | Ben Elliston <bje@gcc.gnu.org> | 2008-07-14 15:09:48 +1000 |
commit | 5950c3c9a7729687a04f9b008e441959a2d9114d (patch) | |
tree | 5549f4ccea5a3b85211df500d0617fd3866b139f /gcc | |
parent | b463e8de6c7e9c7fe8ad2f4f4be126f58b23c07a (diff) | |
download | gcc-5950c3c9a7729687a04f9b008e441959a2d9114d.zip gcc-5950c3c9a7729687a04f9b008e441959a2d9114d.tar.gz gcc-5950c3c9a7729687a04f9b008e441959a2d9114d.tar.bz2 |
cpplib.h (NODE_CONDITIONAL): New.
libcpp/
* include/cpplib.h (NODE_CONDITIONAL): New.
(struct cpp_callbacks): New macro_to_expand field.
(struct cpp_hashnode): Adjust size of flags and type fields.
(cpp_peek_token): Prototype.
* lex.c (cpp_peek_token): New function.
(_cpp_temp_token): Protect pre-existing lookaheads.
* macro.c (cpp_get_token): Expand any conditional macros.
(_cpp_backup_tokens_direct): New.
(_cpp_backup_tokens): Call _cpp_backup_tokens_direct.
(warn_of_redefinition): Silently allow redefined conditional
macros.
(_cpp_create_definition): Remove the conditional flag when a user
defines one of the conditional macros.
* internal.h (_cpp_backup_tokens_direct): New prototype.
gcc/
* c-common.h (C_CPP_HASHNODE): New macro.
* coretypes.h (struct cpp_token): Forward declare.
* doc/extend.texi (PowerPC AltiVec Built-in Functions): Document
the context-sensitive keyword method.
* config/rs6000/rs6000-c.c (__vector_keyword, vector_keyword,
__pixel_keyword, pixel_keyword, __bool_keyword, bool_keyword,
expand_bool_pixel): New.
(altivec_categorize_keyword): New function.
(init_vector_keywords): New function.
(rs6000_macro_to_expand): Likewise.
(rs6000_cpu_cpp_builtins): Enable context-sensitive macros if not
compiling an ISO C dialect.
gcc/testsuite/
* gcc.target/powerpc/altivec-macros.c: New test.
* gcc.target/powerpc/altviec-26.c: Likewise.
* gcc.dg/vmx/1b-06.c: Remove bool variable.
* gcc.dg/vmx/1b-07.c: Likewise.
* gcc.dg/vmx/1b-06-ansi.c: New test for the pre-define method.
* gcc.dg/vmx/1b-07-ansi.c: Likewise.
From-SVN: r137775
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 15 | ||||
-rw-r--r-- | gcc/c-common.h | 2 | ||||
-rw-r--r-- | gcc/config/rs6000/rs6000-c.c | 157 | ||||
-rw-r--r-- | gcc/coretypes.h | 4 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vmx/1b-06-ansi.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vmx/1b-06.c | 1 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vmx/1b-07-ansi.c | 59 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vmx/1b-07.c | 1 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/powerpc/altivec-26.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/powerpc/altivec-macros.c | 63 |
12 files changed, 347 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 39ebddf..c946bb0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2008-07-14 Ben Elliston <bje@au.ibm.com> + + * c-common.h (C_CPP_HASHNODE): New macro. + * coretypes.h (struct cpp_token): Forward declare. + * doc/extend.texi (PowerPC AltiVec Built-in Functions): Document + the context-sensitive keyword method. + * config/rs6000/rs6000-c.c (__vector_keyword, vector_keyword, + __pixel_keyword, pixel_keyword, __bool_keyword, bool_keyword, + expand_bool_pixel): New. + (altivec_categorize_keyword): New function. + (init_vector_keywords): New function. + (rs6000_macro_to_expand): Likewise. + (rs6000_cpu_cpp_builtins): Enable context-sensitive macros if not + compiling an ISO C dialect. + 2008-07-13 Daniel Berlin <dberlin@dberlin.org> * tree-ssa-pre.c (fully_constant_expression): Add fold_convert diff --git a/gcc/c-common.h b/gcc/c-common.h index 7edb4a6..486fdeb 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -188,6 +188,8 @@ enum c_tree_index CTI_MAX }; +#define C_CPP_HASHNODE(id) \ + (&(((struct c_common_identifier *) (id))->node)) #define C_RID_CODE(id) \ ((enum rid) (((struct c_common_identifier *) (id))->node.rid_code)) #define C_SET_RID_CODE(id, code) \ diff --git a/gcc/config/rs6000/rs6000-c.c b/gcc/config/rs6000/rs6000-c.c index d0830bb..ce1ec4b 100644 --- a/gcc/config/rs6000/rs6000-c.c +++ b/gcc/config/rs6000/rs6000-c.c @@ -84,6 +84,149 @@ rs6000_pragma_longcall (cpp_reader *pfile ATTRIBUTE_UNUSED) #define builtin_define(TXT) cpp_define (pfile, TXT) #define builtin_assert(TXT) cpp_assert (pfile, TXT) +/* Keep the AltiVec keywords handy for fast comparisons. */ +static tree __vector_keyword; +static tree vector_keyword; +static tree __pixel_keyword; +static tree pixel_keyword; +static tree __bool_keyword; +static tree bool_keyword; + +/* Preserved across calls. */ +static tree expand_bool_pixel; + +static cpp_hashnode * +altivec_categorize_keyword (const cpp_token *tok) +{ + if (tok->type == CPP_NAME) + { + cpp_hashnode *ident = tok->val.node; + + if (ident == C_CPP_HASHNODE (vector_keyword) + || ident == C_CPP_HASHNODE (__vector_keyword)) + return C_CPP_HASHNODE (__vector_keyword); + + if (ident == C_CPP_HASHNODE (pixel_keyword) + || ident == C_CPP_HASHNODE (__pixel_keyword)) + return C_CPP_HASHNODE (__pixel_keyword); + + if (ident == C_CPP_HASHNODE (bool_keyword) + || ident == C_CPP_HASHNODE (__bool_keyword)) + return C_CPP_HASHNODE (__bool_keyword); + + return ident; + } + + return 0; +} + +static void +init_vector_keywords (void) +{ + /* Keywords without two leading underscores are context-sensitive, + and hence implemented as conditional macros, controlled by the + rs6000_macro_to_expand() function below. */ + + __vector_keyword = get_identifier ("__vector"); + C_CPP_HASHNODE (__vector_keyword)->flags |= NODE_CONDITIONAL; + + __pixel_keyword = get_identifier ("__pixel"); + C_CPP_HASHNODE (__pixel_keyword)->flags |= NODE_CONDITIONAL; + + __bool_keyword = get_identifier ("__bool"); + C_CPP_HASHNODE (__bool_keyword)->flags |= NODE_CONDITIONAL; + + vector_keyword = get_identifier ("vector"); + C_CPP_HASHNODE (vector_keyword)->flags |= NODE_CONDITIONAL; + + pixel_keyword = get_identifier ("pixel"); + C_CPP_HASHNODE (pixel_keyword)->flags |= NODE_CONDITIONAL; + + bool_keyword = get_identifier ("bool"); + C_CPP_HASHNODE (bool_keyword)->flags |= NODE_CONDITIONAL; +} + +/* Called to decide whether a conditional macro should be expanded. + Since we have exactly one such macro (i.e, 'vector'), we do not + need to examine the 'tok' parameter. */ + +static cpp_hashnode * +rs6000_macro_to_expand (cpp_reader *pfile, const cpp_token *tok) +{ + cpp_hashnode *expand_this = tok->val.node; + cpp_hashnode *ident; + + ident = altivec_categorize_keyword (tok); + + if (ident == C_CPP_HASHNODE (__vector_keyword)) + { + tok = cpp_peek_token (pfile, 0); + ident = altivec_categorize_keyword (tok); + + if (ident == C_CPP_HASHNODE (__pixel_keyword)) + { + expand_this = C_CPP_HASHNODE (__vector_keyword); + expand_bool_pixel = __pixel_keyword; + } + else if (ident == C_CPP_HASHNODE (__bool_keyword)) + { + expand_this = C_CPP_HASHNODE (__vector_keyword); + expand_bool_pixel = __bool_keyword; + } + else if (ident) + { + enum rid rid_code = (enum rid)(ident->rid_code); + if (ident->type == NT_MACRO) + { + (void)cpp_get_token (pfile); + tok = cpp_peek_token (pfile, 0); + ident = altivec_categorize_keyword (tok); + if (ident) + rid_code = (enum rid)(ident->rid_code); + } + + if (rid_code == RID_UNSIGNED || rid_code == RID_LONG + || rid_code == RID_SHORT || rid_code == RID_SIGNED + || rid_code == RID_INT || rid_code == RID_CHAR + || rid_code == RID_FLOAT) + { + expand_this = C_CPP_HASHNODE (__vector_keyword); + /* If the next keyword is bool or pixel, it + will need to be expanded as well. */ + tok = cpp_peek_token (pfile, 1); + ident = altivec_categorize_keyword (tok); + + if (ident == C_CPP_HASHNODE (__pixel_keyword)) + expand_bool_pixel = __pixel_keyword; + else if (ident == C_CPP_HASHNODE (__bool_keyword)) + expand_bool_pixel = __bool_keyword; + else + { + /* Try two tokens down, too. */ + tok = cpp_peek_token (pfile, 2); + ident = altivec_categorize_keyword (tok); + if (ident == C_CPP_HASHNODE (__pixel_keyword)) + expand_bool_pixel = __pixel_keyword; + else if (ident == C_CPP_HASHNODE (__bool_keyword)) + expand_bool_pixel = __bool_keyword; + } + } + } + } + else if (expand_bool_pixel && ident == C_CPP_HASHNODE (__pixel_keyword)) + { + expand_this = C_CPP_HASHNODE (__pixel_keyword); + expand_bool_pixel = 0; + } + else if (expand_bool_pixel && ident == C_CPP_HASHNODE (__bool_keyword)) + { + expand_this = C_CPP_HASHNODE (__bool_keyword); + expand_bool_pixel = 0; + } + + return expand_this; +} + void rs6000_cpu_cpp_builtins (cpp_reader *pfile) { @@ -120,6 +263,20 @@ rs6000_cpu_cpp_builtins (cpp_reader *pfile) builtin_define ("__vector=__attribute__((altivec(vector__)))"); builtin_define ("__pixel=__attribute__((altivec(pixel__))) unsigned short"); builtin_define ("__bool=__attribute__((altivec(bool__))) unsigned"); + + if (!flag_iso) + { + /* Define this when supporting context-sensitive keywords. */ + builtin_define ("__APPLE_ALTIVEC__"); + + builtin_define ("vector=vector"); + builtin_define ("pixel=pixel"); + builtin_define ("bool=bool"); + init_vector_keywords (); + + /* Enable context-sensitive macros. */ + cpp_get_callbacks (pfile)->macro_to_expand = rs6000_macro_to_expand; + } } if (TARGET_SPE) builtin_define ("__SPE__"); diff --git a/gcc/coretypes.h b/gcc/coretypes.h index 4fe480f..f585eb4 100644 --- a/gcc/coretypes.h +++ b/gcc/coretypes.h @@ -60,9 +60,11 @@ enum ir_type { /* Provide forward struct declaration so that we don't have to include all of cpplib.h whenever a random prototype includes a pointer. - Note that the cpp_reader typedef remains part of cpplib.h. */ + Note that the cpp_reader and cpp_token typedefs remain part of + cpplib.h. */ struct cpp_reader; +struct cpp_token; /* The thread-local storage model associated with a given VAR_DECL or SYMBOL_REF. This isn't used much, but both trees and RTL refer diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 56e8926..eecb4ca 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -9120,9 +9120,10 @@ always specify the signedness. @item Compiling with @option{-maltivec} adds keywords @code{__vector}, -@code{__pixel}, and @code{__bool}. Macros @option{vector}, -@code{pixel}, and @code{bool} are defined in @code{<altivec.h>} and can -be undefined. +@code{vector}, @code{__pixel}, @code{pixel}, @code{__bool} and +@code{bool}. When compiling ISO C, the context-sensitive substitution +of the keywords @code{vector}, @code{pixel} and @code{bool} is +disabled. To use them, you must include @code{<altivec.h>} instead. @item GCC allows using a @code{typedef} name as the type specifier for a diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dd05af11..0bf9bd3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2008-07-14 Ben Elliston <bje@au.ibm.com> + + * gcc.target/powerpc/altivec-macros.c: New test. + * gcc.target/powerpc/altviec-26.c: Likewise. + * gcc.dg/vmx/1b-06.c: Remove bool variable. + * gcc.dg/vmx/1b-07.c: Likewise. + * gcc.dg/vmx/1b-06-ansi.c: New test for the pre-define method. + * gcc.dg/vmx/1b-07-ansi.c: Likewise. + 2008-07-14 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR fortran/36725 diff --git a/gcc/testsuite/gcc.dg/vmx/1b-06-ansi.c b/gcc/testsuite/gcc.dg/vmx/1b-06-ansi.c new file mode 100644 index 0000000..780a4e6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vmx/1b-06-ansi.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-ansi -maltivec" } */ + +#include <altivec.h> +vector char bool _4 ; +vector char unsigned _31 ; +vector char signed _59 ; +/* bool is permitted in the predefine method, as it is expanded + unconditionally to int. */ +bool _84 ; +vector pixel _89 ; +vector int bool _95 ; +vector short bool _102 ; +vector unsigned int _122 ; +vector unsigned short _129 ; +vector signed int _150 ; +vector signed short _157 ; +vector int bool _179 ; +vector int short bool _186 ; +vector unsigned int _206 ; +vector int unsigned short _213 ; +vector signed int _234 ; +vector int signed short _241 ; +vector float _339 ; diff --git a/gcc/testsuite/gcc.dg/vmx/1b-06.c b/gcc/testsuite/gcc.dg/vmx/1b-06.c index 84c6981..d25164c 100644 --- a/gcc/testsuite/gcc.dg/vmx/1b-06.c +++ b/gcc/testsuite/gcc.dg/vmx/1b-06.c @@ -3,7 +3,6 @@ vector char bool _4 ; vector char unsigned _31 ; vector char signed _59 ; -bool _84 ; vector pixel _89 ; vector int bool _95 ; vector short bool _102 ; diff --git a/gcc/testsuite/gcc.dg/vmx/1b-07-ansi.c b/gcc/testsuite/gcc.dg/vmx/1b-07-ansi.c new file mode 100644 index 0000000..cfc9863 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vmx/1b-07-ansi.c @@ -0,0 +1,59 @@ +/* { dg-do compile } */ +/* { dg-options "-ansi -maltivec" } */ + +#include <altivec.h> +vector char bool _0 ; +vector bool char _8 ; +vector char unsigned _56 ; +vector unsigned char _64 ; +vector char signed _112 ; +vector signed char _120 ; +/* bool is permitted in the predefine method, as it is expanded + unconditionally to int. */ +bool _168 ; +vector pixel _170 ; +vector int bool _178 ; +vector bool int _186 ; +vector short bool _234 ; +vector bool short _242 ; +vector unsigned int _290 ; +vector int unsigned _298 ; +vector unsigned short _346 ; +vector short unsigned _354 ; +vector signed int _402 ; +vector int signed _410 ; +vector signed short _458 ; +vector short signed _466 ; +vector int bool _514 ; +vector int bool _544 ; +vector int bool _559 ; +vector bool int _589 ; +vector int short bool _874 ; +vector int bool short _889 ; +vector short int bool _904 ; +vector short bool int _919 ; +vector bool int short _934 ; +vector bool short int _949 ; +vector unsigned int _1234 ; +vector int unsigned _1249 ; +vector unsigned int _1279 ; +vector int unsigned _1294 ; +vector unsigned int _1309 ; +vector int unsigned short _1594 ; +vector int short unsigned _1609 ; +vector unsigned int short _1624 ; +vector unsigned short int _1639 ; +vector short int unsigned _1654 ; +vector short unsigned int _1669 ; +vector signed int _1954 ; +vector int signed _1969 ; +vector signed int _1999 ; +vector int signed _2014 ; +vector signed int _2029 ; +vector int signed short _2314 ; +vector int short signed _2329 ; +vector signed int short _2344 ; +vector signed short int _2359 ; +vector short int signed _2374 ; +vector short signed int _2389 ; +vector float _2674 ; diff --git a/gcc/testsuite/gcc.dg/vmx/1b-07.c b/gcc/testsuite/gcc.dg/vmx/1b-07.c index b1f4bb6..44bf402 100644 --- a/gcc/testsuite/gcc.dg/vmx/1b-07.c +++ b/gcc/testsuite/gcc.dg/vmx/1b-07.c @@ -6,7 +6,6 @@ vector char unsigned _56 ; vector unsigned char _64 ; vector char signed _112 ; vector signed char _120 ; -bool _168 ; vector pixel _170 ; vector int bool _178 ; vector bool int _186 ; diff --git a/gcc/testsuite/gcc.target/powerpc/altivec-26.c b/gcc/testsuite/gcc.target/powerpc/altivec-26.c new file mode 100644 index 0000000..689d13a --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/altivec-26.c @@ -0,0 +1,11 @@ +/* { dg-do compile { target powerpc*-*-* } } */ +/* { dg-require-effective-target powerpc_altivec_ok } */ +/* { dg-options "-maltivec" } */ + +/* A compiler implementing context-sensitive keywords must define this + preprocessor macro so that altivec.h does not provide the vector, + pixel, etc. macros. */ + +#ifndef __APPLE_ALTIVEC__ +#error __APPLE_ALTIVEC__ not pre-defined +#endif diff --git a/gcc/testsuite/gcc.target/powerpc/altivec-macros.c b/gcc/testsuite/gcc.target/powerpc/altivec-macros.c new file mode 100644 index 0000000..d95a68d --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/altivec-macros.c @@ -0,0 +1,63 @@ +/* Copyright (C) 2007 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ +/* { dg-options "-maltivec" } */ + +/* Conditional macros should not be expanded by pragmas. */ +#pragma __vector +_Pragma ("__vector") + +/* Redefinition of conditional macros. */ +/* No warning should be generated. */ + +#define __vector __new_vector +#define __pixel __new_pixel +#define __bool __new_bool +#define vector new_vector +#define pixel new_pixel +#define bool new_bool + +/* Definition of conditional macros. */ +/* No warning should be generated. */ + +#undef __vector +#define __vector __new_vector + +#undef __pixel +#define __pixel __new_pixel + +#undef __bool +#define __bool __new_bool + +#undef vector +#define vector new_vector + +#undef pixel +#define pixel new_pixel + +#undef bool +#define bool new_bool + +/* Re-definition of "unconditional" macros. */ +/* Warnings should be generated as usual. */ + +#define __vector __newer_vector +#define __pixel __newer_pixel +#define __bool __newer_bool +#define vector newer_vector +#define pixel newer_pixel +#define bool newer_bool + +/* { dg-warning "redefined" "__vector redefined" { target *-*-* } 44 } */ +/* { dg-warning "redefined" "__pixel redefined" { target *-*-* } 45 } */ +/* { dg-warning "redefined" "__bool redefined" { target *-*-* } 46 } */ +/* { dg-warning "redefined" "vector redefined" { target *-*-* } 47 } */ +/* { dg-warning "redefined" "pixel redefined" { target *-*-* } 48 } */ +/* { dg-warning "redefined" "bool redefined" { target *-*-* } 49 } */ + +/* { dg-warning "previous" "prev __vector defn" { target *-*-* } 24 } */ +/* { dg-warning "previous" "prev __pixel defn" { target *-*-* } 27 } */ +/* { dg-warning "previous" "prev __bool defn" { target *-*-* } 30 } */ +/* { dg-warning "previous" "prev vector defn" { target *-*-* } 33 } */ +/* { dg-warning "previous" "prev pixel defn" { target *-*-* } 36 } */ +/* { dg-warning "previous" "prev bool defn" { target *-*-* } 39 } */ |