lang_set_decl_assembler_name langhook

Neil Booth neil@daikokuya.demon.co.uk
Wed Apr 3 09:30:00 GMT 2002


DECL_ASSEMBLER_NAME macro uses the langhook, so to avoid having to
trace every caller (some in header files themselves, ugh) and have
them #include langhooks.h, I instead made that macro into a
function in tree.c, which calls the langhook.

Bootstrapped and regtested.  OK?

Neil.

	* langhooks-def.h (lhd_set_decl_assembler_name,
	LANG_HOOKS_SET_DECL_ASSEMBLER_NAME): New.
	(LANG_HOOKS_INITIALIZER): Update.
	* langhooks.c (lhd_set_decl_assembler_name): New, from tree.c
	* langhooks.h (struct lang_hooks): New hook.
	* tree.c (set_decl_assembler_name): Move to langhooks.c.
	(lang_set_decl_assembler_name): Remove.
	(init_obstacks): Don't set hook.
	(decl_assembler_name): New function.
	* tree.h (DECL_ASSEMBLER_NAME): Turn into a function call.
	(decl_assembler_name): New.
	(lang_set_decl_assembler_name): Remove.
cp:
	* cp-lang.c (LANG_HOOKS_SET_DECL_ASSEMBLER_NAME): Redefine.
	* tree.c (init_tree): Don't set hook.

