This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to merge uses of HOST_PTR_PRINTF with adjacent stdio calls
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 5 Jul 2003 01:57:32 -0400 (EDT)
- Subject: Patch to merge uses of HOST_PTR_PRINTF with adjacent stdio calls
Regarding this discussion:
http://gcc.gnu.org/ml/gcc/2003-07/msg00279.html
I didn't see any support for deleting HOST_PTR_PRINTF in favor of just
using "%p".
So here's my patch to use string concatenation on HOST_PTR_PRINTF
calls and collapse multiple stdio calls into one.
One twist, the backup choice for HOST_PTR_PRINTF when "%p" isn't
available was a series of tests for finding a same-sized-int. This C
expression cannot be concatenated with another string. So I had to
use individual cpp comparisons on the type sizes to set the value of
HOST_PTR_PRINTF to a string literal. (Look at the system.h hunk
below.)
Bootstrapped on sparc-sun-solaris2.7 (saves 736 bytes of text size in
cc1plus.) I also faked that "%p" wasn't available and rebootstrapped
to test the backup mechanism.
Ok for mainline?
Thanks,
--Kaveh
PS: Someday soon hopefully I'll write an optimization to do this
automatically ...
2003-07-04 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* bitmap.c (debug_bitmap_file): Merge uses of HOST_PTR_PRINTF with
adjacent stdio calls.
* c-decl.c (c_print_identifier): Likewise.
* mips-tfile.c (write_varray, write_object, allocate_cluster): Likewise.
* print-rtl.c (print_rtx): Likewise.
* print-tree.c (print_node_brief, print_node): Likewise.
* system.h (HOST_PTR_PRINTF): Ensure we have a literal string.
* configure.in (AC_COMPILE_CHECK_SIZEOF): Check for `void *'.
* config.in, configure: Regenerated.
cp:
* decl.c (print_binding_level, print_other_binding_stack,
print_binding_stack): Merge uses of HOST_PTR_PRINTF with adjacent
stdio calls.
* ptree.c (cxx_print_decl, cxx_print_binding): Likewise.
diff -rup orig/egcc-CVS20030701/gcc/bitmap.c egcc-CVS20030701/gcc/bitmap.c
--- orig/egcc-CVS20030701/gcc/bitmap.c 2003-06-29 20:00:58.000000000 -0400
+++ egcc-CVS20030701/gcc/bitmap.c 2003-07-04 22:51:49.406458000 -0400
@@ -728,23 +728,17 @@ debug_bitmap_file (FILE *file, bitmap he
{
bitmap_element *ptr;
- fprintf (file, "\nfirst = ");
- fprintf (file, HOST_PTR_PRINTF, (void *) head->first);
- fprintf (file, " current = ");
- fprintf (file, HOST_PTR_PRINTF, (void *) head->current);
- fprintf (file, " indx = %u\n", head->indx);
+ fprintf (file, "\nfirst = " HOST_PTR_PRINTF
+ " current = " HOST_PTR_PRINTF " indx = %u\n",
+ (void *) head->first, (void *) head->current, head->indx);
for (ptr = head->first; ptr; ptr = ptr->next)
{
unsigned int i, j, col = 26;
- fprintf (file, "\t");
- fprintf (file, HOST_PTR_PRINTF, (void *) ptr);
- fprintf (file, " next = ");
- fprintf (file, HOST_PTR_PRINTF, (void *) ptr->next);
- fprintf (file, " prev = ");
- fprintf (file, HOST_PTR_PRINTF, (void *) ptr->prev);
- fprintf (file, " indx = %u\n\t\tbits = {", ptr->indx);
+ fprintf (file, "\t" HOST_PTR_PRINTF " next = " HOST_PTR_PRINTF
+ " prev = " HOST_PTR_PRINTF " indx = %u\n\t\tbits = {",
+ (void*) ptr, (void*) ptr->next, (void*) ptr->prev, ptr->indx);
for (i = 0; i < BITMAP_ELEMENT_WORDS; i++)
for (j = 0; j < BITMAP_WORD_BITS; j++)
diff -rup orig/egcc-CVS20030701/gcc/c-decl.c egcc-CVS20030701/gcc/c-decl.c
--- orig/egcc-CVS20030701/gcc/c-decl.c 2003-07-01 14:29:42.000000000 -0400
+++ egcc-CVS20030701/gcc/c-decl.c 2003-07-04 22:30:17.082015000 -0400
@@ -305,9 +305,8 @@ c_print_identifier (FILE *file, tree nod
{
tree rid = ridpointers[C_RID_CODE (node)];
indent_to (file, indent + 4);
- fprintf (file, "rid ");
- fprintf (file, HOST_PTR_PRINTF, (void *)rid);
- fprintf (file, " \"%s\"", IDENTIFIER_POINTER (rid));
+ fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"",
+ (void *) rid, IDENTIFIER_POINTER (rid));
}
}
diff -rup orig/egcc-CVS20030701/gcc/configure.in egcc-CVS20030701/gcc/configure.in
--- orig/egcc-CVS20030701/gcc/configure.in 2003-06-28 20:01:03.000000000 -0400
+++ egcc-CVS20030701/gcc/configure.in 2003-07-04 22:30:17.101994000 -0400
@@ -249,6 +249,7 @@ gcc_AC_C_LONG_LONG
gcc_AC_C__BOOL
# sizeof(char) is 1 by definition.
+AC_COMPILE_CHECK_SIZEOF(void *)
AC_COMPILE_CHECK_SIZEOF(short)
AC_COMPILE_CHECK_SIZEOF(int)
AC_COMPILE_CHECK_SIZEOF(long)
diff -rup orig/egcc-CVS20030701/gcc/cp/decl.c egcc-CVS20030701/gcc/cp/decl.c
--- orig/egcc-CVS20030701/gcc/cp/decl.c 2003-07-01 21:12:24.000000000 -0400
+++ egcc-CVS20030701/gcc/cp/decl.c 2003-07-04 22:30:17.182063000 -0400
@@ -1900,8 +1900,7 @@ print_binding_level (struct cp_binding_l
{
tree t;
int i = 0, len;
- fprintf (stderr, " blocks=");
- fprintf (stderr, HOST_PTR_PRINTF, (void *) lvl->blocks);
+ fprintf (stderr, " blocks=" HOST_PTR_PRINTF, (void *) lvl->blocks);
if (lvl->tag_transparent)
fprintf (stderr, " tag-transparent");
if (lvl->more_cleanups_ok)
@@ -1974,9 +1973,7 @@ print_other_binding_stack (struct cp_bin
struct cp_binding_level *level;
for (level = stack; !global_scope_p (level); level = level->level_chain)
{
- fprintf (stderr, "binding level ");
- fprintf (stderr, HOST_PTR_PRINTF, (void *) level);
- fprintf (stderr, "\n");
+ fprintf (stderr, "binding level " HOST_PTR_PRINTF "\n", (void *) level);
print_binding_level (level);
}
}
@@ -1985,14 +1982,11 @@ void
print_binding_stack (void)
{
struct cp_binding_level *b;
- fprintf (stderr, "current_binding_level=");
- fprintf (stderr, HOST_PTR_PRINTF, (void *) current_binding_level);
- fprintf (stderr, "\nclass_binding_level=");
- fprintf (stderr, HOST_PTR_PRINTF, (void *) class_binding_level);
- fprintf (stderr, "\nNAMESPACE_LEVEL (global_namespace)=");
- fprintf (stderr, HOST_PTR_PRINTF,
+ fprintf (stderr, "current_binding_level=" HOST_PTR_PRINTF
+ "\nclass_binding_level=" HOST_PTR_PRINTF
+ "\nNAMESPACE_LEVEL (global_namespace)=" HOST_PTR_PRINTF "\n",
+ (void *) current_binding_level, (void *) class_binding_level,
(void *) NAMESPACE_LEVEL (global_namespace));
- fprintf (stderr, "\n");
if (class_binding_level)
{
for (b = class_binding_level; b; b = b->level_chain)
diff -rup orig/egcc-CVS20030701/gcc/cp/ptree.c egcc-CVS20030701/gcc/cp/ptree.c
--- orig/egcc-CVS20030701/gcc/cp/ptree.c 2003-05-16 21:37:50.000000000 -0400
+++ egcc-CVS20030701/gcc/cp/ptree.c 2003-07-04 22:30:17.211983000 -0400
@@ -46,22 +46,16 @@ cxx_print_decl (FILE *file, tree node, i
indent_to (file, indent + 3);
if (TREE_CODE (node) == FUNCTION_DECL
&& DECL_PENDING_INLINE_INFO (node))
- {
- fprintf (file, " pending-inline-info ");
- fprintf (file, HOST_PTR_PRINTF, (void *) DECL_PENDING_INLINE_INFO (node));
- }
+ fprintf (file, " pending-inline-info " HOST_PTR_PRINTF,
+ (void *) DECL_PENDING_INLINE_INFO (node));
if (TREE_CODE (node) == TYPE_DECL
&& DECL_SORTED_FIELDS (node))
- {
- fprintf (file, " sorted-fields ");
- fprintf (file, HOST_PTR_PRINTF, (void *) DECL_SORTED_FIELDS (node));
- }
+ fprintf (file, " sorted-fields " HOST_PTR_PRINTF,
+ (void *) DECL_SORTED_FIELDS (node));
if ((TREE_CODE (node) == FUNCTION_DECL || TREE_CODE (node) == VAR_DECL)
&& DECL_TEMPLATE_INFO (node))
- {
- fprintf (file, " template-info ");
- fprintf (file, HOST_PTR_PRINTF, (void *) DECL_TEMPLATE_INFO (node));
- }
+ fprintf (file, " template-info " HOST_PTR_PRINTF,
+ (void *) DECL_TEMPLATE_INFO (node));
}
void
@@ -155,9 +149,8 @@ cxx_print_type (FILE *file, tree node, i
static void
cxx_print_binding (FILE *stream, cxx_binding *binding, const char *prefix)
{
- fprintf (stream, "%s <", prefix);
- fprintf (stream, HOST_PTR_PRINTF, (char *) binding);
- fprintf (stream, ">");
+ fprintf (stream, "%s <" HOST_PTR_PRINTF ">",
+ prefix, (void *) binding);
}
void
diff -rup orig/egcc-CVS20030701/gcc/mips-tfile.c egcc-CVS20030701/gcc/mips-tfile.c
--- orig/egcc-CVS20030701/gcc/mips-tfile.c 2003-07-01 14:29:52.000000000 -0400
+++ egcc-CVS20030701/gcc/mips-tfile.c 2003-07-04 22:30:17.241989000 -0400
@@ -4058,12 +4058,10 @@ write_varray (vp, offset, str)
return;
if (debug)
- {
- fputs ("\twarray\tvp = ", stderr);
- fprintf (stderr, HOST_PTR_PRINTF, (void *) vp);
- fprintf (stderr, ", offset = %7lu, size = %7lu, %s\n",
- (unsigned long) offset, vp->num_allocated * vp->object_size, str);
- }
+ fprintf (stderr, "\twarray\tvp = " HOST_PTR_PRINTF
+ ", offset = %7lu, size = %7lu, %s\n",
+ (void *) vp, (unsigned long) offset,
+ vp->num_allocated * vp->object_size, str);
if (file_offset != (unsigned long) offset
&& fseek (object_stream, (long) offset, SEEK_SET) < 0)
@@ -4100,12 +4098,10 @@ write_object ()
off_t offset;
if (debug)
- {
- fputs ("\n\twrite\tvp = ", stderr);
- fprintf (stderr, HOST_PTR_PRINTF, (void *) &symbolic_header);
- fprintf (stderr, ", offset = %7u, size = %7lu, %s\n",
- 0, (unsigned long) sizeof (symbolic_header), "symbolic header");
- }
+ fprintf (stderr, "\n\twrite\tvp = " HOST_PTR_PRINTF
+ ", offset = %7u, size = %7lu, %s\n",
+ (void *) &symbolic_header, 0,
+ (unsigned long) sizeof (symbolic_header), "symbolic header");
sys_write = fwrite (&symbolic_header,
1,
@@ -4133,13 +4129,10 @@ write_object ()
pfatal_with_name (object_name);
if (debug)
- {
- fputs ("\twrite\tvp = ", stderr);
- fprintf (stderr, HOST_PTR_PRINTF, (void *) &orig_linenum);
- fprintf (stderr, ", offset = %7lu, size = %7lu, %s\n",
- (long) symbolic_header.cbLineOffset,
- (long) symbolic_header.cbLine, "Line numbers");
- }
+ fprintf (stderr, "\twrite\tvp = " HOST_PTR_PRINTF
+ ", offset = %7lu, size = %7lu, %s\n",
+ (void *) &orig_linenum, (long) symbolic_header.cbLineOffset,
+ (long) symbolic_header.cbLine, "Line numbers");
sys_write = fwrite (orig_linenum,
1,
@@ -4168,13 +4161,10 @@ write_object ()
pfatal_with_name (object_name);
if (debug)
- {
- fputs ("\twrite\tvp = ", stderr);
- fprintf (stderr, HOST_PTR_PRINTF, (void *) &orig_opt_syms);
- fprintf (stderr, ", offset = %7lu, size = %7lu, %s\n",
- (long) symbolic_header.cbOptOffset,
- num_write, "Optimizer symbols");
- }
+ fprintf (stderr, "\twrite\tvp = " HOST_PTR_PRINTF
+ ", offset = %7lu, size = %7lu, %s\n",
+ (void *) &orig_opt_syms, (long) symbolic_header.cbOptOffset,
+ num_write, "Optimizer symbols");
sys_write = fwrite (orig_opt_syms,
1,
@@ -4260,13 +4250,10 @@ write_object ()
file_ptr = file_ptr->next_file)
{
if (debug)
- {
- fputs ("\twrite\tvp = ", stderr);
- fprintf (stderr, HOST_PTR_PRINTF, (void *) &file_ptr->fdr);
- fprintf (stderr, ", offset = %7lu, size = %7lu, %s\n",
- file_offset, (unsigned long) sizeof (FDR),
- "File header");
- }
+ fprintf (stderr, "\twrite\tvp = " HOST_PTR_PRINTF
+ ", offset = %7lu, size = %7lu, %s\n",
+ (void *) &file_ptr->fdr, file_offset,
+ (unsigned long) sizeof (FDR), "File header");
sys_write = fwrite (&file_ptr->fdr,
1,
@@ -4296,13 +4283,10 @@ write_object ()
pfatal_with_name (object_name);
if (debug)
- {
- fputs ("\twrite\tvp = ", stderr);
- fprintf (stderr, HOST_PTR_PRINTF, (void *) &orig_rfds);
- fprintf (stderr, ", offset = %7lu, size = %7lu, %s\n",
- (long) symbolic_header.cbRfdOffset,
- num_write, "Relative file descriptors");
- }
+ fprintf (stderr, "\twrite\tvp = " HOST_PTR_PRINTF
+ ", offset = %7lu, size = %7lu, %s\n",
+ (void *) &orig_rfds, (long) symbolic_header.cbRfdOffset,
+ num_write, "Relative file descriptors");
sys_write = fwrite (orig_rfds,
1,
@@ -5101,12 +5085,8 @@ allocate_cluster (npages)
pfatal_with_name ("allocate_cluster");
if (debug > 3)
- {
- fprintf (stderr, "\talloc\tnpages = %lu, value = ",
- (unsigned long) npages);
- fprintf (stderr, HOST_PTR_PRINTF, (void *) ptr);
- fputs ("\n", stderr);
- }
+ fprintf (stderr, "\talloc\tnpages = %lu, value = " HOST_PTR_PRINTF "\n",
+ (unsigned long) npages, (void *) ptr);
return ptr;
}
diff -rup orig/egcc-CVS20030701/gcc/print-rtl.c egcc-CVS20030701/gcc/print-rtl.c
--- orig/egcc-CVS20030701/gcc/print-rtl.c 2003-06-28 20:01:06.000000000 -0400
+++ egcc-CVS20030701/gcc/print-rtl.c 2003-07-04 22:30:17.251988000 -0400
@@ -504,8 +504,7 @@ print_rtx (in_rtx)
break;
case 't':
- putc (' ', outfile);
- fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
+ fprintf (outfile, " " HOST_PTR_PRINTF, (void *) XTREE (in_rtx, i));
break;
case '*':
diff -rup orig/egcc-CVS20030701/gcc/print-tree.c egcc-CVS20030701/gcc/print-tree.c
--- orig/egcc-CVS20030701/gcc/print-tree.c 2003-06-16 09:44:12.000000000 -0400
+++ egcc-CVS20030701/gcc/print-tree.c 2003-07-04 22:30:17.351998000 -0400
@@ -77,8 +77,8 @@ print_node_brief (file, prefix, node, in
name if any. */
if (indent > 0)
fprintf (file, " ");
- fprintf (file, "%s <%s ", prefix, tree_code_name[(int) TREE_CODE (node)]);
- fprintf (file, HOST_PTR_PRINTF, (char *) node);
+ fprintf (file, "%s <%s " HOST_PTR_PRINTF,
+ prefix, tree_code_name[(int) TREE_CODE (node)], (char *) node);
if (class == 'd')
{
@@ -220,8 +220,8 @@ print_node (file, prefix, node, indent)
indent_to (file, indent);
/* Print the slot this node is in, and its code, and address. */
- fprintf (file, "%s <%s ", prefix, tree_code_name[(int) TREE_CODE (node)]);
- fprintf (file, HOST_PTR_PRINTF, (char *) node);
+ fprintf (file, "%s <%s " HOST_PTR_PRINTF,
+ prefix, tree_code_name[(int) TREE_CODE (node)], (void *) node);
/* Print the name, if any. */
if (class == 'd')
@@ -456,8 +456,8 @@ print_node (file, prefix, node, indent)
&& DECL_SAVED_INSNS (node) != 0)
{
indent_to (file, indent + 4);
- fprintf (file, "saved-insns ");
- fprintf (file, HOST_PTR_PRINTF, (char *) DECL_SAVED_INSNS (node));
+ fprintf (file, "saved-insns " HOST_PTR_PRINTF,
+ (void *) DECL_SAVED_INSNS (node));
}
/* Print the decl chain only if decl is at second level. */
diff -rup orig/egcc-CVS20030701/gcc/system.h egcc-CVS20030701/gcc/system.h
--- orig/egcc-CVS20030701/gcc/system.h 2003-06-29 20:01:18.000000000 -0400
+++ egcc-CVS20030701/gcc/system.h 2003-07-04 22:45:09.675869000 -0400
@@ -446,10 +446,12 @@ extern void abort (void);
#ifndef HOST_PTR_PRINTF
# ifdef HAVE_PRINTF_PTR
# define HOST_PTR_PRINTF "%p"
+# elif SIZEOF_INT == SIZEOF_VOID_P
+# define HOST_PTR_PRINTF "%x"
+# elif SIZEOF_LONG == SIZEOF_VOID_P
+# define HOST_PTR_PRINTF "%lx"
# else
-# define HOST_PTR_PRINTF \
- (sizeof (int) == sizeof (char *) ? "%x" \
- : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
+# define HOST_PTR_PRINTF "%llx"
# endif
#endif /* ! HOST_PTR_PRINTF */