OSDN Git Service

2010-03-16 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
[pf3gnuchains/gcc-fork.git] / gcc / gengtype.c
index bb06736..91f3f57 100644 (file)
@@ -141,8 +141,7 @@ static void oprintf (outf_p o, const char *S, ...)
 static outf_p output_files;
 
 /* The plugin input files and their number; in that case only
-   corresponding gt-<plugin>.h are generated in the current
-   directory.  */
+   a single file is produced.  */
 static char** plugin_files;
 static size_t nb_plugin_files;
 /* the generated plugin output name & file */
@@ -464,7 +463,7 @@ read_input_list (const char *listname)
         things there are.  (We do not bother resizing the arrays down.)  */
       num_lang_dirs = langno;
       /* Add the plugin files if provided.  */
-      if (plugin_files) 
+      if (plugin_files)
        {
          size_t i;
          for (i = 0; i < nb_plugin_files; i++)
@@ -977,7 +976,7 @@ write_rtx_next (void)
 {
   outf_p f = get_output_file_with_visibility (NULL);
   int i;
-  if (!f) 
+  if (!f)
     return;
 
   oprintf (f, "\n/* Used to implement the RTX_NEXT macro.  */\n");
@@ -1118,6 +1117,8 @@ adjust_field_rtx_def (type_p t, options_p ARG_UNUSED (opt))
                t = scalar_tp, subname = "rt_int";
              else if (i == VALUE && aindex == 0)
                t = scalar_tp, subname = "rt_int";
+             else if (i == DEBUG_EXPR && aindex == 0)
+               t = tree_tp, subname = "rt_tree";
              else if (i == REG && aindex == 1)
                t = scalar_tp, subname = "rt_int";
              else if (i == REG && aindex == 2)
@@ -1392,7 +1393,7 @@ set_gc_used_type (type_p t, enum gc_used_enum level, type_p param[NUM_PARAM])
                                &length, &skip, &nested_ptr);
 
            if (nested_ptr && f->type->kind == TYPE_POINTER)
-             set_gc_used_type (nested_ptr, GC_POINTED_TO, 
+             set_gc_used_type (nested_ptr, GC_POINTED_TO,
                                pass_param ? param : NULL);
            else if (length && f->type->kind == TYPE_POINTER)
              set_gc_used_type (f->type->u.p, GC_USED, NULL);
@@ -1502,7 +1503,7 @@ create_file (const char *name, const char *oname)
   return f;
 }
 
-/* Print, like fprintf, to O.  
+/* Print, like fprintf, to O.
    N.B. You might think this could be implemented more efficiently
    with vsnprintf().  Unfortunately, there are C libraries that
    provide that function but without the C99 semantics for its return
@@ -1516,7 +1517,7 @@ oprintf (outf_p o, const char *format, ...)
 
   /* In plugin mode, the O could be a NULL pointer, so avoid crashing
      in that case.  */
-  if (!o) 
+  if (!o)
     return;
 
   va_start (ap, format);
@@ -1563,14 +1564,14 @@ open_base_files (void)
   {
     /* The order of files here matters very much.  */
     static const char *const ifiles [] = {
-      "config.h", "system.h", "coretypes.h", "tm.h", "varray.h", 
+      "config.h", "system.h", "coretypes.h", "tm.h", "varray.h",
       "hashtab.h", "splay-tree.h",  "obstack.h", "bitmap.h", "input.h",
       "tree.h", "rtl.h", "function.h", "insn-config.h", "expr.h",
       "hard-reg-set.h", "basic-block.h", "cselib.h", "insn-addr.h",
       "optabs.h", "libfuncs.h", "debug.h", "ggc.h", "cgraph.h",
       "tree-flow.h", "reload.h", "cpp-id-data.h", "tree-chrec.h",
       "cfglayout.h", "except.h", "output.h", "gimple.h", "cfgloop.h",
-      "target.h", NULL
+      "target.h", "ipa-prop.h", NULL
     };
     const char *const *ifp;
     outf_p gtype_desc_c;
@@ -1592,7 +1593,7 @@ static const char *
 get_file_realbasename (const char *f)
 {
   const char * lastslash = strrchr (f, '/');
-  
+
   return (lastslash != NULL) ? lastslash + 1 : f;
 }
 
@@ -1634,7 +1635,7 @@ get_prefix_langdir_index (const char *f)
     {
       const char * langdir = lang_dir_names [lang_index];
       size_t langdir_len = strlen (langdir);
-         
+
       if (f_len > langdir_len
          && IS_DIR_SEPARATOR (f[langdir_len])
          && memcmp (f, langdir, langdir_len) == 0)
@@ -1675,7 +1676,7 @@ get_file_gtfilename (const char *f)
 
   const char *basename = get_file_realbasename (f);
   const char *langdir = get_file_langdir (f);
-  
+
   char * result =
     (langdir ? xasprintf ("gt-%s-%s", langdir, basename)
      : xasprintf ("gt-%s", basename));
@@ -1734,7 +1735,7 @@ get_output_file_with_visibility (const char *input_file)
       || (len > 2 && memcmp (basename+len-2, ".y", 2) == 0)
       || (len > 3 && memcmp (basename+len-3, ".in", 3) == 0))
     {
-      output_name = get_file_gtfilename (input_file); 
+      output_name = get_file_gtfilename (input_file);
       for_name = basename;
     }
   /* Some headers get used by more than one front-end; hence, it
@@ -1760,7 +1761,7 @@ get_output_file_with_visibility (const char *input_file)
   else if (strncmp (basename, "objc", 4) == 0 && IS_DIR_SEPARATOR (basename[4])
           && strcmp (basename + 5, "objc-act.h") == 0)
     output_name = "gt-objc-objc-act.h", for_name = "objc/objc-act.c";
-  else 
+  else
     {
       int lang_index = get_prefix_langdir_index (basename);
 
@@ -2171,9 +2172,9 @@ walk_type (type_p t, struct walk_type_data *d)
                d->indent += 2;
                d->val = xasprintf ("x%d", d->counter++);
                oprintf (d->of, "%*s%s %s * %s%s =\n", d->indent, "",
-                        (nested_ptr_d->type->kind == TYPE_UNION 
-                         ? "union" : "struct"), 
-                        nested_ptr_d->type->u.s.tag, 
+                        (nested_ptr_d->type->kind == TYPE_UNION
+                         ? "union" : "struct"),
+                        nested_ptr_d->type->u.s.tag,
                         d->fn_wants_lvalue ? "" : "const ",
                         d->val);
                oprintf (d->of, "%*s", d->indent + 2, "");
@@ -2261,7 +2262,7 @@ walk_type (type_p t, struct walk_type_data *d)
        else
          oprintf (d->of, "%s", t->u.a.len);
        oprintf (d->of, ");\n");
-       
+
        oprintf (d->of, "%*sfor (i%d = 0; i%d != l%d; i%d++) {\n",
                 d->indent, "",
                 loopcounter, loopcounter, loopcounter, loopcounter);
@@ -2719,6 +2720,9 @@ write_types (outf_p output_header, type_p structures, type_p param_structs,
   type_p s;
 
   oprintf (output_header, "\n/* %s*/\n", wtd->comment);
+  /* We first emit the macros and the declarations. Functions' code is
+     emitted afterwards.  This is needed in plugin mode.  */
+  oprintf (output_header, "/* macros and declarations */\n");
   for (s = structures; s; s = s->next)
     if (s->gc_used == GC_POINTED_TO
        || s->gc_used == GC_MAYBE_POINTED_TO)
@@ -2767,21 +2771,11 @@ write_types (outf_p output_header, type_p structures, type_p param_structs,
                     s->u.s.tag);
            continue;
          }
-
-       if (s->kind == TYPE_LANG_STRUCT)
-         {
-           type_p ss;
-           for (ss = s->u.s.lang_struct; ss; ss = ss->next)
-             write_func_for_structure (s, ss, NULL, wtd);
-         }
-       else
-         write_func_for_structure (s, s, NULL, wtd);
       }
 
   for (s = param_structs; s; s = s->next)
     if (s->gc_used == GC_POINTED_TO)
       {
-       type_p * param = s->u.param_struct.param;
        type_p stru = s->u.param_struct.stru;
 
        /* Declare the marker procedure.  */
@@ -2795,7 +2789,41 @@ write_types (outf_p output_header, type_p structures, type_p param_structs,
                     s->u.s.tag);
            continue;
          }
