* 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.
From-SVN: r53165
+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
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) \
#include "tm_p.h"
#include "splay-tree.h"
#include "debug.h"
+#include "target.h"
#ifdef MULTIBYTE_CHARS
#include "mbchar.h"
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 *));
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
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. */
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 */
}
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");
_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
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
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 *));
@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
#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. */
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, \
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. */
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));
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
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. */