OSDN Git Service

2011-05-26 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / genhooks.c
index 66d3633..d70c4fe 100644 (file)
@@ -1,6 +1,6 @@
 /* Process target.def to create initialization macros definition in
    target-hooks-def.h and documentation in target-hooks.texi.
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -19,25 +19,25 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 #include "bconfig.h"
 #include "system.h"
-#include <string.h>
 #include "hashtab.h"
 #include "errors.h"
 
-struct hook_desc { const char *doc, *type, *name, *param, *init; };
+struct hook_desc { const char *doc, *type, *name, *param, *init, *docname; };
 static struct hook_desc hook_array[] = {
-#define HOOK_VECTOR_1(NAME, FRAGMENT) \
-  { 0, 0, #NAME, 0, 0 },
+#define HOOK_VECTOR_1(NAME, FRAGMENT)  \
+  { 0, 0, #NAME, 0, 0, HOOK_TYPE },
 #define DEFHOOKPOD(NAME, DOC, TYPE, INIT) \
-  { DOC, #TYPE, HOOK_PREFIX #NAME, 0, #INIT },
+  { DOC, #TYPE, HOOK_PREFIX #NAME, 0, #INIT, HOOK_TYPE },
 #define DEFHOOK(NAME, DOC, TYPE, PARAMS, INIT) \
-  { DOC, #TYPE, HOOK_PREFIX #NAME, #PARAMS, #INIT },
+  { DOC, #TYPE, HOOK_PREFIX #NAME, #PARAMS, #INIT, HOOK_TYPE },
 #define DEFHOOK_UNDOC(NAME, DOC, TYPE, PARAMS, INIT) \
-  { "*", #TYPE, HOOK_PREFIX #NAME, #PARAMS, #INIT },
+  { "*", #TYPE, HOOK_PREFIX #NAME, #PARAMS, #INIT, HOOK_TYPE },
 #include "target.def"
+#include "c-family/c-target.def"
 #undef DEFHOOK
 };
 
-/* For each @Fcode in the the first paragraph of the documentation string DOC,
+/* For each @Fcode in the first paragraph of the documentation string DOC,
    print an @findex directive.  HOOK_NAME is the name of the hook this bit of
    documentation pertains to.  */
 static void
@@ -52,7 +52,7 @@ emit_findices (const char *doc, const char *hook_name)
       doc = strchr (fcode, '}');
       if (!doc)
        fatal ("Malformed @Fcode for hook %s\n", hook_name);
-      printf ("@findex %.*s\n", doc - fcode, fcode);
+      printf ("@findex %.*s\n", (int) (doc - fcode), fcode);
       doc = fcode;
     }
 }
@@ -222,7 +222,7 @@ emit_documentation (const char *in_fname)
              /* Print header.  Function-valued hooks have a parameter list, 
                 unlike POD-valued ones.  */
              deftype = hook_array[i].param ? "deftypefn" : "deftypevr";
-             printf ("@%s {Target Hook} ", deftype);
+             printf ("@%s {%s} ", deftype, hook_array[i].docname);
              if (strchr (hook_array[i].type, ' '))
                printf ("{%s}", hook_array[i].type);
              else
@@ -238,9 +238,9 @@ emit_documentation (const char *in_fname)
                    /* Type names like 'int' are followed by a space, sometimes
                       also by '*'.  'void' should appear only in "(void)".  */
                    if (*e == ' ' || *e == '*' || *q == '(')
-                     printf ("%.*s", e - q + 1, q);
+                     printf ("%.*s", (int) (e - q + 1), q);
                    else
-                     printf ("@var{%.*s}%c", e - q, q, *e);
+                     printf ("@var{%.*s}%c", (int) (e - q), q, *e);
                }
              /* POD-valued hooks sometimes come in groups with common
                 documentation.*/
@@ -250,8 +250,9 @@ emit_documentation (const char *in_fname)
                {
                  char *namex = upstrdup (hook_array[j].name);
 
-                 printf ("\n@%sx {Target Hook} {%s} %s",
-                         deftype, hook_array[j].type, namex);
+                 printf ("\n@%sx {%s} {%s} %s",
+                         deftype, hook_array[j].docname,
+                         hook_array[j].type, namex);
                }
              if (hook_array[i].doc[0])
                {
@@ -265,8 +266,8 @@ emit_documentation (const char *in_fname)
                      /* Print paragraph, emitting @Fcode as @code.  */
                      for (; (fcode = strstr (doc, "@Fcode{")) && fcode < p_end;
                           doc = fcode + 2)
-                       printf ("%.*s@", fcode - doc, doc);
-                     printf ("%.*s", p_end - doc, doc);
+                       printf ("%.*s@", (int) (fcode - doc), doc);
+                     printf ("%.*s", (int) (p_end - doc), doc);
                      /* Emit function indices for next paragraph.  */
                      emit_findices (p_end, name);
                    }
@@ -286,9 +287,10 @@ emit_documentation (const char *in_fname)
 
 /* Emit #defines to stdout (this will be redirected to generate
    target-hook-def.h) which set target hooks initializer macros
-   to their default values.  */
+   to their default values.  These should only be emitted for hooks
+   whose type is given by DOCNAME.  */
 static void
-emit_init_macros (void)
+emit_init_macros (const char *docname)
 {
   int i;
   const int MAX_NEST = 2;
@@ -300,6 +302,9 @@ emit_init_macros (void)
        {
          char *name = upstrdup (hook_array[i].name);
 
+         if (strcmp (hook_array[i].docname, docname) != 0)
+           continue;
+
          if (!hook_array[i].type)
            {
              if (*name)
@@ -335,9 +340,9 @@ emit_init_macros (void)
 int
 main (int argc, char **argv)
 {
-  if (argc >= 2)
-    emit_documentation (argv[1]);
+  if (argc >= 3)
+    emit_documentation (argv[2]);
   else
-    emit_init_macros ();
+    emit_init_macros (argv[1]);
   return 0;
 }