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
PARAMS ((void));
36 static void write_rtx_next
PARAMS ((void));
37 static void open_base_files
PARAMS ((void));
38 static void close_output_files
PARAMS ((void));
40 /* Report an error at POS, printing MSG. */
43 error_at_line
VPARAMS ((struct fileloc
*pos
, const char *msg
, ...))
46 VA_FIXEDARG (ap
, struct fileloc
*, pos
);
47 VA_FIXEDARG (ap
, 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 (result
, format
, args
)
64 int ret
= vasprintf (result
, format
, args
);
65 if (*result
== NULL
|| ret
< 0)
67 fputs ("gengtype: out of memory", stderr
);
73 /* Wrapper for xvasprintf. */
75 xasprintf
VPARAMS ((const char *format
, ...))
79 VA_FIXEDARG (ap
, const char *, format
);
80 xvasprintf (&result
, format
, ap
);
85 /* The one and only TYPE_STRING. */
87 struct type string_type
= {
88 TYPE_STRING
, NULL
, NULL
, GC_USED
92 /* Lists of various things. */
94 static pair_p typedefs
;
95 static type_p structures
;
96 static type_p param_structs
;
97 static pair_p variables
;
99 static void do_scalar_typedef
PARAMS ((const char *, struct fileloc
*));
100 static type_p find_param_structure
101 PARAMS ((type_p t
, type_p param
[NUM_PARAM
]));
102 static type_p adjust_field_tree_exp
PARAMS ((type_p t
, options_p opt
));
103 static type_p adjust_field_rtx_def
PARAMS ((type_p t
, options_p opt
));
105 /* Define S as a typedef to T at POS. */
108 do_typedef (s
, t
, pos
)
115 for (p
= typedefs
; p
!= NULL
; p
= p
->next
)
116 if (strcmp (p
->name
, s
) == 0)
120 error_at_line (pos
, "type `%s' previously defined", s
);
121 error_at_line (&p
->line
, "previously defined here");
126 p
= xmalloc (sizeof (struct pair
));
134 /* Define S as a typename of a scalar. */
137 do_scalar_typedef (s
, pos
)
141 do_typedef (s
, create_scalar_type (s
, strlen (s
)), pos
);
144 /* Return the type previously defined for S. Use POS to report errors. */
147 resolve_typedef (s
, pos
)
152 for (p
= typedefs
; p
!= NULL
; p
= p
->next
)
153 if (strcmp (p
->name
, s
) == 0)
155 error_at_line (pos
, "unidentified type `%s'", s
);
156 return create_scalar_type ("char", 4);
159 /* Create a new structure with tag NAME (or a union iff ISUNION is nonzero),
160 at POS with fields FIELDS and options O. */
163 new_structure (name
, isunion
, pos
, fields
, o
)
172 lang_bitmap bitmap
= get_base_file_bitmap (pos
->file
);
174 for (si
= structures
; si
!= NULL
; si
= si
->next
)
175 if (strcmp (name
, si
->u
.s
.tag
) == 0
176 && UNION_P (si
) == isunion
)
179 if (si
->kind
== TYPE_LANG_STRUCT
)
183 for (si
= ls
->u
.s
.lang_struct
; si
!= NULL
; si
= si
->next
)
184 if (si
->u
.s
.bitmap
== bitmap
)
187 else if (si
->u
.s
.line
.file
!= NULL
&& si
->u
.s
.bitmap
!= bitmap
)
190 si
= xcalloc (1, sizeof (struct type
));
191 memcpy (si
, ls
, sizeof (struct type
));
192 ls
->kind
= TYPE_LANG_STRUCT
;
193 ls
->u
.s
.lang_struct
= si
;
194 ls
->u
.s
.fields
= NULL
;
196 si
->pointer_to
= NULL
;
197 si
->u
.s
.lang_struct
= ls
;
202 if (ls
!= NULL
&& s
== NULL
)
204 s
= xcalloc (1, sizeof (struct type
));
205 s
->next
= ls
->u
.s
.lang_struct
;
206 ls
->u
.s
.lang_struct
= s
;
207 s
->u
.s
.lang_struct
= ls
;
214 s
= xcalloc (1, sizeof (struct type
));
215 s
->next
= structures
;
219 if (s
->u
.s
.line
.file
!= NULL
220 || (s
->u
.s
.lang_struct
&& (s
->u
.s
.lang_struct
->u
.s
.bitmap
& bitmap
)))
222 error_at_line (pos
, "duplicate structure definition");
223 error_at_line (&s
->u
.s
.line
, "previous definition here");
226 s
->kind
= isunion
? TYPE_UNION
: TYPE_STRUCT
;
229 s
->u
.s
.fields
= fields
;
231 s
->u
.s
.bitmap
= bitmap
;
232 if (s
->u
.s
.lang_struct
)
233 s
->u
.s
.lang_struct
->u
.s
.bitmap
|= bitmap
;
236 /* Return the previously-defined structure with tag NAME (or a union
237 iff ISUNION is nonzero), or a new empty structure or union if none
238 was defined previously. */
241 find_structure (name
, isunion
)
247 for (s
= structures
; s
!= NULL
; s
= s
->next
)
248 if (strcmp (name
, s
->u
.s
.tag
) == 0
249 && UNION_P (s
) == isunion
)
252 s
= xcalloc (1, sizeof (struct type
));
253 s
->next
= structures
;
255 s
->kind
= isunion
? TYPE_UNION
: TYPE_STRUCT
;
261 /* Return the previously-defined parameterized structure for structure
262 T and parameters PARAM, or a new parameterized empty structure or
263 union if none was defined previously. */
266 find_param_structure (t
, param
)
268 type_p param
[NUM_PARAM
];
272 for (res
= param_structs
; res
; res
= res
->next
)
273 if (res
->u
.param_struct
.stru
== t
274 && memcmp (res
->u
.param_struct
.param
, param
,
275 sizeof (type_p
) * NUM_PARAM
) == 0)
279 res
= xcalloc (1, sizeof (*res
));
280 res
->kind
= TYPE_PARAM_STRUCT
;
281 res
->next
= param_structs
;
283 res
->u
.param_struct
.stru
= t
;
284 memcpy (res
->u
.param_struct
.param
, param
, sizeof (type_p
) * NUM_PARAM
);
289 /* Return a scalar type with name NAME. */
292 create_scalar_type (name
, name_len
)
296 type_p r
= xcalloc (1, sizeof (struct type
));
297 r
->kind
= TYPE_SCALAR
;
298 r
->u
.sc
= xmemdup (name
, name_len
, name_len
+ 1);
302 /* Return a pointer to T. */
310 type_p r
= xcalloc (1, sizeof (struct type
));
311 r
->kind
= TYPE_POINTER
;
315 return t
->pointer_to
;
318 /* Return an array of length LEN. */
321 create_array (t
, len
)
327 v
= xcalloc (1, sizeof (*v
));
328 v
->kind
= TYPE_ARRAY
;
334 /* Add a variable named S of type T with options O defined at POS,
338 note_variable (s
, t
, o
, pos
)
345 n
= xmalloc (sizeof (*n
));
354 /* We really don't care how long a CONST_DOUBLE is. */
355 #define CONST_DOUBLE_FORMAT "ww"
356 const char * const rtx_format
[NUM_RTX_CODE
] = {
357 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT ,
362 static int rtx_next_new
[NUM_RTX_CODE
];
364 /* Generate the contents of the rtx_next array. This really doesn't belong
365 in gengtype at all, but it's needed for adjust_field_rtx_def. */
371 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
375 rtx_next_new
[i
] = -1;
376 if (strncmp (rtx_format
[i
], "iuu", 3) == 0)
378 else if (i
== COND_EXEC
|| i
== SET
|| i
== EXPR_LIST
|| i
== INSN_LIST
)
381 for (k
= strlen (rtx_format
[i
]) - 1; k
>= 0; k
--)
382 if (rtx_format
[i
][k
] == 'e' || rtx_format
[i
][k
] == 'u')
387 /* Write out the contents of the rtx_next array. */
391 outf_p f
= get_output_file_with_visibility (NULL
);
394 oprintf (f
, "\n/* Used to implement the RTX_NEXT macro. */\n");
395 oprintf (f
, "const unsigned char rtx_next[NUM_RTX_CODE] = {\n");
396 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
397 if (rtx_next_new
[i
] == -1)
398 oprintf (f
, " 0,\n");
401 " offsetof (struct rtx_def, fld) + %d * sizeof (rtunion),\n",
406 /* Handle `special("rtx_def")'. This is a special case for field
407 `fld' of struct rtx_def, which is an array of unions whose values
408 are based in a complex way on the type of RTL. */
411 adjust_field_rtx_def (t
, opt
)
413 options_p opt ATTRIBUTE_UNUSED
;
418 type_p rtx_tp
, rtvec_tp
, tree_tp
, mem_attrs_tp
, note_union_tp
, scalar_tp
;
419 type_p bitmap_tp
, basic_block_tp
, reg_attrs_tp
;
421 static const char * const rtx_name
[NUM_RTX_CODE
] = {
422 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME ,
427 if (t
->kind
!= TYPE_ARRAY
)
429 error_at_line (&lexer_line
,
430 "special `rtx_def' must be applied to an array");
434 nodot
= xmalloc (sizeof (*nodot
));
439 rtx_tp
= create_pointer (find_structure ("rtx_def", 0));
440 rtvec_tp
= create_pointer (find_structure ("rtvec_def", 0));
441 tree_tp
= create_pointer (find_structure ("tree_node", 1));
442 mem_attrs_tp
= create_pointer (find_structure ("mem_attrs", 0));
443 reg_attrs_tp
= create_pointer (find_structure ("reg_attrs", 0));
444 bitmap_tp
= create_pointer (find_structure ("bitmap_element_def", 0));
445 basic_block_tp
= create_pointer (find_structure ("basic_block_def", 0));
446 scalar_tp
= create_scalar_type ("rtunion scalar", 14);
449 pair_p note_flds
= NULL
;
452 for (c
= NOTE_INSN_BIAS
; c
<= NOTE_INSN_MAX
; c
++)
454 pair_p old_note_flds
= note_flds
;
456 note_flds
= xmalloc (sizeof (*note_flds
));
457 note_flds
->line
.file
= __FILE__
;
458 note_flds
->line
.line
= __LINE__
;
459 note_flds
->opt
= xmalloc (sizeof (*note_flds
->opt
));
460 note_flds
->opt
->next
= nodot
;
461 note_flds
->opt
->name
= "tag";
462 note_flds
->opt
->info
= xasprintf ("%d", c
);
463 note_flds
->next
= old_note_flds
;
467 /* NOTE_INSN_MAX is used as the default field for line
470 note_flds
->opt
->name
= "default";
471 note_flds
->name
= "rtstr";
472 note_flds
->type
= &string_type
;
475 case NOTE_INSN_BLOCK_BEG
:
476 case NOTE_INSN_BLOCK_END
:
477 note_flds
->name
= "rttree";
478 note_flds
->type
= tree_tp
;
481 case NOTE_INSN_EXPECTED_VALUE
:
482 note_flds
->name
= "rtx";
483 note_flds
->type
= rtx_tp
;
487 note_flds
->name
= "rtint";
488 note_flds
->type
= scalar_tp
;
492 new_structure ("rtx_def_note_subunion", 1, &lexer_line
, note_flds
, NULL
);
495 note_union_tp
= find_structure ("rtx_def_note_subunion", 1);
497 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
499 pair_p old_flds
= flds
;
500 pair_p subfields
= NULL
;
501 size_t aindex
, nmindex
;
505 for (aindex
= 0; aindex
< strlen (rtx_format
[i
]); aindex
++)
507 pair_p old_subf
= subfields
;
511 switch (rtx_format
[i
][aindex
])
522 if (i
== MEM
&& aindex
== 1)
523 t
= mem_attrs_tp
, subname
= "rtmem";
524 else if (i
== JUMP_INSN
&& aindex
== 9)
525 t
= rtx_tp
, subname
= "rtx";
526 else if (i
== CODE_LABEL
&& aindex
== 4)
527 t
= scalar_tp
, subname
= "rtint";
528 else if (i
== CODE_LABEL
&& aindex
== 5)
529 t
= rtx_tp
, subname
= "rtx";
530 else if (i
== LABEL_REF
531 && (aindex
== 1 || aindex
== 2))
532 t
= rtx_tp
, subname
= "rtx";
533 else if (i
== NOTE
&& aindex
== 4)
534 t
= note_union_tp
, subname
= "";
535 else if (i
== NOTE
&& aindex
>= 7)
536 t
= scalar_tp
, subname
= "rtint";
537 else if (i
== ADDR_DIFF_VEC
&& aindex
== 4)
538 t
= scalar_tp
, subname
= "rtint";
539 else if (i
== VALUE
&& aindex
== 0)
540 t
= scalar_tp
, subname
= "rtint";
541 else if (i
== REG
&& aindex
== 1)
542 t
= scalar_tp
, subname
= "rtint";
543 else if (i
== REG
&& aindex
== 2)
544 t
= reg_attrs_tp
, subname
= "rtreg";
545 else if (i
== SCRATCH
&& aindex
== 0)
546 t
= scalar_tp
, subname
= "rtint";
547 else if (i
== BARRIER
&& aindex
>= 3)
548 t
= scalar_tp
, subname
= "rtint";
551 error_at_line (&lexer_line
,
552 "rtx type `%s' has `0' in position %lu, can't handle",
553 rtx_name
[i
], (unsigned long) aindex
);
594 error_at_line (&lexer_line
,
595 "rtx type `%s' has `%c' in position %lu, can't handle",
596 rtx_name
[i
], rtx_format
[i
][aindex
],
597 (unsigned long)aindex
);
603 subfields
= xmalloc (sizeof (*subfields
));
604 subfields
->next
= old_subf
;
606 subfields
->name
= xasprintf ("[%lu].%s", (unsigned long)aindex
,
608 subfields
->line
.file
= __FILE__
;
609 subfields
->line
.line
= __LINE__
;
610 if (t
== note_union_tp
)
612 subfields
->opt
= xmalloc (sizeof (*subfields
->opt
));
613 subfields
->opt
->next
= nodot
;
614 subfields
->opt
->name
= "desc";
615 subfields
->opt
->info
= "NOTE_LINE_NUMBER (&%0)";
617 else if (t
== basic_block_tp
)
619 /* We don't presently GC basic block structures... */
620 subfields
->opt
= xmalloc (sizeof (*subfields
->opt
));
621 subfields
->opt
->next
= nodot
;
622 subfields
->opt
->name
= "skip";
623 subfields
->opt
->info
= NULL
;
626 subfields
->opt
= nodot
;
629 flds
= xmalloc (sizeof (*flds
));
630 flds
->next
= old_flds
;
632 sname
= xasprintf ("rtx_def_%s", rtx_name
[i
]);
633 new_structure (sname
, 0, &lexer_line
, subfields
, NULL
);
634 flds
->type
= find_structure (sname
, 0);
635 flds
->line
.file
= __FILE__
;
636 flds
->line
.line
= __LINE__
;
637 flds
->opt
= xmalloc (sizeof (*flds
->opt
));
638 flds
->opt
->next
= nodot
;
639 flds
->opt
->name
= "tag";
640 ftag
= xstrdup (rtx_name
[i
]);
641 for (nmindex
= 0; nmindex
< strlen (ftag
); nmindex
++)
642 ftag
[nmindex
] = TOUPPER (ftag
[nmindex
]);
643 flds
->opt
->info
= ftag
;
646 new_structure ("rtx_def_subunion", 1, &lexer_line
, flds
, nodot
);
647 return find_structure ("rtx_def_subunion", 1);
650 /* Handle `special("tree_exp")'. This is a special case for
651 field `operands' of struct tree_exp, which although it claims to contain
652 pointers to trees, actually sometimes contains pointers to RTL too.
653 Passed T, the old type of the field, and OPT its options. Returns
654 a new type for the field. */
657 adjust_field_tree_exp (t
, opt
)
659 options_p opt ATTRIBUTE_UNUSED
;
664 static const struct {
669 { "SAVE_EXPR", 2, 1 },
670 { "GOTO_SUBROUTINE_EXPR", 0, 2 },
671 { "RTL_EXPR", 0, 2 },
672 { "WITH_CLEANUP_EXPR", 2, 1 },
673 { "METHOD_CALL_EXPR", 3, 1 }
676 if (t
->kind
!= TYPE_ARRAY
)
678 error_at_line (&lexer_line
,
679 "special `tree_exp' must be applied to an array");
683 nodot
= xmalloc (sizeof (*nodot
));
688 flds
= xmalloc (sizeof (*flds
));
692 flds
->line
.file
= __FILE__
;
693 flds
->line
.line
= __LINE__
;
694 flds
->opt
= xmalloc (sizeof (*flds
->opt
));
695 flds
->opt
->next
= nodot
;
696 flds
->opt
->name
= "length";
697 flds
->opt
->info
= "TREE_CODE_LENGTH (TREE_CODE ((tree) &%0))";
699 options_p oldopt
= flds
->opt
;
700 flds
->opt
= xmalloc (sizeof (*flds
->opt
));
701 flds
->opt
->next
= oldopt
;
702 flds
->opt
->name
= "default";
703 flds
->opt
->info
= "";
706 for (i
= 0; i
< ARRAY_SIZE (data
); i
++)
708 pair_p old_flds
= flds
;
709 pair_p subfields
= NULL
;
714 r_index
< data
[i
].first_rtl
+ data
[i
].num_rtl
;
717 pair_p old_subf
= subfields
;
718 subfields
= xmalloc (sizeof (*subfields
));
719 subfields
->next
= old_subf
;
720 subfields
->name
= xasprintf ("[%d]", r_index
);
721 if (r_index
< data
[i
].first_rtl
)
722 subfields
->type
= t
->u
.a
.p
;
724 subfields
->type
= create_pointer (find_structure ("rtx_def", 0));
725 subfields
->line
.file
= __FILE__
;
726 subfields
->line
.line
= __LINE__
;
727 subfields
->opt
= nodot
;
730 flds
= xmalloc (sizeof (*flds
));
731 flds
->next
= old_flds
;
733 sname
= xasprintf ("tree_exp_%s", data
[i
].name
);
734 new_structure (sname
, 0, &lexer_line
, subfields
, NULL
);
735 flds
->type
= find_structure (sname
, 0);
736 flds
->line
.file
= __FILE__
;
737 flds
->line
.line
= __LINE__
;
738 flds
->opt
= xmalloc (sizeof (*flds
->opt
));
739 flds
->opt
->next
= nodot
;
740 flds
->opt
->name
= "tag";
741 flds
->opt
->info
= data
[i
].name
;
744 new_structure ("tree_exp_subunion", 1, &lexer_line
, flds
, nodot
);
745 return find_structure ("tree_exp_subunion", 1);
748 /* Perform any special processing on a type T, about to become the type
749 of a field. Return the appropriate type for the field.
751 - Converts pointer-to-char, with no length parameter, to TYPE_STRING;
752 - Similarly for arrays of pointer-to-char;
753 - Converts structures for which a parameter is provided to
755 - Handles "special" options.
759 adjust_field_type (t
, opt
)
764 const int pointer_p
= t
->kind
== TYPE_POINTER
;
765 type_p params
[NUM_PARAM
];
769 for (i
= 0; i
< NUM_PARAM
; i
++)
772 for (; opt
; opt
= opt
->next
)
773 if (strcmp (opt
->name
, "length") == 0)
775 else if (strcmp (opt
->name
, "param_is") == 0
776 || (strncmp (opt
->name
, "param", 5) == 0
777 && ISDIGIT (opt
->name
[5])
778 && strcmp (opt
->name
+ 6, "_is") == 0))
780 int num
= ISDIGIT (opt
->name
[5]) ? opt
->name
[5] - '0' : 0;
782 if (! UNION_OR_STRUCT_P (t
)
783 && (t
->kind
!= TYPE_POINTER
|| ! UNION_OR_STRUCT_P (t
->u
.p
)))
785 error_at_line (&lexer_line
,
786 "option `%s' may only be applied to structures or structure pointers",
792 if (params
[num
] != NULL
)
793 error_at_line (&lexer_line
, "duplicate `%s' option", opt
->name
);
794 if (! ISDIGIT (opt
->name
[5]))
795 params
[num
] = create_pointer ((type_p
) opt
->info
);
797 params
[num
] = (type_p
) opt
->info
;
799 else if (strcmp (opt
->name
, "special") == 0)
801 const char *special_name
= (const char *)opt
->info
;
802 if (strcmp (special_name
, "tree_exp") == 0)
803 t
= adjust_field_tree_exp (t
, opt
);
804 else if (strcmp (special_name
, "rtx_def") == 0)
805 t
= adjust_field_rtx_def (t
, opt
);
807 error_at_line (&lexer_line
, "unknown special `%s'", special_name
);
816 realt
= find_param_structure (t
, params
);
817 t
= pointer_p
? create_pointer (realt
) : realt
;
822 && t
->u
.p
->kind
== TYPE_SCALAR
823 && (strcmp (t
->u
.p
->u
.sc
, "char") == 0
824 || strcmp (t
->u
.p
->u
.sc
, "unsigned char") == 0))
826 if (t
->kind
== TYPE_ARRAY
&& t
->u
.a
.p
->kind
== TYPE_POINTER
827 && t
->u
.a
.p
->u
.p
->kind
== TYPE_SCALAR
828 && (strcmp (t
->u
.a
.p
->u
.p
->u
.sc
, "char") == 0
829 || strcmp (t
->u
.a
.p
->u
.p
->u
.sc
, "unsigned char") == 0))
830 return create_array (&string_type
, t
->u
.a
.len
);
835 /* Create a union for YYSTYPE, as yacc would do it, given a fieldlist FIELDS
836 and information about the correspondence between token types and fields
837 in TYPEINFO. POS is used for error messages. */
840 note_yacc_type (o
, fields
, typeinfo
, pos
)
849 for (p
= typeinfo
; p
; p
= p
->next
)
856 if (p
->type
== (type_p
) 1)
861 for (pp
= typeinfo
; pp
; pp
= pp
->next
)
862 if (pp
->type
!= (type_p
) 1
863 && strcmp (pp
->opt
->info
, p
->opt
->info
) == 0)
872 for (m
= fields
; m
; m
= m
->next
)
873 if (strcmp (m
->name
, p
->name
) == 0)
877 error_at_line (&p
->line
,
878 "couldn't match fieldname `%s'", p
->name
);
889 || p
->type
== (type_p
) 1)
895 new_structure ("yy_union", 1, pos
, typeinfo
, o
);
896 do_typedef ("YYSTYPE", find_structure ("yy_union", 1), pos
);
899 static void process_gc_options
PARAMS ((options_p
, enum gc_used_enum
,
900 int *, int *, int *));
901 static void set_gc_used_type
PARAMS ((type_p
, enum gc_used_enum
, type_p
*));
902 static void set_gc_used
PARAMS ((pair_p
));
904 /* Handle OPT for set_gc_used_type. */
907 process_gc_options (opt
, level
, maybe_undef
, pass_param
, length
)
909 enum gc_used_enum level
;
915 for (o
= opt
; o
; o
= o
->next
)
916 if (strcmp (o
->name
, "ptr_alias") == 0 && level
== GC_POINTED_TO
)
917 set_gc_used_type ((type_p
) o
->info
, GC_POINTED_TO
, NULL
);
918 else if (strcmp (o
->name
, "maybe_undef") == 0)
920 else if (strcmp (o
->name
, "use_params") == 0)
922 else if (strcmp (o
->name
, "length") == 0)
926 /* Set the gc_used field of T to LEVEL, and handle the types it references. */
929 set_gc_used_type (t
, level
, param
)
931 enum gc_used_enum level
;
932 type_p param
[NUM_PARAM
];
934 if (t
->gc_used
>= level
)
947 process_gc_options (t
->u
.s
.opt
, level
, &dummy
, &dummy
, &dummy
);
949 for (f
= t
->u
.s
.fields
; f
; f
= f
->next
)
954 process_gc_options (f
->opt
, level
, &maybe_undef
, &pass_param
,
957 if (length
&& f
->type
->kind
== TYPE_POINTER
)
958 set_gc_used_type (f
->type
->u
.p
, GC_USED
, NULL
);
959 else if (maybe_undef
&& f
->type
->kind
== TYPE_POINTER
)
960 set_gc_used_type (f
->type
->u
.p
, GC_MAYBE_POINTED_TO
, NULL
);
961 else if (pass_param
&& f
->type
->kind
== TYPE_POINTER
&& param
)
962 set_gc_used_type (find_param_structure (f
->type
->u
.p
, param
),
963 GC_POINTED_TO
, NULL
);
965 set_gc_used_type (f
->type
, GC_USED
, pass_param
? param
: NULL
);
971 set_gc_used_type (t
->u
.p
, GC_POINTED_TO
, NULL
);
975 set_gc_used_type (t
->u
.a
.p
, GC_USED
, param
);
978 case TYPE_LANG_STRUCT
:
979 for (t
= t
->u
.s
.lang_struct
; t
; t
= t
->next
)
980 set_gc_used_type (t
, level
, param
);
983 case TYPE_PARAM_STRUCT
:
986 for (i
= 0; i
< NUM_PARAM
; i
++)
987 if (t
->u
.param_struct
.param
[i
] != 0)
988 set_gc_used_type (t
->u
.param_struct
.param
[i
], GC_USED
, NULL
);
990 if (t
->u
.param_struct
.stru
->gc_used
== GC_POINTED_TO
)
991 level
= GC_POINTED_TO
;
994 t
->u
.param_struct
.stru
->gc_used
= GC_UNUSED
;
995 set_gc_used_type (t
->u
.param_struct
.stru
, level
,
996 t
->u
.param_struct
.param
);
1004 /* Set the gc_used fields of all the types pointed to by VARIABLES. */
1007 set_gc_used (variables
)
1011 for (p
= variables
; p
; p
= p
->next
)
1012 set_gc_used_type (p
->type
, GC_USED
, NULL
);
1015 /* File mapping routines. For each input file, there is one output .c file
1016 (but some output files have many input files), and there is one .h file
1017 for the whole build. */
1019 /* The list of output files. */
1020 static outf_p output_files
;
1022 /* The output header file that is included into pretty much every
1026 /* Number of files specified in gtfiles. */
1027 #define NUM_GT_FILES (ARRAY_SIZE (all_files) - 1)
1029 /* Number of files in the language files array. */
1030 #define NUM_LANG_FILES (ARRAY_SIZE (lang_files) - 1)
1032 /* Length of srcdir name. */
1033 static int srcdir_len
= 0;
1035 #define NUM_BASE_FILES (ARRAY_SIZE (lang_dir_names) - 1)
1036 outf_p base_files
[NUM_BASE_FILES
];
1038 static outf_p create_file
PARAMS ((const char *, const char *));
1039 static const char * get_file_basename
PARAMS ((const char *));
1041 /* Create and return an outf_p for a new file for NAME, to be called
1045 create_file (name
, oname
)
1049 static const char *const hdr
[] = {
1050 " Copyright (C) 2002 Free Software Foundation, Inc.\n",
1052 "This file is part of GCC.\n",
1054 "GCC is free software; you can redistribute it and/or modify it under\n",
1055 "the terms of the GNU General Public License as published by the Free\n",
1056 "Software Foundation; either version 2, or (at your option) any later\n",
1059 "GCC is distributed in the hope that it will be useful, but WITHOUT ANY\n",
1060 "WARRANTY; without even the implied warranty of MERCHANTABILITY or\n",
1061 "FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n",
1062 "for more details.\n",
1064 "You should have received a copy of the GNU General Public License\n",
1065 "along with GCC; see the file COPYING. If not, write to the Free\n",
1066 "Software Foundation, 59 Temple Place - Suite 330, Boston, MA\n",
1067 "02111-1307, USA. */\n",
1069 "/* This file is machine generated. Do not edit. */\n"
1074 f
= xcalloc (sizeof (*f
), 1);
1075 f
->next
= output_files
;
1079 oprintf (f
, "/* Type information for %s.\n", name
);
1080 for (i
= 0; i
< ARRAY_SIZE (hdr
); i
++)
1081 oprintf (f
, "%s", hdr
[i
]);
1085 /* Print, like fprintf, to O. */
1087 oprintf
VPARAMS ((outf_p o
, const char *format
, ...))
1092 VA_OPEN (ap
, format
);
1093 VA_FIXEDARG (ap
, outf_p
, o
);
1094 VA_FIXEDARG (ap
, const char *, format
);
1095 slength
= xvasprintf (&s
, format
, ap
);
1097 if (o
->bufused
+ slength
> o
->buflength
)
1099 size_t new_len
= o
->buflength
;
1104 } while (o
->bufused
+ slength
>= new_len
);
1105 o
->buf
= xrealloc (o
->buf
, new_len
);
1106 o
->buflength
= new_len
;
1108 memcpy (o
->buf
+ o
->bufused
, s
, slength
);
1109 o
->bufused
+= slength
;
1114 /* Open the global header file and the language-specific header files. */
1121 header_file
= create_file ("GCC", "gtype-desc.h");
1123 for (i
= 0; i
< NUM_BASE_FILES
; i
++)
1124 base_files
[i
] = create_file (lang_dir_names
[i
],
1125 xasprintf ("gtype-%s.h", lang_dir_names
[i
]));
1127 /* gtype-desc.c is a little special, so we create it here. */
1129 /* The order of files here matters very much. */
1130 static const char *const ifiles
[] = {
1131 "config.h", "system.h", "coretypes.h", "tm.h", "varray.h",
1132 "hashtab.h", "splay-tree.h", "bitmap.h", "tree.h", "rtl.h",
1133 "function.h", "insn-config.h", "expr.h", "hard-reg-set.h",
1134 "basic-block.h", "cselib.h", "insn-addr.h", "ssa.h", "optabs.h",
1135 "libfuncs.h", "debug.h", "ggc.h",
1138 const char *const *ifp
;
1139 outf_p gtype_desc_c
;
1141 gtype_desc_c
= create_file ("GCC", "gtype-desc.c");
1142 for (ifp
= ifiles
; *ifp
; ifp
++)
1143 oprintf (gtype_desc_c
, "#include \"%s\"\n", *ifp
);
1147 /* Determine the pathname to F relative to $(srcdir). */
1150 get_file_basename (f
)
1153 const char *basename
;
1156 basename
= strrchr (f
, '/');
1163 for (i
= 1; i
< NUM_BASE_FILES
; i
++)
1169 s1
= basename
- strlen (lang_dir_names
[i
]) - 1;
1170 s2
= lang_dir_names
[i
];
1173 if (l1
>= l2
&& !memcmp (s1
, s2
, l2
))
1176 if ((basename
- f
- 1) != srcdir_len
)
1177 abort (); /* Match is wrong - should be preceded by $srcdir. */
1185 /* Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff
1186 INPUT_FILE is used by <lang>.
1188 This function should be written to assume that a file _is_ used
1189 if the situation is unclear. If it wrongly assumes a file _is_ used,
1190 a linker error will result. If it wrongly assumes a file _is not_ used,
1191 some GC roots may be missed, which is a much harder-to-debug problem. */
1194 get_base_file_bitmap (input_file
)
1195 const char *input_file
;
1197 const char *basename
= get_file_basename (input_file
);
1198 const char *slashpos
= strchr (basename
, '/');
1206 for (i
= 1; i
< NUM_BASE_FILES
; i
++)
1207 if ((size_t)(slashpos
- basename
) == strlen (lang_dir_names
[i
])
1208 && memcmp (basename
, lang_dir_names
[i
], strlen (lang_dir_names
[i
])) == 0)
1210 /* It's in a language directory, set that language. */
1215 abort (); /* Should have found the language. */
1218 /* If it's in any config-lang.in, then set for the languages
1223 for (j
= 0; j
< NUM_LANG_FILES
; j
++)
1225 if (!strcmp(input_file
, lang_files
[j
]))
1227 for (k
= 0; k
< NUM_BASE_FILES
; k
++)
1229 if (!strcmp(lang_dir_names
[k
], langs_for_lang_files
[j
]))
1235 /* Otherwise, set all languages. */
1237 bitmap
= (1 << NUM_BASE_FILES
) - 1;
1242 /* An output file, suitable for definitions, that can see declarations
1243 made in INPUT_FILE and is linked into every language that uses
1247 get_output_file_with_visibility (input_file
)
1248 const char *input_file
;
1252 const char *basename
;
1253 const char *for_name
;
1254 const char *output_name
;
1256 /* This can happen when we need a file with visibility on a
1257 structure that we've never seen. We have to just hope that it's
1258 globally visible. */
1259 if (input_file
== NULL
)
1260 input_file
= "system.h";
1262 /* Determine the output file name. */
1263 basename
= get_file_basename (input_file
);
1265 len
= strlen (basename
);
1266 if ((len
> 2 && memcmp (basename
+len
-2, ".c", 2) == 0)
1267 || (len
> 2 && memcmp (basename
+len
-2, ".y", 2) == 0)
1268 || (len
> 3 && memcmp (basename
+len
-3, ".in", 3) == 0))
1272 output_name
= s
= xasprintf ("gt-%s", basename
);
1273 for (; *s
!= '.'; s
++)
1274 if (! ISALNUM (*s
) && *s
!= '-')
1276 memcpy (s
, ".h", sizeof (".h"));
1277 for_name
= basename
;
1279 else if (strcmp (basename
, "c-common.h") == 0)
1280 output_name
= "gt-c-common.h", for_name
= "c-common.c";
1281 else if (strcmp (basename
, "c-tree.h") == 0)
1282 output_name
= "gt-c-decl.h", for_name
= "c-decl.c";
1287 for (i
= 0; i
< NUM_BASE_FILES
; i
++)
1288 if (memcmp (basename
, lang_dir_names
[i
], strlen (lang_dir_names
[i
])) == 0
1289 && basename
[strlen(lang_dir_names
[i
])] == '/')
1290 return base_files
[i
];
1292 output_name
= "gtype-desc.c";
1296 /* Look through to see if we've ever seen this output filename before. */
1297 for (r
= output_files
; r
; r
= r
->next
)
1298 if (strcmp (r
->name
, output_name
) == 0)
1301 /* If not, create it. */
1302 r
= create_file (for_name
, output_name
);
1307 /* The name of an output file, suitable for definitions, that can see
1308 declarations made in INPUT_FILE and is linked into every language
1309 that uses INPUT_FILE. */
1312 get_output_file_name (input_file
)
1313 const char *input_file
;
1315 return get_output_file_with_visibility (input_file
)->name
;
1318 /* Copy the output to its final destination,
1319 but don't unnecessarily change modification times. */
1321 static void close_output_files
PARAMS ((void));
1324 close_output_files ()
1328 for (of
= output_files
; of
; of
= of
->next
)
1332 newfile
= fopen (of
->name
, "r");
1333 if (newfile
!= NULL
)
1338 for (i
= 0; i
< of
->bufused
; i
++)
1341 ch
= fgetc (newfile
);
1342 if (ch
== EOF
|| ch
!= (unsigned char) of
->buf
[i
])
1345 no_write_p
= i
== of
->bufused
&& fgetc (newfile
) == EOF
;
1352 newfile
= fopen (of
->name
, "w");
1353 if (newfile
== NULL
)
1355 perror ("opening output file");
1358 if (fwrite (of
->buf
, 1, of
->bufused
, newfile
) != of
->bufused
)
1360 perror ("writing output file");
1363 if (fclose (newfile
) != 0)
1365 perror ("closing output file");
1378 struct walk_type_data
;
1380 /* For scalars and strings, given the item in 'val'.
1381 For structures, given a pointer to the item in 'val'.
1382 For misc. pointers, given the item in 'val'.
1384 typedef void (*process_field_fn
)
1385 PARAMS ((type_p f
, const struct walk_type_data
*p
));
1386 typedef void (*func_name_fn
)
1387 PARAMS ((type_p s
, const struct walk_type_data
*p
));
1389 /* Parameters for write_types. */
1391 struct write_types_data
1394 const char *param_prefix
;
1395 const char *subfield_marker_routine
;
1396 const char *marker_routine
;
1397 const char *reorder_note_routine
;
1398 const char *comment
;
1401 static void output_escaped_param
PARAMS ((struct walk_type_data
*d
,
1402 const char *, const char *));
1403 static void output_mangled_typename
PARAMS ((outf_p
, type_p
));
1404 static void walk_type
PARAMS ((type_p t
, struct walk_type_data
*d
));
1405 static void write_func_for_structure
1406 PARAMS ((type_p orig_s
, type_p s
, type_p
* param
,
1407 const struct write_types_data
*wtd
));
1408 static void write_types_process_field
1409 PARAMS ((type_p f
, const struct walk_type_data
*d
));
1410 static void write_types
PARAMS ((type_p structures
,
1411 type_p param_structs
,
1412 const struct write_types_data
*wtd
));
1413 static void write_types_local_process_field
1414 PARAMS ((type_p f
, const struct walk_type_data
*d
));
1415 static void write_local_func_for_structure
1416 PARAMS ((type_p orig_s
, type_p s
, type_p
* param
));
1417 static void write_local
PARAMS ((type_p structures
,
1418 type_p param_structs
));
1419 static void write_enum_defn
PARAMS ((type_p structures
, type_p param_structs
));
1420 static int contains_scalar_p
PARAMS ((type_p t
));
1421 static void put_mangled_filename
PARAMS ((outf_p
, const char *));
1422 static void finish_root_table
PARAMS ((struct flist
*flp
, const char *pfx
,
1423 const char *tname
, const char *lastname
,
1425 static void write_root
PARAMS ((outf_p
, pair_p
, type_p
, const char *, int,
1426 struct fileloc
*, const char *));
1427 static void write_array
PARAMS ((outf_p f
, pair_p v
,
1428 const struct write_types_data
*wtd
));
1429 static void write_roots
PARAMS ((pair_p
));
1431 /* Parameters for walk_type. */
1433 struct walk_type_data
1435 process_field_fn process_field
;
1440 const char *prev_val
[4];
1443 struct fileloc
*line
;
1448 const char *reorder_fn
;
1452 /* Print a mangled name representing T to OF. */
1455 output_mangled_typename (of
, t
)
1461 else switch (t
->kind
)
1465 output_mangled_typename (of
, t
->u
.p
);
1475 case TYPE_LANG_STRUCT
:
1476 oprintf (of
, "%lu%s", (unsigned long) strlen (t
->u
.s
.tag
), t
->u
.s
.tag
);
1478 case TYPE_PARAM_STRUCT
:
1481 for (i
= 0; i
< NUM_PARAM
; i
++)
1482 if (t
->u
.param_struct
.param
[i
] != NULL
)
1483 output_mangled_typename (of
, t
->u
.param_struct
.param
[i
]);
1484 output_mangled_typename (of
, t
->u
.param_struct
.stru
);
1492 /* Print PARAM to D->OF processing escapes. D->VAL references the
1493 current object, D->PREV_VAL the object containing the current
1494 object, ONAME is the name of the option and D->LINE is used to
1495 print error messages. */
1498 output_escaped_param (d
, param
, oname
)
1499 struct walk_type_data
*d
;
1505 for (p
= param
; *p
; p
++)
1507 oprintf (d
->of
, "%c", *p
);
1511 oprintf (d
->of
, "(%s)", d
->prev_val
[2]);
1514 oprintf (d
->of
, "(%s)", d
->prev_val
[0]);
1517 oprintf (d
->of
, "(%s)", d
->prev_val
[1]);
1521 const char *pp
= d
->val
+ strlen (d
->val
);
1522 while (pp
[-1] == ']')
1525 oprintf (d
->of
, "%s", pp
);
1529 error_at_line (d
->line
, "`%s' option contains bad escape %c%c",
1534 /* Call D->PROCESS_FIELD for every field (or subfield) of D->VAL,
1535 which is of type T. Write code to D->OF to constrain execution (at
1536 the point that D->PROCESS_FIELD is called) to the appropriate
1537 cases. D->PREV_VAL lists the objects containing the current object,
1538 D->OPT is a list of options to apply, D->INDENT is the current
1539 indentation level, D->LINE is used to print error messages,
1540 D->BITMAP indicates which languages to print the structure for, and
1541 D->PARAM is the current parameter (from an enclosing param_is
1547 struct walk_type_data
*d
;
1549 const char *length
= NULL
;
1550 const char *desc
= NULL
;
1551 int maybe_undef_p
= 0;
1552 int use_param_num
= -1;
1553 int use_params_p
= 0;
1556 d
->needs_cast_p
= 0;
1557 for (oo
= d
->opt
; oo
; oo
= oo
->next
)
1558 if (strcmp (oo
->name
, "length") == 0)
1559 length
= (const char *)oo
->info
;
1560 else if (strcmp (oo
->name
, "maybe_undef") == 0)
1562 else if (strncmp (oo
->name
, "use_param", 9) == 0
1563 && (oo
->name
[9] == '\0' || ISDIGIT (oo
->name
[9])))
1564 use_param_num
= oo
->name
[9] == '\0' ? 0 : oo
->name
[9] - '0';
1565 else if (strcmp (oo
->name
, "use_params") == 0)
1567 else if (strcmp (oo
->name
, "desc") == 0)
1568 desc
= (const char *)oo
->info
;
1569 else if (strcmp (oo
->name
, "dot") == 0)
1571 else if (strcmp (oo
->name
, "tag") == 0)
1573 else if (strcmp (oo
->name
, "special") == 0)
1575 else if (strcmp (oo
->name
, "skip") == 0)
1577 else if (strcmp (oo
->name
, "default") == 0)
1579 else if (strcmp (oo
->name
, "descbits") == 0)
1581 else if (strcmp (oo
->name
, "param_is") == 0)
1583 else if (strncmp (oo
->name
, "param", 5) == 0
1584 && ISDIGIT (oo
->name
[5])
1585 && strcmp (oo
->name
+ 6, "_is") == 0)
1587 else if (strcmp (oo
->name
, "chain_next") == 0)
1589 else if (strcmp (oo
->name
, "chain_prev") == 0)
1591 else if (strcmp (oo
->name
, "reorder") == 0)
1594 error_at_line (d
->line
, "unknown option `%s'\n", oo
->name
);
1601 int pointer_p
= t
->kind
== TYPE_POINTER
;
1605 if (! UNION_OR_STRUCT_P (t
))
1606 error_at_line (d
->line
, "`use_params' option on unimplemented type");
1608 t
= find_param_structure (t
, d
->param
);
1610 t
= create_pointer (t
);
1613 if (use_param_num
!= -1)
1615 if (d
->param
!= NULL
&& d
->param
[use_param_num
] != NULL
)
1617 type_p nt
= d
->param
[use_param_num
];
1619 if (t
->kind
== TYPE_ARRAY
)
1620 nt
= create_array (nt
, t
->u
.a
.len
);
1621 else if (length
!= NULL
&& t
->kind
== TYPE_POINTER
)
1622 nt
= create_pointer (nt
);
1623 d
->needs_cast_p
= (t
->kind
!= TYPE_POINTER
1624 && (nt
->kind
== TYPE_POINTER
1625 || nt
->kind
== TYPE_STRING
));
1629 error_at_line (d
->line
, "no parameter defined for `%s'",
1634 && (t
->kind
!= TYPE_POINTER
|| ! UNION_OR_STRUCT_P (t
->u
.p
)))
1636 error_at_line (d
->line
,
1637 "field `%s' has invalid option `maybe_undef_p'\n",
1646 d
->process_field (t
, d
);
1652 && t
->u
.p
->u
.s
.line
.file
== NULL
)
1654 oprintf (d
->of
, "%*sif (%s) abort();\n", d
->indent
, "", d
->val
);
1660 if (! UNION_OR_STRUCT_P (t
->u
.p
)
1661 && t
->u
.p
->kind
!= TYPE_PARAM_STRUCT
)
1663 error_at_line (d
->line
,
1664 "field `%s' is pointer to unimplemented type",
1669 d
->process_field (t
->u
.p
, d
);
1673 int loopcounter
= d
->counter
++;
1674 const char *oldval
= d
->val
;
1675 const char *oldprevval3
= d
->prev_val
[3];
1678 oprintf (d
->of
, "%*sif (%s != NULL) {\n", d
->indent
, "", d
->val
);
1680 oprintf (d
->of
, "%*ssize_t i%d;\n", d
->indent
, "", loopcounter
);
1681 d
->process_field(t
, d
);
1682 oprintf (d
->of
, "%*sfor (i%d = 0; i%d < (size_t)(", d
->indent
, "",
1683 loopcounter
, loopcounter
);
1684 output_escaped_param (d
, length
, "length");
1685 oprintf (d
->of
, "); i%d++) {\n", loopcounter
);
1687 d
->val
= newval
= xasprintf ("%s[i%d]", oldval
, loopcounter
);
1689 d
->prev_val
[3] = oldval
;
1690 walk_type (t
->u
.p
, d
);
1693 d
->prev_val
[3] = oldprevval3
;
1696 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
1698 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
1705 int loopcounter
= d
->counter
++;
1706 const char *oldval
= d
->val
;
1709 /* If it's an array of scalars, we optimise by not generating
1711 if (t
->u
.a
.p
->kind
== TYPE_SCALAR
)
1714 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
1716 oprintf (d
->of
, "%*ssize_t i%d;\n", d
->indent
, "", loopcounter
);
1717 oprintf (d
->of
, "%*sfor (i%d = 0; i%d < (size_t)(", d
->indent
, "",
1718 loopcounter
, loopcounter
);
1720 output_escaped_param (d
, length
, "length");
1722 oprintf (d
->of
, "%s", t
->u
.a
.len
);
1723 oprintf (d
->of
, "); i%d++) {\n", loopcounter
);
1725 d
->val
= newval
= xasprintf ("%s[i%d]", oldval
, loopcounter
);
1727 walk_type (t
->u
.a
.p
, d
);
1732 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
1734 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
1742 const char *oldval
= d
->val
;
1743 const char *oldprevval1
= d
->prev_val
[1];
1744 const char *oldprevval2
= d
->prev_val
[2];
1745 const int union_p
= t
->kind
== TYPE_UNION
;
1746 int seen_default_p
= 0;
1749 if (! t
->u
.s
.line
.file
)
1750 error_at_line (d
->line
, "incomplete structure `%s'", t
->u
.s
.tag
);
1752 if ((d
->bitmap
& t
->u
.s
.bitmap
) != d
->bitmap
)
1754 error_at_line (d
->line
,
1755 "structure `%s' defined for mismatching languages",
1757 error_at_line (&t
->u
.s
.line
, "one structure defined here");
1760 /* Some things may also be defined in the structure's options. */
1761 for (o
= t
->u
.s
.opt
; o
; o
= o
->next
)
1762 if (! desc
&& strcmp (o
->name
, "desc") == 0)
1763 desc
= (const char *)o
->info
;
1765 d
->prev_val
[2] = oldval
;
1766 d
->prev_val
[1] = oldprevval2
;
1771 error_at_line (d
->line
, "missing `desc' option for union `%s'",
1775 oprintf (d
->of
, "%*sswitch (", d
->indent
, "");
1776 output_escaped_param (d
, desc
, "desc");
1777 oprintf (d
->of
, ")\n");
1779 oprintf (d
->of
, "%*s{\n", d
->indent
, "");
1781 for (f
= t
->u
.s
.fields
; f
; f
= f
->next
)
1784 const char *dot
= ".";
1785 const char *tagid
= NULL
;
1788 int use_param_p
= 0;
1791 d
->reorder_fn
= NULL
;
1792 for (oo
= f
->opt
; oo
; oo
= oo
->next
)
1793 if (strcmp (oo
->name
, "dot") == 0)
1794 dot
= (const char *)oo
->info
;
1795 else if (strcmp (oo
->name
, "tag") == 0)
1796 tagid
= (const char *)oo
->info
;
1797 else if (strcmp (oo
->name
, "skip") == 0)
1799 else if (strcmp (oo
->name
, "default") == 0)
1801 else if (strcmp (oo
->name
, "reorder") == 0)
1802 d
->reorder_fn
= (const char *)oo
->info
;
1803 else if (strncmp (oo
->name
, "use_param", 9) == 0
1804 && (oo
->name
[9] == '\0' || ISDIGIT (oo
->name
[9])))
1810 if (union_p
&& tagid
)
1812 oprintf (d
->of
, "%*scase %s:\n", d
->indent
, "", tagid
);
1815 else if (union_p
&& default_p
)
1817 oprintf (d
->of
, "%*sdefault:\n", d
->indent
, "");
1821 else if (! union_p
&& (default_p
|| tagid
))
1822 error_at_line (d
->line
,
1823 "can't use `%s' outside a union on field `%s'",
1824 default_p
? "default" : "tag", f
->name
);
1825 else if (union_p
&& ! (default_p
|| tagid
)
1826 && f
->type
->kind
== TYPE_SCALAR
)
1829 "%s:%d: warning: field `%s' is missing `tag' or `default' option\n",
1830 d
->line
->file
, d
->line
->line
, f
->name
);
1833 else if (union_p
&& ! (default_p
|| tagid
))
1834 error_at_line (d
->line
,
1835 "field `%s' is missing `tag' or `default' option",
1839 d
->val
= newval
= xasprintf ("%s%s%s", oldval
, dot
, f
->name
);
1842 if (union_p
&& use_param_p
&& d
->param
== NULL
)
1843 oprintf (d
->of
, "%*sabort();\n", d
->indent
, "");
1845 walk_type (f
->type
, d
);
1851 oprintf (d
->of
, "%*sbreak;\n", d
->indent
, "");
1855 d
->reorder_fn
= NULL
;
1858 d
->prev_val
[1] = oldprevval1
;
1859 d
->prev_val
[2] = oldprevval2
;
1861 if (union_p
&& ! seen_default_p
)
1863 oprintf (d
->of
, "%*sdefault:\n", d
->indent
, "");
1864 oprintf (d
->of
, "%*s break;\n", d
->indent
, "");
1868 oprintf (d
->of
, "%*s}\n", d
->indent
, "");
1874 case TYPE_LANG_STRUCT
:
1877 for (nt
= t
->u
.s
.lang_struct
; nt
; nt
= nt
->next
)
1878 if ((d
->bitmap
& nt
->u
.s
.bitmap
) == d
->bitmap
)
1881 error_at_line (d
->line
, "structure `%s' differs between languages",
1888 case TYPE_PARAM_STRUCT
:
1890 type_p
*oldparam
= d
->param
;
1892 d
->param
= t
->u
.param_struct
.param
;
1893 walk_type (t
->u
.param_struct
.stru
, d
);
1894 d
->param
= oldparam
;
1903 /* process_field routine for marking routines. */
1906 write_types_process_field (f
, d
)
1908 const struct walk_type_data
*d
;
1910 const struct write_types_data
*wtd
;
1911 const char *cast
= d
->needs_cast_p
? "(void *)" : "";
1912 wtd
= (const struct write_types_data
*) d
->cookie
;
1917 oprintf (d
->of
, "%*s%s (%s%s", d
->indent
, "",
1918 wtd
->subfield_marker_routine
, cast
, d
->val
);
1919 if (wtd
->param_prefix
)
1921 oprintf (d
->of
, ", %s", d
->prev_val
[3]);
1924 oprintf (d
->of
, ", gt_%s_", wtd
->param_prefix
);
1925 output_mangled_typename (d
->of
, d
->orig_s
);
1928 oprintf (d
->of
, ", gt_%sa_%s", wtd
->param_prefix
, d
->prev_val
[0]);
1930 oprintf (d
->of
, ");\n");
1931 if (d
->reorder_fn
&& wtd
->reorder_note_routine
)
1932 oprintf (d
->of
, "%*s%s (%s%s, %s, %s);\n", d
->indent
, "",
1933 wtd
->reorder_note_routine
, cast
, d
->val
,
1934 d
->prev_val
[3], d
->reorder_fn
);
1938 if (wtd
->param_prefix
== NULL
)
1943 case TYPE_LANG_STRUCT
:
1944 case TYPE_PARAM_STRUCT
:
1945 oprintf (d
->of
, "%*sgt_%s_", d
->indent
, "", wtd
->prefix
);
1946 output_mangled_typename (d
->of
, f
);
1947 oprintf (d
->of
, " (%s%s);\n", cast
, d
->val
);
1948 if (d
->reorder_fn
&& wtd
->reorder_note_routine
)
1949 oprintf (d
->of
, "%*s%s (%s%s, %s%s, %s);\n", d
->indent
, "",
1950 wtd
->reorder_note_routine
, cast
, d
->val
, cast
, d
->val
,
1962 /* For S, a structure that's part of ORIG_S, and using parameters
1963 PARAM, write out a routine that:
1964 - Takes a parameter, a void * but actually of type *S
1965 - If SEEN_ROUTINE returns nonzero, calls write_types_process_field on each
1966 field of S or its substructures and (in some cases) things
1967 that are pointed to by S.
1971 write_func_for_structure (orig_s
, s
, param
, wtd
)
1975 const struct write_types_data
*wtd
;
1977 const char *fn
= s
->u
.s
.line
.file
;
1979 const char *chain_next
= NULL
;
1980 const char *chain_prev
= NULL
;
1982 struct walk_type_data d
;
1984 /* This is a hack, and not the good kind either. */
1985 for (i
= NUM_PARAM
- 1; i
>= 0; i
--)
1986 if (param
&& param
[i
] && param
[i
]->kind
== TYPE_POINTER
1987 && UNION_OR_STRUCT_P (param
[i
]->u
.p
))
1988 fn
= param
[i
]->u
.p
->u
.s
.line
.file
;
1990 memset (&d
, 0, sizeof (d
));
1991 d
.of
= get_output_file_with_visibility (fn
);
1993 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
1994 if (strcmp (opt
->name
, "chain_next") == 0)
1995 chain_next
= (const char *) opt
->info
;
1996 else if (strcmp (opt
->name
, "chain_prev") == 0)
1997 chain_prev
= (const char *) opt
->info
;
1999 if (chain_prev
!= NULL
&& chain_next
== NULL
)
2000 error_at_line (&s
->u
.s
.line
, "chain_prev without chain_next");
2002 d
.process_field
= write_types_process_field
;
2006 d
.line
= &s
->u
.s
.line
;
2007 d
.bitmap
= s
->u
.s
.bitmap
;
2009 d
.prev_val
[0] = "*x";
2010 d
.prev_val
[1] = "not valid postage"; /* guarantee an error */
2011 d
.prev_val
[3] = "x";
2014 oprintf (d
.of
, "\n");
2015 oprintf (d
.of
, "void\n");
2017 oprintf (d
.of
, "gt_%sx_%s", wtd
->prefix
, orig_s
->u
.s
.tag
);
2020 oprintf (d
.of
, "gt_%s_", wtd
->prefix
);
2021 output_mangled_typename (d
.of
, orig_s
);
2023 oprintf (d
.of
, " (x_p)\n");
2024 oprintf (d
.of
, " void *x_p;\n");
2025 oprintf (d
.of
, "{\n");
2026 oprintf (d
.of
, " %s %s * %sx = (%s %s *)x_p;\n",
2027 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
,
2028 chain_next
== NULL
? "const " : "",
2029 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
2030 if (chain_next
!= NULL
)
2031 oprintf (d
.of
, " %s %s * xlimit = x;\n",
2032 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
2033 if (chain_next
== NULL
)
2035 oprintf (d
.of
, " if (%s (x", wtd
->marker_routine
);
2036 if (wtd
->param_prefix
)
2038 oprintf (d
.of
, ", x, gt_%s_", wtd
->param_prefix
);
2039 output_mangled_typename (d
.of
, orig_s
);
2041 oprintf (d
.of
, "))\n");
2045 oprintf (d
.of
, " while (%s (xlimit", wtd
->marker_routine
);
2046 if (wtd
->param_prefix
)
2048 oprintf (d
.of
, ", xlimit, gt_%s_", wtd
->param_prefix
);
2049 output_mangled_typename (d
.of
, orig_s
);
2051 oprintf (d
.of
, "))\n");
2052 oprintf (d
.of
, " xlimit = (");
2053 d
.prev_val
[2] = "*xlimit";
2054 output_escaped_param (&d
, chain_next
, "chain_next");
2055 oprintf (d
.of
, ");\n");
2056 if (chain_prev
!= NULL
)
2058 oprintf (d
.of
, " if (x != xlimit)\n");
2059 oprintf (d
.of
, " for (;;)\n");
2060 oprintf (d
.of
, " {\n");
2061 oprintf (d
.of
, " %s %s * const xprev = (",
2062 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
2064 d
.prev_val
[2] = "*x";
2065 output_escaped_param (&d
, chain_prev
, "chain_prev");
2066 oprintf (d
.of
, ");\n");
2067 oprintf (d
.of
, " if (xprev == NULL) break;\n");
2068 oprintf (d
.of
, " x = xprev;\n");
2069 oprintf (d
.of
, " (void) %s (xprev",
2070 wtd
->marker_routine
);
2071 if (wtd
->param_prefix
)
2073 oprintf (d
.of
, ", xprev, gt_%s_", wtd
->param_prefix
);
2074 output_mangled_typename (d
.of
, orig_s
);
2076 oprintf (d
.of
, ");\n");
2077 oprintf (d
.of
, " }\n");
2079 oprintf (d
.of
, " while (x != xlimit)\n");
2081 oprintf (d
.of
, " {\n");
2083 d
.prev_val
[2] = "*x";
2087 if (chain_next
!= NULL
)
2089 oprintf (d
.of
, " x = (");
2090 output_escaped_param (&d
, chain_next
, "chain_next");
2091 oprintf (d
.of
, ");\n");
2094 oprintf (d
.of
, " }\n");
2095 oprintf (d
.of
, "}\n");
2098 /* Write out marker routines for STRUCTURES and PARAM_STRUCTS. */
2101 write_types (structures
, param_structs
, wtd
)
2103 type_p param_structs
;
2104 const struct write_types_data
*wtd
;
2108 oprintf (header_file
, "\n/* %s*/\n", wtd
->comment
);
2109 for (s
= structures
; s
; s
= s
->next
)
2110 if (s
->gc_used
== GC_POINTED_TO
2111 || s
->gc_used
== GC_MAYBE_POINTED_TO
)
2115 if (s
->gc_used
== GC_MAYBE_POINTED_TO
2116 && s
->u
.s
.line
.file
== NULL
)
2119 oprintf (header_file
, "#define gt_%s_", wtd
->prefix
);
2120 output_mangled_typename (header_file
, s
);
2121 oprintf (header_file
, "(X) do { \\\n");
2122 oprintf (header_file
,
2123 " if (X != NULL) gt_%sx_%s (X);\\\n", wtd
->prefix
,
2125 oprintf (header_file
,
2128 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
2129 if (strcmp (opt
->name
, "ptr_alias") == 0)
2131 type_p t
= (type_p
) opt
->info
;
2132 if (t
->kind
== TYPE_STRUCT
2133 || t
->kind
== TYPE_UNION
2134 || t
->kind
== TYPE_LANG_STRUCT
)
2135 oprintf (header_file
,
2136 "#define gt_%sx_%s gt_%sx_%s\n",
2137 wtd
->prefix
, s
->u
.s
.tag
, wtd
->prefix
, t
->u
.s
.tag
);
2139 error_at_line (&s
->u
.s
.line
,
2140 "structure alias is not a structure");
2146 /* Declare the marker procedure only once. */
2147 oprintf (header_file
,
2148 "extern void gt_%sx_%s PARAMS ((void *));\n",
2149 wtd
->prefix
, s
->u
.s
.tag
);
2151 if (s
->u
.s
.line
.file
== NULL
)
2153 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
2158 if (s
->kind
== TYPE_LANG_STRUCT
)
2161 for (ss
= s
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2162 write_func_for_structure (s
, ss
, NULL
, wtd
);
2165 write_func_for_structure (s
, s
, NULL
, wtd
);
2168 for (s
= param_structs
; s
; s
= s
->next
)
2169 if (s
->gc_used
== GC_POINTED_TO
)
2171 type_p
* param
= s
->u
.param_struct
.param
;
2172 type_p stru
= s
->u
.param_struct
.stru
;
2174 /* Declare the marker procedure. */
2175 oprintf (header_file
, "extern void gt_%s_", wtd
->prefix
);
2176 output_mangled_typename (header_file
, s
);
2177 oprintf (header_file
, " PARAMS ((void *));\n");
2179 if (stru
->u
.s
.line
.file
== NULL
)
2181 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
2186 if (stru
->kind
== TYPE_LANG_STRUCT
)
2189 for (ss
= stru
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2190 write_func_for_structure (s
, ss
, param
, wtd
);
2193 write_func_for_structure (s
, stru
, param
, wtd
);
2197 static const struct write_types_data ggc_wtd
=
2199 "ggc_m", NULL
, "ggc_mark", "ggc_test_and_set_mark", NULL
,
2200 "GC marker procedures. "
2203 static const struct write_types_data pch_wtd
=
2205 "pch_n", "pch_p", "gt_pch_note_object", "gt_pch_note_object",
2206 "gt_pch_note_reorder",
2207 "PCH type-walking procedures. "
2210 /* Write out the local pointer-walking routines. */
2212 /* process_field routine for local pointer-walking. */
2215 write_types_local_process_field (f
, d
)
2217 const struct walk_type_data
*d
;
2224 case TYPE_LANG_STRUCT
:
2225 case TYPE_PARAM_STRUCT
:
2227 oprintf (d
->of
, "%*sif ((void *)(%s) == this_obj)\n", d
->indent
, "",
2229 oprintf (d
->of
, "%*s op (&(%s), cookie);\n", d
->indent
, "", d
->val
);
2240 /* For S, a structure that's part of ORIG_S, and using parameters
2241 PARAM, write out a routine that:
2242 - Is of type gt_note_pointers
2243 - If calls PROCESS_FIELD on each field of S or its substructures.
2247 write_local_func_for_structure (orig_s
, s
, param
)
2252 const char *fn
= s
->u
.s
.line
.file
;
2254 struct walk_type_data d
;
2256 /* This is a hack, and not the good kind either. */
2257 for (i
= NUM_PARAM
- 1; i
>= 0; i
--)
2258 if (param
&& param
[i
] && param
[i
]->kind
== TYPE_POINTER
2259 && UNION_OR_STRUCT_P (param
[i
]->u
.p
))
2260 fn
= param
[i
]->u
.p
->u
.s
.line
.file
;
2262 memset (&d
, 0, sizeof (d
));
2263 d
.of
= get_output_file_with_visibility (fn
);
2265 d
.process_field
= write_types_local_process_field
;
2267 d
.line
= &s
->u
.s
.line
;
2268 d
.bitmap
= s
->u
.s
.bitmap
;
2270 d
.prev_val
[0] = d
.prev_val
[2] = "*x";
2271 d
.prev_val
[1] = "not valid postage"; /* guarantee an error */
2272 d
.prev_val
[3] = "x";
2275 oprintf (d
.of
, "\n");
2276 oprintf (d
.of
, "void\n");
2277 oprintf (d
.of
, "gt_pch_p_");
2278 output_mangled_typename (d
.of
, orig_s
);
2279 oprintf (d
.of
, " (this_obj, x_p, op, cookie)\n");
2280 oprintf (d
.of
, " void *this_obj ATTRIBUTE_UNUSED;\n");
2281 oprintf (d
.of
, " void *x_p;\n");
2282 oprintf (d
.of
, " gt_pointer_operator op ATTRIBUTE_UNUSED;\n");
2283 oprintf (d
.of
, " void *cookie ATTRIBUTE_UNUSED;\n");
2284 oprintf (d
.of
, "{\n");
2285 oprintf (d
.of
, " %s %s * const x ATTRIBUTE_UNUSED = (%s %s *)x_p;\n",
2286 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
,
2287 s
->kind
== TYPE_UNION
? "union" : "struct", s
->u
.s
.tag
);
2290 oprintf (d
.of
, "}\n");
2293 /* Write out local marker routines for STRUCTURES and PARAM_STRUCTS. */
2296 write_local (structures
, param_structs
)
2298 type_p param_structs
;
2302 oprintf (header_file
, "\n/* Local pointer-walking routines. */\n");
2303 for (s
= structures
; s
; s
= s
->next
)
2304 if (s
->gc_used
== GC_POINTED_TO
2305 || s
->gc_used
== GC_MAYBE_POINTED_TO
)
2309 if (s
->u
.s
.line
.file
== NULL
)
2312 for (opt
= s
->u
.s
.opt
; opt
; opt
= opt
->next
)
2313 if (strcmp (opt
->name
, "ptr_alias") == 0)
2315 type_p t
= (type_p
) opt
->info
;
2316 if (t
->kind
== TYPE_STRUCT
2317 || t
->kind
== TYPE_UNION
2318 || t
->kind
== TYPE_LANG_STRUCT
)
2320 oprintf (header_file
, "#define gt_pch_p_");
2321 output_mangled_typename (header_file
, s
);
2322 oprintf (header_file
, " gt_pch_p_");
2323 output_mangled_typename (header_file
, t
);
2324 oprintf (header_file
, "\n");
2327 error_at_line (&s
->u
.s
.line
,
2328 "structure alias is not a structure");
2334 /* Declare the marker procedure only once. */
2335 oprintf (header_file
, "extern void gt_pch_p_");
2336 output_mangled_typename (header_file
, s
);
2337 oprintf (header_file
,
2338 "\n PARAMS ((void *, void *, gt_pointer_operator, void *));\n");
2340 if (s
->kind
== TYPE_LANG_STRUCT
)
2343 for (ss
= s
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2344 write_local_func_for_structure (s
, ss
, NULL
);
2347 write_local_func_for_structure (s
, s
, NULL
);
2350 for (s
= param_structs
; s
; s
= s
->next
)
2351 if (s
->gc_used
== GC_POINTED_TO
)
2353 type_p
* param
= s
->u
.param_struct
.param
;
2354 type_p stru
= s
->u
.param_struct
.stru
;
2356 /* Declare the marker procedure. */
2357 oprintf (header_file
, "extern void gt_pch_p_");
2358 output_mangled_typename (header_file
, s
);
2359 oprintf (header_file
,
2360 "\n PARAMS ((void *, void *, gt_pointer_operator, void *));\n");
2362 if (stru
->u
.s
.line
.file
== NULL
)
2364 fprintf (stderr
, "warning: structure `%s' used but not defined\n",
2369 if (stru
->kind
== TYPE_LANG_STRUCT
)
2372 for (ss
= stru
->u
.s
.lang_struct
; ss
; ss
= ss
->next
)
2373 write_local_func_for_structure (s
, ss
, param
);
2376 write_local_func_for_structure (s
, stru
, param
);
2380 /* Write out the 'enum' definition for gt_types_enum. */
2383 write_enum_defn (structures
, param_structs
)
2385 type_p param_structs
;
2389 oprintf (header_file
, "\n/* Enumeration of types known. */\n");
2390 oprintf (header_file
, "enum gt_types_enum {\n");
2391 for (s
= structures
; s
; s
= s
->next
)
2392 if (s
->gc_used
== GC_POINTED_TO
2393 || s
->gc_used
== GC_MAYBE_POINTED_TO
)
2395 if (s
->gc_used
== GC_MAYBE_POINTED_TO
2396 && s
->u
.s
.line
.file
== NULL
)
2399 oprintf (header_file
, " gt_ggc_e_");
2400 output_mangled_typename (header_file
, s
);
2401 oprintf (header_file
, ", \n");
2403 for (s
= param_structs
; s
; s
= s
->next
)
2404 if (s
->gc_used
== GC_POINTED_TO
)
2406 oprintf (header_file
, " gt_e_");
2407 output_mangled_typename (header_file
, s
);
2408 oprintf (header_file
, ", \n");
2410 oprintf (header_file
, " gt_types_enum_last\n");
2411 oprintf (header_file
, "};\n");
2414 /* Might T contain any non-pointer elements? */
2417 contains_scalar_p (t
)
2426 return contains_scalar_p (t
->u
.a
.p
);
2428 /* Could also check for structures that have no non-pointer
2429 fields, but there aren't enough of those to worry about. */
2434 /* Mangle FN and print it to F. */
2437 put_mangled_filename (f
, fn
)
2441 const char *name
= get_output_file_name (fn
);
2442 for (; *name
!= 0; name
++)
2443 if (ISALNUM (*name
))
2444 oprintf (f
, "%c", *name
);
2446 oprintf (f
, "%c", '_');
2449 /* Finish off the currently-created root tables in FLP. PFX, TNAME,
2450 LASTNAME, and NAME are all strings to insert in various places in
2451 the resulting code. */
2454 finish_root_table (flp
, pfx
, lastname
, tname
, name
)
2458 const char *lastname
;
2463 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
2464 if (fli2
->started_p
)
2466 oprintf (fli2
->f
, " %s\n", lastname
);
2467 oprintf (fli2
->f
, "};\n\n");
2470 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
2471 if (fli2
->started_p
)
2473 lang_bitmap bitmap
= get_base_file_bitmap (fli2
->name
);
2476 for (fnum
= 0; bitmap
!= 0; fnum
++, bitmap
>>= 1)
2479 oprintf (base_files
[fnum
],
2480 "extern const struct %s gt_%s_",
2482 put_mangled_filename (base_files
[fnum
], fli2
->name
);
2483 oprintf (base_files
[fnum
], "[];\n");
2489 for (fnum
= 0; fnum
< NUM_BASE_FILES
; fnum
++)
2490 oprintf (base_files
[fnum
],
2491 "const struct %s * const %s[] = {\n",
2496 for (fli2
= flp
; fli2
; fli2
= fli2
->next
)
2497 if (fli2
->started_p
)
2499 lang_bitmap bitmap
= get_base_file_bitmap (fli2
->name
);
2502 fli2
->started_p
= 0;
2504 for (fnum
= 0; bitmap
!= 0; fnum
++, bitmap
>>= 1)
2507 oprintf (base_files
[fnum
], " gt_%s_", pfx
);
2508 put_mangled_filename (base_files
[fnum
], fli2
->name
);
2509 oprintf (base_files
[fnum
], ",\n");
2515 for (fnum
= 0; fnum
< NUM_BASE_FILES
; fnum
++)
2517 oprintf (base_files
[fnum
], " NULL\n");
2518 oprintf (base_files
[fnum
], "};\n");
2523 /* Write out to F the table entry and any marker routines needed to
2524 mark NAME as TYPE. The original variable is V, at LINE.
2525 HAS_LENGTH is nonzero iff V was a variable-length array. IF_MARKED
2526 is nonzero iff we are building the root table for hash table caches. */
2529 write_root (f
, v
, type
, name
, has_length
, line
, if_marked
)
2535 struct fileloc
*line
;
2536 const char *if_marked
;
2543 for (fld
= type
->u
.s
.fields
; fld
; fld
= fld
->next
)
2546 const char *desc
= NULL
;
2549 for (o
= fld
->opt
; o
; o
= o
->next
)
2550 if (strcmp (o
->name
, "skip") == 0)
2552 else if (strcmp (o
->name
, "desc") == 0)
2553 desc
= (const char *)o
->info
;
2555 error_at_line (line
,
2556 "field `%s' of global `%s' has unknown option `%s'",
2557 fld
->name
, name
, o
->name
);
2561 else if (desc
&& fld
->type
->kind
== TYPE_UNION
)
2563 pair_p validf
= NULL
;
2566 for (ufld
= fld
->type
->u
.s
.fields
; ufld
; ufld
= ufld
->next
)
2568 const char *tag
= NULL
;
2571 for (oo
= ufld
->opt
; oo
; oo
= oo
->next
)
2572 if (strcmp (oo
->name
, "tag") == 0)
2573 tag
= (const char *)oo
->info
;
2574 if (tag
== NULL
|| strcmp (tag
, desc
) != 0)
2577 error_at_line (line
,
2578 "both `%s.%s.%s' and `%s.%s.%s' have tag `%s'",
2579 name
, fld
->name
, validf
->name
,
2580 name
, fld
->name
, ufld
->name
,
2587 newname
= xasprintf ("%s.%s.%s",
2588 name
, fld
->name
, validf
->name
);
2589 write_root (f
, v
, validf
->type
, newname
, 0, line
,
2595 error_at_line (line
,
2596 "global `%s.%s' has `desc' option but is not union",
2601 newname
= xasprintf ("%s.%s", name
, fld
->name
);
2602 write_root (f
, v
, fld
->type
, newname
, 0, line
, if_marked
);
2612 newname
= xasprintf ("%s[0]", name
);
2613 write_root (f
, v
, type
->u
.a
.p
, newname
, has_length
, line
, if_marked
);
2622 oprintf (f
, " {\n");
2623 oprintf (f
, " &%s,\n", name
);
2626 for (ap
= v
->type
; ap
->kind
== TYPE_ARRAY
; ap
= ap
->u
.a
.p
)
2628 oprintf (f
, " * (%s)", ap
->u
.a
.len
);
2629 else if (ap
== v
->type
)
2630 oprintf (f
, " * ARRAY_SIZE (%s)", v
->name
);
2632 oprintf (f
, " sizeof (%s", v
->name
);
2633 for (ap
= v
->type
; ap
->kind
== TYPE_ARRAY
; ap
= ap
->u
.a
.p
)
2635 oprintf (f
, "),\n");
2639 if (! has_length
&& UNION_OR_STRUCT_P (tp
))
2641 oprintf (f
, " >_ggc_mx_%s,\n", tp
->u
.s
.tag
);
2642 oprintf (f
, " >_pch_nx_%s", tp
->u
.s
.tag
);
2644 else if (! has_length
&& tp
->kind
== TYPE_PARAM_STRUCT
)
2646 oprintf (f
, " >_ggc_m_");
2647 output_mangled_typename (f
, tp
);
2648 oprintf (f
, ",\n >_pch_n_");
2649 output_mangled_typename (f
, tp
);
2652 && (tp
->kind
== TYPE_POINTER
|| UNION_OR_STRUCT_P (tp
)))
2654 oprintf (f
, " >_ggc_ma_%s,\n", name
);
2655 oprintf (f
, " >_pch_na_%s", name
);
2659 error_at_line (line
,
2660 "global `%s' is pointer to unimplemented type",
2664 oprintf (f
, ",\n &%s", if_marked
);
2665 oprintf (f
, "\n },\n");
2671 oprintf (f
, " {\n");
2672 oprintf (f
, " &%s,\n", name
);
2673 oprintf (f
, " 1, \n");
2674 oprintf (f
, " sizeof (%s),\n", v
->name
);
2675 oprintf (f
, " >_ggc_m_S,\n");
2676 oprintf (f
, " (gt_pointer_walker) >_pch_n_S\n");
2677 oprintf (f
, " },\n");
2685 error_at_line (line
,
2686 "global `%s' is unimplemented type",
2691 /* This generates a routine to walk an array. */
2694 write_array (f
, v
, wtd
)
2697 const struct write_types_data
*wtd
;
2699 struct walk_type_data d
;
2702 memset (&d
, 0, sizeof (d
));
2708 d
.bitmap
= get_base_file_bitmap (v
->line
.file
);
2711 d
.prev_val
[3] = prevval3
= xasprintf ("&%s", v
->name
);
2713 if (wtd
->param_prefix
)
2715 oprintf (f
, "static void gt_%sa_%s\n", wtd
->param_prefix
, v
->name
);
2717 " PARAMS ((void *, void *, gt_pointer_operator, void *));\n");
2718 oprintf (f
, "static void gt_%sa_%s (this_obj, x_p, op, cookie)\n",
2719 wtd
->param_prefix
, v
->name
);
2720 oprintf (d
.of
, " void *this_obj ATTRIBUTE_UNUSED;\n");
2721 oprintf (d
.of
, " void *x_p ATTRIBUTE_UNUSED;\n");
2722 oprintf (d
.of
, " gt_pointer_operator op ATTRIBUTE_UNUSED;\n");
2723 oprintf (d
.of
, " void *cookie ATTRIBUTE_UNUSED;\n");
2724 oprintf (d
.of
, "{\n");
2725 d
.prev_val
[0] = d
.prev_val
[1] = d
.prev_val
[2] = d
.val
= v
->name
;
2726 d
.process_field
= write_types_local_process_field
;
2727 walk_type (v
->type
, &d
);
2728 oprintf (f
, "}\n\n");
2732 oprintf (f
, "static void gt_%sa_%s PARAMS ((void *));\n",
2733 wtd
->prefix
, v
->name
);
2734 oprintf (f
, "static void\ngt_%sa_%s (x_p)\n",
2735 wtd
->prefix
, v
->name
);
2736 oprintf (f
, " void *x_p ATTRIBUTE_UNUSED;\n");
2738 d
.prev_val
[0] = d
.prev_val
[1] = d
.prev_val
[2] = d
.val
= v
->name
;
2739 d
.process_field
= write_types_process_field
;
2740 walk_type (v
->type
, &d
);
2742 oprintf (f
, "}\n\n");
2745 /* Output a table describing the locations and types of VARIABLES. */
2748 write_roots (variables
)
2752 struct flist
*flp
= NULL
;
2754 for (v
= variables
; v
; v
= v
->next
)
2756 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2758 const char *length
= NULL
;
2759 int deletable_p
= 0;
2762 for (o
= v
->opt
; o
; o
= o
->next
)
2763 if (strcmp (o
->name
, "length") == 0)
2764 length
= (const char *)o
->info
;
2765 else if (strcmp (o
->name
, "deletable") == 0)
2767 else if (strcmp (o
->name
, "param_is") == 0)
2769 else if (strncmp (o
->name
, "param", 5) == 0
2770 && ISDIGIT (o
->name
[5])
2771 && strcmp (o
->name
+ 6, "_is") == 0)
2773 else if (strcmp (o
->name
, "if_marked") == 0)
2776 error_at_line (&v
->line
,
2777 "global `%s' has unknown option `%s'",
2780 for (fli
= flp
; fli
; fli
= fli
->next
)
2785 fli
= xmalloc (sizeof (*fli
));
2789 fli
->name
= v
->line
.file
;
2792 oprintf (f
, "\n/* GC roots. */\n\n");
2797 && v
->type
->kind
== TYPE_POINTER
2798 && (v
->type
->u
.p
->kind
== TYPE_POINTER
2799 || v
->type
->u
.p
->kind
== TYPE_STRUCT
))
2801 write_array (f
, v
, &ggc_wtd
);
2802 write_array (f
, v
, &pch_wtd
);
2806 for (v
= variables
; v
; v
= v
->next
)
2808 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2814 for (o
= v
->opt
; o
; o
= o
->next
)
2815 if (strcmp (o
->name
, "length") == 0)
2817 else if (strcmp (o
->name
, "deletable") == 0
2818 || strcmp (o
->name
, "if_marked") == 0)
2824 for (fli
= flp
; fli
; fli
= fli
->next
)
2827 if (! fli
->started_p
)
2831 oprintf (f
, "const struct ggc_root_tab gt_ggc_r_");
2832 put_mangled_filename (f
, v
->line
.file
);
2833 oprintf (f
, "[] = {\n");
2836 write_root (f
, v
, v
->type
, v
->name
, length_p
, &v
->line
, NULL
);
2839 finish_root_table (flp
, "ggc_r", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2842 for (v
= variables
; v
; v
= v
->next
)
2844 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2849 for (o
= v
->opt
; o
; o
= o
->next
)
2850 if (strcmp (o
->name
, "deletable") == 0)
2852 else if (strcmp (o
->name
, "if_marked") == 0)
2858 for (fli
= flp
; fli
; fli
= fli
->next
)
2861 if (! fli
->started_p
)
2865 oprintf (f
, "const struct ggc_root_tab gt_ggc_rd_");
2866 put_mangled_filename (f
, v
->line
.file
);
2867 oprintf (f
, "[] = {\n");
2870 oprintf (f
, " { &%s, 1, sizeof (%s), NULL, NULL },\n",
2874 finish_root_table (flp
, "ggc_rd", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2875 "gt_ggc_deletable_rtab");
2877 for (v
= variables
; v
; v
= v
->next
)
2879 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2881 const char *if_marked
= NULL
;
2885 for (o
= v
->opt
; o
; o
= o
->next
)
2886 if (strcmp (o
->name
, "length") == 0)
2888 else if (strcmp (o
->name
, "if_marked") == 0)
2889 if_marked
= (const char *) o
->info
;
2891 if (if_marked
== NULL
)
2894 if (v
->type
->kind
!= TYPE_POINTER
2895 || v
->type
->u
.p
->kind
!= TYPE_PARAM_STRUCT
2896 || v
->type
->u
.p
->u
.param_struct
.stru
!= find_structure ("htab", 0))
2898 error_at_line (&v
->line
, "if_marked option used but not hash table");
2902 for (fli
= flp
; fli
; fli
= fli
->next
)
2905 if (! fli
->started_p
)
2909 oprintf (f
, "const struct ggc_cache_tab gt_ggc_rc_");
2910 put_mangled_filename (f
, v
->line
.file
);
2911 oprintf (f
, "[] = {\n");
2914 write_root (f
, v
, v
->type
->u
.p
->u
.param_struct
.param
[0],
2915 v
->name
, length_p
, &v
->line
, if_marked
);
2918 finish_root_table (flp
, "ggc_rc", "LAST_GGC_CACHE_TAB", "ggc_cache_tab",
2919 "gt_ggc_cache_rtab");
2921 for (v
= variables
; v
; v
= v
->next
)
2923 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2926 int if_marked_p
= 0;
2929 for (o
= v
->opt
; o
; o
= o
->next
)
2930 if (strcmp (o
->name
, "length") == 0)
2932 else if (strcmp (o
->name
, "if_marked") == 0)
2938 for (fli
= flp
; fli
; fli
= fli
->next
)
2941 if (! fli
->started_p
)
2945 oprintf (f
, "const struct ggc_root_tab gt_pch_rc_");
2946 put_mangled_filename (f
, v
->line
.file
);
2947 oprintf (f
, "[] = {\n");
2950 write_root (f
, v
, v
->type
, v
->name
, length_p
, &v
->line
, NULL
);
2953 finish_root_table (flp
, "pch_rc", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2954 "gt_pch_cache_rtab");
2956 for (v
= variables
; v
; v
= v
->next
)
2958 outf_p f
= get_output_file_with_visibility (v
->line
.file
);
2963 for (o
= v
->opt
; o
; o
= o
->next
)
2964 if (strcmp (o
->name
, "deletable") == 0
2965 || strcmp (o
->name
, "if_marked") == 0)
2971 if (! contains_scalar_p (v
->type
))
2974 for (fli
= flp
; fli
; fli
= fli
->next
)
2977 if (! fli
->started_p
)
2981 oprintf (f
, "const struct ggc_root_tab gt_pch_rs_");
2982 put_mangled_filename (f
, v
->line
.file
);
2983 oprintf (f
, "[] = {\n");
2986 oprintf (f
, " { &%s, 1, sizeof (%s), NULL, NULL },\n",
2990 finish_root_table (flp
, "pch_rs", "LAST_GGC_ROOT_TAB", "ggc_root_tab",
2991 "gt_pch_scalar_rtab");
2995 extern int main
PARAMS ((int argc
, char **argv
));
2998 int argc ATTRIBUTE_UNUSED
;
2999 char **argv ATTRIBUTE_UNUSED
;
3002 static struct fileloc pos
= { __FILE__
, __LINE__
};
3007 srcdir_len
= strlen (srcdir
);
3009 do_scalar_typedef ("CUMULATIVE_ARGS", &pos
);
3010 do_scalar_typedef ("REAL_VALUE_TYPE", &pos
);
3011 do_scalar_typedef ("uint8", &pos
);
3012 do_scalar_typedef ("jword", &pos
);
3013 do_scalar_typedef ("JCF_u2", &pos
);
3015 do_typedef ("PTR", create_pointer (create_scalar_type ("void",
3018 do_typedef ("HARD_REG_SET", create_array (
3019 create_scalar_type ("unsigned long", strlen ("unsigned long")),
3022 for (i
= 0; i
< NUM_GT_FILES
; i
++)
3025 /* Omit if already seen. */
3026 for (j
= 0; j
< i
; j
++)
3028 if (!strcmp (all_files
[i
], all_files
[j
]))
3035 parse_file (all_files
[i
]);
3041 set_gc_used (variables
);
3044 write_enum_defn (structures
, param_structs
);
3045 write_types (structures
, param_structs
, &ggc_wtd
);
3046 write_types (structures
, param_structs
, &pch_wtd
);
3047 write_local (structures
, param_structs
);
3048 write_roots (variables
);
3050 close_output_files ();
3052 return (hit_error
!= 0);