1 /* Process source files and output type information.
2 Copyright (C) 2002, 2003 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
23 #include "coretypes.h"
32 /* Nonzero iff an error has occurred. */
33 static int hit_error = 0;
35 static void gen_rtx_next (void);
36 static void write_rtx_next (void);
37 static void open_base_files (void);
38 static void close_output_files (void);
40 /* Report an error at POS, printing MSG. */
43 error_at_line (struct fileloc *pos, const char *msg, ...)
49 fprintf (stderr, "%s:%d: ", pos->file, pos->line);
50 vfprintf (stderr, msg, ap);
57 /* vasprintf, but produces fatal message on out-of-memory. */
59 xvasprintf (char **result, const char *format, va_list args)
61 int ret = vasprintf (result, format, args);
62 if (*result == NULL || ret < 0)
64 fputs ("gengtype: out of memory", stderr);
70 /* Wrapper for xvasprintf. */
72 xasprintf (const char *format, ...)
77 va_start (ap, format);
78 xvasprintf (&result, format, ap);
83 /* The one and only TYPE_STRING. */
85 struct type string_type = {
86 TYPE_STRING, NULL, NULL, GC_USED, {0}
89 /* Lists of various things. */
91 static pair_p typedefs;
92 static type_p structures;
93 static type_p param_structs;
94 static pair_p variables;
96 static void do_scalar_typedef (const char *, struct fileloc *);
97 static type_p find_param_structure
98 (type_p t, type_p param[NUM_PARAM]);
99 static type_p adjust_field_tree_exp (type_p t, options_p opt);
100 static type_p adjust_field_rtx_def (type_p t, options_p opt);
102 /* Define S as a typedef to T at POS. */
105 do_typedef (const char *s, type_p t, struct fileloc *pos)
109 for (p = typedefs; p != NULL; p = p->next)
110 if (strcmp (p->name, s) == 0)
114 error_at_line (pos, "type `%s' previously defined", s);
115 error_at_line (&p->line, "previously defined here");
120 p = xmalloc (sizeof (struct pair));
128 /* Define S as a typename of a scalar. */
131 do_scalar_typedef (const char *s, struct fileloc *pos)
133 do_typedef (s, create_scalar_type (s, strlen (s)), pos);
136 /* Return the type previously defined for S. Use POS to report errors. */
139 resolve_typedef (const char *s, struct fileloc *pos)
142 for (p = typedefs; p != NULL; p = p->next)
143 if (strcmp (p->name, s) == 0)
145 error_at_line (pos, "unidentified type `%s'", s);
146 return create_scalar_type ("char", 4);
149 /* Create a new structure with tag NAME (or a union iff ISUNION is nonzero),
150 at POS with fields FIELDS and options O. */
153 new_structure (const char *name, int isunion, struct fileloc *pos,
154 pair_p fields, options_p o)
158 lang_bitmap bitmap = get_base_file_bitmap (pos->file);
160 for (si = structures; si != NULL; si = si->next)
161 if (strcmp (name, si->u.s.tag) == 0
162 && UNION_P (si) == isunion)
165 if (si->kind == TYPE_LANG_STRUCT)
169 for (si = ls->u.s.lang_struct; si != NULL; si = si->next)
170 if (si->u.s.bitmap == bitmap)
173 else if (si->u.s.line.file != NULL && si->u.s.bitmap != bitmap)
176 si = xcalloc (1, sizeof (struct type));
177 memcpy (si, ls, sizeof (struct type));
178 ls->kind = TYPE_LANG_STRUCT;
179 ls->u.s.lang_struct = si;
180 ls->u.s.fields = NULL;
182 si->pointer_to = NULL;
183 si->u.s.lang_struct = ls;
188 if (ls != NULL && s == NULL)
190 s = xcalloc (1, sizeof (struct type));
191 s->next = ls->u.s.lang_struct;
192 ls->u.s.lang_struct = s;
193 s->u.s.lang_struct = ls;
200 s = xcalloc (1, sizeof (struct type));
201 s->next = structures;
205 if (s->u.s.line.file != NULL
206 || (s->u.s.lang_struct && (s->u.s.lang_struct->u.s.bitmap & bitmap)))
208 error_at_line (pos, "duplicate structure definition");
209 error_at_line (&s->u.s.line, "previous definition here");
212 s->kind = isunion ? TYPE_UNION : TYPE_STRUCT;
215 s->u.s.fields = fields;
217 s->u.s.bitmap = bitmap;
218 if (s->u.s.lang_struct)
219 s->u.s.lang_struct->u.s.bitmap |= bitmap;
222 /* Return the previously-defined structure with tag NAME (or a union
223 iff ISUNION is nonzero), or a new empty structure or union if none
224 was defined previously. */
227 find_structure (const char *name, int isunion)
231 for (s = structures; s != NULL; s = s->next)
232 if (strcmp (name, s->u.s.tag) == 0
233 && UNION_P (s) == isunion)
236 s = xcalloc (1, sizeof (struct type));
237 s->next = structures;
239 s->kind = isunion ? TYPE_UNION : TYPE_STRUCT;
245 /* Return the previously-defined parameterized structure for structure
246 T and parameters PARAM, or a new parameterized empty structure or
247 union if none was defined previously. */
250 find_param_structure (type_p t, type_p param[NUM_PARAM])
254 for (res = param_structs; res; res = res->next)
255 if (res->u.param_struct.stru == t
256 && memcmp (res->u.param_struct.param, param,
257 sizeof (type_p) * NUM_PARAM) == 0)
261 res = xcalloc (1, sizeof (*res));
262 res->kind = TYPE_PARAM_STRUCT;
263 res->next = param_structs;
265 res->u.param_struct.stru = t;
266 memcpy (res->u.param_struct.param, param, sizeof (type_p) * NUM_PARAM);
271 /* Return a scalar type with name NAME. */
274 create_scalar_type (const char *name, size_t name_len)
276 type_p r = xcalloc (1, sizeof (struct type));
277 r->kind = TYPE_SCALAR;
278 r->u.sc = xmemdup (name, name_len, name_len + 1);
282 /* Return a pointer to T. */
285 create_pointer (type_p t)
289 type_p r = xcalloc (1, sizeof (struct type));
290 r->kind = TYPE_POINTER;
294 return t->pointer_to;
297 /* Return an array of length LEN. */
300 create_array (type_p t, const char *len)
304 v = xcalloc (1, sizeof (*v));
305 v->kind = TYPE_ARRAY;
311 /* Add a variable named S of type T with options O defined at POS,
315 note_variable (const char *s, type_p t, options_p o, struct fileloc *pos)
318 n = xmalloc (sizeof (*n));
327 /* We really don't care how long a CONST_DOUBLE is. */
328 #define CONST_DOUBLE_FORMAT "ww"
329 const char * const rtx_format[NUM_RTX_CODE] = {
330 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT ,
335 static int rtx_next_new[NUM_RTX_CODE];
337 /* Generate the contents of the rtx_next array. This really doesn't belong
338 in gengtype at all, but it's needed for adjust_field_rtx_def. */
344 for (i = 0; i < NUM_RTX_CODE; i++)
348 rtx_next_new[i] = -1;
349 if (strncmp (rtx_format[i], "iuu", 3) == 0)
351 else if (i == COND_EXEC || i == SET || i == EXPR_LIST || i == INSN_LIST)
354 for (k = strlen (rtx_format[i]) - 1; k >= 0; k--)
355 if (rtx_format[i][k] == 'e' || rtx_format[i][k] == 'u')
360 /* Write out the contents of the rtx_next array. */
362 write_rtx_next (void)
364 outf_p f = get_output_file_with_visibility (NULL);
367 oprintf (f, "\n/* Used to implement the RTX_NEXT macro. */\n");
368 oprintf (f, "const unsigned char rtx_next[NUM_RTX_CODE] = {\n");
369 for (i = 0; i < NUM_RTX_CODE; i++)
370 if (rtx_next_new[i] == -1)
371 oprintf (f, " 0,\n");
374 " offsetof (struct rtx_def, fld) + %d * sizeof (rtunion),\n",
379 /* Handle `special("rtx_def")'. This is a special case for field
380 `fld' of struct rtx_def, which is an array of unions whose values
381 are based in a complex way on the type of RTL. */
384 adjust_field_rtx_def (type_p t, options_p opt ATTRIBUTE_UNUSED)
389 type_p rtx_tp, rtvec_tp, tree_tp, mem_attrs_tp, note_union_tp, scalar_tp;
390 type_p bitmap_tp, basic_block_tp, reg_attrs_tp;
392 static const char * const rtx_name[NUM_RTX_CODE] = {
393 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME ,
398 if (t->kind != TYPE_ARRAY)
400 error_at_line (&lexer_line,
401 "special `rtx_def' must be applied to an array");
405 nodot = xmalloc (sizeof (*nodot));
410 rtx_tp = create_pointer (find_structure ("rtx_def", 0));
411 rtvec_tp = create_pointer (find_structure ("rtvec_def", 0));
412 tree_tp = create_pointer (find_structure ("tree_node", 1));
413 mem_attrs_tp = create_pointer (find_structure ("mem_attrs", 0));
414 reg_attrs_tp = create_pointer (find_structure ("reg_attrs", 0));
415 bitmap_tp = create_pointer (find_structure ("bitmap_element_def", 0));
416 basic_block_tp = create_pointer (find_structure ("basic_block_def", 0));
417 scalar_tp = create_scalar_type ("rtunion scalar", 14);
420 pair_p note_flds = NULL;
423 for (c = NOTE_INSN_BIAS; c <= NOTE_INSN_MAX; c++)
425 pair_p old_note_flds = note_flds;
427 note_flds = xmalloc (sizeof (*note_flds));
428 note_flds->line.file = __FILE__;
429 note_flds->line.line = __LINE__;
430 note_flds->opt = xmalloc (sizeof (*note_flds->opt));
431 note_flds->opt->next = nodot;
432 note_flds->opt->name = "tag";
433 note_flds->opt->info = xasprintf ("%d", c);
434 note_flds->next = old_note_flds;
438 /* NOTE_INSN_MAX is used as the default field for line
441 note_flds->opt->name = "default";
442 note_flds->name = "rtstr";
443 note_flds->type = &string_type;
446 case NOTE_INSN_BLOCK_BEG:
447 case NOTE_INSN_BLOCK_END:
448 note_flds->name = "rttree";
449 note_flds->type = tree_tp;
452 case NOTE_INSN_EXPECTED_VALUE:
453 note_flds->name = "rtx";
454 note_flds->type = rtx_tp;
458 note_flds->name = "rtint";
459 note_flds->type = scalar_tp;
463 new_structure ("rtx_def_note_subunion", 1, &lexer_line, note_flds, NULL);
466 note_union_tp = find_structure ("rtx_def_note_subunion", 1);
468 for (i = 0; i < NUM_RTX_CODE; i++)
470 pair_p old_flds = flds;
471 pair_p subfields = NULL;
472 size_t aindex, nmindex;
476 for (aindex = 0; aindex < strlen (rtx_format[i]); aindex++)
478 pair_p old_subf = subfields;
482 switch (rtx_format[i][aindex])
493 if (i == MEM && aindex == 1)
494 t = mem_attrs_tp, subname = "rtmem";
495 else if (i == JUMP_INSN && aindex == 9)
496 t = rtx_tp, subname = "rtx";
497 else if (i == CODE_LABEL && aindex == 4)
498 t = scalar_tp, subname = "rtint";
499 else if (i == CODE_LABEL && aindex == 5)
500 t = rtx_tp, subname = "rtx";
501 else if (i == LABEL_REF
502 && (aindex == 1 || aindex == 2))
503 t = rtx_tp, subname = "rtx";
504 else if (i == NOTE && aindex == 4)
505 t = note_union_tp, subname = "";
506 else if (i == NOTE && aindex >= 7)
507 t = scalar_tp, subname = "rtint";
508 else if (i == ADDR_DIFF_VEC && aindex == 4)
509 t = scalar_tp, subname = "rtint";
510 else if (i == VALUE && aindex == 0)
511 t = scalar_tp, subname = "rtint";
512 else if (i == REG && aindex == 1)
513 t = scalar_tp, subname = "rtint";
514 else if (i == REG && aindex == 2)
515 t = reg_attrs_tp, subname = "rtreg";
516 else if (i == SCRATCH && aindex == 0)
517 t = scalar_tp, subname = "rtint";
518 else if (i == SYMBOL_REF && aindex == 1)
519 t = scalar_tp, subname = "rtint";
520 else if (i == SYMBOL_REF && aindex == 2)
521 t = tree_tp, subname = "rttree";
522 else if (i == BARRIER && aindex >= 3)
523 t = scalar_tp, subname = "rtint";
526 error_at_line (&lexer_line,
527 "rtx type `%s' has `0' in position %lu, can't handle",
528 rtx_name[i], (unsigned long) aindex);
569 error_at_line (&lexer_line,
570 "rtx type `%s' has `%c' in position %lu, can't handle",
571 rtx_name[i], rtx_format[i][aindex],
572 (unsigned long)aindex);
578 subfields = xmalloc (sizeof (*subfields));
579 subfields->next = old_subf;
581 subfields->name = xasprintf ("[%lu].%s", (unsigned long)aindex,
583 subfields->line.file = __FILE__;
584 subfields->line.line = __LINE__;
585 if (t == note_union_tp)
587 subfields->opt = xmalloc (sizeof (*subfields->opt));
588 subfields->opt->next = nodot;
589 subfields->opt->name = "desc";
590 subfields->opt->info = "NOTE_LINE_NUMBER (&%0)";
592 else if (t == basic_block_tp)
594 /* We don't presently GC basic block structures... */
595 subfields->opt = xmalloc (sizeof (*subfields->opt));
596 subfields->opt->next = nodot;
597 subfields->opt->name = "skip";
598 subfields->opt->info = NULL;
601 subfields->opt = nodot;
604 flds = xmalloc (sizeof (*flds));
605 flds->next = old_flds;
607 sname = xasprintf ("rtx_def_%s", rtx_name[i]);
608 new_structure (sname, 0, &lexer_line, subfields, NULL);
609 flds->type = find_structure (sname, 0);
610 flds->line.file = __FILE__;
611 flds->line.line = __LINE__;
612 flds->opt = xmalloc (sizeof (*flds->opt));
613 flds->opt->next = nodot;
614 flds->opt->name = "tag";
615 ftag = xstrdup (rtx_name[i]);
616 for (nmindex = 0; nmindex < strlen (ftag); nmindex++)
617 ftag[nmindex] = TOUPPER (ftag[nmindex]);
618 flds->opt->info = ftag;
621 new_structure ("rtx_def_subunion", 1, &lexer_line, flds, nodot);
622 return find_structure ("rtx_def_subunion", 1);
625 /* Handle `special("tree_exp")'. This is a special case for
626 field `operands' of struct tree_exp, which although it claims to contain
627 pointers to trees, actually sometimes contains pointers to RTL too.
628 Passed T, the old type of the field, and OPT its options. Returns
629 a new type for the field. */
632 adjust_field_tree_exp (type_p t, options_p opt ATTRIBUTE_UNUSED)
637 static const struct {
642 { "SAVE_EXPR", 2, 1 },
643 { "GOTO_SUBROUTINE_EXPR", 0, 2 },
644 { "RTL_EXPR", 0, 2 },
645 { "WITH_CLEANUP_EXPR", 2, 1 },
646 { "METHOD_CALL_EXPR", 3, 1 }
649 if (t->kind != TYPE_ARRAY)
651 error_at_line (&lexer_line,
652 "special `tree_exp' must be applied to an array");
656 nodot = xmalloc (sizeof (*nodot));
661 flds = xmalloc (sizeof (*flds));
665 flds->line.file = __FILE__;
666 flds->line.line = __LINE__;
667 flds->opt = xmalloc (sizeof (*flds->opt));
668 flds->opt->next = nodot;
669 flds->opt->name = "length";
670 flds->opt->info = "TREE_CODE_LENGTH (TREE_CODE ((tree) &%0))";
672 options_p oldopt = flds->opt;
673 flds->opt = xmalloc (sizeof (*flds->opt));
674 flds->opt->next = oldopt;
675 flds->opt->name = "default";
676 flds->opt->info = "";
679 for (i = 0; i < ARRAY_SIZE (data); i++)
681 pair_p old_flds = flds;
682 pair_p subfields = NULL;
687 r_index < data[i].first_rtl + data[i].num_rtl;
690 pair_p old_subf = subfields;
691 subfields = xmalloc (sizeof (*subfields));
692 subfields->next = old_subf;
693 subfields->name = xasprintf ("[%d]", r_index);
694 if (r_index < data[i].first_rtl)
695 subfields->type = t->u.a.p;
697 subfields->type = create_pointer (find_structure ("rtx_def", 0));
698 subfields->line.file = __FILE__;
699 subfields->line.line = __LINE__;
700 subfields->opt = nodot;
703 flds = xmalloc (sizeof (*flds));
704 flds->next = old_flds;
706 sname = xasprintf ("tree_exp_%s", data[i].name);
707 new_structure (sname, 0, &lexer_line, subfields, NULL);
708 flds->type = find_structure (sname, 0);
709 flds->line.file = __FILE__;
710 flds->line.line = __LINE__;
711 flds->opt = xmalloc (sizeof (*flds->opt));
712 flds->opt->next = nodot;
713 flds->opt->name = "tag";
714 flds->opt->info = data[i].name;
717 new_structure ("tree_exp_subunion", 1, &lexer_line, flds, nodot);
718 return find_structure ("tree_exp_subunion", 1);
721 /* Perform any special processing on a type T, about to become the type
722 of a field. Return the appropriate type for the field.
724 - Converts pointer-to-char, with no length parameter, to TYPE_STRING;
725 - Similarly for arrays of pointer-to-char;
726 - Converts structures for which a parameter is provided to
728 - Handles "special" options.
732 adjust_field_type (type_p t, options_p opt)
735 const int pointer_p = t->kind == TYPE_POINTER;
736 type_p params[NUM_PARAM];
740 for (i = 0; i < NUM_PARAM; i++)
743 for (; opt; opt = opt->next)
744 if (strcmp (opt->name, "length") == 0)
746 else if (strcmp (opt->name, "param_is") == 0
747 || (strncmp (opt->name, "param", 5) == 0
748 && ISDIGIT (opt->name[5])
749 && strcmp (opt->name + 6, "_is") == 0))
751 int num = ISDIGIT (opt->name[5]) ? opt->name[5] - '0' : 0;
753 if (! UNION_OR_STRUCT_P (t)
754 && (t->kind != TYPE_POINTER || ! UNION_OR_STRUCT_P (t->u.p)))
756 error_at_line (&lexer_line,
757 "option `%s' may only be applied to structures or structure pointers",
763 if (params[num] != NULL)
764 error_at_line (&lexer_line, "duplicate `%s' option", opt->name);
765 if (! ISDIGIT (opt->name[5]))
766 params[num] = create_pointer ((type_p) opt->info);
768 params[num] = (type_p) opt->info;
770 else if (strcmp (opt->name, "special") == 0)
772 const char *special_name = (const char *)opt->info;
773 if (strcmp (special_name, "tree_exp") == 0)
774 t = adjust_field_tree_exp (t, opt);
775 else if (strcmp (special_name, "rtx_def") == 0)
776 t = adjust_field_rtx_def (t, opt);
778 error_at_line (&lexer_line, "unknown special `%s'", special_name);
787 realt = find_param_structure (t, params);
788 t = pointer_p ? create_pointer (realt) : realt;
793 && t->u.p->kind == TYPE_SCALAR
794 && (strcmp (t->u.p->u.sc, "char") == 0
795 || strcmp (t->u.p->u.sc, "unsigned char") == 0))
797 if (t->kind == TYPE_ARRAY && t->u.a.p->kind == TYPE_POINTER
798 && t->u.a.p->u.p->kind == TYPE_SCALAR
799 && (strcmp (t->u.a.p->u.p->u.sc, "char") == 0
800 || strcmp (t->u.a.p->u.p->u.sc, "unsigned char") == 0))
801 return create_array (&string_type, t->u.a.len);
806 /* Create a union for YYSTYPE, as yacc would do it, given a fieldlist FIELDS
807 and information about the correspondence between token types and fields
808 in TYPEINFO. POS is used for error messages. */
811 note_yacc_type (options_p o, pair_p fields, pair_p typeinfo,
817 for (p = typeinfo; p; p = p->next)
824 if (p->type == (type_p) 1)
829 for (pp = typeinfo; pp; pp = pp->next)
830 if (pp->type != (type_p) 1
831 && strcmp (pp->opt->info, p->opt->info) == 0)
840 for (m = fields; m; m = m->next)
841 if (strcmp (m->name, p->name) == 0)
845 error_at_line (&p->line,
846 "couldn't match fieldname `%s'", p->name);
857 || p->type == (type_p) 1)
863 new_structure ("yy_union", 1, pos, typeinfo, o);
864 do_typedef ("YYSTYPE", find_structure ("yy_union", 1), pos);
867 static void process_gc_options (options_p, enum gc_used_enum,
868 int *, int *, int *);
869 static void set_gc_used_type (type_p, enum gc_used_enum, type_p *);
870 static void set_gc_used (pair_p);
872 /* Handle OPT for set_gc_used_type. */
875 process_gc_options (options_p opt, enum gc_used_enum level, int *maybe_undef,
876 int *pass_param, int *length)
879 for (o = opt; o; o = o->next)
880 if (strcmp (o->name, "ptr_alias") == 0 && level == GC_POINTED_TO)
881 set_gc_used_type ((type_p) o->info, GC_POINTED_TO, NULL);
882 else if (strcmp (o->name, "maybe_undef") == 0)
884 else if (strcmp (o->name, "use_params") == 0)
886 else if (strcmp (o->name, "length") == 0)
890 /* Set the gc_used field of T to LEVEL, and handle the types it references. */
893 set_gc_used_type (type_p t, enum gc_used_enum level, type_p param[NUM_PARAM])
895 if (t->gc_used >= level)
908 process_gc_options (t->u.s.opt, level, &dummy, &dummy, &dummy);
910 for (f = t->u.s.fields; f; f = f->next)
915 process_gc_options (f->opt, level, &maybe_undef, &pass_param,
918 if (length && f->type->kind == TYPE_POINTER)
919 set_gc_used_type (f->type->u.p, GC_USED, NULL);
920 else if (maybe_undef && f->type->kind == TYPE_POINTER)
921 set_gc_used_type (f->type->u.p, GC_MAYBE_POINTED_TO, NULL);
922 else if (pass_param && f->type->kind == TYPE_POINTER && param)
923 set_gc_used_type (find_param_structure (f->type->u.p, param),
924 GC_POINTED_TO, NULL);
926 set_gc_used_type (f->type, GC_USED, pass_param ? param : NULL);
932 set_gc_used_type (t->u.p, GC_POINTED_TO, NULL);
936 set_gc_used_type (t->u.a.p, GC_USED, param);
939 case TYPE_LANG_STRUCT:
940 for (t = t->u.s.lang_struct; t; t = t->next)
941 set_gc_used_type (t, level, param);
944 case TYPE_PARAM_STRUCT:
947 for (i = 0; i < NUM_PARAM; i++)
948 if (t->u.param_struct.param[i] != 0)
949 set_gc_used_type (t->u.param_struct.param[i], GC_USED, NULL);
951 if (t->u.param_struct.stru->gc_used == GC_POINTED_TO)
952 level = GC_POINTED_TO;
955 t->u.param_struct.stru->gc_used = GC_UNUSED;
956 set_gc_used_type (t->u.param_struct.stru, level,
957 t->u.param_struct.param);
965 /* Set the gc_used fields of all the types pointed to by VARIABLES. */
968 set_gc_used (pair_p variables)
971 for (p = variables; p; p = p->next)
972 set_gc_used_type (p->type, GC_USED, NULL);
975 /* File mapping routines. For each input file, there is one output .c file
976 (but some output files have many input files), and there is one .h file
977 for the whole build. */
979 /* The list of output files. */
980 static outf_p output_files;
982 /* The output header file that is included into pretty much every
986 /* Number of files specified in gtfiles. */
987 #define NUM_GT_FILES (ARRAY_SIZE (all_files) - 1)
989 /* Number of files in the language files array. */
990 #define NUM_LANG_FILES (ARRAY_SIZE (lang_files) - 1)
992 /* Length of srcdir name. */
993 static int srcdir_len = 0;
995 #define NUM_BASE_FILES (ARRAY_SIZE (lang_dir_names) - 1)
996 outf_p base_files[NUM_BASE_FILES];
998 static outf_p create_file (const char *, const char *);
999 static const char * get_file_basename (const char *);
1001 /* Create and return an outf_p for a new file for NAME, to be called
1005 create_file (const char *name, const char *oname)
1007 static const char *const hdr[] = {
1008 " Copyright (C) 2003 Free Software Foundation, Inc.\n",
1010 "This file is part of GCC.\n",
1012 "GCC is free software; you can redistribute it and/or modify it under\n",
1013 "the terms of the GNU General Public License as published by the Free\n",
1014 "Software Foundation; either version 2, or (at your option) any later\n",
1017 "GCC is distributed in the hope that it will be useful, but WITHOUT ANY\n",
1018 "WARRANTY; without even the implied warranty of MERCHANTABILITY or\n",
1019 "FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n",
1020 "for more details.\n",
1022 "You should have received a copy of the GNU General Public License\n",
1023 "along with GCC; see the file COPYING. If not, write to the Free\n",
1024 "Software Foundation, 59 Temple Place - Suite 330, Boston, MA\n",
1025 "02111-1307, USA. */\n",
1027 "/* This file is machine generated. Do not edit. */\n"
1032 f = xcalloc (sizeof (*f), 1);
1033 f->next = output_files;
1037 oprintf (f, "/* Type information for %s.\n", name);
1038 for (i = 0; i < ARRAY_SIZE (hdr); i++)
1039 oprintf (f, "%s", hdr[i]);
1043 /* Print, like fprintf, to O. */
1045 oprintf (outf_p o, const char *format, ...)
1051 va_start (ap, format);
1052 slength = xvasprintf (&s, format, ap);
1054 if (o->bufused + slength > o->buflength)
1056 size_t new_len = o->buflength;
1061 } while (o->bufused + slength >= new_len);
1062 o->buf = xrealloc (o->buf, new_len);
1063 o->buflength = new_len;
1065 memcpy (o->buf + o->bufused, s, slength);
1066 o->bufused += slength;
1071 /* Open the global header file and the language-specific header files. */
1074 open_base_files (void)
1078 header_file = create_file ("GCC", "gtype-desc.h");
1080 for (i = 0; i < NUM_BASE_FILES; i++)
1081 base_files[i] = create_file (lang_dir_names[i],
1082 xasprintf ("gtype-%s.h", lang_dir_names[i]));
1084 /* gtype-desc.c is a little special, so we create it here. */
1086 /* The order of files here matters very much. */
1087 static const char *const ifiles [] = {
1088 "config.h", "system.h", "coretypes.h", "tm.h", "varray.h",
1089 "hashtab.h", "splay-tree.h", "bitmap.h", "tree.h", "rtl.h",
1090 "function.h", "insn-config.h", "expr.h", "hard-reg-set.h",
1091 "basic-block.h", "cselib.h", "insn-addr.h", "ssa.h", "optabs.h",
1092 "libfuncs.h", "debug.h", "ggc.h", "cgraph.h",
1095 const char *const *ifp;
1096 outf_p gtype_desc_c;
1098 gtype_desc_c = create_file ("GCC", "gtype-desc.c");
1099 for (ifp = ifiles; *ifp; ifp++)
1100 oprintf (gtype_desc_c, "#include \"%s\"\n", *ifp);
1104 /* Determine the pathname to F relative to $(srcdir). */
1107 get_file_basename (const char *f)
1109 const char *basename;
1112 basename = strrchr (f, '/');
1119 for (i = 1; i < NUM_BASE_FILES; i++)
1125 s1 = basename - strlen (lang_dir_names [i]) - 1;
1126 s2 = lang_dir_names [i];
1129 if (l1 >= l2 && !memcmp (s1, s2, l2))
1132 if ((basename - f - 1) != srcdir_len)
1133 abort (); /* Match is wrong - should be preceded by $srcdir. */
1141 /* Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff
1142 INPUT_FILE is used by <lang>.
1144 This function should be written to assume that a file _is_ used
1145 if the situation is unclear. If it wrongly assumes a file _is_ used,
1146 a linker error will result. If it wrongly assumes a file _is not_ used,
1147 some GC roots may be missed, which is a much harder-to-debug problem. */
1150 get_base_file_bitmap (const char *input_file)
1152 const char *basename = get_file_basename (input_file);
1153 const char *slashpos = strchr (basename, '/');
1161 for (i = 1; i < NUM_BASE_FILES; i++)
1162 if ((size_t)(slashpos - basename) == strlen (lang_dir_names [i])
1163 && memcmp (basename, lang_dir_names[i], strlen (lang_dir_names[i])) == 0)
1165 /* It's in a language directory, set that language. */
1170 abort (); /* Should have found the language. */
1173 /* If it's in any config-lang.in, then set for the languages
1178 for (j = 0; j < NUM_LANG_FILES; j++)
1180 if (!strcmp(input_file, lang_files[j]))
1182 for (k = 0; k < NUM_BASE_FILES; k++)
1184 if (!strcmp(lang_dir_names[k], langs_for_lang_files[j]))
1190 /* Otherwise, set all languages. */
1192 bitmap = (1 << NUM_BASE_FILES) - 1;
1197 /* An output file, suitable for definitions, that can see declarations
1198 made in INPUT_FILE and is linked into every language that uses
1202 get_output_file_with_visibility (const char *input_file)
1206 const char *basename;
1207 const char *for_name;
1208 const char *output_name;
1210 /* This can happen when we need a file with visibility on a
1211 structure that we've never seen. We have to just hope that it's
1212 globally visible. */
1213 if (input_file == NULL)
1214 input_file = "system.h";
1216 /* Determine the output file name. */
1217 basename = get_file_basename (input_file);
1219 len = strlen (basename);
1220 if ((len > 2 && memcmp (basename+len-2, ".c", 2) == 0)
1221 || (len > 2 && memcmp (basename+len-2, ".y", 2) == 0)
1222 || (len > 3 && memcmp (basename+len-3, ".in", 3) == 0))
1226 output_name = s = xasprintf ("gt-%s", basename);
1227 for (; *s != '.'; s++)
1228 if (! ISALNUM (*s) && *s != '-')
1230 memcpy (s, ".h", sizeof (".h"));
1231 for_name = basename;
1233 else if (strcmp (basename, "c-common.h") == 0)
1234 output_name = "gt-c-common.h", for_name = "c-common.c";
1235 else if (strcmp (basename, "c-tree.h") == 0)
1236 output_name = "gt-c-decl.h", for_name = "c-decl.c";
1241 for (i = 0; i < NUM_BASE_FILES; i++)
1242 if (memcmp (basename, lang_dir_names[i], strlen (lang_dir_names[i])) == 0
1243 && basename[strlen(lang_dir_names[i])] == '/')
1244 return base_files[i];
1246 output_name = "gtype-desc.c";
1250 /* Look through to see if we've ever seen this output filename before. */
1251 for (r = output_files; r; r = r->next)
1252 if (strcmp (r->name, output_name) == 0)
1255 /* If not, create it. */
1256 r = create_file (for_name, output_name);
1261 /* The name of an output file, suitable for definitions, that can see
1262 declarations made in INPUT_FILE and is linked into every language
1263 that uses INPUT_FILE. */
1266 get_output_file_name (const char *input_file)
1268 return get_output_file_with_visibility (input_file)->name;
1271 /* Copy the output to its final destination,
1272 but don't unnecessarily change modification times. */
1275 close_output_files (void)
1279 for (of = output_files; of; of = of->next)
1283 newfile = fopen (of->name, "r");
1284 if (newfile != NULL )
1289 for (i = 0; i < of->bufused; i++)
1292 ch = fgetc (newfile);
1293 if (ch == EOF || ch != (unsigned char) of->buf[i])
1296 no_write_p = i == of->bufused && fgetc (newfile) == EOF;
1303 newfile = fopen (of->name, "w");
1304 if (newfile == NULL)
1306 perror ("opening output file");
1309 if (fwrite (of->buf, 1, of->bufused, newfile) != of->bufused)
1311 perror ("writing output file");
1314 if (fclose (newfile) != 0)
1316 perror ("closing output file");
1329 struct walk_type_data;
1331 /* For scalars and strings, given the item in 'val'.
1332 For structures, given a pointer to the item in 'val'.
1333 For misc. pointers, given the item in 'val'.
1335 typedef void (*process_field_fn)
1336 (type_p f, const struct walk_type_data *p);
1337 typedef void (*func_name_fn)
1338 (type_p s, const struct walk_type_data *p);
1340 /* Parameters for write_types. */
1342 struct write_types_data
1345 const char *param_prefix;
1346 const char *subfield_marker_routine;
1347 const char *marker_routine;
1348 const char *reorder_note_routine;
1349 const char *comment;
1352 static void output_escaped_param (struct walk_type_data *d,
1353 const char *, const char *);
1354 static void output_mangled_typename (outf_p, type_p);
1355 static void walk_type (type_p t, struct walk_type_data *d);
1356 static void write_func_for_structure
1357 (type_p orig_s, type_p s, type_p * param,
1358 const struct write_types_data *wtd);
1359 static void write_types_process_field
1360 (type_p f, const struct walk_type_data *d);
1361 static void write_types (type_p structures,
1362 type_p param_structs,
1363 const struct write_types_data *wtd);
1364 static void write_types_local_process_field
1365 (type_p f, const struct walk_type_data *d);
1366 static void write_local_func_for_structure
1367 (type_p orig_s, type_p s, type_p * param);
1368 static void write_local (type_p structures,
1369 type_p param_structs);
1370 static void write_enum_defn (type_p structures, type_p param_structs);
1371 static int contains_scalar_p (type_p t);
1372 static void put_mangled_filename (outf_p , const char *);
1373 static void finish_root_table (struct flist *flp, const char *pfx,
1374 const char *tname, const char *lastname,
1376 static void write_root (outf_p , pair_p, type_p, const char *, int,
1377 struct fileloc *, const char *);
1378 static void write_array (outf_p f, pair_p v,
1379 const struct write_types_data *wtd);
1380 static void write_roots (pair_p);
1382 /* Parameters for walk_type. */
1384 struct walk_type_data
1386 process_field_fn process_field;
1391 const char *prev_val[4];
1394 struct fileloc *line;
1399 const char *reorder_fn;
1403 /* Print a mangled name representing T to OF. */
1406 output_mangled_typename (outf_p of, type_p t)
1410 else switch (t->kind)
1414 output_mangled_typename (of, t->u.p);
1424 case TYPE_LANG_STRUCT:
1425 oprintf (of, "%lu%s", (unsigned long) strlen (t->u.s.tag), t->u.s.tag);
1427 case TYPE_PARAM_STRUCT:
1430 for (i = 0; i < NUM_PARAM; i++)
1431 if (t->u.param_struct.param[i] != NULL)
1432 output_mangled_typename (of, t->u.param_struct.param[i]);
1433 output_mangled_typename (of, t->u.param_struct.stru);
1441 /* Print PARAM to D->OF processing escapes. D->VAL references the
1442 current object, D->PREV_VAL the object containing the current
1443 object, ONAME is the name of the option and D->LINE is used to
1444 print error messages. */
1447 output_escaped_param (struct walk_type_data *d, const char *param,
1452 for (p = param; *p; p++)
1454 oprintf (d->of, "%c", *p);
1458 oprintf (d->of, "(%s)", d->prev_val[2]);
1461 oprintf (d->of, "(%s)", d->prev_val[0]);
1464 oprintf (d->of, "(%s)", d->prev_val[1]);
1468 const char *pp = d->val + strlen (d->val);
1469 while (pp[-1] == ']')
1472 oprintf (d->of, "%s", pp);
1476 error_at_line (d->line, "`%s' option contains bad escape %c%c",
1481 /* Call D->PROCESS_FIELD for every field (or subfield) of D->VAL,
1482 which is of type T. Write code to D->OF to constrain execution (at
1483 the point that D->PROCESS_FIELD is called) to the appropriate
1484 cases. D->PREV_VAL lists the objects containing the current object,
1485 D->OPT is a list of options to apply, D->INDENT is the current
1486 indentation level, D->LINE is used to print error messages,
1487 D->BITMAP indicates which languages to print the structure for, and
1488 D->PARAM is the current parameter (from an enclosing param_is
1492 walk_type (type_p t, struct walk_type_data *d)
1494 const char *length = NULL;
1495 const char *desc = NULL;
1496 int maybe_undef_p = 0;
1497 int use_param_num = -1;
1498 int use_params_p = 0;
1501 d->needs_cast_p = 0;
1502 for (oo = d->opt; oo; oo = oo->next)
1503 if (strcmp (oo->name, "length") == 0)
1504 length = (const char *)oo->info;
1505 else if (strcmp (oo->name, "maybe_undef") == 0)
1507 else if (strncmp (oo->name, "use_param", 9) == 0
1508 && (oo->name[9] == '\0' || ISDIGIT (oo->name[9])))
1509 use_param_num = oo->name[9] == '\0' ? 0 : oo->name[9] - '0';
1510 else if (strcmp (oo->name, "use_params") == 0)
1512 else if (strcmp (oo->name, "desc") == 0)
1513 desc = (const char *)oo->info;
1514 else if (strcmp (oo->name, "dot") == 0)
1516 else if (strcmp (oo->name, "tag") == 0)
1518 else if (strcmp (oo->name, "special") == 0)
1520 else if (strcmp (oo->name, "skip") == 0)
1522 else if (strcmp (oo->name, "default") == 0)
1524 else if (strcmp (oo->name, "descbits") == 0)
1526 else if (strcmp (oo->name, "param_is") == 0)
1528 else if (strncmp (oo->name, "param", 5) == 0
1529 && ISDIGIT (oo->name[5])
1530 && strcmp (oo->name + 6, "_is") == 0)
1532 else if (strcmp (oo->name, "chain_next") == 0)
1534 else if (strcmp (oo->name, "chain_prev") == 0)
1536 else if (strcmp (oo->name, "reorder") == 0)
1539 error_at_line (d->line, "unknown option `%s'\n", oo->name);
1546 int pointer_p = t->kind == TYPE_POINTER;
1550 if (! UNION_OR_STRUCT_P (t))
1551 error_at_line (d->line, "`use_params' option on unimplemented type");
1553 t = find_param_structure (t, d->param);
1555 t = create_pointer (t);
1558 if (use_param_num != -1)
1560 if (d->param != NULL && d->param[use_param_num] != NULL)
1562 type_p nt = d->param[use_param_num];
1564 if (t->kind == TYPE_ARRAY)
1565 nt = create_array (nt, t->u.a.len);
1566 else if (length != NULL && t->kind == TYPE_POINTER)
1567 nt = create_pointer (nt);
1568 d->needs_cast_p = (t->kind != TYPE_POINTER
1569 && (nt->kind == TYPE_POINTER
1570 || nt->kind == TYPE_STRING));
1574 error_at_line (d->line, "no parameter defined for `%s'",
1579 && (t->kind != TYPE_POINTER || ! UNION_OR_STRUCT_P (t->u.p)))
1581 error_at_line (d->line,
1582 "field `%s' has invalid option `maybe_undef_p'\n",
1591 d->process_field (t, d);
1597 && t->u.p->u.s.line.file == NULL)
1599 oprintf (d->of, "%*sif (%s) abort();\n", d->indent, "", d->val);
1605 if (! UNION_OR_STRUCT_P (t->u.p)
1606 && t->u.p->kind != TYPE_PARAM_STRUCT)
1608 error_at_line (d->line,
1609 "field `%s' is pointer to unimplemented type",
1614 d->process_field (t->u.p, d);
1618 int loopcounter = d->counter++;
1619 const char *oldval = d->val;
1620 const char *oldprevval3 = d->prev_val[3];
1623 oprintf (d->of, "%*sif (%s != NULL) {\n", d->indent, "", d->val);
1625 oprintf (d->of, "%*ssize_t i%d;\n", d->indent, "", loopcounter);
1626 d->process_field(t, d);
1627 oprintf (d->of, "%*sfor (i%d = 0; i%d < (size_t)(", d->indent, "",
1628 loopcounter, loopcounter);
1629 output_escaped_param (d, length, "length");
1630 oprintf (d->of, "); i%d++) {\n", loopcounter);
1632 d->val = newval = xasprintf ("%s[i%d]", oldval, loopcounter);
1634 d->prev_val[3] = oldval;
1635 walk_type (t->u.p, d);
1638 d->prev_val[3] = oldprevval3;
1641 oprintf (d->of, "%*s}\n", d->indent, "");
1643 oprintf (d->of, "%*s}\n", d->indent, "");
1650 int loopcounter = d->counter++;
1651 const char *oldval = d->val;
1654 /* If it's an array of scalars, we optimize by not generating
1656 if (t->u.a.p->kind == TYPE_SCALAR)
1659 oprintf (d->of, "%*s{\n", d->indent, "");
1661 oprintf (d->of, "%*ssize_t i%d;\n", d->indent, "", loopcounter);
1662 oprintf (d->of, "%*sfor (i%d = 0; i%d < (size_t)(", d->indent, "",
1663 loopcounter, loopcounter);
1665 output_escaped_param (d, length, "length");
1667 oprintf (d->of, "%s", t->u.a.len);
1668 oprintf (d->of, "); i%d++) {\n", loopcounter);
1670 d->val = newval = xasprintf ("%s[i%d]", oldval, loopcounter);
1672 walk_type (t->u.a.p, d);
1677 oprintf (d->of, "%*s}\n", d->indent, "");
1679 oprintf (d->of, "%*s}\n", d->indent, "");
1687 const char *oldval = d->val;
1688 const char *oldprevval1 = d->prev_val[1];
1689 const char *oldprevval2 = d->prev_val[2];
1690 const int union_p = t->kind == TYPE_UNION;
1691 int seen_default_p = 0;
1694 if (! t->u.s.line.file)
1695 error_at_line (d->line, "incomplete structure `%s'", t->u.s.tag);
1697 if ((d->bitmap & t->u.s.bitmap) != d->bitmap)
1699 error_at_line (d->line,
1700 "structure `%s' defined for mismatching languages",
1702 error_at_line (&t->u.s.line, "one structure defined here");
1705 /* Some things may also be defined in the structure's options. */
1706 for (o = t->u.s.opt; o; o = o->next)
1707 if (! desc && strcmp (o->name, "desc") == 0)
1708 desc = (const char *)o->info;
1710 d->prev_val[2] = oldval;
1711 d->prev_val[1] = oldprevval2;
1716 error_at_line (d->line, "missing `desc' option for union `%s'",
1720 oprintf (d->of, "%*sswitch (", d->indent, "");
1721 output_escaped_param (d, desc, "desc");
1722 oprintf (d->of, ")\n");
1724 oprintf (d->of, "%*s{\n", d->indent, "");
1726 for (f = t->u.s.fields; f; f = f->next)
1729 const char *dot = ".";
1730 const char *tagid = NULL;
1733 int use_param_p = 0;
1736 d->reorder_fn = NULL;
1737 for (oo = f->opt; oo; oo = oo->next)
1738 if (strcmp (oo->name, "dot") == 0)
1739 dot = (const char *)oo->info;
1740 else if (strcmp (oo->name, "tag") == 0)
1741 tagid = (const char *)oo->info;
1742 else if (strcmp (oo->name, "skip") == 0)
1744 else if (strcmp (oo->name, "default") == 0)
1746 else if (strcmp (oo->name, "reorder") == 0)
1747 d->reorder_fn = (const char *)oo->info;
1748 else if (strncmp (oo->name, "use_param", 9) == 0
1749 && (oo->name[9] == '\0' || ISDIGIT (oo->name[9])))
1755 if (union_p && tagid)
1757 oprintf (d->of, "%*scase %s:\n", d->indent, "", tagid);
1760 else if (union_p && default_p)
1762 oprintf (d->of, "%*sdefault:\n", d->indent, "");
1766 else if (! union_p && (default_p || tagid))
1767 error_at_line (d->line,
1768 "can't use `%s' outside a union on field `%s'",
1769 default_p ? "default" : "tag", f->name);
1770 else if (union_p && ! (default_p || tagid)
1771 && f->type->kind == TYPE_SCALAR)
1774 "%s:%d: warning: field `%s' is missing `tag' or `default' option\n",
1775 d->line->file, d->line->line, f->name);
1778 else if (union_p && ! (default_p || tagid))
1779 error_at_line (d->line,
1780 "field `%s' is missing `tag' or `default' option",
1784 d->val = newval = xasprintf ("%s%s%s", oldval, dot, f->name);
1787 if (union_p && use_param_p && d->param == NULL)
1788 oprintf (d->of, "%*sabort();\n", d->indent, "");
1790 walk_type (f->type, d);
1796 oprintf (d->of, "%*sbreak;\n", d->indent, "");
1800 d->reorder_fn = NULL;
1803 d->prev_val[1] = oldprevval1;
1804 d->prev_val[2] = oldprevval2;
1806 if (union_p && ! seen_default_p)
1808 oprintf (d->of, "%*sdefault:\n", d->indent, "");
1809 oprintf (d->of, "%*s break;\n", d->indent, "");
1813 oprintf (d->of, "%*s}\n", d->indent, "");
1819 case TYPE_LANG_STRUCT:
1822 for (nt = t->u.s.lang_struct; nt; nt = nt->next)
1823 if ((d->bitmap & nt->u.s.bitmap) == d->bitmap)
1826 error_at_line (d->line, "structure `%s' differs between languages",
1833 case TYPE_PARAM_STRUCT:
1835 type_p *oldparam = d->param;
1837 d->param = t->u.param_struct.param;
1838 walk_type (t->u.param_struct.stru, d);
1839 d->param = oldparam;
1848 /* process_field routine for marking routines. */
1851 write_types_process_field (type_p f, const struct walk_type_data *d)
1853 const struct write_types_data *wtd;
1854 const char *cast = d->needs_cast_p ? "(void *)" : "";
1855 wtd = (const struct write_types_data *) d->cookie;
1860 oprintf (d->of, "%*s%s (%s%s", d->indent, "",
1861 wtd->subfield_marker_routine, cast, d->val);
1862 if (wtd->param_prefix)
1864 oprintf (d->of, ", %s", d->prev_val[3]);
1867 oprintf (d->of, ", gt_%s_", wtd->param_prefix);
1868 output_mangled_typename (d->of, d->orig_s);
1871 oprintf (d->of, ", gt_%sa_%s", wtd->param_prefix, d->prev_val[0]);
1873 oprintf (d->of, ");\n");
1874 if (d->reorder_fn && wtd->reorder_note_routine)
1875 oprintf (d->of, "%*s%s (%s%s, %s, %s);\n", d->indent, "",
1876 wtd->reorder_note_routine, cast, d->val,
1877 d->prev_val[3], d->reorder_fn);
1881 if (wtd->param_prefix == NULL)
1886 case TYPE_LANG_STRUCT:
1887 case TYPE_PARAM_STRUCT:
1888 oprintf (d->of, "%*sgt_%s_", d->indent, "", wtd->prefix);
1889 output_mangled_typename (d->of, f);
1890 oprintf (d->of, " (%s%s);\n", cast, d->val);
1891 if (d->reorder_fn && wtd->reorder_note_routine)
1892 oprintf (d->of, "%*s%s (%s%s, %s%s, %s);\n", d->indent, "",
1893 wtd->reorder_note_routine, cast, d->val, cast, d->val,
1905 /* For S, a structure that's part of ORIG_S, and using parameters
1906 PARAM, write out a routine that:
1907 - Takes a parameter, a void * but actually of type *S
1908 - If SEEN_ROUTINE returns nonzero, calls write_types_process_field on each
1909 field of S or its substructures and (in some cases) things
1910 that are pointed to by S.
1914 write_func_for_structure (type_p orig_s, type_p s, type_p *param,
1915 const struct write_types_data *wtd)
1917 const char *fn = s->u.s.line.file;
1919 const char *chain_next = NULL;
1920 const char *chain_prev = NULL;
1922 struct walk_type_data d;
1924 /* This is a hack, and not the good kind either. */
1925 for (i = NUM_PARAM - 1; i >= 0; i--)
1926 if (param && param[i] && param[i]->kind == TYPE_POINTER
1927 && UNION_OR_STRUCT_P (param[i]->u.p))
1928 fn = param[i]->u.p->u.s.line.file;
1930 memset (&d, 0, sizeof (d));
1931 d.of = get_output_file_with_visibility (fn);
1933 for (opt = s->u.s.opt; opt; opt = opt->next)
1934 if (strcmp (opt->name, "chain_next") == 0)
1935 chain_next = (const char *) opt->info;
1936 else if (strcmp (opt->name, "chain_prev") == 0)
1937 chain_prev = (const char *) opt->info;
1939 if (chain_prev != NULL && chain_next == NULL)
1940 error_at_line (&s->u.s.line, "chain_prev without chain_next");
1942 d.process_field = write_types_process_field;
1946 d.line = &s->u.s.line;
1947 d.bitmap = s->u.s.bitmap;
1949 d.prev_val[0] = "*x";
1950 d.prev_val[1] = "not valid postage"; /* guarantee an error */
1951 d.prev_val[3] = "x";
1954 oprintf (d.of, "\n");
1955 oprintf (d.of, "void\n");
1957 oprintf (d.of, "gt_%sx_%s", wtd->prefix, orig_s->u.s.tag);
1960 oprintf (d.of, "gt_%s_", wtd->prefix);
1961 output_mangled_typename (d.of, orig_s);
1963 oprintf (d.of, " (x_p)\n");
1964 oprintf (d.of, " void *x_p;\n");
1965 oprintf (d.of, "{\n");
1966 oprintf (d.of, " %s %s * %sx = (%s %s *)x_p;\n",
1967 s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag,
1968 chain_next == NULL ? "const " : "",
1969 s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag);
1970 if (chain_next != NULL)
1971 oprintf (d.of, " %s %s * xlimit = x;\n",
1972 s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag);
1973 if (chain_next == NULL)
1975 oprintf (d.of, " if (%s (x", wtd->marker_routine);
1976 if (wtd->param_prefix)
1978 oprintf (d.of, ", x, gt_%s_", wtd->param_prefix);
1979 output_mangled_typename (d.of, orig_s);
1981 oprintf (d.of, "))\n");
1985 oprintf (d.of, " while (%s (xlimit", wtd->marker_routine);
1986 if (wtd->param_prefix)
1988 oprintf (d.of, ", xlimit, gt_%s_", wtd->param_prefix);
1989 output_mangled_typename (d.of, orig_s);
1991 oprintf (d.of, "))\n");
1992 oprintf (d.of, " xlimit = (");
1993 d.prev_val[2] = "*xlimit";
1994 output_escaped_param (&d, chain_next, "chain_next");
1995 oprintf (d.of, ");\n");
1996 if (chain_prev != NULL)
1998 oprintf (d.of, " if (x != xlimit)\n");
1999 oprintf (d.of, " for (;;)\n");
2000 oprintf (d.of, " {\n");
2001 oprintf (d.of, " %s %s * const xprev = (",
2002 s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag);
2004 d.prev_val[2] = "*x";
2005 output_escaped_param (&d, chain_prev, "chain_prev");
2006 oprintf (d.of, ");\n");
2007 oprintf (d.of, " if (xprev == NULL) break;\n");
2008 oprintf (d.of, " x = xprev;\n");
2009 oprintf (d.of, " (void) %s (xprev",
2010 wtd->marker_routine);
2011 if (wtd->param_prefix)
2013 oprintf (d.of, ", xprev, gt_%s_", wtd->param_prefix);
2014 output_mangled_typename (d.of, orig_s);
2016 oprintf (d.of, ");\n");
2017 oprintf (d.of, " }\n");
2019 oprintf (d.of, " while (x != xlimit)\n");
2021 oprintf (d.of, " {\n");
2023 d.prev_val[2] = "*x";
2027 if (chain_next != NULL)
2029 oprintf (d.of, " x = (");
2030 output_escaped_param (&d, chain_next, "chain_next");
2031 oprintf (d.of, ");\n");
2034 oprintf (d.of, " }\n");
2035 oprintf (d.of, "}\n");
2038 /* Write out marker routines for STRUCTURES and PARAM_STRUCTS. */
2041 write_types (type_p structures, type_p param_structs,
2042 const struct write_types_data *wtd)
2046 oprintf (header_file, "\n/* %s*/\n", wtd->comment);
2047 for (s = structures; s; s = s->next)
2048 if (s->gc_used == GC_POINTED_TO
2049 || s->gc_used == GC_MAYBE_POINTED_TO)
2053 if (s->gc_used == GC_MAYBE_POINTED_TO
2054 && s->u.s.line.file == NULL)
2057 oprintf (header_file, "#define gt_%s_", wtd->prefix);
2058 output_mangled_typename (header_file, s);
2059 oprintf (header_file, "(X) do { \\\n");
2060 oprintf (header_file,
2061 " if (X != NULL) gt_%sx_%s (X);\\\n", wtd->prefix,
2063 oprintf (header_file,
2066 for (opt = s->u.s.opt; opt; opt = opt->next)
2067 if (strcmp (opt->name, "ptr_alias") == 0)
2069 type_p t = (type_p) opt->info;
2070 if (t->kind == TYPE_STRUCT
2071 || t->kind == TYPE_UNION
2072 || t->kind == TYPE_LANG_STRUCT)
2073 oprintf (header_file,
2074 "#define gt_%sx_%s gt_%sx_%s\n",
2075 wtd->prefix, s->u.s.tag, wtd->prefix, t->u.s.tag);
2077 error_at_line (&s->u.s.line,
2078 "structure alias is not a structure");
2084 /* Declare the marker procedure only once. */
2085 oprintf (header_file,
2086 "extern void gt_%sx_%s (void *);\n",
2087 wtd->prefix, s->u.s.tag);
2089 if (s->u.s.line.file == NULL)
2091 fprintf (stderr, "warning: structure `%s' used but not defined\n",
2096 if (s->kind == TYPE_LANG_STRUCT)
2099 for (ss = s->u.s.lang_struct; ss; ss = ss->next)
2100 write_func_for_structure (s, ss, NULL, wtd);
2103 write_func_for_structure (s, s, NULL, wtd);
2106 for (s = param_structs; s; s = s->next)
2107 if (s->gc_used == GC_POINTED_TO)
2109 type_p * param = s->u.param_struct.param;
2110 type_p stru = s->u.param_struct.stru;
2112 /* Declare the marker procedure. */
2113 oprintf (header_file, "extern void gt_%s_", wtd->prefix);
2114 output_mangled_typename (header_file, s);
2115 oprintf (header_file, " (void *);\n");
2117 if (stru->u.s.line.file == NULL)
2119 fprintf (stderr, "warning: structure `%s' used but not defined\n",
2124 if (stru->kind == TYPE_LANG_STRUCT)
2127 for (ss = stru->u.s.lang_struct; ss; ss = ss->next)
2128 write_func_for_structure (s, ss, param, wtd);
2131 write_func_for_structure (s, stru, param, wtd);
2135 static const struct write_types_data ggc_wtd =
2137 "ggc_m", NULL, "ggc_mark", "ggc_test_and_set_mark", NULL,
2138 "GC marker procedures. "
2141 static const struct write_types_data pch_wtd =
2143 "pch_n", "pch_p", "gt_pch_note_object", "gt_pch_note_object",
2144 "gt_pch_note_reorder",
2145 "PCH type-walking procedures. "
2148 /* Write out the local pointer-walking routines. */
2150 /* process_field routine for local pointer-walking. */
2153 write_types_local_process_field (type_p f, const struct walk_type_data *d)
2160 case TYPE_LANG_STRUCT:
2161 case TYPE_PARAM_STRUCT:
2163 oprintf (d->of, "%*sif ((void *)(%s) == this_obj)\n", d->indent, "",
2165 oprintf (d->of, "%*s op (&(%s), cookie);\n", d->indent, "", d->val);
2176 /* For S, a structure that's part of ORIG_S, and using parameters
2177 PARAM, write out a routine that:
2178 - Is of type gt_note_pointers
2179 - If calls PROCESS_FIELD on each field of S or its substructures.
2183 write_local_func_for_structure (type_p orig_s, type_p s, type_p *param)
2185 const char *fn = s->u.s.line.file;
2187 struct walk_type_data d;
2189 /* This is a hack, and not the good kind either. */
2190 for (i = NUM_PARAM - 1; i >= 0; i--)
2191 if (param && param[i] && param[i]->kind == TYPE_POINTER
2192 && UNION_OR_STRUCT_P (param[i]->u.p))
2193 fn = param[i]->u.p->u.s.line.file;
2195 memset (&d, 0, sizeof (d));
2196 d.of = get_output_file_with_visibility (fn);
2198 d.process_field = write_types_local_process_field;
2200 d.line = &s->u.s.line;
2201 d.bitmap = s->u.s.bitmap;
2203 d.prev_val[0] = d.prev_val[2] = "*x";
2204 d.prev_val[1] = "not valid postage"; /* guarantee an error */
2205 d.prev_val[3] = "x";
2208 oprintf (d.of, "\n");
2209 oprintf (d.of, "void\n");
2210 oprintf (d.of, "gt_pch_p_");
2211 output_mangled_typename (d.of, orig_s);
2212 oprintf (d.of, " (this_obj, x_p, op, cookie)\n");
2213 oprintf (d.of, " void *this_obj ATTRIBUTE_UNUSED;\n");
2214 oprintf (d.of, " void *x_p;\n");
2215 oprintf (d.of, " gt_pointer_operator op ATTRIBUTE_UNUSED;\n");
2216 oprintf (d.of, " void *cookie ATTRIBUTE_UNUSED;\n");
2217 oprintf (d.of, "{\n");
2218 oprintf (d.of, " %s %s * const x ATTRIBUTE_UNUSED = (%s %s *)x_p;\n",
2219 s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag,
2220 s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag);
2223 oprintf (d.of, "}\n");
2226 /* Write out local marker routines for STRUCTURES and PARAM_STRUCTS. */
2229 write_local (type_p structures, type_p param_structs)
2233 oprintf (header_file, "\n/* Local pointer-walking routines. */\n");
2234 for (s = structures; s; s = s->next)
2235 if (s->gc_used == GC_POINTED_TO
2236 || s->gc_used == GC_MAYBE_POINTED_TO)
2240 if (s->u.s.line.file == NULL)
2243 for (opt = s->u.s.opt; opt; opt = opt->next)
2244 if (strcmp (opt->name, "ptr_alias") == 0)
2246 type_p t = (type_p) opt->info;
2247 if (t->kind == TYPE_STRUCT
2248 || t->kind == TYPE_UNION
2249 || t->kind == TYPE_LANG_STRUCT)
2251 oprintf (header_file, "#define gt_pch_p_");
2252 output_mangled_typename (header_file, s);
2253 oprintf (header_file, " gt_pch_p_");
2254 output_mangled_typename (header_file, t);
2255 oprintf (header_file, "\n");
2258 error_at_line (&s->u.s.line,
2259 "structure alias is not a structure");
2265 /* Declare the marker procedure only once. */
2266 oprintf (header_file, "extern void gt_pch_p_");
2267 output_mangled_typename (header_file, s);
2268 oprintf (header_file,
2269 "\n (void *, void *, gt_pointer_operator, void *);\n");
2271 if (s->kind == TYPE_LANG_STRUCT)
2274 for (ss = s->u.s.lang_struct; ss; ss = ss->next)
2275 write_local_func_for_structure (s, ss, NULL);
2278 write_local_func_for_structure (s, s, NULL);
2281 for (s = param_structs; s; s = s->next)
2282 if (s->gc_used == GC_POINTED_TO)
2284 type_p * param = s->u.param_struct.param;
2285 type_p stru = s->u.param_struct.stru;
2287 /* Declare the marker procedure. */
2288 oprintf (header_file, "extern void gt_pch_p_");
2289 output_mangled_typename (header_file, s);
2290 oprintf (header_file,
2291 "\n (void *, void *, gt_pointer_operator, void *);\n");
2293 if (stru->u.s.line.file == NULL)
2295 fprintf (stderr, "warning: structure `%s' used but not defined\n",
2300 if (stru->kind == TYPE_LANG_STRUCT)
2303 for (ss = stru->u.s.lang_struct; ss; ss = ss->next)
2304 write_local_func_for_structure (s, ss, param);
2307 write_local_func_for_structure (s, stru, param);
2311 /* Write out the 'enum' definition for gt_types_enum. */
2314 write_enum_defn (type_p structures, type_p param_structs)
2318 oprintf (header_file, "\n/* Enumeration of types known. */\n");
2319 oprintf (header_file, "enum gt_types_enum {\n");
2320 for (s = structures; s; s = s->next)
2321 if (s->gc_used == GC_POINTED_TO
2322 || s->gc_used == GC_MAYBE_POINTED_TO)
2324 if (s->gc_used == GC_MAYBE_POINTED_TO
2325 && s->u.s.line.file == NULL)
2328 oprintf (header_file, " gt_ggc_e_");
2329 output_mangled_typename (header_file, s);
2330 oprintf (header_file, ", \n");
2332 for (s = param_structs; s; s = s->next)
2333 if (s->gc_used == GC_POINTED_TO)
2335 oprintf (header_file, " gt_e_");
2336 output_mangled_typename (header_file, s);
2337 oprintf (header_file, ", \n");
2339 oprintf (header_file, " gt_types_enum_last\n");
2340 oprintf (header_file, "};\n");
2343 /* Might T contain any non-pointer elements? */
2346 contains_scalar_p (type_p t)
2354 return contains_scalar_p (t->u.a.p);
2356 /* Could also check for structures that have no non-pointer
2357 fields, but there aren't enough of those to worry about. */
2362 /* Mangle FN and print it to F. */
2365 put_mangled_filename (outf_p f, const char *fn)
2367 const char *name = get_output_file_name (fn);
2368 for (; *name != 0; name++)
2369 if (ISALNUM (*name))
2370 oprintf (f, "%c", *name);
2372 oprintf (f, "%c", '_');
2375 /* Finish off the currently-created root tables in FLP. PFX, TNAME,
2376 LASTNAME, and NAME are all strings to insert in various places in
2377 the resulting code. */
2380 finish_root_table (struct flist *flp, const char *pfx, const char *lastname,
2381 const char *tname, const char *name)
2385 for (fli2 = flp; fli2; fli2 = fli2->next)
2386 if (fli2->started_p)
2388 oprintf (fli2->f, " %s\n", lastname);
2389 oprintf (fli2->f, "};\n\n");
2392 for (fli2 = flp; fli2; fli2 = fli2->next)
2393 if (fli2->started_p)
2395 lang_bitmap bitmap = get_base_file_bitmap (fli2->name);
2398 for (fnum = 0; bitmap != 0; fnum++, bitmap >>= 1)
2401 oprintf (base_files[fnum],
2402 "extern const struct %s gt_%s_",
2404 put_mangled_filename (base_files[fnum], fli2->name);
2405 oprintf (base_files[fnum], "[];\n");
2411 for (fnum = 0; fnum < NUM_BASE_FILES; fnum++)
2412 oprintf (base_files [fnum],
2413 "const struct %s * const %s[] = {\n",
2418 for (fli2 = flp; fli2; fli2 = fli2->next)
2419 if (fli2->started_p)
2421 lang_bitmap bitmap = get_base_file_bitmap (fli2->name);
2424 fli2->started_p = 0;
2426 for (fnum = 0; bitmap != 0; fnum++, bitmap >>= 1)
2429 oprintf (base_files[fnum], " gt_%s_", pfx);
2430 put_mangled_filename (base_files[fnum], fli2->name);
2431 oprintf (base_files[fnum], ",\n");
2437 for (fnum = 0; fnum < NUM_BASE_FILES; fnum++)
2439 oprintf (base_files[fnum], " NULL\n");
2440 oprintf (base_files[fnum], "};\n");
2445 /* Write out to F the table entry and any marker routines needed to
2446 mark NAME as TYPE. The original variable is V, at LINE.
2447 HAS_LENGTH is nonzero iff V was a variable-length array. IF_MARKED
2448 is nonzero iff we are building the root table for hash table caches. */
2451 write_root (outf_p f, pair_p v, type_p type, const char *name, int has_length,
2452 struct fileloc *line, const char *if_marked)
2459 for (fld = type->u.s.fields; fld; fld = fld->next)
2462 const char *desc = NULL;
2465 for (o = fld->opt; o; o = o->next)
2466 if (strcmp (o->name, "skip") == 0)
2468 else if (strcmp (o->name, "desc") == 0)
2469 desc = (const char *)o->info;
2471 error_at_line (line,
2472 "field `%s' of global `%s' has unknown option `%s'",
2473 fld->name, name, o->name);
2477 else if (desc && fld->type->kind == TYPE_UNION)
2479 pair_p validf = NULL;
2482 for (ufld = fld->type->u.s.fields; ufld; ufld = ufld->next)
2484 const char *tag = NULL;
2487 for (oo = ufld->opt; oo; oo = oo->next)
2488 if (strcmp (oo->name, "tag") == 0)
2489 tag = (const char *)oo->info;
2490 if (tag == NULL || strcmp (tag, desc) != 0)
2493 error_at_line (line,
2494 "both `%s.%s.%s' and `%s.%s.%s' have tag `%s'",
2495 name, fld->name, validf->name,
2496 name, fld->name, ufld->name,
2503 newname = xasprintf ("%s.%s.%s",
2504 name, fld->name, validf->name);
2505 write_root (f, v, validf->type, newname, 0, line,
2511 error_at_line (line,
2512 "global `%s.%s' has `desc' option but is not union",
2517 newname = xasprintf ("%s.%s", name, fld->name);
2518 write_root (f, v, fld->type, newname, 0, line, if_marked);
2528 newname = xasprintf ("%s[0]", name);
2529 write_root (f, v, type->u.a.p, newname, has_length, line, if_marked);
2538 oprintf (f, " {\n");
2539 oprintf (f, " &%s,\n", name);
2542 for (ap = v->type; ap->kind == TYPE_ARRAY; ap = ap->u.a.p)
2544 oprintf (f, " * (%s)", ap->u.a.len);
2545 else if (ap == v->type)
2546 oprintf (f, " * ARRAY_SIZE (%s)", v->name);
2548 oprintf (f, " sizeof (%s", v->name);
2549 for (ap = v->type; ap->kind == TYPE_ARRAY; ap = ap->u.a.p)
2551 oprintf (f, "),\n");
2555 if (! has_length && UNION_OR_STRUCT_P (tp))
2557 oprintf (f, " >_ggc_mx_%s,\n", tp->u.s.tag);
2558 oprintf (f, " >_pch_nx_%s", tp->u.s.tag);
2560 else if (! has_length && tp->kind == TYPE_PARAM_STRUCT)
2562 oprintf (f, " >_ggc_m_");
2563 output_mangled_typename (f, tp);
2564 oprintf (f, ",\n >_pch_n_");
2565 output_mangled_typename (f, tp);
2568 && (tp->kind == TYPE_POINTER || UNION_OR_STRUCT_P (tp)))
2570 oprintf (f, " >_ggc_ma_%s,\n", name);
2571 oprintf (f, " >_pch_na_%s", name);
2575 error_at_line (line,
2576 "global `%s' is pointer to unimplemented type",
2580 oprintf (f, ",\n &%s", if_marked);
2581 oprintf (f, "\n },\n");
2587 oprintf (f, " {\n");
2588 oprintf (f, " &%s,\n", name);
2589 oprintf (f, " 1, \n");
2590 oprintf (f, " sizeof (%s),\n", v->name);
2591 oprintf (f, " >_ggc_m_S,\n");
2592 oprintf (f, " (gt_pointer_walker) >_pch_n_S\n");
2593 oprintf (f, " },\n");
2601 error_at_line (line,
2602 "global `%s' is unimplemented type",
2607 /* This generates a routine to walk an array. */
2610 write_array (outf_p f, pair_p v, const struct write_types_data *wtd)
2612 struct walk_type_data d;
2615 memset (&d, 0, sizeof (d));
2621 d.bitmap = get_base_file_bitmap (v->line.file);
2624 d.prev_val[3] = prevval3 = xasprintf ("&%s", v->name);
2626 if (wtd->param_prefix)
2628 oprintf (f, "static void gt_%sa_%s\n", wtd->param_prefix, v->name);
2630 " (void *, void *, gt_pointer_operator, void *);\n");
2631 oprintf (f, "static void gt_%sa_%s (this_obj, x_p, op, cookie)\n",
2632 wtd->param_prefix, v->name);
2633 oprintf (d.of, " void *this_obj ATTRIBUTE_UNUSED;\n");
2634 oprintf (d.of, " void *x_p ATTRIBUTE_UNUSED;\n");
2635 oprintf (d.of, " gt_pointer_operator op ATTRIBUTE_UNUSED;\n");
2636 oprintf (d.of, " void *cookie ATTRIBUTE_UNUSED;\n");
2637 oprintf (d.of, "{\n");
2638 d.prev_val[0] = d.prev_val[1] = d.prev_val[2] = d.val = v->name;
2639 d.process_field = write_types_local_process_field;
2640 walk_type (v->type, &d);
2641 oprintf (f, "}\n\n");
2645 oprintf (f, "static void gt_%sa_%s (void *);\n",
2646 wtd->prefix, v->name);
2647 oprintf (f, "static void\ngt_%sa_%s (x_p)\n",
2648 wtd->prefix, v->name);
2649 oprintf (f, " void *x_p ATTRIBUTE_UNUSED;\n");
2651 d.prev_val[0] = d.prev_val[1] = d.prev_val[2] = d.val = v->name;
2652 d.process_field = write_types_process_field;
2653 walk_type (v->type, &d);
2655 oprintf (f, "}\n\n");
2658 /* Output a table describing the locations and types of VARIABLES. */
2661 write_roots (pair_p variables)
2664 struct flist *flp = NULL;
2666 for (v = variables; v; v = v->next)
2668 outf_p f = get_output_file_with_visibility (v->line.file);
2670 const char *length = NULL;
2671 int deletable_p = 0;
2674 for (o = v->opt; o; o = o->next)
2675 if (strcmp (o->name, "length") == 0)
2676 length = (const char *)o->info;
2677 else if (strcmp (o->name, "deletable") == 0)
2679 else if (strcmp (o->name, "param_is") == 0)
2681 else if (strncmp (o->name, "param", 5) == 0
2682 && ISDIGIT (o->name[5])
2683 && strcmp (o->name + 6, "_is") == 0)
2685 else if (strcmp (o->name, "if_marked") == 0)
2688 error_at_line (&v->line,
2689 "global `%s' has unknown option `%s'",
2692 for (fli = flp; fli; fli = fli->next)
2697 fli = xmalloc (sizeof (*fli));
2701 fli->name = v->line.file;
2704 oprintf (f, "\n/* GC roots. */\n\n");
2709 && v->type->kind == TYPE_POINTER
2710 && (v->type->u.p->kind == TYPE_POINTER
2711 || v->type->u.p->kind == TYPE_STRUCT))
2713 write_array (f, v, &ggc_wtd);
2714 write_array (f, v, &pch_wtd);
2718 for (v = variables; v; v = v->next)
2720 outf_p f = get_output_file_with_visibility (v->line.file);
2726 for (o = v->opt; o; o = o->next)
2727 if (strcmp (o->name, "length") == 0)
2729 else if (strcmp (o->name, "deletable") == 0
2730 || strcmp (o->name, "if_marked") == 0)
2736 for (fli = flp; fli; fli = fli->next)
2739 if (! fli->started_p)
2743 oprintf (f, "const struct ggc_root_tab gt_ggc_r_");
2744 put_mangled_filename (f, v->line.file);
2745 oprintf (f, "[] = {\n");
2748 write_root (f, v, v->type, v->name, length_p, &v->line, NULL);
2751 finish_root_table (flp, "ggc_r", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2754 for (v = variables; v; v = v->next)
2756 outf_p f = get_output_file_with_visibility (v->line.file);
2761 for (o = v->opt; o; o = o->next)
2762 if (strcmp (o->name, "deletable") == 0)
2764 else if (strcmp (o->name, "if_marked") == 0)
2770 for (fli = flp; fli; fli = fli->next)
2773 if (! fli->started_p)
2777 oprintf (f, "const struct ggc_root_tab gt_ggc_rd_");
2778 put_mangled_filename (f, v->line.file);
2779 oprintf (f, "[] = {\n");
2782 oprintf (f, " { &%s, 1, sizeof (%s), NULL, NULL },\n",
2786 finish_root_table (flp, "ggc_rd", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2787 "gt_ggc_deletable_rtab");
2789 for (v = variables; v; v = v->next)
2791 outf_p f = get_output_file_with_visibility (v->line.file);
2793 const char *if_marked = NULL;
2797 for (o = v->opt; o; o = o->next)
2798 if (strcmp (o->name, "length") == 0)
2800 else if (strcmp (o->name, "if_marked") == 0)
2801 if_marked = (const char *) o->info;
2803 if (if_marked == NULL)
2806 if (v->type->kind != TYPE_POINTER
2807 || v->type->u.p->kind != TYPE_PARAM_STRUCT
2808 || v->type->u.p->u.param_struct.stru != find_structure ("htab", 0))
2810 error_at_line (&v->line, "if_marked option used but not hash table");
2814 for (fli = flp; fli; fli = fli->next)
2817 if (! fli->started_p)
2821 oprintf (f, "const struct ggc_cache_tab gt_ggc_rc_");
2822 put_mangled_filename (f, v->line.file);
2823 oprintf (f, "[] = {\n");
2826 write_root (f, v, v->type->u.p->u.param_struct.param[0],
2827 v->name, length_p, &v->line, if_marked);
2830 finish_root_table (flp, "ggc_rc", "LAST_GGC_CACHE_TAB", "ggc_cache_tab",
2831 "gt_ggc_cache_rtab");
2833 for (v = variables; v; v = v->next)
2835 outf_p f = get_output_file_with_visibility (v->line.file);
2838 int if_marked_p = 0;
2841 for (o = v->opt; o; o = o->next)
2842 if (strcmp (o->name, "length") == 0)
2844 else if (strcmp (o->name, "if_marked") == 0)
2850 for (fli = flp; fli; fli = fli->next)
2853 if (! fli->started_p)
2857 oprintf (f, "const struct ggc_root_tab gt_pch_rc_");
2858 put_mangled_filename (f, v->line.file);
2859 oprintf (f, "[] = {\n");
2862 write_root (f, v, v->type, v->name, length_p, &v->line, NULL);
2865 finish_root_table (flp, "pch_rc", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2866 "gt_pch_cache_rtab");
2868 for (v = variables; v; v = v->next)
2870 outf_p f = get_output_file_with_visibility (v->line.file);
2875 for (o = v->opt; o; o = o->next)
2876 if (strcmp (o->name, "deletable") == 0
2877 || strcmp (o->name, "if_marked") == 0)
2883 if (! contains_scalar_p (v->type))
2886 for (fli = flp; fli; fli = fli->next)
2889 if (! fli->started_p)
2893 oprintf (f, "const struct ggc_root_tab gt_pch_rs_");
2894 put_mangled_filename (f, v->line.file);
2895 oprintf (f, "[] = {\n");
2898 oprintf (f, " { &%s, 1, sizeof (%s), NULL, NULL },\n",
2902 finish_root_table (flp, "pch_rs", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2903 "gt_pch_scalar_rtab");
2907 extern int main (int argc, char **argv);
2909 main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
2912 static struct fileloc pos = { __FILE__, __LINE__ };
2917 srcdir_len = strlen (srcdir);
2919 do_scalar_typedef ("CUMULATIVE_ARGS", &pos);
2920 do_scalar_typedef ("REAL_VALUE_TYPE", &pos);
2921 do_scalar_typedef ("uint8", &pos);
2922 do_scalar_typedef ("jword", &pos);
2923 do_scalar_typedef ("JCF_u2", &pos);
2925 do_typedef ("PTR", create_pointer (create_scalar_type ("void",
2928 do_typedef ("HARD_REG_SET", create_array (
2929 create_scalar_type ("unsigned long", strlen ("unsigned long")),
2932 for (i = 0; i < NUM_GT_FILES; i++)
2935 /* Omit if already seen. */
2936 for (j = 0; j < i; j++)
2938 if (!strcmp (all_files[i], all_files[j]))
2945 parse_file (all_files[i]);
2951 set_gc_used (variables);
2954 write_enum_defn (structures, param_structs);
2955 write_types (structures, param_structs, &ggc_wtd);
2956 write_types (structures, param_structs, &pch_wtd);
2957 write_local (structures, param_structs);
2958 write_roots (variables);
2960 close_output_files ();
2962 return (hit_error != 0);