1 /* Process source files and output type information.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
24 #include "errors.h" /* for fatal */
25 #include "double-int.h"
28 /* Data types, macros, etc. used only in this file. */
30 /* Kinds of types we can understand. */
43 typedef unsigned lang_bitmap
;
45 /* A way to pass data through to the output end. */
53 /* Option data for the 'nested_ptr' option. */
54 struct nested_ptr_data
57 const char *convert_to
;
58 const char *convert_from
;
61 /* A name and a type. */
73 /* A description of a type. */
78 /* Used for structures whose definitions we haven't seen so far when
79 we encounter a pointer to it that is annotated with ``maybe_undef''.
80 If after reading in everything we don't have source file
81 information for it, we assume that it never has been defined. */
91 enum gc_used_enum gc_used
;
113 type_p param
[NUM_PARAM
];
120 ((x)->kind == TYPE_UNION || \
121 ((x)->kind == TYPE_LANG_STRUCT \
122 && (x)->u.s.lang_struct->kind == TYPE_UNION))
123 #define UNION_OR_STRUCT_P(x) \
124 ((x)->kind == TYPE_UNION \
125 || (x)->kind == TYPE_STRUCT \
126 || (x)->kind == TYPE_LANG_STRUCT)
128 /* Structure representing an output file. */
137 typedef struct outf
*outf_p
;
139 /* An output file, suitable for definitions, that can see declarations
140 made in INPUT_FILE and is linked into every language that uses
141 INPUT_FILE. May return NULL in plugin mode. */
142 extern outf_p
get_output_file_with_visibility (const char *input_file
);
143 const char *get_output_file_name (const char *);
145 /* Print, like fprintf, to O. No-op if O is NULL. */
147 oprintf (outf_p o
, const char *S
, ...)
150 /* The list of output files. */
151 static outf_p output_files
;
153 /* The plugin input files and their number; in that case only
154 a single file is produced. */
155 static char **plugin_files
;
156 static size_t nb_plugin_files
;
157 /* the generated plugin output name & file */
158 static outf_p plugin_output
;
160 /* The output header file that is included into pretty much every
162 static outf_p header_file
;
164 /* Source directory. */
165 static const char *srcdir
;
167 /* Length of srcdir name. */
168 static size_t srcdir_len
= 0;
170 static outf_p
create_file (const char *, const char *);
172 static const char *get_file_basename (const char *);
173 static const char *get_file_realbasename (const char *);
174 static const char *get_file_srcdir_relative_path (const char *);
176 static int get_prefix_langdir_index (const char *);
177 static const char *get_file_langdir (const char *);
180 /* Nonzero iff an error has occurred. */
181 bool hit_error
= false;
183 static void gen_rtx_next (void);
184 static void write_rtx_next (void);
185 static void open_base_files (void);
186 static void close_output_files (void);
188 /* Report an error at POS, printing MSG. */
191 error_at_line (const struct fileloc
*pos
, const char *msg
, ...)
197 fprintf (stderr
, "%s:%d: ", pos
->file
, pos
->line
);
198 vfprintf (stderr
, msg
, ap
);
199 fputc ('\n', stderr
);
205 /* asprintf, but produces fatal message on out-of-memory. */
207 xasprintf (const char *format
, ...)
213 va_start (ap
, format
);
214 n
= vasprintf (&result
, format
, ap
);
215 if (result
== NULL
|| n
< 0)
216 fatal ("out of memory");
222 /* Input file handling. */
224 /* Table of all input files. */
225 static const char **gt_files
;
226 static size_t num_gt_files
;
228 /* A number of places use the name of this file for a location for
229 things that we can't rely on the source to define. Make sure we
230 can still use pointer comparison on filenames. */
231 static const char this_file
[] = __FILE__
;
233 /* Vector of per-language directories. */
234 static const char **lang_dir_names
;
235 static size_t num_lang_dirs
;
237 /* An array of output files suitable for definitions. There is one
238 BASE_FILES entry for each language. */
239 static outf_p
*base_files
;
241 /* Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff
242 INPUT_FILE is used by <lang>.
244 This function should be written to assume that a file _is_ used
245 if the situation is unclear. If it wrongly assumes a file _is_ used,
246 a linker error will result. If it wrongly assumes a file _is not_ used,
247 some GC roots may be missed, which is a much harder-to-debug problem.
249 The relevant bitmap is stored immediately before the file's name in the
250 buffer set up by read_input_list. It may be unaligned, so we have to
251 read it byte-by-byte. */
254 get_lang_bitmap (const char *gtfile
)
257 if (gtfile
== this_file
)
258 /* Things defined in this file are universal. */
259 return (((lang_bitmap
) 1) << num_lang_dirs
) - 1;
264 for (i
= -(int) sizeof (lang_bitmap
); i
< 0; i
++)
265 n
= (n
<< CHAR_BIT
) + (unsigned char) gtfile
[i
];
270 /* Set the bitmap returned by get_lang_bitmap. The only legitimate
271 caller of this function is read_input_list. */
273 set_lang_bitmap (char *gtfile
, lang_bitmap n
)
276 for (i
= -1; i
>= -(int) sizeof (lang_bitmap
); i
--)
278 gtfile
[i
] = n
& ((1U << CHAR_BIT
) - 1);
283 /* Scan the input file, LIST, and determine how much space we need to
284 store strings in. Also, count the number of language directories
285 and files. The numbers returned are overestimates as they does not
286 consider repeated files. */
288 measure_input_list (FILE *list
)
294 num_gt_files
= plugin_files
? nb_plugin_files
: 0;
295 while ((c
= getc (list
)) != EOF
)
304 /* Add space for a lang_bitmap before the input file name. */
305 n
+= sizeof (lang_bitmap
);
319 /* Read one input line from LIST to HEREP (which is updated). A
320 pointer to the string is returned via LINEP. If it was a language
321 subdirectory in square brackets, strip off the square brackets and
322 return true. Otherwise, leave space before the string for a
323 lang_bitmap, and return false. At EOF, returns false, does not
324 touch *HEREP, and sets *LINEP to NULL. POS is used for
327 read_input_line (FILE *list
, char **herep
, char **linep
, struct fileloc
*pos
)
333 /* Read over whitespace. */
334 while (c
== '\n' || c
== ' ')
344 /* No space for a lang_bitmap is necessary. Discard the '['. */
347 while (c
!= ']' && c
!= '\n' && c
!= EOF
)
356 c
= getc (list
); /* eat what should be a newline */
357 if (c
!= '\n' && c
!= EOF
)
358 error_at_line (pos
, "junk on line after language tag [%s]", line
);
361 error_at_line (pos
, "missing close bracket for language tag [%s",
370 /* Leave space for a lang_bitmap. */
371 memset (here
, 0, sizeof (lang_bitmap
));
372 here
+= sizeof (lang_bitmap
);
379 while (c
!= EOF
&& c
!= '\n');
387 /* Read the list of input files from LIST and compute all of the
388 relevant tables. There is one file per line of the list. At
389 first, all the files on the list are language-generic, but
390 eventually a line will appear which is the name of a language
391 subdirectory in square brackets, like this: [cp]. All subsequent
392 files are specific to that language, until another language
393 subdirectory tag appears. Files can appear more than once, if
394 they apply to more than one language. */
396 read_input_list (const char *listname
)
398 FILE *list
= fopen (listname
, "r");
400 fatal ("cannot open %s: %s", listname
, xstrerror (errno
));
404 size_t bufsz
= measure_input_list (list
);
405 char *buf
= XNEWVEC (char, bufsz
);
407 char *committed
= buf
;
408 char *limit
= buf
+ bufsz
;
413 lang_bitmap curlangs
= (1 << num_lang_dirs
) - 1;
415 epos
.file
= listname
;
418 lang_dir_names
= XNEWVEC (const char *, num_lang_dirs
);
419 gt_files
= XNEWVEC (const char *, num_gt_files
);
426 is_language
= read_input_line (list
, &here
, &line
, &epos
);
427 gcc_assert (here
<= limit
);
430 else if (is_language
)
433 gcc_assert (langno
<= num_lang_dirs
);
434 for (i
= 0; i
< langno
; i
++)
435 if (strcmp (lang_dir_names
[i
], line
) == 0)
437 error_at_line (&epos
, "duplicate language tag [%s]",
444 curlangs
= 1 << langno
;
445 lang_dir_names
[langno
++] = line
;
450 gcc_assert (nfiles
<= num_gt_files
);
451 for (i
= 0; i
< nfiles
; i
++)
452 if (strcmp (gt_files
[i
], line
) == 0)
454 /* Throw away the string we just read, and add the
455 current language to the existing string's bitmap. */
456 lang_bitmap bmap
= get_lang_bitmap (gt_files
[i
]);
458 error_at_line (&epos
,
459 "file %s specified more than once "
460 "for language %s", line
,
462 0 ? "(all)" : lang_dir_names
[langno
-
466 set_lang_bitmap (CONST_CAST (char *, gt_files
[i
]), bmap
);
471 set_lang_bitmap (line
, curlangs
);
472 gt_files
[nfiles
++] = line
;
475 /* Update the global counts now that we know accurately how many
476 things there are. (We do not bother resizing the arrays down.) */
477 num_lang_dirs
= langno
;
478 /* Add the plugin files if provided. */
482 for (i
= 0; i
< nb_plugin_files
; i
++)
483 gt_files
[nfiles
++] = plugin_files
[i
];
485 num_gt_files
= nfiles
;
488 /* Sanity check: any file that resides in a language subdirectory
489 (e.g. 'cp') ought to belong to the corresponding language.
490 ??? Still true if for instance ObjC++ is enabled and C++ isn't?
491 (Can you even do that? Should you be allowed to?) */
494 for (f
= 0; f
< num_gt_files
; f
++)
496 lang_bitmap bitmap
= get_lang_bitmap (gt_files
[f
]);
497 const char *basename
= get_file_basename (gt_files
[f
]);
498 const char *slashpos
= strchr (basename
, '/');
503 for (l
= 0; l
< num_lang_dirs
; l
++)
504 if ((size_t) (slashpos
- basename
) == strlen (lang_dir_names
[l
])
505 && memcmp (basename
, lang_dir_names
[l
],
506 strlen (lang_dir_names
[l
])) == 0)
508 if (!(bitmap
& (1 << l
)))
509 error ("%s is in language directory '%s' but is not "
510 "tagged for that language",
511 basename
, lang_dir_names
[l
]);
519 fatal ("error reading %s: %s", listname
, xstrerror (errno
));
526 /* The one and only TYPE_STRING. */
528 static struct type string_type
= {
529 TYPE_STRING
, 0, 0, GC_USED
, {0}
532 /* The two and only TYPE_SCALARs. Their u.scalar_is_char flags are
533 set to appropriate values at the beginning of main. */
535 static struct type scalar_nonchar
= {
536 TYPE_SCALAR
, 0, 0, GC_USED
, {0}
539 static struct type scalar_char
= {
540 TYPE_SCALAR
, 0, 0, GC_USED
, {0}
543 /* Lists of various things. */
545 static pair_p typedefs
;
546 static type_p structures
;
547 static type_p param_structs
;
548 static pair_p variables
;
550 static type_p
find_param_structure (type_p t
, type_p param
[NUM_PARAM
]);
551 static type_p
adjust_field_tree_exp (type_p t
, options_p opt
);
552 static type_p
adjust_field_rtx_def (type_p t
, options_p opt
);
554 /* Define S as a typedef to T at POS. */
557 do_typedef (const char *s
, type_p t
, struct fileloc
*pos
)
561 /* temporary kludge - gengtype doesn't handle conditionals or
562 macros. Ignore any attempt to typedef CUMULATIVE_ARGS, unless it
563 is coming from this file (main() sets them up with safe dummy
565 if (!strcmp (s
, "CUMULATIVE_ARGS") && pos
->file
!= this_file
)
568 for (p
= typedefs
; p
!= NULL
; p
= p
->next
)
569 if (strcmp (p
->name
, s
) == 0)
573 error_at_line (pos
, "type `%s' previously defined", s
);
574 error_at_line (&p
->line
, "previously defined here");
579 p
= XNEW (struct pair
);
588 /* Define S as a typename of a scalar. Cannot be used to define
589 typedefs of 'char'. Note: is also used for pointer-to-function
590 typedefs (which are therefore not treated as pointers). */
593 do_scalar_typedef (const char *s
, struct fileloc
*pos
)
595 do_typedef (s
, &scalar_nonchar
, pos
);
598 /* Return the type previously defined for S. Use POS to report errors. */
601 resolve_typedef (const char *s
, struct fileloc
*pos
)
604 for (p
= typedefs
; p
!= NULL
; p
= p
->next
)
605 if (strcmp (p
->name
, s
) == 0)
607 error_at_line (pos
, "unidentified type `%s'", s
);
608 return &scalar_nonchar
; /* treat as "int" */
611 /* Create and return a new structure with tag NAME (or a union iff
612 ISUNION is nonzero), at POS with fields FIELDS and options O. */
615 new_structure (const char *name
, int isunion
, struct fileloc
*pos
,
616 pair_p fields
, options_p o
)
620 lang_bitmap bitmap
= get_lang_bitmap (pos
->file
);
622 /* temporary kludge - gengtype doesn't handle conditionals or
623 macros. Ignore any attempt to define struct location_s, unless
624 it is coming from this file (main() sets it up safely). */
625 if (!strcmp (name
, "location_s") && !isunion
&& pos
->file
!= this_file
)
626 return find_structure (name
, 0);
628 for (si
= structures
; si
!= NULL
; si
= si
->next
)
629 if (strcmp (name
, si
->u
.s
.tag
) == 0 && UNION_P (si
) == isunion
)
632 if (si
->kind
== TYPE_LANG_STRUCT
)
636 for (si
= ls
->u
.s
.lang_struct
; si
!= NULL
; si
= si
->next
)
637 if (si
->u
.s
.bitmap
== bitmap
)
640 else if (si
->u
.s
.line
.file
!= NULL
&& si
->u
.s
.bitmap
!= bitmap
)
643 si
= XCNEW (struct type
);
644 memcpy (si
, ls
, sizeof (struct type
));
645 ls
->kind
= TYPE_LANG_STRUCT
;
646 ls
->u
.s
.lang_struct
= si
;
647 ls
->u
.s
.fields
= NULL
;
649 si
->pointer_to
= NULL
;
650 si
->u
.s
.lang_struct
= ls
;
655 if (ls
!= NULL
&& s
== NULL
)
657 s
= XCNEW (struct type
);
658 s
->next
= ls
->u
.s
.lang_struct
;
659 ls
->u
.s
.lang_struct
= s
;
660 s
->u
.s
.lang_struct
= ls
;
667 s
= XCNEW (struct type
);
668 s
->next
= structures
;
672 if (s
->u
.s
.line
.file
!= NULL
673 || (s
->u
.s
.lang_struct
&& (s
->u
.s
.lang_struct
->u
.s
.bitmap
& bitmap
)))
675 error_at_line (pos
, "duplicate definition of '%s %s'",
676 isunion
? "union" : "struct", s
->u
.s
.tag
);
677 error_at_line (&s
->u
.s
.line
, "previous definition here");
680 s
->kind
= isunion
? TYPE_UNION
: TYPE_STRUCT
;
683 s
->u
.s
.fields
= fields
;
685 s
->u
.s
.bitmap
= bitmap
;
686 if (s
->u
.s
.lang_struct
)
687 s
->u
.s
.lang_struct
->u
.s
.bitmap
|= bitmap
;
689 /* Reset location_s's location to input.h so that we know where to
690 write out its mark routine. */
691 if (!strcmp (name
, "location_s") && !isunion
&& pos
->file
== this_file
)
694 for (n
= 0; n
< num_gt_files
; n
++)
695 if (!strcmp (gt_files
[n
] + strlen (gt_files
[n
]) - strlen ("input.h"),
698 s
->u
.s
.line
.file
= gt_files
[n
];
706 /* Return the previously-defined structure with tag NAME (or a union
707 iff ISUNION is nonzero), or a new empty structure or union if none
708 was defined previously. */
711 find_structure (const char *name
, int isunion
)
715 for (s
= structures
; s
!= NULL
; s
= s
->next
)
716 if (strcmp (name
, s
->u
.s
.tag
) == 0 && UNION_P (s
) == isunion
)
719 s
= XCNEW (struct type
);
720 s
->next
= structures
;
722 s
->kind
= isunion
? TYPE_UNION
: TYPE_STRUCT
;
728 /* Return the previously-defined parameterized structure for structure
729 T and parameters PARAM, or a new parameterized empty structure or
730 union if none was defined previously. */
733 find_param_structure (type_p t
, type_p param
[NUM_PARAM
])
737 for (res
= param_structs
; res
; res
= res
->next
)
738 if (res
->u
.param_struct
.stru
== t
739 && memcmp (res
->u
.param_struct
.param
, param
,
740 sizeof (type_p
) * NUM_PARAM
) == 0)
744 res
= XCNEW (struct type
);
745 res
->kind
= TYPE_PARAM_STRUCT
;
746 res
->next
= param_structs
;
748 res
->u
.param_struct
.stru
= t
;
749 memcpy (res
->u
.param_struct
.param
, param
, sizeof (type_p
) * NUM_PARAM
);
754 /* Return a scalar type with name NAME. */
757 create_scalar_type (const char *name
)
759 if (!strcmp (name
, "char") || !strcmp (name
, "unsigned char"))
762 return &scalar_nonchar
;
765 /* Return a pointer to T. */
768 create_pointer (type_p t
)
772 type_p r
= XCNEW (struct type
);
773 r
->kind
= TYPE_POINTER
;
777 return t
->pointer_to
;
780 /* Return an array of length LEN. */
783 create_array (type_p t
, const char *len
)
787 v
= XCNEW (struct type
);
788 v
->kind
= TYPE_ARRAY
;
794 /* Return an options structure with name NAME and info INFO. NEXT is the
795 next option in the chain. */
798 create_option (options_p next
, const char *name
, const void *info
)
800 options_p o
= XNEW (struct options
);
803 o
->info
= (const char *) info
;
807 /* Return an options structure for a "nested_ptr" option. */
809 create_nested_ptr_option (options_p next
, type_p t
,
810 const char *to
, const char *from
)
812 struct nested_ptr_data
*d
= XNEW (struct nested_ptr_data
);
814 d
->type
= adjust_field_type (t
, 0);
816 d
->convert_from
= from
;
817 return create_option (next
, "nested_ptr", d
);
820 /* Add a variable named S of type T with options O defined at POS,
824 note_variable (const char *s
, type_p t
, options_p o
, struct fileloc
*pos
)
827 n
= XNEW (struct pair
);
836 /* Most-general structure field creator. */
838 create_field_all (pair_p next
, type_p type
, const char *name
, options_p opt
,
839 const char *file
, int line
)
843 field
= XNEW (struct pair
);
848 field
->line
.file
= file
;
849 field
->line
.line
= line
;
853 /* Create a field that came from the source code we are scanning,
854 i.e. we have a 'struct fileloc', and possibly options; also,
855 adjust_field_type should be called. */
857 create_field_at (pair_p next
, type_p type
, const char *name
, options_p opt
,
860 return create_field_all (next
, adjust_field_type (type
, opt
),
861 name
, opt
, pos
->file
, pos
->line
);
864 /* Create a fake field with the given type and name. NEXT is the next
865 field in the chain. */
866 #define create_field(next,type,name) \
867 create_field_all(next,type,name, 0, this_file, __LINE__)
869 /* Like create_field, but the field is only valid when condition COND
873 create_optional_field_ (pair_p next
, type_p type
, const char *name
,
874 const char *cond
, int line
)
880 /* Create a fake union type with a single nameless field of type TYPE.
881 The field has a tag of "1". This allows us to make the presence
882 of a field of type TYPE depend on some boolean "desc" being true. */
883 union_fields
= create_field (NULL
, type
, "");
884 union_fields
->opt
= create_option (union_fields
->opt
, "dot", "");
885 union_fields
->opt
= create_option (union_fields
->opt
, "tag", "1");
886 union_type
= new_structure (xasprintf ("%s_%d", "fake_union", id
++), 1,
887 &lexer_line
, union_fields
, NULL
);
889 /* Create the field and give it the new fake union type. Add a "desc"
890 tag that specifies the condition under which the field is valid. */
891 return create_field_all (next
, union_type
, name
,
892 create_option (0, "desc", cond
), this_file
, line
);
895 #define create_optional_field(next,type,name,cond) \
896 create_optional_field_(next,type,name,cond,__LINE__)
898 /* Reverse a linked list of 'struct pair's in place. */
900 nreverse_pairs (pair_p list
)
902 pair_p prev
= 0, p
, next
;
903 for (p
= list
; p
; p
= next
)
913 /* We don't care how long a CONST_DOUBLE is. */
914 #define CONST_DOUBLE_FORMAT "ww"
915 /* We don't want to see codes that are only for generator files. */
916 #undef GENERATOR_FILE
920 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) ENUM ,
926 static const char *const rtx_name
[NUM_RTX_CODE
] = {
927 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME ,
932 static const char *const rtx_format
[NUM_RTX_CODE
] = {
933 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT ,
938 static int rtx_next_new
[NUM_RTX_CODE
];
940 /* We also need codes and names for insn notes (not register notes).
941 Note that we do *not* bias the note values here. */
944 #define DEF_INSN_NOTE(NAME) NAME,
945 #include "insn-notes.def"
951 /* We must allocate one more entry here, as we use NOTE_INSN_MAX as the
952 default field for line number notes. */
953 static const char *const note_insn_name
[NOTE_INSN_MAX
+ 1] = {
954 #define DEF_INSN_NOTE(NAME) #NAME,
955 #include "insn-notes.def"
959 #undef CONST_DOUBLE_FORMAT
960 #define GENERATOR_FILE
962 /* Generate the contents of the rtx_next array. This really doesn't belong
963 in gengtype at all, but it's needed for adjust_field_rtx_def. */
969 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
973 rtx_next_new
[i
] = -1;
974 if (strncmp (rtx_format
[i
], "iuu", 3) == 0)
976 else if (i
== COND_EXEC
|| i
== SET
|| i
== EXPR_LIST
|| i
== INSN_LIST
)
979 for (k
= strlen (rtx_format
[i
]) - 1; k
>= 0; k
--)
980 if (rtx_format
[i
][k
] == 'e' || rtx_format
[i
][k
] == 'u')
985 /* Write out the contents of the rtx_next array. */
987 write_rtx_next (void)
989 outf_p f
= get_output_file_with_visibility (NULL
);
994 oprintf (f
, "\n/* Used to implement the RTX_NEXT macro. */\n");
995 oprintf (f
, "EXPORTED_CONST unsigned char rtx_next[NUM_RTX_CODE] = {\n");
996 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
997 if (rtx_next_new
[i
] == -1)
998 oprintf (f
, " 0,\n");
1001 " RTX_HDR_SIZE + %d * sizeof (rtunion),\n", rtx_next_new
[i
]);
1002 oprintf (f
, "};\n");
1005 /* Handle `special("rtx_def")'. This is a special case for field
1006 `fld' of struct rtx_def, which is an array of unions whose values
1007 are based in a complex way on the type of RTL. */
1010 adjust_field_rtx_def (type_p t
, options_p
ARG_UNUSED (opt
))
1015 type_p rtx_tp
, rtvec_tp
, tree_tp
, mem_attrs_tp
, note_union_tp
, scalar_tp
;
1016 type_p basic_block_tp
, reg_attrs_tp
, constant_tp
, symbol_union_tp
;
1018 if (t
->kind
!= TYPE_UNION
)
1020 error_at_line (&lexer_line
,
1021 "special `rtx_def' must be applied to a union");
1022 return &string_type
;
1025 nodot
= create_option (NULL
, "dot", "");
1027 rtx_tp
= create_pointer (find_structure ("rtx_def", 0));
1028 rtvec_tp
= create_pointer (find_structure ("rtvec_def", 0));
1029 tree_tp
= create_pointer (find_structure ("tree_node", 1));
1030 mem_attrs_tp
= create_pointer (find_structure ("mem_attrs", 0));
1031 reg_attrs_tp
= create_pointer (find_structure ("reg_attrs", 0));
1032 basic_block_tp
= create_pointer (find_structure ("basic_block_def", 0));
1034 create_pointer (find_structure ("constant_descriptor_rtx", 0));
1035 scalar_tp
= &scalar_nonchar
; /* rtunion int */
1038 pair_p note_flds
= NULL
;
1041 for (c
= 0; c
<= NOTE_INSN_MAX
; c
++)
1046 case NOTE_INSN_DELETED_LABEL
:
1047 note_flds
= create_field (note_flds
, &string_type
, "rt_str");
1050 case NOTE_INSN_BLOCK_BEG
:
1051 case NOTE_INSN_BLOCK_END
:
1052 note_flds
= create_field (note_flds
, tree_tp
, "rt_tree");
1055 case NOTE_INSN_VAR_LOCATION
:
1056 note_flds
= create_field (note_flds
, rtx_tp
, "rt_rtx");
1060 note_flds
= create_field (note_flds
, scalar_tp
, "rt_int");
1063 /* NOTE_INSN_MAX is used as the default field for line
1065 if (c
== NOTE_INSN_MAX
)
1066 note_flds
->opt
= create_option (nodot
, "default", "");
1068 note_flds
->opt
= create_option (nodot
, "tag", note_insn_name
[c
]);
1070 note_union_tp
= new_structure ("rtx_def_note_subunion", 1,
1071 &lexer_line
, note_flds
, NULL
);
1073 /* Create a type to represent the various forms of SYMBOL_REF_DATA. */
1077 sym_flds
= create_field (NULL
, tree_tp
, "rt_tree");
1078 sym_flds
->opt
= create_option (nodot
, "default", "");
1080 sym_flds
= create_field (sym_flds
, constant_tp
, "rt_constant");
1081 sym_flds
->opt
= create_option (nodot
, "tag", "1");
1083 symbol_union_tp
= new_structure ("rtx_def_symbol_subunion", 1,
1084 &lexer_line
, sym_flds
, NULL
);
1086 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
1088 pair_p subfields
= NULL
;
1089 size_t aindex
, nmindex
;
1094 for (aindex
= 0; aindex
< strlen (rtx_format
[i
]); aindex
++)
1097 const char *subname
;
1099 switch (rtx_format
[i
][aindex
])
1110 if (i
== MEM
&& aindex
== 1)
1111 t
= mem_attrs_tp
, subname
= "rt_mem";
1112 else if (i
== JUMP_INSN
&& aindex
== 8)
1113 t
= rtx_tp
, subname
= "rt_rtx";
1114 else if (i
== CODE_LABEL
&& aindex
== 5)
1115 t
= scalar_tp
, subname
= "rt_int";
1116 else if (i
== CODE_LABEL
&& aindex
== 4)
1117 t
= rtx_tp
, subname
= "rt_rtx";
1118 else if (i
== LABEL_REF
&& (aindex
== 1 || aindex
== 2))
1119 t
= rtx_tp
, subname
= "rt_rtx";
1120 else if (i
== NOTE
&& aindex
== 4)
1121 t
= note_union_tp
, subname
= "";
1122 else if (i
== NOTE
&& aindex
== 5)
1123 t
= scalar_tp
, subname
= "rt_int";
1124 else if (i
== NOTE
&& aindex
>= 7)
1125 t
= scalar_tp
, subname
= "rt_int";
1126 else if (i
== ADDR_DIFF_VEC
&& aindex
== 4)
1127 t
= scalar_tp
, subname
= "rt_int";
1128 else if (i
== VALUE
&& aindex
== 0)
1129 t
= scalar_tp
, subname
= "rt_int";
1130 else if (i
== DEBUG_EXPR
&& aindex
== 0)
1131 t
= tree_tp
, subname
= "rt_tree";
1132 else if (i
== REG
&& aindex
== 1)
1133 t
= scalar_tp
, subname
= "rt_int";
1134 else if (i
== REG
&& aindex
== 2)
1135 t
= reg_attrs_tp
, subname
= "rt_reg";
1136 else if (i
== SCRATCH
&& aindex
== 0)
1137 t
= scalar_tp
, subname
= "rt_int";
1138 else if (i
== SYMBOL_REF
&& aindex
== 1)
1139 t
= scalar_tp
, subname
= "rt_int";
1140 else if (i
== SYMBOL_REF
&& aindex
== 2)
1141 t
= symbol_union_tp
, subname
= "";
1142 else if (i
== BARRIER
&& aindex
>= 3)
1143 t
= scalar_tp
, subname
= "rt_int";
1146 error_at_line (&lexer_line
,
1147 "rtx type `%s' has `0' in position %lu, can't handle",
1148 rtx_name
[i
], (unsigned long) aindex
);
1170 subname
= "rt_rtvec";
1175 subname
= "rt_tree";
1184 error_at_line (&lexer_line
,
1185 "rtx type `%s' has `%c' in position %lu, can't handle",
1186 rtx_name
[i
], rtx_format
[i
][aindex
],
1187 (unsigned long) aindex
);
1193 subfields
= create_field (subfields
, t
,
1194 xasprintf (".fld[%lu].%s",
1195 (unsigned long) aindex
,
1197 subfields
->opt
= nodot
;
1198 if (t
== note_union_tp
)
1199 subfields
->opt
= create_option (subfields
->opt
, "desc",
1201 if (t
== symbol_union_tp
)
1202 subfields
->opt
= create_option (subfields
->opt
, "desc",
1203 "CONSTANT_POOL_ADDRESS_P (&%0)");
1206 if (i
== SYMBOL_REF
)
1208 /* Add the "block_sym" field if SYMBOL_REF_HAS_BLOCK_INFO_P holds. */
1209 type_p field_tp
= find_structure ("block_symbol", 0);
1211 = create_optional_field (subfields
, field_tp
, "block_sym",
1212 "SYMBOL_REF_HAS_BLOCK_INFO_P (&%0)");
1215 sname
= xasprintf ("rtx_def_%s", rtx_name
[i
]);
1216 substruct
= new_structure (sname
, 0, &lexer_line
, subfields
, NULL
);
1218 ftag
= xstrdup (rtx_name
[i
]);
1219 for (nmindex
= 0; nmindex
< strlen (ftag
); nmindex
++)
1220 ftag
[nmindex
] = TOUPPER (ftag
[nmindex
]);
1222 flds
= create_field (flds
, substruct
, "");
1223 flds
->opt
= create_option (nodot
, "tag", ftag
);
1226 return new_structure ("rtx_def_subunion", 1, &lexer_line
, flds
, nodot
);
1229 /* Handle `special("tree_exp")'. This is a special case for
1230 field `operands' of struct tree_exp, which although it claims to contain
1231 pointers to trees, actually sometimes contains pointers to RTL too.
1232 Passed T, the old type of the field, and OPT its options. Returns
1233 a new type for the field. */
1236 adjust_field_tree_exp (type_p t
, options_p opt ATTRIBUTE_UNUSED
)
1241 if (t
->kind
!= TYPE_ARRAY
)
1243 error_at_line (&lexer_line
,
1244 "special `tree_exp' must be applied to an array");
1245 return &string_type
;
1248 nodot
= create_option (NULL
, "dot", "");
1250 flds
= create_field (NULL
, t
, "");
1251 flds
->opt
= create_option (nodot
, "length",
1252 "TREE_OPERAND_LENGTH ((tree) &%0)");
1253 flds
->opt
= create_option (flds
->opt
, "default", "");
1255 return new_structure ("tree_exp_subunion", 1, &lexer_line
, flds
, nodot
);
1258 /* Perform any special processing on a type T, about to become the type
1259 of a field. Return the appropriate type for the field.
1261 - Converts pointer-to-char, with no length parameter, to TYPE_STRING;
1262 - Similarly for arrays of pointer-to-char;
1263 - Converts structures for which a parameter is provided to
1265 - Handles "special" options.
1269 adjust_field_type (type_p t
, options_p opt
)
1272 const int pointer_p
= t
->kind
== TYPE_POINTER
;
1273 type_p params
[NUM_PARAM
];
1277 for (i
= 0; i
< NUM_PARAM
; i
++)
1280 for (; opt
; opt
= opt
->next
)
1281 if (strcmp (opt
->name
, "length") == 0)
1283 else if (strcmp (opt
->name
, "param_is") == 0
1284 || (strncmp (opt
->name
, "param", 5) == 0
1285 && ISDIGIT (opt
->name
[5])
1286 && strcmp (opt
->name
+ 6, "_is") == 0))
1288 int num
= ISDIGIT (opt
->name
[5]) ? opt
->name
[5] - '0' : 0;
1290 if (!UNION_OR_STRUCT_P (t
)
1291 && (t
->kind
!= TYPE_POINTER
|| !UNION_OR_STRUCT_P (t
->u
.p
)))
1293 error_at_line (&lexer_line
,
1294 "option `%s' may only be applied to structures or structure pointers",
1300 if (params
[num
] != NULL
)
1301 error_at_line (&lexer_line
, "duplicate `%s' option", opt
->name
);
1302 if (!ISDIGIT (opt
->name
[5]))
1304 create_pointer (CONST_CAST2 (type_p
, const char *, opt
->info
));
1306 params
[num
] = CONST_CAST2 (type_p
, const char *, opt
->info
);
1308 else if (strcmp (opt
->name
, "special") == 0)
1310 const char *special_name
= opt
->info
;
1311 if (strcmp (special_name
, "tree_exp") == 0)
1312 t
= adjust_field_tree_exp (t
, opt
);
1313 else if (strcmp (special_name
, "rtx_def") == 0)
1314 t
= adjust_field_rtx_def (t
, opt
);
1316 error_at_line (&lexer_line
, "unknown special `%s'", special_name
);
1325 realt
= find_param_structure (t
, params
);
1326 t
= pointer_p
? create_pointer (realt
) : realt
;
1330 && pointer_p
&& t
->u
.p
->kind
== TYPE_SCALAR
&& t
->u
.p
->u
.scalar_is_char
)
1331 return &string_type
;
1332 if (t
->kind
== TYPE_ARRAY
&& t
->u
.a
.p
->kind
== TYPE_POINTER
1333 && t
->u
.a
.p
->u
.p
->kind
== TYPE_SCALAR
1334 && t
->u
.a
.p
->u
.p
->u
.scalar_is_char
)
1335 return create_array (&string_type
, t
->u
.a
.len
);
1341 static void set_gc_used_type (type_p
, enum gc_used_enum
, type_p
*);
1342 static void set_gc_used (pair_p
);
1344 /* Handle OPT for set_gc_used_type. */
1347 process_gc_options (options_p opt
, enum gc_used_enum level
, int *maybe_undef
,
1348 int *pass_param
, int *length
, int *skip
,
1352 for (o
= opt
; o
; o
= o
->next
)
1353 if (strcmp (o
->name
, "ptr_alias") == 0 && level
== GC_POINTED_TO
)
1354 set_gc_used_type (CONST_CAST2 (type_p
, const char *, o
->info
),
1355 GC_POINTED_TO
, NULL
);
1356 else if (strcmp (o
->name
, "maybe_undef") == 0)
1358 else if (strcmp (o
->name
, "use_params") == 0)
1360 else if (strcmp (o
->name
, "length") == 0)
1362 else if (strcmp (o
->name
, "skip") == 0)
1364 else if (strcmp (o
->name
, "nested_ptr") == 0)
1365 *nested_ptr
= ((const struct nested_ptr_data
*) o
->info
)->type
;
1368 /* Set the gc_used field of T to LEVEL, and handle the types it references. */
1371 set_gc_used_type (type_p t
, enum gc_used_enum level
, type_p param
[NUM_PARAM
])
1373 if (t
->gc_used
>= level
)
1387 process_gc_options (t
->u
.s
.opt
, level
, &dummy
, &dummy
, &dummy
, &dummy
,
1390 for (f
= t
->u
.s
.fields
; f
; f
= f
->next
)
1392 int maybe_undef
= 0;
1396 type_p nested_ptr
= NULL
;
1397 process_gc_options (f
->opt
, level
, &maybe_undef
, &pass_param
,
1398 &length
, &skip
, &nested_ptr
);
1400 if (nested_ptr
&& f
->type
->kind
== TYPE_POINTER
)
1401 set_gc_used_type (nested_ptr
, GC_POINTED_TO
,
1402 pass_param
? param
: NULL
);
1403 else if (length
&& f
->type
->kind
== TYPE_POINTER
)
1404 set_gc_used_type (f
->type
->u
.p
, GC_USED
, NULL
);
1405 else if (maybe_undef
&& f
->type
->kind
== TYPE_POINTER
)
1406 set_gc_used_type (f
->type
->u
.p
, GC_MAYBE_POINTED_TO
, NULL
);
1407 else if (pass_param
&& f
->type
->kind
== TYPE_POINTER
&& param
)
1408 set_gc_used_type (find_param_structure (f
->type
->u
.p
, param
),
1409 GC_POINTED_TO
, NULL
);
1411 ; /* target type is not used through this field */
1413 set_gc_used_type (f
->type
, GC_USED
, pass_param
? param
: NULL
);
1419 set_gc_used_type (t
->u
.p
, GC_POINTED_TO
, NULL
);
1423 set_gc_used_type (t
->u
.a
.p
, GC_USED
, param
);
1426 case TYPE_LANG_STRUCT
:
1427 for (t
= t
->u
.s
.lang_struct
; t
; t
= t
->next
)
1428 set_gc_used_type (t
, level
, param
);
1431 case TYPE_PARAM_STRUCT
:
1434 for (i
= 0; i
< NUM_PARAM
; i
++)
1435 if (t
->u
.param_struct
.param
[i
] != 0)
1436 set_gc_used_type (t
->u
.param_struct
.param
[i
], GC_USED
, NULL
);
1438 if (t
->u
.param_struct
.stru
->gc_used
== GC_POINTED_TO
)
1439 level
= GC_POINTED_TO
;
1442 t
->u
.param_struct
.stru
->gc_used
= GC_UNUSED
;
1443 set_gc_used_type (t
->u
.param_struct
.stru
, level
,
1444 t
->u
.param_struct
.param
);
1452 /* Set the gc_used fields of all the types pointed to by VARIABLES. */
1455 set_gc_used (pair_p variables
)
1458 for (p
= variables
; p
; p
= p
->next
)
1459 set_gc_used_type (p
->type
, GC_USED
, NULL
);
1462 /* File mapping routines. For each input file, there is one output .c file
1463 (but some output files have many input files), and there is one .h file
1464 for the whole build. */
1466 /* Output file handling. */
1468 /* Create and return an outf_p for a new file for NAME, to be called
1472 create_file (const char *name
, const char *oname
)
1474 static const char *const hdr
[] = {
1475 " Copyright (C) 2004, 2007, 2009 Free Software Foundation, Inc.\n",
1477 "This file is part of GCC.\n",
1479 "GCC is free software; you can redistribute it and/or modify it under\n",
1480 "the terms of the GNU General Public License as published by the Free\n",
1481 "Software Foundation; either version 3, or (at your option) any later\n",
1484 "GCC is distributed in the hope that it will be useful, but WITHOUT ANY\n",
1485 "WARRANTY; without even the implied warranty of MERCHANTABILITY or\n",
1486 "FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n",
1487 "for more details.\n",
1489 "You should have received a copy of the GNU General Public License\n",
1490 "along with GCC; see the file COPYING3. If not see\n",
1491 "<http://www.gnu.org/licenses/>. */\n",
1493 "/* This file is machine generated. Do not edit. */\n"
1498 gcc_assert (name
!= NULL
);
1499 gcc_assert (oname
!= NULL
);
1500 f
= XCNEW (struct outf
);
1501 f
->next
= output_files
;
1505 oprintf (f
, "/* Type information for %s.\n", name
);
1506 for (i
= 0; i
< ARRAY_SIZE (hdr
); i
++)
1507 oprintf (f
, "%s", hdr
[i
]);
1511 /* Print, like fprintf, to O.
1512 N.B. You might think this could be implemented more efficiently
1513 with vsnprintf(). Unfortunately, there are C libraries that
1514 provide that function but without the C99 semantics for its return
1515 value, making it impossible to know how much space is required. */
1517 oprintf (outf_p o
, const char *format
, ...)
1523 /* In plugin mode, the O could be a NULL pointer, so avoid crashing
1528 va_start (ap
, format
);
1529 slength
= vasprintf (&s
, format
, ap
);
1530 if (s
== NULL
|| (int) slength
< 0)
1531 fatal ("out of memory");
1534 if (o
->bufused
+ slength
> o
->buflength
)
1536 size_t new_len
= o
->buflength
;
1543 while (o
->bufused
+ slength
>= new_len
);
1544 o
->buf
= XRESIZEVEC (char, o
->buf
, new_len
);
1545 o
->buflength
= new_len
;
1547 memcpy (o
->buf
+ o
->bufused
, s
, slength
);
1548 o
->bufused
+= slength
;
1552 /* Open the global header file and the language-specific header files. */
1555 open_base_files (void)
1559 if (nb_plugin_files
> 0 && plugin_files
)
1562 header_file
= create_file ("GCC", "gtype-desc.h");
1564 base_files
= XNEWVEC (outf_p
, num_lang_dirs
);
1566 for (i
= 0; i
< num_lang_dirs
; i
++)
1567 base_files
[i
] = create_file (lang_dir_names
[i
],
1568 xasprintf ("gtype-%s.h", lang_dir_names
[i
]));
1570 /* gtype-desc.c is a little special, so we create it here. */
1572 /* The order of files here matters very much. */
1573 static const char *const ifiles
[] = {
1574 "config.h", "system.h", "coretypes.h", "tm.h",
1575 "hashtab.h", "splay-tree.h", "obstack.h", "bitmap.h", "input.h",
1576 "tree.h", "rtl.h", "function.h", "insn-config.h", "expr.h",
1577 "hard-reg-set.h", "basic-block.h", "cselib.h", "insn-addr.h",
1578 "optabs.h", "libfuncs.h", "debug.h", "ggc.h", "cgraph.h",
1579 "tree-flow.h", "reload.h", "cpp-id-data.h", "tree-chrec.h",
1580 "cfglayout.h", "except.h", "output.h", "gimple.h", "cfgloop.h",
1581 "target.h", "ipa-prop.h", "lto-streamer.h", "target-globals.h", NULL
1583 const char *const *ifp
;
1584 outf_p gtype_desc_c
;
1586 gtype_desc_c
= create_file ("GCC", "gtype-desc.c");
1587 for (ifp
= ifiles
; *ifp
; ifp
++)
1588 oprintf (gtype_desc_c
, "#include \"%s\"\n", *ifp
);
1590 /* Make sure we handle "cfun" specially. */
1591 oprintf (gtype_desc_c
, "\n/* See definition in function.h. */\n");
1592 oprintf (gtype_desc_c
, "#undef cfun\n");
1596 /* For F a filename, return the real basename of F, with all the directory
1597 components skipped. */
1600 get_file_realbasename (const char *f
)
1602 const char *lastslash
= strrchr (f
, '/');
1604 return (lastslash
!= NULL
) ? lastslash
+ 1 : f
;
1607 /* For F a filename, return the relative path to F from $(srcdir) if the
1608 latter is a prefix in F, NULL otherwise. */
1611 get_file_srcdir_relative_path (const char *f
)
1613 if (strlen (f
) > srcdir_len
1614 && IS_DIR_SEPARATOR (f
[srcdir_len
])
1615 && memcmp (f
, srcdir
, srcdir_len
) == 0)
1616 return f
+ srcdir_len
+ 1;
1621 /* For F a filename, return the relative path to F from $(srcdir) if the
1622 latter is a prefix in F, or the real basename of F otherwise. */
1625 get_file_basename (const char *f
)
1627 const char *srcdir_path
= get_file_srcdir_relative_path (f
);
1629 return (srcdir_path
!= NULL
) ? srcdir_path
: get_file_realbasename (f
);
1632 /* For F a filename, return the lang_dir_names relative index of the language
1633 directory that is a prefix in F, if any, -1 otherwise. */
1636 get_prefix_langdir_index (const char *f
)
1638 size_t f_len
= strlen (f
);
1641 for (lang_index
= 0; lang_index
< num_lang_dirs
; lang_index
++)
1643 const char *langdir
= lang_dir_names
[lang_index
];
1644 size_t langdir_len
= strlen (langdir
);
1646 if (f_len
> langdir_len
1647 && IS_DIR_SEPARATOR (f
[langdir_len
])
1648 && memcmp (f
, langdir
, langdir_len
) == 0)
1655 /* For F a filename, return the name of language directory where F is located,
1656 if any, NULL otherwise. */
1659 get_file_langdir (const char *f
)
1661 /* Get the relative path to F from $(srcdir) and find the language by
1662 comparing the prefix with language directory names. If F is not even
1663 srcdir relative, no point in looking further. */
1666 const char *srcdir_relative_path
= get_file_srcdir_relative_path (f
);
1669 if (!srcdir_relative_path
)
1672 lang_index
= get_prefix_langdir_index (srcdir_relative_path
);
1673 if (lang_index
< 0 && strncmp (srcdir_relative_path
, "c-family", 8) == 0)
1675 else if (lang_index
>= 0)
1676 r
= lang_dir_names
[lang_index
];
1683 /* The gt- output file name for F. */
1686 get_file_gtfilename (const char *f
)
1688 /* Cook up an initial version of the gt- file name from the file real
1689 basename and the language name, if any. */
1691 const char *basename
= get_file_realbasename (f
);
1692 const char *langdir
= get_file_langdir (f
);
1695 (langdir
? xasprintf ("gt-%s-%s", langdir
, basename
)
1696 : xasprintf ("gt-%s", basename
));
1698 /* Then replace all non alphanumerics characters by '-' and change the
1699 extension to ".h". We expect the input filename extension was at least
1700 one character long. */
1704 for (; *s
!= '.'; s
++)
1705 if (!ISALNUM (*s
) && *s
!= '-')
1708 memcpy (s
, ".h", sizeof (".h"));
1713 /* An output file, suitable for definitions, that can see declarations
1714 made in INPUT_FILE and is linked into every language that uses
1718 get_output_file_with_visibility (const char *input_file
)
1722 const char *basename
;
1723 const char *for_name
;
1724 const char *output_name
;
1726 /* This can happen when we need a file with visibility on a
1727 structure that we've never seen. We have to just hope that it's
1728 globally visible. */
1729 if (input_file
== NULL
)
1730 input_file
= "system.h";
1732 /* In plugin mode, return NULL unless the input_file is one of the
1737 for (i
= 0; i
< nb_plugin_files
; i
++)
1738 if (strcmp (input_file
, plugin_files
[i
]) == 0)
1739 return plugin_output
;
1744 /* Determine the output file name. */
1745 basename
= get_file_basename (input_file
);
1747 len
= strlen (basename
);
1748 if ((len
> 2 && memcmp (basename
+ len
- 2, ".c", 2) == 0)
1749 || (len
> 2 && memcmp (basename
+ len
- 2, ".y", 2) == 0)
1750 || (len
> 3 && memcmp (basename
+ len
- 3, ".in", 3) == 0))
1752 output_name
= get_file_gtfilename (input_file
);
1753 for_name
= basename
;
1755 /* Some headers get used by more than one front-end; hence, it
1756 would be inappropriate to spew them out to a single gtype-<lang>.h
1757 (and gengtype doesn't know how to direct spewage into multiple
1758 gtype-<lang>.h headers at this time). Instead, we pair up these
1759 headers with source files (and their special purpose gt-*.h headers). */
1760 else if (strncmp (basename
, "c-family", 8) == 0
1761 && IS_DIR_SEPARATOR (basename
[8])
1762 && strcmp (basename
+ 9, "c-common.h") == 0)
1763 output_name
= "gt-c-family-c-common.h", for_name
= "c-family/c-common.c";
1764 else if (strcmp (basename
, "c-lang.h") == 0)
1765 output_name
= "gt-c-decl.h", for_name
= "c-decl.c";
1766 else if (strcmp (basename
, "c-tree.h") == 0)
1767 output_name
= "gt-c-decl.h", for_name
= "c-decl.c";
1768 else if (strncmp (basename
, "cp", 2) == 0 && IS_DIR_SEPARATOR (basename
[2])
1769 && strcmp (basename
+ 3, "cp-tree.h") == 0)
1770 output_name
= "gt-cp-tree.h", for_name
= "cp/tree.c";
1771 else if (strncmp (basename
, "cp", 2) == 0 && IS_DIR_SEPARATOR (basename
[2])
1772 && strcmp (basename
+ 3, "decl.h") == 0)
1773 output_name
= "gt-cp-decl.h", for_name
= "cp/decl.c";
1774 else if (strncmp (basename
, "cp", 2) == 0 && IS_DIR_SEPARATOR (basename
[2])
1775 && strcmp (basename
+ 3, "name-lookup.h") == 0)
1776 output_name
= "gt-cp-name-lookup.h", for_name
= "cp/name-lookup.c";
1777 else if (strncmp (basename
, "objc", 4) == 0
1778 && IS_DIR_SEPARATOR (basename
[4])
1779 && strcmp (basename
+ 5, "objc-act.h") == 0)
1780 output_name
= "gt-objc-objc-act.h", for_name
= "objc/objc-act.c";
1783 int lang_index
= get_prefix_langdir_index (basename
);
1785 if (lang_index
>= 0)
1786 return base_files
[lang_index
];
1788 output_name
= "gtype-desc.c";
1792 /* Look through to see if we've ever seen this output filename before. */
1793 for (r
= output_files
; r
; r
= r
->next
)
1794 if (strcmp (r
->name
, output_name
) == 0)
1797 /* If not, create it. */
1798 r
= create_file (for_name
, output_name
);
1800 gcc_assert (r
&& r
->name
);
1804 /* The name of an output file, suitable for definitions, that can see
1805 declarations made in INPUT_FILE and is linked into every language
1806 that uses INPUT_FILE. */
1809 get_output_file_name (const char *input_file
)
1811 outf_p o
= get_output_file_with_visibility (input_file
);
1817 /* Check if existing file is equal to the in memory buffer. */
1820 is_file_equal (outf_p of
)
1822 FILE *newfile
= fopen (of
->name
, "r");
1825 if (newfile
== NULL
)
1829 for (i
= 0; i
< of
->bufused
; i
++)
1832 ch
= fgetc (newfile
);
1833 if (ch
== EOF
|| ch
!= (unsigned char) of
->buf
[i
])
1843 /* Copy the output to its final destination,
1844 but don't unnecessarily change modification times. */
1847 close_output_files (void)
1851 for (of
= output_files
; of
; of
= of
->next
)
1854 if (!is_file_equal (of
))
1856 FILE *newfile
= fopen (of
->name
, "w");
1857 if (newfile
== NULL
)
1858 fatal ("opening output file %s: %s", of
->name
, xstrerror (errno
));
1859 if (fwrite (of
->buf
, 1, of
->bufused
, newfile
) != of
->bufused
)
1860 fatal ("writing output file %s: %s", of
->name
, xstrerror (errno
));
1861 if (fclose (newfile
) != 0)
1862 fatal ("closing output file %s: %s", of
->name
, xstrerror (errno
));
1866 of
->bufused
= of
->buflength
= 0;
1878 struct walk_type_data
;
1880 /* For scalars and strings, given the item in 'val'.
1881 For structures, given a pointer to the item in 'val'.
1882 For misc. pointers, given the item in 'val'.
1884 typedef void (*process_field_fn
) (type_p f
, const struct walk_type_data
* p
);
1885 typedef void (*func_name_fn
) (type_p s
, const struct walk_type_data
* p
);
1887 /* Parameters for write_types. */
1889 struct write_types_data
1892 const char *param_prefix
;
1893 const char *subfield_marker_routine
;
1894 const char *marker_routine
;
1895 const char *reorder_note_routine
;
1896 const char *comment
;
1897 int skip_hooks
; /* skip hook generation if non zero */
1900 static void output_escaped_param (struct walk_type_data
*d
,
1901 const char *, const char *);
1902 static void output_mangled_typename (outf_p
, const_type_p
);
1903 static void walk_type (type_p t
, struct walk_type_data
*d
);
1904 static void write_func_for_structure (type_p orig_s
, type_p s
, type_p
*param
,
1905 const struct write_types_data
*wtd
);
1906 static void write_types_process_field
1907 (type_p f
, const struct walk_type_data
*d
);
1908 static void write_types (outf_p output_header
,
1910 type_p param_structs
,
1911 const struct write_types_data
*wtd
);
1912 static void write_types_local_process_field
1913 (type_p f
, const struct walk_type_data
*d
);
1914 static void write_local_func_for_structure
1915 (const_type_p orig_s
, type_p s
, type_p
*param
);
1916 static void write_local (outf_p output_header
,
1917 type_p structures
, type_p param_structs
);
1918 static void write_enum_defn (type_p structures
, type_p param_structs
);
1919 static int contains_scalar_p (type_p t
);
1920 static void put_mangled_filename (outf_p
, const char *);
1921 static void finish_root_table (struct flist
*flp
, const char *pfx
,
1922 const char *tname
, const char *lastname
,
1924 static void write_root (outf_p
, pair_p
, type_p
, const char *, int,
1925 struct fileloc
*, const char *, bool);
1926 static void write_array (outf_p f
, pair_p v
,
1927 const struct write_types_data
*wtd
);
1928 static void write_roots (pair_p
, bool);
1930 /* Parameters for walk_type. */
1932 struct walk_type_data
1934 process_field_fn process_field
;
1939 const char *prev_val
[4];
1942 const struct fileloc
*line
;
1947 const char *reorder_fn
;
1949 bool fn_wants_lvalue
;
1952 /* Print a mangled name representing T to OF. */
1955 output_mangled_typename (outf_p of
, const_type_p t
)
1964 output_mangled_typename (of
, t
->u
.p
);
1974 case TYPE_LANG_STRUCT
:
1975 oprintf (of
, "%lu%s", (unsigned long) strlen (t
->u
.s
.tag
),
1978 case TYPE_PARAM_STRUCT
:
1981 for (i
= 0; i
< NUM_PARAM
; i
++)
1982 if (t
->u
.param_struct
.param
[i
] != NULL
)
1983 output_mangled_typename (of
, t
->u
.param_struct
.param
[i
]);
1984 output_mangled_typename (of
, t
->u
.param_struct
.stru
);
1992 /* Print PARAM to D->OF processing escapes. D->VAL references the
1993 current object, D->PREV_VAL the object containing the current
1994 object, ONAME is the name of the option and D->LINE is used to
1995 print error messages. */
1998 output_escaped_param (struct walk_type_data
*d
, const char *param
,
2003 for (p
= param
; *p
; p
++)
2005 oprintf (d
->of
, "%c", *p
);
2010 oprintf (d
->of
, "(%s)", d
->prev_val
[2]);
2013 oprintf (d
->of
, "(%s)", d
->prev_val
[0]);
2016 oprintf (d
->of
, "(%s)", d
->prev_val
[1]);
2020 const char *pp
= d
->val
+ strlen (d
->val
);
2021 while (pp
[-1] == ']')
2024 oprintf (d
->of
, "%s", pp
);
2028 error_at_line (d
->line
, "`%s' option contains bad escape %c%c",
2033 /* Call D->PROCESS_FIELD for every field (or subfield) of D->VAL,
2034 which is of type T. Write code to D->OF to constrain execution (at
2035 the point that D->PROCESS_FIELD is called) to the appropriate
2036 cases. Call D->PROCESS_FIELD on subobjects before calling it on
2037 pointers to those objects. D->PREV_VAL lists the objects
2038 containing the current object, D->OPT is a list of options to
2039 apply, D->INDENT is the current indentation level, D->LINE is used
2040 to print error messages, D->BITMAP indicates which languages to
2041 print the structure for, and D->PARAM is the current parameter
2042 (from an enclosing param_is option). */
2045 walk_type (type_p t
, struct walk_type_data
*d
)
2047 const char *length
= NULL
;
2048 const char *desc
= NULL
;
2049 int maybe_undef_p
= 0;
2050 int use_param_num
= -1;
2051 int use_params_p
= 0;
2053 const struct nested_ptr_data
*nested_ptr_d
= NULL
;
2055 d
->needs_cast_p
= false;
2056 for (oo
= d
->opt
; oo
; oo
= oo
->next
)
2057 if (strcmp (oo
->name
, "length") == 0)
2059 else if (strcmp (oo
->name
, "maybe_undef") == 0)
2061 else if (strncmp (oo
->name
, "use_param", 9) == 0
2062 && (oo
->name
[9] == '\0' || ISDIGIT (oo
->name
[9])))
2063 use_param_num
= oo
->name
[9] == '\0' ? 0 : oo
->name
[9] - '0';
2064 else if (strcmp (oo
->name
, "use_params") == 0)
2066 else if (strcmp (oo
->name
, "desc") == 0)
2068 else if (strcmp (oo
->name
, "mark_hook") == 0)
2070 else if (strcmp (oo
->name
, "nested_ptr") == 0)
2071 nested_ptr_d
= (const struct nested_ptr_data
*) oo
->info
;
2072 else if (strcmp (oo
->name
, "dot") == 0)
2074 else if (strcmp (oo
->name
, "tag") == 0)
2076 else if (strcmp (oo
->name
, "special") == 0)
2078 else if (strcmp (oo
->name
, "skip") == 0)
2080 else if (strcmp (oo
->name
, "default") == 0)
2082 else if (strcmp (oo
->name
, "descbits") == 0)
2084 else if (strcmp (oo
->name
, "param_is") == 0)
2086 else if (strncmp (oo
->name
, "param", 5) == 0
2087 && ISDIGIT (oo
->name
[5]) && strcmp (oo
->name
+ 6, "_is") == 0)
2089 else if (strcmp (oo
->name
, "chain_next") == 0)
2091 else if (strcmp (oo
->name
, "chain_prev") == 0)
2093 else if (strcmp (oo
->name
, "chain_circular") == 0)
2095 else if (strcmp (oo
->name
, "reorder") == 0)
2097 else if (strcmp (oo
->name
, "variable_size") == 0)
2100 error_at_line (d
->line
, "unknown option `%s'\n", oo
->name
);
2107 int pointer_p
= t
->kind
== TYPE_POINTER
;
2111 if (!UNION_OR_STRUCT_P (t
))
2112 error_at_line (d
->line
, "`use_params' option on unimplemented type");
2114 t
= find_param_structure (t
, d
->param
);
2116 t
= create_pointer (t
);
2119 if (use_param_num
!= -1)
2121 if (d
->param
!= NULL
&& d
->param
[use_param_num
] != NULL
)
2123 type_p nt
= d
->param
[use_param_num
];
2125 if (t
->kind
== TYPE_ARRAY
)
2126 nt
= create_array (nt
, t
->u
.a
.len
);
2127 else if (length
!= NULL
&& t
->kind
== TYPE_POINTER
)
2128 nt
= create_pointer (nt
);
2129 d
->needs_cast_p
= (t
->kind
!= TYPE_POINTER
2130 && (nt
->kind
== TYPE_POINTER
2131 || nt
->kind
== TYPE_STRING
));
2135 error_at_line (d
->line
, "no parameter defined for `%s'", d
->val
);
2139 && (t
->kind
!= TYPE_POINTER
|| !UNION_OR_STRUCT_P (t
->u
.p
)))
2141 error_at_line (d
->line
,
2142 "field `%s' has invalid option `maybe_undef_p'\n",
2151 d
->process_field (t
, d
);
2156 if (maybe_undef_p
&& t
->u
.p
->u
.s
.line
.file
== NULL
)
2158 oprintf (d
->of
, "%*sgcc_assert (!%s);\n", d
->indent
, "", d
->val
);
2164 if (!UNION_OR_STRUCT_P (t
->u
.p
)
2165 && t
->u
.p
->kind
!= TYPE_PARAM_STRUCT
)
2167 error_at_line (d
->line
,
2168 "field `%s' is pointer to unimplemented type",
2175 const char *oldprevval2
= d
->prev_val
[2];
2177 if (!UNION_OR_STRUCT_P (nested_ptr_d
->type
))
2179 error_at_line (d
->line
,
2180 "field `%s' has invalid "
2181 "option `nested_ptr'\n", d
->val
);
2185 d
->prev_val
[2] = d
->val
;
2186 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
2188 d
->val
= xasprintf ("x%d", d
->counter
++);
2189 oprintf (d
->of
, "%*s%s %s * %s%s =\n", d
->indent
, "",
2190 (nested_ptr_d
->type
->kind
== TYPE_UNION
2191 ? "union" : "struct"),
2192 nested_ptr_d
->type
->u
.s
.tag
,
2193 d
->fn_wants_lvalue
? "" : "const ", d
->val
);
2194 oprintf (d
->of
, "%*s", d
->indent
+ 2, "");
2195 output_escaped_param (d
, nested_ptr_d
->convert_from
,
2197 oprintf (d
->of
, ";\n");
2199 d
->process_field (nested_ptr_d
->type
, d
);
2201 if (d
->fn_wants_lvalue
)
2203 oprintf (d
->of
, "%*s%s = ", d
->indent
, "",
2205 d
->prev_val
[2] = d
->val
;
2206 output_escaped_param (d
, nested_ptr_d
->convert_to
,
2208 oprintf (d
->of
, ";\n");
2212 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2213 d
->val
= d
->prev_val
[2];
2214 d
->prev_val
[2] = oldprevval2
;
2217 d
->process_field (t
->u
.p
, d
);
2221 int loopcounter
= d
->counter
++;
2222 const char *oldval
= d
->val
;
2223 const char *oldprevval3
= d
->prev_val
[3];
2226 oprintf (d
->of
, "%*sif (%s != NULL) {\n", d
->indent
, "", d
->val
);
2228 oprintf (d
->of
, "%*ssize_t i%d;\n", d
->indent
, "", loopcounter
);
2229 oprintf (d
->of
, "%*sfor (i%d = 0; i%d != (size_t)(", d
->indent
,
2230 "", loopcounter
, loopcounter
);
2231 output_escaped_param (d
, length
, "length");
2232 oprintf (d
->of
, "); i%d++) {\n", loopcounter
);
2234 d
->val
= newval
= xasprintf ("%s[i%d]", oldval
, loopcounter
);
2236 d
->prev_val
[3] = oldval
;
2237 walk_type (t
->u
.p
, d
);
2240 d
->prev_val
[3] = oldprevval3
;
2243 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2244 d
->process_field (t
, d
);
2246 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2253 int loopcounter
= d
->counter
++;
2254 const char *oldval
= d
->val
;
2257 /* If it's an array of scalars, we optimize by not generating
2259 if (t
->u
.a
.p
->kind
== TYPE_SCALAR
)
2262 /* When walking an array, compute the length and store it in a
2263 local variable before walking the array elements, instead of
2264 recomputing the length expression each time through the loop.
2265 This is necessary to handle tcc_vl_exp objects like CALL_EXPR,
2266 where the length is stored in the first array element,
2267 because otherwise that operand can get overwritten on the
2269 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
2271 oprintf (d
->of
, "%*ssize_t i%d;\n", d
->indent
, "", loopcounter
);
2272 oprintf (d
->of
, "%*ssize_t l%d = (size_t)(",
2273 d
->indent
, "", loopcounter
);
2275 output_escaped_param (d
, length
, "length");
2277 oprintf (d
->of
, "%s", t
->u
.a
.len
);
2278 oprintf (d
->of
, ");\n");
2280 oprintf (d
->of
, "%*sfor (i%d = 0; i%d != l%d; i%d++) {\n",
2282 loopcounter
, loopcounter
, loopcounter
, loopcounter
);
2284 d
->val
= newval
= xasprintf ("%s[i%d]", oldval
, loopcounter
);
2286 walk_type (t
->u
.a
.p
, d
);
2291 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2293 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2301 const char *oldval
= d
->val
;
2302 const char *oldprevval1
= d
->prev_val
[1];
2303 const char *oldprevval2
= d
->prev_val
[2];
2304 const int union_p
= t
->kind
== TYPE_UNION
;
2305 int seen_default_p
= 0;
2308 if (!t
->u
.s
.line
.file
)
2309 error_at_line (d
->line
, "incomplete structure `%s'", t
->u
.s
.tag
);
2311 if ((d
->bitmap
& t
->u
.s
.bitmap
) != d
->bitmap
)
2313 error_at_line (d
->line
,
2314 "structure `%s' defined for mismatching languages",
2316 error_at_line (&t
->u
.s
.line
, "one structure defined here");
2319 /* Some things may also be defined in the structure's options. */
2320 for (o
= t
->u
.s
.opt
; o
; o
= o
->next
)
2321 if (!desc
&& strcmp (o
->name
, "desc") == 0)
2324 d
->prev_val
[2] = oldval
;
2325 d
->prev_val
[1] = oldprevval2
;
2330 error_at_line (d
->line
,
2331 "missing `desc' option for union `%s'",
2335 oprintf (d
->of
, "%*sswitch (", d
->indent
, "");
2336 output_escaped_param (d
, desc
, "desc");
2337 oprintf (d
->of
, ")\n");
2339 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
2341 for (f
= t
->u
.s
.fields
; f
; f
= f
->next
)
2344 const char *dot
= ".";
2345 const char *tagid
= NULL
;
2348 int use_param_p
= 0;
2351 d
->reorder_fn
= NULL
;
2352 for (oo
= f
->opt
; oo
; oo
= oo
->next
)
2353 if (strcmp (oo
->name
, "dot") == 0)
2355 else if (strcmp (oo
->name
, "tag") == 0)
2357 else if (strcmp (oo
->name
, "skip") == 0)
2359 else if (strcmp (oo
->name
, "default") == 0)
2361 else if (strcmp (oo
->name
, "reorder") == 0)
2362 d
->reorder_fn
= oo
->info
;
2363 else if (strncmp (oo
->name
, "use_param", 9) == 0
2364 && (oo
->name
[9] == '\0' || ISDIGIT (oo
->name
[9])))
2370 if (union_p
&& tagid
)
2372 oprintf (d
->of
, "%*scase %s:\n", d
->indent
, "", tagid
);
2375 else if (union_p
&& default_p
)
2377 oprintf (d
->of
, "%*sdefault:\n", d
->indent
, "");
2381 else if (!union_p
&& (default_p
|| tagid
))
2382 error_at_line (d
->line
,
2383 "can't use `%s' outside a union on field `%s'",
2384 default_p
? "default" : "tag", f
->name
);
2385 else if (union_p
&& !(default_p
|| tagid
)
2386 && f
->type
->kind
== TYPE_SCALAR
)
2389 "%s:%d: warning: field `%s' is missing `tag' or `default' option\n",
2390 d
->line
->file
, d
->line
->line
, f
->name
);
2393 else if (union_p
&& !(default_p
|| tagid
))
2394 error_at_line (d
->line
,
2395 "field `%s' is missing `tag' or `default' option",
2399 d
->val
= newval
= xasprintf ("%s%s%s", oldval
, dot
, f
->name
);
2401 d
->used_length
= false;
2403 if (union_p
&& use_param_p
&& d
->param
== NULL
)
2404 oprintf (d
->of
, "%*sgcc_unreachable ();\n", d
->indent
, "");
2406 walk_type (f
->type
, d
);
2412 oprintf (d
->of
, "%*sbreak;\n", d
->indent
, "");
2416 d
->reorder_fn
= NULL
;
2419 d
->prev_val
[1] = oldprevval1
;
2420 d
->prev_val
[2] = oldprevval2
;
2422 if (union_p
&& !seen_default_p
)
2424 oprintf (d
->of
, "%*sdefault:\n", d
->indent
, "");
2425 oprintf (d
->of
, "%*s break;\n", d
->indent
, "");
2429 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
2435 case TYPE_LANG_STRUCT
:
2438 for (nt
= t
->u
.s
.lang_struct
; nt
; nt
= nt
->next
)
2439 if ((d
->bitmap
& nt
->u
.s
.bitmap
) == d
->bitmap
)
2442 error_at_line (d
->line
, "structure `%s' differs between languages",
2449 case TYPE_PARAM_STRUCT
:
2451 type_p
*oldparam
= d
->param
;
2453 d
->param
= t
->u
.param_struct
.param
;
2454 walk_type (t
->u
.param_struct
.stru
, d
);
2455 d
->param
= oldparam
;
2464 /* process_field routine for marking routines. */
2467 write_types_process_field (type_p f
, const struct walk_type_data
*d
)
2469 const struct write_types_data
*wtd
;
2470 const char *cast
= d
->needs_cast_p
? "(void *)" : "";
2471 wtd
= (const struct write_types_data
*) d
->cookie
;
2476 oprintf (d
->of
, "%*s%s (%s%s", d
->indent
, "",
2477 wtd
->subfield_marker_routine
, cast
, d
->val
);
2478 if (wtd
->param_prefix
)
2480 oprintf (d
->of
, ", %s", d
->prev_val
[3]);
2483 oprintf (d
->of
, ", gt_%s_", wtd
->param_prefix
);
2484 output_mangled_typename (d
->of
, d
->orig_s
);
2487 oprintf (d
->of
, ", gt_%sa_%s", wtd
->param_prefix
, d
->prev_val
[0]);
2489 if (f
->u
.p
->kind
== TYPE_PARAM_STRUCT
2490 && f
->u
.p
->u
.s
.line
.file
!= NULL
)
2492 oprintf (d
->of
, ", gt_e_");
2493 output_mangled_typename (d
->of
, f
);
2495 else if (UNION_OR_STRUCT_P (f
) && f
->u
.p
->u
.s
.line
.file
!= NULL
)
2497 oprintf (d
->of
, ", gt_ggc_e_");
2498 output_mangled_typename (d
->of
, f
);
2501 oprintf (d
->of
, ", gt_types_enum_last");
2503 oprintf (d
->of
, ");\n");
2504 if (d
->reorder_fn
&& wtd
->reorder_note_routine
)
2505 oprintf (d
->of
, "%*s%s (%s%s, %s, %s);\n", d
->indent
, "",
2506 wtd
->reorder_note_routine
, cast
, d
->val
,
2507 d
->prev_val
[3], d
->reorder_fn
);
2513 case TYPE_LANG_STRUCT
:
2514 case TYPE_PARAM_STRUCT
:
2515 oprintf (d
->of
, "%*sgt_%s_", d
->indent
, "", wtd
->prefix
);
2516 output_mangled_typename (d
->of
, f
);
2517 oprintf (d
->of
, " (%s%s);\n", cast
, d
->val
);
2518 if (d
->reorder_fn
&& wtd
->reorder_note_routine
)
2519 oprintf (d
->of
, "%*s%s (%s%s, %s%s, %s);\n", d
->indent
, "",
2520 wtd
->reorder_note_routine
, cast
, d
->val
, cast
, d
->val
,
2532 /* A subroutine of write_func_for_structure. Write the enum tag for S. */
2535 output_type_enum (outf_p of
, type_p s
)
2537 if (s
->kind
== TYPE_PARAM_STRUCT
&& s
->u
.param_struct
.line
.file
!= NULL
)
2539 oprintf (of
, ", gt_e_");
2540 output_mangled_typename (of
, s
);
2542 else if (UNION_OR_STRUCT_P (s
) && s
->u
.s
.line
.file
!= NULL
)
2544 oprintf (of
, ", gt_ggc_e_");
2545 output_mangled_typename (of
, s
);
2548 oprintf (of
, ", gt_types_enum_last");
2551 /* Return an output file that is suitable for definitions which can
2552 reference struct S */
2555 get_output_file_for_structure (const_type_p s
, type_p
*param
)
2557 const char *fn
= s
->u
.s
.line
.file
;
2560 /* This is a hack, and not the good kind either. */
2561 for (i
= NUM_PARAM
- 1; i
>= 0; i
--)
2562 if (param
&& param
[i
] && param
[i
]->kind
== TYPE_POINTER
2563 && UNION_OR_STRUCT_P (param
[i
]->u
.p
))
2564 fn
= param
[i
]->u
.p
->u
.s
.line
.file
;
2566 return get_output_file_with_visibility (fn
);
2569 /* For S, a structure that's part of ORIG_S, and using parameters
2570 PARAM, write out a routine that:
2571 - Takes a parameter, a void * but actually of type *S
2572 - If SEEN_ROUTINE returns nonzero, calls write_types_process_field on each
2573 field of S or its substructures and (in some cases) things
2574 that are pointed to by S.
2578 write_func_for_structure (type_p orig_s
, type_p s
, type_p
*param
,
2579 const struct write_types_data
*wtd
)
2581 const char *chain_next
= NULL
;
2582 const char *chain_prev
= NULL
;
2583 const char *chain_circular
= NULL
;
2584 const char *mark_hook_name
= NULL
;
2586 struct walk_type_data d
;
2588 memset (&d
, 0, sizeof (d
));
2589 d
.of
= get_output_file_for_structure (s
, param
);
2591 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
2592 if (strcmp (opt
->name
, "chain_next") == 0)
2593 chain_next
= opt
->info
;
2594 else if (strcmp (opt
->name
, "chain_prev") == 0)
2595 chain_prev
= opt
->info
;
2596 else if (strcmp (opt
->name
, "chain_circular") == 0)
2597 chain_circular
= opt
->info
;
2598 else if (strcmp (opt
->name
, "mark_hook") == 0)
2599 mark_hook_name
= opt
->info
;
2601 if (chain_prev
!= NULL
&& chain_next
== NULL
)
2602 error_at_line (&s
->u
.s
.line
, "chain_prev without chain_next");
2603 if (chain_circular
!= NULL
&& chain_next
!= NULL
)
2604 error_at_line (&s
->u
.s
.line
, "chain_circular with chain_next");
2605 if (chain_circular
!= NULL
)
2606 chain_next
= chain_circular
;
2608 d
.process_field
= write_types_process_field
;
2612 d
.line
= &s
->u
.s
.line
;
2613 d
.bitmap
= s
->u
.s
.bitmap
;
2615 d
.prev_val
[0] = "*x";
2616 d
.prev_val
[1] = "not valid postage"; /* Guarantee an error. */
2617 d
.prev_val
[3] = "x";
2620 oprintf (d
.of
, "\n");
2621 oprintf (d
.of
, "void\n");
2623 oprintf (d
.of
, "gt_%sx_%s", wtd
->prefix
, orig_s
->u
.s
.tag
);
2626 oprintf (d
.of
, "gt_%s_", wtd
->prefix
);
2627 output_mangled_typename (d
.of
, orig_s
);
2629 oprintf (d
.of
, " (void *x_p)\n");
2630 oprintf (d
.of
, "{\n");
2631 oprintf (d
.of
, " %s %s * %sx = (%s %s *)x_p;\n",
2632 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
,
2633 chain_next
== NULL
? "const " : "",
2634 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
2635 if (chain_next
!= NULL
)
2636 oprintf (d
.of
, " %s %s * xlimit = x;\n",
2637 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
2638 if (chain_next
== NULL
)
2640 oprintf (d
.of
, " if (%s (x", wtd
->marker_routine
);
2641 if (wtd
->param_prefix
)
2643 oprintf (d
.of
, ", x, gt_%s_", wtd
->param_prefix
);
2644 output_mangled_typename (d
.of
, orig_s
);
2645 output_type_enum (d
.of
, orig_s
);
2647 oprintf (d
.of
, "))\n");
2651 if (chain_circular
!= NULL
)
2652 oprintf (d
.of
, " if (!%s (xlimit", wtd
->marker_routine
);
2654 oprintf (d
.of
, " while (%s (xlimit", wtd
->marker_routine
);
2655 if (wtd
->param_prefix
)
2657 oprintf (d
.of
, ", xlimit, gt_%s_", wtd
->param_prefix
);
2658 output_mangled_typename (d
.of
, orig_s
);
2659 output_type_enum (d
.of
, orig_s
);
2661 oprintf (d
.of
, "))\n");
2662 if (chain_circular
!= NULL
)
2663 oprintf (d
.of
, " return;\n do\n");
2664 if (mark_hook_name
&& !wtd
->skip_hooks
)
2666 oprintf (d
.of
, " {\n");
2667 oprintf (d
.of
, " %s (xlimit);\n ", mark_hook_name
);
2669 oprintf (d
.of
, " xlimit = (");
2670 d
.prev_val
[2] = "*xlimit";
2671 output_escaped_param (&d
, chain_next
, "chain_next");
2672 oprintf (d
.of
, ");\n");
2673 if (mark_hook_name
&& !wtd
->skip_hooks
)
2674 oprintf (d
.of
, " }\n");
2675 if (chain_prev
!= NULL
)
2677 oprintf (d
.of
, " if (x != xlimit)\n");
2678 oprintf (d
.of
, " for (;;)\n");
2679 oprintf (d
.of
, " {\n");
2680 oprintf (d
.of
, " %s %s * const xprev = (",
2681 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
2683 d
.prev_val
[2] = "*x";
2684 output_escaped_param (&d
, chain_prev
, "chain_prev");
2685 oprintf (d
.of
, ");\n");
2686 oprintf (d
.of
, " if (xprev == NULL) break;\n");
2687 oprintf (d
.of
, " x = xprev;\n");
2688 oprintf (d
.of
, " (void) %s (xprev", wtd
->marker_routine
);
2689 if (wtd
->param_prefix
)
2691 oprintf (d
.of
, ", xprev, gt_%s_", wtd
->param_prefix
);
2692 output_mangled_typename (d
.of
, orig_s
);
2693 output_type_enum (d
.of
, orig_s
);
2695 oprintf (d
.of
, ");\n");
2696 oprintf (d
.of
, " }\n");
2698 if (chain_circular
!= NULL
)
2700 oprintf (d
.of
, " while (%s (xlimit", wtd
->marker_routine
);
2701 if (wtd
->param_prefix
)
2703 oprintf (d
.of
, ", xlimit, gt_%s_", wtd
->param_prefix
);
2704 output_mangled_typename (d
.of
, orig_s
);
2705 output_type_enum (d
.of
, orig_s
);
2707 oprintf (d
.of
, "));\n");
2708 if (mark_hook_name
&& !wtd
->skip_hooks
)
2709 oprintf (d
.of
, " %s (xlimit);\n", mark_hook_name
);
2710 oprintf (d
.of
, " do\n");
2713 oprintf (d
.of
, " while (x != xlimit)\n");
2715 oprintf (d
.of
, " {\n");
2716 if (mark_hook_name
&& chain_next
== NULL
&& !wtd
->skip_hooks
)
2718 oprintf (d
.of
, " %s (x);\n", mark_hook_name
);
2720 d
.prev_val
[2] = "*x";
2724 if (chain_next
!= NULL
)
2726 oprintf (d
.of
, " x = (");
2727 output_escaped_param (&d
, chain_next
, "chain_next");
2728 oprintf (d
.of
, ");\n");
2731 oprintf (d
.of
, " }\n");
2732 if (chain_circular
!= NULL
)
2733 oprintf (d
.of
, " while (x != xlimit);\n");
2734 oprintf (d
.of
, "}\n");
2737 /* Write out marker routines for STRUCTURES and PARAM_STRUCTS. */
2740 write_types (outf_p output_header
, type_p structures
, type_p param_structs
,
2741 const struct write_types_data
*wtd
)
2745 oprintf (output_header
, "\n/* %s*/\n", wtd
->comment
);
2746 /* We first emit the macros and the declarations. Functions' code is
2747 emitted afterwards. This is needed in plugin mode. */
2748 oprintf (output_header
, "/* macros and declarations */\n");
2749 for (s
= structures
; s
; s
= s
->next
)
2750 if (s
->gc_used
== GC_POINTED_TO
|| s
->gc_used
== GC_MAYBE_POINTED_TO
)
2754 if (s
->gc_used
== GC_MAYBE_POINTED_TO
&& s
->u
.s
.line
.file
== NULL
)
2757 oprintf (output_header
, "#define gt_%s_", wtd
->prefix
);
2758 output_mangled_typename (output_header
, s
);
2759 oprintf (output_header
, "(X) do { \\\n");
2760 oprintf (output_header
,
2761 " if (X != NULL) gt_%sx_%s (X);\\\n", wtd
->prefix
,
2763 oprintf (output_header
, " } while (0)\n");
2765 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
2766 if (strcmp (opt
->name
, "ptr_alias") == 0)
2768 const_type_p
const t
= (const_type_p
) opt
->info
;
2769 if (t
->kind
== TYPE_STRUCT
2770 || t
->kind
== TYPE_UNION
|| t
->kind
== TYPE_LANG_STRUCT
)
2771 oprintf (output_header
,
2772 "#define gt_%sx_%s gt_%sx_%s\n",
2773 wtd
->prefix
, s
->u
.s
.tag
, wtd
->prefix
, t
->u
.s
.tag
);
2775 error_at_line (&s
->u
.s
.line
,
2776 "structure alias is not a structure");
2782 /* Declare the marker procedure only once. */
2783 oprintf (output_header
,
2784 "extern void gt_%sx_%s (void *);\n",
2785 wtd
->prefix
, s
->u
.s
.tag
);
2787 if (s
->u
.s
.line
.file
== NULL
)
2789 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
2795 for (s
= param_structs
; s
; s
= s
->next
)
2796 if (s
->gc_used
== GC_POINTED_TO
)
2798 type_p stru
= s
->u
.param_struct
.stru
;
2800 /* Declare the marker procedure. */
2801 oprintf (output_header
, "extern void gt_%s_", wtd
->prefix
);
2802 output_mangled_typename (output_header
, s
);
2803 oprintf (output_header
, " (void *);\n");
2805 if (stru
->u
.s
.line
.file
== NULL
)
2807 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
2813 /* At last we emit the functions code. */
2814 oprintf (output_header
, "\n/* functions code */\n");
2815 for (s
= structures
; s
; s
= s
->next
)
2816 if (s
->gc_used
== GC_POINTED_TO
|| s
->gc_used
== GC_MAYBE_POINTED_TO
)
2820 if (s
->gc_used
== GC_MAYBE_POINTED_TO
&& s
->u
.s
.line
.file
== NULL
)
2822 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
2823 if (strcmp (opt
->name
, "ptr_alias") == 0)
2828 if (s
->kind
== TYPE_LANG_STRUCT
)
2831 for (ss
= s
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2832 write_func_for_structure (s
, ss
, NULL
, wtd
);
2835 write_func_for_structure (s
, s
, NULL
, wtd
);
2837 for (s
= param_structs
; s
; s
= s
->next
)
2838 if (s
->gc_used
== GC_POINTED_TO
)
2840 type_p
*param
= s
->u
.param_struct
.param
;
2841 type_p stru
= s
->u
.param_struct
.stru
;
2842 if (stru
->u
.s
.line
.file
== NULL
)
2844 if (stru
->kind
== TYPE_LANG_STRUCT
)
2847 for (ss
= stru
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2848 write_func_for_structure (s
, ss
, param
, wtd
);
2851 write_func_for_structure (s
, stru
, param
, wtd
);
2855 static const struct write_types_data ggc_wtd
= {
2856 "ggc_m", NULL
, "ggc_mark", "ggc_test_and_set_mark", NULL
,
2857 "GC marker procedures. ",
2861 static const struct write_types_data pch_wtd
= {
2862 "pch_n", "pch_p", "gt_pch_note_object", "gt_pch_note_object",
2863 "gt_pch_note_reorder",
2864 "PCH type-walking procedures. ",
2868 /* Write out the local pointer-walking routines. */
2870 /* process_field routine for local pointer-walking. */
2873 write_types_local_process_field (type_p f
, const struct walk_type_data
*d
)
2880 case TYPE_LANG_STRUCT
:
2881 case TYPE_PARAM_STRUCT
:
2883 oprintf (d
->of
, "%*sif ((void *)(%s) == this_obj)\n", d
->indent
, "",
2885 oprintf (d
->of
, "%*s op (&(%s), cookie);\n", d
->indent
, "", d
->val
);
2896 /* For S, a structure that's part of ORIG_S, and using parameters
2897 PARAM, write out a routine that:
2898 - Is of type gt_note_pointers
2899 - Calls PROCESS_FIELD on each field of S or its substructures.
2903 write_local_func_for_structure (const_type_p orig_s
, type_p s
, type_p
*param
)
2905 struct walk_type_data d
;
2907 memset (&d
, 0, sizeof (d
));
2908 d
.of
= get_output_file_for_structure (s
, param
);
2909 d
.process_field
= write_types_local_process_field
;
2911 d
.line
= &s
->u
.s
.line
;
2912 d
.bitmap
= s
->u
.s
.bitmap
;
2914 d
.prev_val
[0] = d
.prev_val
[2] = "*x";
2915 d
.prev_val
[1] = "not valid postage"; /* Guarantee an error. */
2916 d
.prev_val
[3] = "x";
2918 d
.fn_wants_lvalue
= true;
2920 oprintf (d
.of
, "\n");
2921 oprintf (d
.of
, "void\n");
2922 oprintf (d
.of
, "gt_pch_p_");
2923 output_mangled_typename (d
.of
, orig_s
);
2924 oprintf (d
.of
, " (ATTRIBUTE_UNUSED void *this_obj,\n"
2926 "\tATTRIBUTE_UNUSED gt_pointer_operator op,\n"
2927 "\tATTRIBUTE_UNUSED void *cookie)\n");
2928 oprintf (d
.of
, "{\n");
2929 oprintf (d
.of
, " %s %s * const x ATTRIBUTE_UNUSED = (%s %s *)x_p;\n",
2930 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
,
2931 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
2934 oprintf (d
.of
, "}\n");
2937 /* Write out local marker routines for STRUCTURES and PARAM_STRUCTS. */
2940 write_local (outf_p output_header
, type_p structures
, type_p param_structs
)
2946 oprintf (output_header
, "\n/* Local pointer-walking routines. */\n");
2947 for (s
= structures
; s
; s
= s
->next
)
2948 if (s
->gc_used
== GC_POINTED_TO
|| s
->gc_used
== GC_MAYBE_POINTED_TO
)
2952 if (s
->u
.s
.line
.file
== NULL
)
2955 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
2956 if (strcmp (opt
->name
, "ptr_alias") == 0)
2958 const_type_p
const t
= (const_type_p
) opt
->info
;
2959 if (t
->kind
== TYPE_STRUCT
2960 || t
->kind
== TYPE_UNION
|| t
->kind
== TYPE_LANG_STRUCT
)
2962 oprintf (output_header
, "#define gt_pch_p_");
2963 output_mangled_typename (output_header
, s
);
2964 oprintf (output_header
, " gt_pch_p_");
2965 output_mangled_typename (output_header
, t
);
2966 oprintf (output_header
, "\n");
2969 error_at_line (&s
->u
.s
.line
,
2970 "structure alias is not a structure");
2976 /* Declare the marker procedure only once. */
2977 oprintf (output_header
, "extern void gt_pch_p_");
2978 output_mangled_typename (output_header
, s
);
2979 oprintf (output_header
,
2980 "\n (void *, void *, gt_pointer_operator, void *);\n");
2982 if (s
->kind
== TYPE_LANG_STRUCT
)
2985 for (ss
= s
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2986 write_local_func_for_structure (s
, ss
, NULL
);
2989 write_local_func_for_structure (s
, s
, NULL
);
2992 for (s
= param_structs
; s
; s
= s
->next
)
2993 if (s
->gc_used
== GC_POINTED_TO
)
2995 type_p
*param
= s
->u
.param_struct
.param
;
2996 type_p stru
= s
->u
.param_struct
.stru
;
2998 /* Declare the marker procedure. */
2999 oprintf (output_header
, "extern void gt_pch_p_");
3000 output_mangled_typename (output_header
, s
);
3001 oprintf (output_header
,
3002 "\n (void *, void *, gt_pointer_operator, void *);\n");
3004 if (stru
->u
.s
.line
.file
== NULL
)
3006 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
3011 if (stru
->kind
== TYPE_LANG_STRUCT
)
3014 for (ss
= stru
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
3015 write_local_func_for_structure (s
, ss
, param
);
3018 write_local_func_for_structure (s
, stru
, param
);
3022 /* Nonzero if S is a type for which typed GC allocators should be output. */
3024 #define USED_BY_TYPED_GC_P(s) \
3025 (((s->kind == TYPE_POINTER) \
3026 && ((s->u.p->gc_used == GC_POINTED_TO) \
3027 || (s->u.p->gc_used == GC_USED))) \
3028 || (UNION_OR_STRUCT_P (s) && \
3029 (((s)->gc_used == GC_POINTED_TO) \
3030 || ((s)->gc_used == GC_MAYBE_POINTED_TO \
3031 && s->u.s.line.file != NULL) \
3032 || ((s)->gc_used == GC_USED \
3033 && strncmp (s->u.s.tag, "anonymous", strlen ("anonymous"))))))
3036 /* Write out the 'enum' definition for gt_types_enum. */
3039 write_enum_defn (type_p structures
, type_p param_structs
)
3045 oprintf (header_file
, "\n/* Enumeration of types known. */\n");
3046 oprintf (header_file
, "enum gt_types_enum {\n");
3047 for (s
= structures
; s
; s
= s
->next
)
3048 if (USED_BY_TYPED_GC_P (s
))
3050 oprintf (header_file
, " gt_ggc_e_");
3051 output_mangled_typename (header_file
, s
);
3052 oprintf (header_file
, ",\n");
3054 for (s
= param_structs
; s
; s
= s
->next
)
3055 if (s
->gc_used
== GC_POINTED_TO
)
3057 oprintf (header_file
, " gt_e_");
3058 output_mangled_typename (header_file
, s
);
3059 oprintf (header_file
, ",\n");
3061 oprintf (header_file
, " gt_types_enum_last\n");
3062 oprintf (header_file
, "};\n");
3065 /* Might T contain any non-pointer elements? */
3068 contains_scalar_p (type_p t
)
3076 return contains_scalar_p (t
->u
.a
.p
);
3078 /* Could also check for structures that have no non-pointer
3079 fields, but there aren't enough of those to worry about. */
3084 /* Mangle FN and print it to F. */
3087 put_mangled_filename (outf_p f
, const char *fn
)
3089 const char *name
= get_output_file_name (fn
);
3092 for (; *name
!= 0; name
++)
3093 if (ISALNUM (*name
))
3094 oprintf (f
, "%c", *name
);
3096 oprintf (f
, "%c", '_');
3099 /* Finish off the currently-created root tables in FLP. PFX, TNAME,
3100 LASTNAME, and NAME are all strings to insert in various places in
3101 the resulting code. */
3104 finish_root_table (struct flist
*flp
, const char *pfx
, const char *lastname
,
3105 const char *tname
, const char *name
)
3109 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
3110 if (fli2
->started_p
)
3112 oprintf (fli2
->f
, " %s\n", lastname
);
3113 oprintf (fli2
->f
, "};\n\n");
3116 for (fli2
= flp
; fli2
&& base_files
; fli2
= fli2
->next
)
3117 if (fli2
->started_p
)
3119 lang_bitmap bitmap
= get_lang_bitmap (fli2
->name
);
3122 for (fnum
= 0; bitmap
!= 0; fnum
++, bitmap
>>= 1)
3125 oprintf (base_files
[fnum
],
3126 "extern const struct %s gt_%s_", tname
, pfx
);
3127 put_mangled_filename (base_files
[fnum
], fli2
->name
);
3128 oprintf (base_files
[fnum
], "[];\n");
3134 for (fnum
= 0; base_files
&& fnum
< num_lang_dirs
; fnum
++)
3135 oprintf (base_files
[fnum
],
3136 "EXPORTED_CONST struct %s * const %s[] = {\n", tname
, name
);
3140 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
3141 if (fli2
->started_p
)
3143 lang_bitmap bitmap
= get_lang_bitmap (fli2
->name
);
3146 fli2
->started_p
= 0;
3148 for (fnum
= 0; base_files
&& bitmap
!= 0; fnum
++, bitmap
>>= 1)
3151 oprintf (base_files
[fnum
], " gt_%s_", pfx
);
3152 put_mangled_filename (base_files
[fnum
], fli2
->name
);
3153 oprintf (base_files
[fnum
], ",\n");
3159 for (fnum
= 0; base_files
&& fnum
< num_lang_dirs
; fnum
++)
3161 oprintf (base_files
[fnum
], " NULL\n");
3162 oprintf (base_files
[fnum
], "};\n");
3167 /* Write the first three fields (pointer, count and stride) for
3168 root NAME to F. V and LINE are as for write_root.
3170 Return true if the entry could be written; return false on error. */
3173 start_root_entry (outf_p f
, pair_p v
, const char *name
, struct fileloc
*line
)
3179 error_at_line (line
, "`%s' is too complex to be a root", name
);
3183 oprintf (f
, " {\n");
3184 oprintf (f
, " &%s,\n", name
);
3187 for (ap
= v
->type
; ap
->kind
== TYPE_ARRAY
; ap
= ap
->u
.a
.p
)
3189 oprintf (f
, " * (%s)", ap
->u
.a
.len
);
3190 else if (ap
== v
->type
)
3191 oprintf (f
, " * ARRAY_SIZE (%s)", v
->name
);
3193 oprintf (f
, " sizeof (%s", v
->name
);
3194 for (ap
= v
->type
; ap
->kind
== TYPE_ARRAY
; ap
= ap
->u
.a
.p
)
3196 oprintf (f
, "),\n");
3200 /* A subroutine of write_root for writing the roots for field FIELD_NAME,
3201 which has type FIELD_TYPE. Parameters F to EMIT_PCH are the parameters
3205 write_field_root (outf_p f
, pair_p v
, type_p type
, const char *name
,
3206 int has_length
, struct fileloc
*line
, const char *if_marked
,
3207 bool emit_pch
, type_p field_type
, const char *field_name
)
3209 /* If the field reference is relative to V, rather than to some
3210 subcomponent of V, we can mark any subarrays with a single stride.
3211 We're effectively treating the field as a global variable in its
3213 if (v
&& type
== v
->type
)
3218 newv
.type
= field_type
;
3219 newv
.name
= ACONCAT ((v
->name
, ".", field_name
, NULL
));
3222 /* Otherwise, any arrays nested in the structure are too complex to
3224 else if (field_type
->kind
== TYPE_ARRAY
)
3226 write_root (f
, v
, field_type
, ACONCAT ((name
, ".", field_name
, NULL
)),
3227 has_length
, line
, if_marked
, emit_pch
);
3230 /* Write out to F the table entry and any marker routines needed to
3231 mark NAME as TYPE. V can be one of three values:
3233 - null, if NAME is too complex to represent using a single
3234 count and stride. In this case, it is an error for NAME to
3235 contain any gc-ed data.
3237 - the outermost array that contains NAME, if NAME is part of an array.
3239 - the C variable that contains NAME, if NAME is not part of an array.
3241 LINE is the line of the C source that declares the root variable.
3242 HAS_LENGTH is nonzero iff V was a variable-length array. IF_MARKED
3243 is nonzero iff we are building the root table for hash table caches. */
3246 write_root (outf_p f
, pair_p v
, type_p type
, const char *name
, int has_length
,
3247 struct fileloc
*line
, const char *if_marked
, bool emit_pch
)
3254 for (fld
= type
->u
.s
.fields
; fld
; fld
= fld
->next
)
3257 const char *desc
= NULL
;
3260 for (o
= fld
->opt
; o
; o
= o
->next
)
3261 if (strcmp (o
->name
, "skip") == 0)
3263 else if (strcmp (o
->name
, "desc") == 0)
3265 else if (strcmp (o
->name
, "param_is") == 0)
3268 error_at_line (line
,
3269 "field `%s' of global `%s' has unknown option `%s'",
3270 fld
->name
, name
, o
->name
);
3274 else if (desc
&& fld
->type
->kind
== TYPE_UNION
)
3276 pair_p validf
= NULL
;
3279 for (ufld
= fld
->type
->u
.s
.fields
; ufld
; ufld
= ufld
->next
)
3281 const char *tag
= NULL
;
3284 for (oo
= ufld
->opt
; oo
; oo
= oo
->next
)
3285 if (strcmp (oo
->name
, "tag") == 0)
3287 if (tag
== NULL
|| strcmp (tag
, desc
) != 0)
3290 error_at_line (line
,
3291 "both `%s.%s.%s' and `%s.%s.%s' have tag `%s'",
3292 name
, fld
->name
, validf
->name
,
3293 name
, fld
->name
, ufld
->name
, tag
);
3297 write_field_root (f
, v
, type
, name
, 0, line
, if_marked
,
3298 emit_pch
, validf
->type
,
3299 ACONCAT ((fld
->name
, ".",
3300 validf
->name
, NULL
)));
3303 error_at_line (line
,
3304 "global `%s.%s' has `desc' option but is not union",
3307 write_field_root (f
, v
, type
, name
, 0, line
, if_marked
,
3308 emit_pch
, fld
->type
, fld
->name
);
3316 newname
= xasprintf ("%s[0]", name
);
3317 write_root (f
, v
, type
->u
.a
.p
, newname
, has_length
, line
, if_marked
,
3327 if (!start_root_entry (f
, v
, name
, line
))
3332 if (!has_length
&& UNION_OR_STRUCT_P (tp
))
3334 oprintf (f
, " >_ggc_mx_%s,\n", tp
->u
.s
.tag
);
3336 oprintf (f
, " >_pch_nx_%s", tp
->u
.s
.tag
);
3338 oprintf (f
, " NULL");
3340 else if (!has_length
&& tp
->kind
== TYPE_PARAM_STRUCT
)
3342 oprintf (f
, " >_ggc_m_");
3343 output_mangled_typename (f
, tp
);
3346 oprintf (f
, ",\n >_pch_n_");
3347 output_mangled_typename (f
, tp
);
3350 oprintf (f
, ",\n NULL");
3353 && (tp
->kind
== TYPE_POINTER
|| UNION_OR_STRUCT_P (tp
)))
3355 oprintf (f
, " >_ggc_ma_%s,\n", name
);
3357 oprintf (f
, " >_pch_na_%s", name
);
3359 oprintf (f
, " NULL");
3363 error_at_line (line
,
3364 "global `%s' is pointer to unimplemented type",
3368 oprintf (f
, ",\n &%s", if_marked
);
3369 oprintf (f
, "\n },\n");
3375 if (!start_root_entry (f
, v
, name
, line
))
3378 oprintf (f
, " (gt_pointer_walker) >_ggc_m_S,\n");
3379 oprintf (f
, " (gt_pointer_walker) >_pch_n_S\n");
3380 oprintf (f
, " },\n");
3388 error_at_line (line
, "global `%s' is unimplemented type", name
);
3392 /* This generates a routine to walk an array. */
3395 write_array (outf_p f
, pair_p v
, const struct write_types_data
*wtd
)
3397 struct walk_type_data d
;
3400 memset (&d
, 0, sizeof (d
));
3406 d
.bitmap
= get_lang_bitmap (v
->line
.file
);
3409 d
.prev_val
[3] = prevval3
= xasprintf ("&%s", v
->name
);
3411 if (wtd
->param_prefix
)
3413 oprintf (f
, "static void gt_%sa_%s\n", wtd
->param_prefix
, v
->name
);
3414 oprintf (f
, " (void *, void *, gt_pointer_operator, void *);\n");
3415 oprintf (f
, "static void gt_%sa_%s (ATTRIBUTE_UNUSED void *this_obj,\n",
3416 wtd
->param_prefix
, v
->name
);
3418 " ATTRIBUTE_UNUSED void *x_p,\n"
3419 " ATTRIBUTE_UNUSED gt_pointer_operator op,\n"
3420 " ATTRIBUTE_UNUSED void * cookie)\n");
3421 oprintf (d
.of
, "{\n");
3422 d
.prev_val
[0] = d
.prev_val
[1] = d
.prev_val
[2] = d
.val
= v
->name
;
3423 d
.process_field
= write_types_local_process_field
;
3424 walk_type (v
->type
, &d
);
3425 oprintf (f
, "}\n\n");
3429 oprintf (f
, "static void gt_%sa_%s (void *);\n", wtd
->prefix
, v
->name
);
3430 oprintf (f
, "static void\ngt_%sa_%s (ATTRIBUTE_UNUSED void *x_p)\n",
3431 wtd
->prefix
, v
->name
);
3433 d
.prev_val
[0] = d
.prev_val
[1] = d
.prev_val
[2] = d
.val
= v
->name
;
3434 d
.process_field
= write_types_process_field
;
3435 walk_type (v
->type
, &d
);
3437 oprintf (f
, "}\n\n");
3440 /* Output a table describing the locations and types of VARIABLES. */
3443 write_roots (pair_p variables
, bool emit_pch
)
3446 struct flist
*flp
= NULL
;
3448 for (v
= variables
; v
; v
= v
->next
)
3450 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
3452 const char *length
= NULL
;
3453 int deletable_p
= 0;
3456 for (o
= v
->opt
; o
; o
= o
->next
)
3457 if (strcmp (o
->name
, "length") == 0)
3459 else if (strcmp (o
->name
, "deletable") == 0)
3461 else if (strcmp (o
->name
, "param_is") == 0)
3463 else if (strncmp (o
->name
, "param", 5) == 0
3464 && ISDIGIT (o
->name
[5]) && strcmp (o
->name
+ 6, "_is") == 0)
3466 else if (strcmp (o
->name
, "if_marked") == 0)
3469 error_at_line (&v
->line
,
3470 "global `%s' has unknown option `%s'",
3473 for (fli
= flp
; fli
; fli
= fli
->next
)
3474 if (fli
->f
== f
&& f
)
3478 fli
= XNEW (struct flist
);
3482 fli
->name
= v
->line
.file
;
3483 gcc_assert (fli
->name
);
3486 oprintf (f
, "\n/* GC roots. */\n\n");
3491 && v
->type
->kind
== TYPE_POINTER
3492 && (v
->type
->u
.p
->kind
== TYPE_POINTER
3493 || v
->type
->u
.p
->kind
== TYPE_STRUCT
))
3495 write_array (f
, v
, &ggc_wtd
);
3496 write_array (f
, v
, &pch_wtd
);
3500 for (v
= variables
; v
; v
= v
->next
)
3502 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
3508 for (o
= v
->opt
; o
; o
= o
->next
)
3509 if (strcmp (o
->name
, "length") == 0)
3511 else if (strcmp (o
->name
, "deletable") == 0
3512 || strcmp (o
->name
, "if_marked") == 0)
3518 for (fli
= flp
; fli
; fli
= fli
->next
)
3521 if (!fli
->started_p
)
3525 oprintf (f
, "EXPORTED_CONST struct ggc_root_tab gt_ggc_r_");
3526 put_mangled_filename (f
, v
->line
.file
);
3527 oprintf (f
, "[] = {\n");
3530 write_root (f
, v
, v
->type
, v
->name
, length_p
, &v
->line
, NULL
, emit_pch
);
3533 finish_root_table (flp
, "ggc_r", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
3536 for (v
= variables
; v
; v
= v
->next
)
3538 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
3543 for (o
= v
->opt
; o
; o
= o
->next
)
3544 if (strcmp (o
->name
, "deletable") == 0)
3546 else if (strcmp (o
->name
, "if_marked") == 0)
3552 for (fli
= flp
; fli
; fli
= fli
->next
)
3555 if (!fli
->started_p
)
3559 oprintf (f
, "EXPORTED_CONST struct ggc_root_tab gt_ggc_rd_");
3560 put_mangled_filename (f
, v
->line
.file
);
3561 oprintf (f
, "[] = {\n");
3564 oprintf (f
, " { &%s, 1, sizeof (%s), NULL, NULL },\n",
3568 finish_root_table (flp
, "ggc_rd", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
3569 "gt_ggc_deletable_rtab");
3571 for (v
= variables
; v
; v
= v
->next
)
3573 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
3575 const char *if_marked
= NULL
;
3579 for (o
= v
->opt
; o
; o
= o
->next
)
3580 if (strcmp (o
->name
, "length") == 0)
3582 else if (strcmp (o
->name
, "if_marked") == 0)
3583 if_marked
= o
->info
;
3585 if (if_marked
== NULL
)
3588 if (v
->type
->kind
!= TYPE_POINTER
3589 || v
->type
->u
.p
->kind
!= TYPE_PARAM_STRUCT
3590 || v
->type
->u
.p
->u
.param_struct
.stru
!= find_structure ("htab", 0))
3592 error_at_line (&v
->line
,
3593 "if_marked option used but not hash table");
3597 for (fli
= flp
; fli
; fli
= fli
->next
)
3600 if (!fli
->started_p
)
3604 oprintf (f
, "EXPORTED_CONST struct ggc_cache_tab gt_ggc_rc_");
3605 put_mangled_filename (f
, v
->line
.file
);
3606 oprintf (f
, "[] = {\n");
3609 write_root (f
, v
, v
->type
->u
.p
->u
.param_struct
.param
[0],
3610 v
->name
, length_p
, &v
->line
, if_marked
, emit_pch
);
3613 finish_root_table (flp
, "ggc_rc", "LAST_GGC_CACHE_TAB", "ggc_cache_tab",
3614 "gt_ggc_cache_rtab");
3619 for (v
= variables
; v
; v
= v
->next
)
3621 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
3624 int if_marked_p
= 0;
3627 for (o
= v
->opt
; o
; o
= o
->next
)
3628 if (strcmp (o
->name
, "length") == 0)
3630 else if (strcmp (o
->name
, "if_marked") == 0)
3636 for (fli
= flp
; fli
; fli
= fli
->next
)
3639 if (!fli
->started_p
)
3643 oprintf (f
, "EXPORTED_CONST struct ggc_root_tab gt_pch_rc_");
3644 put_mangled_filename (f
, v
->line
.file
);
3645 oprintf (f
, "[] = {\n");
3648 write_root (f
, v
, v
->type
, v
->name
, length_p
, &v
->line
, NULL
, emit_pch
);
3651 finish_root_table (flp
, "pch_rc", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
3652 "gt_pch_cache_rtab");
3654 for (v
= variables
; v
; v
= v
->next
)
3656 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
3661 for (o
= v
->opt
; o
; o
= o
->next
)
3662 if (strcmp (o
->name
, "deletable") == 0
3663 || strcmp (o
->name
, "if_marked") == 0)
3669 if (!contains_scalar_p (v
->type
))
3672 for (fli
= flp
; fli
; fli
= fli
->next
)
3675 if (!fli
->started_p
)
3679 oprintf (f
, "EXPORTED_CONST struct ggc_root_tab gt_pch_rs_");
3680 put_mangled_filename (f
, v
->line
.file
);
3681 oprintf (f
, "[] = {\n");
3684 oprintf (f
, " { &%s, 1, sizeof (%s), NULL, NULL },\n",
3688 finish_root_table (flp
, "pch_rs", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
3689 "gt_pch_scalar_rtab");
3692 /* Record the definition of a generic VEC structure, as if we had expanded
3693 the macros in vec.h:
3695 typedef struct VEC_<type>_base GTY(()) {
3698 <type> GTY((length ("%h.num"))) vec[1];
3701 where the GTY(()) tags are only present if is_scalar is _false_. */
3704 note_def_vec (const char *type_name
, bool is_scalar
, struct fileloc
*pos
)
3709 type_p len_ty
= create_scalar_type ("unsigned");
3710 const char *name
= concat ("VEC_", type_name
, "_base", (char *) 0);
3714 t
= create_scalar_type (type_name
);
3719 t
= resolve_typedef (type_name
, pos
);
3720 o
= create_option (0, "length", "%h.num");
3723 /* We assemble the field list in reverse order. */
3724 fields
= create_field_at (0, create_array (t
, "1"), "vec", o
, pos
);
3725 fields
= create_field_at (fields
, len_ty
, "alloc", 0, pos
);
3726 fields
= create_field_at (fields
, len_ty
, "num", 0, pos
);
3728 do_typedef (name
, new_structure (name
, 0, pos
, fields
, 0), pos
);
3731 /* Record the definition of an allocation-specific VEC structure, as if
3732 we had expanded the macros in vec.h:
3734 typedef struct VEC_<type>_<astrat> {
3735 VEC_<type>_base base;
3736 } VEC_<type>_<astrat>;
3739 note_def_vec_alloc (const char *type
, const char *astrat
, struct fileloc
*pos
)
3741 const char *astratname
= concat ("VEC_", type
, "_", astrat
, (char *) 0);
3742 const char *basename
= concat ("VEC_", type
, "_base", (char *) 0);
3744 pair_p field
= create_field_at (0, resolve_typedef (basename
, pos
),
3747 do_typedef (astratname
, new_structure (astratname
, 0, pos
, field
, 0), pos
);
3750 /* Returns the specifier keyword for a string or union type S, empty string
3754 get_type_specifier (const type_p s
)
3756 if (s
->kind
== TYPE_STRUCT
|| s
->kind
== TYPE_LANG_STRUCT
)
3758 if (s
->kind
== TYPE_UNION
)
3763 /* TRUE if type S has the GTY variable_size annotation. */
3766 variable_size_p (const type_p s
)
3769 for (o
= s
->u
.s
.opt
; o
; o
= o
->next
)
3770 if (strcmp (o
->name
, "variable_size") == 0)
3778 { any_zone
, specific_zone
};
3780 /* Writes one typed allocator definition for type identifier TYPE_NAME with
3781 optional type specifier TYPE_SPECIFIER. The allocator name will contain
3782 ALLOCATOR_TYPE. If VARIABLE_SIZE is true, the allocator will have an extra
3783 parameter specifying number of bytes to allocate. If QUANTITY is set to
3784 VECTOR, a vector allocator will be output, if ZONE is set to SPECIFIC_ZONE,
3785 the allocator will be zone-specific. */
3788 write_typed_alloc_def (bool variable_size
, const char *type_specifier
,
3789 const char *type_name
, const char *allocator_type
,
3790 enum alloc_quantity quantity
, enum alloc_zone zone
)
3792 bool two_args
= variable_size
&& (quantity
== vector
);
3793 bool third_arg
= ((zone
== specific_zone
)
3794 && (variable_size
|| (quantity
== vector
)));
3796 oprintf (header_file
, "#define ggc_alloc_%s%s", allocator_type
, type_name
);
3797 oprintf (header_file
, "(%s%s%s%s%s) ",
3798 (variable_size
? "SIZE" : ""),
3799 (two_args
? ", " : ""),
3800 (quantity
== vector
) ? "n" : "",
3801 (third_arg
? ", " : ""), (zone
== specific_zone
) ? "z" : "");
3802 oprintf (header_file
, "((%s%s *)", type_specifier
, type_name
);
3803 oprintf (header_file
, "(ggc_internal_%salloc_stat (", allocator_type
);
3804 if (zone
== specific_zone
)
3805 oprintf (header_file
, "z, ");
3807 oprintf (header_file
, "SIZE");
3809 oprintf (header_file
, "sizeof (%s%s)", type_specifier
, type_name
);
3810 if (quantity
== vector
)
3811 oprintf (header_file
, ", n");
3812 oprintf (header_file
, " MEM_STAT_INFO)))\n");
3815 /* Writes a typed allocator definition for a struct or union S. */
3818 write_typed_struct_alloc_def (const type_p s
, const char *allocator_type
,
3819 enum alloc_quantity quantity
,
3820 enum alloc_zone zone
)
3822 write_typed_alloc_def (variable_size_p (s
), get_type_specifier (s
),
3823 s
->u
.s
.tag
, allocator_type
, quantity
, zone
);
3826 /* Writes a typed allocator definition for a typedef P. */
3829 write_typed_typedef_alloc_def (const pair_p p
, const char *allocator_type
,
3830 enum alloc_quantity quantity
,
3831 enum alloc_zone zone
)
3833 write_typed_alloc_def (variable_size_p (p
->type
), "", p
->name
,
3834 allocator_type
, quantity
, zone
);
3837 /* Writes typed allocator definitions for the types in STRUCTURES and
3838 TYPEDEFS that are used by GC. */
3841 write_typed_alloc_defns (const type_p structures
, const pair_p typedefs
)
3846 oprintf (header_file
,
3847 "\n/* Allocators for known structs and unions. */\n\n");
3848 for (s
= structures
; s
; s
= s
->next
)
3850 if (!USED_BY_TYPED_GC_P (s
))
3852 write_typed_struct_alloc_def (s
, "", single
, any_zone
);
3853 write_typed_struct_alloc_def (s
, "cleared_", single
, any_zone
);
3854 write_typed_struct_alloc_def (s
, "vec_", vector
, any_zone
);
3855 write_typed_struct_alloc_def (s
, "cleared_vec_", vector
, any_zone
);
3856 write_typed_struct_alloc_def (s
, "zone_", single
, specific_zone
);
3857 write_typed_struct_alloc_def (s
, "zone_cleared_", single
,
3859 write_typed_struct_alloc_def (s
, "zone_vec_", vector
, specific_zone
);
3860 write_typed_struct_alloc_def (s
, "zone_cleared_vec_", vector
,
3864 oprintf (header_file
, "\n/* Allocators for known typedefs. */\n");
3865 for (p
= typedefs
; p
; p
= p
->next
)
3868 if (!USED_BY_TYPED_GC_P (s
) || (strcmp (p
->name
, s
->u
.s
.tag
) == 0))
3870 write_typed_typedef_alloc_def (p
, "", single
, any_zone
);
3871 write_typed_typedef_alloc_def (p
, "cleared_", single
, any_zone
);
3872 write_typed_typedef_alloc_def (p
, "vec_", vector
, any_zone
);
3873 write_typed_typedef_alloc_def (p
, "cleared_vec_", vector
, any_zone
);
3874 write_typed_typedef_alloc_def (p
, "zone_", single
, specific_zone
);
3875 write_typed_typedef_alloc_def (p
, "zone_cleared_", single
,
3877 write_typed_typedef_alloc_def (p
, "zone_cleared_vec_", vector
,
3882 /* Prints not-as-ugly version of a typename of T to OF. Trades the uniquness
3883 guaranteee for somewhat increased readability. If name conflicts do happen,
3884 this funcion will have to be adjusted to be more like
3885 output_mangled_typename. */
3888 output_typename (outf_p of
, const_type_p t
)
3893 oprintf (of
, "str");
3896 oprintf (of
, "scalar");
3899 output_typename (of
, t
->u
.p
);
3903 case TYPE_LANG_STRUCT
:
3904 oprintf (of
, "%s", t
->u
.s
.tag
);
3906 case TYPE_PARAM_STRUCT
:
3909 for (i
= 0; i
< NUM_PARAM
; i
++)
3910 if (t
->u
.param_struct
.param
[i
] != NULL
)
3912 output_typename (of
, t
->u
.param_struct
.param
[i
]);
3915 output_typename (of
, t
->u
.param_struct
.stru
);
3923 /* Writes a typed GC allocator for type S that is suitable as a callback for
3924 the splay tree implementation in libiberty. */
3927 write_splay_tree_allocator_def (const_type_p s
)
3929 outf_p of
= get_output_file_for_structure (s
, NULL
);
3930 oprintf (of
, "void * ggc_alloc_splay_tree_");
3931 output_typename (of
, s
);
3932 oprintf (of
, " (int sz, void * nl)\n");
3933 oprintf (of
, "{\n");
3934 oprintf (of
, " return ggc_splay_alloc (");
3935 oprintf (of
, "gt_e_");
3936 output_mangled_typename (of
, s
);
3937 oprintf (of
, ", sz, nl);\n");
3938 oprintf (of
, "}\n\n");
3941 /* Writes typed GC allocators for PARAM_STRUCTS that are suitable as callbacks
3942 for the splay tree implementation in libiberty. */
3945 write_splay_tree_allocators (const_type_p param_structs
)
3949 oprintf (header_file
, "\n/* Splay tree callback allocators. */\n");
3950 for (s
= param_structs
; s
; s
= s
->next
)
3951 if (s
->gc_used
== GC_POINTED_TO
)
3953 oprintf (header_file
, "extern void * ggc_alloc_splay_tree_");
3954 output_typename (header_file
, s
);
3955 oprintf (header_file
, " (int, void *);\n");
3956 write_splay_tree_allocator_def (s
);
3960 static void dump_pair (int indent
, pair_p p
);
3961 static void dump_type (int indent
, type_p p
);
3962 static void dump_type_list (int indent
, type_p p
);
3966 /* Dumps the value of typekind KIND. */
3969 dump_typekind (int indent
, enum typekind kind
)
3971 printf ("%*ckind = ", indent
, ' ');
3975 printf ("TYPE_SCALAR");
3978 printf ("TYPE_STRING");
3981 printf ("TYPE_STRUCT");
3984 printf ("TYPE_UNION");
3987 printf ("TYPE_POINTER");
3990 printf ("TYPE_ARRAY");
3992 case TYPE_LANG_STRUCT
:
3993 printf ("TYPE_LANG_STRUCT");
3995 case TYPE_PARAM_STRUCT
:
3996 printf ("TYPE_PARAM_STRUCT");
4004 /* Dumps the value of GC_USED flag. */
4007 dump_gc_used (int indent
, enum gc_used_enum gc_used
)
4009 printf ("%*cgc_used = ", indent
, ' ');
4013 printf ("GC_UNUSED");
4018 case GC_MAYBE_POINTED_TO
:
4019 printf ("GC_MAYBE_POINTED_TO");
4022 printf ("GC_POINTED_TO");
4030 /* Dumps the type options OPT. */
4033 dump_options (int indent
, options_p opt
)
4036 printf ("%*coptions = ", indent
, ' ');
4040 printf ("%s:%s ", o
->name
, o
->info
);
4046 /* Dumps the source file location in LINE. */
4049 dump_fileloc (int indent
, struct fileloc line
)
4051 printf ("%*cfileloc: file = %s, line = %d\n", indent
, ' ', line
.file
,
4055 /* Recursively dumps the struct, union, or a language-specific
4059 dump_type_u_s (int indent
, type_p t
)
4063 gcc_assert (t
->kind
== TYPE_STRUCT
|| t
->kind
== TYPE_UNION
4064 || t
->kind
== TYPE_LANG_STRUCT
);
4065 printf ("%*cu.s.tag = %s\n", indent
, ' ', t
->u
.s
.tag
);
4066 dump_fileloc (indent
, t
->u
.s
.line
);
4067 printf ("%*cu.s.fields =\n", indent
, ' ');
4068 fields
= t
->u
.s
.fields
;
4071 dump_pair (indent
+ INDENT
, fields
);
4072 fields
= fields
->next
;
4074 printf ("%*cend of fields of type %p\n", indent
, ' ', (void *) t
);
4075 dump_options (indent
, t
->u
.s
.opt
);
4076 printf ("%*cu.s.bitmap = %X\n", indent
, ' ', t
->u
.s
.bitmap
);
4077 if (t
->kind
== TYPE_LANG_STRUCT
)
4079 printf ("%*cu.s.lang_struct:\n", indent
, ' ');
4080 dump_type_list (indent
+ INDENT
, t
->u
.s
.lang_struct
);
4084 /* Recursively dumps the array T. */
4087 dump_type_u_a (int indent
, type_p t
)
4089 gcc_assert (t
->kind
== TYPE_ARRAY
);
4090 printf ("%*clen = %s, u.a.p:\n", indent
, ' ', t
->u
.a
.len
);
4091 dump_type_list (indent
+ INDENT
, t
->u
.a
.p
);
4094 /* Recursively dumps the parameterized struct T. */
4097 dump_type_u_param_struct (int indent
, type_p t
)
4100 gcc_assert (t
->kind
== TYPE_PARAM_STRUCT
);
4101 printf ("%*cu.param_struct.stru:\n", indent
, ' ');
4102 dump_type_list (indent
, t
->u
.param_struct
.stru
);
4103 dump_fileloc (indent
, t
->u
.param_struct
.line
);
4104 for (i
= 0; i
< NUM_PARAM
; i
++)
4106 if (t
->u
.param_struct
.param
[i
] == NULL
)
4108 printf ("%*cu.param_struct.param[%d]:\n", indent
, ' ', i
);
4109 dump_type (indent
+ INDENT
, t
->u
.param_struct
.param
[i
]);
4113 /* Recursively dumps the type list T. */
4116 dump_type_list (int indent
, type_p t
)
4121 dump_type (indent
, p
);
4126 static htab_t seen_types
;
4128 /* Recursively dumps the type T if it was not dumped previously. */
4131 dump_type (int indent
, type_p t
)
4135 printf ("%*cType at %p: ", indent
, ' ', (void *) t
);
4136 slot
= htab_find_slot (seen_types
, t
, INSERT
);
4139 printf ("already seen.\n");
4145 dump_typekind (indent
, t
->kind
);
4146 printf ("%*cpointer_to = %p\n", indent
+ INDENT
, ' ',
4147 (void *) t
->pointer_to
);
4148 dump_gc_used (indent
+ INDENT
, t
->gc_used
);
4152 printf ("%*cscalar_is_char = %s\n", indent
+ INDENT
, ' ',
4153 t
->u
.scalar_is_char
? "true" : "false");
4159 case TYPE_LANG_STRUCT
:
4160 dump_type_u_s (indent
+ INDENT
, t
);
4163 printf ("%*cp:\n", indent
+ INDENT
, ' ');
4164 dump_type (indent
+ INDENT
, t
->u
.p
);
4167 dump_type_u_a (indent
+ INDENT
, t
);
4169 case TYPE_PARAM_STRUCT
:
4170 dump_type_u_param_struct (indent
+ INDENT
, t
);
4175 printf ("%*cEnd of type at %p\n", indent
, ' ', (void *) t
);
4178 /* Dumps the pair P. */
4181 dump_pair (int indent
, pair_p p
)
4183 printf ("%*cpair: name = %s\n", indent
, ' ', p
->name
);
4184 dump_type (indent
, p
->type
);
4185 dump_fileloc (indent
, p
->line
);
4186 dump_options (indent
, p
->opt
);
4187 printf ("%*cEnd of pair %s\n", indent
, ' ', p
->name
);
4190 /* Dumps the list of pairs PP. */
4193 dump_pair_list (const char *name
, pair_p pp
)
4196 printf ("%s:\n", name
);
4197 for (p
= pp
; p
!= NULL
; p
= p
->next
)
4199 printf ("End of %s\n\n", name
);
4202 /* Dumps the STRUCTURES. */
4205 dump_structures (const char *name
, type_p structures
)
4207 printf ("%s:\n", name
);
4208 dump_type_list (0, structures
);
4209 printf ("End of %s\n\n", name
);
4212 /* Dumps the internal structures of gengtype. */
4215 dump_everything (void)
4217 seen_types
= htab_create (100, htab_hash_pointer
, htab_eq_pointer
, NULL
);
4218 dump_pair_list ("typedefs", typedefs
);
4219 dump_structures ("structures", structures
);
4220 dump_structures ("param_structs", param_structs
);
4221 dump_pair_list ("variables", variables
);
4222 htab_delete (seen_types
);
4227 main (int argc
, char **argv
)
4230 static struct fileloc pos
= { this_file
, 0 };
4231 char *inputlist
= 0;
4233 outf_p output_header
;
4234 char *plugin_output_filename
= NULL
;
4235 /* fatal uses this */
4236 progname
= "gengtype";
4238 if (argc
>= 2 && !strcmp (argv
[1], "-d"))
4245 if (argc
>= 6 && !strcmp (argv
[1], "-P"))
4247 plugin_output_filename
= argv
[2];
4248 plugin_output
= create_file ("GCC", plugin_output_filename
);
4250 inputlist
= argv
[4];
4251 nb_plugin_files
= argc
- 5;
4252 plugin_files
= XCNEWVEC (char *, nb_plugin_files
);
4253 for (i
= 0; i
< nb_plugin_files
; i
++)
4255 /* Place an all zero lang_bitmap before the plugin file
4257 char *name
= argv
[i
+ 5];
4258 int len
= strlen (name
) + 1 + sizeof (lang_bitmap
);
4259 plugin_files
[i
] = XCNEWVEC (char, len
) + sizeof (lang_bitmap
);
4260 strcpy (plugin_files
[i
], name
);
4266 inputlist
= argv
[2];
4269 fatal ("usage: gengtype [-d] [-P pluginout.h] srcdir input-list "
4270 "[file1 file2 ... fileN]");
4272 srcdir_len
= strlen (srcdir
);
4274 read_input_list (inputlist
);
4278 scalar_char
.u
.scalar_is_char
= true;
4279 scalar_nonchar
.u
.scalar_is_char
= false;
4282 /* These types are set up with #define or else outside of where
4284 pos
.line
= __LINE__
+ 1;
4285 do_scalar_typedef ("CUMULATIVE_ARGS", &pos
);
4287 do_scalar_typedef ("REAL_VALUE_TYPE", &pos
);
4289 do_scalar_typedef ("FIXED_VALUE_TYPE", &pos
);
4291 do_scalar_typedef ("double_int", &pos
);
4293 do_scalar_typedef ("uint64_t", &pos
);
4295 do_scalar_typedef ("uint8", &pos
);
4297 do_scalar_typedef ("jword", &pos
);
4299 do_scalar_typedef ("JCF_u2", &pos
);
4301 do_scalar_typedef ("void", &pos
);
4303 do_typedef ("PTR", create_pointer (resolve_typedef ("void", &pos
)), &pos
);
4305 for (i
= 0; i
< num_gt_files
; i
++)
4306 parse_file (gt_files
[i
]);
4311 set_gc_used (variables
);
4314 write_enum_defn (structures
, param_structs
);
4315 write_typed_alloc_defns (structures
, typedefs
);
4316 output_header
= plugin_output
? plugin_output
: header_file
;
4317 write_types (output_header
, structures
, param_structs
, &ggc_wtd
);
4318 if (plugin_files
== NULL
)
4320 write_types (header_file
, structures
, param_structs
, &pch_wtd
);
4321 write_local (header_file
, structures
, param_structs
);
4323 write_splay_tree_allocators (param_structs
);
4324 write_roots (variables
, plugin_files
== NULL
);
4326 close_output_files ();
4333 for (i
= 0; i
< nb_plugin_files
; i
++)
4334 free (plugin_files
[i
] - sizeof (lang_bitmap
));
4335 free (plugin_files
);