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]

Re: PATCH RFA: Permit macro attributes to set modes


Richard Sandiford <rsandifo@redhat.com> writes:

> My one concern is about the checking code.  We don't complain about
> unrecognised "<...>" sequences in strings because there's no guarantee
> that a particular "<" or ">" character was supposed to be part of a
> string substitution.  That doesn't apply to modes though.  It should
> be a hard error if "<FOO:BARMODE>" doesn't match anything.

I intentionally didn't bother with doing serious error checking,
because this is a developer only tool, and because genrecog will crash
when given an invalid mode.

But your approach for detecting an undefined error string is a good
one.  I'm testing this patch.

How does it look?  OK if it passes tests?

Ian


2005-05-16  Ian Lance Taylor  <ian@airs.com>

	* read-rtl.c (struct macro_traverse_data): Add unknown_mode_attr
	field.
	(mode_attr_index): Remove check for defined attribute.
	(apply_mode_maps): Add unknown parameter.  Change caller.  Always
	return after finding attribute.
	(apply_macro_to_rtx): Add uknown_mode_attr parameter.  Change
	callers.
	(apply_macro_traverse): Set mtd->unknown_mode_attr.
	(read_rtx): Use mtd.unknown_mode_attr to check for an undefined
	attribute used for a mode.


Index: read-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/read-rtl.c,v
retrieving revision 1.37
diff -p -u -r1.37 read-rtl.c
--- read-rtl.c	10 May 2005 22:40:36 -0000	1.37
+++ read-rtl.c	16 May 2005 04:51:36 -0000
@@ -96,6 +96,8 @@ struct macro_traverse_data {
   struct map_value *mode_maps;
   /* Input file.  */
   FILE *infile;
+  /* The last unknown attribute used as a mode.  */
+  const char *unknown_mode_attr;
 };
 
 /* If CODE is the number of a code macro, return a real rtx code that
@@ -114,7 +116,7 @@ static bool uses_code_macro_p (rtx, int)
 static void apply_code_macro (rtx, int);
 static const char *apply_macro_to_string (const char *, struct mapping *, int);
 static rtx apply_macro_to_rtx (rtx, struct mapping *, int,
-			       struct map_value *, FILE *);
+			       struct map_value *, FILE *, const char **);
 static bool uses_macro_p (rtx, struct mapping *);
 static const char *add_condition_to_string (const char *, const char *);
 static void add_condition_to_rtx (rtx, const char *);
@@ -315,7 +317,6 @@ mode_attr_index (struct map_value **mode
 		 FILE *infile)
 {
   char *p;
-  char *attr;
   struct map_value *mv;
 
   /* Copy the attribute string into permanent storage, without the
@@ -323,19 +324,6 @@ mode_attr_index (struct map_value **mode
   obstack_grow (&string_obstack, string + 1, strlen (string) - 2);
   p = (char *) obstack_finish (&string_obstack);
 
-  /* Make sure the attribute is defined as either a code attribute or
-     a mode attribute.  */
-  attr = strchr (p, ':');
-  if (attr == 0)
-    attr = p;
-  else
-    ++attr;
-
-  if (!htab_find (modes.attrs, &attr) && !htab_find (codes.attrs, &attr))
-    fatal_with_file_and_line (infile,
-			      "undefined attribute '%s' used for mode",
-			      p);
-
   mv = XNEW (struct map_value);
   mv->number = *mode_maps == 0 ? 0 : (*mode_maps)->number + 1;
   mv->string = p;
@@ -348,11 +336,16 @@ mode_attr_index (struct map_value **mode
   return MAX_MACHINE_MODE + htab_elements (modes.macros) + mv->number;
 }
 
-/* Apply MODE_MAPS to the top level of X.  */
+/* Apply MODE_MAPS to the top level of X, expanding cases where an
+   attribute is used for a mode.  MACRO is the current macro we are
+   expanding, and VALUE is the value to which we are expanding it.
+   INFILE is used for error messages.  This sets *UNKNOWN to true if
+   we find a mode attribute which has not yet been defined, and does
+   not change it otherwise.  */
 
 static void
 apply_mode_maps (rtx x, struct map_value *mode_maps, struct mapping *macro,
-		 int value, FILE *infile)
+		 int value, FILE *infile, const char **unknown)
 {
   unsigned int offset;
   int indx;
@@ -371,10 +364,10 @@ apply_mode_maps (rtx x, struct map_value
 
 	  v = map_attr_string (pm->string, macro, value);
 	  if (v)
-	    {
-	      PUT_MODE (x, find_mode (v->string, infile));
-	      return;
-	    }
+	    PUT_MODE (x, find_mode (v->string, infile));
+	  else
+	    *unknown = pm->string;
+	  return;
 	}
     }
 }