+      }
+
+  /* At last we emit the functions code.  */
+  oprintf (output_header, "\n/* functions code */\n");
+  for (s = structures; s; s = s->next)
+    if (s->gc_used == GC_POINTED_TO
+       || s->gc_used == GC_MAYBE_POINTED_TO)
+      {
+       options_p opt;
 
+       if (s->gc_used == GC_MAYBE_POINTED_TO
+           && s->u.s.line.file == NULL)
+         continue;
+       for (opt = s->u.s.opt; opt; opt = opt->next)
+         if (strcmp (opt->name, "ptr_alias") == 0)
+           break;
+       if (opt)
+         continue;
+
+       if (s->kind == TYPE_LANG_STRUCT)
+         {
+           type_p ss;
+           for (ss = s->u.s.lang_struct; ss; ss = ss->next)
+             write_func_for_structure (s, ss, NULL, wtd);
+         }
+       else
+         write_func_for_structure (s, s, NULL, wtd);
+      }
+  for (s = param_structs; s; s = s->next)
+    if (s->gc_used == GC_POINTED_TO)
+      {
+       type_p *param = s->u.param_struct.param;
+       type_p stru = s->u.param_struct.stru;
+       if (stru->u.s.line.file == NULL)
+         continue;
        if (stru->kind == TYPE_LANG_STRUCT)
          {
            type_p ss;
@@ -2906,7 +2934,7 @@ write_local (outf_p output_header, type_p structures, type_p param_structs)
 {
   type_p s;
 
-  if (!output_header) 
+  if (!output_header)
     return;
   oprintf (output_header, "\n/* Local pointer-walking routines.  */\n");
   for (s = structures; s; s = s->next)
@@ -2993,7 +3021,7 @@ write_enum_defn (type_p structures, type_p param_structs)
 {
   type_p s;
 
-  if (!header_file) 
+  if (!header_file)
     return;
   oprintf (header_file, "\n/* Enumeration of types known.  */\n");
   oprintf (header_file, "enum gt_types_enum {\n");
@@ -3045,7 +3073,7 @@ static void
 put_mangled_filename (outf_p f, const char *fn)
 {
   const char *name = get_output_file_name (fn);
-  if (!f || !name) 
+  if (!f || !name)
     return;
   for (; *name != 0; name++)
     if (ISALNUM (*name))
@@ -3691,11 +3719,11 @@ main (int argc, char **argv)
         strcpy (plugin_files[i], name);
       }
     }
-  else if (argc == 3) 
+  else if (argc == 3)
     {
       srcdir = argv[1];
       inputlist = argv[2];
-    } 
+    }
   else
     fatal ("usage: gengtype [-P pluginout.h] srcdir input-list "
            "[file1 file2 ... fileN]");