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
This commit is contained in:
Mark Mitchell 1998-07-30 12:30:30 +00:00 committed by Mark Mitchell
parent 07417085a1
commit b170964afd
5 changed files with 182 additions and 45 deletions

View File

@ -1,3 +1,16 @@
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>
Function entry/exit profiling instrumentation:

View File

@ -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-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 \
mbchar.o
mbchar.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
@ -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
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 \
@ -1491,6 +1491,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 \

View File

@ -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 <assert.h> 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. */

100
gcc/dyn-string.c Normal file
View File

@ -0,0 +1,100 @@
/* 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;
}

31
gcc/dyn-string.h Normal file
View File

@ -0,0 +1,31 @@
/* 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));