============================================================
Index: gcc/langhooks-def.h
--- gcc/langhooks-def.h	2002/04/01 20:25:58	1.24
+++ gcc/langhooks-def.h	2002/04/02 18:36:19
@@ -55,6 +55,7 @@ extern void lhd_set_yydebug PARAMS ((int
 extern rtx lhd_expand_expr PARAMS ((tree, rtx, enum machine_mode, int));
 extern void lhd_print_error_function PARAMS ((struct diagnostic_context *,
 					      const char *));
+extern void lhd_set_decl_assembler_name PARAMS ((tree));
 
 /* Declarations of default tree inlining hooks.  */
 tree lhd_tree_inlining_walk_subtrees		PARAMS ((tree *, int *,
@@ -94,6 +95,7 @@ tree lhd_tree_inlining_convert_parm_for_
 #define LANG_HOOKS_UNSAVE_EXPR_NOW	lhd_unsave_expr_now
 #define LANG_HOOKS_MAYBE_BUILD_CLEANUP	lhd_return_null_tree
 #define LANG_HOOKS_MARK_TREE		lhd_do_nothing_t
+#define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lhd_set_decl_assembler_name
 #define LANG_HOOKS_HONOR_READONLY	false
 #define LANG_HOOKS_PRINT_STATISTICS	lhd_do_nothing
 #define LANG_HOOKS_PRINT_XNODE		lhd_print_tree_nothing
@@ -209,6 +211,7 @@ int lhd_tree_dump_type_quals			PARAMS ((
   LANG_HOOKS_UNSAVE_EXPR_NOW, \
   LANG_HOOKS_MAYBE_BUILD_CLEANUP, \
   LANG_HOOKS_MARK_TREE, \
+  LANG_HOOKS_SET_DECL_ASSEMBLER_NAME, \
   LANG_HOOKS_HONOR_READONLY, \
   LANG_HOOKS_PRINT_STATISTICS, \
   LANG_HOOKS_PRINT_XNODE, \
============================================================
Index: gcc/langhooks.c
--- gcc/langhooks.c	2002/03/31 22:40:42	1.24
+++ gcc/langhooks.c	2002/04/02 18:36:21
@@ -123,6 +123,33 @@ lhd_set_yydebug (value)
     fprintf (stderr, "warning: no yacc/bison-generated output to debug!\n");
 }
 
+/* Set the DECL_ASSEMBLER_NAME for DECL.  */
+void
+lhd_set_decl_assembler_name (decl)
+     tree decl;
+{
+  /* The language-independent code should never use the
+     DECL_ASSEMBLER_NAME for lots of DECLs.  Only FUNCTION_DECLs and
+     VAR_DECLs for variables with static storage duration need a real
+     DECL_ASSEMBLER_NAME.  */
+  if (TREE_CODE (decl) == FUNCTION_DECL
+      || (TREE_CODE (decl) == VAR_DECL 
+	  && (TREE_STATIC (decl) 
+	      || DECL_EXTERNAL (decl) 
+	      || TREE_PUBLIC (decl))))
+    /* By default, assume the name to use in assembly code is the
+       same as that used in the source language.  (That's correct
+       for C, and GCC used to set DECL_ASSEMBLER_NAME to the same
+       value as DECL_NAME in build_decl, so this choice provides
+       backwards compatibility with existing front-ends.  */
+    SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
+  else
+    /* Nobody should ever be asking for the DECL_ASSEMBLER_NAME of
+       these DECLs -- unless they're in language-dependent code, in
+       which case set_decl_assembler_name hook should handle things.  */
+    abort ();
+}
+
 /* Provide a default routine to clear the binding stack.  This is used
    by languages that don't need to do anything special.  */
 void
============================================================
Index: gcc/langhooks.h
--- gcc/langhooks.h	2002/04/01 20:25:58	1.31
+++ gcc/langhooks.h	2002/04/02 18:36:23
@@ -242,6 +242,13 @@ struct lang_hooks
   /* Mark nodes held through the lang_specific hooks in the tree.  */
   void (*mark_tree) PARAMS ((tree));
 
+  /* Set the DECL_ASSEMBLER_NAME for a node.  If it is the sort of
+     thing that the assembler should talk about, set
+     DECL_ASSEMBLER_NAME to an appropriate IDENTIFIER_NODE.
+     Otherwise, set it to the ERROR_MARK_NODE to ensure that the
+     assembler does not talk about it.  */
+  void (*set_decl_assembler_name) PARAMS ((tree));
+
   /* Nonzero if TYPE_READONLY and TREE_READONLY should always be honored.  */
   bool honor_readonly;
 
============================================================
Index: gcc/tree.c
--- gcc/tree.c	2002/03/31 22:40:43	1.249
+++ gcc/tree.c	2002/04/02 18:36:57
@@ -133,43 +133,9 @@ static int type_hash_marked_p PARAMS ((c
 static void type_hash_mark PARAMS ((const void *));
 static int mark_tree_hashtable_entry PARAMS((void **, void *));
 
-/* Set the DECL_ASSEMBLER_NAME for a node.  If it is the sort of thing
-   that the assembler should talk about, set DECL_ASSEMBLER_NAME to an
-   appropriate IDENTIFIER_NODE.  Otherwise, set it to the
-   ERROR_MARK_NODE to ensure that the assembler does not talk about
-   it.  */
-void (*lang_set_decl_assembler_name)     PARAMS ((tree));
-
 tree global_trees[TI_MAX];
 tree integer_types[itk_none];
 
-/* Set the DECL_ASSEMBLER_NAME for DECL.  */
-void
-set_decl_assembler_name (decl)
-     tree decl;
-{
-  /* The language-independent code should never use the
-     DECL_ASSEMBLER_NAME for lots of DECLs.  Only FUNCTION_DECLs and
-     VAR_DECLs for variables with static storage duration need a real
-     DECL_ASSEMBLER_NAME.  */
-  if (TREE_CODE (decl) == FUNCTION_DECL
-      || (TREE_CODE (decl) == VAR_DECL 
-	  && (TREE_STATIC (decl) 
-	      || DECL_EXTERNAL (decl) 
-	      || TREE_PUBLIC (decl))))
-    /* By default, assume the name to use in assembly code is the
-       same as that used in the source language.  (That's correct
-       for C, and GCC used to set DECL_ASSEMBLER_NAME to the same
-       value as DECL_NAME in build_decl, so this choice provides
-       backwards compatibility with existing front-ends.  */
-    SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
-  else
-    /* Nobody should ever be asking for the DECL_ASSEMBLER_NAME of
-       these DECLs -- unless they're in language-dependent code, in
-       which case lang_set_decl_assembler_name should handle things.  */
-    abort ();
-}
-
 /* Init the principal obstacks.  */
 
 void
@@ -184,9 +150,6 @@ init_obstacks ()
 			  type_hash_mark);
   ggc_add_tree_root (global_trees, TI_MAX);
   ggc_add_tree_root (integer_types, itk_none);
-
-  /* Set lang_set_decl_set_assembler_name to a default value.  */
-  lang_set_decl_assembler_name = set_decl_assembler_name;
 }
 
 
@@ -212,6 +175,18 @@ perm_calloc (nelem, size)
   char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
   memset (rval, 0, nelem * size);
   return rval;
+}
+
+/* The name of the object as the assembler will see it (but before any
+   translations made by ASM_OUTPUT_LABELREF).  Often this is the same
+   as DECL_NAME.  It is an IDENTIFIER_NODE.  */
+tree
+decl_assembler_name (decl)
+     tree decl;
+{
+  if (!DECL_ASSEMBLER_NAME_SET_P (decl))
+    (*lang_hooks.set_decl_assembler_name) (decl);
+  return DECL_CHECK (decl)->decl.assembler_name;
 }
 
 /* Compute the number of bytes occupied by 'node'.  This routine only
============================================================
Index: gcc/tree.h
--- gcc/tree.h	2002/04/01 20:25:58	1.324
+++ gcc/tree.h	2002/04/02 18:37:05
@@ -1352,11 +1352,7 @@ struct tree_type
 /* The name of the object as the assembler will see it (but before any
    translations made by ASM_OUTPUT_LABELREF).  Often this is the same
    as DECL_NAME.  It is an IDENTIFIER_NODE.  */
-#define DECL_ASSEMBLER_NAME(NODE)		\
-  ((DECL_ASSEMBLER_NAME_SET_P (NODE)		\
-    ? (void) 0					\
-    : (*lang_set_decl_assembler_name) (NODE)),	\
-   DECL_CHECK (NODE)->decl.assembler_name)
+#define DECL_ASSEMBLER_NAME(NODE) decl_assembler_name (NODE)
 
 /* Returns non-zero if the DECL_ASSEMBLER_NAME for NODE has been set.  If zero,
    the NODE might still have a DECL_ASSEMBLER_NAME -- it just hasn't been set
@@ -2057,6 +2053,7 @@ extern double approx_sqrt		PARAMS ((doub
 
 extern char *permalloc			PARAMS ((int));
 extern char *expralloc			PARAMS ((int));
+extern tree decl_assembler_name		PARAMS ((tree));
 
 /* Compute the number of bytes occupied by 'node'.  This routine only
    looks at TREE_CODE and, if the code is TREE_VEC, TREE_VEC_LENGTH.  */
@@ -2810,13 +2807,6 @@ extern int alias_sets_conflict_p		PARAMS
 							 HOST_WIDE_INT));
 extern int readonly_fields_p			PARAMS ((tree));
 extern int objects_must_conflict_p		PARAMS ((tree, tree));
-
-/* Set the DECL_ASSEMBLER_NAME for a node.  If it is the sort of thing
-   that the assembler should talk about, set DECL_ASSEMBLER_NAME to an
-   appropriate IDENTIFIER_NODE.  Otherwise, set it to the
-   ERROR_MARK_NODE to ensure that the assembler does not talk about
-   it.  */
-extern void (*lang_set_decl_assembler_name)     PARAMS ((tree));
 
 struct obstack;
 
============================================================
Index: gcc/cp/cp-lang.c
--- gcc/cp/cp-lang.c	2002/04/01 20:26:11	1.25
+++ gcc/cp/cp-lang.c	2002/04/02 18:37:07
@@ -67,6 +67,8 @@ static bool ok_to_generate_alias_set_for
 #define LANG_HOOKS_MARK_TREE cxx_mark_tree
 #undef LANG_HOOKS_UNSAFE_FOR_REEVAL
 #define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval
+#undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
+#define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME mangle_decl
 #undef LANG_HOOKS_MARK_ADDRESSABLE
 #define LANG_HOOKS_MARK_ADDRESSABLE cxx_mark_addressable
 #undef LANG_HOOKS_PRINT_STATISTICS
============================================================
Index: gcc/cp/tree.c
--- gcc/cp/tree.c	2002/03/29 08:43:22	1.276
+++ gcc/cp/tree.c	2002/04/02 18:37:11
@@ -2295,7 +2295,6 @@ void
 init_tree ()
 {
   lang_statement_code_p = cp_statement_code_p;
-  lang_set_decl_assembler_name = mangle_decl;
   list_hash_table = htab_create (31, list_hash, list_hash_eq, NULL);
   ggc_add_root (&list_hash_table, 1, 
 		sizeof (list_hash_table),



More information about the Gcc-patches mailing list