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
90 /* Lists of various things. */
92 static pair_p typedefs
;
93 static type_p structures
;
94 static type_p param_structs
;
95 static pair_p variables
;
97 static void do_scalar_typedef (const char *, struct fileloc
*);
98 static type_p find_param_structure
99 (type_p t
, type_p param
[NUM_PARAM
]);
100 static type_p
adjust_field_tree_exp (type_p t
, options_p opt
);
101 static type_p
adjust_field_rtx_def (type_p t
, options_p opt
);
103 /* Define S as a typedef to T at POS. */
106 do_typedef (const char *s
, type_p t
, struct fileloc
*pos
)
110 for (p
= typedefs
; p
!= NULL
; p
= p
->next
)
111 if (strcmp (p
->name
, s
) == 0)
115 error_at_line (pos
, "type `%s' previously defined", s
);
116 error_at_line (&p
->line
, "previously defined here");
121 p
= xmalloc (sizeof (struct pair
));
129 /* Define S as a typename of a scalar. */
132 do_scalar_typedef (const char *s
, struct fileloc
*pos
)
134 do_typedef (s
, create_scalar_type (s
, strlen (s
)), pos
);
137 /* Return the type previously defined for S. Use POS to report errors. */
140 resolve_typedef (const char *s
, struct fileloc
*pos
)
143 for (p
= typedefs
; p
!= NULL
; p
= p
->next
)
144 if (strcmp (p
->name
, s
) == 0)
146 error_at_line (pos
, "unidentified type `%s'", s
);
147 return create_scalar_type ("char", 4);
150 /* Create a new structure with tag NAME (or a union iff ISUNION is nonzero),
151 at POS with fields FIELDS and options O. */
154 new_structure (const char *name
, int isunion
, struct fileloc
*pos
,
155 pair_p fields
, options_p o
)
159 lang_bitmap bitmap
= get_base_file_bitmap (pos
->file
);
161 for (si
= structures
; si
!= NULL
; si
= si
->next
)
162 if (strcmp (name
, si
->u
.s
.tag
) == 0
163 && UNION_P (si
) == isunion
)
166 if (si
->kind
== TYPE_LANG_STRUCT
)
170 for (si
= ls
->u
.s
.lang_struct
; si
!= NULL
; si
= si
->next
)
171 if (si
->u
.s
.bitmap
== bitmap
)
174 else if (si
->u
.s
.line
.file
!= NULL
&& si
->u
.s
.bitmap
!= bitmap
)
177 si
= xcalloc (1, sizeof (struct type
));
178 memcpy (si
, ls
, sizeof (struct type
));
179 ls
->kind
= TYPE_LANG_STRUCT
;
180 ls
->u
.s
.lang_struct
= si
;
181 ls
->u
.s
.fields
= NULL
;
183 si
->pointer_to
= NULL
;
184 si
->u
.s
.lang_struct
= ls
;
189 if (ls
!= NULL
&& s
== NULL
)
191 s
= xcalloc (1, sizeof (struct type
));
192 s
->next
= ls
->u
.s
.lang_struct
;
193 ls
->u
.s
.lang_struct
= s
;
194 s
->u
.s
.lang_struct
= ls
;
201 s
= xcalloc (1, sizeof (struct type
));
202 s
->next
= structures
;
206 if (s
->u
.s
.line
.file
!= NULL
207 || (s
->u
.s
.lang_struct
&& (s
->u
.s
.lang_struct
->u
.s
.bitmap
& bitmap
)))
209 error_at_line (pos
, "duplicate structure definition");
210 error_at_line (&s
->u
.s
.line
, "previous definition here");
213 s
->kind
= isunion
? TYPE_UNION
: TYPE_STRUCT
;
216 s
->u
.s
.fields
= fields
;
218 s
->u
.s
.bitmap
= bitmap
;
219 if (s
->u
.s
.lang_struct
)
220 s
->u
.s
.lang_struct
->u
.s
.bitmap
|= bitmap
;
223 /* Return the previously-defined structure with tag NAME (or a union
224 iff ISUNION is nonzero), or a new empty structure or union if none
225 was defined previously. */
228 find_structure (const char *name
, int isunion
)
232 for (s
= structures
; s
!= NULL
; s
= s
->next
)
233 if (strcmp (name
, s
->u
.s
.tag
) == 0
234 && UNION_P (s
) == isunion
)
237 s
= xcalloc (1, sizeof (struct type
));
238 s
->next
= structures
;
240 s
->kind
= isunion
? TYPE_UNION
: TYPE_STRUCT
;
246 /* Return the previously-defined parameterized structure for structure
247 T and parameters PARAM, or a new parameterized empty structure or
248 union if none was defined previously. */
251 find_param_structure (type_p t
, type_p param
[NUM_PARAM
])
255 for (res
= param_structs
; res
; res
= res
->next
)
256 if (res
->u
.param_struct
.stru
== t
257 && memcmp (res
->u
.param_struct
.param
, param
,
258 sizeof (type_p
) * NUM_PARAM
) == 0)
262 res
= xcalloc (1, sizeof (*res
));
263 res
->kind
= TYPE_PARAM_STRUCT
;
264 res
->next
= param_structs
;
266 res
->u
.param_struct
.stru
= t
;
267 memcpy (res
->u
.param_struct
.param
, param
, sizeof (type_p
) * NUM_PARAM
);
272 /* Return a scalar type with name NAME. */
275 create_scalar_type (const char *name
, size_t name_len
)
277 type_p r
= xcalloc (1, sizeof (struct type
));
278 r
->kind
= TYPE_SCALAR
;
279 r
->u
.sc
= xmemdup (name
, name_len
, name_len
+ 1);
283 /* Return a pointer to T. */
286 create_pointer (type_p t
)
290 type_p r
= xcalloc (1, sizeof (struct type
));
291 r
->kind
= TYPE_POINTER
;
295 return t
->pointer_to
;
298 /* Return an array of length LEN. */
301 create_array (type_p t
, const char *len
)
305 v
= xcalloc (1, sizeof (*v
));
306 v
->kind
= TYPE_ARRAY
;
312 /* Add a variable named S of type T with options O defined at POS,
316 note_variable (const char *s
, type_p t
, options_p o
, struct fileloc
*pos
)
319 n
= xmalloc (sizeof (*n
));
328 /* We really don't care how long a CONST_DOUBLE is. */
329 #define CONST_DOUBLE_FORMAT "ww"
330 const char * const rtx_format
[NUM_RTX_CODE
] = {
331 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT ,
336 static int rtx_next_new
[NUM_RTX_CODE
];
338 /* Generate the contents of the rtx_next array. This really doesn't belong
339 in gengtype at all, but it's needed for adjust_field_rtx_def. */
345 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
349 rtx_next_new
[i
] = -1;
350 if (strncmp (rtx_format
[i
], "iuu", 3) == 0)
352 else if (i
== COND_EXEC
|| i
== SET
|| i
== EXPR_LIST
|| i
== INSN_LIST
)
355 for (k
= strlen (rtx_format
[i
]) - 1; k
>= 0; k
--)
356 if (rtx_format
[i
][k
] == 'e' || rtx_format
[i
][k
] == 'u')
361 /* Write out the contents of the rtx_next array. */
363 write_rtx_next (void)
365 outf_p f
= get_output_file_with_visibility (NULL
);
368 oprintf (f
, "\n/* Used to implement the RTX_NEXT macro. */\n");
369 oprintf (f
, "const unsigned char rtx_next[NUM_RTX_CODE] = {\n");
370 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
371 if (rtx_next_new
[i
] == -1)
372 oprintf (f
, " 0,\n");
375 " offsetof (struct rtx_def, fld) + %d * sizeof (rtunion),\n",
380 /* Handle `special("rtx_def")'. This is a special case for field
381 `fld' of struct rtx_def, which is an array of unions whose values
382 are based in a complex way on the type of RTL. */
385 adjust_field_rtx_def (type_p t
, options_p opt ATTRIBUTE_UNUSED
)
390 type_p rtx_tp
, rtvec_tp
, tree_tp
, mem_attrs_tp
, note_union_tp
, scalar_tp
;
391 type_p bitmap_tp
, basic_block_tp
, reg_attrs_tp
;
393 static const char * const rtx_name
[NUM_RTX_CODE
] = {
394 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME ,
399 if (t
->kind
!= TYPE_ARRAY
)
401 error_at_line (&lexer_line
,
402 "special `rtx_def' must be applied to an array");
406 nodot
= xmalloc (sizeof (*nodot
));
411 rtx_tp
= create_pointer (find_structure ("rtx_def", 0));
412 rtvec_tp
= create_pointer (find_structure ("rtvec_def", 0));
413 tree_tp
= create_pointer (find_structure ("tree_node", 1));
414 mem_attrs_tp
= create_pointer (find_structure ("mem_attrs", 0));
415 reg_attrs_tp
= create_pointer (find_structure ("reg_attrs", 0));
416 bitmap_tp
= create_pointer (find_structure ("bitmap_element_def", 0));
417 basic_block_tp
= create_pointer (find_structure ("basic_block_def", 0));
418 scalar_tp
= create_scalar_type ("rtunion scalar", 14);
421 pair_p note_flds
= NULL
;
424 for (c
= NOTE_INSN_BIAS
; c
<= NOTE_INSN_MAX
; c
++)
426 pair_p old_note_flds
= note_flds
;
428 note_flds
= xmalloc (sizeof (*note_flds
));
429 note_flds
->line
.file
= __FILE__
;
430 note_flds
->line
.line
= __LINE__
;
431 note_flds
->opt
= xmalloc (sizeof (*note_flds
->opt
));
432 note_flds
->opt
->next
= nodot
;
433 note_flds
->opt
->name
= "tag";
434 note_flds
->opt
->info
= xasprintf ("%d", c
);
435 note_flds
->next
= old_note_flds
;
439 /* NOTE_INSN_MAX is used as the default field for line
442 note_flds
->opt
->name
= "default";
443 note_flds
->name
= "rtstr";
444 note_flds
->type
= &string_type
;
447 case NOTE_INSN_BLOCK_BEG
:
448 case NOTE_INSN_BLOCK_END
:
449 note_flds
->name
= "rttree";
450 note_flds
->type
= tree_tp
;
453 case NOTE_INSN_EXPECTED_VALUE
:
454 note_flds
->name
= "rtx";
455 note_flds
->type
= rtx_tp
;
459 note_flds
->name
= "rtint";
460 note_flds
->type
= scalar_tp
;
464 new_structure ("rtx_def_note_subunion", 1, &lexer_line
, note_flds
, NULL
);
467 note_union_tp
= find_structure ("rtx_def_note_subunion", 1);
469 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
471 pair_p old_flds
= flds
;
472 pair_p subfields
= NULL
;
473 size_t aindex
, nmindex
;
477 for (aindex
= 0; aindex
< strlen (rtx_format
[i
]); aindex
++)
479 pair_p old_subf
= subfields
;
483 switch (rtx_format
[i
][aindex
])
494 if (i
== MEM
&& aindex
== 1)
495 t
= mem_attrs_tp
, subname
= "rtmem";
496 else if (i
== JUMP_INSN
&& aindex
== 9)
497 t
= rtx_tp
, subname
= "rtx";
498 else if (i
== CODE_LABEL
&& aindex
== 4)
499 t
= scalar_tp
, subname
= "rtint";
500 else if (i
== CODE_LABEL
&& aindex
== 5)
501 t
= rtx_tp
, subname
= "rtx";
502 else if (i
== LABEL_REF
503 && (aindex
== 1 || aindex
== 2))
504 t
= rtx_tp
, subname
= "rtx";
505 else if (i
== NOTE
&& aindex
== 4)
506 t
= note_union_tp
, subname
= "";
507 else if (i
== NOTE
&& aindex
>= 7)
508 t
= scalar_tp
, subname
= "rtint";
509 else if (i
== ADDR_DIFF_VEC
&& aindex
== 4)
510 t
= scalar_tp
, subname
= "rtint";
511 else if (i
== VALUE
&& aindex
== 0)
512 t
= scalar_tp
, subname
= "rtint";
513 else if (i
== REG
&& aindex
== 1)
514 t
= scalar_tp
, subname
= "rtint";
515 else if (i
== REG
&& aindex
== 2)
516 t
= reg_attrs_tp
, subname
= "rtreg";
517 else if (i
== SCRATCH
&& aindex
== 0)
518 t
= scalar_tp
, subname
= "rtint";
519 else if (i
== SYMBOL_REF
&& aindex
== 1)
520 t
= scalar_tp
, subname
= "rtint";
521 else if (i
== SYMBOL_REF
&& aindex
== 2)
522 t
= tree_tp
, subname
= "rttree";
523 else if (i
== BARRIER
&& aindex
>= 3)
524 t
= scalar_tp
, subname
= "rtint";
527 error_at_line (&lexer_line
,
528 "rtx type `%s' has `0' in position %lu, can't handle",
529 rtx_name
[i
], (unsigned long) aindex
);
570 error_at_line (&lexer_line
,
571 "rtx type `%s' has `%c' in position %lu, can't handle",
572 rtx_name
[i
], rtx_format
[i
][aindex
],
573 (unsigned long)aindex
);
579 subfields
= xmalloc (sizeof (*subfields
));
580 subfields
->next
= old_subf
;
582 subfields
->name
= xasprintf ("[%lu].%s", (unsigned long)aindex
,
584 subfields
->line
.file
= __FILE__
;
585 subfields
->line
.line
= __LINE__
;
586 if (t
== note_union_tp
)
588 subfields
->opt
= xmalloc (sizeof (*subfields
->opt
));
589 subfields
->opt
->next
= nodot
;
590 subfields
->opt
->name
= "desc";
591 subfields
->opt
->info
= "NOTE_LINE_NUMBER (&%0)";
593 else if (t
== basic_block_tp
)
595 /* We don't presently GC basic block structures... */
596 subfields
->opt
= xmalloc (sizeof (*subfields
->opt
));
597 subfields
->opt
->next
= nodot
;
598 subfields
->opt
->name
= "skip";
599 subfields
->opt
->info
= NULL
;
602 subfields
->opt
= nodot
;
605 flds
= xmalloc (sizeof (*flds
));
606 flds
->next
= old_flds
;
608 sname
= xasprintf ("rtx_def_%s", rtx_name
[i
]);
609 new_structure (sname
, 0, &lexer_line
, subfields
, NULL
);
610 flds
->type
= find_structure (sname
, 0);
611 flds
->line
.file
= __FILE__
;
612 flds
->line
.line
= __LINE__
;
613 flds
->opt
= xmalloc (sizeof (*flds
->opt
));
614 flds
->opt
->next
= nodot
;
615 flds
->opt
->name
= "tag";
616 ftag
= xstrdup (rtx_name
[i
]);
617 for (nmindex
= 0; nmindex
< strlen (ftag
); nmindex
++)
618 ftag
[nmindex
] = TOUPPER (ftag
[nmindex
]);
619 flds
->opt
->info
= ftag
;
622 new_structure ("rtx_def_subunion", 1, &lexer_line
, flds
, nodot
);
623 return find_structure ("rtx_def_subunion", 1);
626 /* Handle `special("tree_exp")'. This is a special case for
627 field `operands' of struct tree_exp, which although it claims to contain
628 pointers to trees, actually sometimes contains pointers to RTL too.
629 Passed T, the old type of the field, and OPT its options. Returns
630 a new type for the field. */
633 adjust_field_tree_exp (type_p t
, options_p opt ATTRIBUTE_UNUSED
)
638 static const struct {
643 { "SAVE_EXPR", 2, 1 },
644 { "GOTO_SUBROUTINE_EXPR", 0, 2 },
645 { "RTL_EXPR", 0, 2 },
646 { "WITH_CLEANUP_EXPR", 2, 1 },
647 { "METHOD_CALL_EXPR", 3, 1 }
650 if (t
->kind
!= TYPE_ARRAY
)
652 error_at_line (&lexer_line
,
653 "special `tree_exp' must be applied to an array");
657 nodot
= xmalloc (sizeof (*nodot
));
662 flds
= xmalloc (sizeof (*flds
));
666 flds
->line
.file
= __FILE__
;
667 flds
->line
.line
= __LINE__
;
668 flds
->opt
= xmalloc (sizeof (*flds
->opt
));
669 flds
->opt
->next
= nodot
;
670 flds
->opt
->name
= "length";
671 flds
->opt
->info
= "TREE_CODE_LENGTH (TREE_CODE ((tree) &%0))";
673 options_p oldopt
= flds
->opt
;
674 flds
->opt
= xmalloc (sizeof (*flds
->opt
));
675 flds
->opt
->next
= oldopt
;
676 flds
->opt
->name
= "default";
677 flds
->opt
->info
= "";
680 for (i
= 0; i
< ARRAY_SIZE (data
); i
++)
682 pair_p old_flds
= flds
;
683 pair_p subfields
= NULL
;
688 r_index
< data
[i
].first_rtl
+ data
[i
].num_rtl
;
691 pair_p old_subf
= subfields
;
692 subfields
= xmalloc (sizeof (*subfields
));
693 subfields
->next
= old_subf
;
694 subfields
->name
= xasprintf ("[%d]", r_index
);
695 if (r_index
< data
[i
].first_rtl
)
696 subfields
->type
= t
->u
.a
.p
;
698 subfields
->type
= create_pointer (find_structure ("rtx_def", 0));
699 subfields
->line
.file
= __FILE__
;
700 subfields
->line
.line
= __LINE__
;
701 subfields
->opt
= nodot
;
704 flds
= xmalloc (sizeof (*flds
));
705 flds
->next
= old_flds
;
707 sname
= xasprintf ("tree_exp_%s", data
[i
].name
);
708 new_structure (sname
, 0, &lexer_line
, subfields
, NULL
);
709 flds
->type
= find_structure (sname
, 0);
710 flds
->line
.file
= __FILE__
;
711 flds
->line
.line
= __LINE__
;
712 flds
->opt
= xmalloc (sizeof (*flds
->opt
));
713 flds
->opt
->next
= nodot
;
714 flds
->opt
->name
= "tag";
715 flds
->opt
->info
= data
[i
].name
;
718 new_structure ("tree_exp_subunion", 1, &lexer_line
, flds
, nodot
);
719 return find_structure ("tree_exp_subunion", 1);
722 /* Perform any special processing on a type T, about to become the type
723 of a field. Return the appropriate type for the field.
725 - Converts pointer-to-char, with no length parameter, to TYPE_STRING;
726 - Similarly for arrays of pointer-to-char;
727 - Converts structures for which a parameter is provided to
729 - Handles "special" options.
733 adjust_field_type (type_p t
, options_p opt
)
736 const int pointer_p
= t
->kind
== TYPE_POINTER
;
737 type_p params
[NUM_PARAM
];
741 for (i
= 0; i
< NUM_PARAM
; i
++)
744 for (; opt
; opt
= opt
->next
)
745 if (strcmp (opt
->name
, "length") == 0)
747 else if (strcmp (opt
->name
, "param_is") == 0
748 || (strncmp (opt
->name
, "param", 5) == 0
749 && ISDIGIT (opt
->name
[5])
750 && strcmp (opt
->name
+ 6, "_is") == 0))
752 int num
= ISDIGIT (opt
->name
[5]) ? opt
->name
[5] - '0' : 0;
754 if (! UNION_OR_STRUCT_P (t
)
755 && (t
->kind
!= TYPE_POINTER
|| ! UNION_OR_STRUCT_P (t
->u
.p
)))
757 error_at_line (&lexer_line
,
758 "option `%s' may only be applied to structures or structure pointers",
764 if (params
[num
] != NULL
)
765 error_at_line (&lexer_line
, "duplicate `%s' option", opt
->name
);
766 if (! ISDIGIT (opt
->name
[5]))
767 params
[num
] = create_pointer ((type_p
) opt
->info
);
769 params
[num
] = (type_p
) opt
->info
;
771 else if (strcmp (opt
->name
, "special") == 0)
773 const char *special_name
= (const char *)opt
->info
;
774 if (strcmp (special_name
, "tree_exp") == 0)
775 t
= adjust_field_tree_exp (t
, opt
);
776 else if (strcmp (special_name
, "rtx_def") == 0)
777 t
= adjust_field_rtx_def (t
, opt
);
779 error_at_line (&lexer_line
, "unknown special `%s'", special_name
);
788 realt
= find_param_structure (t
, params
);
789 t
= pointer_p
? create_pointer (realt
) : realt
;
794 && t
->u
.p
->kind
== TYPE_SCALAR
795 && (strcmp (t
->u
.p
->u
.sc
, "char") == 0
796 || strcmp (t
->u
.p
->u
.sc
, "unsigned char") == 0))
798 if (t
->kind
== TYPE_ARRAY
&& t
->u
.a
.p
->kind
== TYPE_POINTER
799 && t
->u
.a
.p
->u
.p
->kind
== TYPE_SCALAR
800 && (strcmp (t
->u
.a
.p
->u
.p
->u
.sc
, "char") == 0
801 || strcmp (t
->u
.a
.p
->u
.p
->u
.sc
, "unsigned char") == 0))
802 return create_array (&string_type
, t
->u
.a
.len
);
807 /* Create a union for YYSTYPE, as yacc would do it, given a fieldlist FIELDS
808 and information about the correspondence between token types and fields
809 in TYPEINFO. POS is used for error messages. */
812 note_yacc_type (options_p o
, pair_p fields
, pair_p typeinfo
,
818 for (p
= typeinfo
; p
; p
= p
->next
)
825 if (p
->type
== (type_p
) 1)
830 for (pp
= typeinfo
; pp
; pp
= pp
->next
)
831 if (pp
->type
!= (type_p
) 1
832 && strcmp (pp
->opt
->info
, p
->opt
->info
) == 0)
841 for (m
= fields
; m
; m
= m
->next
)
842 if (strcmp (m
->name
, p
->name
) == 0)
846 error_at_line (&p
->line
,
847 "couldn't match fieldname `%s'", p
->name
);
858 || p
->type
== (type_p
) 1)
864 new_structure ("yy_union", 1, pos
, typeinfo
, o
);
865 do_typedef ("YYSTYPE", find_structure ("yy_union", 1), pos
);
868 static void process_gc_options (options_p
, enum gc_used_enum
,
869 int *, int *, int *);
870 static void set_gc_used_type (type_p
, enum gc_used_enum
, type_p
*);
871 static void set_gc_used (pair_p
);
873 /* Handle OPT for set_gc_used_type. */
876 process_gc_options (options_p opt
, enum gc_used_enum level
, int *maybe_undef
,
877 int *pass_param
, int *length
)
880 for (o
= opt
; o
; o
= o
->next
)
881 if (strcmp (o
->name
, "ptr_alias") == 0 && level
== GC_POINTED_TO
)
882 set_gc_used_type ((type_p
) o
->info
, GC_POINTED_TO
, NULL
);
883 else if (strcmp (o
->name
, "maybe_undef") == 0)
885 else if (strcmp (o
->name
, "use_params") == 0)
887 else if (strcmp (o
->name
, "length") == 0)
891 /* Set the gc_used field of T to LEVEL, and handle the types it references. */
894 set_gc_used_type (type_p t
, enum gc_used_enum level
, type_p param
[NUM_PARAM
])
896 if (t
->gc_used
>= level
)
909 process_gc_options (t
->u
.s
.opt
, level
, &dummy
, &dummy
, &dummy
);
911 for (f
= t
->u
.s
.fields
; f
; f
= f
->next
)
916 process_gc_options (f
->opt
, level
, &maybe_undef
, &pass_param
,
919 if (length
&& f
->type
->kind
== TYPE_POINTER
)
920 set_gc_used_type (f
->type
->u
.p
, GC_USED
, NULL
);
921 else if (maybe_undef
&& f
->type
->kind
== TYPE_POINTER
)
922 set_gc_used_type (f
->type
->u
.p
, GC_MAYBE_POINTED_TO
, NULL
);
923 else if (pass_param
&& f
->type
->kind
== TYPE_POINTER
&& param
)
924 set_gc_used_type (find_param_structure (f
->type
->u
.p
, param
),
925 GC_POINTED_TO
, NULL
);
927 set_gc_used_type (f
->type
, GC_USED
, pass_param
? param
: NULL
);
933 set_gc_used_type (t
->u
.p
, GC_POINTED_TO
, NULL
);
937 set_gc_used_type (t
->u
.a
.p
, GC_USED
, param
);
940 case TYPE_LANG_STRUCT
:
941 for (t
= t
->u
.s
.lang_struct
; t
; t
= t
->next
)
942 set_gc_used_type (t
, level
, param
);
945 case TYPE_PARAM_STRUCT
:
948 for (i
= 0; i
< NUM_PARAM
; i
++)
949 if (t
->u
.param_struct
.param
[i
] != 0)
950 set_gc_used_type (t
->u
.param_struct
.param
[i
], GC_USED
, NULL
);
952 if (t
->u
.param_struct
.stru
->gc_used
== GC_POINTED_TO
)
953 level
= GC_POINTED_TO
;
956 t
->u
.param_struct
.stru
->gc_used
= GC_UNUSED
;
957 set_gc_used_type (t
->u
.param_struct
.stru
, level
,
958 t
->u
.param_struct
.param
);
966 /* Set the gc_used fields of all the types pointed to by VARIABLES. */
969 set_gc_used (pair_p variables
)
972 for (p
= variables
; p
; p
= p
->next
)
973 set_gc_used_type (p
->type
, GC_USED
, NULL
);
976 /* File mapping routines. For each input file, there is one output .c file
977 (but some output files have many input files), and there is one .h file
978 for the whole build. */
980 /* The list of output files. */
981 static outf_p output_files
;
983 /* The output header file that is included into pretty much every
987 /* Number of files specified in gtfiles. */
988 #define NUM_GT_FILES (ARRAY_SIZE (all_files) - 1)
990 /* Number of files in the language files array. */
991 #define NUM_LANG_FILES (ARRAY_SIZE (lang_files) - 1)
993 /* Length of srcdir name. */
994 static int srcdir_len
= 0;
996 #define NUM_BASE_FILES (ARRAY_SIZE (lang_dir_names) - 1)
997 outf_p base_files
[NUM_BASE_FILES
];
999 static outf_p
create_file (const char *, const char *);
1000 static const char * get_file_basename (const char *);
1002 /* Create and return an outf_p for a new file for NAME, to be called
1006 create_file (const char *name
, const char *oname
)
1008 static const char *const hdr
[] = {
1009 " Copyright (C) 2003 Free Software Foundation, Inc.\n",
1011 "This file is part of GCC.\n",
1013 "GCC is free software; you can redistribute it and/or modify it under\n",
1014 "the terms of the GNU General Public License as published by the Free\n",
1015 "Software Foundation; either version 2, or (at your option) any later\n",
1018 "GCC is distributed in the hope that it will be useful, but WITHOUT ANY\n",
1019 "WARRANTY; without even the implied warranty of MERCHANTABILITY or\n",
1020 "FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n",
1021 "for more details.\n",
1023 "You should have received a copy of the GNU General Public License\n",
1024 "along with GCC; see the file COPYING. If not, write to the Free\n",
1025 "Software Foundation, 59 Temple Place - Suite 330, Boston, MA\n",
1026 "02111-1307, USA. */\n",
1028 "/* This file is machine generated. Do not edit. */\n"
1033 f
= xcalloc (sizeof (*f
), 1);
1034 f
->next
= output_files
;
1038 oprintf (f
, "/* Type information for %s.\n", name
);
1039 for (i
= 0; i
< ARRAY_SIZE (hdr
); i
++)
1040 oprintf (f
, "%s", hdr
[i
]);
1044 /* Print, like fprintf, to O. */
1046 oprintf (outf_p o
, const char *format
, ...)
1052 va_start (ap
, format
);
1053 slength
= xvasprintf (&s
, format
, ap
);
1055 if (o
->bufused
+ slength
> o
->buflength
)
1057 size_t new_len
= o
->buflength
;
1062 } while (o
->bufused
+ slength
>= new_len
);
1063 o
->buf
= xrealloc (o
->buf
, new_len
);
1064 o
->buflength
= new_len
;
1066 memcpy (o
->buf
+ o
->bufused
, s
, slength
);
1067 o
->bufused
+= slength
;
1072 /* Open the global header file and the language-specific header files. */
1075 open_base_files (void)
1079 header_file
= create_file ("GCC", "gtype-desc.h");
1081 for (i
= 0; i
< NUM_BASE_FILES
; i
++)
1082 base_files
[i
] = create_file (lang_dir_names
[i
],
1083 xasprintf ("gtype-%s.h", lang_dir_names
[i
]));
1085 /* gtype-desc.c is a little special, so we create it here. */
1087 /* The order of files here matters very much. */
1088 static const char *const ifiles
[] = {
1089 "config.h", "system.h", "coretypes.h", "tm.h", "varray.h",
1090 "hashtab.h", "splay-tree.h", "bitmap.h", "tree.h", "rtl.h",
1091 "function.h", "insn-config.h", "expr.h", "hard-reg-set.h",
1092 "basic-block.h", "cselib.h", "insn-addr.h", "ssa.h", "optabs.h",
1093 "libfuncs.h", "debug.h", "ggc.h",
1096 const char *const *ifp
;
1097 outf_p gtype_desc_c
;
1099 gtype_desc_c
= create_file ("GCC", "gtype-desc.c");
1100 for (ifp
= ifiles
; *ifp
; ifp
++)
1101 oprintf (gtype_desc_c
, "#include \"%s\"\n", *ifp
);
1105 /* Determine the pathname to F relative to $(srcdir). */
1108 get_file_basename (const char *f
)
1110 const char *basename
;
1113 basename
= strrchr (f
, '/');
1120 for (i
= 1; i
< NUM_BASE_FILES
; i
++)
1126 s1
= basename
- strlen (lang_dir_names
[i
]) - 1;
1127 s2
= lang_dir_names
[i
];
1130 if (l1
>= l2
&& !memcmp (s1
, s2
, l2
))
1133 if ((basename
- f
- 1) != srcdir_len
)
1134 abort (); /* Match is wrong - should be preceded by $srcdir. */
1142 /* Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff
1143 INPUT_FILE is used by <lang>.
1145 This function should be written to assume that a file _is_ used
1146 if the situation is unclear. If it wrongly assumes a file _is_ used,
1147 a linker error will result. If it wrongly assumes a file _is not_ used,
1148 some GC roots may be missed, which is a much harder-to-debug problem. */
1151 get_base_file_bitmap (const char *input_file
)
1153 const char *basename
= get_file_basename (input_file
);
1154 const char *slashpos
= strchr (basename
, '/');
1162 for (i
= 1; i
< NUM_BASE_FILES
; i
++)
1163 if ((size_t)(slashpos
- basename
) == strlen (lang_dir_names
[i
])
1164 && memcmp (basename
, lang_dir_names
[i
], strlen (lang_dir_names
[i
])) == 0)
1166 /* It's in a language directory, set that language. */
1171 abort (); /* Should have found the language. */
1174 /* If it's in any config-lang.in, then set for the languages
1179 for (j
= 0; j
< NUM_LANG_FILES
; j
++)
1181 if (!strcmp(input_file
, lang_files
[j
]))
1183 for (k
= 0; k
< NUM_BASE_FILES
; k
++)
1185 if (!strcmp(lang_dir_names
[k
], langs_for_lang_files
[j
]))
1191 /* Otherwise, set all languages. */
1193 bitmap
= (1 << NUM_BASE_FILES
) - 1;
1198 /* An output file, suitable for definitions, that can see declarations
1199 made in INPUT_FILE and is linked into every language that uses
1203 get_output_file_with_visibility (const char *input_file
)
1207 const char *basename
;
1208 const char *for_name
;
1209 const char *output_name
;
1211 /* This can happen when we need a file with visibility on a
1212 structure that we've never seen. We have to just hope that it's
1213 globally visible. */
1214 if (input_file
== NULL
)
1215 input_file
= "system.h";
1217 /* Determine the output file name. */
1218 basename
= get_file_basename (input_file
);
1220 len
= strlen (basename
);
1221 if ((len
> 2 && memcmp (basename
+len
-2, ".c", 2) == 0)
1222 || (len
> 2 && memcmp (basename
+len
-2, ".y", 2) == 0)
1223 || (len
> 3 && memcmp (basename
+len
-3, ".in", 3) == 0))
1227 output_name
= s
= xasprintf ("gt-%s", basename
);
1228 for (; *s
!= '.'; s
++)
1229 if (! ISALNUM (*s
) && *s
!= '-')
1231 memcpy (s
, ".h", sizeof (".h"));
1232 for_name
= basename
;
1234 else if (strcmp (basename
, "c-common.h") == 0)
1235 output_name
= "gt-c-common.h", for_name
= "c-common.c";
1236 else if (strcmp (basename
, "c-tree.h") == 0)
1237 output_name
= "gt-c-decl.h", for_name
= "c-decl.c";
1242 for (i
= 0; i
< NUM_BASE_FILES
; i
++)
1243 if (memcmp (basename
, lang_dir_names
[i
], strlen (lang_dir_names
[i
])) == 0
1244 && basename
[strlen(lang_dir_names
[i
])] == '/')
1245 return base_files
[i
];
1247 output_name
= "gtype-desc.c";
1251 /* Look through to see if we've ever seen this output filename before. */
1252 for (r
= output_files
; r
; r
= r
->next
)
1253 if (strcmp (r
->name
, output_name
) == 0)
1256 /* If not, create it. */
1257 r
= create_file (for_name
, output_name
);
1262 /* The name of an output file, suitable for definitions, that can see
1263 declarations made in INPUT_FILE and is linked into every language
1264 that uses INPUT_FILE. */
1267 get_output_file_name (const char *input_file
)
1269 return get_output_file_with_visibility (input_file
)->name
;
1272 /* Copy the output to its final destination,
1273 but don't unnecessarily change modification times. */
1275 static void close_output_files (void);
1278 close_output_files (void)
1282 for (of
= output_files
; of
; of
= of
->next
)
1286 newfile
= fopen (of
->name
, "r");
1287 if (newfile
!= NULL
)
1292 for (i
= 0; i
< of
->bufused
; i
++)
1295 ch
= fgetc (newfile
);
1296 if (ch
== EOF
|| ch
!= (unsigned char) of
->buf
[i
])
1299 no_write_p
= i
== of
->bufused
&& fgetc (newfile
) == EOF
;
1306 newfile
= fopen (of
->name
, "w");
1307 if (newfile
== NULL
)
1309 perror ("opening output file");
1312 if (fwrite (of
->buf
, 1, of
->bufused
, newfile
) != of
->bufused
)
1314 perror ("writing output file");
1317 if (fclose (newfile
) != 0)
1319 perror ("closing output file");
1332 struct walk_type_data
;
1334 /* For scalars and strings, given the item in 'val'.
1335 For structures, given a pointer to the item in 'val'.
1336 For misc. pointers, given the item in 'val'.
1338 typedef void (*process_field_fn
)
1339 (type_p f
, const struct walk_type_data
*p
);
1340 typedef void (*func_name_fn
)
1341 (type_p s
, const struct walk_type_data
*p
);
1343 /* Parameters for write_types. */
1345 struct write_types_data
1348 const char *param_prefix
;
1349 const char *subfield_marker_routine
;
1350 const char *marker_routine
;
1351 const char *reorder_note_routine
;
1352 const char *comment
;
1355 static void output_escaped_param (struct walk_type_data
*d
,
1356 const char *, const char *);
1357 static void output_mangled_typename (outf_p
, type_p
);
1358 static void walk_type (type_p t
, struct walk_type_data
*d
);
1359 static void write_func_for_structure
1360 (type_p orig_s
, type_p s
, type_p
* param
,
1361 const struct write_types_data
*wtd
);
1362 static void write_types_process_field
1363 (type_p f
, const struct walk_type_data
*d
);
1364 static void write_types (type_p structures
,
1365 type_p param_structs
,
1366 const struct write_types_data
*wtd
);
1367 static void write_types_local_process_field
1368 (type_p f
, const struct walk_type_data
*d
);
1369 static void write_local_func_for_structure
1370 (type_p orig_s
, type_p s
, type_p
* param
);
1371 static void write_local (type_p structures
,
1372 type_p param_structs
);
1373 static void write_enum_defn (type_p structures
, type_p param_structs
);
1374 static int contains_scalar_p (type_p t
);
1375 static void put_mangled_filename (outf_p
, const char *);
1376 static void finish_root_table (struct flist
*flp
, const char *pfx
,
1377 const char *tname
, const char *lastname
,
1379 static void write_root (outf_p
, pair_p
, type_p
, const char *, int,
1380 struct fileloc
*, const char *);
1381 static void write_array (outf_p f
, pair_p v
,
1382 const struct write_types_data
*wtd
);
1383 static void write_roots (pair_p
);
1385 /* Parameters for walk_type. */
1387 struct walk_type_data
1389 process_field_fn process_field
;
1394 const char *prev_val
[4];
1397 struct fileloc
*line
;
1402 const char *reorder_fn
;
1406 /* Print a mangled name representing T to OF. */
1409 output_mangled_typename (outf_p of
, type_p t
)
1413 else switch (t
->kind
)
1417 output_mangled_typename (of
, t
->u
.p
);
1427 case TYPE_LANG_STRUCT
:
1428 oprintf (of
, "%lu%s", (unsigned long) strlen (t
->u
.s
.tag
), t
->u
.s
.tag
);
1430 case TYPE_PARAM_STRUCT
:
1433 for (i
= 0; i
< NUM_PARAM
; i
++)
1434 if (t
->u
.param_struct
.param
[i
] != NULL
)
1435 output_mangled_typename (of
, t
->u
.param_struct
.param
[i
]);
1436 output_mangled_typename (of
, t
->u
.param_struct
.stru
);
1444 /* Print PARAM to D->OF processing escapes. D->VAL references the
1445 current object, D->PREV_VAL the object containing the current
1446 object, ONAME is the name of the option and D->LINE is used to
1447 print error messages. */
1450 output_escaped_param (struct walk_type_data
*d
, const char *param
,
1455 for (p
= param
; *p
; p
++)
1457 oprintf (d
->of
, "%c", *p
);
1461 oprintf (d
->of
, "(%s)", d
->prev_val
[2]);
1464 oprintf (d
->of
, "(%s)", d
->prev_val
[0]);
1467 oprintf (d
->of
, "(%s)", d
->prev_val
[1]);
1471 const char *pp
= d
->val
+ strlen (d
->val
);
1472 while (pp
[-1] == ']')
1475 oprintf (d
->of
, "%s", pp
);
1479 error_at_line (d
->line
, "`%s' option contains bad escape %c%c",
1484 /* Call D->PROCESS_FIELD for every field (or subfield) of D->VAL,
1485 which is of type T. Write code to D->OF to constrain execution (at
1486 the point that D->PROCESS_FIELD is called) to the appropriate
1487 cases. D->PREV_VAL lists the objects containing the current object,
1488 D->OPT is a list of options to apply, D->INDENT is the current
1489 indentation level, D->LINE is used to print error messages,
1490 D->BITMAP indicates which languages to print the structure for, and
1491 D->PARAM is the current parameter (from an enclosing param_is
1495 walk_type (type_p t
, struct walk_type_data
*d
)
1497 const char *length
= NULL
;
1498 const char *desc
= NULL
;
1499 int maybe_undef_p
= 0;
1500 int use_param_num
= -1;
1501 int use_params_p
= 0;
1504 d
->needs_cast_p
= 0;
1505 for (oo
= d
->opt
; oo
; oo
= oo
->next
)
1506 if (strcmp (oo
->name
, "length") == 0)
1507 length
= (const char *)oo
->info
;
1508 else if (strcmp (oo
->name
, "maybe_undef") == 0)
1510 else if (strncmp (oo
->name
, "use_param", 9) == 0
1511 && (oo
->name
[9] == '\0' || ISDIGIT (oo
->name
[9])))
1512 use_param_num
= oo
->name
[9] == '\0' ? 0 : oo
->name
[9] - '0';
1513 else if (strcmp (oo
->name
, "use_params") == 0)
1515 else if (strcmp (oo
->name
, "desc") == 0)
1516 desc
= (const char *)oo
->info
;
1517 else if (strcmp (oo
->name
, "dot") == 0)
1519 else if (strcmp (oo
->name
, "tag") == 0)
1521 else if (strcmp (oo
->name
, "special") == 0)
1523 else if (strcmp (oo
->name
, "skip") == 0)
1525 else if (strcmp (oo
->name
, "default") == 0)
1527 else if (strcmp (oo
->name
, "descbits") == 0)
1529 else if (strcmp (oo
->name
, "param_is") == 0)
1531 else if (strncmp (oo
->name
, "param", 5) == 0
1532 && ISDIGIT (oo
->name
[5])
1533 && strcmp (oo
->name
+ 6, "_is") == 0)
1535 else if (strcmp (oo
->name
, "chain_next") == 0)
1537 else if (strcmp (oo
->name
, "chain_prev") == 0)
1539 else if (strcmp (oo
->name
, "reorder") == 0)
1542 error_at_line (d
->line
, "unknown option `%s'\n", oo
->name
);
1549 int pointer_p
= t
->kind
== TYPE_POINTER
;
1553 if (! UNION_OR_STRUCT_P (t
))
1554 error_at_line (d
->line
, "`use_params' option on unimplemented type");
1556 t
= find_param_structure (t
, d
->param
);
1558 t
= create_pointer (t
);
1561 if (use_param_num
!= -1)
1563 if (d
->param
!= NULL
&& d
->param
[use_param_num
] != NULL
)
1565 type_p nt
= d
->param
[use_param_num
];
1567 if (t
->kind
== TYPE_ARRAY
)
1568 nt
= create_array (nt
, t
->u
.a
.len
);
1569 else if (length
!= NULL
&& t
->kind
== TYPE_POINTER
)
1570 nt
= create_pointer (nt
);
1571 d
->needs_cast_p
= (t
->kind
!= TYPE_POINTER
1572 && (nt
->kind
== TYPE_POINTER
1573 || nt
->kind
== TYPE_STRING
));
1577 error_at_line (d
->line
, "no parameter defined for `%s'",
1582 && (t
->kind
!= TYPE_POINTER
|| ! UNION_OR_STRUCT_P (t
->u
.p
)))
1584 error_at_line (d
->line
,
1585 "field `%s' has invalid option `maybe_undef_p'\n",
1594 d
->process_field (t
, d
);
1600 && t
->u
.p
->u
.s
.line
.file
== NULL
)
1602 oprintf (d
->of
, "%*sif (%s) abort();\n", d
->indent
, "", d
->val
);
1608 if (! UNION_OR_STRUCT_P (t
->u
.p
)
1609 && t
->u
.p
->kind
!= TYPE_PARAM_STRUCT
)
1611 error_at_line (d
->line
,
1612 "field `%s' is pointer to unimplemented type",
1617 d
->process_field (t
->u
.p
, d
);
1621 int loopcounter
= d
->counter
++;
1622 const char *oldval
= d
->val
;
1623 const char *oldprevval3
= d
->prev_val
[3];
1626 oprintf (d
->of
, "%*sif (%s != NULL) {\n", d
->indent
, "", d
->val
);
1628 oprintf (d
->of
, "%*ssize_t i%d;\n", d
->indent
, "", loopcounter
);
1629 d
->process_field(t
, d
);
1630 oprintf (d
->of
, "%*sfor (i%d = 0; i%d < (size_t)(", d
->indent
, "",
1631 loopcounter
, loopcounter
);
1632 output_escaped_param (d
, length
, "length");
1633 oprintf (d
->of
, "); i%d++) {\n", loopcounter
);
1635 d
->val
= newval
= xasprintf ("%s[i%d]", oldval
, loopcounter
);
1637 d
->prev_val
[3] = oldval
;
1638 walk_type (t
->u
.p
, d
);
1641 d
->prev_val
[3] = oldprevval3
;
1644 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
1646 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
1653 int loopcounter
= d
->counter
++;
1654 const char *oldval
= d
->val
;
1657 /* If it's an array of scalars, we optimize by not generating
1659 if (t
->u
.a
.p
->kind
== TYPE_SCALAR
)
1662 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
1664 oprintf (d
->of
, "%*ssize_t i%d;\n", d
->indent
, "", loopcounter
);
1665 oprintf (d
->of
, "%*sfor (i%d = 0; i%d < (size_t)(", d
->indent
, "",
1666 loopcounter
, loopcounter
);
1668 output_escaped_param (d
, length
, "length");
1670 oprintf (d
->of
, "%s", t
->u
.a
.len
);
1671 oprintf (d
->of
, "); i%d++) {\n", loopcounter
);
1673 d
->val
= newval
= xasprintf ("%s[i%d]", oldval
, loopcounter
);
1675 walk_type (t
->u
.a
.p
, d
);
1680 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
1682 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
1690 const char *oldval
= d
->val
;
1691 const char *oldprevval1
= d
->prev_val
[1];
1692 const char *oldprevval2
= d
->prev_val
[2];
1693 const int union_p
= t
->kind
== TYPE_UNION
;
1694 int seen_default_p
= 0;
1697 if (! t
->u
.s
.line
.file
)
1698 error_at_line (d
->line
, "incomplete structure `%s'", t
->u
.s
.tag
);
1700 if ((d
->bitmap
& t
->u
.s
.bitmap
) != d
->bitmap
)
1702 error_at_line (d
->line
,
1703 "structure `%s' defined for mismatching languages",
1705 error_at_line (&t
->u
.s
.line
, "one structure defined here");
1708 /* Some things may also be defined in the structure's options. */
1709 for (o
= t
->u
.s
.opt
; o
; o
= o
->next
)
1710 if (! desc
&& strcmp (o
->name
, "desc") == 0)
1711 desc
= (const char *)o
->info
;
1713 d
->prev_val
[2] = oldval
;
1714 d
->prev_val
[1] = oldprevval2
;
1719 error_at_line (d
->line
, "missing `desc' option for union `%s'",
1723 oprintf (d
->of
, "%*sswitch (", d
->indent
, "");
1724 output_escaped_param (d
, desc
, "desc");
1725 oprintf (d
->of
, ")\n");
1727 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
1729 for (f
= t
->u
.s
.fields
; f
; f
= f
->next
)
1732 const char *dot
= ".";
1733 const char *tagid
= NULL
;
1736 int use_param_p
= 0;
1739 d
->reorder_fn
= NULL
;
1740 for (oo
= f
->opt
; oo
; oo
= oo
->next
)
1741 if (strcmp (oo
->name
, "dot") == 0)
1742 dot
= (const char *)oo
->info
;
1743 else if (strcmp (oo
->name
, "tag") == 0)
1744 tagid
= (const char *)oo
->info
;
1745 else if (strcmp (oo
->name
, "skip") == 0)
1747 else if (strcmp (oo
->name
, "default") == 0)
1749 else if (strcmp (oo
->name
, "reorder") == 0)
1750 d
->reorder_fn
= (const char *)oo
->info
;
1751 else if (strncmp (oo
->name
, "use_param", 9) == 0
1752 && (oo
->name
[9] == '\0' || ISDIGIT (oo
->name
[9])))
1758 if (union_p
&& tagid
)
1760 oprintf (d
->of
, "%*scase %s:\n", d
->indent
, "", tagid
);
1763 else if (union_p
&& default_p
)
1765 oprintf (d
->of
, "%*sdefault:\n", d
->indent
, "");
1769 else if (! union_p
&& (default_p
|| tagid
))
1770 error_at_line (d
->line
,
1771 "can't use `%s' outside a union on field `%s'",
1772 default_p
? "default" : "tag", f
->name
);
1773 else if (union_p
&& ! (default_p
|| tagid
)
1774 && f
->type
->kind
== TYPE_SCALAR
)
1777 "%s:%d: warning: field `%s' is missing `tag' or `default' option\n",
1778 d
->line
->file
, d
->line
->line
, f
->name
);
1781 else if (union_p
&& ! (default_p
|| tagid
))
1782 error_at_line (d
->line
,
1783 "field `%s' is missing `tag' or `default' option",
1787 d
->val
= newval
= xasprintf ("%s%s%s", oldval
, dot
, f
->name
);
1790 if (union_p
&& use_param_p
&& d
->param
== NULL
)
1791 oprintf (d
->of
, "%*sabort();\n", d
->indent
, "");
1793 walk_type (f
->type
, d
);
1799 oprintf (d
->of
, "%*sbreak;\n", d
->indent
, "");
1803 d
->reorder_fn
= NULL
;
1806 d
->prev_val
[1] = oldprevval1
;
1807 d
->prev_val
[2] = oldprevval2
;
1809 if (union_p
&& ! seen_default_p
)
1811 oprintf (d
->of
, "%*sdefault:\n", d
->indent
, "");
1812 oprintf (d
->of
, "%*s break;\n", d
->indent
, "");
1816 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
1822 case TYPE_LANG_STRUCT
:
1825 for (nt
= t
->u
.s
.lang_struct
; nt
; nt
= nt
->next
)
1826 if ((d
->bitmap
& nt
->u
.s
.bitmap
) == d
->bitmap
)
1829 error_at_line (d
->line
, "structure `%s' differs between languages",
1836 case TYPE_PARAM_STRUCT
:
1838 type_p
*oldparam
= d
->param
;
1840 d
->param
= t
->u
.param_struct
.param
;
1841 walk_type (t
->u
.param_struct
.stru
, d
);
1842 d
->param
= oldparam
;
1851 /* process_field routine for marking routines. */
1854 write_types_process_field (type_p f
, const struct walk_type_data
*d
)
1856 const struct write_types_data
*wtd
;
1857 const char *cast
= d
->needs_cast_p
? "(void *)" : "";
1858 wtd
= (const struct write_types_data
*) d
->cookie
;
1863 oprintf (d
->of
, "%*s%s (%s%s", d
->indent
, "",
1864 wtd
->subfield_marker_routine
, cast
, d
->val
);
1865 if (wtd
->param_prefix
)
1867 oprintf (d
->of
, ", %s", d
->prev_val
[3]);
1870 oprintf (d
->of
, ", gt_%s_", wtd
->param_prefix
);
1871 output_mangled_typename (d
->of
, d
->orig_s
);
1874 oprintf (d
->of
, ", gt_%sa_%s", wtd
->param_prefix
, d
->prev_val
[0]);
1876 oprintf (d
->of
, ");\n");
1877 if (d
->reorder_fn
&& wtd
->reorder_note_routine
)
1878 oprintf (d
->of
, "%*s%s (%s%s, %s, %s);\n", d
->indent
, "",
1879 wtd
->reorder_note_routine
, cast
, d
->val
,
1880 d
->prev_val
[3], d
->reorder_fn
);
1884 if (wtd
->param_prefix
== NULL
)
1889 case TYPE_LANG_STRUCT
:
1890 case TYPE_PARAM_STRUCT
:
1891 oprintf (d
->of
, "%*sgt_%s_", d
->indent
, "", wtd
->prefix
);
1892 output_mangled_typename (d
->of
, f
);
1893 oprintf (d
->of
, " (%s%s);\n", cast
, d
->val
);
1894 if (d
->reorder_fn
&& wtd
->reorder_note_routine
)
1895 oprintf (d
->of
, "%*s%s (%s%s, %s%s, %s);\n", d
->indent
, "",
1896 wtd
->reorder_note_routine
, cast
, d
->val
, cast
, d
->val
,
1908 /* For S, a structure that's part of ORIG_S, and using parameters
1909 PARAM, write out a routine that:
1910 - Takes a parameter, a void * but actually of type *S
1911 - If SEEN_ROUTINE returns nonzero, calls write_types_process_field on each
1912 field of S or its substructures and (in some cases) things
1913 that are pointed to by S.
1917 write_func_for_structure (type_p orig_s
, type_p s
, type_p
*param
,
1918 const struct write_types_data
*wtd
)
1920 const char *fn
= s
->u
.s
.line
.file
;
1922 const char *chain_next
= NULL
;
1923 const char *chain_prev
= NULL
;
1925 struct walk_type_data d
;
1927 /* This is a hack, and not the good kind either. */
1928 for (i
= NUM_PARAM
- 1; i
>= 0; i
--)
1929 if (param
&& param
[i
] && param
[i
]->kind
== TYPE_POINTER
1930 && UNION_OR_STRUCT_P (param
[i
]->u
.p
))
1931 fn
= param
[i
]->u
.p
->u
.s
.line
.file
;
1933 memset (&d
, 0, sizeof (d
));
1934 d
.of
= get_output_file_with_visibility (fn
);
1936 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
1937 if (strcmp (opt
->name
, "chain_next") == 0)
1938 chain_next
= (const char *) opt
->info
;
1939 else if (strcmp (opt
->name
, "chain_prev") == 0)
1940 chain_prev
= (const char *) opt
->info
;
1942 if (chain_prev
!= NULL
&& chain_next
== NULL
)
1943 error_at_line (&s
->u
.s
.line
, "chain_prev without chain_next");
1945 d
.process_field
= write_types_process_field
;
1949 d
.line
= &s
->u
.s
.line
;
1950 d
.bitmap
= s
->u
.s
.bitmap
;
1952 d
.prev_val
[0] = "*x";
1953 d
.prev_val
[1] = "not valid postage"; /* guarantee an error */
1954 d
.prev_val
[3] = "x";
1957 oprintf (d
.of
, "\n");
1958 oprintf (d
.of
, "void\n");
1960 oprintf (d
.of
, "gt_%sx_%s", wtd
->prefix
, orig_s
->u
.s
.tag
);
1963 oprintf (d
.of
, "gt_%s_", wtd
->prefix
);
1964 output_mangled_typename (d
.of
, orig_s
);
1966 oprintf (d
.of
, " (x_p)\n");
1967 oprintf (d
.of
, " void *x_p;\n");
1968 oprintf (d
.of
, "{\n");
1969 oprintf (d
.of
, " %s %s * %sx = (%s %s *)x_p;\n",
1970 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
,
1971 chain_next
== NULL
? "const " : "",
1972 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
1973 if (chain_next
!= NULL
)
1974 oprintf (d
.of
, " %s %s * xlimit = x;\n",
1975 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
1976 if (chain_next
== NULL
)
1978 oprintf (d
.of
, " if (%s (x", wtd
->marker_routine
);
1979 if (wtd
->param_prefix
)
1981 oprintf (d
.of
, ", x, gt_%s_", wtd
->param_prefix
);
1982 output_mangled_typename (d
.of
, orig_s
);
1984 oprintf (d
.of
, "))\n");
1988 oprintf (d
.of
, " while (%s (xlimit", wtd
->marker_routine
);
1989 if (wtd
->param_prefix
)
1991 oprintf (d
.of
, ", xlimit, gt_%s_", wtd
->param_prefix
);
1992 output_mangled_typename (d
.of
, orig_s
);
1994 oprintf (d
.of
, "))\n");
1995 oprintf (d
.of
, " xlimit = (");
1996 d
.prev_val
[2] = "*xlimit";
1997 output_escaped_param (&d
, chain_next
, "chain_next");
1998 oprintf (d
.of
, ");\n");
1999 if (chain_prev
!= NULL
)
2001 oprintf (d
.of
, " if (x != xlimit)\n");
2002 oprintf (d
.of
, " for (;;)\n");
2003 oprintf (d
.of
, " {\n");
2004 oprintf (d
.of
, " %s %s * const xprev = (",
2005 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
2007 d
.prev_val
[2] = "*x";
2008 output_escaped_param (&d
, chain_prev
, "chain_prev");
2009 oprintf (d
.of
, ");\n");
2010 oprintf (d
.of
, " if (xprev == NULL) break;\n");
2011 oprintf (d
.of
, " x = xprev;\n");
2012 oprintf (d
.of
, " (void) %s (xprev",
2013 wtd
->marker_routine
);
2014 if (wtd
->param_prefix
)
2016 oprintf (d
.of
, ", xprev, gt_%s_", wtd
->param_prefix
);
2017 output_mangled_typename (d
.of
, orig_s
);
2019 oprintf (d
.of
, ");\n");
2020 oprintf (d
.of
, " }\n");
2022 oprintf (d
.of
, " while (x != xlimit)\n");
2024 oprintf (d
.of
, " {\n");
2026 d
.prev_val
[2] = "*x";
2030 if (chain_next
!= NULL
)
2032 oprintf (d
.of
, " x = (");
2033 output_escaped_param (&d
, chain_next
, "chain_next");
2034 oprintf (d
.of
, ");\n");
2037 oprintf (d
.of
, " }\n");
2038 oprintf (d
.of
, "}\n");
2041 /* Write out marker routines for STRUCTURES and PARAM_STRUCTS. */
2044 write_types (type_p structures
, type_p param_structs
,
2045 const struct write_types_data
*wtd
)
2049 oprintf (header_file
, "\n/* %s*/\n", wtd
->comment
);
2050 for (s
= structures
; s
; s
= s
->next
)
2051 if (s
->gc_used
== GC_POINTED_TO
2052 || s
->gc_used
== GC_MAYBE_POINTED_TO
)
2056 if (s
->gc_used
== GC_MAYBE_POINTED_TO
2057 && s
->u
.s
.line
.file
== NULL
)
2060 oprintf (header_file
, "#define gt_%s_", wtd
->prefix
);
2061 output_mangled_typename (header_file
, s
);
2062 oprintf (header_file
, "(X) do { \\\n");
2063 oprintf (header_file
,
2064 " if (X != NULL) gt_%sx_%s (X);\\\n", wtd
->prefix
,
2066 oprintf (header_file
,
2069 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
2070 if (strcmp (opt
->name
, "ptr_alias") == 0)
2072 type_p t
= (type_p
) opt
->info
;
2073 if (t
->kind
== TYPE_STRUCT
2074 || t
->kind
== TYPE_UNION
2075 || t
->kind
== TYPE_LANG_STRUCT
)
2076 oprintf (header_file
,
2077 "#define gt_%sx_%s gt_%sx_%s\n",
2078 wtd
->prefix
, s
->u
.s
.tag
, wtd
->prefix
, t
->u
.s
.tag
);
2080 error_at_line (&s
->u
.s
.line
,
2081 "structure alias is not a structure");
2087 /* Declare the marker procedure only once. */
2088 oprintf (header_file
,
2089 "extern void gt_%sx_%s (void *);\n",
2090 wtd
->prefix
, s
->u
.s
.tag
);
2092 if (s
->u
.s
.line
.file
== NULL
)
2094 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
2099 if (s
->kind
== TYPE_LANG_STRUCT
)
2102 for (ss
= s
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2103 write_func_for_structure (s
, ss
, NULL
, wtd
);
2106 write_func_for_structure (s
, s
, NULL
, wtd
);
2109 for (s
= param_structs
; s
; s
= s
->next
)
2110 if (s
->gc_used
== GC_POINTED_TO
)
2112 type_p
* param
= s
->u
.param_struct
.param
;
2113 type_p stru
= s
->u
.param_struct
.stru
;
2115 /* Declare the marker procedure. */
2116 oprintf (header_file
, "extern void gt_%s_", wtd
->prefix
);
2117 output_mangled_typename (header_file
, s
);
2118 oprintf (header_file
, " (void *);\n");
2120 if (stru
->u
.s
.line
.file
== NULL
)
2122 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
2127 if (stru
->kind
== TYPE_LANG_STRUCT
)
2130 for (ss
= stru
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2131 write_func_for_structure (s
, ss
, param
, wtd
);
2134 write_func_for_structure (s
, stru
, param
, wtd
);
2138 static const struct write_types_data ggc_wtd
=
2140 "ggc_m", NULL
, "ggc_mark", "ggc_test_and_set_mark", NULL
,
2141 "GC marker procedures. "
2144 static const struct write_types_data pch_wtd
=
2146 "pch_n", "pch_p", "gt_pch_note_object", "gt_pch_note_object",
2147 "gt_pch_note_reorder",
2148 "PCH type-walking procedures. "
2151 /* Write out the local pointer-walking routines. */
2153 /* process_field routine for local pointer-walking. */
2156 write_types_local_process_field (type_p f
, const struct walk_type_data
*d
)
2163 case TYPE_LANG_STRUCT
:
2164 case TYPE_PARAM_STRUCT
:
2166 oprintf (d
->of
, "%*sif ((void *)(%s) == this_obj)\n", d
->indent
, "",
2168 oprintf (d
->of
, "%*s op (&(%s), cookie);\n", d
->indent
, "", d
->val
);
2179 /* For S, a structure that's part of ORIG_S, and using parameters
2180 PARAM, write out a routine that:
2181 - Is of type gt_note_pointers
2182 - If calls PROCESS_FIELD on each field of S or its substructures.
2186 write_local_func_for_structure (type_p orig_s
, type_p s
, type_p
*param
)
2188 const char *fn
= s
->u
.s
.line
.file
;
2190 struct walk_type_data d
;
2192 /* This is a hack, and not the good kind either. */
2193 for (i
= NUM_PARAM
- 1; i
>= 0; i
--)
2194 if (param
&& param
[i
] && param
[i
]->kind
== TYPE_POINTER
2195 && UNION_OR_STRUCT_P (param
[i
]->u
.p
))
2196 fn
= param
[i
]->u
.p
->u
.s
.line
.file
;
2198 memset (&d
, 0, sizeof (d
));
2199 d
.of
= get_output_file_with_visibility (fn
);
2201 d
.process_field
= write_types_local_process_field
;
2203 d
.line
= &s
->u
.s
.line
;
2204 d
.bitmap
= s
->u
.s
.bitmap
;
2206 d
.prev_val
[0] = d
.prev_val
[2] = "*x";
2207 d
.prev_val
[1] = "not valid postage"; /* guarantee an error */
2208 d
.prev_val
[3] = "x";
2211 oprintf (d
.of
, "\n");
2212 oprintf (d
.of
, "void\n");
2213 oprintf (d
.of
, "gt_pch_p_");
2214 output_mangled_typename (d
.of
, orig_s
);
2215 oprintf (d
.of
, " (this_obj, x_p, op, cookie)\n");
2216 oprintf (d
.of
, " void *this_obj ATTRIBUTE_UNUSED;\n");
2217 oprintf (d
.of
, " void *x_p;\n");
2218 oprintf (d
.of
, " gt_pointer_operator op ATTRIBUTE_UNUSED;\n");
2219 oprintf (d
.of
, " void *cookie ATTRIBUTE_UNUSED;\n");
2220 oprintf (d
.of
, "{\n");
2221 oprintf (d
.of
, " %s %s * const x ATTRIBUTE_UNUSED = (%s %s *)x_p;\n",
2222 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
,
2223 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
2226 oprintf (d
.of
, "}\n");
2229 /* Write out local marker routines for STRUCTURES and PARAM_STRUCTS. */
2232 write_local (type_p structures
, type_p param_structs
)
2236 oprintf (header_file
, "\n/* Local pointer-walking routines. */\n");
2237 for (s
= structures
; s
; s
= s
->next
)
2238 if (s
->gc_used
== GC_POINTED_TO
2239 || s
->gc_used
== GC_MAYBE_POINTED_TO
)
2243 if (s
->u
.s
.line
.file
== NULL
)
2246 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
2247 if (strcmp (opt
->name
, "ptr_alias") == 0)
2249 type_p t
= (type_p
) opt
->info
;
2250 if (t
->kind
== TYPE_STRUCT
2251 || t
->kind
== TYPE_UNION
2252 || t
->kind
== TYPE_LANG_STRUCT
)
2254 oprintf (header_file
, "#define gt_pch_p_");
2255 output_mangled_typename (header_file
, s
);
2256 oprintf (header_file
, " gt_pch_p_");
2257 output_mangled_typename (header_file
, t
);
2258 oprintf (header_file
, "\n");
2261 error_at_line (&s
->u
.s
.line
,
2262 "structure alias is not a structure");
2268 /* Declare the marker procedure only once. */
2269 oprintf (header_file
, "extern void gt_pch_p_");
2270 output_mangled_typename (header_file
, s
);
2271 oprintf (header_file
,
2272 "\n (void *, void *, gt_pointer_operator, void *);\n");
2274 if (s
->kind
== TYPE_LANG_STRUCT
)
2277 for (ss
= s
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2278 write_local_func_for_structure (s
, ss
, NULL
);
2281 write_local_func_for_structure (s
, s
, NULL
);
2284 for (s
= param_structs
; s
; s
= s
->next
)
2285 if (s
->gc_used
== GC_POINTED_TO
)
2287 type_p
* param
= s
->u
.param_struct
.param
;
2288 type_p stru
= s
->u
.param_struct
.stru
;
2290 /* Declare the marker procedure. */
2291 oprintf (header_file
, "extern void gt_pch_p_");
2292 output_mangled_typename (header_file
, s
);
2293 oprintf (header_file
,
2294 "\n (void *, void *, gt_pointer_operator, void *);\n");
2296 if (stru
->u
.s
.line
.file
== NULL
)
2298 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
2303 if (stru
->kind
== TYPE_LANG_STRUCT
)
2306 for (ss
= stru
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2307 write_local_func_for_structure (s
, ss
, param
);
2310 write_local_func_for_structure (s
, stru
, param
);
2314 /* Write out the 'enum' definition for gt_types_enum. */
2317 write_enum_defn (type_p structures
, type_p param_structs
)
2321 oprintf (header_file
, "\n/* Enumeration of types known. */\n");
2322 oprintf (header_file
, "enum gt_types_enum {\n");
2323 for (s
= structures
; s
; s
= s
->next
)
2324 if (s
->gc_used
== GC_POINTED_TO
2325 || s
->gc_used
== GC_MAYBE_POINTED_TO
)
2327 if (s
->gc_used
== GC_MAYBE_POINTED_TO
2328 && s
->u
.s
.line
.file
== NULL
)
2331 oprintf (header_file
, " gt_ggc_e_");
2332 output_mangled_typename (header_file
, s
);
2333 oprintf (header_file
, ", \n");
2335 for (s
= param_structs
; s
; s
= s
->next
)
2336 if (s
->gc_used
== GC_POINTED_TO
)
2338 oprintf (header_file
, " gt_e_");
2339 output_mangled_typename (header_file
, s
);
2340 oprintf (header_file
, ", \n");
2342 oprintf (header_file
, " gt_types_enum_last\n");
2343 oprintf (header_file
, "};\n");
2346 /* Might T contain any non-pointer elements? */
2349 contains_scalar_p (type_p t
)
2357 return contains_scalar_p (t
->u
.a
.p
);
2359 /* Could also check for structures that have no non-pointer
2360 fields, but there aren't enough of those to worry about. */
2365 /* Mangle FN and print it to F. */
2368 put_mangled_filename (outf_p f
, const char *fn
)
2370 const char *name
= get_output_file_name (fn
);
2371 for (; *name
!= 0; name
++)
2372 if (ISALNUM (*name
))
2373 oprintf (f
, "%c", *name
);
2375 oprintf (f
, "%c", '_');
2378 /* Finish off the currently-created root tables in FLP. PFX, TNAME,
2379 LASTNAME, and NAME are all strings to insert in various places in
2380 the resulting code. */
2383 finish_root_table (struct flist
*flp
, const char *pfx
, const char *lastname
,
2384 const char *tname
, const char *name
)
2388 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
2389 if (fli2
->started_p
)
2391 oprintf (fli2
->f
, " %s\n", lastname
);
2392 oprintf (fli2
->f
, "};\n\n");
2395 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
2396 if (fli2
->started_p
)
2398 lang_bitmap bitmap
= get_base_file_bitmap (fli2
->name
);
2401 for (fnum
= 0; bitmap
!= 0; fnum
++, bitmap
>>= 1)
2404 oprintf (base_files
[fnum
],
2405 "extern const struct %s gt_%s_",
2407 put_mangled_filename (base_files
[fnum
], fli2
->name
);
2408 oprintf (base_files
[fnum
], "[];\n");
2414 for (fnum
= 0; fnum
< NUM_BASE_FILES
; fnum
++)
2415 oprintf (base_files
[fnum
],
2416 "const struct %s * const %s[] = {\n",
2421 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
2422 if (fli2
->started_p
)
2424 lang_bitmap bitmap
= get_base_file_bitmap (fli2
->name
);
2427 fli2
->started_p
= 0;
2429 for (fnum
= 0; bitmap
!= 0; fnum
++, bitmap
>>= 1)
2432 oprintf (base_files
[fnum
], " gt_%s_", pfx
);
2433 put_mangled_filename (base_files
[fnum
], fli2
->name
);
2434 oprintf (base_files
[fnum
], ",\n");
2440 for (fnum
= 0; fnum
< NUM_BASE_FILES
; fnum
++)
2442 oprintf (base_files
[fnum
], " NULL\n");
2443 oprintf (base_files
[fnum
], "};\n");
2448 /* Write out to F the table entry and any marker routines needed to
2449 mark NAME as TYPE. The original variable is V, at LINE.
2450 HAS_LENGTH is nonzero iff V was a variable-length array. IF_MARKED
2451 is nonzero iff we are building the root table for hash table caches. */
2454 write_root (outf_p f
, pair_p v
, type_p type
, const char *name
, int has_length
,
2455 struct fileloc
*line
, const char *if_marked
)
2462 for (fld
= type
->u
.s
.fields
; fld
; fld
= fld
->next
)
2465 const char *desc
= NULL
;
2468 for (o
= fld
->opt
; o
; o
= o
->next
)
2469 if (strcmp (o
->name
, "skip") == 0)
2471 else if (strcmp (o
->name
, "desc") == 0)
2472 desc
= (const char *)o
->info
;
2474 error_at_line (line
,
2475 "field `%s' of global `%s' has unknown option `%s'",
2476 fld
->name
, name
, o
->name
);
2480 else if (desc
&& fld
->type
->kind
== TYPE_UNION
)
2482 pair_p validf
= NULL
;
2485 for (ufld
= fld
->type
->u
.s
.fields
; ufld
; ufld
= ufld
->next
)
2487 const char *tag
= NULL
;
2490 for (oo
= ufld
->opt
; oo
; oo
= oo
->next
)
2491 if (strcmp (oo
->name
, "tag") == 0)
2492 tag
= (const char *)oo
->info
;
2493 if (tag
== NULL
|| strcmp (tag
, desc
) != 0)
2496 error_at_line (line
,
2497 "both `%s.%s.%s' and `%s.%s.%s' have tag `%s'",
2498 name
, fld
->name
, validf
->name
,
2499 name
, fld
->name
, ufld
->name
,
2506 newname
= xasprintf ("%s.%s.%s",
2507 name
, fld
->name
, validf
->name
);
2508 write_root (f
, v
, validf
->type
, newname
, 0, line
,
2514 error_at_line (line
,
2515 "global `%s.%s' has `desc' option but is not union",
2520 newname
= xasprintf ("%s.%s", name
, fld
->name
);
2521 write_root (f
, v
, fld
->type
, newname
, 0, line
, if_marked
);
2531 newname
= xasprintf ("%s[0]", name
);
2532 write_root (f
, v
, type
->u
.a
.p
, newname
, has_length
, line
, if_marked
);
2541 oprintf (f
, " {\n");
2542 oprintf (f
, " &%s,\n", name
);
2545 for (ap
= v
->type
; ap
->kind
== TYPE_ARRAY
; ap
= ap
->u
.a
.p
)
2547 oprintf (f
, " * (%s)", ap
->u
.a
.len
);
2548 else if (ap
== v
->type
)
2549 oprintf (f
, " * ARRAY_SIZE (%s)", v
->name
);
2551 oprintf (f
, " sizeof (%s", v
->name
);
2552 for (ap
= v
->type
; ap
->kind
== TYPE_ARRAY
; ap
= ap
->u
.a
.p
)
2554 oprintf (f
, "),\n");
2558 if (! has_length
&& UNION_OR_STRUCT_P (tp
))
2560 oprintf (f
, " >_ggc_mx_%s,\n", tp
->u
.s
.tag
);
2561 oprintf (f
, " >_pch_nx_%s", tp
->u
.s
.tag
);
2563 else if (! has_length
&& tp
->kind
== TYPE_PARAM_STRUCT
)
2565 oprintf (f
, " >_ggc_m_");
2566 output_mangled_typename (f
, tp
);
2567 oprintf (f
, ",\n >_pch_n_");
2568 output_mangled_typename (f
, tp
);
2571 && (tp
->kind
== TYPE_POINTER
|| UNION_OR_STRUCT_P (tp
)))
2573 oprintf (f
, " >_ggc_ma_%s,\n", name
);
2574 oprintf (f
, " >_pch_na_%s", name
);
2578 error_at_line (line
,
2579 "global `%s' is pointer to unimplemented type",
2583 oprintf (f
, ",\n &%s", if_marked
);
2584 oprintf (f
, "\n },\n");
2590 oprintf (f
, " {\n");
2591 oprintf (f
, " &%s,\n", name
);
2592 oprintf (f
, " 1, \n");
2593 oprintf (f
, " sizeof (%s),\n", v
->name
);
2594 oprintf (f
, " >_ggc_m_S,\n");
2595 oprintf (f
, " (gt_pointer_walker) >_pch_n_S\n");
2596 oprintf (f
, " },\n");
2604 error_at_line (line
,
2605 "global `%s' is unimplemented type",
2610 /* This generates a routine to walk an array. */
2613 write_array (outf_p f
, pair_p v
, const struct write_types_data
*wtd
)
2615 struct walk_type_data d
;
2618 memset (&d
, 0, sizeof (d
));
2624 d
.bitmap
= get_base_file_bitmap (v
->line
.file
);
2627 d
.prev_val
[3] = prevval3
= xasprintf ("&%s", v
->name
);
2629 if (wtd
->param_prefix
)
2631 oprintf (f
, "static void gt_%sa_%s\n", wtd
->param_prefix
, v
->name
);
2633 " (void *, void *, gt_pointer_operator, void *);\n");
2634 oprintf (f
, "static void gt_%sa_%s (this_obj, x_p, op, cookie)\n",
2635 wtd
->param_prefix
, v
->name
);
2636 oprintf (d
.of
, " void *this_obj ATTRIBUTE_UNUSED;\n");
2637 oprintf (d
.of
, " void *x_p ATTRIBUTE_UNUSED;\n");
2638 oprintf (d
.of
, " gt_pointer_operator op ATTRIBUTE_UNUSED;\n");
2639 oprintf (d
.of
, " void *cookie ATTRIBUTE_UNUSED;\n");
2640 oprintf (d
.of
, "{\n");
2641 d
.prev_val
[0] = d
.prev_val
[1] = d
.prev_val
[2] = d
.val
= v
->name
;
2642 d
.process_field
= write_types_local_process_field
;
2643 walk_type (v
->type
, &d
);
2644 oprintf (f
, "}\n\n");
2648 oprintf (f
, "static void gt_%sa_%s (void *);\n",
2649 wtd
->prefix
, v
->name
);
2650 oprintf (f
, "static void\ngt_%sa_%s (x_p)\n",
2651 wtd
->prefix
, v
->name
);
2652 oprintf (f
, " void *x_p ATTRIBUTE_UNUSED;\n");
2654 d
.prev_val
[0] = d
.prev_val
[1] = d
.prev_val
[2] = d
.val
= v
->name
;
2655 d
.process_field
= write_types_process_field
;
2656 walk_type (v
->type
, &d
);
2658 oprintf (f
, "}\n\n");
2661 /* Output a table describing the locations and types of VARIABLES. */
2664 write_roots (pair_p variables
)
2667 struct flist
*flp
= NULL
;
2669 for (v
= variables
; v
; v
= v
->next
)
2671 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2673 const char *length
= NULL
;
2674 int deletable_p
= 0;
2677 for (o
= v
->opt
; o
; o
= o
->next
)
2678 if (strcmp (o
->name
, "length") == 0)
2679 length
= (const char *)o
->info
;
2680 else if (strcmp (o
->name
, "deletable") == 0)
2682 else if (strcmp (o
->name
, "param_is") == 0)
2684 else if (strncmp (o
->name
, "param", 5) == 0
2685 && ISDIGIT (o
->name
[5])
2686 && strcmp (o
->name
+ 6, "_is") == 0)
2688 else if (strcmp (o
->name
, "if_marked") == 0)
2691 error_at_line (&v
->line
,
2692 "global `%s' has unknown option `%s'",
2695 for (fli
= flp
; fli
; fli
= fli
->next
)
2700 fli
= xmalloc (sizeof (*fli
));
2704 fli
->name
= v
->line
.file
;
2707 oprintf (f
, "\n/* GC roots. */\n\n");
2712 && v
->type
->kind
== TYPE_POINTER
2713 && (v
->type
->u
.p
->kind
== TYPE_POINTER
2714 || v
->type
->u
.p
->kind
== TYPE_STRUCT
))
2716 write_array (f
, v
, &ggc_wtd
);
2717 write_array (f
, v
, &pch_wtd
);
2721 for (v
= variables
; v
; v
= v
->next
)
2723 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2729 for (o
= v
->opt
; o
; o
= o
->next
)
2730 if (strcmp (o
->name
, "length") == 0)
2732 else if (strcmp (o
->name
, "deletable") == 0
2733 || strcmp (o
->name
, "if_marked") == 0)
2739 for (fli
= flp
; fli
; fli
= fli
->next
)
2742 if (! fli
->started_p
)
2746 oprintf (f
, "const struct ggc_root_tab gt_ggc_r_");
2747 put_mangled_filename (f
, v
->line
.file
);
2748 oprintf (f
, "[] = {\n");
2751 write_root (f
, v
, v
->type
, v
->name
, length_p
, &v
->line
, NULL
);
2754 finish_root_table (flp
, "ggc_r", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2757 for (v
= variables
; v
; v
= v
->next
)
2759 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2764 for (o
= v
->opt
; o
; o
= o
->next
)
2765 if (strcmp (o
->name
, "deletable") == 0)
2767 else if (strcmp (o
->name
, "if_marked") == 0)
2773 for (fli
= flp
; fli
; fli
= fli
->next
)
2776 if (! fli
->started_p
)
2780 oprintf (f
, "const struct ggc_root_tab gt_ggc_rd_");
2781 put_mangled_filename (f
, v
->line
.file
);
2782 oprintf (f
, "[] = {\n");
2785 oprintf (f
, " { &%s, 1, sizeof (%s), NULL, NULL },\n",
2789 finish_root_table (flp
, "ggc_rd", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2790 "gt_ggc_deletable_rtab");
2792 for (v
= variables
; v
; v
= v
->next
)
2794 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2796 const char *if_marked
= NULL
;
2800 for (o
= v
->opt
; o
; o
= o
->next
)
2801 if (strcmp (o
->name
, "length") == 0)
2803 else if (strcmp (o
->name
, "if_marked") == 0)
2804 if_marked
= (const char *) o
->info
;
2806 if (if_marked
== NULL
)
2809 if (v
->type
->kind
!= TYPE_POINTER
2810 || v
->type
->u
.p
->kind
!= TYPE_PARAM_STRUCT
2811 || v
->type
->u
.p
->u
.param_struct
.stru
!= find_structure ("htab", 0))
2813 error_at_line (&v
->line
, "if_marked option used but not hash table");
2817 for (fli
= flp
; fli
; fli
= fli
->next
)
2820 if (! fli
->started_p
)
2824 oprintf (f
, "const struct ggc_cache_tab gt_ggc_rc_");
2825 put_mangled_filename (f
, v
->line
.file
);
2826 oprintf (f
, "[] = {\n");
2829 write_root (f
, v
, v
->type
->u
.p
->u
.param_struct
.param
[0],
2830 v
->name
, length_p
, &v
->line
, if_marked
);
2833 finish_root_table (flp
, "ggc_rc", "LAST_GGC_CACHE_TAB", "ggc_cache_tab",
2834 "gt_ggc_cache_rtab");
2836 for (v
= variables
; v
; v
= v
->next
)
2838 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2841 int if_marked_p
= 0;
2844 for (o
= v
->opt
; o
; o
= o
->next
)
2845 if (strcmp (o
->name
, "length") == 0)
2847 else if (strcmp (o
->name
, "if_marked") == 0)
2853 for (fli
= flp
; fli
; fli
= fli
->next
)
2856 if (! fli
->started_p
)
2860 oprintf (f
, "const struct ggc_root_tab gt_pch_rc_");
2861 put_mangled_filename (f
, v
->line
.file
);
2862 oprintf (f
, "[] = {\n");
2865 write_root (f
, v
, v
->type
, v
->name
, length_p
, &v
->line
, NULL
);
2868 finish_root_table (flp
, "pch_rc", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2869 "gt_pch_cache_rtab");
2871 for (v
= variables
; v
; v
= v
->next
)
2873 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2878 for (o
= v
->opt
; o
; o
= o
->next
)
2879 if (strcmp (o
->name
, "deletable") == 0
2880 || strcmp (o
->name
, "if_marked") == 0)
2886 if (! contains_scalar_p (v
->type
))
2889 for (fli
= flp
; fli
; fli
= fli
->next
)
2892 if (! fli
->started_p
)
2896 oprintf (f
, "const struct ggc_root_tab gt_pch_rs_");
2897 put_mangled_filename (f
, v
->line
.file
);
2898 oprintf (f
, "[] = {\n");
2901 oprintf (f
, " { &%s, 1, sizeof (%s), NULL, NULL },\n",
2905 finish_root_table (flp
, "pch_rs", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2906 "gt_pch_scalar_rtab");
2910 extern int main (int argc
, char **argv
);
2912 main(int argc ATTRIBUTE_UNUSED
, char **argv ATTRIBUTE_UNUSED
)
2915 static struct fileloc pos
= { __FILE__
, __LINE__
};
2920 srcdir_len
= strlen (srcdir
);
2922 do_scalar_typedef ("CUMULATIVE_ARGS", &pos
);
2923 do_scalar_typedef ("REAL_VALUE_TYPE", &pos
);
2924 do_scalar_typedef ("uint8", &pos
);
2925 do_scalar_typedef ("jword", &pos
);
2926 do_scalar_typedef ("JCF_u2", &pos
);
2928 do_typedef ("PTR", create_pointer (create_scalar_type ("void",
2931 do_typedef ("HARD_REG_SET", create_array (
2932 create_scalar_type ("unsigned long", strlen ("unsigned long")),
2935 for (i
= 0; i
< NUM_GT_FILES
; i
++)
2938 /* Omit if already seen. */
2939 for (j
= 0; j
< i
; j
++)
2941 if (!strcmp (all_files
[i
], all_files
[j
]))
2948 parse_file (all_files
[i
]);
2954 set_gc_used (variables
);
2957 write_enum_defn (structures
, param_structs
);
2958 write_types (structures
, param_structs
, &ggc_wtd
);
2959 write_types (structures
, param_structs
, &pch_wtd
);
2960 write_local (structures
, param_structs
);
2961 write_roots (variables
);
2963 close_output_files ();
2965 return (hit_error
!= 0);