@@ -420,11 +413,15 @@ apply_macro_to_string (const char *strin
 }
 
 /* Return a copy of ORIGINAL in which all uses of MACRO have been
-   replaced by VALUE.  */
+   replaced by VALUE.  MODE_MAPS holds information about attribute
+   strings used for modes.  INFILE is used for error messages.  This
+   sets *UNKNOWN_MODE_ATTR to the value of an unknown mode attribute,
+   and does not change it otherwise.  */
 
 static rtx
 apply_macro_to_rtx (rtx original, struct mapping *macro, int value,
-		    struct map_value *mode_maps, FILE *infile)
+		    struct map_value *mode_maps, FILE *infile,
+		    const char **unknown_mode_attr)
 {
   struct macro_group *group;
   const char *format_ptr;
@@ -446,7 +443,7 @@ apply_macro_to_rtx (rtx original, struct
     group->apply_macro (x, value);
 
   if (mode_maps)
-    apply_mode_maps (x, mode_maps, macro, value, infile);
+    apply_mode_maps (x, mode_maps, macro, value, infile, unknown_mode_attr);
 
   /* Change each string and recursively change each rtx.  */
   format_ptr = GET_RTX_FORMAT (bellwether_code);
@@ -464,7 +461,8 @@ apply_macro_to_rtx (rtx original, struct
 
       case 'e':
 	XEXP (x, i) = apply_macro_to_rtx (XEXP (x, i), macro, value,
-					  mode_maps, infile);
+					  mode_maps, infile,
+					  unknown_mode_attr);
 	break;
 
       case 'V':
@@ -475,7 +473,8 @@ apply_macro_to_rtx (rtx original, struct
 	    for (j = 0; j < XVECLEN (x, i); j++)
 	      XVECEXP (x, i, j) = apply_macro_to_rtx (XVECEXP (original, i, j),
 						      macro, value, mode_maps,
-						      infile);
+						      infile,
+						      unknown_mode_attr);
 	  }
 	break;
 
@@ -581,11 +580,20 @@ apply_macro_traverse (void **slot, void 
   for (elem = mtd->queue; elem != 0; elem = XEXP (elem, 1))
     if (uses_macro_p (XEXP (elem, 0), macro))
       {
+	/* For each macro we expand, we set UNKNOWN_MODE_ATTR to NULL.
+	   If apply_macro_rtx finds an unknown attribute for a mode,
+	   it will set it to the attribute.  We want to know whether
+	   the attribute is unknown after we have expanded all
+	   possible macros, so setting it to NULL here gives us the
+	   right result when the hash table traversal is complete.  */
+	mtd->unknown_mode_attr = NULL;
+
 	original = XEXP (elem, 0);
 	for (v = macro->values; v != 0; v = v->next)
 	  {
 	    x = apply_macro_to_rtx (original, macro, v->number,
-				    mtd->mode_maps, mtd->infile);
+				    mtd->mode_maps, mtd->infile,
+				    &mtd->unknown_mode_attr);
 	    add_condition_to_rtx (x, v->string);
 	    if (v != macro->values)
 	      {
@@ -1362,8 +1370,13 @@ read_rtx (FILE *infile, rtx *x, int *lin
       mtd.queue = queue_next;
       mtd.mode_maps = mode_maps;
       mtd.infile = infile;
+      mtd.unknown_mode_attr = mode_maps ? mode_maps->string : NULL;
       htab_traverse (modes.macros, apply_macro_traverse, &mtd);
       htab_traverse (codes.macros, apply_macro_traverse, &mtd);
+      if (mtd.unknown_mode_attr)
+	fatal_with_file_and_line (infile,
+				  "undefined attribute '%s' used for mode",
+				  mtd.unknown_mode_attr);
     }
 
   *x = XEXP (queue_next, 0);


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