This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] 5 function langhooks


I posted this about a week ago.  It adds 5 langhooks related to
functions.  The need for 4 of these can probably be removed, but
that's clean-up, which comes after getting all hooks implemented.

OK?

Neil.

	* Makefile.in: Update.
	* decl.c (push_c_function_context, pop_c_function_context,
	mark_c_function_context): Rename for consistency.
	* c-objc-common.c (c_objc_common_init): Langhooks set elsewhere.
	* c-tree.h (push_c_function_context, pop_c_function_context,
	mark_c_function_context): Rename for consistency.
	* c-lang.c (LANG_HOOKS_FUNCTION_ENTER_NESTED,
	LANG_HOOKS_FUNCTION_LEAVE_NESTED, LANG_HOOKS_FUNCTION_MARK): Redefine.
	* function.c (init_lang_status, save_lang_status,
	restore_lang_status, mark_lang_status, free_lang_status):
	Move to langhooks.h.
	(push_function_context_to, pop_function_context_from,
	free_after_parsing, prepare_function_start, ggc_mark_struct_function):
	Update.
	* function.h (init_lang_status, save_lang_status,
	restore_lang_status, mark_lang_status, free_lang_status):
	Move to langhooks.h.
	* langhooks-def.h (LANG_HOOKS_FUNCTION_ENTER,
	LANG_HOOKS_FUNCTION_LEAVE, LANG_HOOKS_FUNCTION_ENTER_NESTED,
	LANG_HOOKS_FUNCTION_LEAVE_NESTED, LANG_HOOKS_FUNCTION_MARK,
	LANG_HOOKS_FUNCTION_INITIALIZER): New.
	(LANG_HOOKS_INITIALIZER): Update.
	(lhd_do_nothing_f): New.
	* langhooks.h (struct lang_hooks_for_functions): New.
	(struct lang_hooks): New hooks.
	* langhooks.c (lhd_do_nothing_f): New.
cp:
	* cp-lang.c (LANG_HOOKS_FUNCTION_ENTER,
	LANG_HOOKS_FUNCTION_LEAVE, LANG_HOOKS_FUNCTION_MARK): Redefine.
	* cp-tree.h (cxx_push_function_context, cxx_pop_function_context,
	cxx_mark_function_context): New.
	* decl.c (push_cp_function_context, pop_cp_function_context,
	mark_cp_function_context): Rename for consistency.
	(cxx_init_decl_processing): Don't set old hooks.
objc:
	* objc-lang.c (LANG_HOOKS_FUNCTION_ENTER_NESTED,
	LANG_HOOKS_FUNCTION_LEAVE_NESTED, LANG_HOOKS_FUNCTION_MARK): Redefine.

============================================================
Index: gcc/Makefile.in
--- gcc/Makefile.in	2002/03/15 07:09:36	1.839
+++ gcc/Makefile.in	2002/03/17 21:09:39
@@ -1152,9 +1152,9 @@ c-decl.o : c-decl.c $(CONFIG_H) $(SYSTEM
 c-typeck.o : c-typeck.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
     $(TARGET_H) flags.h intl.h output.h $(EXPR_H) $(RTL_H) toplev.h $(TM_P_H)
 c-lang.o : c-lang.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
-    langhooks.h langhooks-def.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) \
+    debug.h $(C_TREE_H) c-common.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) \
@@ -1378,7 +1378,8 @@ varasm.o : varasm.c $(CONFIG_H) $(SYSTEM
    $(HASHTAB_H) $(TARGET_H) langhooks.h
 function.o : function.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) $(TREE_H) flags.h \
    function.h $(EXPR_H) libfuncs.h $(REGS_H) hard-reg-set.h \
-   insn-config.h $(RECOG_H) output.h toplev.h except.h hash.h $(GGC_H) $(TM_P_H)
+   insn-config.h $(RECOG_H) output.h toplev.h except.h hash.h $(GGC_H) \
+   $(TM_P_H) langhooks.h
 stmt.o : stmt.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) $(TREE_H) flags.h function.h  \
    insn-config.h hard-reg-set.h $(EXPR_H) libfuncs.h except.h \
    $(LOOP_H) $(RECOG_H) toplev.h output.h varray.h $(GGC_H) $(TM_P_H)
