constify (first|weak)_global_function_name
Zack Weinberg
zack@wolery.cumb.org
Tue Apr 4 14:38:00 GMT 2000
This patch constifies first_global_function_name and
weak_global_function_name, and moves their declarations to function.h.
zw
top level:
* function.h: Declare first_global_function_name and
weak_global_function_name here. Make them const char *.
* tree.c: Don't declare them here.
(get_file_function_name_long): Constify strings. Remove
obsolete code.
* varasm.c: Define f_g_f_n and w_g_f_n as const char *.
(assemble_start_function): Constify strings.
ch:
* Makefile.in (grant.o): Depend on function.h.
* grant.c: Include function.h. Don't declare
first_global_function_name or asm_out_file.
(chill_finish_compile): Constify strings.
===================================================================
Index: function.h
--- function.h 2000/04/01 00:09:22 1.54
+++ function.h 2000/04/04 21:34:27
@@ -238,7 +238,7 @@ struct function
/* Nonzero if function being compiled contains nested functions. */
int contains_functions;
- /* Nonzero if the function being compiled issues a computed jump. */
+ /* Nonzero if function being compiled issues a computed jump. */
int has_computed_jump;
/* Nonzero if the current function is a thunk (a lightweight function that
@@ -549,6 +549,11 @@ struct function *find_function_data PARA
/* Pointer to chain of `struct function' for containing functions. */
extern struct function *outer_function_chain;
+
+/* The assembler names of the first globally-visible object and the
+ first globally-visible weak definition output. */
+extern const char *first_global_object_name;
+extern const char *weak_global_object_name;
/* Set NOTE_BLOCK for each block note in the current function. */
extern void identify_blocks PARAMS ((void));
===================================================================
Index: tree.c
--- tree.c 2000/04/04 02:24:49 1.135
+++ tree.c 2000/04/04 21:34:29
@@ -5337,9 +5337,6 @@ dump_tree_statistics ()
#endif /* NO_DOT_IN_LABEL */
#endif /* NO_DOLLAR_IN_LABEL */
-extern char *first_global_object_name;
-extern char *weak_global_object_name;
-
/* Appends 6 random characters to TEMPLATE to (hopefully) avoid name
clashes in cases where we can't reliably choose a unique name.
@@ -5395,7 +5392,7 @@ get_file_function_name_long (type)
const char *type;
{
char *buf;
- register char *p;
+ const char *p;
if (first_global_object_name)
p = first_global_object_name;
@@ -5406,16 +5403,18 @@ get_file_function_name_long (type)
const char *name = weak_global_object_name;
const char *file = main_input_filename;
+ char *q;
if (! name)
name = "";
if (! file)
file = input_filename;
- p = (char *) alloca (7 + strlen (name) + strlen (file));
+ q = (char *) alloca (7 + strlen (name) + strlen (file));
- sprintf (p, "%s%s", name, file);
- append_random_chars (p);
+ sprintf (q, "%s%s", name, file);
+ append_random_chars (q);
+ p = q;
}
buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
@@ -5430,22 +5429,18 @@ get_file_function_name_long (type)
/* Don't need to pull weird characters out of global names. */
if (p != first_global_object_name)
{
- for (p = buf+11; *p; p++)
- if (! ( ISDIGIT(*p)
-#if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
-#ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */
- || *p == '.'
-#endif
-#endif
+ char *q;
+ for (q = buf+11; *q; q++)
+ if (! ( ISDIGIT(*q)
#ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
- || *p == '$'
+ || *q == '$'
#endif
#ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
- || *p == '.'
+ || *q == '.'
#endif
- || ISUPPER(*p)
- || ISLOWER(*p)))
- *p = '_';
+ || ISUPPER(*q)
+ || ISLOWER(*q)))
+ *q = '_';
}
return get_identifier (buf);
===================================================================
Index: varasm.c
--- varasm.c 2000/03/25 18:34:05 1.110
+++ varasm.c 2000/04/04 21:34:29
@@ -77,8 +77,8 @@ Boston, MA 02111-1307, USA. */
extern FILE *asm_out_file;
/* The (assembler) name of the first globally-visible object output. */
-char *first_global_object_name;
-char *weak_global_object_name;
+const char *first_global_object_name;
+const char *weak_global_object_name;
extern struct obstack *current_obstack;
extern struct obstack *saveable_obstack;
@@ -1060,8 +1060,9 @@ assemble_start_function (decl, fnname)
{
if (! first_global_object_name)
{
+ char *q;
const char *p;
- char **name;
+ const char **name;
if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
name = &first_global_object_name;
@@ -1069,8 +1070,9 @@ assemble_start_function (decl, fnname)
name = &weak_global_object_name;
STRIP_NAME_ENCODING (p, fnname);
- *name = permalloc (strlen (p) + 1);
- strcpy (*name, p);
+ q = permalloc (strlen (p) + 1);
+ strcpy (q, p);
+ *name = q;
}
#ifdef ASM_WEAKEN_LABEL
@@ -1438,10 +1440,12 @@ assemble_variable (decl, top_level, at_e
&& ! DECL_ONE_ONLY (decl))
{
const char *p;
+ char *q;
STRIP_NAME_ENCODING (p, name);
- first_global_object_name = permalloc (strlen (p) + 1);
- strcpy (first_global_object_name, p);
+ q = permalloc (strlen (p) + 1);
+ strcpy (q, p);
+ first_global_object_name = q;
}
/* Compute the alignment of this data. */
===================================================================
Index: ch/Makefile.in
--- ch/Makefile.in 2000/02/26 13:51:58 1.22
+++ ch/Makefile.in 2000/04/04 21:34:29
@@ -277,7 +277,7 @@ expr.o : expr.c $(CONFIG_H) $(RTL_H) $(C
$(srcdir)/../system.h $(srcdir)/../toplev.h
grant.o: grant.c $(CONFIG_H) $(CHILL_TREE_H) $(RTL_H) $(srcdir)/../flags.h \
$(srcdir)/../input.h lex.h actions.h $(srcdir)/../system.h \
- $(srcdir)/../toplev.h $(srcdir)/../output.h
+ $(srcdir)/../toplev.h $(srcdir)/../output.h $(srcdir)/../function.h
inout.o : inout.c $(CONFIG_H) $(CHILL_TREE_H) $(srcdir)/../flags.h \
$(srcdir)/../input.h $(srcdir)/../system.h $(srcdir)/../toplev.h
lang.o : lang.c $(CONFIG_H) $(CHILL_TREE_H) $(srcdir)/../input.h lex.h \
===================================================================
Index: ch/grant.c
--- ch/grant.c 2000/03/07 20:39:05 1.14
+++ ch/grant.c 2000/04/04 21:34:29
@@ -30,6 +30,7 @@ Boston, MA 02111-1307, USA. */
#include "rtl.h"
#include "tasking.h"
#include "toplev.h"
+#include "function.h"
#include "output.h"
#define APPEND(X,Y) X = append (X, Y)
@@ -2544,10 +2545,8 @@ globalize_decl (decl)
if (!TREE_PUBLIC (decl) && DECL_NAME (decl) &&
(TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL))
{
- extern FILE *asm_out_file;
- extern char *first_global_object_name;
- const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
-
+ const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
+
if (!first_global_object_name)
first_global_object_name = name + (name[0] == '*');
ASM_GLOBALIZE_LABEL (asm_out_file, name);
@@ -2993,18 +2992,18 @@ chill_finish_compile ()
Perhaps rewrite this so nothing is done in pass 1. */
if (pass == 1)
{
- extern char *first_global_object_name;
/* If we don't do this spoof, we get the name of the first
tasking_code variable, and not the file name. */
- char *tmp = first_global_object_name;
+ const char *tmp = first_global_object_name;
+ char *cin;
first_global_object_name = NULL;
chill_init_name = get_file_function_name ('I');
first_global_object_name = tmp;
/* strip off the file's extension, if any. */
- tmp = strrchr (IDENTIFIER_POINTER (chill_init_name), '.');
- if (tmp)
- *tmp = '\0';
+ cin = strrchr (IDENTIFIER_POINTER (chill_init_name), '.');
+ if (cin)
+ *cin = '\0';
}
start_chill_function (chill_init_name, void_type_node, NULL_TREE,
More information about the Gcc-patches
mailing list