1 /* Process source files and output type information.
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 /* Nonzero iff an error has occurred. */
27 static int hit_error
= 0;
29 static void open_base_files
PARAMS ((void));
30 static void close_output_files
PARAMS ((void));
33 /* Report an error at POS, printing MSG. */
36 error_at_line
VPARAMS ((struct fileloc
*pos
, const char *msg
, ...))
39 VA_FIXEDARG (ap
, struct fileloc
*, pos
);
40 VA_FIXEDARG (ap
, const char *, msg
);
42 fprintf (stderr
, "%s:%d: ", pos
->file
, pos
->line
);
43 vfprintf (stderr
, msg
, ap
);
50 /* vasprintf, but produces fatal message on out-of-memory. */
52 xvasprintf (result
, format
, args
)
57 int ret
= vasprintf (result
, format
, args
);
58 if (*result
== NULL
|| ret
< 0)
60 fputs ("gengtype: out of memory", stderr
);
66 /* Wrapper for xvasprintf. */
68 xasprintf
VPARAMS ((const char *format
, ...))
72 VA_FIXEDARG (ap
, const char *, format
);
73 xvasprintf (&result
, format
, ap
);
78 /* The one and only TYPE_STRING. */
80 struct type string_type
= {
81 TYPE_STRING
, NULL
, NULL
, GC_USED
85 /* Lists of various things. */
87 static pair_p typedefs
;
88 static type_p structures
;
89 static type_p param_structs
;
90 static pair_p variables
;
92 /* Define S as a typedef to T at POS. */
95 do_typedef (s
, t
, pos
)
102 for (p
= typedefs
; p
!= NULL
; p
= p
->next
)
103 if (strcmp (p
->name
, s
) == 0)
107 error_at_line (pos
, "type `%s' previously defined", s
);
108 error_at_line (&p
->line
, "previously defined here");
113 p
= xmalloc (sizeof (struct pair
));
121 /* Return the type previously defined for S. Use POS to report errors. */
124 resolve_typedef (s
, pos
)
129 for (p
= typedefs
; p
!= NULL
; p
= p
->next
)
130 if (strcmp (p
->name
, s
) == 0)
132 error_at_line (pos
, "unidentified type `%s'", s
);
133 return create_scalar_type ("char", 4);
136 /* Create a new structure with tag NAME (or a union iff ISUNION is nonzero),
137 at POS with fields FIELDS and options O. */
140 new_structure (name
, isunion
, pos
, fields
, o
)
149 lang_bitmap bitmap
= get_base_file_bitmap (pos
->file
);
151 for (si
= structures
; si
!= NULL
; si
= si
->next
)
152 if (strcmp (name
, si
->u
.s
.tag
) == 0
153 && UNION_P (si
) == isunion
)
156 if (si
->kind
== TYPE_LANG_STRUCT
)
160 for (si
= ls
->u
.s
.lang_struct
; si
!= NULL
; si
= si
->next
)
161 if (si
->u
.s
.bitmap
== bitmap
)
164 else if (si
->u
.s
.line
.file
!= NULL
&& si
->u
.s
.bitmap
!= bitmap
)
167 si
= xcalloc (1, sizeof (struct type
));
168 memcpy (si
, ls
, sizeof (struct type
));
169 ls
->kind
= TYPE_LANG_STRUCT
;
170 ls
->u
.s
.lang_struct
= si
;
171 ls
->u
.s
.fields
= NULL
;
173 si
->pointer_to
= NULL
;
174 si
->u
.s
.lang_struct
= ls
;
179 if (ls
!= NULL
&& s
== NULL
)
181 s
= xcalloc (1, sizeof (struct type
));
182 s
->next
= ls
->u
.s
.lang_struct
;
183 ls
->u
.s
.lang_struct
= s
;
184 s
->u
.s
.lang_struct
= ls
;
191 s
= xcalloc (1, sizeof (struct type
));
192 s
->next
= structures
;
196 if (s
->u
.s
.line
.file
!= NULL
197 || (s
->u
.s
.lang_struct
&& (s
->u
.s
.lang_struct
->u
.s
.bitmap
& bitmap
)))
199 error_at_line (pos
, "duplicate structure definition");
200 error_at_line (&s
->u
.s
.line
, "previous definition here");
203 s
->kind
= isunion
? TYPE_UNION
: TYPE_STRUCT
;
206 s
->u
.s
.fields
= fields
;
208 s
->u
.s
.bitmap
= bitmap
;
209 if (s
->u
.s
.lang_struct
)
210 s
->u
.s
.lang_struct
->u
.s
.bitmap
|= bitmap
;
213 /* Return the previously-defined structure with tag NAME (or a union
214 iff ISUNION is nonzero), or a new empty structure or union if none
215 was defined previously. */
218 find_structure (name
, isunion
)
224 for (s
= structures
; s
!= NULL
; s
= s
->next
)
225 if (strcmp (name
, s
->u
.s
.tag
) == 0
226 && UNION_P (s
) == isunion
)
229 s
= xcalloc (1, sizeof (struct type
));
230 s
->next
= structures
;
232 s
->kind
= isunion
? TYPE_UNION
: TYPE_STRUCT
;
238 /* Return a scalar type with name NAME. */
241 create_scalar_type (name
, name_len
)
245 type_p r
= xcalloc (1, sizeof (struct type
));
246 r
->kind
= TYPE_SCALAR
;
247 r
->u
.sc
= xmemdup (name
, name_len
, name_len
+ 1);
251 /* Return a pointer to T. */
259 type_p r
= xcalloc (1, sizeof (struct type
));
260 r
->kind
= TYPE_POINTER
;
264 return t
->pointer_to
;
267 /* Return an array of length LEN. */
270 create_array (t
, len
)
276 v
= xcalloc (1, sizeof (*v
));
277 v
->kind
= TYPE_ARRAY
;
283 /* Perform any special processing on a type T, about to become the type
284 of a field. Return the appropriate type for the field.
286 - Converts pointer-to-char, with no length parameter, to TYPE_STRING;
287 - Similarly for arrays of pointer-to-char;
288 - Converts structures for which a parameter is provided to
293 adjust_field_type (t
, opt
)
298 const int pointer_p
= t
->kind
== TYPE_POINTER
;
300 for (; opt
; opt
= opt
->next
)
301 if (strcmp (opt
->name
, "length") == 0)
303 else if (strcmp (opt
->name
, "param_is") == 0)
310 for (realt
= param_structs
; realt
; realt
= realt
->next
)
311 if (realt
->u
.param_struct
.stru
== t
312 && realt
->u
.param_struct
.param
== (type_p
) opt
->info
)
313 return pointer_p
? create_pointer (realt
) : realt
;
314 realt
= xcalloc (1, sizeof (*realt
));
315 realt
->kind
= TYPE_PARAM_STRUCT
;
316 realt
->next
= param_structs
;
317 param_structs
= realt
;
318 realt
->u
.param_struct
.stru
= t
;
319 realt
->u
.param_struct
.param
= (type_p
) opt
->info
;
320 return pointer_p
? create_pointer (realt
) : realt
;
325 && t
->u
.p
->kind
== TYPE_SCALAR
326 && (strcmp (t
->u
.p
->u
.sc
, "char") == 0
327 || strcmp (t
->u
.p
->u
.sc
, "unsigned char") == 0))
329 if (t
->kind
== TYPE_ARRAY
&& t
->u
.a
.p
->kind
== TYPE_POINTER
330 && t
->u
.a
.p
->u
.p
->kind
== TYPE_SCALAR
331 && (strcmp (t
->u
.a
.p
->u
.p
->u
.sc
, "char") == 0
332 || strcmp (t
->u
.a
.p
->u
.p
->u
.sc
, "unsigned char") == 0))
333 return create_array (&string_type
, t
->u
.a
.len
);
338 /* Add a variable named S of type T with options O defined at POS,
342 note_variable (s
, t
, o
, pos
)
349 n
= xmalloc (sizeof (*n
));
358 /* Create a union for YYSTYPE, as yacc would do it, given a fieldlist FIELDS
359 and information about the correspondance between token types and fields
360 in TYPEINFO. POS is used for error messages. */
363 note_yacc_type (o
, fields
, typeinfo
, pos
)
372 for (p
= typeinfo
; p
; p
= p
->next
)
379 if (p
->type
== (type_p
) 1)
384 for (pp
= typeinfo
; pp
; pp
= pp
->next
)
385 if (pp
->type
!= (type_p
) 1
386 && strcmp (pp
->opt
->info
, p
->opt
->info
) == 0)
395 for (m
= fields
; m
; m
= m
->next
)
396 if (strcmp (m
->name
, p
->name
) == 0)
400 error_at_line (&p
->line
,
401 "couldn't match fieldname `%s'", p
->name
);
412 || p
->type
== (type_p
) 1)
418 new_structure ("yy_union", 1, pos
, typeinfo
, o
);
419 do_typedef ("YYSTYPE", find_structure ("yy_union", 1), pos
);
422 static void process_gc_options
PARAMS ((options_p
, enum gc_used_enum
, int *));
423 static void set_gc_used_type
PARAMS ((type_p
, enum gc_used_enum
));
424 static void set_gc_used
PARAMS ((pair_p
));
426 /* Handle OPT for set_gc_used_type. */
429 process_gc_options (opt
, level
, maybe_undef
)
431 enum gc_used_enum level
;
435 for (o
= opt
; o
; o
= o
->next
)
436 if (strcmp (o
->name
, "ptr_alias") == 0 && level
== GC_POINTED_TO
)
437 set_gc_used_type ((type_p
) o
->info
, GC_POINTED_TO
);
438 else if (strcmp (o
->name
, "maybe_undef") == 0)
442 /* Set the gc_used field of T to LEVEL, and handle the types it references. */
445 set_gc_used_type (t
, level
)
447 enum gc_used_enum level
;
449 if (t
->gc_used
>= level
)
462 process_gc_options (t
->u
.s
.opt
, level
, &dummy
);
464 for (f
= t
->u
.s
.fields
; f
; f
= f
->next
)
467 process_gc_options (t
->u
.s
.opt
, level
, &maybe_undef
);
469 if (maybe_undef
&& f
->type
->kind
== TYPE_POINTER
)
470 set_gc_used_type (f
->type
->u
.p
, GC_MAYBE_POINTED_TO
);
472 set_gc_used_type (f
->type
, GC_USED
);
478 set_gc_used_type (t
->u
.p
, GC_POINTED_TO
);
482 set_gc_used_type (t
->u
.a
.p
, GC_USED
);
485 case TYPE_LANG_STRUCT
:
486 for (t
= t
->u
.s
.lang_struct
; t
; t
= t
->next
)
487 set_gc_used_type (t
, level
);
490 case TYPE_PARAM_STRUCT
:
491 set_gc_used_type (t
->u
.param_struct
.param
, GC_POINTED_TO
);
492 set_gc_used_type (t
->u
.param_struct
.stru
, GC_USED
);
500 /* Set the gc_used fileds of all the types pointed to by VARIABLES. */
503 set_gc_used (variables
)
507 for (p
= variables
; p
; p
= p
->next
)
508 set_gc_used_type (p
->type
, GC_USED
);
511 /* File mapping routines. For each input file, there is one output .c file
512 (but some output files have many input files), and there is one .h file
513 for the whole build. */
515 /* The list of output files. */
516 static outf_p output_files
;
518 /* The output header file that is included into pretty much every
522 /* Number of files specified in gtfiles. */
523 #define NUM_GT_FILES (ARRAY_SIZE (all_files) - 1)
525 /* Number of files in the language files array. */
526 #define NUM_LANG_FILES (ARRAY_SIZE (lang_files) - 1)
528 /* Length of srcdir name. */
529 static int srcdir_len
= 0;
531 #define NUM_BASE_FILES (ARRAY_SIZE (lang_dir_names) - 1)
532 outf_p base_files
[NUM_BASE_FILES
];
534 static outf_p create_file
PARAMS ((const char *, const char *));
535 static const char * get_file_basename
PARAMS ((const char *));
537 /* Create and return an outf_p for a new file for NAME, to be called
541 create_file (name
, oname
)
545 static const char *const hdr
[] = {
546 " Copyright (C) 2002 Free Software Foundation, Inc.\n",
548 "This file is part of GCC.\n",
550 "GCC is free software; you can redistribute it and/or modify it under\n",
551 "the terms of the GNU General Public License as published by the Free\n",
552 "Software Foundation; either version 2, or (at your option) any later\n",
555 "GCC is distributed in the hope that it will be useful, but WITHOUT ANY\n",
556 "WARRANTY; without even the implied warranty of MERCHANTABILITY or\n",
557 "FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n",
558 "for more details.\n",
560 "You should have received a copy of the GNU General Public License\n",
561 "along with GCC; see the file COPYING. If not, write to the Free\n",
562 "Software Foundation, 59 Temple Place - Suite 330, Boston, MA\n",
563 "02111-1307, USA. */\n",
565 "/* This file is machine generated. Do not edit. */\n"
570 f
= xcalloc (sizeof (*f
), 1);
571 f
->next
= output_files
;
575 oprintf (f
, "/* Type information for %s.\n", name
);
576 for (i
= 0; i
< ARRAY_SIZE (hdr
); i
++)
577 oprintf (f
, "%s", hdr
[i
]);
581 /* Print, like fprintf, to O. */
583 oprintf
VPARAMS ((outf_p o
, const char *format
, ...))
588 VA_OPEN (ap
, format
);
589 VA_FIXEDARG (ap
, outf_p
, o
);
590 VA_FIXEDARG (ap
, const char *, format
);
591 slength
= xvasprintf (&s
, format
, ap
);
593 if (o
->bufused
+ slength
> o
->buflength
)
595 size_t new_len
= o
->buflength
;
600 } while (o
->bufused
+ slength
>= new_len
);
601 o
->buf
= xrealloc (o
->buf
, new_len
);
602 o
->buflength
= new_len
;
604 memcpy (o
->buf
+ o
->bufused
, s
, slength
);
605 o
->bufused
+= slength
;
610 /* Open the global header file and the language-specific header files. */
612 static void open_base_files
PARAMS((void));
619 header_file
= create_file ("GCC", "gtype-desc.h");
621 for (i
= 0; i
< NUM_BASE_FILES
; i
++)
622 base_files
[i
] = create_file (lang_dir_names
[i
],
623 xasprintf ("gtype-%s.h", lang_dir_names
[i
]));
625 /* gtype-desc.c is a little special, so we create it here. */
627 /* The order of files here matters very much. */
628 static const char *const ifiles
[] = {
629 "config.h", "system.h", "varray.h", "hashtab.h",
630 "bitmap.h", "tree.h", "rtl.h", "function.h", "insn-config.h",
631 "expr.h", "hard-reg-set.h", "basic-block.h", "cselib.h",
632 "insn-addr.h", "ssa.h", "optabs.h", "libfuncs.h",
636 const char *const *ifp
;
639 gtype_desc_c
= create_file ("GCC", "gtype-desc.c");
640 for (ifp
= ifiles
; *ifp
; ifp
++)
641 oprintf (gtype_desc_c
, "#include \"%s\"\n", *ifp
);
645 /* Determine the pathname to F relative to $(srcdir). */
648 get_file_basename (f
)
652 const char *basename
;
655 basename
= strrchr (f
, '/');
663 for (i
= 1; i
< NUM_BASE_FILES
; i
++)
669 s1
= basename
- strlen (lang_dir_names
[i
]) - 1;
670 s2
= lang_dir_names
[i
];
673 if (l1
>= l2
&& !memcmp (s1
, s2
, l2
))
676 if ((basename
- f
- 1) != srcdir_len
)
677 abort (); /* Match is wrong - should be preceded by $srcdir. */
685 /* Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff
686 INPUT_FILE is used by <lang>.
688 This function should be written to assume that a file _is_ used
689 if the situation is unclear. If it wrongly assumes a file _is_ used,
690 a linker error will result. If it wrongly assumes a file _is not_ used,
691 some GC roots may be missed, which is a much harder-to-debug problem. */
694 get_base_file_bitmap (input_file
)
695 const char *input_file
;
697 const char *basename
= get_file_basename (input_file
);
698 const char *slashpos
= strchr (basename
, '/');
706 for (i
= 1; i
< NUM_BASE_FILES
; i
++)
707 if ((size_t)(slashpos
- basename
) == strlen (lang_dir_names
[i
])
708 && memcmp (basename
, lang_dir_names
[i
], strlen (lang_dir_names
[i
])) == 0)
710 /* It's in a language directory, set that language. */
715 abort (); /* Should have found the language. */
718 /* If it's in any config-lang.in, then set for the languages
723 for (j
= 0; j
< NUM_LANG_FILES
; j
++)
725 if (!strcmp(input_file
, lang_files
[j
]))
727 for (k
= 0; k
< NUM_BASE_FILES
; k
++)
729 if (!strcmp(lang_dir_names
[k
], langs_for_lang_files
[j
]))
735 /* Otherwise, set all languages. */
737 bitmap
= (1 << NUM_BASE_FILES
) - 1;
742 /* An output file, suitable for definitions, that can see declarations
743 made in INPUT_FILE and is linked into every language that uses
747 get_output_file_with_visibility (input_file
)
748 const char *input_file
;
752 const char *basename
;
753 const char *for_name
;
754 const char *output_name
;
756 /* This can happen when we need a file with visibility on a
757 structure that we've never seen. We have to just hope that it's
759 if (input_file
== NULL
)
760 input_file
= "system.h";
762 /* Determine the output file name. */
763 basename
= get_file_basename (input_file
);
765 len
= strlen (basename
);
766 if ((len
> 2 && memcmp (basename
+len
-2, ".c", 2) == 0)
767 || (len
> 2 && memcmp (basename
+len
-2, ".y", 2) == 0)
768 || (len
> 3 && memcmp (basename
+len
-3, ".in", 3) == 0))
772 output_name
= s
= xasprintf ("gt-%s", basename
);
773 for (; *s
!= '.'; s
++)
774 if (! ISALNUM (*s
) && *s
!= '-')
776 memcpy (s
, ".h", sizeof (".h"));
779 else if (strcmp (basename
, "c-common.h") == 0)
780 output_name
= "gt-c-common.h", for_name
= "c-common.c";
781 else if (strcmp (basename
, "c-tree.h") == 0)
782 output_name
= "gt-c-decl.h", for_name
= "c-decl.c";
787 for (i
= 0; i
< NUM_BASE_FILES
; i
++)
788 if (memcmp (basename
, lang_dir_names
[i
], strlen (lang_dir_names
[i
])) == 0
789 && basename
[strlen(lang_dir_names
[i
])] == '/')
790 return base_files
[i
];
792 output_name
= "gtype-desc.c";
796 /* Look through to see if we've ever seen this output filename before. */
797 for (r
= output_files
; r
; r
= r
->next
)
798 if (strcmp (r
->name
, output_name
) == 0)
801 /* If not, create it. */
802 r
= create_file (for_name
, output_name
);
807 /* The name of an output file, suitable for definitions, that can see
808 declarations made in INPUT_FILE and is linked into every language
809 that uses INPUT_FILE. */
812 get_output_file_name (input_file
)
813 const char *input_file
;
815 return get_output_file_with_visibility (input_file
)->name
;
818 /* Copy the output to its final destination,
819 but don't unnecessarily change modification times. */
821 static void close_output_files
PARAMS ((void));
824 close_output_files ()
828 for (of
= output_files
; of
; of
= of
->next
)
832 newfile
= fopen (of
->name
, "r");
833 if (newfile
!= NULL
)
838 for (i
= 0; i
< of
->bufused
; i
++)
841 ch
= fgetc (newfile
);
842 if (ch
== EOF
|| ch
!= (unsigned char) of
->buf
[i
])
845 no_write_p
= i
== of
->bufused
&& fgetc (newfile
) == EOF
;
852 newfile
= fopen (of
->name
, "w");
855 perror ("opening output file");
858 if (fwrite (of
->buf
, 1, of
->bufused
, newfile
) != of
->bufused
)
860 perror ("writing output file");
863 if (fclose (newfile
) != 0)
865 perror ("closing output file");
878 static void output_escaped_param
PARAMS ((outf_p
, const char *, const char *,
879 const char *, const char *,
881 static void write_gc_structure_fields
882 PARAMS ((outf_p
, type_p
, const char *, const char *, options_p
,
883 int, struct fileloc
*, lang_bitmap
, type_p
));
884 static void write_gc_marker_routine_for_structure
PARAMS ((type_p
, type_p
));
885 static void write_gc_types
PARAMS ((type_p structures
, type_p param_structs
));
886 static void put_mangled_filename
PARAMS ((outf_p
, const char *));
887 static void finish_root_table
PARAMS ((struct flist
*flp
, const char *pfx
,
888 const char *tname
, const char *lastname
,
890 static void write_gc_root
PARAMS ((outf_p
, pair_p
, type_p
, const char *, int,
891 struct fileloc
*, const char *));
892 static void write_gc_roots
PARAMS ((pair_p
));
894 static int gc_counter
;
896 /* Print PARAM to OF processing escapes. VAL references the current object,
897 PREV_VAL the object containing the current object, ONAME is the name
898 of the option and LINE is used to print error messages. */
901 output_escaped_param (of
, param
, val
, prev_val
, oname
, line
)
905 const char *prev_val
;
907 struct fileloc
*line
;
911 for (p
= param
; *p
; p
++)
913 oprintf (of
, "%c", *p
);
914 else if (*++p
== 'h')
915 oprintf (of
, "(%s)", val
);
917 oprintf (of
, "(*x)");
919 oprintf (of
, "(%s)", prev_val
);
921 error_at_line (line
, "`%s' option contains bad escape %c%c",
925 /* Write out code to OF which marks the fields of S. VAL references
926 the current object, PREV_VAL the object containing the current
927 object, OPTS is a list of options to apply, INDENT is the current
928 indentation level, LINE is used to print error messages, BITMAP
929 indicates which languages to print the structure for, and PARAM is
930 the current parameter (from an enclosing param_is option). */
933 write_gc_structure_fields (of
, s
, val
, prev_val
, opts
, indent
, line
, bitmap
,
938 const char *prev_val
;
941 struct fileloc
*line
;
948 if (! s
->u
.s
.line
.file
)
949 error_at_line (line
, "incomplete structure `%s'", s
->u
.s
.tag
);
950 else if ((s
->u
.s
.bitmap
& bitmap
) != bitmap
)
952 error_at_line (line
, "structure defined for mismatching languages");
953 error_at_line (&s
->u
.s
.line
, "one structure defined here");
956 if (s
->kind
== TYPE_UNION
)
958 const char *tagexpr
= NULL
;
961 tagcounter
= ++gc_counter
;
962 for (oo
= opts
; oo
; oo
= oo
->next
)
963 if (strcmp (oo
->name
, "desc") == 0)
964 tagexpr
= (const char *)oo
->info
;
968 error_at_line (line
, "missing `desc' option");
971 oprintf (of
, "%*s{\n", indent
, "");
973 oprintf (of
, "%*sunsigned int tag%d = (", indent
, "", tagcounter
);
974 output_escaped_param (of
, tagexpr
, val
, prev_val
, "desc", line
);
975 oprintf (of
, ");\n");
978 for (f
= s
->u
.s
.fields
; f
; f
= f
->next
)
980 const char *tagid
= NULL
;
981 const char *length
= NULL
;
982 const char *special
= NULL
;
985 int maybe_undef_p
= 0;
990 if (t
->kind
== TYPE_SCALAR
991 || (t
->kind
== TYPE_ARRAY
992 && t
->u
.a
.p
->kind
== TYPE_SCALAR
))
995 for (oo
= f
->opt
; oo
; oo
= oo
->next
)
996 if (strcmp (oo
->name
, "length") == 0)
997 length
= (const char *)oo
->info
;
998 else if (strcmp (oo
->name
, "maybe_undef") == 0)
1000 else if (strcmp (oo
->name
, "tag") == 0)
1001 tagid
= (const char *)oo
->info
;
1002 else if (strcmp (oo
->name
, "special") == 0)
1003 special
= (const char *)oo
->info
;
1004 else if (strcmp (oo
->name
, "skip") == 0)
1006 else if (strcmp (oo
->name
, "always") == 0)
1008 else if (strcmp (oo
->name
, "desc") == 0 && UNION_P (t
))
1010 else if (strcmp (oo
->name
, "descbits") == 0 && UNION_P (t
))
1012 else if (strcmp (oo
->name
, "param_is") == 0)
1014 else if (strcmp (oo
->name
, "use_param") == 0)
1017 error_at_line (&f
->line
, "unknown field option `%s'\n", oo
->name
);
1030 for (t1
= t
; t
->kind
== TYPE_ARRAY
; t
= t
->u
.a
.p
)
1032 for (; t
->kind
== TYPE_POINTER
; t
= t
->u
.p
)
1033 nt
= create_pointer (nt
);
1034 while (arraycount
-- > 0)
1035 nt
= create_array (nt
, t
->u
.a
.len
);
1038 else if (s
->kind
== TYPE_UNION
&& ! always_p
&& tagid
)
1041 error_at_line (&f
->line
, "no parameter defined");
1045 && (t
->kind
!= TYPE_POINTER
1046 || t
->u
.p
->kind
!= TYPE_STRUCT
))
1047 error_at_line (&f
->line
,
1048 "field `%s' has invalid option `maybe_undef_p'\n",
1050 if (s
->kind
== TYPE_UNION
&& ! always_p
)
1054 error_at_line (&f
->line
, "field `%s' has no tag", f
->name
);
1057 oprintf (of
, "%*sif (tag%d == (%s)) {\n", indent
, "",
1065 /* Do nothing; strings go in the string pool. */
1068 case TYPE_LANG_STRUCT
:
1071 for (ti
= t
->u
.s
.lang_struct
; ti
; ti
= ti
->next
)
1072 if (ti
->u
.s
.bitmap
& bitmap
)
1079 error_at_line (&f
->line
,
1080 "structure not defined for this language");
1084 /* Fall through... */
1090 newval
= xasprintf ("%s.%s", val
, f
->name
);
1091 write_gc_structure_fields (of
, t
, newval
, val
, f
->opt
, indent
,
1092 &f
->line
, bitmap
, param
);
1101 && t
->u
.p
->u
.s
.line
.file
== NULL
)
1102 oprintf (of
, "%*sif (%s.%s) abort();\n", indent
, "",
1104 else if (UNION_OR_STRUCT_P (t
->u
.p
))
1105 oprintf (of
, "%*sgt_ggc_m_%s (%s.%s);\n", indent
, "",
1106 t
->u
.p
->u
.s
.tag
, val
, f
->name
);
1107 else if (t
->u
.p
->kind
== TYPE_PARAM_STRUCT
)
1108 oprintf (of
, "%*sgt_ggc_mm_%d%s_%s (%s.%s);\n", indent
, "",
1109 (int) strlen (t
->u
.p
->u
.param_struct
.param
->u
.s
.tag
),
1110 t
->u
.p
->u
.param_struct
.param
->u
.s
.tag
,
1111 t
->u
.p
->u
.param_struct
.stru
->u
.s
.tag
,
1114 error_at_line (&f
->line
, "field `%s' is pointer to scalar",
1118 else if (t
->u
.p
->kind
== TYPE_SCALAR
1119 || t
->u
.p
->kind
== TYPE_STRING
)
1120 oprintf (of
, "%*sggc_mark (%s.%s);\n", indent
, "",
1124 int loopcounter
= ++gc_counter
;
1126 oprintf (of
, "%*sif (%s.%s != NULL) {\n", indent
, "",
1129 oprintf (of
, "%*ssize_t i%d;\n", indent
, "", loopcounter
);
1130 oprintf (of
, "%*sggc_set_mark (%s.%s);\n", indent
, "",
1132 oprintf (of
, "%*sfor (i%d = 0; i%d < (", indent
, "",
1133 loopcounter
, loopcounter
);
1134 output_escaped_param (of
, length
, val
, prev_val
, "length", line
);
1135 oprintf (of
, "); i%d++) {\n", loopcounter
);
1137 switch (t
->u
.p
->kind
)
1144 newval
= xasprintf ("%s.%s[i%d]", val
, f
->name
,
1146 write_gc_structure_fields (of
, t
->u
.p
, newval
, val
,
1147 f
->opt
, indent
, &f
->line
,
1153 if (UNION_OR_STRUCT_P (t
->u
.p
->u
.p
))
1154 oprintf (of
, "%*sgt_ggc_m_%s (%s.%s[i%d]);\n", indent
, "",
1155 t
->u
.p
->u
.p
->u
.s
.tag
, val
, f
->name
,
1158 error_at_line (&f
->line
,
1159 "field `%s' is array of pointer to scalar",
1163 error_at_line (&f
->line
,
1164 "field `%s' is array of unimplemented type",
1169 oprintf (of
, "%*s}\n", indent
, "");
1171 oprintf (of
, "%*s}\n", indent
, "");
1177 int loopcounter
= ++gc_counter
;
1182 (strcmp (t
->u
.a
.len
, "0") == 0
1183 || strcmp (t
->u
.a
.len
, "1") == 0))
1184 error_at_line (&f
->line
,
1185 "field `%s' is array of size %s",
1186 f
->name
, t
->u
.a
.len
);
1188 /* Arrays of scalars can be ignored. */
1189 for (ta
= t
; ta
->kind
== TYPE_ARRAY
; ta
= ta
->u
.a
.p
)
1191 if (ta
->kind
== TYPE_SCALAR
1192 || ta
->kind
== TYPE_STRING
)
1195 oprintf (of
, "%*s{\n", indent
, "");
1198 if (special
!= NULL
&& strcmp (special
, "tree_exp") == 0)
1200 oprintf (of
, "%*sconst size_t tree_exp_size = (",
1202 output_escaped_param (of
, length
, val
, prev_val
,
1204 oprintf (of
, ");\n");
1206 length
= "first_rtl_op (TREE_CODE ((tree)&%h))";
1209 for (ta
= t
, i
= 0; ta
->kind
== TYPE_ARRAY
; ta
= ta
->u
.a
.p
, i
++)
1211 oprintf (of
, "%*ssize_t i%d_%d;\n",
1212 indent
, "", loopcounter
, i
);
1213 oprintf (of
, "%*sconst size_t ilimit%d_%d = (",
1214 indent
, "", loopcounter
, i
);
1215 if (i
== 0 && length
!= NULL
)
1216 output_escaped_param (of
, length
, val
, prev_val
,
1219 oprintf (of
, "%s", ta
->u
.a
.len
);
1220 oprintf (of
, ");\n");
1223 for (ta
= t
, i
= 0; ta
->kind
== TYPE_ARRAY
; ta
= ta
->u
.a
.p
, i
++)
1226 "%*sfor (i%d_%d = 0; i%d_%d < ilimit%d_%d; i%d_%d++) {\n",
1227 indent
, "", loopcounter
, i
, loopcounter
, i
,
1228 loopcounter
, i
, loopcounter
, i
);
1232 if (ta
->kind
== TYPE_POINTER
1233 && (ta
->u
.p
->kind
== TYPE_STRUCT
1234 || ta
->u
.p
->kind
== TYPE_UNION
))
1236 oprintf (of
, "%*sgt_ggc_m_%s (%s.%s",
1237 indent
, "", ta
->u
.p
->u
.s
.tag
, val
, f
->name
);
1239 ta
->kind
== TYPE_ARRAY
;
1240 ta
= ta
->u
.a
.p
, i
++)
1241 oprintf (of
, "[i%d_%d]", loopcounter
, i
);
1242 oprintf (of
, ");\n");
1244 else if (ta
->kind
== TYPE_STRUCT
|| ta
->kind
== TYPE_UNION
)
1249 len
= strlen (val
) + strlen (f
->name
) + 2;
1250 for (ta
= t
; ta
->kind
== TYPE_ARRAY
; ta
= ta
->u
.a
.p
)
1251 len
+= sizeof ("[i_]") + 2*6;
1253 newval
= xmalloc (len
);
1254 sprintf (newval
, "%s.%s", val
, f
->name
);
1256 ta
->kind
== TYPE_ARRAY
;
1257 ta
= ta
->u
.a
.p
, i
++)
1258 sprintf (newval
+ strlen (newval
), "[i%d_%d]",
1260 write_gc_structure_fields (of
, t
->u
.p
, newval
, val
,
1261 f
->opt
, indent
, &f
->line
, bitmap
,
1265 else if (ta
->kind
== TYPE_POINTER
&& ta
->u
.p
->kind
== TYPE_SCALAR
1266 && use_param_p
&& param
== NULL
)
1267 oprintf (of
, "%*sabort();\n", indent
, "");
1269 error_at_line (&f
->line
,
1270 "field `%s' is array of unimplemented type",
1272 for (ta
= t
, i
= 0; ta
->kind
== TYPE_ARRAY
; ta
= ta
->u
.a
.p
, i
++)
1275 oprintf (of
, "%*s}\n", indent
, "");
1278 if (special
!= NULL
&& strcmp (special
, "tree_exp") == 0)
1281 "%*sfor (; i%d_0 < tree_exp_size; i%d_0++)\n",
1282 indent
, "", loopcounter
, loopcounter
);
1283 oprintf (of
, "%*s gt_ggc_m_rtx_def (%s.%s[i%d_0]);\n",
1284 indent
, "", val
, f
->name
, loopcounter
);
1289 oprintf (of
, "%*s}\n", indent
, "");
1294 error_at_line (&f
->line
,
1295 "field `%s' is unimplemented type",
1300 if (s
->kind
== TYPE_UNION
&& ! always_p
)
1303 oprintf (of
, "%*s}\n", indent
, "");
1306 error_at_line (&f
->line
, "unhandled special `%s'", special
);
1308 if (s
->kind
== TYPE_UNION
)
1311 oprintf (of
, "%*s}\n", indent
, "");
1315 /* Write out a marker routine for S. PARAM is the parameter from an
1316 enclosing PARAM_IS option. */
1319 write_gc_marker_routine_for_structure (s
, param
)
1325 f
= get_output_file_with_visibility (s
->u
.s
.line
.file
);
1327 f
= get_output_file_with_visibility (param
->u
.s
.line
.file
);
1329 oprintf (f
, "%c", '\n');
1330 oprintf (f
, "void\n");
1332 oprintf (f
, "gt_ggc_mx_%s (x_p)\n", s
->u
.s
.tag
);
1334 oprintf (f
, "gt_ggc_mm_%d%s_%s (x_p)\n", (int) strlen (param
->u
.s
.tag
),
1335 param
->u
.s
.tag
, s
->u
.s
.tag
);
1336 oprintf (f
, " void *x_p;\n");
1338 oprintf (f
, " %s %s * const x = (%s %s *)x_p;\n",
1339 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
,
1340 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
1341 oprintf (f
, " if (! ggc_test_and_set_mark (x))\n");
1342 oprintf (f
, " return;\n");
1345 write_gc_structure_fields (f
, s
, "(*x)", "not valid postage",
1346 s
->u
.s
.opt
, 2, &s
->u
.s
.line
, s
->u
.s
.bitmap
,
1352 /* Write out marker routines for STRUCTURES and PARAM_STRUCTS. */
1355 write_gc_types (structures
, param_structs
)
1357 type_p param_structs
;
1361 oprintf (header_file
, "\n/* GC marker procedures. */\n");
1362 for (s
= structures
; s
; s
= s
->next
)
1363 if (s
->gc_used
== GC_POINTED_TO
1364 || s
->gc_used
== GC_MAYBE_POINTED_TO
)
1368 if (s
->gc_used
== GC_MAYBE_POINTED_TO
1369 && s
->u
.s
.line
.file
== NULL
)
1372 oprintf (header_file
,
1373 "#define gt_ggc_m_%s(X) do { \\\n", s
->u
.s
.tag
);
1374 oprintf (header_file
,
1375 " if (X != NULL) gt_ggc_mx_%s (X);\\\n", s
->u
.s
.tag
);
1376 oprintf (header_file
,
1379 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
1380 if (strcmp (opt
->name
, "ptr_alias") == 0)
1382 type_p t
= (type_p
) opt
->info
;
1383 if (t
->kind
== TYPE_STRUCT
1384 || t
->kind
== TYPE_UNION
1385 || t
->kind
== TYPE_LANG_STRUCT
)
1386 oprintf (header_file
,
1387 "#define gt_ggc_mx_%s gt_ggc_mx_%s\n",
1388 s
->u
.s
.tag
, t
->u
.s
.tag
);
1390 error_at_line (&s
->u
.s
.line
,
1391 "structure alias is not a structure");
1397 /* Declare the marker procedure only once. */
1398 oprintf (header_file
,
1399 "extern void gt_ggc_mx_%s PARAMS ((void *));\n",
1402 if (s
->u
.s
.line
.file
== NULL
)
1404 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
1409 if (s
->kind
== TYPE_LANG_STRUCT
)
1412 for (ss
= s
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
1413 write_gc_marker_routine_for_structure (ss
, NULL
);
1416 write_gc_marker_routine_for_structure (s
, NULL
);
1419 for (s
= param_structs
; s
; s
= s
->next
)
1420 if (s
->gc_used
== GC_POINTED_TO
)
1422 type_p param
= s
->u
.param_struct
.param
;
1423 type_p stru
= s
->u
.param_struct
.stru
;
1425 if (param
->kind
!= TYPE_STRUCT
&& param
->kind
!= TYPE_UNION
1426 && param
->kind
!= TYPE_LANG_STRUCT
)
1428 error_at_line (&s
->u
.param_struct
.line
,
1429 "unsupported parameter type");
1433 /* Declare the marker procedure. */
1434 oprintf (header_file
,
1435 "extern void gt_ggc_mm_%d%s_%s PARAMS ((void *));\n",
1436 (int) strlen (param
->u
.s
.tag
), param
->u
.s
.tag
,
1439 if (stru
->u
.s
.line
.file
== NULL
)
1441 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
1446 if (stru
->kind
== TYPE_LANG_STRUCT
)
1449 for (ss
= stru
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
1450 write_gc_marker_routine_for_structure (ss
, param
);
1453 write_gc_marker_routine_for_structure (stru
, param
);
1457 /* Mangle FN and print it to F. */
1460 put_mangled_filename (f
, fn
)
1464 const char *name
= get_output_file_name (fn
);
1465 for (; *name
!= 0; name
++)
1466 if (ISALNUM (*name
))
1467 oprintf (f
, "%c", *name
);
1469 oprintf (f
, "%c", '_');
1472 /* Finish off the currently-created root tables in FLP. PFX, TNAME,
1473 LASTNAME, and NAME are all strings to insert in various places in
1474 the resulting code. */
1477 finish_root_table (flp
, pfx
, lastname
, tname
, name
)
1481 const char *lastname
;
1485 unsigned started_bitmap
= 0;
1487 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
1488 if (fli2
->started_p
)
1490 oprintf (fli2
->f
, " %s\n", lastname
);
1491 oprintf (fli2
->f
, "};\n\n");
1494 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
1495 if (fli2
->started_p
)
1497 lang_bitmap bitmap
= get_base_file_bitmap (fli2
->name
);
1500 for (fnum
= 0; bitmap
!= 0; fnum
++, bitmap
>>= 1)
1503 oprintf (base_files
[fnum
],
1504 "extern const struct %s gt_ggc_%s_",
1506 put_mangled_filename (base_files
[fnum
], fli2
->name
);
1507 oprintf (base_files
[fnum
], "[];\n");
1511 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
1512 if (fli2
->started_p
)
1514 lang_bitmap bitmap
= get_base_file_bitmap (fli2
->name
);
1517 fli2
->started_p
= 0;
1519 for (fnum
= 0; bitmap
!= 0; fnum
++, bitmap
>>= 1)
1522 if (! (started_bitmap
& (1 << fnum
)))
1524 oprintf (base_files
[fnum
],
1525 "const struct %s * const %s[] = {\n",
1527 started_bitmap
|= 1 << fnum
;
1529 oprintf (base_files
[fnum
], " gt_ggc_%s_", pfx
);
1530 put_mangled_filename (base_files
[fnum
], fli2
->name
);
1531 oprintf (base_files
[fnum
], ",\n");
1539 for (bitmap
= started_bitmap
, fnum
= 0; bitmap
!= 0; fnum
++, bitmap
>>= 1)
1542 oprintf (base_files
[fnum
], " NULL\n");
1543 oprintf (base_files
[fnum
], "};\n\n");
1548 /* Write out to F the table entry and any marker routines needed to
1549 mark NAME as TYPE. The original variable is V, at LINE.
1550 HAS_LENGTH is nonzero iff V was a variable-length array. IF_MARKED
1551 is nonzero iff we are building the root table for hash table caches. */
1554 write_gc_root (f
, v
, type
, name
, has_length
, line
, if_marked
)
1560 struct fileloc
*line
;
1561 const char *if_marked
;
1568 for (fld
= type
->u
.s
.fields
; fld
; fld
= fld
->next
)
1571 const char *desc
= NULL
;
1574 for (o
= fld
->opt
; o
; o
= o
->next
)
1575 if (strcmp (o
->name
, "skip") == 0)
1577 else if (strcmp (o
->name
, "desc") == 0)
1578 desc
= (const char *)o
->info
;
1580 error_at_line (line
,
1581 "field `%s' of global `%s' has unknown option `%s'",
1582 fld
->name
, name
, o
->name
);
1586 else if (desc
&& fld
->type
->kind
== TYPE_UNION
)
1588 pair_p validf
= NULL
;
1591 for (ufld
= fld
->type
->u
.s
.fields
; ufld
; ufld
= ufld
->next
)
1593 const char *tag
= NULL
;
1596 for (oo
= ufld
->opt
; oo
; oo
= oo
->next
)
1597 if (strcmp (oo
->name
, "tag") == 0)
1598 tag
= (const char *)oo
->info
;
1599 if (tag
== NULL
|| strcmp (tag
, desc
) != 0)
1602 error_at_line (line
,
1603 "both `%s.%s.%s' and `%s.%s.%s' have tag `%s'",
1604 name
, fld
->name
, validf
->name
,
1605 name
, fld
->name
, ufld
->name
,
1612 newname
= xasprintf ("%s.%s.%s",
1613 name
, fld
->name
, validf
->name
);
1614 write_gc_root (f
, v
, validf
->type
, newname
, 0, line
,
1620 error_at_line (line
,
1621 "global `%s.%s' has `desc' option but is not union",
1626 newname
= xasprintf ("%s.%s", name
, fld
->name
);
1627 write_gc_root (f
, v
, fld
->type
, newname
, 0, line
, if_marked
);
1637 newname
= xasprintf ("%s[0]", name
);
1638 write_gc_root (f
, v
, type
->u
.a
.p
, newname
, has_length
, line
, if_marked
);
1647 oprintf (f
, " {\n");
1648 oprintf (f
, " &%s,\n", name
);
1651 for (ap
= v
->type
; ap
->kind
== TYPE_ARRAY
; ap
= ap
->u
.a
.p
)
1653 oprintf (f
, " * (%s)", ap
->u
.a
.len
);
1654 else if (ap
== v
->type
)
1655 oprintf (f
, " * ARRAY_SIZE (%s)", v
->name
);
1657 oprintf (f
, " sizeof (%s", v
->name
);
1658 for (ap
= v
->type
; ap
->kind
== TYPE_ARRAY
; ap
= ap
->u
.a
.p
)
1660 oprintf (f
, "),\n");
1664 if (! has_length
&& UNION_OR_STRUCT_P (tp
))
1666 oprintf (f
, " >_ggc_mx_%s\n", tp
->u
.s
.tag
);
1668 else if (! has_length
&& tp
->kind
== TYPE_PARAM_STRUCT
)
1670 oprintf (f
, " >_ggc_mm_%d%s_%s",
1671 (int) strlen (tp
->u
.param_struct
.param
->u
.s
.tag
),
1672 tp
->u
.param_struct
.param
->u
.s
.tag
,
1673 tp
->u
.param_struct
.stru
->u
.s
.tag
);
1676 && (tp
->kind
== TYPE_POINTER
|| UNION_OR_STRUCT_P (tp
)))
1678 oprintf (f
, " >_ggc_ma_%s", name
);
1682 error_at_line (line
,
1683 "global `%s' is pointer to unimplemented type",
1687 oprintf (f
, ",\n &%s", if_marked
);
1688 oprintf (f
, "\n },\n");
1697 error_at_line (line
,
1698 "global `%s' is unimplemented type",
1703 /* Output a table describing the locations and types of VARIABLES. */
1706 write_gc_roots (variables
)
1710 struct flist
*flp
= NULL
;
1712 for (v
= variables
; v
; v
= v
->next
)
1714 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
1716 const char *length
= NULL
;
1717 int deletable_p
= 0;
1720 for (o
= v
->opt
; o
; o
= o
->next
)
1721 if (strcmp (o
->name
, "length") == 0)
1722 length
= (const char *)o
->info
;
1723 else if (strcmp (o
->name
, "deletable") == 0)
1725 else if (strcmp (o
->name
, "param_is") == 0)
1727 else if (strcmp (o
->name
, "if_marked") == 0)
1730 error_at_line (&v
->line
,
1731 "global `%s' has unknown option `%s'",
1734 for (fli
= flp
; fli
; fli
= fli
->next
)
1739 fli
= xmalloc (sizeof (*fli
));
1743 fli
->name
= v
->line
.file
;
1746 oprintf (f
, "\n/* GC roots. */\n\n");
1751 && v
->type
->kind
== TYPE_POINTER
1752 && (v
->type
->u
.p
->kind
== TYPE_POINTER
1753 || v
->type
->u
.p
->kind
== TYPE_STRUCT
))
1755 oprintf (f
, "static void gt_ggc_ma_%s PARAMS ((void *));\n",
1757 oprintf (f
, "static void\ngt_ggc_ma_%s (x_p)\n void *x_p;\n",
1760 oprintf (f
, " size_t i;\n");
1762 if (v
->type
->u
.p
->kind
== TYPE_POINTER
)
1764 type_p s
= v
->type
->u
.p
->u
.p
;
1766 oprintf (f
, " %s %s ** const x = (%s %s **)x_p;\n",
1767 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
,
1768 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
1769 oprintf (f
, " if (ggc_test_and_set_mark (x))\n");
1770 oprintf (f
, " for (i = 0; i < (%s); i++)\n", length
);
1771 if (s
->kind
!= TYPE_STRUCT
&& s
->kind
!= TYPE_UNION
)
1773 error_at_line (&v
->line
,
1774 "global `%s' has unsupported ** type",
1779 oprintf (f
, " gt_ggc_m_%s (x[i]);\n", s
->u
.s
.tag
);
1783 type_p s
= v
->type
->u
.p
;
1785 oprintf (f
, " %s %s * const x = (%s %s *)x_p;\n",
1786 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
,
1787 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
1788 oprintf (f
, " if (ggc_test_and_set_mark (x))\n");
1789 oprintf (f
, " for (i = 0; i < (%s); i++)\n", length
);
1790 oprintf (f
, " {\n");
1791 write_gc_structure_fields (f
, s
, "x[i]", "x[i]",
1792 v
->opt
, 8, &v
->line
, s
->u
.s
.bitmap
,
1794 oprintf (f
, " }\n");
1797 oprintf (f
, "}\n\n");
1801 for (v
= variables
; v
; v
= v
->next
)
1803 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
1809 for (o
= v
->opt
; o
; o
= o
->next
)
1810 if (strcmp (o
->name
, "length") == 0)
1812 else if (strcmp (o
->name
, "deletable") == 0
1813 || strcmp (o
->name
, "if_marked") == 0)
1819 for (fli
= flp
; fli
; fli
= fli
->next
)
1822 if (! fli
->started_p
)
1826 oprintf (f
, "const struct ggc_root_tab gt_ggc_r_");
1827 put_mangled_filename (f
, v
->line
.file
);
1828 oprintf (f
, "[] = {\n");
1831 write_gc_root (f
, v
, v
->type
, v
->name
, length_p
, &v
->line
, NULL
);
1834 finish_root_table (flp
, "r", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
1837 for (v
= variables
; v
; v
= v
->next
)
1839 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
1844 for (o
= v
->opt
; o
; o
= o
->next
)
1845 if (strcmp (o
->name
, "deletable") == 0)
1847 else if (strcmp (o
->name
, "if_marked") == 0)
1853 for (fli
= flp
; fli
; fli
= fli
->next
)
1856 if (! fli
->started_p
)
1860 oprintf (f
, "const struct ggc_root_tab gt_ggc_rd_");
1861 put_mangled_filename (f
, v
->line
.file
);
1862 oprintf (f
, "[] = {\n");
1865 oprintf (f
, " { &%s, 1, sizeof (%s), NULL },\n",
1869 finish_root_table (flp
, "rd", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
1870 "gt_ggc_deletable_rtab");
1872 for (v
= variables
; v
; v
= v
->next
)
1874 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
1876 const char *if_marked
= NULL
;
1880 for (o
= v
->opt
; o
; o
= o
->next
)
1881 if (strcmp (o
->name
, "length") == 0)
1883 else if (strcmp (o
->name
, "if_marked") == 0)
1884 if_marked
= (const char *) o
->info
;
1886 if (if_marked
== NULL
)
1889 if (v
->type
->kind
!= TYPE_POINTER
1890 || v
->type
->u
.p
->kind
!= TYPE_PARAM_STRUCT
1891 || v
->type
->u
.p
->u
.param_struct
.stru
!= find_structure ("htab", 0))
1893 error_at_line (&v
->line
, "if_marked option used but not hash table");
1897 for (fli
= flp
; fli
; fli
= fli
->next
)
1900 if (! fli
->started_p
)
1904 oprintf (f
, "const struct ggc_cache_tab gt_ggc_rc_");
1905 put_mangled_filename (f
, v
->line
.file
);
1906 oprintf (f
, "[] = {\n");
1909 write_gc_root (f
, v
, create_pointer (v
->type
->u
.p
->u
.param_struct
.param
),
1910 v
->name
, length_p
, &v
->line
, if_marked
);
1913 finish_root_table (flp
, "rc", "LAST_GGC_CACHE_TAB", "ggc_cache_tab",
1914 "gt_ggc_cache_rtab");
1918 extern int main
PARAMS ((int argc
, char **argv
));
1921 int argc ATTRIBUTE_UNUSED
;
1922 char **argv ATTRIBUTE_UNUSED
;
1925 static struct fileloc pos
= { __FILE__
, __LINE__
};
1928 srcdir_len
= strlen (srcdir
);
1930 do_typedef ("CUMULATIVE_ARGS",
1931 create_scalar_type ("CUMULATIVE_ARGS",
1932 strlen ("CUMULATIVE_ARGS")),
1934 do_typedef ("REAL_VALUE_TYPE",
1935 create_scalar_type ("REAL_VALUE_TYPE",
1936 strlen ("REAL_VALUE_TYPE")),
1938 do_typedef ("PTR", create_pointer (create_scalar_type ("void",
1942 do_typedef ("HARD_REG_SET", create_array (
1943 create_scalar_type ("unsigned long", strlen ("unsigned long")),
1946 for (i
= 0; i
< NUM_GT_FILES
; i
++)
1949 /* Omit if already seen. */
1950 for (j
= 0; j
< i
; j
++)
1952 if (!strcmp (all_files
[i
], all_files
[j
]))
1959 parse_file (all_files
[i
]);
1965 set_gc_used (variables
);
1968 write_gc_types (structures
, param_structs
);
1969 write_gc_roots (variables
);
1970 close_output_files ();
1972 return (hit_error
!= 0);