This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch to fix internal behavior of the asm_fprintf function [take 2]


This patch is a followup to:
http://gcc.gnu.org/ml/gcc-patches/2003-05/msg02445.html

As per the changes Joseph requested to asm_fprintf format checking:
http://gcc.gnu.org/ml/gcc-patches/2003-05/msg02552.html

I've updated the previous patch to asm_fprintf to conform.

Changes from last time are

1.  Delete %p instead of fixing it.
2.  Delete %e, %f, %g.

I couldn't find any uses of '%[pefg]' with asm_fprintf using grep.
The %p was broken, and IIRC, we're supposed to output floats as hex
values in assembly files so the %[efg] should be discouraged in
asm_fprintf.

Since neither solaris or irix use asm_fprintf, I again tested this by
copying the asm_fprintf function into a standalone file and using a
hand written driver passed it the various formats to check it.

Ok for mainline?

		Thanks,
		--Kaveh

2003-06-03  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* final.c (asm_fprintf): Update comments, accept "-+ #0" flags,
	optimize '%' case, handle %c, don't accept %p, %e, %f or %g,
	handle %ll, optimize regular character case.

diff -rup orig/egcc-CVS20030602/gcc/final.c egcc-CVS20030602/gcc/final.c
--- orig/egcc-CVS20030602/gcc/final.c	2003-05-17 18:18:39.000000000 -0400
+++ egcc-CVS20030602/gcc/final.c	2003-06-03 11:00:07.645068582 -0400
@@ -3372,7 +3372,7 @@ output_addr_const (file, x)
    %U prints the value of USER_LABEL_PREFIX.
    %I prints the value of IMMEDIATE_PREFIX.
    %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
-   Also supported are %d, %x, %s, %e, %f, %g and %%.
+   Also supported are %d, %i, %u, %x, %X, %o, %c, %s and %%.
 
    We handle alternate assembler dialects here, just like output_asm_insn.  */
 
@@ -3421,6 +3421,11 @@ asm_fprintf (FILE *file, const char *p, 
       case '%':
 	c = *p++;
 	q = &buf[1];
+	while (strchr ("-+ #0", c))
+	  {
+	    *q++ = c;
+	    c = *p++;
+	  }
 	while (ISDIGIT (c) || c == '.')
 	  {
 	    *q++ = c;
@@ -3429,21 +3434,22 @@ asm_fprintf (FILE *file, const char *p, 
 	switch (c)
 	  {
 	  case '%':
-	    fprintf (file, "%%");
+	    putc ('%', file);
 	    break;
 
 	  case 'd':  case 'i':  case 'u':
-	  case 'x':  case 'p':  case 'X':
-	  case 'o':
+	  case 'x':  case 'X':  case 'o':
+	  case 'c':
 	    *q++ = c;
 	    *q = 0;
 	    fprintf (file, buf, va_arg (argptr, int));
 	    break;
 
 	  case 'w':
-	    /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
-	       but we do not check for those cases.  It means that the value
-	       is a HOST_WIDE_INT, which may be either `int' or `long'.  */
+	    /* This is a prefix to the 'd', 'i', 'u', 'x', 'X', and
+	       'o' cases, but we do not check for those cases.  It
+	       means that the value is a HOST_WIDE_INT, which may be
+	       either `long' or `long long'.  */
 
 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
 #else
@@ -3462,17 +3468,22 @@ asm_fprintf (FILE *file, const char *p, 
 
 	  case 'l':
 	    *q++ = c;
-	    *q++ = *p++;
-	    *q = 0;
-	    fprintf (file, buf, va_arg (argptr, long));
-	    break;
-
-	  case 'e':
-	  case 'f':
-	  case 'g':
-	    *q++ = c;
-	    *q = 0;
-	    fprintf (file, buf, va_arg (argptr, double));
+#ifdef HAVE_LONG_LONG
+	    if (*p == 'l')
+	      {
+		*q++ = *p++;
+		*q++ = *p++;
+		*q = 0;
+		fprintf (file, buf, va_arg (argptr, long long));
+	      }
+	    else
+#endif
+	      {
+		*q++ = *p++;
+		*q = 0;
+		fprintf (file, buf, va_arg (argptr, long));
+	      }
+	    
 	    break;
 
 	  case 's':
@@ -3529,7 +3540,7 @@ asm_fprintf (FILE *file, const char *p, 
 	break;
 
       default:
-	fputc (c, file);
+	putc (c, file);
       }
   va_end (argptr);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]