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]

Accept whitespace in define_attr/set_attr lists


This patch permits one to write

(define_attr "type"
  "other,multi,
   alu,alu1,negnot,imov,imovx,lea,
   incdec,ishift,rotate,imul,idiv,
   icmp,test,ibr,setcc,icmov,
   push,pop,call,callv,
   str,cld,
   fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp,
   sselog,sseiadd,sseishft,sseimul,
   sse,ssemov,sseadd,ssemul,ssecmp,ssecvt,ssediv,
   mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft"
  (const_string "other"))

instead of putting it all on one long line.  I converted the i386
backend to use this new notation, as a demo.  There is no
documentation patch because the documentation of attributes is
severely lacking and I didn't see any way to explain this short of a
major revision -- perhaps I shall do that as a separate patch.

Bootstrapped i686-linux.

zw

	* gensupport.c (n_comma_elts): Moved here from genattrtab.c.
	(scan_comma_elt): New function.  Accepts whitespace in comma lists.
	* gensupport.h: Prototype new routines.
	* genattr.c (gen_attr): Use scan_comma_elt.  Avoid unnecessary
	use of printf.
	* genattrtab.c (n_comma_elts): Moved to gensupport.c.
	(next_comma_elt): Use scan_comma_elt.

	* config/i386/i386.md: Use new attribute notation to break up
	long lines in define_attr forms.

===================================================================
Index: genattr.c
--- genattr.c	29 Apr 2002 22:34:32 -0000	1.49
+++ genattr.c	12 May 2002 00:47:37 -0000
@@ -86,34 +86,30 @@ static void
 gen_attr (attr)
      rtx attr;
 {
-  const char *p;
+  const char *p, *tag;
   int is_const = GET_CODE (XEXP (attr, 2)) == CONST;  
 
   printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0));
 
   /* If numeric attribute, don't need to write an enum.  */
-  if (*XSTR (attr, 1) == '\0')
+  p = XSTR (attr, 1);
+  if (*p == '\0')
     printf ("extern int get_attr_%s PARAMS ((%s));\n", XSTR (attr, 0),
 	    (is_const ? "void" : "rtx"));
   else
     {
       printf ("enum attr_%s {", XSTR (attr, 0));
-      write_upcase (XSTR (attr, 0));
-      printf ("_");
 
-      for (p = XSTR (attr, 1); *p != '\0'; p++)
+      while ((tag = scan_comma_elt (&p)) != 0)
 	{
-	  if (*p == ',')
-	    {
-	      printf (", ");
-	      write_upcase (XSTR (attr, 0));
-	      printf ("_");
-	    }
-	  else
-	    putchar (TOUPPER(*p));
+	  write_upcase (XSTR (attr, 0));
+	  putchar ('_');
+	  while (tag != p)
+	    putchar (TOUPPER (*tag++));
+	  fputs (", ", stdout);
 	}
 
-      printf ("};\n");
+      fputs ("};\n", stdout);
       printf ("extern enum attr_%s get_attr_%s PARAMS ((%s));\n\n",
 	      XSTR (attr, 0), XSTR (attr, 0), (is_const ? "void" : "rtx"));
     }
