aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog18
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/c-lex.c19
-rw-r--r--gcc/c-lex.h4
-rw-r--r--gcc/cppinit.c12
-rw-r--r--gcc/cpplib.h5
-rw-r--r--gcc/doc/tm.texi12
-rw-r--r--gcc/target-def.h2
-rw-r--r--gcc/target.h4
-rw-r--r--gcc/tree.c7
-rw-r--r--gcc/tree.h2
11 files changed, 79 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e91a779..98117b1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,23 @@
2002-05-04 Neil Booth <neil@daikokuya.demon.co.uk>
+ * Makefile.in (c-lex.o): Update.
+ * c-lex.c: Include target.h.
+ (cb_register_builtins): New.
+ (init_c_lex): Set builtins callback.
+ * c-lex.h (cpp_define, cpp_assert): New prototypes.
+ * cppinit.c (init_builtins): Use callback, including for
+ GXX_WEAK.
+ * cpplib.h (struct cpp_callbacks): New member.
+ * target-def.h (TARGET_REGISTER_CPP_BUILTINS): New.
+ (TARGET_INITIALIZER): Update.
+ * target.h (struct gcc_target): New hook.
+ * tree.c (default_register_cpp_builtins): New.
+ * tree.h (default_register_cpp_builtins): New.
+doc:
+ * tm.texi (TARGET_REGISTER_CPP_BUILTINS): Document.
+
+2002-05-04 Neil Booth <neil@daikokuya.demon.co.uk>
+
* cppinit.c (MAX_WCHAR_TYPE_SIZE): Move to cpplib.h
(cpp_post_options): Move sanity checks to...
(sanity_checks): New.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 2826b64..068add3 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1157,7 +1157,7 @@ c-typeck.o : c-typeck.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
c-lang.o : c-lang.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
langhooks.h langhooks-def.h c-common.h
c-lex.o : c-lex.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) c-lex.h \
- debug.h $(C_TREE_H) c-common.h \
+ debug.h $(C_TREE_H) c-common.h $(TARGET_H) \
c-pragma.h input.h intl.h flags.h toplev.h output.h \
mbchar.h $(CPPLIB_H) $(EXPR_H) $(TM_P_H)
c-objc-common.o : c-objc-common.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) \
diff --git a/gcc/c-lex.c b/gcc/c-lex.c
index 0c10f30..9679b60 100644
--- a/gcc/c-lex.c
+++ b/gcc/c-lex.c
@@ -39,6 +39,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "tm_p.h"
#include "splay-tree.h"
#include "debug.h"
+#include "target.h"
#ifdef MULTIBYTE_CHARS
#include "mbchar.h"
@@ -80,6 +81,7 @@ static tree lex_string PARAMS ((const unsigned char *, unsigned int,
static tree lex_charconst PARAMS ((const cpp_token *));
static void update_header_times PARAMS ((const char *));
static int dump_one_header PARAMS ((splay_tree_node, void *));
+static void cb_register_builtins PARAMS ((cpp_reader *));
static void cb_line_change PARAMS ((cpp_reader *, const cpp_token *, int));
static void cb_ident PARAMS ((cpp_reader *, unsigned int,
const cpp_string *));
@@ -121,6 +123,7 @@ init_c_lex (filename)
cb->ident = cb_ident;
cb->file_change = cb_file_change;
cb->def_pragma = cb_def_pragma;
+ cb->register_builtins = cb_register_builtins;
/* Set the debug callbacks if we can use them. */
if (debug_info_level == DINFO_LEVEL_VERBOSE
@@ -225,6 +228,22 @@ dump_time_statistics ()
splay_tree_foreach (file_info_tree, dump_one_header, 0);
}
+/* Register preprocessor built-ins. */
+static void
+cb_register_builtins (pfile)
+ cpp_reader *pfile;
+{
+ if (c_language == clk_cplusplus)
+ {
+ if (SUPPORTS_ONE_ONLY)
+ cpp_define (pfile, "__GXX_WEAK__");
+ else
+ cpp_define (pfile, "__GXX_WEAK__=0");
+ }
+
+ (*targetm.register_cpp_builtins) (pfile);
+}
+
/* Not yet handled: #pragma, #define, #undef.
No need to deal with linemarkers under normal conditions. */
diff --git a/gcc/c-lex.h b/gcc/c-lex.h
index fed695d..7821ab9 100644
--- a/gcc/c-lex.h
+++ b/gcc/c-lex.h
@@ -34,5 +34,9 @@ extern int indent_level;
struct cpp_reader;
extern struct cpp_reader* parse_in;
+/* Copied from cpplib.h to avoid target code having to pull in all of
+ cpplib.h. */
+extern void cpp_define PARAMS ((struct cpp_reader *, const char *));
+extern void cpp_assert PARAMS ((struct cpp_reader *, const char *));
#endif /* ! GCC_C_LEX_H */
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index 594fa7e..9e7241a 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -769,13 +769,8 @@ init_builtins (pfile)
}
if (CPP_OPTION (pfile, cplusplus))
- {
- _cpp_define_builtin (pfile, "__cplusplus 1");
- if (SUPPORTS_ONE_ONLY)
- _cpp_define_builtin (pfile, "__GXX_WEAK__ 1");
- else
- _cpp_define_builtin (pfile, "__GXX_WEAK__ 0");
- }
+ _cpp_define_builtin (pfile, "__cplusplus 1");
+
if (CPP_OPTION (pfile, objc))
_cpp_define_builtin (pfile, "__OBJC__ 1");
@@ -793,6 +788,9 @@ init_builtins (pfile)
_cpp_define_builtin (pfile, "__STRICT_ANSI__ 1");
else if (CPP_OPTION (pfile, lang) == CLK_ASM)
_cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
+
+ if (pfile->cb.register_builtins)
+ (*pfile->cb.register_builtins) (pfile);
}
#undef BUILTIN
#undef OPERATOR
diff --git a/gcc/cpplib.h b/gcc/cpplib.h
index 9063647..72f4884 100644
--- a/gcc/cpplib.h
+++ b/gcc/cpplib.h
@@ -406,6 +406,9 @@ struct cpp_callbacks
void (*undef) PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
void (*ident) PARAMS ((cpp_reader *, unsigned int, const cpp_string *));
void (*def_pragma) PARAMS ((cpp_reader *, unsigned int));
+ /* Called when the client has a chance to properly register
+ built-ins with cpp_define() and cpp_assert(). */
+ void (*register_builtins) PARAMS ((cpp_reader *));
};
#define CPP_FATAL_LIMIT 1000
@@ -557,6 +560,8 @@ extern cppchar_t
cpp_interpret_charconst PARAMS ((cpp_reader *, const cpp_token *,
int, unsigned int *, int *));
+/* Used to register builtins during the register_builtins callback.
+ The text is the same as the command line argument. */
extern void cpp_define PARAMS ((cpp_reader *, const char *));
extern void cpp_assert PARAMS ((cpp_reader *, const char *));
extern void cpp_undef PARAMS ((cpp_reader *, const char *));
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index cd11b99..c41c098 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -622,6 +622,18 @@ The macro @code{STANDARD_STARTFILE_PREFIX}.
@c prevent bad page break with this line
Here are run-time target specifications.
+@deftypefn {Target Hook} void TARGET_REGISTER_CPP_BUILTINS (cpp_reader *@var{pfile})
+This macro expands to a target-specific function, called by the C
+family of front ends, that allows you to define preprocessor built-in
+macros and assertions at run-time.
+
+Pass the argument (a preprocessor handle) as the first argument to the
+functions @code{cpp_define} and @code{cpp_assert}, declared in
+@file{c-lex.h}. The second argument is the same as the argument to
+the respective command-line option, for example @code{__mips__} for
+@code{cpp_define}, and @code{cpu=mips} for @code{cpp_assert}.
+@end deftypefn
+
@table @code
@findex CPP_PREDEFINES
@item CPP_PREDEFINES
diff --git a/gcc/target-def.h b/gcc/target-def.h
index 76d238e..c419441 100644
--- a/gcc/target-def.h
+++ b/gcc/target-def.h
@@ -179,6 +179,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES default_set_default_type_attributes
#define TARGET_INSERT_ATTRIBUTES default_insert_attributes
#define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P default_function_attribute_inlinable_p
+#define TARGET_REGISTER_CPP_BUILTINS default_register_cpp_builtins
#define TARGET_MS_BITFIELD_LAYOUT_P default_ms_bitfield_layout_p
/* In builtins.c. */
@@ -205,6 +206,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
TARGET_SET_DEFAULT_TYPE_ATTRIBUTES, \
TARGET_INSERT_ATTRIBUTES, \
TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P, \
+ TARGET_REGISTER_CPP_BUILTINS, \
TARGET_MS_BITFIELD_LAYOUT_P, \
TARGET_INIT_BUILTINS, \
TARGET_EXPAND_BUILTIN, \
diff --git a/gcc/target.h b/gcc/target.h
index 1f29412..a21c512 100644
--- a/gcc/target.h
+++ b/gcc/target.h
@@ -44,6 +44,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
to gradually reduce the amount of conditional compilation that is
scattered throughout GCC. */
+struct cpp_reader;
+
struct gcc_target
{
/* Functions that output assembler for the target. */
@@ -198,6 +200,8 @@ struct gcc_target
can be inlined despite its machine attributes, false otherwise. */
bool (* function_attribute_inlinable_p) PARAMS ((tree fndecl));
+ void (* register_cpp_builtins) PARAMS ((struct cpp_reader *));
+
/* Return true if bitfields in RECORD_TYPE should follow the
Microsoft Visual C++ bitfield layout rules. */
bool (* ms_bitfield_layout_p) PARAMS ((tree record_type));
diff --git a/gcc/tree.c b/gcc/tree.c
index 945f3a1..aaef973 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -2543,6 +2543,13 @@ build_type_attribute_variant (ttype, attribute)
return ttype;
}
+/* Default registration of target-specific CPP built-ins. */
+void
+default_register_cpp_builtins (pfile)
+ struct cpp_reader *pfile ATTRIBUTE_UNUSED;
+{
+}
+
/* Default value of targetm.comp_type_attributes that always returns 1. */
int
diff --git a/gcc/tree.h b/gcc/tree.h
index b7a45e7..15397b2 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -2261,6 +2261,8 @@ extern void default_set_default_type_attributes PARAMS ((tree));
extern void default_insert_attributes PARAMS ((tree, tree *));
extern bool default_function_attribute_inlinable_p PARAMS ((tree));
extern bool default_ms_bitfield_layout_p PARAMS ((tree));
+struct cpp_reader;
+extern void default_register_cpp_builtins PARAMS ((struct cpp_reader *));
/* Split a list of declspecs and attributes into two. */