From: Mark Mitchell Date: Thu, 30 Jul 1998 12:52:18 +0000 (+0000) Subject: dyn-string.h: New file. X-Git-Tag: prereleases/egcs-1.1-prerelease~125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6d503f412f9b22815e77c14a5e467598681d952;p=thirdparty%2Fgcc.git dyn-string.h: New file. * dyn-string.h: New file. * dyn-string.c: Likewise. * Makefile.in (OBJS): Add dyn-string.o. (dwarf2out.o): Add dyn-string.h dependency. (dyn-string.o): List dependencies. * dwarf2out.c: Include dyn-string.h. (ASM_NAME_TO_STRING): Use dyn_string_append, rather than strcpy. (addr_const_to_string): Take a dyn_string_t, not a char* as a prototype. Use dyn_string_append rather than strcat, throughout. (addr_to_string): Use dyn_string_t. From-SVN: r21498 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 259e969f6434..e64bdad098c1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +Thu Jul 30 12:51:09 1998 Mark Mitchell + + * dyn-string.h: New file. + * dyn-string.c: Likewise. + * Makefile.in (OBJS): Add dyn-string.o. + (dwarf2out.o): Add dyn-string.h dependency. + (dyn-string.o): List dependencies. + * dwarf2out.c: Include dyn-string.h. + (ASM_NAME_TO_STRING): Use dyn_string_append, rather than strcpy. + (addr_const_to_string): Take a dyn_string_t, not a char* as a + prototype. Use dyn_string_append rather than strcat, throughout. + (addr_to_string): Use dyn_string_t. + Thu Jul 30 00:58:34 1998 Jeffrey A Law (law@cygnus.com) * i386.md (movqi): When optimizing a load of (const_int 1) into a diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 8687192e3bdd..89894eb658a8 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -641,7 +641,8 @@ OBJS = toplev.o version.o tree.o print-tree.o stor-layout.o fold-const.o \ regclass.o local-alloc.o global.o reload.o reload1.o caller-save.o gcse.o \ insn-peep.o reorg.o $(SCHED_PREFIX)sched.o final.o recog.o reg-stack.o \ insn-opinit.o insn-recog.o insn-extract.o insn-output.o insn-emit.o \ - profile.o insn-attrtab.o $(out_object_file) getpwd.o $(EXTRA_OBJS) convert.o + profile.o insn-attrtab.o $(out_object_file) getpwd.o $(EXTRA_OBJS) convert.o \ + dyn-string.o # GEN files are listed separately, so they can be built before doing parallel # makes for cc1 or cc1plus. Otherwise sequent parallel make attempts to load @@ -1413,7 +1414,7 @@ dwarfout.o : dwarfout.c $(CONFIG_H) system.h $(TREE_H) $(RTL_H) dwarf.h \ flags.h insn-config.h reload.h output.h defaults.h toplev.h dwarfout.h dwarf2out.o : dwarf2out.c $(CONFIG_H) system.h $(TREE_H) $(RTL_H) dwarf2.h \ flags.h insn-config.h reload.h output.h defaults.h \ - hard-reg-set.h $(REGS_H) $(EXPR_H) toplev.h dwarf2out.h + hard-reg-set.h $(REGS_H) $(EXPR_H) toplev.h dwarf2out.h dyn-string.h xcoffout.o : xcoffout.c $(CONFIG_H) system.h $(TREE_H) $(RTL_H) xcoffout.h \ flags.h toplev.h output.h dbxout.h emit-rtl.o : emit-rtl.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h \ @@ -1489,6 +1490,7 @@ recog.o : recog.c $(CONFIG_H) system.h $(RTL_H) \ insn-flags.h insn-codes.h real.h reg-stack.o : reg-stack.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) \ $(REGS_H) hard-reg-set.h flags.h insn-config.h insn-flags.h toplev.h +dyn-string.o: dyn-string.c dyn-string.h $(CONFIG_H) system.h gansidecl.h $(out_object_file): $(out_file) $(CONFIG_H) $(TREE_H) \ $(RTL_H) $(REGS_H) hard-reg-set.h real.h insn-config.h conditions.h \ diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 61b16ca3fee8..b72d86166225 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -42,6 +42,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "dwarf2.h" #include "dwarf2out.h" #include "toplev.h" +#include "dyn-string.h" /* We cannot use in GCC source, since that would include GCC's assert.h, which may not be compatible with the host compiler. */ @@ -2374,7 +2375,7 @@ static tree dwarf_last_decl; /* Forward declarations for functions defined in this file. */ -static void addr_const_to_string PROTO((char *, rtx)); +static void addr_const_to_string PROTO((dyn_string_t, rtx)); static char *addr_to_string PROTO((rtx)); static int is_pseudo_reg PROTO((rtx)); static tree type_main_variant PROTO((tree)); @@ -2639,9 +2640,9 @@ static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; #define ASM_NAME_TO_STRING(STR, NAME) \ do { \ if ((NAME)[0] == '*') \ - strcpy (STR, NAME+1); \ + dyn_string_append (STR, NAME + 1); \ else \ - strcpy (STR, NAME); \ + dyn_string_append (STR, NAME); \ } \ while (0) #endif @@ -2654,50 +2655,44 @@ static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; static void addr_const_to_string (str, x) - char *str; + dyn_string_t str; rtx x; { char buf1[256]; - char buf2[256]; restart: - str[0] = '\0'; switch (GET_CODE (x)) { case PC: if (flag_pic) - strcat (str, ","); + dyn_string_append (str, ","); else abort (); break; case SYMBOL_REF: - ASM_NAME_TO_STRING (buf1, XSTR (x, 0)); - strcat (str, buf1); + ASM_NAME_TO_STRING (str, XSTR (x, 0)); break; case LABEL_REF: ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0))); - ASM_NAME_TO_STRING (buf2, buf1); - strcat (str, buf2); + ASM_NAME_TO_STRING (str, buf1); break; case CODE_LABEL: ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x)); - ASM_NAME_TO_STRING (buf2, buf1); - strcat (str, buf2); + ASM_NAME_TO_STRING (str, buf1); break; case CONST_INT: sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); - strcat (str, buf1); + dyn_string_append (str, buf1); break; case CONST: /* This used to output parentheses around the expression, but that does not work on the 386 (either ATT or BSD assembler). */ - addr_const_to_string (buf1, XEXP (x, 0)); - strcat (str, buf1); + addr_const_to_string (str, XEXP (x, 0)); break; case CONST_DOUBLE: @@ -2712,7 +2707,7 @@ restart: else sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x)); - strcat (str, buf1); + dyn_string_append (str, buf1); } else /* We can't handle floating point constants; PRINT_OPERAND must @@ -2724,23 +2719,19 @@ restart: /* Some assemblers need integer constants to appear last (eg masm). */ if (GET_CODE (XEXP (x, 0)) == CONST_INT) { - addr_const_to_string (buf1, XEXP (x, 1)); - strcat (str, buf1); + addr_const_to_string (str, XEXP (x, 1)); if (INTVAL (XEXP (x, 0)) >= 0) - strcat (str, "+"); + dyn_string_append (str, "+"); - addr_const_to_string (buf1, XEXP (x, 0)); - strcat (str, buf1); + addr_const_to_string (str, XEXP (x, 0)); } else { - addr_const_to_string (buf1, XEXP (x, 0)); - strcat (str, buf1); + addr_const_to_string (str, XEXP (x, 0)); if (INTVAL (XEXP (x, 1)) >= 0) - strcat (str, "+"); + dyn_string_append (str, "+"); - addr_const_to_string (buf1, XEXP (x, 1)); - strcat (str, buf1); + addr_const_to_string (str, XEXP (x, 1)); } break; @@ -2751,28 +2742,22 @@ restart: if (GET_CODE (x) != MINUS) goto restart; - addr_const_to_string (buf1, XEXP (x, 0)); - strcat (str, buf1); - strcat (str, "-"); + addr_const_to_string (str, XEXP (x, 0)); + dyn_string_append (str, "-"); if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) < 0) { - strcat (str, ASM_OPEN_PAREN); - addr_const_to_string (buf1, XEXP (x, 1)); - strcat (str, buf1); - strcat (str, ASM_CLOSE_PAREN); + dyn_string_append (str, ASM_OPEN_PAREN); + addr_const_to_string (str, XEXP (x, 1)); + dyn_string_append (str, ASM_CLOSE_PAREN); } else - { - addr_const_to_string (buf1, XEXP (x, 1)); - strcat (str, buf1); - } + addr_const_to_string (str, XEXP (x, 1)); break; case ZERO_EXTEND: case SIGN_EXTEND: - addr_const_to_string (buf1, XEXP (x, 0)); - strcat (str, buf1); + addr_const_to_string (str, XEXP (x, 0)); break; default: @@ -2787,9 +2772,16 @@ static char * addr_to_string (x) rtx x; { - char buf[1024]; - addr_const_to_string (buf, x); - return xstrdup (buf); + dyn_string_t ds = dyn_string_new (256); + char *s; + + addr_const_to_string (ds, x); + + /* Return the dynamically allocated string, but free the + dyn_string_t itself. */ + s = ds->s; + free (ds); + return s; } /* Test if rtl node points to a pseudo register. */