1 /* Process source files and output type information.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
26 #include "errors.h" /* for fatal */
28 #include "version.h" /* for version_string & pkgversion_string. */
33 #include "filenames.h"
35 /* Data types, macros, etc. used only in this file. */
38 /* The list of output files. */
41 /* The output header file that is included into pretty much every
46 /* The name of the file containing the list of input files. */
47 static char *inputlist
;
49 /* The plugin input files and their number; in that case only
50 a single file is produced. */
51 static input_file
**plugin_files
;
52 static size_t nb_plugin_files
;
54 /* The generated plugin output file and name. */
55 static outf_p plugin_output
;
56 static char *plugin_output_filename
;
58 /* Our source directory and its length. */
62 /* Variables used for reading and writing the state. */
63 const char *read_state_filename
;
64 const char *write_state_filename
;
66 /* Variables to help debugging. */
70 /* Level for verbose messages. */
73 /* We have a type count and use it to set the state_number of newly
74 allocated types to some unique negative number. */
75 static int type_count
;
77 /* The backup directory should be in the same file system as the
78 generated files, otherwise the rename(2) system call would fail.
79 If NULL, no backup is made when overwriting a generated file. */
80 static const char* backup_dir
; /* (-B) program option. */
83 static outf_p
create_file (const char *, const char *);
85 static const char *get_file_basename (const input_file
*);
86 static const char *get_file_realbasename (const input_file
*);
88 static int get_prefix_langdir_index (const char *);
89 static const char *get_file_langdir (const input_file
*);
91 static void dump_pair (int indent
, pair_p p
);
92 static void dump_type (int indent
, type_p p
);
93 static void dump_type_list (int indent
, type_p p
);
96 /* Nonzero iff an error has occurred. */
97 bool hit_error
= false;
99 static void gen_rtx_next (void);
100 static void write_rtx_next (void);
101 static void open_base_files (void);
102 static void close_output_files (void);
104 /* Report an error at POS, printing MSG. */
107 error_at_line (const struct fileloc
*pos
, const char *msg
, ...)
111 gcc_assert (pos
!= NULL
&& pos
->file
!= NULL
);
114 fprintf (stderr
, "%s:%d: ", get_input_file_name (pos
->file
), pos
->line
);
115 vfprintf (stderr
, msg
, ap
);
116 fputc ('\n', stderr
);
122 /* asprintf, but produces fatal message on out-of-memory. */
124 xasprintf (const char *format
, ...)
130 va_start (ap
, format
);
131 n
= vasprintf (&result
, format
, ap
);
132 if (result
== NULL
|| n
< 0)
133 fatal ("out of memory");
139 /* Input file handling. */
141 /* Table of all input files. */
142 const input_file
**gt_files
;
145 /* A number of places use the name of this "gengtype.c" file for a
146 location for things that we can't rely on the source to define.
147 Make sure we can still use pointer comparison on filenames. */
148 input_file
* this_file
;
149 /* The "system.h" file is likewise specially useful. */
150 input_file
* system_h_file
;
152 /* Vector of per-language directories. */
153 const char **lang_dir_names
;
154 size_t num_lang_dirs
;
156 /* An array of output files suitable for definitions. There is one
157 BASE_FILES entry for each language. */
158 static outf_p
*base_files
;
163 /* Utility debugging function, printing the various type counts within
164 a list of types. Called through the DBGPRINT_COUNT_TYPE macro. */
166 dbgprint_count_type_at (const char *fil
, int lin
, const char *msg
, type_p t
)
168 int nb_types
= 0, nb_scalar
= 0, nb_string
= 0;
169 int nb_struct
= 0, nb_union
= 0, nb_array
= 0, nb_pointer
= 0;
170 int nb_lang_struct
= 0, nb_param_struct
= 0;
171 int nb_user_struct
= 0, nb_undefined
= 0;
173 for (p
= t
; p
; p
= p
->next
)
189 case TYPE_USER_STRUCT
:
201 case TYPE_LANG_STRUCT
:
204 case TYPE_PARAM_STRUCT
:
211 fprintf (stderr
, "\n" "%s:%d: %s: @@%%@@ %d types ::\n",
212 lbasename (fil
), lin
, msg
, nb_types
);
213 if (nb_scalar
> 0 || nb_string
> 0)
214 fprintf (stderr
, "@@%%@@ %d scalars, %d strings\n", nb_scalar
, nb_string
);
215 if (nb_struct
> 0 || nb_union
> 0)
216 fprintf (stderr
, "@@%%@@ %d structs, %d unions\n", nb_struct
, nb_union
);
217 if (nb_pointer
> 0 || nb_array
> 0)
218 fprintf (stderr
, "@@%%@@ %d pointers, %d arrays\n", nb_pointer
, nb_array
);
219 if (nb_lang_struct
> 0 || nb_param_struct
> 0)
220 fprintf (stderr
, "@@%%@@ %d lang_structs, %d param_structs\n",
221 nb_lang_struct
, nb_param_struct
);
222 if (nb_user_struct
> 0)
223 fprintf (stderr
, "@@%%@@ %d user_structs\n", nb_user_struct
);
224 if (nb_undefined
> 0)
225 fprintf (stderr
, "@@%%@@ %d undefined types\n", nb_undefined
);
226 fprintf (stderr
, "\n");
228 #endif /* ENABLE_CHECKING */
230 /* Scan the input file, LIST, and determine how much space we need to
231 store strings in. Also, count the number of language directories
232 and files. The numbers returned are overestimates as they does not
233 consider repeated files. */
235 measure_input_list (FILE *list
)
241 num_gt_files
= plugin_files
? nb_plugin_files
: 0;
242 while ((c
= getc (list
)) != EOF
)
251 /* Add space for a lang_bitmap before the input file name. */
252 n
+= sizeof (lang_bitmap
);
266 /* Read one input line from LIST to HEREP (which is updated). A
267 pointer to the string is returned via LINEP. If it was a language
268 subdirectory in square brackets, strip off the square brackets and
269 return true. Otherwise, leave space before the string for a
270 lang_bitmap, and return false. At EOF, returns false, does not
271 touch *HEREP, and sets *LINEP to NULL. POS is used for
274 read_input_line (FILE *list
, char **herep
, char **linep
, struct fileloc
*pos
)
280 /* Read over whitespace. */
281 while (c
== '\n' || c
== ' ')
291 /* No space for a lang_bitmap is necessary. Discard the '['. */
294 while (c
!= ']' && c
!= '\n' && c
!= EOF
)
303 c
= getc (list
); /* eat what should be a newline */
304 if (c
!= '\n' && c
!= EOF
)
305 error_at_line (pos
, "junk on line after language tag [%s]", line
);
308 error_at_line (pos
, "missing close bracket for language tag [%s",
317 /* Leave space for a lang_bitmap. */
318 memset (here
, 0, sizeof (lang_bitmap
));
319 here
+= sizeof (lang_bitmap
);
326 while (c
!= EOF
&& c
!= '\n');
334 /* Read the list of input files from LIST and compute all of the
335 relevant tables. There is one file per line of the list. At
336 first, all the files on the list are language-generic, but
337 eventually a line will appear which is the name of a language
338 subdirectory in square brackets, like this: [cp]. All subsequent
339 files are specific to that language, until another language
340 subdirectory tag appears. Files can appear more than once, if
341 they apply to more than one language. */
343 read_input_list (const char *listname
)
345 FILE *list
= fopen (listname
, "r");
347 fatal ("cannot open %s: %s", listname
, xstrerror (errno
));
351 size_t bufsz
= measure_input_list (list
);
352 char *buf
= XNEWVEC (char, bufsz
);
354 char *committed
= buf
;
355 char *limit
= buf
+ bufsz
;
360 lang_bitmap curlangs
= (1 << num_lang_dirs
) - 1;
362 epos
.file
= input_file_by_name (listname
);
365 lang_dir_names
= XNEWVEC (const char *, num_lang_dirs
);
366 gt_files
= XNEWVEC (const input_file
*, num_gt_files
);
373 is_language
= read_input_line (list
, &here
, &line
, &epos
);
374 gcc_assert (here
<= limit
);
377 else if (is_language
)
380 gcc_assert (langno
<= num_lang_dirs
);
381 for (i
= 0; i
< langno
; i
++)
382 if (strcmp (lang_dir_names
[i
], line
) == 0)
384 error_at_line (&epos
, "duplicate language tag [%s]",
391 curlangs
= 1 << langno
;
392 lang_dir_names
[langno
++] = line
;
397 input_file
*inpf
= input_file_by_name (line
);
398 gcc_assert (nfiles
<= num_gt_files
);
399 for (i
= 0; i
< nfiles
; i
++)
400 /* Since the input_file-s are uniquely hash-consed, we
401 can just compare pointers! */
402 if (gt_files
[i
] == inpf
)
404 /* Throw away the string we just read, and add the
405 current language to the existing string's bitmap. */
406 lang_bitmap bmap
= get_lang_bitmap (inpf
);
408 error_at_line (&epos
,
409 "file %s specified more than once "
410 "for language %s", line
,
412 0 ? "(all)" : lang_dir_names
[langno
-
416 set_lang_bitmap (inpf
, bmap
);
421 set_lang_bitmap (inpf
, curlangs
);
422 gt_files
[nfiles
++] = inpf
;
425 /* Update the global counts now that we know accurately how many
426 things there are. (We do not bother resizing the arrays down.) */
427 num_lang_dirs
= langno
;
428 /* Add the plugin files if provided. */
432 for (i
= 0; i
< nb_plugin_files
; i
++)
433 gt_files
[nfiles
++] = plugin_files
[i
];
435 num_gt_files
= nfiles
;
438 /* Sanity check: any file that resides in a language subdirectory
439 (e.g. 'cp') ought to belong to the corresponding language.
440 ??? Still true if for instance ObjC++ is enabled and C++ isn't?
441 (Can you even do that? Should you be allowed to?) */
444 for (f
= 0; f
< num_gt_files
; f
++)
446 lang_bitmap bitmap
= get_lang_bitmap (gt_files
[f
]);
447 const char *basename
= get_file_basename (gt_files
[f
]);
448 const char *slashpos
= strchr (basename
, '/');
449 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
450 const char *slashpos2
= strchr (basename
, '\\');
452 if (!slashpos
|| (slashpos2
&& slashpos2
< slashpos
))
453 slashpos
= slashpos2
;
459 for (l
= 0; l
< num_lang_dirs
; l
++)
460 if ((size_t) (slashpos
- basename
) == strlen (lang_dir_names
[l
])
461 && memcmp (basename
, lang_dir_names
[l
],
462 strlen (lang_dir_names
[l
])) == 0)
464 if (!(bitmap
& (1 << l
)))
465 error ("%s is in language directory '%s' but is not "
466 "tagged for that language",
467 basename
, lang_dir_names
[l
]);
475 fatal ("error reading %s: %s", listname
, xstrerror (errno
));
482 /* The one and only TYPE_STRING. */
484 struct type string_type
= {
485 TYPE_STRING
, 0, 0, 0, GC_USED
, {0}
488 /* The two and only TYPE_SCALARs. Their u.scalar_is_char flags are
489 set early in main. */
491 struct type scalar_nonchar
= {
492 TYPE_SCALAR
, 0, 0, 0, GC_USED
, {0}
495 struct type scalar_char
= {
496 TYPE_SCALAR
, 0, 0, 0, GC_USED
, {0}
499 /* Lists of various things. */
501 pair_p typedefs
= NULL
;
502 type_p structures
= NULL
;
503 type_p param_structs
= NULL
;
504 pair_p variables
= NULL
;
506 static type_p
find_param_structure (type_p t
, type_p param
[NUM_PARAM
]);
507 static type_p
adjust_field_tree_exp (type_p t
, options_p opt
);
508 static type_p
adjust_field_rtx_def (type_p t
, options_p opt
);
510 /* Define S as a typedef to T at POS. */
513 do_typedef (const char *s
, type_p t
, struct fileloc
*pos
)
517 /* temporary kludge - gengtype doesn't handle conditionals or
518 macros. Ignore any attempt to typedef CUMULATIVE_ARGS, unless it
519 is coming from this file (main() sets them up with safe dummy
521 if (!strcmp (s
, "CUMULATIVE_ARGS") && pos
->file
!= this_file
)
524 for (p
= typedefs
; p
!= NULL
; p
= p
->next
)
525 if (strcmp (p
->name
, s
) == 0)
527 if (p
->type
!= t
&& strcmp (s
, "result_type") != 0)
529 error_at_line (pos
, "type `%s' previously defined", s
);
530 error_at_line (&p
->line
, "previously defined here");
535 p
= XNEW (struct pair
);
544 /* Define S as a typename of a scalar. Cannot be used to define
545 typedefs of 'char'. Note: is also used for pointer-to-function
546 typedefs (which are therefore not treated as pointers). */
549 do_scalar_typedef (const char *s
, struct fileloc
*pos
)
551 do_typedef (s
, &scalar_nonchar
, pos
);
555 /* Define TYPE_NAME to be a user defined type at location POS. */
558 create_user_defined_type (const char *type_name
, struct fileloc
*pos
)
560 type_p ty
= find_structure (type_name
, TYPE_USER_STRUCT
);
562 /* We might have already seen an incomplete decl of the given type,
563 in which case we won't have yet seen a GTY((user)), and the type will
564 only have kind "TYPE_STRUCT". Mark it as a user struct. */
565 ty
->kind
= TYPE_USER_STRUCT
;
568 ty
->u
.s
.bitmap
= get_lang_bitmap (pos
->file
);
569 do_typedef (type_name
, ty
, pos
);
571 /* If TYPE_NAME specifies a template, create references to the types
572 in the template by pretending that each type is a field of TY.
573 This is needed to make sure that the types referenced by the
574 template are marked as used. */
575 char *str
= xstrdup (type_name
);
576 char *open_bracket
= strchr (str
, '<');
579 /* We only accept simple template declarations (see
580 require_template_declaration), so we only need to parse a
581 comma-separated list of strings, implicitly assumed to
583 char *arg
= open_bracket
+ 1;
584 char *type_id
= strtok (arg
, ",>");
588 /* Create a new field for every type found inside the template
590 const char *field_name
= xstrdup (type_id
);
591 type_p arg_type
= resolve_typedef (field_name
, pos
);
592 fields
= create_field_at (fields
, arg_type
, field_name
, 0, pos
);
593 type_id
= strtok (0, ",>");
596 /* Associate the field list to TY. */
597 ty
->u
.s
.fields
= fields
;
605 /* Given a typedef name S, return its associated type. Return NULL if
606 S is not a registered type name. */
609 type_for_name (const char *s
)
613 /* Special-case support for types within a "gcc::" namespace. Rather
614 than fully-supporting namespaces, simply strip off the "gcc::" prefix
615 where present. This allows us to have GTY roots of this form:
616 extern GTY(()) gcc::some_type *some_ptr;
617 where the autogenerated functions will refer to simply "some_type",
618 where they can be resolved into their namespace. */
619 if (0 == strncmp (s
, "gcc::", 5))
622 for (p
= typedefs
; p
!= NULL
; p
= p
->next
)
623 if (strcmp (p
->name
, s
) == 0)
629 /* Create an undefined type with name S and location POS. Return the
630 newly created type. */
633 create_undefined_type (const char *s
, struct fileloc
*pos
)
635 type_p ty
= find_structure (s
, TYPE_UNDEFINED
);
637 ty
->u
.s
.bitmap
= get_lang_bitmap (pos
->file
);
638 do_typedef (s
, ty
, pos
);
643 /* Return the type previously defined for S. Use POS to report errors. */
646 resolve_typedef (const char *s
, struct fileloc
*pos
)
648 bool is_template_instance
= (strchr (s
, '<') != NULL
);
649 type_p p
= type_for_name (s
);
651 /* If we did not find a typedef registered, generate a TYPE_UNDEFINED
652 type for regular type identifiers. If the type identifier S is a
653 template instantiation, however, we treat it as a user defined
656 FIXME, this is actually a limitation in gengtype. Supporting
657 template types and their instances would require keeping separate
658 track of the basic types definition and its instances. This
659 essentially forces all template classes in GC to be marked
662 p
= (is_template_instance
)
663 ? create_user_defined_type (s
, pos
)
664 : create_undefined_type (s
, pos
);
670 /* Create and return a new structure with tag NAME at POS with fields
671 FIELDS and options O. The KIND of structure must be one of
672 TYPE_STRUCT, TYPE_UNION or TYPE_USER_STRUCT. */
675 new_structure (const char *name
, enum typekind kind
, struct fileloc
*pos
,
676 pair_p fields
, options_p o
)
680 lang_bitmap bitmap
= get_lang_bitmap (pos
->file
);
681 bool isunion
= (kind
== TYPE_UNION
);
683 gcc_assert (union_or_struct_p (kind
));
685 for (si
= structures
; si
!= NULL
; si
= si
->next
)
686 if (strcmp (name
, si
->u
.s
.tag
) == 0 && UNION_P (si
) == isunion
)
689 if (si
->kind
== TYPE_LANG_STRUCT
)
693 for (si
= ls
->u
.s
.lang_struct
; si
!= NULL
; si
= si
->next
)
694 if (si
->u
.s
.bitmap
== bitmap
)
697 else if (si
->u
.s
.line
.file
!= NULL
&& si
->u
.s
.bitmap
!= bitmap
)
701 si
= XCNEW (struct type
);
702 memcpy (si
, ls
, sizeof (struct type
));
703 ls
->kind
= TYPE_LANG_STRUCT
;
704 ls
->u
.s
.lang_struct
= si
;
705 ls
->u
.s
.fields
= NULL
;
707 si
->state_number
= -type_count
;
708 si
->pointer_to
= NULL
;
709 si
->u
.s
.lang_struct
= ls
;
714 if (ls
!= NULL
&& s
== NULL
)
717 s
= XCNEW (struct type
);
718 s
->state_number
= -type_count
;
719 s
->next
= ls
->u
.s
.lang_struct
;
720 ls
->u
.s
.lang_struct
= s
;
721 s
->u
.s
.lang_struct
= ls
;
729 s
= XCNEW (struct type
);
730 s
->state_number
= -type_count
;
731 s
->next
= structures
;
735 if (s
->u
.s
.lang_struct
&& (s
->u
.s
.lang_struct
->u
.s
.bitmap
& bitmap
))
737 error_at_line (pos
, "duplicate definition of '%s %s'",
738 isunion
? "union" : "struct", s
->u
.s
.tag
);
739 error_at_line (&s
->u
.s
.line
, "previous definition here");
745 s
->u
.s
.fields
= fields
;
747 s
->u
.s
.bitmap
= bitmap
;
748 if (s
->u
.s
.lang_struct
)
749 s
->u
.s
.lang_struct
->u
.s
.bitmap
|= bitmap
;
754 /* Return the previously-defined structure or union with tag NAME,
755 or a new empty structure or union if none was defined previously.
756 The KIND of structure must be one of TYPE_STRUCT, TYPE_UNION or
760 find_structure (const char *name
, enum typekind kind
)
763 bool isunion
= (kind
== TYPE_UNION
);
765 gcc_assert (kind
== TYPE_UNDEFINED
|| union_or_struct_p (kind
));
767 for (s
= structures
; s
!= NULL
; s
= s
->next
)
768 if (strcmp (name
, s
->u
.s
.tag
) == 0 && UNION_P (s
) == isunion
)
772 s
= XCNEW (struct type
);
773 s
->next
= structures
;
774 s
->state_number
= -type_count
;
782 /* Return the previously-defined parameterized structure for structure
783 T and parameters PARAM, or a new parameterized empty structure or
784 union if none was defined previously. */
787 find_param_structure (type_p t
, type_p param
[NUM_PARAM
])
791 for (res
= param_structs
; res
; res
= res
->next
)
792 if (res
->u
.param_struct
.stru
== t
793 && memcmp (res
->u
.param_struct
.param
, param
,
794 sizeof (type_p
) * NUM_PARAM
) == 0)
799 res
= XCNEW (struct type
);
800 res
->kind
= TYPE_PARAM_STRUCT
;
801 res
->next
= param_structs
;
802 res
->state_number
= -type_count
;
804 res
->u
.param_struct
.stru
= t
;
805 memcpy (res
->u
.param_struct
.param
, param
, sizeof (type_p
) * NUM_PARAM
);
810 /* Return a scalar type with name NAME. */
813 create_scalar_type (const char *name
)
815 if (!strcmp (name
, "char") || !strcmp (name
, "unsigned char"))
818 return &scalar_nonchar
;
822 /* Return a pointer to T. */
825 create_pointer (type_p t
)
829 type_p r
= XCNEW (struct type
);
831 r
->state_number
= -type_count
;
832 r
->kind
= TYPE_POINTER
;
836 return t
->pointer_to
;
839 /* Return an array of length LEN. */
842 create_array (type_p t
, const char *len
)
847 v
= XCNEW (struct type
);
848 v
->kind
= TYPE_ARRAY
;
849 v
->state_number
= -type_count
;
855 /* Return a string options structure with name NAME and info INFO.
856 NEXT is the next option in the chain. */
858 create_string_option (options_p next
, const char *name
, const char *info
)
860 options_p o
= XNEW (struct options
);
861 o
->kind
= OPTION_STRING
;
864 o
->info
.string
= info
;
868 /* Create a type options structure with name NAME and info INFO. NEXT
869 is the next option in the chain. */
871 create_type_option (options_p next
, const char* name
, type_p info
)
873 options_p o
= XNEW (struct options
);
876 o
->kind
= OPTION_TYPE
;
881 /* Create a nested pointer options structure with name NAME and info
882 INFO. NEXT is the next option in the chain. */
884 create_nested_option (options_p next
, const char* name
,
885 struct nested_ptr_data
* info
)
888 o
= XNEW (struct options
);
891 o
->kind
= OPTION_NESTED
;
892 o
->info
.nested
= info
;
896 /* Return an options structure for a "nested_ptr" option. */
898 create_nested_ptr_option (options_p next
, type_p t
,
899 const char *to
, const char *from
)
901 struct nested_ptr_data
*d
= XNEW (struct nested_ptr_data
);
903 d
->type
= adjust_field_type (t
, 0);
905 d
->convert_from
= from
;
906 return create_nested_option (next
, "nested_ptr", d
);
909 /* Add a variable named S of type T with options O defined at POS,
912 note_variable (const char *s
, type_p t
, options_p o
, struct fileloc
*pos
)
915 n
= XNEW (struct pair
);
924 /* Most-general structure field creator. */
926 create_field_all (pair_p next
, type_p type
, const char *name
, options_p opt
,
927 const input_file
*inpf
, int line
)
931 field
= XNEW (struct pair
);
936 field
->line
.file
= inpf
;
937 field
->line
.line
= line
;
941 /* Create a field that came from the source code we are scanning,
942 i.e. we have a 'struct fileloc', and possibly options; also,
943 adjust_field_type should be called. */
945 create_field_at (pair_p next
, type_p type
, const char *name
, options_p opt
,
948 return create_field_all (next
, adjust_field_type (type
, opt
),
949 name
, opt
, pos
->file
, pos
->line
);
952 /* Create a fake field with the given type and name. NEXT is the next
953 field in the chain. */
954 #define create_field(next,type,name) \
955 create_field_all (next,type,name, 0, this_file, __LINE__)
957 /* Like create_field, but the field is only valid when condition COND
961 create_optional_field_ (pair_p next
, type_p type
, const char *name
,
962 const char *cond
, int line
)
968 /* Create a fake union type with a single nameless field of type TYPE.
969 The field has a tag of "1". This allows us to make the presence
970 of a field of type TYPE depend on some boolean "desc" being true. */
971 union_fields
= create_field (NULL
, type
, "");
973 create_string_option (union_fields
->opt
, "dot", "");
975 create_string_option (union_fields
->opt
, "tag", "1");
977 new_structure (xasprintf ("%s_%d", "fake_union", id
++), TYPE_UNION
,
978 &lexer_line
, union_fields
, NULL
);
980 /* Create the field and give it the new fake union type. Add a "desc"
981 tag that specifies the condition under which the field is valid. */
982 return create_field_all (next
, union_type
, name
,
983 create_string_option (0, "desc", cond
),
987 #define create_optional_field(next,type,name,cond) \
988 create_optional_field_(next,type,name,cond,__LINE__)
990 /* Reverse a linked list of 'struct pair's in place. */
992 nreverse_pairs (pair_p list
)
994 pair_p prev
= 0, p
, next
;
995 for (p
= list
; p
; p
= next
)
1005 /* We don't care how long a CONST_DOUBLE is. */
1006 #define CONST_DOUBLE_FORMAT "ww"
1007 /* We don't want to see codes that are only for generator files. */
1008 #undef GENERATOR_FILE
1012 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) ENUM ,
1018 static const char *const rtx_name
[NUM_RTX_CODE
] = {
1019 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME ,
1024 static const char *const rtx_format
[NUM_RTX_CODE
] = {
1025 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT ,
1030 static int rtx_next_new
[NUM_RTX_CODE
];
1032 /* We also need codes and names for insn notes (not register notes).
1033 Note that we do *not* bias the note values here. */
1036 #define DEF_INSN_NOTE(NAME) NAME,
1037 #include "insn-notes.def"
1038 #undef DEF_INSN_NOTE
1043 /* We must allocate one more entry here, as we use NOTE_INSN_MAX as the
1044 default field for line number notes. */
1045 static const char *const note_insn_name
[NOTE_INSN_MAX
+ 1] = {
1046 #define DEF_INSN_NOTE(NAME) #NAME,
1047 #include "insn-notes.def"
1048 #undef DEF_INSN_NOTE
1051 #undef CONST_DOUBLE_FORMAT
1052 #define GENERATOR_FILE
1054 /* Generate the contents of the rtx_next array. This really doesn't belong
1055 in gengtype at all, but it's needed for adjust_field_rtx_def. */
1061 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
1065 rtx_next_new
[i
] = -1;
1066 if (strncmp (rtx_format
[i
], "iuu", 3) == 0)
1067 rtx_next_new
[i
] = 2;
1068 else if (i
== COND_EXEC
|| i
== SET
|| i
== EXPR_LIST
|| i
== INSN_LIST
)
1069 rtx_next_new
[i
] = 1;
1071 for (k
= strlen (rtx_format
[i
]) - 1; k
>= 0; k
--)
1072 if (rtx_format
[i
][k
] == 'e' || rtx_format
[i
][k
] == 'u')
1073 rtx_next_new
[i
] = k
;
1077 /* Write out the contents of the rtx_next array. */
1079 write_rtx_next (void)
1081 outf_p f
= get_output_file_with_visibility (NULL
);
1086 oprintf (f
, "\n/* Used to implement the RTX_NEXT macro. */\n");
1087 oprintf (f
, "EXPORTED_CONST unsigned char rtx_next[NUM_RTX_CODE] = {\n");
1088 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
1089 if (rtx_next_new
[i
] == -1)
1090 oprintf (f
, " 0,\n");
1093 " RTX_HDR_SIZE + %d * sizeof (rtunion),\n", rtx_next_new
[i
]);
1094 oprintf (f
, "};\n");
1097 /* Handle `special("rtx_def")'. This is a special case for field
1098 `fld' of struct rtx_def, which is an array of unions whose values
1099 are based in a complex way on the type of RTL. */
1102 adjust_field_rtx_def (type_p t
, options_p
ARG_UNUSED (opt
))
1107 type_p rtx_tp
, rtvec_tp
, tree_tp
, mem_attrs_tp
, note_union_tp
, scalar_tp
;
1108 type_p basic_block_tp
, reg_attrs_tp
, constant_tp
, symbol_union_tp
;
1110 if (t
->kind
!= TYPE_UNION
)
1112 error_at_line (&lexer_line
,
1113 "special `rtx_def' must be applied to a union");
1114 return &string_type
;
1117 nodot
= create_string_option (NULL
, "dot", "");
1119 rtx_tp
= create_pointer (find_structure ("rtx_def", TYPE_STRUCT
));
1120 rtvec_tp
= create_pointer (find_structure ("rtvec_def", TYPE_STRUCT
));
1121 tree_tp
= create_pointer (find_structure ("tree_node", TYPE_UNION
));
1122 mem_attrs_tp
= create_pointer (find_structure ("mem_attrs", TYPE_STRUCT
));
1124 create_pointer (find_structure ("reg_attrs", TYPE_STRUCT
));
1126 create_pointer (find_structure ("basic_block_def", TYPE_STRUCT
));
1128 create_pointer (find_structure ("constant_descriptor_rtx", TYPE_STRUCT
));
1129 scalar_tp
= &scalar_nonchar
; /* rtunion int */
1132 pair_p note_flds
= NULL
;
1135 for (c
= 0; c
<= NOTE_INSN_MAX
; c
++)
1140 case NOTE_INSN_DELETED_LABEL
:
1141 case NOTE_INSN_DELETED_DEBUG_LABEL
:
1142 note_flds
= create_field (note_flds
, &string_type
, "rt_str");
1145 case NOTE_INSN_BLOCK_BEG
:
1146 case NOTE_INSN_BLOCK_END
:
1147 note_flds
= create_field (note_flds
, tree_tp
, "rt_tree");
1150 case NOTE_INSN_VAR_LOCATION
:
1151 case NOTE_INSN_CALL_ARG_LOCATION
:
1152 note_flds
= create_field (note_flds
, rtx_tp
, "rt_rtx");
1156 note_flds
= create_field (note_flds
, scalar_tp
, "rt_int");
1159 /* NOTE_INSN_MAX is used as the default field for line
1161 if (c
== NOTE_INSN_MAX
)
1163 create_string_option (nodot
, "default", "");
1166 create_string_option (nodot
, "tag", note_insn_name
[c
]);
1168 note_union_tp
= new_structure ("rtx_def_note_subunion", TYPE_UNION
,
1169 &lexer_line
, note_flds
, NULL
);
1171 /* Create a type to represent the various forms of SYMBOL_REF_DATA. */
1174 sym_flds
= create_field (NULL
, tree_tp
, "rt_tree");
1175 sym_flds
->opt
= create_string_option (nodot
, "default", "");
1176 sym_flds
= create_field (sym_flds
, constant_tp
, "rt_constant");
1177 sym_flds
->opt
= create_string_option (nodot
, "tag", "1");
1178 symbol_union_tp
= new_structure ("rtx_def_symbol_subunion", TYPE_UNION
,
1179 &lexer_line
, sym_flds
, NULL
);
1181 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
1183 pair_p subfields
= NULL
;
1184 size_t aindex
, nmindex
;
1189 for (aindex
= 0; aindex
< strlen (rtx_format
[i
]); aindex
++)
1192 const char *subname
;
1194 switch (rtx_format
[i
][aindex
])
1205 if (i
== MEM
&& aindex
== 1)
1206 t
= mem_attrs_tp
, subname
= "rt_mem";
1207 else if (i
== JUMP_INSN
&& aindex
== 8)
1208 t
= rtx_tp
, subname
= "rt_rtx";
1209 else if (i
== CODE_LABEL
&& aindex
== 5)
1210 t
= scalar_tp
, subname
= "rt_int";
1211 else if (i
== CODE_LABEL
&& aindex
== 4)
1212 t
= rtx_tp
, subname
= "rt_rtx";
1213 else if (i
== LABEL_REF
&& (aindex
== 1 || aindex
== 2))
1214 t
= rtx_tp
, subname
= "rt_rtx";
1215 else if (i
== NOTE
&& aindex
== 4)
1216 t
= note_union_tp
, subname
= "";
1217 else if (i
== NOTE
&& aindex
== 5)
1218 t
= scalar_tp
, subname
= "rt_int";
1219 else if (i
== NOTE
&& aindex
>= 7)
1220 t
= scalar_tp
, subname
= "rt_int";
1221 else if (i
== ADDR_DIFF_VEC
&& aindex
== 4)
1222 t
= scalar_tp
, subname
= "rt_int";
1223 else if (i
== VALUE
&& aindex
== 0)
1224 t
= scalar_tp
, subname
= "rt_int";
1225 else if (i
== DEBUG_EXPR
&& aindex
== 0)
1226 t
= tree_tp
, subname
= "rt_tree";
1227 else if (i
== REG
&& aindex
== 1)
1228 t
= scalar_tp
, subname
= "rt_int";
1229 else if (i
== REG
&& aindex
== 2)
1230 t
= reg_attrs_tp
, subname
= "rt_reg";
1231 else if (i
== SCRATCH
&& aindex
== 0)
1232 t
= scalar_tp
, subname
= "rt_int";
1233 else if (i
== SYMBOL_REF
&& aindex
== 1)
1234 t
= scalar_tp
, subname
= "rt_int";
1235 else if (i
== SYMBOL_REF
&& aindex
== 2)
1236 t
= symbol_union_tp
, subname
= "";
1237 else if (i
== JUMP_TABLE_DATA
&& aindex
>= 5)
1238 t
= scalar_tp
, subname
= "rt_int";
1239 else if (i
== BARRIER
&& aindex
>= 3)
1240 t
= scalar_tp
, subname
= "rt_int";
1241 else if (i
== ENTRY_VALUE
&& aindex
== 0)
1242 t
= rtx_tp
, subname
= "rt_rtx";
1247 "rtx type `%s' has `0' in position %lu, can't handle",
1248 rtx_name
[i
], (unsigned long) aindex
);
1270 subname
= "rt_rtvec";
1275 subname
= "rt_tree";
1286 "rtx type `%s' has `%c' in position %lu, can't handle",
1287 rtx_name
[i
], rtx_format
[i
][aindex
],
1288 (unsigned long) aindex
);
1294 subfields
= create_field (subfields
, t
,
1295 xasprintf (".fld[%lu].%s",
1296 (unsigned long) aindex
,
1298 subfields
->opt
= nodot
;
1299 if (t
== note_union_tp
)
1301 create_string_option (subfields
->opt
, "desc",
1303 if (t
== symbol_union_tp
)
1305 create_string_option (subfields
->opt
, "desc",
1306 "CONSTANT_POOL_ADDRESS_P (&%0)");
1309 if (i
== SYMBOL_REF
)
1311 /* Add the "block_sym" field if SYMBOL_REF_HAS_BLOCK_INFO_P
1313 type_p field_tp
= find_structure ("block_symbol", TYPE_STRUCT
);
1315 = create_optional_field (subfields
, field_tp
, "block_sym",
1316 "SYMBOL_REF_HAS_BLOCK_INFO_P (&%0)");
1319 sname
= xasprintf ("rtx_def_%s", rtx_name
[i
]);
1320 substruct
= new_structure (sname
, TYPE_STRUCT
, &lexer_line
, subfields
,
1323 ftag
= xstrdup (rtx_name
[i
]);
1324 for (nmindex
= 0; nmindex
< strlen (ftag
); nmindex
++)
1325 ftag
[nmindex
] = TOUPPER (ftag
[nmindex
]);
1326 flds
= create_field (flds
, substruct
, "");
1327 flds
->opt
= create_string_option (nodot
, "tag", ftag
);
1329 return new_structure ("rtx_def_subunion", TYPE_UNION
, &lexer_line
, flds
,
1333 /* Handle `special("tree_exp")'. This is a special case for
1334 field `operands' of struct tree_exp, which although it claims to contain
1335 pointers to trees, actually sometimes contains pointers to RTL too.
1336 Passed T, the old type of the field, and OPT its options. Returns
1337 a new type for the field. */
1340 adjust_field_tree_exp (type_p t
, options_p opt ATTRIBUTE_UNUSED
)
1345 if (t
->kind
!= TYPE_ARRAY
)
1347 error_at_line (&lexer_line
,
1348 "special `tree_exp' must be applied to an array");
1349 return &string_type
;
1352 nodot
= create_string_option (NULL
, "dot", "");
1354 flds
= create_field (NULL
, t
, "");
1355 flds
->opt
= create_string_option (nodot
, "length",
1356 "TREE_OPERAND_LENGTH ((tree) &%0)");
1357 flds
->opt
= create_string_option (flds
->opt
, "default", "");
1359 return new_structure ("tree_exp_subunion", TYPE_UNION
, &lexer_line
, flds
,
1363 /* Perform any special processing on a type T, about to become the type
1364 of a field. Return the appropriate type for the field.
1366 - Converts pointer-to-char, with no length parameter, to TYPE_STRING;
1367 - Similarly for arrays of pointer-to-char;
1368 - Converts structures for which a parameter is provided to
1370 - Handles "special" options.
1374 adjust_field_type (type_p t
, options_p opt
)
1377 const int pointer_p
= t
->kind
== TYPE_POINTER
;
1378 type_p params
[NUM_PARAM
];
1382 for (i
= 0; i
< NUM_PARAM
; i
++)
1385 for (; opt
; opt
= opt
->next
)
1386 if (strcmp (opt
->name
, "length") == 0)
1389 error_at_line (&lexer_line
, "duplicate `%s' option", opt
->name
);
1390 if (t
->u
.p
->kind
== TYPE_SCALAR
|| t
->u
.p
->kind
== TYPE_STRING
)
1392 error_at_line (&lexer_line
,
1393 "option `%s' may not be applied to "
1394 "arrays of atomic types", opt
->name
);
1398 else if ((strcmp (opt
->name
, "param_is") == 0
1399 || (strncmp (opt
->name
, "param", 5) == 0
1400 && ISDIGIT (opt
->name
[5])
1401 && strcmp (opt
->name
+ 6, "_is") == 0))
1402 && opt
->kind
== OPTION_TYPE
)
1404 int num
= ISDIGIT (opt
->name
[5]) ? opt
->name
[5] - '0' : 0;
1406 if (!union_or_struct_p (t
)
1407 && (t
->kind
!= TYPE_POINTER
|| !union_or_struct_p (t
->u
.p
)))
1409 error_at_line (&lexer_line
,
1410 "option `%s' may only be applied to structures or structure pointers",
1416 if (params
[num
] != NULL
)
1417 error_at_line (&lexer_line
, "duplicate `%s' option", opt
->name
);
1418 if (!ISDIGIT (opt
->name
[5]))
1419 params
[num
] = create_pointer (opt
->info
.type
);
1421 params
[num
] = opt
->info
.type
;
1423 else if (strcmp (opt
->name
, "special") == 0
1424 && opt
->kind
== OPTION_STRING
)
1426 const char *special_name
= opt
->info
.string
;
1427 if (strcmp (special_name
, "tree_exp") == 0)
1428 t
= adjust_field_tree_exp (t
, opt
);
1429 else if (strcmp (special_name
, "rtx_def") == 0)
1430 t
= adjust_field_rtx_def (t
, opt
);
1432 error_at_line (&lexer_line
, "unknown special `%s'", special_name
);
1441 realt
= find_param_structure (t
, params
);
1442 t
= pointer_p
? create_pointer (realt
) : realt
;
1446 && pointer_p
&& t
->u
.p
->kind
== TYPE_SCALAR
&& t
->u
.p
->u
.scalar_is_char
)
1447 return &string_type
;
1448 if (t
->kind
== TYPE_ARRAY
&& t
->u
.a
.p
->kind
== TYPE_POINTER
1449 && t
->u
.a
.p
->u
.p
->kind
== TYPE_SCALAR
1450 && t
->u
.a
.p
->u
.p
->u
.scalar_is_char
)
1451 return create_array (&string_type
, t
->u
.a
.len
);
1457 static void set_gc_used_type (type_p
, enum gc_used_enum
, type_p
*,
1459 static void set_gc_used (pair_p
);
1461 /* Handle OPT for set_gc_used_type. */
1464 process_gc_options (options_p opt
, enum gc_used_enum level
, int *maybe_undef
,
1465 int *pass_param
, int *length
, int *skip
,
1469 for (o
= opt
; o
; o
= o
->next
)
1470 if (strcmp (o
->name
, "ptr_alias") == 0 && level
== GC_POINTED_TO
1471 && o
->kind
== OPTION_TYPE
)
1472 set_gc_used_type (o
->info
.type
,
1473 GC_POINTED_TO
, NULL
);
1474 else if (strcmp (o
->name
, "maybe_undef") == 0)
1476 else if (strcmp (o
->name
, "use_params") == 0)
1478 else if (strcmp (o
->name
, "length") == 0)
1480 else if (strcmp (o
->name
, "skip") == 0)
1482 else if (strcmp (o
->name
, "nested_ptr") == 0
1483 && o
->kind
== OPTION_NESTED
)
1484 *nested_ptr
= ((const struct nested_ptr_data
*) o
->info
.nested
)->type
;
1488 /* Set the gc_used field of T to LEVEL, and handle the types it references.
1490 If ALLOWED_UNDEFINED_TYPES is true, types of kind TYPE_UNDEFINED
1491 are set to GC_UNUSED. Otherwise, an error is emitted for
1492 TYPE_UNDEFINED types. This is used to support user-defined
1493 template types with non-type arguments.
1495 For instance, when we parse a template type with enum arguments
1496 (e.g. MyType<AnotherType, EnumValue>), the parser created two
1497 artificial fields for 'MyType', one for 'AnotherType', the other
1498 one for 'EnumValue'.
1500 At the time that we parse this type we don't know that 'EnumValue'
1501 is really an enum value, so the parser creates a TYPE_UNDEFINED
1502 type for it. Since 'EnumValue' is never resolved to a known
1503 structure, it will stay with TYPE_UNDEFINED.
1505 Since 'MyType' is a TYPE_USER_STRUCT, we can simply ignore
1506 'EnumValue'. Generating marking code for it would cause
1507 compilation failures since the marking routines assumes that
1508 'EnumValue' is a type. */
1511 set_gc_used_type (type_p t
, enum gc_used_enum level
, type_p param
[NUM_PARAM
],
1512 bool allow_undefined_types
)
1514 if (t
->gc_used
>= level
)
1523 case TYPE_USER_STRUCT
:
1528 bool allow_undefined_field_types
= (t
->kind
== TYPE_USER_STRUCT
);
1530 process_gc_options (t
->u
.s
.opt
, level
, &dummy
, &dummy
, &dummy
, &dummy
,
1533 for (f
= t
->u
.s
.fields
; f
; f
= f
->next
)
1535 int maybe_undef
= 0;
1539 type_p nested_ptr
= NULL
;
1540 process_gc_options (f
->opt
, level
, &maybe_undef
, &pass_param
,
1541 &length
, &skip
, &nested_ptr
);
1543 if (nested_ptr
&& f
->type
->kind
== TYPE_POINTER
)
1544 set_gc_used_type (nested_ptr
, GC_POINTED_TO
,
1545 pass_param
? param
: NULL
);
1546 else if (length
&& f
->type
->kind
== TYPE_POINTER
)
1547 set_gc_used_type (f
->type
->u
.p
, GC_USED
, NULL
);
1548 else if (maybe_undef
&& f
->type
->kind
== TYPE_POINTER
)
1549 set_gc_used_type (f
->type
->u
.p
, GC_MAYBE_POINTED_TO
, NULL
);
1550 else if (pass_param
&& f
->type
->kind
== TYPE_POINTER
&& param
)
1551 set_gc_used_type (find_param_structure (f
->type
->u
.p
, param
),
1552 GC_POINTED_TO
, NULL
);
1554 ; /* target type is not used through this field */
1556 set_gc_used_type (f
->type
, GC_USED
, pass_param
? param
: NULL
,
1557 allow_undefined_field_types
);
1562 case TYPE_UNDEFINED
:
1563 if (level
> GC_UNUSED
)
1565 if (!allow_undefined_types
)
1566 error_at_line (&t
->u
.s
.line
, "undefined type `%s'", t
->u
.s
.tag
);
1567 t
->gc_used
= GC_UNUSED
;
1572 set_gc_used_type (t
->u
.p
, GC_POINTED_TO
, NULL
);
1576 set_gc_used_type (t
->u
.a
.p
, GC_USED
, param
);
1579 case TYPE_LANG_STRUCT
:
1580 for (t
= t
->u
.s
.lang_struct
; t
; t
= t
->next
)
1581 set_gc_used_type (t
, level
, param
);
1584 case TYPE_PARAM_STRUCT
:
1587 for (i
= 0; i
< NUM_PARAM
; i
++)
1588 if (t
->u
.param_struct
.param
[i
] != 0)
1589 set_gc_used_type (t
->u
.param_struct
.param
[i
], GC_USED
, NULL
);
1591 if (t
->u
.param_struct
.stru
->gc_used
== GC_POINTED_TO
)
1592 level
= GC_POINTED_TO
;
1595 t
->u
.param_struct
.stru
->gc_used
= GC_UNUSED
;
1596 set_gc_used_type (t
->u
.param_struct
.stru
, level
,
1597 t
->u
.param_struct
.param
);
1605 /* Set the gc_used fields of all the types pointed to by VARIABLES. */
1608 set_gc_used (pair_p variables
)
1612 for (p
= variables
; p
; p
= p
->next
)
1614 set_gc_used_type (p
->type
, GC_USED
, NULL
);
1617 if (verbosity_level
>= 2)
1618 printf ("%s used %d GTY-ed variables\n", progname
, nbvars
);
1621 /* File mapping routines. For each input file, there is one output .c file
1622 (but some output files have many input files), and there is one .h file
1623 for the whole build. */
1625 /* Output file handling. */
1627 /* Create and return an outf_p for a new file for NAME, to be called
1631 create_file (const char *name
, const char *oname
)
1633 static const char *const hdr
[] = {
1634 " Copyright (C) 2004-2013 Free Software Foundation, Inc.\n",
1636 "This file is part of GCC.\n",
1638 "GCC is free software; you can redistribute it and/or modify it under\n",
1639 "the terms of the GNU General Public License as published by the Free\n",
1640 "Software Foundation; either version 3, or (at your option) any later\n",
1643 "GCC is distributed in the hope that it will be useful, but WITHOUT ANY\n",
1644 "WARRANTY; without even the implied warranty of MERCHANTABILITY or\n",
1645 "FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n",
1646 "for more details.\n",
1648 "You should have received a copy of the GNU General Public License\n",
1649 "along with GCC; see the file COPYING3. If not see\n",
1650 "<http://www.gnu.org/licenses/>. */\n",
1652 "/* This file is machine generated. Do not edit. */\n"
1657 gcc_assert (name
!= NULL
);
1658 gcc_assert (oname
!= NULL
);
1659 f
= XCNEW (struct outf
);
1660 f
->next
= output_files
;
1664 oprintf (f
, "/* Type information for %s.\n", name
);
1665 for (i
= 0; i
< ARRAY_SIZE (hdr
); i
++)
1666 oprintf (f
, "%s", hdr
[i
]);
1670 /* Print, like fprintf, to O.
1671 N.B. You might think this could be implemented more efficiently
1672 with vsnprintf(). Unfortunately, there are C libraries that
1673 provide that function but without the C99 semantics for its return
1674 value, making it impossible to know how much space is required. */
1676 oprintf (outf_p o
, const char *format
, ...)
1682 /* In plugin mode, the O could be a NULL pointer, so avoid crashing
1687 va_start (ap
, format
);
1688 slength
= vasprintf (&s
, format
, ap
);
1689 if (s
== NULL
|| (int) slength
< 0)
1690 fatal ("out of memory");
1693 if (o
->bufused
+ slength
> o
->buflength
)
1695 size_t new_len
= o
->buflength
;
1702 while (o
->bufused
+ slength
>= new_len
);
1703 o
->buf
= XRESIZEVEC (char, o
->buf
, new_len
);
1704 o
->buflength
= new_len
;
1706 memcpy (o
->buf
+ o
->bufused
, s
, slength
);
1707 o
->bufused
+= slength
;
1711 /* Open the global header file and the language-specific header files. */
1714 open_base_files (void)
1718 if (nb_plugin_files
> 0 && plugin_files
)
1721 header_file
= create_file ("GCC", "gtype-desc.h");
1723 base_files
= XNEWVEC (outf_p
, num_lang_dirs
);
1725 for (i
= 0; i
< num_lang_dirs
; i
++)
1726 base_files
[i
] = create_file (lang_dir_names
[i
],
1727 xasprintf ("gtype-%s.h", lang_dir_names
[i
]));
1729 /* gtype-desc.c is a little special, so we create it here. */
1731 /* The order of files here matters very much. */
1732 static const char *const ifiles
[] = {
1733 "config.h", "system.h", "coretypes.h", "tm.h",
1734 "hashtab.h", "splay-tree.h", "obstack.h", "bitmap.h", "input.h",
1735 "tree.h", "rtl.h", "wide-int.h", "function.h", "insn-config.h", "expr.h",
1736 "hard-reg-set.h", "basic-block.h", "cselib.h", "insn-addr.h",
1737 "optabs.h", "libfuncs.h", "debug.h", "ggc.h", "cgraph.h",
1738 "tree-ssa.h", "reload.h", "cpp-id-data.h", "tree-chrec.h",
1739 "except.h", "output.h", "gimple.h", "cfgloop.h",
1740 "target.h", "ipa-prop.h", "lto-streamer.h", "target-globals.h",
1741 "ipa-inline.h", "dwarf2out.h", NULL
1743 const char *const *ifp
;
1744 outf_p gtype_desc_c
;
1746 gtype_desc_c
= create_file ("GCC", "gtype-desc.c");
1747 for (ifp
= ifiles
; *ifp
; ifp
++)
1748 oprintf (gtype_desc_c
, "#include \"%s\"\n", *ifp
);
1750 /* Make sure we handle "cfun" specially. */
1751 oprintf (gtype_desc_c
, "\n/* See definition in function.h. */\n");
1752 oprintf (gtype_desc_c
, "#undef cfun\n");
1754 oprintf (gtype_desc_c
,
1756 "/* Types with a \"gcc::\" namespace have it stripped\n"
1757 " during gengtype parsing. Provide a \"using\" directive\n"
1758 " to ensure that the fully-qualified types are found. */\n"
1759 "using namespace gcc;\n");
1763 /* For INPF an input file, return the real basename of INPF, with all
1764 the directory components skipped. */
1767 get_file_realbasename (const input_file
*inpf
)
1769 return lbasename (get_input_file_name (inpf
));
1772 /* For INPF a filename, return the relative path to INPF from
1773 $(srcdir) if the latter is a prefix in INPF, NULL otherwise. */
1776 get_file_srcdir_relative_path (const input_file
*inpf
)
1778 const char *f
= get_input_file_name (inpf
);
1779 if (strlen (f
) > srcdir_len
1780 && IS_DIR_SEPARATOR (f
[srcdir_len
])
1781 && strncmp (f
, srcdir
, srcdir_len
) == 0)
1782 return f
+ srcdir_len
+ 1;
1787 /* For INPF an input_file, return the relative path to INPF from
1788 $(srcdir) if the latter is a prefix in INPF, or the real basename
1789 of INPF otherwise. */
1792 get_file_basename (const input_file
*inpf
)
1794 const char *srcdir_path
= get_file_srcdir_relative_path (inpf
);
1796 return (srcdir_path
!= NULL
) ? srcdir_path
: get_file_realbasename (inpf
);
1799 /* For F a filename, return the lang_dir_names relative index of the language
1800 directory that is a prefix in F, if any, -1 otherwise. */
1803 get_prefix_langdir_index (const char *f
)
1805 size_t f_len
= strlen (f
);
1808 for (lang_index
= 0; lang_index
< num_lang_dirs
; lang_index
++)
1810 const char *langdir
= lang_dir_names
[lang_index
];
1811 size_t langdir_len
= strlen (langdir
);
1813 if (f_len
> langdir_len
1814 && IS_DIR_SEPARATOR (f
[langdir_len
])
1815 && memcmp (f
, langdir
, langdir_len
) == 0)
1822 /* For INPF an input file, return the name of language directory where
1823 F is located, if any, NULL otherwise. */
1826 get_file_langdir (const input_file
*inpf
)
1828 /* Get the relative path to INPF from $(srcdir) and find the
1829 language by comparing the prefix with language directory names.
1830 If INPF is not even srcdir relative, no point in looking
1834 const char *srcdir_relative_path
= get_file_srcdir_relative_path (inpf
);
1837 if (!srcdir_relative_path
)
1840 lang_index
= get_prefix_langdir_index (srcdir_relative_path
);
1841 if (lang_index
< 0 && strncmp (srcdir_relative_path
, "c-family", 8) == 0)
1843 else if (lang_index
>= 0)
1844 r
= lang_dir_names
[lang_index
];
1851 /* The gt- output file name for INPF. */
1854 get_file_gtfilename (const input_file
*inpf
)
1856 /* Cook up an initial version of the gt- file name from the file real
1857 basename and the language name, if any. */
1859 const char *basename
= get_file_realbasename (inpf
);
1860 const char *langdir
= get_file_langdir (inpf
);
1863 (langdir
? xasprintf ("gt-%s-%s", langdir
, basename
)
1864 : xasprintf ("gt-%s", basename
));
1866 /* Then replace all non alphanumerics characters by '-' and change the
1867 extension to ".h". We expect the input filename extension was at least
1868 one character long. */
1872 for (; *s
!= '.'; s
++)
1873 if (!ISALNUM (*s
) && *s
!= '-')
1876 memcpy (s
, ".h", sizeof (".h"));
1881 /* Each input_file has its associated output file outf_p. The
1882 association is computed by the function
1883 get_output_file_with_visibility. The associated file is cached
1884 inside input_file in its inpoutf field, so is really computed only
1885 once. Associated output file paths (i.e. output_name-s) are
1886 computed by a rule based regexp machinery, using the files_rules
1887 array of struct file_rule_st. A for_name is also computed, giving
1888 the source file name for which the output_file is generated; it is
1889 often the last component of the input_file path. */
1893 Regexpr machinery to compute the output_name and for_name-s of each
1894 input_file. We have a sequence of file rules which gives the POSIX
1895 extended regular expression to match an input file path, and two
1896 transformed strings for the corresponding output_name and the
1897 corresponding for_name. The transformed string contain dollars: $0
1898 is replaced by the entire match, $1 is replaced by the substring
1899 matching the first parenthesis in the regexp, etc. And $$ is replaced
1900 by a single verbatim dollar. The rule order is important. The
1901 general case is last, and the particular cases should come before.
1902 An action routine can, when needed, update the out_name & for_name
1903 and/or return the appropriate output file. It is invoked only when a
1904 rule is triggered. When a rule is triggered, the output_name and
1905 for_name are computed using their transform string in while $$, $0,
1906 $1, ... are suitably replaced. If there is an action, it is called.
1907 In some few cases, the action can directly return the outf_p, but
1908 usually it just updates the output_name and for_name so should free
1909 them before replacing them. The get_output_file_with_visibility
1910 function creates an outf_p only once per each output_name, so it
1911 scans the output_files list for previously seen output file names.
1914 /* Signature of actions in file rules. */
1915 typedef outf_p (frul_actionrout_t
) (input_file
*, char**, char**);
1918 struct file_rule_st
{
1919 const char* frul_srcexpr
; /* Source string for regexp. */
1920 int frul_rflags
; /* Flags passed to regcomp, usually
1922 regex_t
* frul_re
; /* Compiled regular expression
1923 obtained by regcomp. */
1924 const char* frul_tr_out
; /* Transformation string for making
1925 * the output_name, with $1 ... $9 for
1926 * subpatterns and $0 for the whole
1927 * matched filename. */
1928 const char* frul_tr_for
; /* Tranformation string for making the
1930 frul_actionrout_t
* frul_action
; /* The action, if non null, is
1931 * called once the rule matches, on
1932 * the transformed out_name &
1933 * for_name. It could change them
1934 * and/or give the output file. */
1937 /* File rule action handling *.h files. */
1938 static outf_p
header_dot_h_frul (input_file
*, char**, char**);
1940 /* File rule action handling *.c files. */
1941 static outf_p
source_dot_c_frul (input_file
*, char**, char**);
1943 #define NULL_REGEX (regex_t*)0
1945 /* The prefix in our regexp-s matching the directory. */
1946 #define DIR_PREFIX_REGEX "^(([^/]*/)*)"
1948 #define NULL_FRULACT (frul_actionrout_t*)0
1950 /* The array of our rules governing file name generation. Rules order
1951 matters, so change with extreme care! */
1953 struct file_rule_st files_rules
[] = {
1954 /* The general rule assumes that files in subdirectories belong to a
1955 particular front-end, and files not in subdirectories are shared.
1956 The following rules deal with exceptions - files that are in
1957 subdirectories and yet are shared, and files that are top-level,
1958 but are not shared. */
1960 /* the c-family/ source directory is special. */
1961 { DIR_PREFIX_REGEX
"c-family/([[:alnum:]_-]*)\\.c$",
1962 REG_EXTENDED
, NULL_REGEX
,
1963 "gt-c-family-$3.h", "c-family/$3.c", NULL_FRULACT
},
1965 { DIR_PREFIX_REGEX
"c-family/([[:alnum:]_-]*)\\.h$",
1966 REG_EXTENDED
, NULL_REGEX
,
1967 "gt-c-family-$3.h", "c-family/$3.h", NULL_FRULACT
},
1969 /* Both c-lang.h & c-tree.h gives gt-c-c-decl.h for c-decl.c ! */
1970 { DIR_PREFIX_REGEX
"c/c-lang\\.h$",
1971 REG_EXTENDED
, NULL_REGEX
, "gt-c-c-decl.h", "c/c-decl.c", NULL_FRULACT
},
1973 { DIR_PREFIX_REGEX
"c/c-tree\\.h$",
1974 REG_EXTENDED
, NULL_REGEX
, "gt-c-c-decl.h", "c/c-decl.c", NULL_FRULACT
},
1976 /* cp/cp-tree.h gives gt-cp-tree.h for cp/tree.c ! */
1977 { DIR_PREFIX_REGEX
"cp/cp-tree\\.h$",
1978 REG_EXTENDED
, NULL_REGEX
,
1979 "gt-cp-tree.h", "cp/tree.c", NULL_FRULACT
},
1981 /* cp/decl.h & cp/decl.c gives gt-cp-decl.h for cp/decl.c ! */
1982 { DIR_PREFIX_REGEX
"cp/decl\\.[ch]$",
1983 REG_EXTENDED
, NULL_REGEX
,
1984 "gt-cp-decl.h", "cp/decl.c", NULL_FRULACT
},
1986 /* cp/name-lookup.h gives gt-cp-name-lookup.h for cp/name-lookup.c ! */
1987 { DIR_PREFIX_REGEX
"cp/name-lookup\\.h$",
1988 REG_EXTENDED
, NULL_REGEX
,
1989 "gt-cp-name-lookup.h", "cp/name-lookup.c", NULL_FRULACT
},
1991 /* cp/parser.h gives gt-cp-parser.h for cp/parser.c ! */
1992 { DIR_PREFIX_REGEX
"cp/parser\\.h$",
1993 REG_EXTENDED
, NULL_REGEX
,
1994 "gt-cp-parser.h", "cp/parser.c", NULL_FRULACT
},
1996 /* objc/objc-act.h gives gt-objc-objc-act.h for objc/objc-act.c ! */
1997 { DIR_PREFIX_REGEX
"objc/objc-act\\.h$",
1998 REG_EXTENDED
, NULL_REGEX
,
1999 "gt-objc-objc-act.h", "objc/objc-act.c", NULL_FRULACT
},
2001 /* objc/objc-map.h gives gt-objc-objc-map.h for objc/objc-map.c ! */
2002 { DIR_PREFIX_REGEX
"objc/objc-map\\.h$",
2003 REG_EXTENDED
, NULL_REGEX
,
2004 "gt-objc-objc-map.h", "objc/objc-map.c", NULL_FRULACT
},
2006 /* General cases. For header *.h and source *.c or *.cc files, we
2007 * need special actions to handle the language. */
2009 /* Source *.c files are using get_file_gtfilename to compute their
2010 output_name and get_file_basename to compute their for_name
2011 through the source_dot_c_frul action. */
2012 { DIR_PREFIX_REGEX
"([[:alnum:]_-]*)\\.c$",
2013 REG_EXTENDED
, NULL_REGEX
, "gt-$3.h", "$3.c", source_dot_c_frul
},
2015 /* Source *.cc files are using get_file_gtfilename to compute their
2016 output_name and get_file_basename to compute their for_name
2017 through the source_dot_c_frul action. */
2018 { DIR_PREFIX_REGEX
"([[:alnum:]_-]*)\\.cc$",
2019 REG_EXTENDED
, NULL_REGEX
, "gt-$3.h", "$3.cc", source_dot_c_frul
},
2021 /* Common header files get "gtype-desc.c" as their output_name,
2022 * while language specific header files are handled specially. So
2023 * we need the header_dot_h_frul action. */
2024 { DIR_PREFIX_REGEX
"([[:alnum:]_-]*)\\.h$",
2025 REG_EXTENDED
, NULL_REGEX
, "gt-$3.h", "$3.h", header_dot_h_frul
},
2027 { DIR_PREFIX_REGEX
"([[:alnum:]_-]*)\\.in$",
2028 REG_EXTENDED
, NULL_REGEX
, "gt-$3.h", "$3.in", NULL_FRULACT
},
2030 /* Mandatory null last entry signaling end of rules. */
2031 {NULL
, 0, NULL_REGEX
, NULL
, NULL
, NULL_FRULACT
}
2034 /* Special file rules action for handling *.h header files. It gives
2035 "gtype-desc.c" for common headers and corresponding output
2036 files for language-specific header files. */
2038 header_dot_h_frul (input_file
* inpf
, char**poutname
,
2039 char**pforname ATTRIBUTE_UNUSED
)
2041 const char *basename
= 0;
2043 DBGPRINTF ("inpf %p inpname %s outname %s forname %s",
2044 (void*) inpf
, get_input_file_name (inpf
),
2045 *poutname
, *pforname
);
2046 basename
= get_file_basename (inpf
);
2047 lang_index
= get_prefix_langdir_index (basename
);
2048 DBGPRINTF ("basename %s lang_index %d", basename
, lang_index
);
2050 if (lang_index
>= 0)
2052 /* The header is language specific. Given output_name &
2053 for_name remains unchanged. The base_files array gives the
2055 DBGPRINTF ("header_dot_h found language specific @ %p '%s'",
2056 (void*) base_files
[lang_index
],
2057 (base_files
[lang_index
])->name
);
2058 return base_files
[lang_index
];
2062 /* The header is common to all front-end languages. So
2063 output_name is "gtype-desc.c" file. The calling function
2064 get_output_file_with_visibility will find its outf_p. */
2066 *poutname
= xstrdup ("gtype-desc.c");
2067 DBGPRINTF ("special 'gtype-desc.c' for inpname %s",
2068 get_input_file_name (inpf
));
2074 /* Special file rules action for handling *.c source files using
2075 * get_file_gtfilename to compute their output_name and
2076 * get_file_basename to compute their for_name. The output_name is
2077 * gt-<LANG>-<BASE>.h for language specific source files, and
2078 * gt-<BASE>.h for common source files. */
2080 source_dot_c_frul (input_file
* inpf
, char**poutname
, char**pforname
)
2082 char *newbasename
= CONST_CAST (char*, get_file_basename (inpf
));
2083 char *newoutname
= CONST_CAST (char*, get_file_gtfilename (inpf
));
2084 DBGPRINTF ("inpf %p inpname %s original outname %s forname %s",
2085 (void*) inpf
, get_input_file_name (inpf
),
2086 *poutname
, *pforname
);
2087 DBGPRINTF ("newoutname %s", newoutname
);
2088 DBGPRINTF ("newbasename %s", newbasename
);
2091 *poutname
= newoutname
;
2092 *pforname
= newbasename
;
2096 /* Utility function for get_output_file_with_visibility which returns
2097 * a malloc-ed substituted string using TRS on matching of the FILNAM
2098 * file name, using the PMATCH array. */
2100 matching_file_name_substitute (const char *filnam
, regmatch_t pmatch
[10],
2103 struct obstack str_obstack
;
2105 char *rawstr
= NULL
;
2106 const char *pt
= NULL
;
2107 DBGPRINTF ("filnam %s", filnam
);
2108 obstack_init (&str_obstack
);
2109 for (pt
= trs
; *pt
; pt
++) {
2115 /* A double dollar $$ is substituted by a single verbatim
2116 dollar, but who really uses dollar signs in file
2118 obstack_1grow (&str_obstack
, '$');
2120 else if (ISDIGIT (pt
[1]))
2122 /* Handle $0 $1 ... $9 by appropriate substitution. */
2123 int dolnum
= pt
[1] - '0';
2124 int so
= pmatch
[dolnum
].rm_so
;
2125 int eo
= pmatch
[dolnum
].rm_eo
;
2126 DBGPRINTF ("so=%d eo=%d dolnum=%d", so
, eo
, dolnum
);
2127 if (so
>=0 && eo
>=so
)
2128 obstack_grow (&str_obstack
, filnam
+ so
, eo
- so
);
2132 /* This can happen only when files_rules is buggy! */
2135 /* Always skip the character after the dollar. */
2139 obstack_1grow (&str_obstack
, c
);
2141 obstack_1grow (&str_obstack
, '\0');
2142 rawstr
= XOBFINISH (&str_obstack
, char *);
2143 str
= xstrdup (rawstr
);
2144 obstack_free (&str_obstack
, NULL
);
2145 DBGPRINTF ("matched replacement %s", str
);
2151 /* An output file, suitable for definitions, that can see declarations
2152 made in INPF and is linked into every language that uses INPF.
2153 Since the result is cached inside INPF, that argument cannot be
2154 declared constant, but is "almost" constant. */
2157 get_output_file_with_visibility (input_file
*inpf
)
2160 char *for_name
= NULL
;
2161 char *output_name
= NULL
;
2162 const char* inpfname
;
2164 /* This can happen when we need a file with visibility on a
2165 structure that we've never seen. We have to just hope that it's
2166 globally visible. */
2168 inpf
= system_h_file
;
2170 /* The result is cached in INPF, so return it if already known. */
2172 return inpf
->inpoutf
;
2174 /* In plugin mode, return NULL unless the input_file is one of the
2179 for (i
= 0; i
< nb_plugin_files
; i
++)
2180 if (inpf
== plugin_files
[i
])
2182 inpf
->inpoutf
= plugin_output
;
2183 return plugin_output
;
2189 inpfname
= get_input_file_name (inpf
);
2191 /* Try each rule in sequence in files_rules until one is triggered. */
2194 DBGPRINTF ("passing input file @ %p named %s through the files_rules",
2195 (void*) inpf
, inpfname
);
2197 for (; files_rules
[rulix
].frul_srcexpr
!= NULL
; rulix
++)
2199 DBGPRINTF ("rulix#%d srcexpr %s",
2200 rulix
, files_rules
[rulix
].frul_srcexpr
);
2202 if (!files_rules
[rulix
].frul_re
)
2204 /* Compile the regexpr lazily. */
2206 files_rules
[rulix
].frul_re
= XCNEW (regex_t
);
2207 err
= regcomp (files_rules
[rulix
].frul_re
,
2208 files_rules
[rulix
].frul_srcexpr
,
2209 files_rules
[rulix
].frul_rflags
);
2212 /* The regular expression compilation fails only when
2213 file_rules is buggy. */
2221 /* Match the regexpr and trigger the rule if matched. */
2223 /* We have exactly ten pmatch-s, one for each $0, $1, $2,
2225 regmatch_t pmatch
[10];
2226 memset (pmatch
, 0, sizeof (pmatch
));
2227 if (!regexec (files_rules
[rulix
].frul_re
,
2228 inpfname
, 10, pmatch
, 0))
2230 DBGPRINTF ("input @ %p filename %s matched rulix#%d pattern %s",
2231 (void*) inpf
, inpfname
, rulix
,
2232 files_rules
[rulix
].frul_srcexpr
);
2234 matching_file_name_substitute (inpfname
, pmatch
,
2235 files_rules
[rulix
].frul_tr_for
);
2236 DBGPRINTF ("for_name %s", for_name
);
2238 matching_file_name_substitute (inpfname
, pmatch
,
2239 files_rules
[rulix
].frul_tr_out
);
2240 DBGPRINTF ("output_name %s", output_name
);
2241 if (files_rules
[rulix
].frul_action
)
2243 /* Invoke our action routine. */
2245 DBGPRINTF ("before action rulix#%d output_name %s for_name %s",
2246 rulix
, output_name
, for_name
);
2248 (files_rules
[rulix
].frul_action
) (inpf
,
2249 &output_name
, &for_name
);
2250 DBGPRINTF ("after action rulix#%d of=%p output_name %s for_name %s",
2251 rulix
, (void*)of
, output_name
, for_name
);
2252 /* If the action routine returned something, give it back
2253 immediately and cache it in inpf. */
2260 /* The rule matched, and had no action, or that action did
2261 not return any output file but could have changed the
2262 output_name or for_name. We break out of the loop on the
2268 /* The regexpr did not match. */
2269 DBGPRINTF ("rulix#%d did not match %s pattern %s",
2270 rulix
, inpfname
, files_rules
[rulix
].frul_srcexpr
);
2276 if (!output_name
|| !for_name
)
2278 /* This should not be possible, and could only happen if the
2279 files_rules is incomplete or buggy. */
2280 fatal ("failed to compute output name for %s", inpfname
);
2283 /* Look through to see if we've ever seen this output filename
2284 before. If found, cache the result in inpf. */
2285 for (r
= output_files
; r
; r
= r
->next
)
2286 if (filename_cmp (r
->name
, output_name
) == 0)
2289 DBGPRINTF ("found r @ %p for output_name %s for_name %s", (void*)r
,
2290 output_name
, for_name
);
2294 /* If not found, create it, and cache it in inpf. */
2295 r
= create_file (for_name
, output_name
);
2297 gcc_assert (r
&& r
->name
);
2298 DBGPRINTF ("created r @ %p for output_name %s for_name %s", (void*) r
,
2299 output_name
, for_name
);
2306 /* The name of an output file, suitable for definitions, that can see
2307 declarations made in INPF and is linked into every language that
2311 get_output_file_name (input_file
* inpf
)
2313 outf_p o
= get_output_file_with_visibility (inpf
);
2319 /* Check if existing file is equal to the in memory buffer. */
2322 is_file_equal (outf_p of
)
2324 FILE *newfile
= fopen (of
->name
, "r");
2327 if (newfile
== NULL
)
2331 for (i
= 0; i
< of
->bufused
; i
++)
2334 ch
= fgetc (newfile
);
2335 if (ch
== EOF
|| ch
!= (unsigned char) of
->buf
[i
])
2345 /* Copy the output to its final destination,
2346 but don't unnecessarily change modification times. */
2349 close_output_files (void)
2351 int nbwrittenfiles
= 0;
2354 for (of
= output_files
; of
; of
= of
->next
)
2356 if (!is_file_equal (of
))
2358 FILE *newfile
= NULL
;
2359 char *backupname
= NULL
;
2360 /* Back up the old version of the output file gt-FOO.c as
2361 BACKUPDIR/gt-FOO.c~ if we have a backup directory. */
2364 backupname
= concat (backup_dir
, "/",
2365 lbasename (of
->name
), "~", NULL
);
2366 if (!access (of
->name
, F_OK
) && rename (of
->name
, backupname
))
2367 fatal ("failed to back up %s as %s: %s",
2368 of
->name
, backupname
, xstrerror (errno
));
2371 newfile
= fopen (of
->name
, "w");
2372 if (newfile
== NULL
)
2373 fatal ("opening output file %s: %s", of
->name
, xstrerror (errno
));
2374 if (fwrite (of
->buf
, 1, of
->bufused
, newfile
) != of
->bufused
)
2375 fatal ("writing output file %s: %s", of
->name
, xstrerror (errno
));
2376 if (fclose (newfile
) != 0)
2377 fatal ("closing output file %s: %s", of
->name
, xstrerror (errno
));
2379 if (verbosity_level
>= 2 && backupname
)
2380 printf ("%s wrote #%-3d %s backed-up in %s\n",
2381 progname
, nbwrittenfiles
, of
->name
, backupname
);
2382 else if (verbosity_level
>= 1)
2383 printf ("%s write #%-3d %s\n", progname
, nbwrittenfiles
, of
->name
);
2388 /* output file remains unchanged. */
2389 if (verbosity_level
>= 2)
2390 printf ("%s keep %s\n", progname
, of
->name
);
2394 of
->bufused
= of
->buflength
= 0;
2396 if (verbosity_level
>= 1)
2397 printf ("%s wrote %d files.\n", progname
, nbwrittenfiles
);
2404 const input_file
* file
;
2408 struct walk_type_data
;
2410 /* For scalars and strings, given the item in 'val'.
2411 For structures, given a pointer to the item in 'val'.
2412 For misc. pointers, given the item in 'val'.
2414 typedef void (*process_field_fn
) (type_p f
, const struct walk_type_data
* p
);
2415 typedef void (*func_name_fn
) (type_p s
, const struct walk_type_data
* p
);
2417 /* Parameters for write_types. */
2419 struct write_types_data
2422 const char *param_prefix
;
2423 const char *subfield_marker_routine
;
2424 const char *marker_routine
;
2425 const char *reorder_note_routine
;
2426 const char *comment
;
2427 int skip_hooks
; /* skip hook generation if non zero */
2430 static void output_escaped_param (struct walk_type_data
*d
,
2431 const char *, const char *);
2432 static void output_mangled_typename (outf_p
, const_type_p
);
2433 static void walk_type (type_p t
, struct walk_type_data
*d
);
2434 static void write_func_for_structure (type_p orig_s
, type_p s
, type_p
*param
,
2435 const struct write_types_data
*wtd
);
2436 static void write_types_process_field
2437 (type_p f
, const struct walk_type_data
*d
);
2438 static void write_types (outf_p output_header
,
2440 type_p param_structs
,
2441 const struct write_types_data
*wtd
);
2442 static void write_types_local_process_field
2443 (type_p f
, const struct walk_type_data
*d
);
2444 static void write_local_func_for_structure
2445 (const_type_p orig_s
, type_p s
, type_p
*param
);
2446 static void write_local (outf_p output_header
,
2447 type_p structures
, type_p param_structs
);
2448 static int contains_scalar_p (type_p t
);
2449 static void put_mangled_filename (outf_p
, const input_file
*);
2450 static void finish_root_table (struct flist
*flp
, const char *pfx
,
2451 const char *tname
, const char *lastname
,
2453 static void write_root (outf_p
, pair_p
, type_p
, const char *, int,
2454 struct fileloc
*, const char *, bool);
2455 static void write_array (outf_p f
, pair_p v
,
2456 const struct write_types_data
*wtd
);
2457 static void write_roots (pair_p
, bool);
2459 /* Parameters for walk_type. */
2461 struct walk_type_data
2463 process_field_fn process_field
;
2468 const char *prev_val
[4];
2471 const struct fileloc
*line
;
2476 const char *reorder_fn
;
2478 bool fn_wants_lvalue
;
2486 /* Given a string TYPE_NAME, representing a C++ typename, return a valid
2487 pre-processor identifier to use in a #define directive. This replaces
2488 special characters used in C++ identifiers like '>', '<' and ':' with
2491 If no C++ special characters are found in TYPE_NAME, return
2492 TYPE_NAME. Otherwise, return a copy of TYPE_NAME with the special
2493 characters replaced with '_'. In this case, the caller is
2494 responsible for freeing the allocated string. */
2497 filter_type_name (const char *type_name
)
2499 if (strchr (type_name
, '<') || strchr (type_name
, ':'))
2502 char *s
= xstrdup (type_name
);
2503 for (i
= 0; i
< strlen (s
); i
++)
2504 if (s
[i
] == '<' || s
[i
] == '>' || s
[i
] == ':' || s
[i
] == ',')
2513 /* Print a mangled name representing T to OF. */
2516 output_mangled_typename (outf_p of
, const_type_p t
)
2524 case TYPE_UNDEFINED
:
2529 output_mangled_typename (of
, t
->u
.p
);
2539 case TYPE_LANG_STRUCT
:
2540 case TYPE_USER_STRUCT
:
2542 const char *id_for_tag
= filter_type_name (t
->u
.s
.tag
);
2543 oprintf (of
, "%lu%s", (unsigned long) strlen (id_for_tag
),
2545 if (id_for_tag
!= t
->u
.s
.tag
)
2546 free (CONST_CAST (char *, id_for_tag
));
2549 case TYPE_PARAM_STRUCT
:
2552 for (i
= 0; i
< NUM_PARAM
; i
++)
2553 if (t
->u
.param_struct
.param
[i
] != NULL
)
2554 output_mangled_typename (of
, t
->u
.param_struct
.param
[i
]);
2555 output_mangled_typename (of
, t
->u
.param_struct
.stru
);
2563 /* Print PARAM to D->OF processing escapes. D->VAL references the
2564 current object, D->PREV_VAL the object containing the current
2565 object, ONAME is the name of the option and D->LINE is used to
2566 print error messages. */
2569 output_escaped_param (struct walk_type_data
*d
, const char *param
,
2574 for (p
= param
; *p
; p
++)
2576 oprintf (d
->of
, "%c", *p
);
2581 oprintf (d
->of
, "(%s)", d
->prev_val
[2]);
2584 oprintf (d
->of
, "(%s)", d
->prev_val
[0]);
2587 oprintf (d
->of
, "(%s)", d
->prev_val
[1]);
2591 const char *pp
= d
->val
+ strlen (d
->val
);
2592 while (pp
[-1] == ']')
2595 oprintf (d
->of
, "%s", pp
);
2599 error_at_line (d
->line
, "`%s' option contains bad escape %c%c",
2605 /* Call D->PROCESS_FIELD for every field (or subfield) of D->VAL,
2606 which is of type T. Write code to D->OF to constrain execution (at
2607 the point that D->PROCESS_FIELD is called) to the appropriate
2608 cases. Call D->PROCESS_FIELD on subobjects before calling it on
2609 pointers to those objects. D->PREV_VAL lists the objects
2610 containing the current object, D->OPT is a list of options to
2611 apply, D->INDENT is the current indentation level, D->LINE is used
2612 to print error messages, D->BITMAP indicates which languages to
2613 print the structure for, and D->PARAM is the current parameter
2614 (from an enclosing param_is option). */
2617 walk_type (type_p t
, struct walk_type_data
*d
)
2619 const char *length
= NULL
;
2620 const char *desc
= NULL
;
2621 int maybe_undef_p
= 0;
2622 int use_param_num
= -1;
2623 int use_params_p
= 0;
2626 const struct nested_ptr_data
*nested_ptr_d
= NULL
;
2628 d
->needs_cast_p
= false;
2629 for (oo
= d
->opt
; oo
; oo
= oo
->next
)
2630 if (strcmp (oo
->name
, "length") == 0 && oo
->kind
== OPTION_STRING
)
2631 length
= oo
->info
.string
;
2632 else if (strcmp (oo
->name
, "maybe_undef") == 0)
2634 else if (strncmp (oo
->name
, "use_param", 9) == 0
2635 && (oo
->name
[9] == '\0' || ISDIGIT (oo
->name
[9])))
2636 use_param_num
= oo
->name
[9] == '\0' ? 0 : oo
->name
[9] - '0';
2637 else if (strcmp (oo
->name
, "use_params") == 0)
2639 else if (strcmp (oo
->name
, "desc") == 0 && oo
->kind
== OPTION_STRING
)
2640 desc
= oo
->info
.string
;
2641 else if (strcmp (oo
->name
, "mark_hook") == 0)
2643 else if (strcmp (oo
->name
, "nested_ptr") == 0
2644 && oo
->kind
== OPTION_NESTED
)
2645 nested_ptr_d
= (const struct nested_ptr_data
*) oo
->info
.nested
;
2646 else if (strcmp (oo
->name
, "dot") == 0)
2648 else if (strcmp (oo
->name
, "tag") == 0)
2650 else if (strcmp (oo
->name
, "special") == 0)
2652 else if (strcmp (oo
->name
, "skip") == 0)
2654 else if (strcmp (oo
->name
, "atomic") == 0)
2656 else if (strcmp (oo
->name
, "default") == 0)
2658 else if (strcmp (oo
->name
, "param_is") == 0)
2660 else if (strncmp (oo
->name
, "param", 5) == 0
2661 && ISDIGIT (oo
->name
[5]) && strcmp (oo
->name
+ 6, "_is") == 0)
2663 else if (strcmp (oo
->name
, "chain_next") == 0)
2665 else if (strcmp (oo
->name
, "chain_prev") == 0)
2667 else if (strcmp (oo
->name
, "chain_circular") == 0)
2669 else if (strcmp (oo
->name
, "reorder") == 0)
2671 else if (strcmp (oo
->name
, "variable_size") == 0)
2674 error_at_line (d
->line
, "unknown option `%s'\n", oo
->name
);
2681 int pointer_p
= t
->kind
== TYPE_POINTER
;
2685 if (!union_or_struct_p (t
))
2686 error_at_line (d
->line
, "`use_params' option on unimplemented type");
2688 t
= find_param_structure (t
, d
->param
);
2690 t
= create_pointer (t
);
2693 if (use_param_num
!= -1)
2695 if (d
->param
!= NULL
&& d
->param
[use_param_num
] != NULL
)
2697 type_p nt
= d
->param
[use_param_num
];
2699 if (t
->kind
== TYPE_ARRAY
)
2700 nt
= create_array (nt
, t
->u
.a
.len
);
2701 else if (length
!= NULL
&& t
->kind
== TYPE_POINTER
)
2702 nt
= create_pointer (nt
);
2703 d
->needs_cast_p
= (t
->kind
!= TYPE_POINTER
2704 && (nt
->kind
== TYPE_POINTER
2705 || nt
->kind
== TYPE_STRING
));
2709 error_at_line (d
->line
, "no parameter defined for `%s'", d
->val
);
2713 && (t
->kind
!= TYPE_POINTER
|| !union_or_struct_p (t
->u
.p
)))
2715 error_at_line (d
->line
,
2716 "field `%s' has invalid option `maybe_undef_p'\n",
2721 if (atomic_p
&& (t
->kind
!= TYPE_POINTER
) && (t
->kind
!= TYPE_STRING
))
2723 error_at_line (d
->line
, "field `%s' has invalid option `atomic'\n", d
->val
);
2731 d
->process_field (t
, d
);
2736 d
->in_ptr_field
= true;
2737 if (maybe_undef_p
&& t
->u
.p
->u
.s
.line
.file
== NULL
)
2739 oprintf (d
->of
, "%*sgcc_assert (!%s);\n", d
->indent
, "", d
->val
);
2743 /* If a pointer type is marked as "atomic", we process the
2744 field itself, but we don't walk the data that they point to.
2746 There are two main cases where we walk types: to mark
2747 pointers that are reachable, and to relocate pointers when
2748 writing a PCH file. In both cases, an atomic pointer is
2749 itself marked or relocated, but the memory that it points
2750 to is left untouched. In the case of PCH, that memory will
2751 be read/written unchanged to the PCH file. */
2754 oprintf (d
->of
, "%*sif (%s != NULL) {\n", d
->indent
, "", d
->val
);
2756 d
->process_field (t
, d
);
2758 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2764 if (!union_or_struct_p (t
->u
.p
)
2765 && t
->u
.p
->kind
!= TYPE_PARAM_STRUCT
)
2767 error_at_line (d
->line
,
2768 "field `%s' is pointer to unimplemented type",
2775 const char *oldprevval2
= d
->prev_val
[2];
2777 if (!union_or_struct_p (nested_ptr_d
->type
))
2779 error_at_line (d
->line
,
2780 "field `%s' has invalid "
2781 "option `nested_ptr'\n", d
->val
);
2785 d
->prev_val
[2] = d
->val
;
2786 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
2788 d
->val
= xasprintf ("x%d", d
->counter
++);
2789 oprintf (d
->of
, "%*s%s %s * %s%s =\n", d
->indent
, "",
2790 (nested_ptr_d
->type
->kind
== TYPE_UNION
2791 ? "union" : "struct"),
2792 nested_ptr_d
->type
->u
.s
.tag
,
2793 d
->fn_wants_lvalue
? "" : "const ", d
->val
);
2794 oprintf (d
->of
, "%*s", d
->indent
+ 2, "");
2795 output_escaped_param (d
, nested_ptr_d
->convert_from
,
2797 oprintf (d
->of
, ";\n");
2799 d
->process_field (nested_ptr_d
->type
, d
);
2801 if (d
->fn_wants_lvalue
)
2803 oprintf (d
->of
, "%*s%s = ", d
->indent
, "",
2805 d
->prev_val
[2] = d
->val
;
2806 output_escaped_param (d
, nested_ptr_d
->convert_to
,
2808 oprintf (d
->of
, ";\n");
2812 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2813 d
->val
= d
->prev_val
[2];
2814 d
->prev_val
[2] = oldprevval2
;
2817 d
->process_field (t
->u
.p
, d
);
2821 int loopcounter
= d
->loopcounter
;
2822 const char *oldval
= d
->val
;
2823 const char *oldprevval3
= d
->prev_val
[3];
2826 oprintf (d
->of
, "%*sif (%s != NULL) {\n", d
->indent
, "", d
->val
);
2828 oprintf (d
->of
, "%*ssize_t i%d;\n", d
->indent
, "", loopcounter
);
2829 oprintf (d
->of
, "%*sfor (i%d = 0; i%d != (size_t)(", d
->indent
,
2830 "", loopcounter
, loopcounter
);
2831 if (!d
->in_record_p
)
2832 output_escaped_param (d
, length
, "length");
2834 oprintf (d
->of
, "l%d", loopcounter
);
2835 if (d
->have_this_obj
)
2836 /* Try to unswitch loops (see PR53880). */
2837 oprintf (d
->of
, ") && ((void *)%s == this_obj", oldval
);
2838 oprintf (d
->of
, "); i%d++) {\n", loopcounter
);
2840 d
->val
= newval
= xasprintf ("%s[i%d]", oldval
, loopcounter
);
2842 d
->prev_val
[3] = oldval
;
2843 walk_type (t
->u
.p
, d
);
2846 d
->prev_val
[3] = oldprevval3
;
2849 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2850 d
->process_field (t
, d
);
2852 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2854 d
->in_ptr_field
= false;
2861 const char *oldval
= d
->val
;
2864 /* If it's an array of scalars, we optimize by not generating
2866 if (t
->u
.a
.p
->kind
== TYPE_SCALAR
)
2870 loopcounter
= d
->loopcounter
;
2872 loopcounter
= d
->counter
++;
2874 /* When walking an array, compute the length and store it in a
2875 local variable before walking the array elements, instead of
2876 recomputing the length expression each time through the loop.
2877 This is necessary to handle tcc_vl_exp objects like CALL_EXPR,
2878 where the length is stored in the first array element,
2879 because otherwise that operand can get overwritten on the
2881 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
2883 oprintf (d
->of
, "%*ssize_t i%d;\n", d
->indent
, "", loopcounter
);
2884 if (!d
->in_record_p
|| !length
)
2886 oprintf (d
->of
, "%*ssize_t l%d = (size_t)(",
2887 d
->indent
, "", loopcounter
);
2889 output_escaped_param (d
, length
, "length");
2891 oprintf (d
->of
, "%s", t
->u
.a
.len
);
2892 oprintf (d
->of
, ");\n");
2895 oprintf (d
->of
, "%*sfor (i%d = 0; i%d != l%d; i%d++) {\n",
2897 loopcounter
, loopcounter
, loopcounter
, loopcounter
);
2899 d
->val
= newval
= xasprintf ("%s[i%d]", oldval
, loopcounter
);
2901 walk_type (t
->u
.a
.p
, d
);
2906 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2908 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2916 const char *oldval
= d
->val
;
2917 const char *oldprevval1
= d
->prev_val
[1];
2918 const char *oldprevval2
= d
->prev_val
[2];
2919 const char *struct_mark_hook
= NULL
;
2920 const int union_p
= t
->kind
== TYPE_UNION
;
2921 int seen_default_p
= 0;
2923 int lengths_seen
= 0;
2925 bool any_length_seen
= false;
2927 if (!t
->u
.s
.line
.file
)
2928 error_at_line (d
->line
, "incomplete structure `%s'", t
->u
.s
.tag
);
2930 if ((d
->bitmap
& t
->u
.s
.bitmap
) != d
->bitmap
)
2932 error_at_line (d
->line
,
2933 "structure `%s' defined for mismatching languages",
2935 error_at_line (&t
->u
.s
.line
, "one structure defined here");
2938 /* Some things may also be defined in the structure's options. */
2939 for (o
= t
->u
.s
.opt
; o
; o
= o
->next
)
2940 if (!desc
&& strcmp (o
->name
, "desc") == 0
2941 && o
->kind
== OPTION_STRING
)
2942 desc
= o
->info
.string
;
2943 else if (!struct_mark_hook
&& strcmp (o
->name
, "mark_hook") == 0
2944 && o
->kind
== OPTION_STRING
)
2945 struct_mark_hook
= o
->info
.string
;
2947 if (struct_mark_hook
)
2948 oprintf (d
->of
, "%*s%s (&%s);\n",
2949 d
->indent
, "", struct_mark_hook
, oldval
);
2951 d
->prev_val
[2] = oldval
;
2952 d
->prev_val
[1] = oldprevval2
;
2957 error_at_line (d
->line
,
2958 "missing `desc' option for union `%s'",
2962 oprintf (d
->of
, "%*sswitch (", d
->indent
, "");
2963 output_escaped_param (d
, desc
, "desc");
2964 oprintf (d
->of
, ")\n");
2966 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
2969 for (f
= t
->u
.s
.fields
; f
; f
= f
->next
)
2973 const char *fieldlength
= NULL
;
2975 d
->reorder_fn
= NULL
;
2976 for (oo
= f
->opt
; oo
; oo
= oo
->next
)
2977 if (strcmp (oo
->name
, "skip") == 0)
2979 else if (strcmp (oo
->name
, "length") == 0
2980 && oo
->kind
== OPTION_STRING
)
2981 fieldlength
= oo
->info
.string
;
2991 if (!any_length_seen
)
2993 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
2996 any_length_seen
= true;
2998 oprintf (d
->of
, "%*ssize_t l%d = (size_t)(",
2999 d
->indent
, "", d
->counter
- 1);
3000 output_escaped_param (d
, fieldlength
, "length");
3001 oprintf (d
->of
, ");\n");
3005 endcounter
= d
->counter
;
3007 for (f
= t
->u
.s
.fields
; f
; f
= f
->next
)
3010 const char *dot
= ".";
3011 const char *tagid
= NULL
;
3014 int use_param_p
= 0;
3015 const char *fieldlength
= NULL
;
3018 d
->reorder_fn
= NULL
;
3019 for (oo
= f
->opt
; oo
; oo
= oo
->next
)
3020 if (strcmp (oo
->name
, "dot") == 0
3021 && oo
->kind
== OPTION_STRING
)
3022 dot
= oo
->info
.string
;
3023 else if (strcmp (oo
->name
, "tag") == 0
3024 && oo
->kind
== OPTION_STRING
)
3025 tagid
= oo
->info
.string
;
3026 else if (strcmp (oo
->name
, "skip") == 0)
3028 else if (strcmp (oo
->name
, "default") == 0)
3030 else if (strcmp (oo
->name
, "reorder") == 0
3031 && oo
->kind
== OPTION_STRING
)
3032 d
->reorder_fn
= oo
->info
.string
;
3033 else if (strncmp (oo
->name
, "use_param", 9) == 0
3034 && (oo
->name
[9] == '\0' || ISDIGIT (oo
->name
[9])))
3036 else if (strcmp (oo
->name
, "length") == 0
3037 && oo
->kind
== OPTION_STRING
)
3038 fieldlength
= oo
->info
.string
;
3043 if (union_p
&& tagid
)
3045 oprintf (d
->of
, "%*scase %s:\n", d
->indent
, "", tagid
);
3048 else if (union_p
&& default_p
)
3050 oprintf (d
->of
, "%*sdefault:\n", d
->indent
, "");
3054 else if (!union_p
&& (default_p
|| tagid
))
3055 error_at_line (d
->line
,
3056 "can't use `%s' outside a union on field `%s'",
3057 default_p
? "default" : "tag", f
->name
);
3058 else if (union_p
&& !(default_p
|| tagid
)
3059 && f
->type
->kind
== TYPE_SCALAR
)
3062 "%s:%d: warning: field `%s' is missing `tag' or `default' option\n",
3063 get_input_file_name (d
->line
->file
), d
->line
->line
,
3067 else if (union_p
&& !(default_p
|| tagid
))
3068 error_at_line (d
->line
,
3069 "field `%s' is missing `tag' or `default' option",
3074 d
->loopcounter
= endcounter
- lengths_seen
--;
3078 d
->val
= newval
= xasprintf ("%s%s%s", oldval
, dot
, f
->name
);
3080 d
->used_length
= false;
3081 d
->in_record_p
= !union_p
;
3083 if (union_p
&& use_param_p
&& d
->param
== NULL
)
3084 oprintf (d
->of
, "%*sgcc_unreachable ();\n", d
->indent
, "");
3086 walk_type (f
->type
, d
);
3088 d
->in_record_p
= false;
3094 oprintf (d
->of
, "%*sbreak;\n", d
->indent
, "");
3098 d
->reorder_fn
= NULL
;
3101 d
->prev_val
[1] = oldprevval1
;
3102 d
->prev_val
[2] = oldprevval2
;
3104 if (union_p
&& !seen_default_p
)
3106 oprintf (d
->of
, "%*sdefault:\n", d
->indent
, "");
3107 oprintf (d
->of
, "%*s break;\n", d
->indent
, "");
3111 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
3114 if (any_length_seen
)
3117 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
3122 case TYPE_LANG_STRUCT
:
3125 for (nt
= t
->u
.s
.lang_struct
; nt
; nt
= nt
->next
)
3126 if ((d
->bitmap
& nt
->u
.s
.bitmap
) == d
->bitmap
)
3129 error_at_line (d
->line
, "structure `%s' differs between languages",
3136 case TYPE_PARAM_STRUCT
:
3138 type_p
*oldparam
= d
->param
;
3140 d
->param
= t
->u
.param_struct
.param
;
3141 walk_type (t
->u
.param_struct
.stru
, d
);
3142 d
->param
= oldparam
;
3146 case TYPE_USER_STRUCT
:
3147 d
->process_field (t
, d
);
3151 case TYPE_UNDEFINED
:
3156 /* process_field routine for marking routines. */
3159 write_types_process_field (type_p f
, const struct walk_type_data
*d
)
3161 const struct write_types_data
*wtd
;
3162 const char *cast
= d
->needs_cast_p
? "(void *)" : "";
3163 wtd
= (const struct write_types_data
*) d
->cookie
;
3168 case TYPE_UNDEFINED
:
3171 oprintf (d
->of
, "%*s%s (%s%s", d
->indent
, "",
3172 wtd
->subfield_marker_routine
, cast
, d
->val
);
3173 if (wtd
->param_prefix
)
3175 if (f
->u
.p
->kind
== TYPE_SCALAR
)
3176 /* The current type is a pointer to a scalar (so not
3177 considered like a pointer to instances of user defined
3178 types) and we are seeing it; it means we must be even
3179 more careful about the second argument of the
3180 SUBFIELD_MARKER_ROUTINE call. That argument must
3181 always be the instance of the type for which
3182 write_func_for_structure was called - this really is
3183 what the function SUBFIELD_MARKER_ROUTINE expects.
3184 That is, it must be an instance of the ORIG_S type
3185 parameter of write_func_for_structure. The convention
3186 is that that argument must be "x" in that case (as set
3187 by write_func_for_structure). The problem is, we can't
3188 count on d->prev_val[3] to be always set to "x" in that
3189 case. Sometimes walk_type can set it to something else
3190 (to e.g cooperate with write_array when called from
3191 write_roots). So let's set it to "x" here then. */
3192 oprintf (d
->of
, ", x");
3194 oprintf (d
->of
, ", %s", d
->prev_val
[3]);
3197 oprintf (d
->of
, ", gt_%s_", wtd
->param_prefix
);
3198 output_mangled_typename (d
->of
, d
->orig_s
);
3201 oprintf (d
->of
, ", gt_%sa_%s", wtd
->param_prefix
, d
->prev_val
[0]);
3203 oprintf (d
->of
, ");\n");
3204 if (d
->reorder_fn
&& wtd
->reorder_note_routine
)
3205 oprintf (d
->of
, "%*s%s (%s%s, %s, %s);\n", d
->indent
, "",
3206 wtd
->reorder_note_routine
, cast
, d
->val
,
3207 d
->prev_val
[3], d
->reorder_fn
);
3213 case TYPE_LANG_STRUCT
:
3214 case TYPE_PARAM_STRUCT
:
3215 case TYPE_USER_STRUCT
:
3216 if (f
->kind
== TYPE_USER_STRUCT
&& !d
->in_ptr_field
)
3218 /* If F is a user-defined type and the field is not a
3219 pointer to the type, then we should not generate the
3220 standard pointer-marking code. All we need to do is call
3221 the user-provided marking function to process the fields
3223 oprintf (d
->of
, "%*sgt_%sx (&(%s));\n", d
->indent
, "", wtd
->prefix
,
3228 oprintf (d
->of
, "%*sgt_%s_", d
->indent
, "", wtd
->prefix
);
3229 output_mangled_typename (d
->of
, f
);
3230 oprintf (d
->of
, " (%s%s);\n", cast
, d
->val
);
3231 if (d
->reorder_fn
&& wtd
->reorder_note_routine
)
3232 oprintf (d
->of
, "%*s%s (%s%s, %s%s, %s);\n", d
->indent
, "",
3233 wtd
->reorder_note_routine
, cast
, d
->val
, cast
, d
->val
,
3246 /* Return an output file that is suitable for definitions which can
3247 reference struct S */
3250 get_output_file_for_structure (const_type_p s
, type_p
*param
)
3252 const input_file
*fn
;
3255 gcc_assert (union_or_struct_p (s
));
3256 fn
= s
->u
.s
.line
.file
;
3258 /* This is a hack, and not the good kind either. */
3259 for (i
= NUM_PARAM
- 1; i
>= 0; i
--)
3260 if (param
&& param
[i
] && param
[i
]->kind
== TYPE_POINTER
3261 && union_or_struct_p (param
[i
]->u
.p
))
3262 fn
= param
[i
]->u
.p
->u
.s
.line
.file
;
3264 /* The call to get_output_file_with_visibility may update fn by
3265 caching its result inside, so we need the CONST_CAST. */
3266 return get_output_file_with_visibility (CONST_CAST (input_file
*, fn
));
3270 /* Returns the specifier keyword for a string or union type S, empty string
3274 get_type_specifier (const type_p s
)
3276 if (s
->kind
== TYPE_STRUCT
)
3278 else if (s
->kind
== TYPE_LANG_STRUCT
)
3279 return get_type_specifier (s
->u
.s
.lang_struct
);
3280 else if (s
->kind
== TYPE_UNION
)
3286 /* Emits a declaration for type TY (assumed to be a union or a
3287 structure) on stream OUT. */
3290 write_type_decl (outf_p out
, type_p ty
)
3292 if (union_or_struct_p (ty
))
3293 oprintf (out
, "%s%s", get_type_specifier (ty
), ty
->u
.s
.tag
);
3294 else if (ty
->kind
== TYPE_SCALAR
)
3296 if (ty
->u
.scalar_is_char
)
3297 oprintf (out
, "const char");
3299 oprintf (out
, "void");
3301 else if (ty
->kind
== TYPE_POINTER
)
3303 write_type_decl (out
, ty
->u
.p
);
3304 oprintf (out
, " *");
3306 else if (ty
->kind
== TYPE_ARRAY
)
3308 write_type_decl (out
, ty
->u
.a
.p
);
3309 oprintf (out
, " *");
3311 else if (ty
->kind
== TYPE_STRING
)
3313 oprintf (out
, "const char *");
3320 /* Write on OF the name of the marker function for structure S. PREFIX
3321 is the prefix to use (to distinguish ggc from pch markers). */
3324 write_marker_function_name (outf_p of
, type_p s
, const char *prefix
)
3326 if (union_or_struct_p (s
))
3328 const char *id_for_tag
= filter_type_name (s
->u
.s
.tag
);
3329 oprintf (of
, "gt_%sx_%s", prefix
, id_for_tag
);
3330 if (id_for_tag
!= s
->u
.s
.tag
)
3331 free (CONST_CAST (char *, id_for_tag
));
3333 else if (s
->kind
== TYPE_PARAM_STRUCT
)
3335 oprintf (of
, "gt_%s_", prefix
);
3336 output_mangled_typename (of
, s
);
3342 /* Write on OF a user-callable routine to act as an entry point for
3343 the marking routine for S, generated by write_func_for_structure.
3344 PREFIX is the prefix to use to distinguish ggc and pch markers. */
3347 write_user_func_for_structure_ptr (outf_p of
, type_p s
, const char *prefix
)
3349 /* Parameterized structures are not supported in user markers. There
3350 is no way for the marker function to know which specific type
3351 to use to generate the call to the void * entry point. For
3352 instance, a marker for struct htab may need to call different
3353 routines to mark the fields, depending on the paramN_is attributes.
3355 A user-defined marker that accepts 'struct htab' as its argument
3356 would not know which variant to call. Generating several entry
3357 points accepting 'struct htab' would cause multiply-defined
3358 errors during compilation. */
3359 gcc_assert (union_or_struct_p (s
));
3361 type_p alias_of
= NULL
;
3362 for (options_p opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
3363 if (strcmp (opt
->name
, "ptr_alias") == 0)
3365 /* ALIAS_OF is set if ORIG_S is marked "ptr_alias". This means that
3366 we do not generate marking code for ORIG_S here. Instead, a
3367 forwarder #define in gtype-desc.h will cause every call to its
3368 marker to call the target of this alias.
3370 However, we still want to create a user entry code for the
3371 aliased type. So, if ALIAS_OF is set, we only generate the
3372 user-callable marker function. */
3373 alias_of
= opt
->info
.type
;
3377 oprintf (of
, "\nvoid\n");
3378 oprintf (of
, "gt_%sx (", prefix
);
3379 write_type_decl (of
, s
);
3380 oprintf (of
, " *& x)\n");
3381 oprintf (of
, "{\n");
3382 oprintf (of
, " if (x)\n ");
3383 write_marker_function_name (of
, alias_of
? alias_of
: s
, prefix
);
3384 oprintf (of
, " ((void *) x);\n");
3385 oprintf (of
, "}\n");
3389 /* Write a function to mark all the fields of type S on OF. PREFIX
3390 and D are as in write_user_marking_functions. */
3393 write_user_func_for_structure_body (type_p s
, const char *prefix
,
3394 struct walk_type_data
*d
)
3396 oprintf (d
->of
, "\nvoid\n");
3397 oprintf (d
->of
, "gt_%sx (", prefix
);
3398 write_type_decl (d
->of
, s
);
3399 oprintf (d
->of
, "& x_r ATTRIBUTE_UNUSED)\n");
3400 oprintf (d
->of
, "{\n");
3401 oprintf (d
->of
, " ");
3402 write_type_decl (d
->of
, s
);
3403 oprintf (d
->of
, " * ATTRIBUTE_UNUSED x = &x_r;\n");
3407 oprintf (d
->of
, "}\n");
3411 /* Emit the user-callable functions needed to mark all the types used
3412 by the user structure S. PREFIX is the prefix to use to
3413 distinguish ggc and pch markers. D contains data needed to pass to
3414 walk_type when traversing the fields of a type.
3416 For every type T referenced by S, two routines are generated: one
3417 that takes 'T *', marks the pointer and calls the second routine,
3418 which just marks the fields of T. */
3421 write_user_marking_functions (type_p s
, const char *prefix
,
3422 struct walk_type_data
*d
)
3424 gcc_assert (s
->kind
== TYPE_USER_STRUCT
);
3426 for (pair_p fld
= s
->u
.s
.fields
; fld
; fld
= fld
->next
)
3428 type_p fld_type
= fld
->type
;
3429 if (fld_type
->kind
== TYPE_POINTER
)
3431 type_p pointed_to_type
= fld_type
->u
.p
;
3432 if (union_or_struct_p (pointed_to_type
))
3433 write_user_func_for_structure_ptr (d
->of
, pointed_to_type
, prefix
);
3435 else if (union_or_struct_p (fld_type
))
3436 write_user_func_for_structure_body (fld_type
, prefix
, d
);
3441 /* For S, a structure that's part of ORIG_S, and using parameters
3442 PARAM, write out a routine that:
3443 - Takes a parameter, a void * but actually of type *S
3444 - If SEEN_ROUTINE returns nonzero, calls write_types_process_field on each
3445 field of S or its substructures and (in some cases) things
3446 that are pointed to by S. */
3449 write_func_for_structure (type_p orig_s
, type_p s
, type_p
*param
,
3450 const struct write_types_data
*wtd
)
3452 const char *chain_next
= NULL
;
3453 const char *chain_prev
= NULL
;
3454 const char *chain_circular
= NULL
;
3455 const char *mark_hook_name
= NULL
;
3457 struct walk_type_data d
;
3459 memset (&d
, 0, sizeof (d
));
3460 d
.of
= get_output_file_for_structure (s
, param
);
3461 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
3462 if (strcmp (opt
->name
, "chain_next") == 0
3463 && opt
->kind
== OPTION_STRING
)
3464 chain_next
= opt
->info
.string
;
3465 else if (strcmp (opt
->name
, "chain_prev") == 0
3466 && opt
->kind
== OPTION_STRING
)
3467 chain_prev
= opt
->info
.string
;
3468 else if (strcmp (opt
->name
, "chain_circular") == 0
3469 && opt
->kind
== OPTION_STRING
)
3470 chain_circular
= opt
->info
.string
;
3471 else if (strcmp (opt
->name
, "mark_hook") == 0
3472 && opt
->kind
== OPTION_STRING
)
3473 mark_hook_name
= opt
->info
.string
;
3474 if (chain_prev
!= NULL
&& chain_next
== NULL
)
3475 error_at_line (&s
->u
.s
.line
, "chain_prev without chain_next");
3476 if (chain_circular
!= NULL
&& chain_next
!= NULL
)
3477 error_at_line (&s
->u
.s
.line
, "chain_circular with chain_next");
3478 if (chain_circular
!= NULL
)
3479 chain_next
= chain_circular
;
3481 d
.process_field
= write_types_process_field
;
3485 d
.line
= &s
->u
.s
.line
;
3486 d
.bitmap
= s
->u
.s
.bitmap
;
3488 d
.prev_val
[0] = "*x";
3489 d
.prev_val
[1] = "not valid postage"; /* Guarantee an error. */
3490 d
.prev_val
[3] = "x";
3492 d
.have_this_obj
= false;
3494 oprintf (d
.of
, "\n");
3495 oprintf (d
.of
, "void\n");
3496 write_marker_function_name (d
.of
, orig_s
, wtd
->prefix
);
3497 oprintf (d
.of
, " (void *x_p)\n");
3498 oprintf (d
.of
, "{\n ");
3499 write_type_decl (d
.of
, s
);
3500 oprintf (d
.of
, " * %sx = (", chain_next
== NULL
? "const " : "");
3501 write_type_decl (d
.of
, s
);
3502 oprintf (d
.of
, " *)x_p;\n");
3503 if (chain_next
!= NULL
)
3505 /* TYPE_USER_STRUCTs should not occur here. These structures
3506 are completely handled by user code. */
3507 gcc_assert (orig_s
->kind
!= TYPE_USER_STRUCT
);
3509 oprintf (d
.of
, " ");
3510 write_type_decl (d
.of
, s
);
3511 oprintf (d
.of
, " * xlimit = x;\n");
3513 if (chain_next
== NULL
)
3515 oprintf (d
.of
, " if (%s (x", wtd
->marker_routine
);
3516 if (wtd
->param_prefix
)
3518 oprintf (d
.of
, ", x, gt_%s_", wtd
->param_prefix
);
3519 output_mangled_typename (d
.of
, orig_s
);
3521 oprintf (d
.of
, "))\n");
3525 if (chain_circular
!= NULL
)
3526 oprintf (d
.of
, " if (!%s (xlimit", wtd
->marker_routine
);
3528 oprintf (d
.of
, " while (%s (xlimit", wtd
->marker_routine
);
3529 if (wtd
->param_prefix
)
3531 oprintf (d
.of
, ", xlimit, gt_%s_", wtd
->param_prefix
);
3532 output_mangled_typename (d
.of
, orig_s
);
3534 oprintf (d
.of
, "))\n");
3535 if (chain_circular
!= NULL
)
3536 oprintf (d
.of
, " return;\n do\n");
3537 if (mark_hook_name
&& !wtd
->skip_hooks
)
3539 oprintf (d
.of
, " {\n");
3540 oprintf (d
.of
, " %s (xlimit);\n ", mark_hook_name
);
3542 oprintf (d
.of
, " xlimit = (");
3543 d
.prev_val
[2] = "*xlimit";
3544 output_escaped_param (&d
, chain_next
, "chain_next");
3545 oprintf (d
.of
, ");\n");
3546 if (mark_hook_name
&& !wtd
->skip_hooks
)
3547 oprintf (d
.of
, " }\n");
3548 if (chain_prev
!= NULL
)
3550 oprintf (d
.of
, " if (x != xlimit)\n");
3551 oprintf (d
.of
, " for (;;)\n");
3552 oprintf (d
.of
, " {\n");
3553 oprintf (d
.of
, " %s %s * const xprev = (",
3554 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
3556 d
.prev_val
[2] = "*x";
3557 output_escaped_param (&d
, chain_prev
, "chain_prev");
3558 oprintf (d
.of
, ");\n");
3559 oprintf (d
.of
, " if (xprev == NULL) break;\n");
3560 oprintf (d
.of
, " x = xprev;\n");
3561 oprintf (d
.of
, " (void) %s (xprev", wtd
->marker_routine
);
3562 if (wtd
->param_prefix
)
3564 oprintf (d
.of
, ", xprev, gt_%s_", wtd
->param_prefix
);
3565 output_mangled_typename (d
.of
, orig_s
);
3567 oprintf (d
.of
, ");\n");
3568 oprintf (d
.of
, " }\n");
3570 if (chain_circular
!= NULL
)
3572 oprintf (d
.of
, " while (%s (xlimit", wtd
->marker_routine
);
3573 if (wtd
->param_prefix
)
3575 oprintf (d
.of
, ", xlimit, gt_%s_", wtd
->param_prefix
);
3576 output_mangled_typename (d
.of
, orig_s
);
3578 oprintf (d
.of
, "));\n");
3579 if (mark_hook_name
&& !wtd
->skip_hooks
)
3580 oprintf (d
.of
, " %s (xlimit);\n", mark_hook_name
);
3581 oprintf (d
.of
, " do\n");
3584 oprintf (d
.of
, " while (x != xlimit)\n");
3586 oprintf (d
.of
, " {\n");
3587 if (mark_hook_name
&& chain_next
== NULL
&& !wtd
->skip_hooks
)
3589 oprintf (d
.of
, " %s (x);\n", mark_hook_name
);
3592 d
.prev_val
[2] = "*x";
3594 if (orig_s
->kind
!= TYPE_USER_STRUCT
)
3598 /* User structures have no fields to walk. Simply generate a call
3599 to the user-provided structure marker. */
3600 oprintf (d
.of
, "%*sgt_%sx (x);\n", d
.indent
, "", wtd
->prefix
);
3603 if (chain_next
!= NULL
)
3605 oprintf (d
.of
, " x = (");
3606 output_escaped_param (&d
, chain_next
, "chain_next");
3607 oprintf (d
.of
, ");\n");
3610 oprintf (d
.of
, " }\n");
3611 if (chain_circular
!= NULL
)
3612 oprintf (d
.of
, " while (x != xlimit);\n");
3613 oprintf (d
.of
, "}\n");
3615 if (orig_s
->kind
== TYPE_USER_STRUCT
)
3616 write_user_marking_functions (orig_s
, wtd
->prefix
, &d
);
3620 /* Write out marker routines for STRUCTURES and PARAM_STRUCTS. */
3623 write_types (outf_p output_header
, type_p structures
, type_p param_structs
,
3624 const struct write_types_data
*wtd
)
3626 int nbfun
= 0; /* Count the emitted functions. */
3629 oprintf (output_header
, "\n/* %s*/\n", wtd
->comment
);
3631 /* We first emit the macros and the declarations. Functions' code is
3632 emitted afterwards. This is needed in plugin mode. */
3633 oprintf (output_header
, "/* Macros and declarations. */\n");
3634 for (s
= structures
; s
; s
= s
->next
)
3635 if (s
->gc_used
== GC_POINTED_TO
|| s
->gc_used
== GC_MAYBE_POINTED_TO
)
3639 if (s
->gc_used
== GC_MAYBE_POINTED_TO
&& s
->u
.s
.line
.file
== NULL
)
3642 const char *s_id_for_tag
= filter_type_name (s
->u
.s
.tag
);
3644 oprintf (output_header
, "#define gt_%s_", wtd
->prefix
);
3645 output_mangled_typename (output_header
, s
);
3646 oprintf (output_header
, "(X) do { \\\n");
3647 oprintf (output_header
,
3648 " if (X != NULL) gt_%sx_%s (X);\\\n", wtd
->prefix
,
3650 oprintf (output_header
, " } while (0)\n");
3652 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
3653 if (strcmp (opt
->name
, "ptr_alias") == 0
3654 && opt
->kind
== OPTION_TYPE
)
3656 const_type_p
const t
= (const_type_p
) opt
->info
.type
;
3657 if (t
->kind
== TYPE_STRUCT
3658 || t
->kind
== TYPE_UNION
|| t
->kind
== TYPE_LANG_STRUCT
)
3660 const char *t_id_for_tag
= filter_type_name (t
->u
.s
.tag
);
3661 oprintf (output_header
,
3662 "#define gt_%sx_%s gt_%sx_%s\n",
3663 wtd
->prefix
, s
->u
.s
.tag
, wtd
->prefix
, t_id_for_tag
);
3664 if (t_id_for_tag
!= t
->u
.s
.tag
)
3665 free (CONST_CAST (char *, t_id_for_tag
));
3668 error_at_line (&s
->u
.s
.line
,
3669 "structure alias is not a structure");
3675 /* Declare the marker procedure only once. */
3676 oprintf (output_header
,
3677 "extern void gt_%sx_%s (void *);\n",
3678 wtd
->prefix
, s_id_for_tag
);
3680 if (s_id_for_tag
!= s
->u
.s
.tag
)
3681 free (CONST_CAST (char *, s_id_for_tag
));
3683 if (s
->u
.s
.line
.file
== NULL
)
3685 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
3691 for (s
= param_structs
; s
; s
= s
->next
)
3692 if (s
->gc_used
== GC_POINTED_TO
)
3694 type_p stru
= s
->u
.param_struct
.stru
;
3696 /* Declare the marker procedure. */
3697 oprintf (output_header
, "extern void gt_%s_", wtd
->prefix
);
3698 output_mangled_typename (output_header
, s
);
3699 oprintf (output_header
, " (void *);\n");
3701 if (stru
->u
.s
.line
.file
== NULL
)
3703 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
3709 /* At last we emit the functions code. */
3710 oprintf (output_header
, "\n/* functions code */\n");
3711 for (s
= structures
; s
; s
= s
->next
)
3712 if (s
->gc_used
== GC_POINTED_TO
|| s
->gc_used
== GC_MAYBE_POINTED_TO
)
3716 if (s
->gc_used
== GC_MAYBE_POINTED_TO
&& s
->u
.s
.line
.file
== NULL
)
3718 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
3719 if (strcmp (opt
->name
, "ptr_alias") == 0)
3724 if (s
->kind
== TYPE_LANG_STRUCT
)
3727 for (ss
= s
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
3730 DBGPRINTF ("writing func #%d lang_struct ss @ %p '%s'",
3731 nbfun
, (void*) ss
, ss
->u
.s
.tag
);
3732 write_func_for_structure (s
, ss
, NULL
, wtd
);
3738 DBGPRINTF ("writing func #%d struct s @ %p '%s'",
3739 nbfun
, (void*) s
, s
->u
.s
.tag
);
3740 write_func_for_structure (s
, s
, NULL
, wtd
);
3745 /* Structure s is not possibly pointed to, so can be ignored. */
3746 DBGPRINTF ("ignored s @ %p '%s' gc_used#%d",
3747 (void*)s
, s
->u
.s
.tag
,
3751 for (s
= param_structs
; s
; s
= s
->next
)
3752 if (s
->gc_used
== GC_POINTED_TO
)
3754 type_p
*param
= s
->u
.param_struct
.param
;
3755 type_p stru
= s
->u
.param_struct
.stru
;
3756 if (stru
->u
.s
.line
.file
== NULL
)
3758 if (stru
->kind
== TYPE_LANG_STRUCT
)
3761 for (ss
= stru
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
3764 DBGPRINTF ("writing func #%d param lang_struct ss @ %p '%s'",
3765 nbfun
, (void*) ss
, ss
->u
.s
.tag
);
3766 write_func_for_structure (s
, ss
, param
, wtd
);
3772 DBGPRINTF ("writing func #%d param struct s @ %p stru @ %p '%s'",
3774 (void*) stru
, stru
->u
.s
.tag
);
3775 write_func_for_structure (s
, stru
, param
, wtd
);
3780 /* Param structure s is not pointed to, so should be ignored. */
3781 DBGPRINTF ("ignored s @ %p", (void*)s
);
3783 if (verbosity_level
>= 2)
3784 printf ("%s emitted %d routines for %s\n",
3785 progname
, nbfun
, wtd
->comment
);
3788 static const struct write_types_data ggc_wtd
= {
3789 "ggc_m", NULL
, "ggc_mark", "ggc_test_and_set_mark", NULL
,
3790 "GC marker procedures. ",
3794 static const struct write_types_data pch_wtd
= {
3795 "pch_n", "pch_p", "gt_pch_note_object", "gt_pch_note_object",
3796 "gt_pch_note_reorder",
3797 "PCH type-walking procedures. ",
3801 /* Write out the local pointer-walking routines. */
3803 /* process_field routine for local pointer-walking for user-callable
3804 routines. The difference between this and
3805 write_types_local_process_field is that, in this case, we do not
3806 need to check whether the given pointer matches the address of the
3807 parent structure. This check was already generated by the call
3808 to gt_pch_nx in the main gt_pch_p_*() function that is calling
3812 write_types_local_user_process_field (type_p f
, const struct walk_type_data
*d
)
3819 case TYPE_LANG_STRUCT
:
3820 case TYPE_PARAM_STRUCT
:
3822 oprintf (d
->of
, "%*s op (&(%s), cookie);\n", d
->indent
, "", d
->val
);
3825 case TYPE_USER_STRUCT
:
3826 if (d
->in_ptr_field
)
3827 oprintf (d
->of
, "%*s op (&(%s), cookie);\n", d
->indent
, "", d
->val
);
3829 oprintf (d
->of
, "%*s gt_pch_nx (&(%s), op, cookie);\n",
3830 d
->indent
, "", d
->val
);
3838 case TYPE_UNDEFINED
:
3844 /* Write a function to PCH walk all the fields of type S on OF.
3845 D contains data needed by walk_type to recurse into the fields of S. */
3848 write_pch_user_walking_for_structure_body (type_p s
, struct walk_type_data
*d
)
3850 oprintf (d
->of
, "\nvoid\n");
3851 oprintf (d
->of
, "gt_pch_nx (");
3852 write_type_decl (d
->of
, s
);
3853 oprintf (d
->of
, "* x ATTRIBUTE_UNUSED,\n"
3854 "\tATTRIBUTE_UNUSED gt_pointer_operator op,\n"
3855 "\tATTRIBUTE_UNUSED void *cookie)\n");
3856 oprintf (d
->of
, "{\n");
3859 d
->process_field
= write_types_local_user_process_field
;
3861 oprintf (d
->of
, "}\n");
3865 /* Emit the user-callable functions needed to mark all the types used
3866 by the user structure S. PREFIX is the prefix to use to
3867 distinguish ggc and pch markers. CHAIN_NEXT is set if S has the
3868 chain_next option defined. D contains data needed to pass to
3869 walk_type when traversing the fields of a type.
3871 For every type T referenced by S, two routines are generated: one
3872 that takes 'T *', marks the pointer and calls the second routine,
3873 which just marks the fields of T. */
3876 write_pch_user_walking_functions (type_p s
, struct walk_type_data
*d
)
3878 gcc_assert (s
->kind
== TYPE_USER_STRUCT
);
3880 for (pair_p fld
= s
->u
.s
.fields
; fld
; fld
= fld
->next
)
3882 type_p fld_type
= fld
->type
;
3883 if (union_or_struct_p (fld_type
))
3884 write_pch_user_walking_for_structure_body (fld_type
, d
);
3889 /* process_field routine for local pointer-walking. */
3892 write_types_local_process_field (type_p f
, const struct walk_type_data
*d
)
3894 gcc_assert (d
->have_this_obj
);
3900 case TYPE_LANG_STRUCT
:
3901 case TYPE_PARAM_STRUCT
:
3903 oprintf (d
->of
, "%*sif ((void *)(%s) == this_obj)\n", d
->indent
, "",
3905 oprintf (d
->of
, "%*s op (&(%s), cookie);\n", d
->indent
, "", d
->val
);
3908 case TYPE_USER_STRUCT
:
3909 oprintf (d
->of
, "%*sif ((void *)(%s) == this_obj)\n", d
->indent
, "",
3911 if (d
->in_ptr_field
)
3912 oprintf (d
->of
, "%*s op (&(%s), cookie);\n", d
->indent
, "", d
->val
);
3914 oprintf (d
->of
, "%*s gt_pch_nx (&(%s), op, cookie);\n",
3915 d
->indent
, "", d
->val
);
3923 case TYPE_UNDEFINED
:
3929 /* For S, a structure that's part of ORIG_S, and using parameters
3930 PARAM, write out a routine that:
3931 - Is of type gt_note_pointers
3932 - Calls PROCESS_FIELD on each field of S or its substructures.
3936 write_local_func_for_structure (const_type_p orig_s
, type_p s
, type_p
*param
)
3938 struct walk_type_data d
;
3940 memset (&d
, 0, sizeof (d
));
3941 d
.of
= get_output_file_for_structure (s
, param
);
3942 d
.process_field
= write_types_local_process_field
;
3944 d
.line
= &s
->u
.s
.line
;
3945 d
.bitmap
= s
->u
.s
.bitmap
;
3947 d
.prev_val
[0] = d
.prev_val
[2] = "*x";
3948 d
.prev_val
[1] = "not valid postage"; /* Guarantee an error. */
3949 d
.prev_val
[3] = "x";
3951 d
.fn_wants_lvalue
= true;
3953 oprintf (d
.of
, "\n");
3954 oprintf (d
.of
, "void\n");
3955 oprintf (d
.of
, "gt_pch_p_");
3956 output_mangled_typename (d
.of
, orig_s
);
3957 oprintf (d
.of
, " (ATTRIBUTE_UNUSED void *this_obj,\n"
3959 "\tATTRIBUTE_UNUSED gt_pointer_operator op,\n"
3960 "\tATTRIBUTE_UNUSED void *cookie)\n");
3961 oprintf (d
.of
, "{\n");
3962 oprintf (d
.of
, " %s %s * x ATTRIBUTE_UNUSED = (%s %s *)x_p;\n",
3963 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
,
3964 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
3966 d
.have_this_obj
= true;
3968 if (s
->kind
!= TYPE_USER_STRUCT
)
3972 /* User structures have no fields to walk. Simply generate a
3973 call to the user-provided PCH walker. */
3974 oprintf (d
.of
, "%*sif ((void *)(%s) == this_obj)\n", d
.indent
, "",
3976 oprintf (d
.of
, "%*s gt_pch_nx (&(%s), op, cookie);\n",
3977 d
.indent
, "", d
.val
);
3980 oprintf (d
.of
, "}\n");
3982 /* Write user-callable entry points for the PCH walking routines. */
3983 if (orig_s
->kind
== TYPE_USER_STRUCT
)
3984 write_pch_user_walking_functions (s
, &d
);
3987 /* Write out local marker routines for STRUCTURES and PARAM_STRUCTS. */
3990 write_local (outf_p output_header
, type_p structures
, type_p param_structs
)
3997 oprintf (output_header
, "\n/* Local pointer-walking routines. */\n");
3998 for (s
= structures
; s
; s
= s
->next
)
3999 if (s
->gc_used
== GC_POINTED_TO
|| s
->gc_used
== GC_MAYBE_POINTED_TO
)
4003 if (s
->u
.s
.line
.file
== NULL
)
4005 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
4006 if (strcmp (opt
->name
, "ptr_alias") == 0
4007 && opt
->kind
== OPTION_TYPE
)
4009 const_type_p
const t
= (const_type_p
) opt
->info
.type
;
4010 if (t
->kind
== TYPE_STRUCT
4011 || t
->kind
== TYPE_UNION
|| t
->kind
== TYPE_LANG_STRUCT
)
4013 oprintf (output_header
, "#define gt_pch_p_");
4014 output_mangled_typename (output_header
, s
);
4015 oprintf (output_header
, " gt_pch_p_");
4016 output_mangled_typename (output_header
, t
);
4017 oprintf (output_header
, "\n");
4020 error_at_line (&s
->u
.s
.line
,
4021 "structure alias is not a structure");
4027 /* Declare the marker procedure only once. */
4028 oprintf (output_header
, "extern void gt_pch_p_");
4029 output_mangled_typename (output_header
, s
);
4030 oprintf (output_header
,
4031 "\n (void *, void *, gt_pointer_operator, void *);\n");
4033 if (s
->kind
== TYPE_LANG_STRUCT
)
4036 for (ss
= s
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
4037 write_local_func_for_structure (s
, ss
, NULL
);
4040 write_local_func_for_structure (s
, s
, NULL
);
4043 for (s
= param_structs
; s
; s
= s
->next
)
4044 if (s
->gc_used
== GC_POINTED_TO
)
4046 type_p
*param
= s
->u
.param_struct
.param
;
4047 type_p stru
= s
->u
.param_struct
.stru
;
4049 /* Declare the marker procedure. */
4050 oprintf (output_header
, "extern void gt_pch_p_");
4051 output_mangled_typename (output_header
, s
);
4052 oprintf (output_header
,
4053 "\n (void *, void *, gt_pointer_operator, void *);\n");
4055 if (stru
->u
.s
.line
.file
== NULL
)
4057 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
4062 if (stru
->kind
== TYPE_LANG_STRUCT
)
4065 for (ss
= stru
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
4066 write_local_func_for_structure (s
, ss
, param
);
4069 write_local_func_for_structure (s
, stru
, param
);
4073 /* Nonzero if S is a type for which typed GC allocators should be output. */
4075 #define USED_BY_TYPED_GC_P(s) \
4076 ((s->kind == TYPE_POINTER \
4077 && (s->u.p->gc_used == GC_POINTED_TO \
4078 || s->u.p->gc_used == GC_USED)) \
4079 || (union_or_struct_p (s) \
4080 && ((s)->gc_used == GC_POINTED_TO \
4081 || ((s)->gc_used == GC_MAYBE_POINTED_TO \
4082 && s->u.s.line.file != NULL) \
4083 || ((s)->gc_used == GC_USED \
4084 && strncmp (s->u.s.tag, "anonymous", strlen ("anonymous"))))))
4087 /* Might T contain any non-pointer elements? */
4090 contains_scalar_p (type_p t
)
4098 return contains_scalar_p (t
->u
.a
.p
);
4099 case TYPE_USER_STRUCT
:
4100 /* User-marked structures will typically contain pointers. */
4103 /* Could also check for structures that have no non-pointer
4104 fields, but there aren't enough of those to worry about. */
4109 /* Mangle INPF and print it to F. */
4112 put_mangled_filename (outf_p f
, const input_file
*inpf
)
4114 /* The call to get_output_file_name may indirectly update fn since
4115 get_output_file_with_visibility caches its result inside, so we
4116 need the CONST_CAST. */
4117 const char *name
= get_output_file_name (CONST_CAST (input_file
*, inpf
));
4120 for (; *name
!= 0; name
++)
4121 if (ISALNUM (*name
))
4122 oprintf (f
, "%c", *name
);
4124 oprintf (f
, "%c", '_');
4127 /* Finish off the currently-created root tables in FLP. PFX, TNAME,
4128 LASTNAME, and NAME are all strings to insert in various places in
4129 the resulting code. */
4132 finish_root_table (struct flist
*flp
, const char *pfx
, const char *lastname
,
4133 const char *tname
, const char *name
)
4137 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
4138 if (fli2
->started_p
)
4140 oprintf (fli2
->f
, " %s\n", lastname
);
4141 oprintf (fli2
->f
, "};\n\n");
4144 for (fli2
= flp
; fli2
&& base_files
; fli2
= fli2
->next
)
4145 if (fli2
->started_p
)
4147 lang_bitmap bitmap
= get_lang_bitmap (fli2
->file
);
4150 for (fnum
= 0; bitmap
!= 0; fnum
++, bitmap
>>= 1)
4153 oprintf (base_files
[fnum
],
4154 "extern const struct %s gt_%s_", tname
, pfx
);
4155 put_mangled_filename (base_files
[fnum
], fli2
->file
);
4156 oprintf (base_files
[fnum
], "[];\n");
4162 for (fnum
= 0; base_files
&& fnum
< num_lang_dirs
; fnum
++)
4163 oprintf (base_files
[fnum
],
4164 "EXPORTED_CONST struct %s * const %s[] = {\n", tname
, name
);
4168 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
4169 if (fli2
->started_p
)
4171 lang_bitmap bitmap
= get_lang_bitmap (fli2
->file
);
4174 fli2
->started_p
= 0;
4176 for (fnum
= 0; base_files
&& bitmap
!= 0; fnum
++, bitmap
>>= 1)
4179 oprintf (base_files
[fnum
], " gt_%s_", pfx
);
4180 put_mangled_filename (base_files
[fnum
], fli2
->file
);
4181 oprintf (base_files
[fnum
], ",\n");
4187 for (fnum
= 0; base_files
&& fnum
< num_lang_dirs
; fnum
++)
4189 oprintf (base_files
[fnum
], " NULL\n");
4190 oprintf (base_files
[fnum
], "};\n");
4195 /* Write the first three fields (pointer, count and stride) for
4196 root NAME to F. V and LINE are as for write_root.
4198 Return true if the entry could be written; return false on error. */
4201 start_root_entry (outf_p f
, pair_p v
, const char *name
, struct fileloc
*line
)
4207 error_at_line (line
, "`%s' is too complex to be a root", name
);
4211 oprintf (f
, " {\n");
4212 oprintf (f
, " &%s,\n", name
);
4215 for (ap
= v
->type
; ap
->kind
== TYPE_ARRAY
; ap
= ap
->u
.a
.p
)
4217 oprintf (f
, " * (%s)", ap
->u
.a
.len
);
4218 else if (ap
== v
->type
)
4219 oprintf (f
, " * ARRAY_SIZE (%s)", v
->name
);
4221 oprintf (f
, " sizeof (%s", v
->name
);
4222 for (ap
= v
->type
; ap
->kind
== TYPE_ARRAY
; ap
= ap
->u
.a
.p
)
4224 oprintf (f
, "),\n");
4228 /* A subroutine of write_root for writing the roots for field FIELD_NAME,
4229 which has type FIELD_TYPE. Parameters F to EMIT_PCH are the parameters
4233 write_field_root (outf_p f
, pair_p v
, type_p type
, const char *name
,
4234 int has_length
, struct fileloc
*line
, const char *if_marked
,
4235 bool emit_pch
, type_p field_type
, const char *field_name
)
4238 /* If the field reference is relative to V, rather than to some
4239 subcomponent of V, we can mark any subarrays with a single stride.
4240 We're effectively treating the field as a global variable in its
4242 if (v
&& type
== v
->type
)
4245 newv
.type
= field_type
;
4246 newv
.name
= ACONCAT ((v
->name
, ".", field_name
, NULL
));
4249 /* Otherwise, any arrays nested in the structure are too complex to
4251 else if (field_type
->kind
== TYPE_ARRAY
)
4253 write_root (f
, v
, field_type
, ACONCAT ((name
, ".", field_name
, NULL
)),
4254 has_length
, line
, if_marked
, emit_pch
);
4257 /* Write out to F the table entry and any marker routines needed to
4258 mark NAME as TYPE. V can be one of three values:
4260 - null, if NAME is too complex to represent using a single
4261 count and stride. In this case, it is an error for NAME to
4262 contain any gc-ed data.
4264 - the outermost array that contains NAME, if NAME is part of an array.
4266 - the C variable that contains NAME, if NAME is not part of an array.
4268 LINE is the line of the C source that declares the root variable.
4269 HAS_LENGTH is nonzero iff V was a variable-length array. IF_MARKED
4270 is nonzero iff we are building the root table for hash table caches. */
4273 write_root (outf_p f
, pair_p v
, type_p type
, const char *name
, int has_length
,
4274 struct fileloc
*line
, const char *if_marked
, bool emit_pch
)
4281 for (fld
= type
->u
.s
.fields
; fld
; fld
= fld
->next
)
4284 const char *desc
= NULL
;
4287 for (o
= fld
->opt
; o
; o
= o
->next
)
4288 if (strcmp (o
->name
, "skip") == 0)
4290 else if (strcmp (o
->name
, "desc") == 0
4291 && o
->kind
== OPTION_STRING
)
4292 desc
= o
->info
.string
;
4293 else if (strcmp (o
->name
, "param_is") == 0)
4296 error_at_line (line
,
4297 "field `%s' of global `%s' has unknown option `%s'",
4298 fld
->name
, name
, o
->name
);
4302 else if (desc
&& fld
->type
->kind
== TYPE_UNION
)
4304 pair_p validf
= NULL
;
4307 for (ufld
= fld
->type
->u
.s
.fields
; ufld
; ufld
= ufld
->next
)
4309 const char *tag
= NULL
;
4311 for (oo
= ufld
->opt
; oo
; oo
= oo
->next
)
4312 if (strcmp (oo
->name
, "tag") == 0
4313 && oo
->kind
== OPTION_STRING
)
4314 tag
= oo
->info
.string
;
4315 if (tag
== NULL
|| strcmp (tag
, desc
) != 0)
4318 error_at_line (line
,
4319 "both `%s.%s.%s' and `%s.%s.%s' have tag `%s'",
4320 name
, fld
->name
, validf
->name
,
4321 name
, fld
->name
, ufld
->name
, tag
);
4325 write_field_root (f
, v
, type
, name
, 0, line
, if_marked
,
4326 emit_pch
, validf
->type
,
4327 ACONCAT ((fld
->name
, ".",
4328 validf
->name
, NULL
)));
4331 error_at_line (line
,
4332 "global `%s.%s' has `desc' option but is not union",
4335 write_field_root (f
, v
, type
, name
, 0, line
, if_marked
,
4336 emit_pch
, fld
->type
, fld
->name
);
4344 newname
= xasprintf ("%s[0]", name
);
4345 write_root (f
, v
, type
->u
.a
.p
, newname
, has_length
, line
, if_marked
,
4351 case TYPE_USER_STRUCT
:
4352 error_at_line (line
, "`%s' must be a pointer type, because it is "
4353 "a GC root and its type is marked with GTY((user))",
4361 if (!start_root_entry (f
, v
, name
, line
))
4366 if (!has_length
&& union_or_struct_p (tp
))
4368 const char *id_for_tag
= filter_type_name (tp
->u
.s
.tag
);
4369 oprintf (f
, " >_ggc_mx_%s,\n", id_for_tag
);
4371 oprintf (f
, " >_pch_nx_%s", id_for_tag
);
4373 oprintf (f
, " NULL");
4374 if (id_for_tag
!= tp
->u
.s
.tag
)
4375 free (CONST_CAST (char *, id_for_tag
));
4377 else if (!has_length
&& tp
->kind
== TYPE_PARAM_STRUCT
)
4379 oprintf (f
, " >_ggc_m_");
4380 output_mangled_typename (f
, tp
);
4383 oprintf (f
, ",\n >_pch_n_");
4384 output_mangled_typename (f
, tp
);
4387 oprintf (f
, ",\n NULL");
4390 && (tp
->kind
== TYPE_POINTER
|| union_or_struct_p (tp
)))
4392 oprintf (f
, " >_ggc_ma_%s,\n", name
);
4394 oprintf (f
, " >_pch_na_%s", name
);
4396 oprintf (f
, " NULL");
4400 error_at_line (line
,
4401 "global `%s' is pointer to unimplemented type",
4405 oprintf (f
, ",\n &%s", if_marked
);
4406 oprintf (f
, "\n },\n");
4412 if (!start_root_entry (f
, v
, name
, line
))
4415 oprintf (f
, " (gt_pointer_walker) >_ggc_m_S,\n");
4416 oprintf (f
, " (gt_pointer_walker) >_pch_n_S\n");
4417 oprintf (f
, " },\n");
4425 case TYPE_UNDEFINED
:
4427 case TYPE_LANG_STRUCT
:
4428 case TYPE_PARAM_STRUCT
:
4429 error_at_line (line
, "global `%s' is unimplemented type", name
);
4433 /* This generates a routine to walk an array. */
4436 write_array (outf_p f
, pair_p v
, const struct write_types_data
*wtd
)
4438 struct walk_type_data d
;
4441 memset (&d
, 0, sizeof (d
));
4447 d
.bitmap
= get_lang_bitmap (v
->line
.file
);
4450 d
.prev_val
[3] = prevval3
= xasprintf ("&%s", v
->name
);
4452 if (wtd
->param_prefix
)
4454 oprintf (f
, "static void gt_%sa_%s\n", wtd
->param_prefix
, v
->name
);
4455 oprintf (f
, " (void *, void *, gt_pointer_operator, void *);\n");
4456 oprintf (f
, "static void gt_%sa_%s (ATTRIBUTE_UNUSED void *this_obj,\n",
4457 wtd
->param_prefix
, v
->name
);
4459 " ATTRIBUTE_UNUSED void *x_p,\n"
4460 " ATTRIBUTE_UNUSED gt_pointer_operator op,\n"
4461 " ATTRIBUTE_UNUSED void * cookie)\n");
4462 oprintf (d
.of
, "{\n");
4463 d
.prev_val
[0] = d
.prev_val
[1] = d
.prev_val
[2] = d
.val
= v
->name
;
4464 d
.process_field
= write_types_local_process_field
;
4465 d
.have_this_obj
= true;
4466 walk_type (v
->type
, &d
);
4467 oprintf (f
, "}\n\n");
4471 oprintf (f
, "static void gt_%sa_%s (void *);\n", wtd
->prefix
, v
->name
);
4472 oprintf (f
, "static void\ngt_%sa_%s (ATTRIBUTE_UNUSED void *x_p)\n",
4473 wtd
->prefix
, v
->name
);
4475 d
.prev_val
[0] = d
.prev_val
[1] = d
.prev_val
[2] = d
.val
= v
->name
;
4476 d
.process_field
= write_types_process_field
;
4477 d
.have_this_obj
= false;
4478 walk_type (v
->type
, &d
);
4480 oprintf (f
, "}\n\n");
4483 /* Output a table describing the locations and types of VARIABLES. */
4486 write_roots (pair_p variables
, bool emit_pch
)
4489 struct flist
*flp
= NULL
;
4491 for (v
= variables
; v
; v
= v
->next
)
4494 get_output_file_with_visibility (CONST_CAST (input_file
*,
4497 const char *length
= NULL
;
4498 int deletable_p
= 0;
4500 for (o
= v
->opt
; o
; o
= o
->next
)
4501 if (strcmp (o
->name
, "length") == 0
4502 && o
->kind
== OPTION_STRING
)
4503 length
= o
->info
.string
;
4504 else if (strcmp (o
->name
, "deletable") == 0)
4506 else if (strcmp (o
->name
, "param_is") == 0)
4508 else if (strncmp (o
->name
, "param", 5) == 0
4509 && ISDIGIT (o
->name
[5]) && strcmp (o
->name
+ 6, "_is") == 0)
4511 else if (strcmp (o
->name
, "if_marked") == 0)
4514 error_at_line (&v
->line
,
4515 "global `%s' has unknown option `%s'",
4518 for (fli
= flp
; fli
; fli
= fli
->next
)
4519 if (fli
->f
== f
&& f
)
4523 fli
= XNEW (struct flist
);
4527 fli
->file
= v
->line
.file
;
4528 gcc_assert (fli
->file
);
4531 oprintf (f
, "\n/* GC roots. */\n\n");
4536 && v
->type
->kind
== TYPE_POINTER
4537 && (v
->type
->u
.p
->kind
== TYPE_POINTER
4538 || v
->type
->u
.p
->kind
== TYPE_STRUCT
))
4540 write_array (f
, v
, &ggc_wtd
);
4541 write_array (f
, v
, &pch_wtd
);
4545 for (v
= variables
; v
; v
= v
->next
)
4547 outf_p f
= get_output_file_with_visibility (CONST_CAST (input_file
*,
4554 for (o
= v
->opt
; o
; o
= o
->next
)
4555 if (strcmp (o
->name
, "length") == 0)
4557 else if (strcmp (o
->name
, "deletable") == 0
4558 || strcmp (o
->name
, "if_marked") == 0)
4564 for (fli
= flp
; fli
; fli
= fli
->next
)
4567 if (!fli
->started_p
)
4571 oprintf (f
, "EXPORTED_CONST struct ggc_root_tab gt_ggc_r_");
4572 put_mangled_filename (f
, v
->line
.file
);
4573 oprintf (f
, "[] = {\n");
4576 write_root (f
, v
, v
->type
, v
->name
, length_p
, &v
->line
, NULL
, emit_pch
);
4579 finish_root_table (flp
, "ggc_r", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
4582 for (v
= variables
; v
; v
= v
->next
)
4584 outf_p f
= get_output_file_with_visibility (CONST_CAST (input_file
*,
4590 for (o
= v
->opt
; o
; o
= o
->next
)
4591 if (strcmp (o
->name
, "deletable") == 0)
4593 else if (strcmp (o
->name
, "if_marked") == 0)
4599 for (fli
= flp
; fli
; fli
= fli
->next
)
4602 if (!fli
->started_p
)
4606 oprintf (f
, "EXPORTED_CONST struct ggc_root_tab gt_ggc_rd_");
4607 put_mangled_filename (f
, v
->line
.file
);
4608 oprintf (f
, "[] = {\n");
4611 oprintf (f
, " { &%s, 1, sizeof (%s), NULL, NULL },\n",
4615 finish_root_table (flp
, "ggc_rd", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
4616 "gt_ggc_deletable_rtab");
4618 for (v
= variables
; v
; v
= v
->next
)
4620 outf_p f
= get_output_file_with_visibility (CONST_CAST (input_file
*,
4623 const char *if_marked
= NULL
;
4627 for (o
= v
->opt
; o
; o
= o
->next
)
4628 if (strcmp (o
->name
, "length") == 0)
4630 else if (strcmp (o
->name
, "if_marked") == 0
4631 && o
->kind
== OPTION_STRING
)
4632 if_marked
= o
->info
.string
;
4633 if (if_marked
== NULL
)
4635 if (v
->type
->kind
!= TYPE_POINTER
4636 || v
->type
->u
.p
->kind
!= TYPE_PARAM_STRUCT
4637 || v
->type
->u
.p
->u
.param_struct
.stru
!= find_structure ("htab",
4640 error_at_line (&v
->line
,
4641 "if_marked option used but not hash table");
4645 for (fli
= flp
; fli
; fli
= fli
->next
)
4648 if (!fli
->started_p
)
4652 oprintf (f
, "EXPORTED_CONST struct ggc_cache_tab gt_ggc_rc_");
4653 put_mangled_filename (f
, v
->line
.file
);
4654 oprintf (f
, "[] = {\n");
4657 write_root (f
, v
, v
->type
->u
.p
->u
.param_struct
.param
[0],
4658 v
->name
, length_p
, &v
->line
, if_marked
, emit_pch
);
4661 finish_root_table (flp
, "ggc_rc", "LAST_GGC_CACHE_TAB", "ggc_cache_tab",
4662 "gt_ggc_cache_rtab");
4667 for (v
= variables
; v
; v
= v
->next
)
4669 outf_p f
= get_output_file_with_visibility (CONST_CAST (input_file
*,
4673 int if_marked_p
= 0;
4676 for (o
= v
->opt
; o
; o
= o
->next
)
4677 if (strcmp (o
->name
, "length") == 0)
4679 else if (strcmp (o
->name
, "if_marked") == 0)
4685 for (fli
= flp
; fli
; fli
= fli
->next
)
4688 if (!fli
->started_p
)
4692 oprintf (f
, "EXPORTED_CONST struct ggc_root_tab gt_pch_rc_");
4693 put_mangled_filename (f
, v
->line
.file
);
4694 oprintf (f
, "[] = {\n");
4697 write_root (f
, v
, v
->type
, v
->name
, length_p
, &v
->line
, NULL
, emit_pch
);
4700 finish_root_table (flp
, "pch_rc", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
4701 "gt_pch_cache_rtab");
4703 for (v
= variables
; v
; v
= v
->next
)
4705 outf_p f
= get_output_file_with_visibility (CONST_CAST (input_file
*,
4711 for (o
= v
->opt
; o
; o
= o
->next
)
4712 if (strcmp (o
->name
, "deletable") == 0
4713 || strcmp (o
->name
, "if_marked") == 0)
4722 if (!contains_scalar_p (v
->type
))
4725 for (fli
= flp
; fli
; fli
= fli
->next
)
4728 if (!fli
->started_p
)
4732 oprintf (f
, "EXPORTED_CONST struct ggc_root_tab gt_pch_rs_");
4733 put_mangled_filename (f
, v
->line
.file
);
4734 oprintf (f
, "[] = {\n");
4737 oprintf (f
, " { &%s, 1, sizeof (%s), NULL, NULL },\n",
4741 finish_root_table (flp
, "pch_rs", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
4742 "gt_pch_scalar_rtab");
4745 /* TRUE if type S has the GTY variable_size annotation. */
4748 variable_size_p (const type_p s
)
4751 for (o
= s
->u
.s
.opt
; o
; o
= o
->next
)
4752 if (strcmp (o
->name
, "variable_size") == 0)
4760 /* Writes one typed allocator definition into output F for type
4761 identifier TYPE_NAME with optional type specifier TYPE_SPECIFIER.
4762 The allocator name will contain ALLOCATOR_TYPE. If VARIABLE_SIZE
4763 is true, the allocator will have an extra parameter specifying
4764 number of bytes to allocate. If QUANTITY is set to VECTOR, a
4765 vector allocator will be output. */
4768 write_typed_alloc_def (outf_p f
,
4769 bool variable_size
, const char *type_specifier
,
4770 const char *type_name
, const char *allocator_type
,
4771 enum alloc_quantity quantity
)
4773 bool two_args
= variable_size
&& (quantity
== vector
);
4774 gcc_assert (f
!= NULL
);
4775 const char *type_name_as_id
= filter_type_name (type_name
);
4776 oprintf (f
, "#define ggc_alloc_%s%s", allocator_type
, type_name_as_id
);
4777 oprintf (f
, "(%s%s%s) ",
4778 (variable_size
? "SIZE" : ""),
4779 (two_args
? ", " : ""),
4780 (quantity
== vector
) ? "n" : "");
4781 oprintf (f
, "((%s%s *)", type_specifier
, type_name
);
4782 oprintf (f
, "(ggc_internal_%salloc_stat (", allocator_type
);
4784 oprintf (f
, "SIZE");
4786 oprintf (f
, "sizeof (%s%s)", type_specifier
, type_name
);
4787 if (quantity
== vector
)
4789 oprintf (f
, " MEM_STAT_INFO)))\n");
4790 if (type_name_as_id
!= type_name
)
4791 free (CONST_CAST (char *, type_name_as_id
));
4794 /* Writes a typed allocator definition into output F for a struct or
4795 union S, with a given ALLOCATOR_TYPE and QUANTITY for ZONE. */
4798 write_typed_struct_alloc_def (outf_p f
,
4799 const type_p s
, const char *allocator_type
,
4800 enum alloc_quantity quantity
)
4802 gcc_assert (union_or_struct_p (s
));
4803 write_typed_alloc_def (f
, variable_size_p (s
), get_type_specifier (s
),
4804 s
->u
.s
.tag
, allocator_type
, quantity
);
4807 /* Writes a typed allocator definition into output F for a typedef P,
4808 with a given ALLOCATOR_TYPE and QUANTITY for ZONE. */
4811 write_typed_typedef_alloc_def (outf_p f
,
4812 const pair_p p
, const char *allocator_type
,
4813 enum alloc_quantity quantity
)
4815 write_typed_alloc_def (f
, variable_size_p (p
->type
), "", p
->name
,
4816 allocator_type
, quantity
);
4819 /* Writes typed allocator definitions into output F for the types in
4820 STRUCTURES and TYPEDEFS that are used by GC. */
4823 write_typed_alloc_defns (outf_p f
,
4824 const type_p structures
, const pair_p typedefs
)
4829 gcc_assert (f
!= NULL
);
4831 "\n/* Allocators for known structs and unions. */\n\n");
4832 for (s
= structures
; s
; s
= s
->next
)
4834 if (!USED_BY_TYPED_GC_P (s
))
4836 gcc_assert (union_or_struct_p (s
));
4837 /* In plugin mode onput output ggc_alloc macro definitions
4838 relevant to plugin input files. */
4839 if (nb_plugin_files
> 0
4840 && ((s
->u
.s
.line
.file
== NULL
) || !s
->u
.s
.line
.file
->inpisplugin
))
4842 write_typed_struct_alloc_def (f
, s
, "", single
);
4843 write_typed_struct_alloc_def (f
, s
, "cleared_", single
);
4844 write_typed_struct_alloc_def (f
, s
, "vec_", vector
);
4845 write_typed_struct_alloc_def (f
, s
, "cleared_vec_", vector
);
4848 oprintf (f
, "\n/* Allocators for known typedefs. */\n");
4849 for (p
= typedefs
; p
; p
= p
->next
)
4852 if (!USED_BY_TYPED_GC_P (s
) || (strcmp (p
->name
, s
->u
.s
.tag
) == 0))
4854 /* In plugin mode onput output ggc_alloc macro definitions
4855 relevant to plugin input files. */
4856 if (nb_plugin_files
> 0)
4858 struct fileloc
* filoc
= type_fileloc (s
);
4859 if (!filoc
|| !filoc
->file
->inpisplugin
)
4862 write_typed_typedef_alloc_def (f
, p
, "", single
);
4863 write_typed_typedef_alloc_def (f
, p
, "cleared_", single
);
4864 write_typed_typedef_alloc_def (f
, p
, "vec_", vector
);
4865 write_typed_typedef_alloc_def (f
, p
, "cleared_vec_", vector
);
4869 /* Prints not-as-ugly version of a typename of T to OF. Trades the uniquness
4870 guaranteee for somewhat increased readability. If name conflicts do happen,
4871 this funcion will have to be adjusted to be more like
4872 output_mangled_typename. */
4875 output_typename (outf_p of
, const_type_p t
)
4880 oprintf (of
, "str");
4883 oprintf (of
, "scalar");
4886 output_typename (of
, t
->u
.p
);
4889 case TYPE_USER_STRUCT
:
4891 case TYPE_LANG_STRUCT
:
4892 oprintf (of
, "%s", t
->u
.s
.tag
);
4894 case TYPE_PARAM_STRUCT
:
4897 for (i
= 0; i
< NUM_PARAM
; i
++)
4898 if (t
->u
.param_struct
.param
[i
] != NULL
)
4900 output_typename (of
, t
->u
.param_struct
.param
[i
]);
4903 output_typename (of
, t
->u
.param_struct
.stru
);
4907 case TYPE_UNDEFINED
:
4913 /* Writes a typed GC allocator for type S that is suitable as a callback for
4914 the splay tree implementation in libiberty. */
4917 write_splay_tree_allocator_def (const_type_p s
)
4919 outf_p of
= get_output_file_with_visibility (NULL
);
4920 oprintf (of
, "void * ggc_alloc_splay_tree_");
4921 output_typename (of
, s
);
4922 oprintf (of
, " (int sz, void * nl)\n");
4923 oprintf (of
, "{\n");
4924 oprintf (of
, " return ggc_splay_alloc (sz, nl);\n");
4925 oprintf (of
, "}\n\n");
4928 /* Writes typed GC allocators for PARAM_STRUCTS that are suitable as callbacks
4929 for the splay tree implementation in libiberty. */
4932 write_splay_tree_allocators (const_type_p param_structs
)
4936 oprintf (header_file
, "\n/* Splay tree callback allocators. */\n");
4937 for (s
= param_structs
; s
; s
= s
->next
)
4938 if (s
->gc_used
== GC_POINTED_TO
)
4940 oprintf (header_file
, "extern void * ggc_alloc_splay_tree_");
4941 output_typename (header_file
, s
);
4942 oprintf (header_file
, " (int, void *);\n");
4943 write_splay_tree_allocator_def (s
);
4949 /* Dumps the value of typekind KIND. */
4952 dump_typekind (int indent
, enum typekind kind
)
4954 printf ("%*ckind = ", indent
, ' ');
4958 printf ("TYPE_SCALAR");
4961 printf ("TYPE_STRING");
4964 printf ("TYPE_STRUCT");
4966 case TYPE_UNDEFINED
:
4967 printf ("TYPE_UNDEFINED");
4969 case TYPE_USER_STRUCT
:
4970 printf ("TYPE_USER_STRUCT");
4973 printf ("TYPE_UNION");
4976 printf ("TYPE_POINTER");
4979 printf ("TYPE_ARRAY");
4981 case TYPE_LANG_STRUCT
:
4982 printf ("TYPE_LANG_STRUCT");
4984 case TYPE_PARAM_STRUCT
:
4985 printf ("TYPE_PARAM_STRUCT");
4993 /* Dumps the value of GC_USED flag. */
4996 dump_gc_used (int indent
, enum gc_used_enum gc_used
)
4998 printf ("%*cgc_used = ", indent
, ' ');
5002 printf ("GC_UNUSED");
5007 case GC_MAYBE_POINTED_TO
:
5008 printf ("GC_MAYBE_POINTED_TO");
5011 printf ("GC_POINTED_TO");
5019 /* Dumps the type options OPT. */
5022 dump_options (int indent
, options_p opt
)
5025 printf ("%*coptions = ", indent
, ' ');
5032 printf ("%s:string %s ", o
->name
, o
->info
.string
);
5035 printf ("%s:type ", o
->name
);
5036 dump_type (indent
+1, o
->info
.type
);
5039 printf ("%s:nested ", o
->name
);
5049 /* Dumps the source file location in LINE. */
5052 dump_fileloc (int indent
, struct fileloc line
)
5054 printf ("%*cfileloc: file = %s, line = %d\n", indent
, ' ',
5055 get_input_file_name (line
.file
),
5059 /* Recursively dumps the struct, union, or a language-specific
5063 dump_type_u_s (int indent
, type_p t
)
5067 gcc_assert (union_or_struct_p (t
));
5068 printf ("%*cu.s.tag = %s\n", indent
, ' ', t
->u
.s
.tag
);
5069 dump_fileloc (indent
, t
->u
.s
.line
);
5070 printf ("%*cu.s.fields =\n", indent
, ' ');
5071 fields
= t
->u
.s
.fields
;
5074 dump_pair (indent
+ INDENT
, fields
);
5075 fields
= fields
->next
;
5077 printf ("%*cend of fields of type %p\n", indent
, ' ', (void *) t
);
5078 dump_options (indent
, t
->u
.s
.opt
);
5079 printf ("%*cu.s.bitmap = %X\n", indent
, ' ', t
->u
.s
.bitmap
);
5080 if (t
->kind
== TYPE_LANG_STRUCT
)
5082 printf ("%*cu.s.lang_struct:\n", indent
, ' ');
5083 dump_type_list (indent
+ INDENT
, t
->u
.s
.lang_struct
);
5087 /* Recursively dumps the array T. */
5090 dump_type_u_a (int indent
, type_p t
)
5092 gcc_assert (t
->kind
== TYPE_ARRAY
);
5093 printf ("%*clen = %s, u.a.p:\n", indent
, ' ', t
->u
.a
.len
);
5094 dump_type_list (indent
+ INDENT
, t
->u
.a
.p
);
5097 /* Recursively dumps the parameterized struct T. */
5100 dump_type_u_param_struct (int indent
, type_p t
)
5103 gcc_assert (t
->kind
== TYPE_PARAM_STRUCT
);
5104 printf ("%*cu.param_struct.stru:\n", indent
, ' ');
5105 dump_type_list (indent
, t
->u
.param_struct
.stru
);
5106 dump_fileloc (indent
, t
->u
.param_struct
.line
);
5107 for (i
= 0; i
< NUM_PARAM
; i
++)
5109 if (t
->u
.param_struct
.param
[i
] == NULL
)
5111 printf ("%*cu.param_struct.param[%d]:\n", indent
, ' ', i
);
5112 dump_type (indent
+ INDENT
, t
->u
.param_struct
.param
[i
]);
5116 /* Recursively dumps the type list T. */
5119 dump_type_list (int indent
, type_p t
)
5124 dump_type (indent
, p
);
5129 static htab_t seen_types
;
5131 /* Recursively dumps the type T if it was not dumped previously. */
5134 dump_type (int indent
, type_p t
)
5138 if (seen_types
== NULL
)
5139 seen_types
= htab_create (100, htab_hash_pointer
, htab_eq_pointer
, NULL
);
5141 printf ("%*cType at %p: ", indent
, ' ', (void *) t
);
5142 slot
= htab_find_slot (seen_types
, t
, INSERT
);
5145 printf ("already seen.\n");
5151 dump_typekind (indent
, t
->kind
);
5152 printf ("%*cpointer_to = %p\n", indent
+ INDENT
, ' ',
5153 (void *) t
->pointer_to
);
5154 dump_gc_used (indent
+ INDENT
, t
->gc_used
);
5158 printf ("%*cscalar_is_char = %s\n", indent
+ INDENT
, ' ',
5159 t
->u
.scalar_is_char
? "true" : "false");
5165 case TYPE_LANG_STRUCT
:
5166 case TYPE_USER_STRUCT
:
5167 dump_type_u_s (indent
+ INDENT
, t
);
5170 printf ("%*cp:\n", indent
+ INDENT
, ' ');
5171 dump_type (indent
+ INDENT
, t
->u
.p
);
5174 dump_type_u_a (indent
+ INDENT
, t
);
5176 case TYPE_PARAM_STRUCT
:
5177 dump_type_u_param_struct (indent
+ INDENT
, t
);
5182 printf ("%*cEnd of type at %p\n", indent
, ' ', (void *) t
);
5185 /* Dumps the pair P. */
5188 dump_pair (int indent
, pair_p p
)
5190 printf ("%*cpair: name = %s\n", indent
, ' ', p
->name
);
5191 dump_type (indent
, p
->type
);
5192 dump_fileloc (indent
, p
->line
);
5193 dump_options (indent
, p
->opt
);
5194 printf ("%*cEnd of pair %s\n", indent
, ' ', p
->name
);
5197 /* Dumps the list of pairs PP. */
5200 dump_pair_list (const char *name
, pair_p pp
)
5203 printf ("%s:\n", name
);
5204 for (p
= pp
; p
!= NULL
; p
= p
->next
)
5206 printf ("End of %s\n\n", name
);
5209 /* Dumps the STRUCTURES. */
5212 dump_structures (const char *name
, type_p structures
)
5214 printf ("%s:\n", name
);
5215 dump_type_list (0, structures
);
5216 printf ("End of %s\n\n", name
);
5219 /* Dumps the internal structures of gengtype. This is useful to debug
5220 gengtype itself, or to understand what it does, e.g. for plugin
5224 dump_everything (void)
5226 dump_pair_list ("typedefs", typedefs
);
5227 dump_structures ("structures", structures
);
5228 dump_structures ("param_structs", param_structs
);
5229 dump_pair_list ("variables", variables
);
5231 /* Allocated with the first call to dump_type. */
5232 htab_delete (seen_types
);
5237 /* Option specification for getopt_long. */
5238 static const struct option gengtype_long_options
[] = {
5239 {"help", no_argument
, NULL
, 'h'},
5240 {"version", no_argument
, NULL
, 'V'},
5241 {"verbose", no_argument
, NULL
, 'v'},
5242 {"dump", no_argument
, NULL
, 'd'},
5243 {"debug", no_argument
, NULL
, 'D'},
5244 {"plugin", required_argument
, NULL
, 'P'},
5245 {"srcdir", required_argument
, NULL
, 'S'},
5246 {"backupdir", required_argument
, NULL
, 'B'},
5247 {"inputs", required_argument
, NULL
, 'I'},
5248 {"read-state", required_argument
, NULL
, 'r'},
5249 {"write-state", required_argument
, NULL
, 'w'},
5250 /* Terminating NULL placeholder. */
5251 {NULL
, no_argument
, NULL
, 0},
5258 printf ("Usage: %s\n", progname
);
5259 printf ("\t -h | --help " " \t# Give this help.\n");
5260 printf ("\t -D | --debug "
5261 " \t# Give debug output to debug %s itself.\n", progname
);
5262 printf ("\t -V | --version " " \t# Give version information.\n");
5263 printf ("\t -v | --verbose \t# Increase verbosity. Can be given several times.\n");
5264 printf ("\t -d | --dump " " \t# Dump state for debugging.\n");
5265 printf ("\t -P | --plugin <output-file> <plugin-src> ... "
5266 " \t# Generate for plugin.\n");
5267 printf ("\t -S | --srcdir <GCC-directory> "
5268 " \t# Specify the GCC source directory.\n");
5269 printf ("\t -B | --backupdir <directory> "
5270 " \t# Specify the backup directory for updated files.\n");
5271 printf ("\t -I | --inputs <input-list> "
5272 " \t# Specify the file with source files list.\n");
5273 printf ("\t -w | --write-state <state-file> " " \t# Write a state file.\n");
5274 printf ("\t -r | --read-state <state-file> " " \t# Read a state file.\n");
5278 print_version (void)
5280 printf ("%s %s%s\n", progname
, pkgversion_string
, version_string
);
5281 printf ("Report bugs: %s\n", bug_report_url
);
5284 /* Parse the program options using getopt_long... */
5286 parse_program_options (int argc
, char **argv
)
5289 while ((opt
= getopt_long (argc
, argv
, "hVvdP:S:B:I:w:r:D",
5290 gengtype_long_options
, NULL
)) >= 0)
5294 case 'h': /* --help */
5297 case 'V': /* --version */
5300 case 'd': /* --dump */
5303 case 'D': /* --debug */
5306 case 'v': /* --verbose */
5309 case 'P': /* --plugin */
5311 plugin_output_filename
= optarg
;
5313 fatal ("missing plugin output file name");
5315 case 'S': /* --srcdir */
5319 fatal ("missing source directory");
5320 srcdir_len
= strlen (srcdir
);
5322 case 'B': /* --backupdir */
5324 backup_dir
= optarg
;
5326 fatal ("missing backup directory");
5328 case 'I': /* --inputs */
5332 fatal ("missing input list");
5334 case 'r': /* --read-state */
5336 read_state_filename
= optarg
;
5338 fatal ("missing read state file");
5339 DBGPRINTF ("read state %s\n", optarg
);
5341 case 'w': /* --write-state */
5342 DBGPRINTF ("write state %s\n", optarg
);
5344 write_state_filename
= optarg
;
5346 fatal ("missing write state file");
5349 fprintf (stderr
, "%s: unknown flag '%c'\n", progname
, opt
);
5351 fatal ("unexpected flag");
5354 if (plugin_output_filename
)
5356 /* In plugin mode we require some input files. */
5359 fatal ("no source files given in plugin mode");
5360 nb_plugin_files
= argc
- optind
;
5361 plugin_files
= XNEWVEC (input_file
*, nb_plugin_files
);
5362 for (i
= 0; i
< (int) nb_plugin_files
; i
++)
5364 char *name
= argv
[i
+ optind
];
5365 plugin_files
[i
] = input_file_by_name (name
);
5372 /******* Manage input files. ******/
5374 /* Hash table of unique input file names. */
5375 static htab_t input_file_htab
;
5377 /* Find or allocate a new input_file by hash-consing it. */
5379 input_file_by_name (const char* name
)
5382 input_file
* f
= NULL
;
5386 namlen
= strlen (name
);
5387 f
= XCNEWVAR (input_file
, sizeof (input_file
)+namlen
+2);
5390 f
->inpisplugin
= false;
5391 strcpy (f
->inpname
, name
);
5392 slot
= htab_find_slot (input_file_htab
, f
, INSERT
);
5393 gcc_assert (slot
!= NULL
);
5396 /* Already known input file. */
5398 return (input_file
*)(*slot
);
5400 /* New input file. */
5405 /* Hash table support routines for input_file-s. */
5407 htab_hash_inputfile (const void *p
)
5409 const input_file
*inpf
= (const input_file
*) p
;
5411 return htab_hash_string (get_input_file_name (inpf
));
5415 htab_eq_inputfile (const void *x
, const void *y
)
5417 const input_file
*inpfx
= (const input_file
*) x
;
5418 const input_file
*inpfy
= (const input_file
*) y
;
5419 gcc_assert (inpfx
!= NULL
&& inpfy
!= NULL
);
5420 return !filename_cmp (get_input_file_name (inpfx
), get_input_file_name (inpfy
));
5425 main (int argc
, char **argv
)
5428 static struct fileloc pos
= { NULL
, 0 };
5429 outf_p output_header
;
5431 /* Mandatory common initializations. */
5432 progname
= "gengtype"; /* For fatal and messages. */
5433 /* Create the hash-table used to hash-cons input files. */
5435 htab_create (800, htab_hash_inputfile
, htab_eq_inputfile
, NULL
);
5436 /* Initialize our special input files. */
5437 this_file
= input_file_by_name (__FILE__
);
5438 system_h_file
= input_file_by_name ("system.h");
5439 /* Set the scalar_is_char union number for predefined scalar types. */
5440 scalar_nonchar
.u
.scalar_is_char
= FALSE
;
5441 scalar_char
.u
.scalar_is_char
= TRUE
;
5443 parse_program_options (argc
, argv
);
5448 time_t now
= (time_t) 0;
5450 DBGPRINTF ("gengtype started pid %d at %s",
5451 (int) getpid (), ctime (&now
));
5453 #endif /* ENABLE_CHECKING */
5455 /* Parse the input list and the input files. */
5456 DBGPRINTF ("inputlist %s", inputlist
);
5457 if (read_state_filename
)
5460 fatal ("input list %s cannot be given with a read state file %s",
5461 inputlist
, read_state_filename
);
5462 read_state (read_state_filename
);
5463 DBGPRINT_COUNT_TYPE ("structures after read_state", structures
);
5464 DBGPRINT_COUNT_TYPE ("param_structs after read_state", param_structs
);
5468 /* These types are set up with #define or else outside of where
5469 we can see them. We should initialize them before calling
5471 #define POS_HERE(Call) do { pos.file = this_file; pos.line = __LINE__; \
5473 POS_HERE (do_scalar_typedef ("CUMULATIVE_ARGS", &pos
));
5474 POS_HERE (do_scalar_typedef ("REAL_VALUE_TYPE", &pos
));
5475 POS_HERE (do_scalar_typedef ("FIXED_VALUE_TYPE", &pos
));
5476 POS_HERE (do_scalar_typedef ("double_int", &pos
));
5477 POS_HERE (do_scalar_typedef ("double_int_storage", &pos
));
5478 POS_HERE (do_scalar_typedef ("offset_int", &pos
));
5479 POS_HERE (do_scalar_typedef ("widest_int", &pos
));
5480 POS_HERE (do_scalar_typedef ("uint64_t", &pos
));
5481 POS_HERE (do_scalar_typedef ("uint8", &pos
));
5482 POS_HERE (do_scalar_typedef ("uintptr_t", &pos
));
5483 POS_HERE (do_scalar_typedef ("jword", &pos
));
5484 POS_HERE (do_scalar_typedef ("JCF_u2", &pos
));
5485 POS_HERE (do_scalar_typedef ("void", &pos
));
5486 POS_HERE (do_typedef ("PTR",
5487 create_pointer (resolve_typedef ("void", &pos
)),
5490 read_input_list (inputlist
);
5491 for (i
= 0; i
< num_gt_files
; i
++)
5493 parse_file (get_input_file_name (gt_files
[i
]));
5494 DBGPRINTF ("parsed file #%d %s",
5495 (int) i
, get_input_file_name (gt_files
[i
]));
5497 if (verbosity_level
>= 1)
5498 printf ("%s parsed %d files with %d GTY types\n",
5499 progname
, (int) num_gt_files
, type_count
);
5501 DBGPRINT_COUNT_TYPE ("structures after parsing", structures
);
5502 DBGPRINT_COUNT_TYPE ("param_structs after parsing", param_structs
);
5506 fatal ("either an input list or a read state file should be given");
5511 if (plugin_output_filename
)
5514 /* In plugin mode, we should have read a state file, and have
5515 given at least one plugin file. */
5516 if (!read_state_filename
)
5517 fatal ("No read state given in plugin mode for %s",
5518 plugin_output_filename
);
5520 if (nb_plugin_files
== 0 || !plugin_files
)
5521 fatal ("No plugin files given in plugin mode for %s",
5522 plugin_output_filename
);
5524 /* Parse our plugin files and augment the state. */
5525 for (ix
= 0; ix
< nb_plugin_files
; ix
++)
5527 input_file
* pluginput
= plugin_files
[ix
];
5528 pluginput
->inpisplugin
= true;
5529 parse_file (get_input_file_name (pluginput
));
5534 plugin_output
= create_file ("GCC", plugin_output_filename
);
5535 DBGPRINTF ("created plugin_output %p named %s",
5536 (void *) plugin_output
, plugin_output
->name
);
5539 { /* No plugin files, we are in normal mode. */
5541 fatal ("gengtype needs a source directory in normal mode");
5548 /* The call to set_gc_used may indirectly call find_param_structure
5549 hence enlarge the param_structs list of types. */
5550 set_gc_used (variables
);
5552 /* The state at this point is read from the state input file or by
5553 parsing source files and optionally augmented by parsing plugin
5554 source files. Write it now. */
5555 if (write_state_filename
)
5557 DBGPRINT_COUNT_TYPE ("structures before write_state", structures
);
5558 DBGPRINT_COUNT_TYPE ("param_structs before write_state", param_structs
);
5561 fatal ("didn't write state file %s after errors",
5562 write_state_filename
);
5564 DBGPRINTF ("before write_state %s", write_state_filename
);
5565 write_state (write_state_filename
);
5570 /* After having written the state file we return immediately to
5571 avoid generating any output file. */
5581 output_header
= plugin_output
? plugin_output
: header_file
;
5582 write_typed_alloc_defns (output_header
, structures
, typedefs
);
5583 DBGPRINT_COUNT_TYPE ("structures before write_types outputheader",
5585 DBGPRINT_COUNT_TYPE ("param_structs before write_types outputheader",
5588 write_types (output_header
, structures
, param_structs
, &ggc_wtd
);
5589 if (plugin_files
== NULL
)
5591 DBGPRINT_COUNT_TYPE ("structures before write_types headerfil",
5593 DBGPRINT_COUNT_TYPE ("param_structs before write_types headerfil",
5595 write_types (header_file
, structures
, param_structs
, &pch_wtd
);
5596 write_local (header_file
, structures
, param_structs
);
5598 write_splay_tree_allocators (param_structs
);
5599 write_roots (variables
, plugin_files
== NULL
);
5601 close_output_files ();
5606 /* Don't bother about free-ing any input or plugin file, etc. */