Commit b170964a by Mark Mitchell Committed by Mark Mitchell

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: r21496
parent 07417085
Thu Jul 30 12:29:12 1998 Mark Mitchell <mark@markmitchell.com>
* 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 13:08:07 1998 Ken Raeburn <raeburn@cygnus.com> Thu Jul 30 13:08:07 1998 Ken Raeburn <raeburn@cygnus.com>
Function entry/exit profiling instrumentation: Function entry/exit profiling instrumentation:
......
...@@ -642,7 +642,7 @@ OBJS = toplev.o version.o tree.o print-tree.o stor-layout.o fold-const.o \ ...@@ -642,7 +642,7 @@ OBJS = toplev.o version.o tree.o print-tree.o stor-layout.o fold-const.o \
insn-peep.o reorg.o $(SCHED_PREFIX)sched.o final.o recog.o reg-stack.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 \ 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 \
mbchar.o mbchar.o dyn-string.o
# GEN files are listed separately, so they can be built before doing parallel # 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 # makes for cc1 or cc1plus. Otherwise sequent parallel make attempts to load
...@@ -1415,7 +1415,7 @@ dwarfout.o : dwarfout.c $(CONFIG_H) system.h $(TREE_H) $(RTL_H) dwarf.h \ ...@@ -1415,7 +1415,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 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 \ 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 \ 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 \ xcoffout.o : xcoffout.c $(CONFIG_H) system.h $(TREE_H) $(RTL_H) xcoffout.h \
flags.h toplev.h output.h dbxout.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 \ emit-rtl.o : emit-rtl.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h \
...@@ -1491,6 +1491,7 @@ recog.o : recog.c $(CONFIG_H) system.h $(RTL_H) \ ...@@ -1491,6 +1491,7 @@ recog.o : recog.c $(CONFIG_H) system.h $(RTL_H) \
insn-flags.h insn-codes.h real.h insn-flags.h insn-codes.h real.h
reg-stack.o : reg-stack.c $(CONFIG_H) system.h $(RTL_H) $(TREE_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 $(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) \ $(out_object_file): $(out_file) $(CONFIG_H) $(TREE_H) \
$(RTL_H) $(REGS_H) hard-reg-set.h real.h insn-config.h conditions.h \ $(RTL_H) $(REGS_H) hard-reg-set.h real.h insn-config.h conditions.h \
......
...@@ -42,6 +42,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ ...@@ -42,6 +42,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "dwarf2.h" #include "dwarf2.h"
#include "dwarf2out.h" #include "dwarf2out.h"
#include "toplev.h" #include "toplev.h"
#include "dyn-string.h"
/* We cannot use <assert.h> in GCC source, since that would include /* We cannot use <assert.h> in GCC source, since that would include
GCC's assert.h, which may not be compatible with the host compiler. */ GCC's assert.h, which may not be compatible with the host compiler. */
...@@ -2374,7 +2375,7 @@ static tree dwarf_last_decl; ...@@ -2374,7 +2375,7 @@ static tree dwarf_last_decl;
/* Forward declarations for functions defined in this file. */ /* 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 char *addr_to_string PROTO((rtx));
static int is_pseudo_reg PROTO((rtx)); static int is_pseudo_reg PROTO((rtx));
static tree type_main_variant PROTO((tree)); static tree type_main_variant PROTO((tree));
...@@ -2639,9 +2640,9 @@ static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; ...@@ -2639,9 +2640,9 @@ static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
#define ASM_NAME_TO_STRING(STR, NAME) \ #define ASM_NAME_TO_STRING(STR, NAME) \
do { \ do { \
if ((NAME)[0] == '*') \ if ((NAME)[0] == '*') \
strcpy (STR, NAME+1); \ dyn_string_append (STR, NAME + 1); \
else \ else \
strcpy (STR, NAME); \ dyn_string_append (STR, NAME); \
} \ } \
while (0) while (0)
#endif #endif
...@@ -2654,50 +2655,44 @@ static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; ...@@ -2654,50 +2655,44 @@ static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
static void static void
addr_const_to_string (str, x) addr_const_to_string (str, x)
char *str; dyn_string_t str;
rtx x; rtx x;
{ {
char buf1[256]; char buf1[256];
char buf2[256];
restart: restart:
str[0] = '\0';
switch (GET_CODE (x)) switch (GET_CODE (x))
{ {
case PC: case PC:
if (flag_pic) if (flag_pic)
strcat (str, ","); dyn_string_append (str, ",");
else else
abort (); abort ();
break; break;
case SYMBOL_REF: case SYMBOL_REF:
ASM_NAME_TO_STRING (buf1, XSTR (x, 0)); ASM_NAME_TO_STRING (str, XSTR (x, 0));
strcat (str, buf1);
break; break;
case LABEL_REF: case LABEL_REF:
ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0))); ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
ASM_NAME_TO_STRING (buf2, buf1); ASM_NAME_TO_STRING (str, buf1);
strcat (str, buf2);
break; break;
case CODE_LABEL: case CODE_LABEL:
ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x)); ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
ASM_NAME_TO_STRING (buf2, buf1); ASM_NAME_TO_STRING (str, buf1);
strcat (str, buf2);
break; break;
case CONST_INT: case CONST_INT:
sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
strcat (str, buf1); dyn_string_append (str, buf1);
break; break;
case CONST: case CONST:
/* This used to output parentheses around the expression, but that does /* This used to output parentheses around the expression, but that does
not work on the 386 (either ATT or BSD assembler). */ not work on the 386 (either ATT or BSD assembler). */
addr_const_to_string (buf1, XEXP (x, 0)); addr_const_to_string (str, XEXP (x, 0));
strcat (str, buf1);
break; break;
case CONST_DOUBLE: case CONST_DOUBLE:
...@@ -2712,7 +2707,7 @@ restart: ...@@ -2712,7 +2707,7 @@ restart:
else else
sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
CONST_DOUBLE_LOW (x)); CONST_DOUBLE_LOW (x));
strcat (str, buf1); dyn_string_append (str, buf1);
} }
else else
/* We can't handle floating point constants; PRINT_OPERAND must /* We can't handle floating point constants; PRINT_OPERAND must
...@@ -2724,23 +2719,19 @@ restart: ...@@ -2724,23 +2719,19 @@ restart:
/* Some assemblers need integer constants to appear last (eg masm). */ /* Some assemblers need integer constants to appear last (eg masm). */
if (GET_CODE (XEXP (x, 0)) == CONST_INT) if (GET_CODE (XEXP (x, 0)) == CONST_INT)
{ {
addr_const_to_string (buf1, XEXP (x, 1)); addr_const_to_string (str, XEXP (x, 1));
strcat (str, buf1);
if (INTVAL (XEXP (x, 0)) >= 0) if (INTVAL (XEXP (x, 0)) >= 0)
strcat (str, "+"); dyn_string_append (str, "+");
addr_const_to_string (buf1, XEXP (x, 0)); addr_const_to_string (str, XEXP (x, 0));
strcat (str, buf1);
} }
else else
{ {
addr_const_to_string (buf1, XEXP (x, 0)); addr_const_to_string (str, XEXP (x, 0));
strcat (str, buf1);
if (INTVAL (XEXP (x, 1)) >= 0) if (INTVAL (XEXP (x, 1)) >= 0)
strcat (str, "+"); dyn_string_append (str, "+");
addr_const_to_string (buf1, XEXP (x, 1)); addr_const_to_string (str, XEXP (x, 1));
strcat (str, buf1);
} }
break; break;
...@@ -2751,28 +2742,22 @@ restart: ...@@ -2751,28 +2742,22 @@ restart:
if (GET_CODE (x) != MINUS) if (GET_CODE (x) != MINUS)
goto restart; goto restart;
addr_const_to_string (buf1, XEXP (x, 0)); addr_const_to_string (str, XEXP (x, 0));
strcat (str, buf1); dyn_string_append (str, "-");
strcat (str, "-");
if (GET_CODE (XEXP (x, 1)) == CONST_INT if (GET_CODE (XEXP (x, 1)) == CONST_INT
&& INTVAL (XEXP (x, 1)) < 0) && INTVAL (XEXP (x, 1)) < 0)
{ {
strcat (str, ASM_OPEN_PAREN); dyn_string_append (str, ASM_OPEN_PAREN);
addr_const_to_string (buf1, XEXP (x, 1)); addr_const_to_string (str, XEXP (x, 1));
strcat (str, buf1); dyn_string_append (str, ASM_CLOSE_PAREN);
strcat (str, ASM_CLOSE_PAREN);
} }
else else
{ addr_const_to_string (str, XEXP (x, 1));
addr_const_to_string (buf1, XEXP (x, 1));
strcat (str, buf1);
}
break; break;
case ZERO_EXTEND: case ZERO_EXTEND:
case SIGN_EXTEND: case SIGN_EXTEND:
addr_const_to_string (buf1, XEXP (x, 0)); addr_const_to_string (str, XEXP (x, 0));
strcat (str, buf1);
break; break;
default: default:
...@@ -2787,9 +2772,16 @@ static char * ...@@ -2787,9 +2772,16 @@ static char *
addr_to_string (x) addr_to_string (x)
rtx x; rtx x;
{ {
char buf[1024]; dyn_string_t ds = dyn_string_new (256);
addr_const_to_string (buf, x); char *s;
return xstrdup (buf);
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. */ /* Test if rtl node points to a pseudo register. */
......
/* An abstract string datatype.
Copyright (C) 1998 Free Software Foundation, Inc.
Contributed by Mark Mitchell (mark@markmitchell.com).
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to the Free
Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "config.h"
#include "system.h"
#include "gansidecl.h"
#include "dyn-string.h"
extern char *xmalloc ();
extern char *xrealloc ();
/* Create a new dynamic string capable of holding at least SPACE
characters, including the terminating NUL. If SPACE is 0, it
will be silently increased to 1. */
dyn_string_t
dyn_string_new (space)
int space;
{
dyn_string_t result = (dyn_string_t) xmalloc (sizeof (struct dyn_string));
if (space == 0)
/* We need at least one byte in which to store the terminating
NUL. */
space = 1;
result->allocated = space;
result->s = (char*) xmalloc (space);
result->length = 0;
result->s[0] = '\0';
return result;
}
/* Free the memory used by DS. */
void
dyn_string_delete (ds)
dyn_string_t ds;
{
free (ds->s);
free (ds);
}
/* Append the NUL-terminated string S to DS, resizing DS if
necessary. */
dyn_string_t
dyn_string_append (ds, s)
dyn_string_t ds;
char *s;
{
int len = strlen (s);
dyn_string_resize (ds, ds->length + len + 1 /* '\0' */);
strcpy (ds->s + ds->length, s);
ds->length += len;
return ds;
}
/* Increase the capacity of DS so that it can hold at least SPACE
characters, including the terminating NUL. This function will not
(at present) reduce the capacity of DS. */
dyn_string_t
dyn_string_resize (ds, space)
dyn_string_t ds;
int space;
{
int new_allocated = ds->allocated;
while (space > new_allocated)
new_allocated *= 2;
if (new_allocated != ds->allocated)
{
/* We actually need more space. */
ds->allocated = new_allocated;
ds->s = (char*) xrealloc (ds->s, ds->allocated);
}
return ds;
}
/* An abstract string datatype.
Copyright (C) 1998 Free Software Foundation, Inc.
Contributed by Mark Mitchell (mark@markmitchell.com).
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to the Free
Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
typedef struct dyn_string
{
int allocated; /* The amount of space allocated for the string. */
int length; /* The actual length of the string. */
char *s; /* The string itself, NUL-terminated. */
}* dyn_string_t;
extern dyn_string_t dyn_string_new PROTO((int));
extern void dyn_string_delete PROTO((dyn_string_t));
extern dyn_string_t dyn_string_append PROTO((dyn_string_t, char*));
extern dyn_string_t dyn_string_resize PROTO((dyn_string_t, int));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment