RFA: Making attribute values avaliable for options
diff mbox

Message ID 20110710234620.ujver5yio08so8os-nzlynne@webmail.spamcop.net
State New
Headers show

Commit Message

Joern Rennecke July 11, 2011, 3:46 a.m. UTC
Quoting "Joseph S. Myers" <joseph@codesourcery.com>:

> On Tue, 5 Jul 2011, Joern Rennecke wrote:
>
>> This patch splits out a new generator genattr-enum from genattr, and it
>> generates insn-attr-enum.h, which just makes the enum declarations.
>> This new header file is then included by options.c and insn-attr.h .
>
> Is there a particular reason for making this separate from the existing
> genattr-common that I created recently?  Like opts.c, options.c is a file
> shared by both the driver and the core compiler that can't include the
> full insn-attr.h for the same reason.

Attached is a variant of my patch that uses your suggestion.
bootstrapped on x86_64-unknown-linux-gnu.
2011-07-11  Joern Rennecke  <joern.rennecke@embecosm.com>

	* genattr.c (write_upcase, gen_attr <enum definition writing>):
	Move to ...
	* genattr-common.c ... here.
	(main): Call gen_attr.
	* optc-gen.awk: Make generated program include insn-attr-common.h .
	* Makefile.in (oprions.o): Depend on insn-attr-common.h

Comments

Joseph Myers July 21, 2011, 2:33 p.m. UTC | #1
On Sun, 10 Jul 2011, Joern Rennecke wrote:

> Quoting "Joseph S. Myers" <joseph@codesourcery.com>:
> 
> > On Tue, 5 Jul 2011, Joern Rennecke wrote:
> > 
> > > This patch splits out a new generator genattr-enum from genattr, and it
> > > generates insn-attr-enum.h, which just makes the enum declarations.
> > > This new header file is then included by options.c and insn-attr.h .
> > 
> > Is there a particular reason for making this separate from the existing
> > genattr-common that I created recently?  Like opts.c, options.c is a file
> > shared by both the driver and the core compiler that can't include the
> > full insn-attr.h for the same reason.
> 
> Attached is a variant of my patch that uses your suggestion.
> bootstrapped on x86_64-unknown-linux-gnu.

OK in the absence of objections within 48 hours.

Patch
diff mbox

Index: gcc/genattr-common.c
===================================================================
--- gcc/genattr-common.c	(revision 175852)
+++ gcc/genattr-common.c	(working copy)
@@ -30,6 +30,36 @@  Software Foundation; either version 3, o
 #include "read-md.h"
 #include "gensupport.h"
 
+static void
+write_upcase (const char *str)
+{
+  for (; *str; str++)
+    putchar (TOUPPER(*str));
+}
+
+static void
+gen_attr (rtx attr)
+{
+  const char *p, *tag;
+
+  p = XSTR (attr, 1);
+  if (*p != '\0')
+    {
+      printf ("enum attr_%s {", XSTR (attr, 0));
+
+      while ((tag = scan_comma_elt (&p)) != 0)
+	{
+	  write_upcase (XSTR (attr, 0));
+	  putchar ('_');
+	  while (tag != p)
+	    putchar (TOUPPER (*tag++));
+	  if (*p == ',')
+	    fputs (", ", stdout);
+	}
+      fputs ("};\n", stdout);
+    }
+}
+
 int
 main (int argc, char **argv)
 {
@@ -57,6 +87,9 @@  main (int argc, char **argv)
       if (desc == NULL)
 	break;
 
+      if (GET_CODE (desc) == DEFINE_ATTR)
+	gen_attr (desc);
+
       if (GET_CODE (desc) == DEFINE_DELAY)
         {
 	  if (!have_delay)
Index: gcc/genattr.c
===================================================================
--- gcc/genattr.c	(revision 175852)
+++ gcc/genattr.c	(working copy)
@@ -30,23 +30,15 @@  Software Foundation; either version 3, o
 #include "gensupport.h"
 
 
-static void write_upcase (const char *);
 static void gen_attr (rtx);
 
-static void
-write_upcase (const char *str)
-{
-  for (; *str; str++)
-    putchar (TOUPPER(*str));
-}
-
 static VEC (rtx, heap) *const_attrs, *reservations;
 
 
 static void
 gen_attr (rtx attr)
 {
-  const char *p, *tag;
+  const char *p;
   int is_const = GET_CODE (XEXP (attr, 2)) == CONST;
 
   if (is_const)
@@ -65,23 +57,8 @@  gen_attr (rtx attr)
 	printf ("extern int get_attr_%s (%s);\n", XSTR (attr, 0),
 		(is_const ? "void" : "rtx"));
       else
-	{
-	  printf ("enum attr_%s {", XSTR (attr, 0));
-
-	  while ((tag = scan_comma_elt (&p)) != 0)
-	    {
-	      write_upcase (XSTR (attr, 0));
-	      putchar ('_');
-	      while (tag != p)
-		putchar (TOUPPER (*tag++));
-	      if (*p == ',')
-		fputs (", ", stdout);
-	    }
-	  fputs ("};\n", stdout);
-
-	  printf ("extern enum attr_%s get_attr_%s (%s);\n\n",
-		  XSTR (attr, 0), XSTR (attr, 0), (is_const ? "void" : "rtx"));
-	}
+	printf ("extern enum attr_%s get_attr_%s (%s);\n\n",
+		XSTR (attr, 0), XSTR (attr, 0), (is_const ? "void" : "rtx"));
     }
 
   /* If `length' attribute, write additional function definitions and define
Index: gcc/optc-gen.awk
===================================================================
--- gcc/optc-gen.awk	(revision 175852)
+++ gcc/optc-gen.awk	(working copy)
@@ -37,6 +37,7 @@  for (i = 1; i <= n_headers; i++)
 	print "#include " quote headers[i] quote
 print "#include " quote "opts.h" quote
 print "#include " quote "intl.h" quote
+print "#include " quote "insn-attr-common.h" quote
 print ""
 
 if (n_extra_c_includes > 0) {
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 175852)
+++ gcc/Makefile.in	(working copy)
@@ -2311,7 +2311,7 @@  s-options-h: optionlist $(srcdir)/opt-fu
 	$(STAMP) $@
 
 options.o: options.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
-	$(TM_H) $(OPTS_H) intl.h $(OPTIONS_C_EXTRA)
+	$(TM_H) $(OPTS_H) intl.h $(OPTIONS_C_EXTRA) insn-attr-common.h
 
 options-save.o: options-save.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TARGET_H) $(FLAGS_H) \
 	$(TM_H) $(OPTS_H) intl.h $(OPTIONS_C_EXTRA)