@@ -122,11 +118,12 @@ gen_attr (attr)
      variables used by `insn_current_length'.  */
   if (! strcmp (XSTR (attr, 0), "length"))
     {
-      printf ("extern void shorten_branches PARAMS ((rtx));\n");
-      printf ("extern int insn_default_length PARAMS ((rtx));\n");
-      printf ("extern int insn_variable_length_p PARAMS ((rtx));\n");
-      printf ("extern int insn_current_length PARAMS ((rtx));\n\n");
-      printf ("#include \"insn-addr.h\"\n\n");
+      puts ("\
+extern void shorten_branches PARAMS ((rtx));\n\
+extern int insn_default_length PARAMS ((rtx));\n\
+extern int insn_variable_length_p PARAMS ((rtx));\n\
+extern int insn_current_length PARAMS ((rtx));\n\n\
+#include \"insn-addr.h\"\n");
     }
 }
 
===================================================================
Index: genattrtab.c
--- genattrtab.c	2 May 2002 21:28:24 -0000	1.113
+++ genattrtab.c	12 May 2002 00:47:39 -0000
@@ -456,7 +456,6 @@ static void write_complex_function PARAM
 static int write_expr_attr_cache PARAMS ((rtx, struct attr_desc *));
 static void write_toplevel_expr	PARAMS ((rtx));
 static void write_const_num_delay_slots PARAMS ((void));
-static int n_comma_elts		PARAMS ((const char *));
 static char *next_comma_elt	PARAMS ((const char **));
 static struct attr_desc *find_attr PARAMS ((const char *, int));
 static struct attr_value *find_most_used  PARAMS ((struct attr_desc *));
@@ -5793,25 +5792,6 @@ write_complex_function (unit, name, conn
 
 /* This page contains miscellaneous utility routines.  */
 
-/* Given a string, return the number of comma-separated elements in it.
-   Return 0 for the null string.  */
-
-static int
-n_comma_elts (s)
-     const char *s;
-{
-  int n;
-
-  if (*s == '\0')
-    return 0;
-
-  for (n = 1; *s; s++)
-    if (*s == ',')
-      n++;
-
-  return n;
-}
-
 /* Given a pointer to a (char *), return a malloc'ed string containing the
    next comma-separated element.  Advance the pointer to after the string
    scanned, or the end-of-string.  Return NULL if at end of string.  */
@@ -5820,23 +5800,14 @@ static char *
 next_comma_elt (pstr)
      const char **pstr;
 {
-  char *out_str;
-  const char *p;
-
-  if (**pstr == '\0')
-    return NULL;
-
-  /* Find end of string to compute length.  */
-  for (p = *pstr; *p != ',' && *p != '\0'; p++)
-    ;
+  const char *start;
 
-  out_str = attr_string (*pstr, p - *pstr);
-  *pstr = p;
+  start = scan_comma_elt (pstr);
 
-  if (**pstr == ',')
-    (*pstr)++;
+  if (start == NULL)
+    return NULL;
 
-  return out_str;
+  return attr_string (start, *pstr - start);
 }
 
 /* Return a `struct attr_desc' pointer for a given named attribute.  If CREATE
===================================================================
Index: gensupport.c
--- gensupport.c	8 Mar 2002 22:44:21 -0000	1.29
+++ gensupport.c	12 May 2002 00:47:39 -0000
@@ -1,5 +1,5 @@
 /* Support routines for the various generation passes.
-   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
 
    This file is part of GCC.
 
@@ -1098,4 +1098,52 @@ read_md_rtx (lineno, seqnr)
     }
 
   return desc;
+}
+
+/* Given a string, return the number of comma-separated elements in it.
+   Return 0 for the null string.  */
+int
+n_comma_elts (s)
+     const char *s;
+{
+  int n;
+
+  if (*s == '\0')
+    return 0;
+
+  for (n = 1; *s; s++)
+    if (*s == ',')
+      n++;
+
+  return n;
+}
+
+/* Given a pointer to a (char *), return a pointer to the beginning of the
+   next comma-separated element in the string.  Advance the pointer given
+   to the end of that element.  Return NULL if at end of string.  Caller
+   is responsible for copying the string if necessary.  White space between
+   a comma and an element is ignored.  */
+
+const char *
+scan_comma_elt (pstr)
+     const char **pstr;
+{
+  const char *start;
+  const char *p = *pstr;
+
+  if (*p == ',')
+    p++;
+  while (ISSPACE(*p))
+    p++;
+
+  if (*p == '\0')
+    return NULL;
+
+  start = p;
+
+  while (*p != ',' && *p != '\0')
+    p++;
+
+  *pstr = p;
+  return start;
 }
