Makefile.in (c-lex.o): Update.
authorNeil Booth <neil@daikokuya.demon.co.uk>
Sat, 4 May 2002 20:15:00 +0000 (20:15 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Sat, 4 May 2002 20:15:00 +0000 (20:15 +0000)
* 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

gcc/ChangeLog
gcc/Makefile.in
gcc/c-lex.c
gcc/c-lex.h
gcc/cppinit.c
gcc/cpplib.h
gcc/doc/tm.texi
gcc/target-def.h
gcc/target.h
gcc/tree.c
gcc/tree.h

index e91a7793321a279eb7350d4c47a2b6ce9fd1df8c..98117b19c257b8cd2e14d88576697d67140986ae 100644 (file)
@@ -1,3 +1,21 @@
+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
index 2826b645e9ab4a3c6e1001a836d77d104e91d672..068add3f977fcd8392057098b3a4aac5d5834a94 100644 (file)
@@ -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) \
index 0c10f30672e985d0d6c50673aaac93f23c2d975a..9679b607f973a584785eb529dccb1b92597d8a5e 100644 (file)
@@ -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.  */
 
index fed695d3394cc260ac237322abecccd73f0d8d39..7821ab90ee134178e06ef45b797a4cdecfc0edc8 100644 (file)
@@ -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 */
index 594fa7ed7398b46b7555095380111aa80bb946ad..9e7241a4ea313b2e8923cee019a85fd44328acec 100644 (file)
@@ -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
index 9063647f6db76a6a65655681f7303bbaad3a92ec..72f4884e41999670a39319e4942ffa543fc1fb68 100644 (file)
@@ -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 *));
index cd11b991ce8d8a352b2ded52c33c97adffac4fb1..c41c0984b2c45c5b904e4c21c4f65b7173c0653f 100644 (file)
@@ -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
index 76d238e07267b6584bc8c5afdd97ae528ef5d269..c419441976ab11e7db6b4818262370f2c26b25a7 100644 (file)
@@ -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,                       \
index 1f294126ae9434412b9a100bb20594a856f322b9..a21c5126b79dbee0e863e8526b9ee268586fed99 100644 (file)
@@ -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));
index 945f3a15eca873884ff82a2aaaa5afab71c083b7..aaef9737db6057b5611174e2fb2a2d368abf7c14 100644 (file)
@@ -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
index b7a45e77938970f5bfed29a901ac5c2480fbb061..15397b242c3f161d8c6bcbd74578c653bab29f66 100644 (file)
@@ -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.  */