============================================================
Index: gcc/c-decl.c
--- gcc/c-decl.c	2002/03/15 07:09:43	1.306
+++ gcc/c-decl.c	2002/03/17 21:09:56
@@ -6769,7 +6769,7 @@ finish_function (nested)
 
       /* Let the error reporting routines know that we're outside a
 	 function.  For a nested function, this value is used in
-	 pop_c_function_context and then reset via pop_function_context.  */
+	 c_pop_function_context and then reset via pop_function_context.  */
       current_function_decl = NULL;
     }
 }
@@ -6944,7 +6944,7 @@ c_expand_body (fndecl, nested_p, can_def
       /* Stop pointing to the local nodes about to be freed.
 	 But DECL_INITIAL must remain nonzero so we know this
 	 was an actual function definition.
-	 For a nested function, this is done in pop_c_function_context.
+	 For a nested function, this is done in c_pop_function_context.
 	 If rest_of_compilation set this to 0, leave it 0.  */
       if (DECL_INITIAL (fndecl) != 0)
 	DECL_INITIAL (fndecl) = error_mark_node;
@@ -7055,7 +7055,7 @@ struct c_language_function
    used during compilation of a C function.  */
 
 void
-push_c_function_context (f)
+c_push_function_context (f)
      struct function *f;
 {
   struct c_language_function *p;
@@ -7078,7 +7078,7 @@ push_c_function_context (f)
 /* Restore the variables used during compilation of a C function.  */
 
 void
-pop_c_function_context (f)
+c_pop_function_context (f)
      struct function *f;
 {
   struct c_language_function *p
@@ -7119,7 +7119,7 @@ pop_c_function_context (f)
 /* Mark the language specific parts of F for GC.  */
 
 void
-mark_c_function_context (f)
+c_mark_function_context (f)
      struct function *f;
 {
   struct c_language_function *p
============================================================
Index: gcc/c-lang.c
--- gcc/c-lang.c	2002/03/17 20:41:34	1.77
+++ gcc/c-lang.c	2002/03/17 21:09:58
@@ -58,6 +58,12 @@ static void c_post_options PARAMS ((void
 #define LANG_HOOKS_PRINT_IDENTIFIER c_print_identifier
 #undef LANG_HOOKS_SET_YYDEBUG
 #define LANG_HOOKS_SET_YYDEBUG c_set_yydebug
+#undef LANG_HOOKS_FUNCTION_ENTER_NESTED
+#define LANG_HOOKS_FUNCTION_ENTER_NESTED c_push_function_context
+#undef LANG_HOOKS_FUNCTION_LEAVE_NESTED
+#define LANG_HOOKS_FUNCTION_LEAVE_NESTED c_pop_function_context
+#undef LANG_HOOKS_FUNCTION_MARK
+#define LANG_HOOKS_FUNCTION_MARK c_mark_function_context
 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL c_dup_lang_specific_decl
 
============================================================
Index: gcc/c-objc-common.c
--- gcc/c-objc-common.c	2002/03/13 01:42:30	1.4
+++ gcc/c-objc-common.c	2002/03/17 21:09:58
@@ -219,9 +219,6 @@ c_objc_common_init (filename)
 
   lang_unsafe_for_reeval = c_unsafe_for_reeval;
 
-  save_lang_status = &push_c_function_context;
-  restore_lang_status = &pop_c_function_context;
-  mark_lang_status = &mark_c_function_context;
   lang_expand_expr = c_expand_expr;
   lang_expand_decl_stmt = c_expand_decl_stmt;
 
============================================================
Index: gcc/c-tree.h
--- gcc/c-tree.h	2002/03/17 20:41:35	1.84
+++ gcc/c-tree.h	2002/03/17 21:09:59
@@ -196,9 +196,9 @@ extern tree lookup_name                 
 extern tree lookup_name_current_level		PARAMS ((tree));
 extern void parmlist_tags_warning               PARAMS ((void));
 extern void pending_xref_error                  PARAMS ((void));
-extern void mark_c_function_context             PARAMS ((struct function *));
-extern void push_c_function_context             PARAMS ((struct function *));
-extern void pop_c_function_context              PARAMS ((struct function *));
+extern void c_mark_function_context             PARAMS ((struct function *));
+extern void c_push_function_context             PARAMS ((struct function *));
+extern void c_pop_function_context              PARAMS ((struct function *));
 extern void pop_label_level                     PARAMS ((void));
 extern void push_label_level                    PARAMS ((void));
 extern void push_parm_decl                      PARAMS ((tree));
============================================================
Index: gcc/function.c
--- gcc/function.c	2002/03/13 06:10:23	1.350
+++ gcc/function.c	2002/03/17 21:10:17
@@ -59,6 +59,7 @@ Software Foundation, 59 Temple Place - S
 #include "ggc.h"
 #include "tm_p.h"
 #include "integrate.h"
+#include "langhooks.h"
 
 #ifndef TRAMPOLINE_ALIGNMENT
 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
@@ -132,13 +133,6 @@ void (*free_machine_status) PARAMS ((str
    that will need garbage collection.  */
 void (*mark_machine_status) PARAMS ((struct function *));
 
-/* Likewise, but for language-specific data.  */
-void (*init_lang_status) PARAMS ((struct function *));
-void (*save_lang_status) PARAMS ((struct function *));
-void (*restore_lang_status) PARAMS ((struct function *));
-void (*mark_lang_status) PARAMS ((struct function *));
-void (*free_lang_status) PARAMS ((struct function *));
-
 /* The FUNCTION_DECL for an inline function currently being expanded.  */
 tree inline_function_decl;
 
@@ -327,7 +321,7 @@ find_function_data (decl)
 
 /* Save the current context for compilation of a nested function.
    This is called from language-specific code.  The caller should use
-   the save_lang_status callback to save any language-specific state,
+   the enter_nested langhook to save any language-specific state,
    since this function knows only about language-independent
    variables.  */
 
@@ -356,8 +350,7 @@ push_function_context_to (context)
   outer_function_chain = p;
   p->fixup_var_refs_queue = 0;
 
-  if (save_lang_status)
-    (*save_lang_status) (p);
+  (*lang_hooks.function.enter_nested) (p);
 
   cfun = 0;
 }
@@ -386,8 +379,7 @@ pop_function_context_from (context)
 
   restore_emit_status (p);
 
-  if (restore_lang_status)
-    (*restore_lang_status) (p);
+  (*lang_hooks.function.leave_nested) (p);
 
   /* Finish doing put_var_into_stack for any of our variables which became
      addressable during the nested function.  If only one entry has to be
@@ -440,8 +432,7 @@ free_after_parsing (f)
   /* f->varasm is used by code generation.  */
   /* f->eh->eh_return_stub_label is used by code generation.  */
 
-  if (free_lang_status)
-    (*free_lang_status) (f);
+  (*lang_hooks.function.leave) (f);
   free_stmt_status (f);
 }
 
@@ -6232,8 +6223,7 @@ prepare_function_start ()
 
   current_function_outgoing_args_size = 0;
 
-  if (init_lang_status)
-    (*init_lang_status) (cfun);
+  (*lang_hooks.function.enter) (cfun);
   if (init_machine_status)
     (*init_machine_status) (cfun);
 }
@@ -7966,8 +7956,7 @@ ggc_mark_struct_function (f)
 
   if (mark_machine_status)
     (*mark_machine_status) (f);
-  if (mark_lang_status)
-    (*mark_lang_status) (f);
+  (*lang_hooks.function.mark) (f);
 
   if (f->original_arg_vector)
     ggc_mark_rtvec ((rtvec) f->original_arg_vector);
============================================================
Index: gcc/function.h
--- gcc/function.h	2002/03/15 10:17:16	1.76
+++ gcc/function.h	2002/03/17 21:10:20
@@ -574,13 +574,6 @@ extern void (*free_machine_status)	PARAM
    that will need garbage collection.  */
 extern void (*mark_machine_status)	PARAMS ((struct function *));
 
-/* Likewise, but for language-specific data.  */
-extern void (*init_lang_status)         PARAMS ((struct function *));
-extern void (*mark_lang_status)		PARAMS ((struct function *));
-extern void (*save_lang_status)		PARAMS ((struct function *));
-extern void (*restore_lang_status)	PARAMS ((struct function *));
-extern void (*free_lang_status)         PARAMS ((struct function *));
-
 /* Save and restore status information for a nested function.  */
 extern void restore_emit_status		PARAMS ((struct function *));
 extern void free_after_parsing		PARAMS ((struct function *));
============================================================
Index: gcc/langhooks-def.h
--- gcc/langhooks-def.h	2002/03/17 20:41:35	1.11
+++ gcc/langhooks-def.h	2002/03/17 21:10:20
@@ -39,6 +39,7 @@ extern HOST_WIDE_INT hook_get_alias_set_
 
 extern void lhd_do_nothing PARAMS ((void));
 extern void lhd_do_nothing_t PARAMS ((tree));
+extern void lhd_do_nothing_f PARAMS ((struct function *));
 extern int lhd_decode_option PARAMS ((int, char **));
 extern HOST_WIDE_INT lhd_get_alias_set PARAMS ((tree));
 extern tree lhd_return_tree PARAMS ((tree));
@@ -85,6 +86,11 @@ void lhd_tree_inlining_end_inlining		PAR
 #define LANG_HOOKS_PRINT_DECL		lhd_print_tree_nothing
 #define LANG_HOOKS_PRINT_TYPE		lhd_print_tree_nothing
 #define LANG_HOOKS_PRINT_IDENTIFIER	lhd_print_tree_nothing
+#define LANG_HOOKS_FUNCTION_ENTER	lhd_do_nothing_f
+#define LANG_HOOKS_FUNCTION_LEAVE	lhd_do_nothing_f
+#define LANG_HOOKS_FUNCTION_ENTER_NESTED	lhd_do_nothing_f
+#define LANG_HOOKS_FUNCTION_LEAVE_NESTED	lhd_do_nothing_f
+#define LANG_HOOKS_FUNCTION_MARK	lhd_do_nothing_f
 #define LANG_HOOKS_SET_YYDEBUG		lhd_set_yydebug
 
 /* Tree inlining hooks.  */
@@ -121,6 +127,14 @@ void lhd_tree_inlining_end_inlining		PAR
   LANG_HOOKS_TREE_INLINING_END_INLINING \
 } \
 
+#define LANG_HOOKS_FUNCTION_INITIALIZER { \
+  LANG_HOOKS_FUNCTION_ENTER, \
+  LANG_HOOKS_FUNCTION_LEAVE, \
+  LANG_HOOKS_FUNCTION_ENTER_NESTED, \
+  LANG_HOOKS_FUNCTION_LEAVE_NESTED, \
+  LANG_HOOKS_FUNCTION_MARK \
+}
+
 /* Tree dump hooks.  */
 int lhd_tree_dump_dump_tree 			PARAMS ((void *, tree));
 int lhd_tree_dump_type_quals			PARAMS ((tree));
@@ -157,6 +171,7 @@ int lhd_tree_dump_type_quals			PARAMS ((
   LANG_HOOKS_PRINT_TYPE, \
   LANG_HOOKS_PRINT_IDENTIFIER, \
   LANG_HOOKS_SET_YYDEBUG, \
+  LANG_HOOKS_FUNCTION_INITIALIZER, \
   LANG_HOOKS_TREE_INLINING_INITIALIZER, \
   LANG_HOOKS_TREE_DUMP_INITIALIZER \
 }
============================================================
Index: gcc/langhooks.c
--- gcc/langhooks.c	2002/02/28 07:39:24	1.17
+++ gcc/langhooks.c	2002/03/17 21:10:25
@@ -39,11 +39,19 @@ lhd_do_nothing ()
 {
 }
 
-/* Do nothing.  */
+/* Do nothing (tree).  */
 
 void
 lhd_do_nothing_t (t)
      tree t ATTRIBUTE_UNUSED;
+{
+}
+
+/* Do nothing (function).  */
+
+void
+lhd_do_nothing_f (f)
+     struct function *f ATTRIBUTE_UNUSED;
 {
 }
 
============================================================
Index: gcc/langhooks.h
--- gcc/langhooks.h	2002/03/17 20:41:35	1.18
+++ gcc/langhooks.h	2002/03/17 21:10:25
@@ -50,6 +50,26 @@ struct lang_hooks_for_tree_inlining
   void (*end_inlining) PARAMS ((union tree_node *));
 };
 
+/* Lang hooks for management of language-specific data or status
+   when entering / leaving functions etc.  */
+struct lang_hooks_for_functions
+{
+  /* Called when entering a function.  */
+  void (*enter) PARAMS ((struct function *));
+
+  /* Called when leaving a function.  */
+  void (*leave) PARAMS ((struct function *));
+
+  /* Called when entering a nested function.  */
+  void (*enter_nested) PARAMS ((struct function *));
+
+  /* Called when leaving a nested function.  */
+  void (*leave_nested) PARAMS ((struct function *));
+
+  /* Lang-specific function data marking for GC.  */
+  void (*mark) PARAMS ((struct function *));
+};
+
 /* The following hooks are used by tree-dump.c.  */
 
 struct lang_hooks_for_tree_dump
@@ -161,6 +181,9 @@ struct lang_hooks
      command line.  By default, if the parameter is non-zero, prints a
      warning that the front end does not use such a parser.  */
   void (*set_yydebug) PARAMS ((int));
+
+  /* Function-related language hooks.  */
+  struct lang_hooks_for_functions function;
 
   struct lang_hooks_for_tree_inlining tree_inlining;
   
============================================================
Index: gcc/cp/cp-lang.c
--- gcc/cp/cp-lang.c	2002/03/17 20:41:42	1.14
+++ gcc/cp/cp-lang.c	2002/03/17 21:10:25
@@ -69,6 +69,12 @@ static bool ok_to_generate_alias_set_for
 #define LANG_HOOKS_PRINT_IDENTIFIER cxx_print_identifier
 #undef LANG_HOOKS_SET_YYDEBUG
 #define LANG_HOOKS_SET_YYDEBUG cxx_set_yydebug
+#undef LANG_HOOKS_FUNCTION_ENTER
+#define LANG_HOOKS_FUNCTION_ENTER cxx_push_function_context
+#undef LANG_HOOKS_FUNCTION_LEAVE
+#define LANG_HOOKS_FUNCTION_LEAVE cxx_pop_function_context
+#undef LANG_HOOKS_FUNCTION_MARK
+#define LANG_HOOKS_FUNCTION_MARK cxx_mark_function_context
 
 #undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES
 #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES \
============================================================
Index: gcc/cp/cp-tree.h
--- gcc/cp/cp-tree.h	2002/03/16 18:30:11	1.691
+++ gcc/cp/cp-tree.h	2002/03/17 21:10:34
@@ -3660,6 +3660,9 @@ extern void adjust_clone_args			PARAMS (
 /* decl.c */
 /* resume_binding_level */
 extern void cxx_init_decl_processing		PARAMS ((void));
+extern void cxx_push_function_context		PARAMS ((struct function *));
+extern void cxx_pop_function_context		PARAMS ((struct function *));
+extern void cxx_mark_function_context		PARAMS ((struct function *));
 extern int toplevel_bindings_p			PARAMS ((void));
 extern int namespace_bindings_p			PARAMS ((void));
 extern void keep_next_level			PARAMS ((int));
============================================================
Index: gcc/cp/decl.c
--- gcc/cp/decl.c	2002/03/15 20:08:34	1.877
+++ gcc/cp/decl.c	2002/03/17 21:11:08
@@ -125,11 +125,8 @@ static void layout_var_decl PARAMS ((tre
 static void maybe_commonize_var PARAMS ((tree));
 static tree check_initializer PARAMS ((tree, tree));
 static void make_rtl_for_nonlocal_decl PARAMS ((tree, tree, const char *));
-static void push_cp_function_context PARAMS ((struct function *));
-static void pop_cp_function_context PARAMS ((struct function *));
 static void mark_binding_level PARAMS ((void *));
 static void mark_named_label_lists PARAMS ((void *, void *));
-static void mark_cp_function_context PARAMS ((struct function *));
 static void mark_saved_scope PARAMS ((void *));
 static void mark_lang_function PARAMS ((struct cp_language_function *));
 static void save_function_data PARAMS ((tree));
@@ -6401,9 +6398,6 @@ cxx_init_decl_processing ()
   initialize_predefined_identifiers ();
 
   /* Fill in back-end hooks.  */
-  init_lang_status = &push_cp_function_context;
-  free_lang_status = &pop_cp_function_context;
-  mark_lang_status = &mark_cp_function_context;
   lang_missing_noreturn_ok_p = &cp_missing_noreturn_ok_p;
 
   cp_parse_init ();
@@ -14252,7 +14246,7 @@ finish_function (flags)
   if (! nested)
     /* Let the error reporting routines know that we're outside a
        function.  For a nested function, this value is used in
-       pop_cp_function_context and then reset via pop_function_context.  */
+       cxx_pop_function_context and then reset via pop_function_context.  */
     current_function_decl = NULL_TREE;
 
   return fndecl;
@@ -14555,8 +14549,8 @@ revert_static_member_fn (decl)
 /* Initialize the variables used during compilation of a C++
    function.  */
 
-static void
-push_cp_function_context (f)
+void
+cxx_push_function_context (f)
      struct function *f;
 {
   struct cp_language_function *p
@@ -14576,8 +14570,8 @@ push_cp_function_context (f)
 /* Free the language-specific parts of F, now that we've finished
    compiling the function.  */
 
-static void
-pop_cp_function_context (f)
+void
+cxx_pop_function_context (f)
      struct function *f;
 {
   if (f->language)
@@ -14615,8 +14609,8 @@ mark_lang_function (p)
 
 /* Mark the language-specific data in F for GC.  */
 
-static void
-mark_cp_function_context (f)
+void
+cxx_mark_function_context (f)
      struct function *f;
 {
   mark_lang_function ((struct cp_language_function *) f->language);
============================================================
Index: gcc/objc/objc-lang.c
--- gcc/objc/objc-lang.c	2002/03/17 20:41:46	1.5
+++ gcc/objc/objc-lang.c	2002/03/17 21:11:08
@@ -54,6 +54,12 @@ static void objc_post_options           
 #define LANG_HOOKS_PRINT_IDENTIFIER c_print_identifier
 #undef LANG_HOOKS_SET_YYDEBUG
 #define LANG_HOOKS_SET_YYDEBUG c_set_yydebug
+#undef LANG_HOOKS_FUNCTION_ENTER_NESTED
+#define LANG_HOOKS_FUNCTION_ENTER_NESTED c_push_function_context
+#undef LANG_HOOKS_FUNCTION_LEAVE_NESTED
+#define LANG_HOOKS_FUNCTION_LEAVE_NESTED c_pop_function_context
+#undef LANG_HOOKS_FUNCTION_MARK
+#define LANG_HOOKS_FUNCTION_MARK c_mark_function_context
 /* Inlining hooks same as the C front end.  */
 #undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN
 #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]