===================================================================
Index: gensupport.h
--- gensupport.h	14 Nov 2001 20:17:08 -0000	1.4
+++ gensupport.h	12 May 2002 00:47:39 -0000
@@ -1,5 +1,5 @@
 /* Declarations for rtx-reader support for gen* routines.
-   Copyright (C) 2000 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2002 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -27,3 +27,7 @@ extern rtx read_md_rtx		PARAMS ((int *, 
 
 extern void message_with_line	PARAMS ((int, const char *, ...))
      ATTRIBUTE_PRINTF_2;
+
+extern int n_comma_elts		PARAMS ((const char *));
+extern const char *scan_comma_elt PARAMS ((const char **));
+
===================================================================
Index: config/i386/i386.md
--- config/i386/i386.md	11 May 2002 17:16:28 -0000	1.357
+++ config/i386/i386.md	12 May 2002 00:47:42 -0000
@@ -123,20 +123,31 @@
 ;; A basic instruction type.  Refinements due to arguments to be
 ;; provided in other attributes.
 (define_attr "type"
-  "other,multi,alu1,negnot,alu,icmp,test,imov,imovx,lea,incdec,ishift,rotate,imul,idiv,ibr,setcc,push,pop,call,callv,icmov,fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,str,cld,sse,sseadd,ssemul,ssediv,ssemov,ssecmp,ssecvt,sselog,sseiadd,sseishft,sseimul,mmx,mmxmov,mmxadd,mmxshft,mmxcmp,mmxcvt,mmxmul,fistp"
+  "other,multi,
+   alu,alu1,negnot,imov,imovx,lea,
+   incdec,ishift,rotate,imul,idiv,
+   icmp,test,ibr,setcc,icmov,
+   push,pop,call,callv,
+   str,cld,
+   fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp,
+   sselog,sseiadd,sseishft,sseimul,
+   sse,ssemov,sseadd,ssemul,ssecmp,ssecvt,ssediv,
+   mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft"
   (const_string "other"))
 
 ;; Main data type used by the insn
-(define_attr "mode" "unknown,none,QI,HI,SI,DI,unknownfp,SF,DF,XF,TI,V4SF,V2DF,V2SF"
+(define_attr "mode"
+  "unknown,none,QI,HI,SI,DI,unknownfp,SF,DF,XF,TI,V4SF,V2DF,V2SF"
   (const_string "unknown"))
 
 ;; The CPU unit operations uses.
 (define_attr "unit" "integer,i387,sse,mmx,unknown"
   (cond [(eq_attr "type" "fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp")
 	   (const_string "i387")
-	 (eq_attr "type" "sse,sseadd,ssemul,ssediv,ssemov,ssecmp,ssecvt,sselog,sseiadd,sseishft,sseimul")
+	 (eq_attr "type" "sselog,sseiadd,sseishft,sseimul,
+			  sse,ssemov,sseadd,ssemul,ssecmp,ssecvt,ssediv")
 	   (const_string "sse")
-	 (eq_attr "type" "mmx,mmxmov,mmxadd,mmxshft,mmxcmp,mmxcvt,mmxmul")
+	 (eq_attr "type" "mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft")
 	   (const_string "mmx")]
 	 (const_string "integer")))
 
@@ -146,7 +157,8 @@
 	   (const_int 0)
 	 (eq_attr "unit" "i387,sse,mmx")
 	   (const_int 0)
-	 (eq_attr "type" "alu1,negnot,alu,icmp,imovx,ishift,rotate,imul,push,pop")
+	 (eq_attr "type" "alu,alu1,negnot,imovx,ishift,rotate,imul,
+			  icmp,push,pop")
 	   (symbol_ref "ix86_attr_length_immediate_default(insn,1)")
 	 (eq_attr "type" "imov,test")
 	   (symbol_ref "ix86_attr_length_immediate_default(insn,0)")
@@ -166,7 +178,8 @@
 	     (const_int 1)
 	     (const_int 4))
 	 ]
-	 (symbol_ref "/* Update immediate_length and other attributes! */ abort(),1")))
+	 (symbol_ref "/* Update immediate_length and other attributes! */
+		      abort(),1")))
 
 ;; The (bounding maximum) length of an instruction address.
 (define_attr "length_address" ""
@@ -196,7 +209,12 @@
 
 ;; Set when 0f opcode prefix is used.
 (define_attr "prefix_0f" ""
-  (if_then_else (eq_attr "type" "imovx,setcc,icmov,sse,sseadd,ssemul,ssediv,ssemov,ssecmp,ssecvt,sselog,sseiadd,sseishft,sseimul,mmx,mmxmov,mmxadd,mmxshft,mmxcmp,mmxcvt,mmxmul")
+  (if_then_else 
+    (eq_attr "type" 
+             "imovx,setcc,icmov,
+              sselog,sseiadd,sseishft,sseimul,
+              sse,ssemov,sseadd,ssemul,ssecmp,ssecvt,ssediv,
+              mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft")
     (const_int 1)
     (const_int 0)))
 
@@ -287,7 +305,12 @@
 	   (const_string "store")
 	 (match_operand 1 "memory_operand" "")
 	   (const_string "load")
-	 (and (eq_attr "type" "!icmp,test,alu1,negnot,fsgn,imov,imovx,fmov,fcmp,sse,ssecmp,mmx,ssemov,mmxmov,ssecvt,mmxcvt,mmxcmp")
+	 (and (eq_attr "type"
+		 "!alu1,negnot,
+		   imov,imovx,icmp,test,
+		   fmov,fcmp,fsgn,
+		   sse,ssemov,ssecmp,ssecvt,
+		   mmx,mmxmov,mmxcmp,mmxcvt")
 	      (match_operand 2 "memory_operand" ""))
 	   (const_string "load")
 	 (and (eq_attr "type" "icmov")


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