Mercurial > hg > CbC > CbC_gcc
comparison gcc/gengtype.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
comparison
equal
deleted
inserted
replaced
56:3c8a44c06a95 | 63:b7f97abdc517 |
---|---|
21 #include "bconfig.h" | 21 #include "bconfig.h" |
22 #include "system.h" | 22 #include "system.h" |
23 #include "gengtype.h" | 23 #include "gengtype.h" |
24 #include "errors.h" /* for fatal */ | 24 #include "errors.h" /* for fatal */ |
25 #include "double-int.h" | 25 #include "double-int.h" |
26 #include "hashtab.h" | |
26 | 27 |
27 /* Data types, macros, etc. used only in this file. */ | 28 /* Data types, macros, etc. used only in this file. */ |
28 | 29 |
29 /* Kinds of types we can understand. */ | 30 /* Kinds of types we can understand. */ |
30 enum typekind { | 31 enum typekind { |
71 /* A description of a type. */ | 72 /* A description of a type. */ |
72 enum gc_used_enum | 73 enum gc_used_enum |
73 { | 74 { |
74 GC_UNUSED = 0, | 75 GC_UNUSED = 0, |
75 GC_USED, | 76 GC_USED, |
77 /* Used for structures whose definitions we haven't seen so far when | |
78 we encounter a pointer to it that is annotated with ``maybe_undef''. | |
79 If after reading in everything we don't have source file | |
80 information for it, we assume that it never has been defined. */ | |
76 GC_MAYBE_POINTED_TO, | 81 GC_MAYBE_POINTED_TO, |
77 GC_POINTED_TO | 82 GC_POINTED_TO |
78 }; | 83 }; |
79 | 84 |
80 struct type | 85 struct type |
176 static void close_output_files (void); | 181 static void close_output_files (void); |
177 | 182 |
178 /* Report an error at POS, printing MSG. */ | 183 /* Report an error at POS, printing MSG. */ |
179 | 184 |
180 void | 185 void |
181 error_at_line (struct fileloc *pos, const char *msg, ...) | 186 error_at_line (const struct fileloc *pos, const char *msg, ...) |
182 { | 187 { |
183 va_list ap; | 188 va_list ap; |
184 | 189 |
185 va_start (ap, msg); | 190 va_start (ap, msg); |
186 | 191 |
566 p = XNEW (struct pair); | 571 p = XNEW (struct pair); |
567 p->next = typedefs; | 572 p->next = typedefs; |
568 p->name = s; | 573 p->name = s; |
569 p->type = t; | 574 p->type = t; |
570 p->line = *pos; | 575 p->line = *pos; |
576 p->opt = NULL; | |
571 typedefs = p; | 577 typedefs = p; |
572 } | 578 } |
573 | 579 |
574 /* Define S as a typename of a scalar. Cannot be used to define | 580 /* Define S as a typename of a scalar. Cannot be used to define |
575 typedefs of 'char'. Note: is also used for pointer-to-function | 581 typedefs of 'char'. Note: is also used for pointer-to-function |
1000 { | 1006 { |
1001 pair_p flds = NULL; | 1007 pair_p flds = NULL; |
1002 options_p nodot; | 1008 options_p nodot; |
1003 int i; | 1009 int i; |
1004 type_p rtx_tp, rtvec_tp, tree_tp, mem_attrs_tp, note_union_tp, scalar_tp; | 1010 type_p rtx_tp, rtvec_tp, tree_tp, mem_attrs_tp, note_union_tp, scalar_tp; |
1005 type_p bitmap_tp, basic_block_tp, reg_attrs_tp, constant_tp, symbol_union_tp; | 1011 type_p basic_block_tp, reg_attrs_tp, constant_tp, symbol_union_tp; |
1006 | 1012 |
1007 if (t->kind != TYPE_UNION) | 1013 if (t->kind != TYPE_UNION) |
1008 { | 1014 { |
1009 error_at_line (&lexer_line, | 1015 error_at_line (&lexer_line, |
1010 "special `rtx_def' must be applied to a union"); | 1016 "special `rtx_def' must be applied to a union"); |
1016 rtx_tp = create_pointer (find_structure ("rtx_def", 0)); | 1022 rtx_tp = create_pointer (find_structure ("rtx_def", 0)); |
1017 rtvec_tp = create_pointer (find_structure ("rtvec_def", 0)); | 1023 rtvec_tp = create_pointer (find_structure ("rtvec_def", 0)); |
1018 tree_tp = create_pointer (find_structure ("tree_node", 1)); | 1024 tree_tp = create_pointer (find_structure ("tree_node", 1)); |
1019 mem_attrs_tp = create_pointer (find_structure ("mem_attrs", 0)); | 1025 mem_attrs_tp = create_pointer (find_structure ("mem_attrs", 0)); |
1020 reg_attrs_tp = create_pointer (find_structure ("reg_attrs", 0)); | 1026 reg_attrs_tp = create_pointer (find_structure ("reg_attrs", 0)); |
1021 bitmap_tp = create_pointer (find_structure ("bitmap_element_def", 0)); | |
1022 basic_block_tp = create_pointer (find_structure ("basic_block_def", 0)); | 1027 basic_block_tp = create_pointer (find_structure ("basic_block_def", 0)); |
1023 constant_tp = create_pointer (find_structure ("constant_descriptor_rtx", 0)); | 1028 constant_tp = create_pointer (find_structure ("constant_descriptor_rtx", 0)); |
1024 scalar_tp = &scalar_nonchar; /* rtunion int */ | 1029 scalar_tp = &scalar_nonchar; /* rtunion int */ |
1025 | 1030 |
1026 { | 1031 { |
1163 case 't': | 1168 case 't': |
1164 t = tree_tp; | 1169 t = tree_tp; |
1165 subname = "rt_tree"; | 1170 subname = "rt_tree"; |
1166 break; | 1171 break; |
1167 | 1172 |
1168 case 'b': | |
1169 t = bitmap_tp; | |
1170 subname = "rt_bit"; | |
1171 break; | |
1172 | |
1173 case 'B': | 1173 case 'B': |
1174 t = basic_block_tp; | 1174 t = basic_block_tp; |
1175 subname = "rt_bb"; | 1175 subname = "rt_bb"; |
1176 break; | 1176 break; |
1177 | 1177 |
1562 | 1562 |
1563 /* gtype-desc.c is a little special, so we create it here. */ | 1563 /* gtype-desc.c is a little special, so we create it here. */ |
1564 { | 1564 { |
1565 /* The order of files here matters very much. */ | 1565 /* The order of files here matters very much. */ |
1566 static const char *const ifiles [] = { | 1566 static const char *const ifiles [] = { |
1567 "config.h", "system.h", "coretypes.h", "tm.h", "varray.h", | 1567 "config.h", "system.h", "coretypes.h", "tm.h", |
1568 "hashtab.h", "splay-tree.h", "obstack.h", "bitmap.h", "input.h", | 1568 "hashtab.h", "splay-tree.h", "obstack.h", "bitmap.h", "input.h", |
1569 "tree.h", "rtl.h", "function.h", "insn-config.h", "expr.h", | 1569 "tree.h", "rtl.h", "function.h", "insn-config.h", "expr.h", |
1570 "hard-reg-set.h", "basic-block.h", "cselib.h", "insn-addr.h", | 1570 "hard-reg-set.h", "basic-block.h", "cselib.h", "insn-addr.h", |
1571 "optabs.h", "libfuncs.h", "debug.h", "ggc.h", "cgraph.h", | 1571 "optabs.h", "libfuncs.h", "debug.h", "ggc.h", "cgraph.h", |
1572 "tree-flow.h", "reload.h", "cpp-id-data.h", "tree-chrec.h", | 1572 "tree-flow.h", "reload.h", "cpp-id-data.h", "tree-chrec.h", |
1573 "cfglayout.h", "except.h", "output.h", "gimple.h", "cfgloop.h", | 1573 "cfglayout.h", "except.h", "output.h", "gimple.h", "cfgloop.h", |
1574 "target.h", "ipa-prop.h", NULL | 1574 "target.h", "ipa-prop.h", "lto-streamer.h", NULL |
1575 }; | 1575 }; |
1576 const char *const *ifp; | 1576 const char *const *ifp; |
1577 outf_p gtype_desc_c; | 1577 outf_p gtype_desc_c; |
1578 | 1578 |
1579 gtype_desc_c = create_file ("GCC", "gtype-desc.c"); | 1579 gtype_desc_c = create_file ("GCC", "gtype-desc.c"); |
1680 char * result = | 1680 char * result = |
1681 (langdir ? xasprintf ("gt-%s-%s", langdir, basename) | 1681 (langdir ? xasprintf ("gt-%s-%s", langdir, basename) |
1682 : xasprintf ("gt-%s", basename)); | 1682 : xasprintf ("gt-%s", basename)); |
1683 | 1683 |
1684 /* Then replace all non alphanumerics characters by '-' and change the | 1684 /* Then replace all non alphanumerics characters by '-' and change the |
1685 extenstion to ".h". We expect the input filename extension was at least | 1685 extension to ".h". We expect the input filename extension was at least |
1686 one character long. */ | 1686 one character long. */ |
1687 | 1687 |
1688 char *s = result; | 1688 char *s = result; |
1689 | 1689 |
1690 for (; *s != '.'; s++) | 1690 for (; *s != '.'; s++) |
1895 type_p param_structs, | 1895 type_p param_structs, |
1896 const struct write_types_data *wtd); | 1896 const struct write_types_data *wtd); |
1897 static void write_types_local_process_field | 1897 static void write_types_local_process_field |
1898 (type_p f, const struct walk_type_data *d); | 1898 (type_p f, const struct walk_type_data *d); |
1899 static void write_local_func_for_structure | 1899 static void write_local_func_for_structure |
1900 (type_p orig_s, type_p s, type_p * param); | 1900 (const_type_p orig_s, type_p s, type_p * param); |
1901 static void write_local (outf_p output_header, | 1901 static void write_local (outf_p output_header, |
1902 type_p structures, | 1902 type_p structures, |
1903 type_p param_structs); | 1903 type_p param_structs); |
1904 static void write_enum_defn (type_p structures, type_p param_structs); | 1904 static void write_enum_defn (type_p structures, type_p param_structs); |
1905 static int contains_scalar_p (type_p t); | 1905 static int contains_scalar_p (type_p t); |
1923 options_p opt; | 1923 options_p opt; |
1924 const char *val; | 1924 const char *val; |
1925 const char *prev_val[4]; | 1925 const char *prev_val[4]; |
1926 int indent; | 1926 int indent; |
1927 int counter; | 1927 int counter; |
1928 struct fileloc *line; | 1928 const struct fileloc *line; |
1929 lang_bitmap bitmap; | 1929 lang_bitmap bitmap; |
1930 type_p *param; | 1930 type_p *param; |
1931 int used_length; | 1931 int used_length; |
1932 type_p orig_s; | 1932 type_p orig_s; |
1933 const char *reorder_fn; | 1933 const char *reorder_fn; |
2532 } | 2532 } |
2533 else | 2533 else |
2534 oprintf (of, ", gt_types_enum_last"); | 2534 oprintf (of, ", gt_types_enum_last"); |
2535 } | 2535 } |
2536 | 2536 |
2537 /* Return an output file that is suitable for definitions which can | |
2538 reference struct S */ | |
2539 | |
2540 static outf_p | |
2541 get_output_file_for_structure (const_type_p s, type_p *param) | |
2542 { | |
2543 const char * fn = s->u.s.line.file; | |
2544 int i; | |
2545 | |
2546 /* This is a hack, and not the good kind either. */ | |
2547 for (i = NUM_PARAM - 1; i >= 0; i--) | |
2548 if (param && param[i] && param[i]->kind == TYPE_POINTER | |
2549 && UNION_OR_STRUCT_P (param[i]->u.p)) | |
2550 fn = param[i]->u.p->u.s.line.file; | |
2551 | |
2552 return get_output_file_with_visibility (fn); | |
2553 } | |
2554 | |
2537 /* For S, a structure that's part of ORIG_S, and using parameters | 2555 /* For S, a structure that's part of ORIG_S, and using parameters |
2538 PARAM, write out a routine that: | 2556 PARAM, write out a routine that: |
2539 - Takes a parameter, a void * but actually of type *S | 2557 - Takes a parameter, a void * but actually of type *S |
2540 - If SEEN_ROUTINE returns nonzero, calls write_types_process_field on each | 2558 - If SEEN_ROUTINE returns nonzero, calls write_types_process_field on each |
2541 field of S or its substructures and (in some cases) things | 2559 field of S or its substructures and (in some cases) things |
2544 | 2562 |
2545 static void | 2563 static void |
2546 write_func_for_structure (type_p orig_s, type_p s, type_p *param, | 2564 write_func_for_structure (type_p orig_s, type_p s, type_p *param, |
2547 const struct write_types_data *wtd) | 2565 const struct write_types_data *wtd) |
2548 { | 2566 { |
2549 const char *fn = s->u.s.line.file; | |
2550 int i; | |
2551 const char *chain_next = NULL; | 2567 const char *chain_next = NULL; |
2552 const char *chain_prev = NULL; | 2568 const char *chain_prev = NULL; |
2553 const char *chain_circular = NULL; | 2569 const char *chain_circular = NULL; |
2554 const char *mark_hook_name = NULL; | 2570 const char *mark_hook_name = NULL; |
2555 options_p opt; | 2571 options_p opt; |
2556 struct walk_type_data d; | 2572 struct walk_type_data d; |
2557 | 2573 |
2558 /* This is a hack, and not the good kind either. */ | |
2559 for (i = NUM_PARAM - 1; i >= 0; i--) | |
2560 if (param && param[i] && param[i]->kind == TYPE_POINTER | |
2561 && UNION_OR_STRUCT_P (param[i]->u.p)) | |
2562 fn = param[i]->u.p->u.s.line.file; | |
2563 | |
2564 memset (&d, 0, sizeof (d)); | 2574 memset (&d, 0, sizeof (d)); |
2565 d.of = get_output_file_with_visibility (fn); | 2575 d.of = get_output_file_for_structure (s, param); |
2566 | 2576 |
2567 for (opt = s->u.s.opt; opt; opt = opt->next) | 2577 for (opt = s->u.s.opt; opt; opt = opt->next) |
2568 if (strcmp (opt->name, "chain_next") == 0) | 2578 if (strcmp (opt->name, "chain_next") == 0) |
2569 chain_next = opt->info; | 2579 chain_next = opt->info; |
2570 else if (strcmp (opt->name, "chain_prev") == 0) | 2580 else if (strcmp (opt->name, "chain_prev") == 0) |
2883 - Is of type gt_note_pointers | 2893 - Is of type gt_note_pointers |
2884 - Calls PROCESS_FIELD on each field of S or its substructures. | 2894 - Calls PROCESS_FIELD on each field of S or its substructures. |
2885 */ | 2895 */ |
2886 | 2896 |
2887 static void | 2897 static void |
2888 write_local_func_for_structure (type_p orig_s, type_p s, type_p *param) | 2898 write_local_func_for_structure (const_type_p orig_s, type_p s, type_p *param) |
2889 { | 2899 { |
2890 const char *fn = s->u.s.line.file; | |
2891 int i; | |
2892 struct walk_type_data d; | 2900 struct walk_type_data d; |
2893 | 2901 |
2894 /* This is a hack, and not the good kind either. */ | |
2895 for (i = NUM_PARAM - 1; i >= 0; i--) | |
2896 if (param && param[i] && param[i]->kind == TYPE_POINTER | |
2897 && UNION_OR_STRUCT_P (param[i]->u.p)) | |
2898 fn = param[i]->u.p->u.s.line.file; | |
2899 | |
2900 memset (&d, 0, sizeof (d)); | 2902 memset (&d, 0, sizeof (d)); |
2901 d.of = get_output_file_with_visibility (fn); | 2903 d.of = get_output_file_for_structure (s, param); |
2902 d.process_field = write_types_local_process_field; | 2904 d.process_field = write_types_local_process_field; |
2903 d.opt = s->u.s.opt; | 2905 d.opt = s->u.s.opt; |
2904 d.line = &s->u.s.line; | 2906 d.line = &s->u.s.line; |
2905 d.bitmap = s->u.s.bitmap; | 2907 d.bitmap = s->u.s.bitmap; |
2906 d.param = param; | 2908 d.param = param; |
3687 "base", 0, pos); | 3689 "base", 0, pos); |
3688 | 3690 |
3689 do_typedef (astratname, new_structure (astratname, 0, pos, field, 0), pos); | 3691 do_typedef (astratname, new_structure (astratname, 0, pos, field, 0), pos); |
3690 } | 3692 } |
3691 | 3693 |
3694 static void dump_pair (int indent, pair_p p); | |
3695 static void dump_type (int indent, type_p p); | |
3696 static void dump_type_list (int indent, type_p p); | |
3697 | |
3698 #define INDENT 2 | |
3699 | |
3700 /* Dumps the value of typekind KIND. */ | |
3701 | |
3702 static void | |
3703 dump_typekind (int indent, enum typekind kind) | |
3704 { | |
3705 printf ("%*ckind = ", indent, ' '); | |
3706 switch (kind) | |
3707 { | |
3708 case TYPE_SCALAR: printf ("TYPE_SCALAR"); break; | |
3709 case TYPE_STRING: printf ("TYPE_STRING"); break; | |
3710 case TYPE_STRUCT: printf ("TYPE_STRUCT"); break; | |
3711 case TYPE_UNION: printf ("TYPE_UNION"); break; | |
3712 case TYPE_POINTER: printf ("TYPE_POINTER"); break; | |
3713 case TYPE_ARRAY: printf ("TYPE_ARRAY"); break; | |
3714 case TYPE_LANG_STRUCT: printf ("TYPE_LANG_STRUCT"); break; | |
3715 case TYPE_PARAM_STRUCT: printf ("TYPE_PARAM_STRUCT"); break; | |
3716 default: gcc_unreachable (); | |
3717 } | |
3718 printf ("\n"); | |
3719 } | |
3720 | |
3721 /* Dumps the value of GC_USED flag. */ | |
3722 | |
3723 static void | |
3724 dump_gc_used (int indent, enum gc_used_enum gc_used) | |
3725 { | |
3726 printf ("%*cgc_used = ", indent, ' '); | |
3727 switch (gc_used) | |
3728 { | |
3729 case GC_UNUSED: printf ("GC_UNUSED"); break; | |
3730 case GC_USED: printf ("GC_USED"); break; | |
3731 case GC_MAYBE_POINTED_TO: printf ("GC_MAYBE_POINTED_TO"); break; | |
3732 case GC_POINTED_TO: printf ("GC_POINTED_TO"); break; | |
3733 default: gcc_unreachable (); | |
3734 } | |
3735 printf ("\n"); | |
3736 } | |
3737 | |
3738 /* Dumps the type options OPT. */ | |
3739 | |
3740 static void | |
3741 dump_options (int indent, options_p opt) | |
3742 { | |
3743 options_p o; | |
3744 printf ("%*coptions = ", indent, ' '); | |
3745 o = opt; | |
3746 while (o) | |
3747 { | |
3748 printf ("%s:%s ", o->name, o->info); | |
3749 o = o->next; | |
3750 } | |
3751 printf ("\n"); | |
3752 } | |
3753 | |
3754 /* Dumps the source file location in LINE. */ | |
3755 | |
3756 static void | |
3757 dump_fileloc (int indent, struct fileloc line) | |
3758 { | |
3759 printf ("%*cfileloc: file = %s, line = %d\n", indent, ' ', line.file, | |
3760 line.line); | |
3761 } | |
3762 | |
3763 /* Recursively dumps the struct, union, or a language-specific | |
3764 struct T. */ | |
3765 | |
3766 static void | |
3767 dump_type_u_s (int indent, type_p t) | |
3768 { | |
3769 pair_p fields; | |
3770 | |
3771 gcc_assert (t->kind == TYPE_STRUCT || t->kind == TYPE_UNION | |
3772 || t->kind == TYPE_LANG_STRUCT); | |
3773 printf ("%*cu.s.tag = %s\n", indent, ' ', t->u.s.tag); | |
3774 dump_fileloc (indent, t->u.s.line); | |
3775 printf ("%*cu.s.fields =\n", indent, ' '); | |
3776 fields = t->u.s.fields; | |
3777 while (fields) | |
3778 { | |
3779 dump_pair (indent + INDENT, fields); | |
3780 fields = fields->next; | |
3781 } | |
3782 printf ("%*cend of fields of type %p\n", indent, ' ', (void *) t); | |
3783 dump_options (indent, t->u.s.opt); | |
3784 printf ("%*cu.s.bitmap = %X\n", indent, ' ', t->u.s.bitmap); | |
3785 if (t->kind == TYPE_LANG_STRUCT) | |
3786 { | |
3787 printf ("%*cu.s.lang_struct:\n", indent, ' '); | |
3788 dump_type_list (indent + INDENT, t->u.s.lang_struct); | |
3789 } | |
3790 } | |
3791 | |
3792 /* Recursively dumps the array T. */ | |
3793 | |
3794 static void | |
3795 dump_type_u_a (int indent, type_p t) | |
3796 { | |
3797 gcc_assert (t->kind == TYPE_ARRAY); | |
3798 printf ("%*clen = %s, u.a.p:\n", indent, ' ', t->u.a.len); | |
3799 dump_type_list (indent + INDENT, t->u.a.p); | |
3800 } | |
3801 | |
3802 /* Recursively dumps the parameterized struct T. */ | |
3803 | |
3804 static void | |
3805 dump_type_u_param_struct (int indent, type_p t) | |
3806 { | |
3807 int i; | |
3808 gcc_assert (t->kind == TYPE_PARAM_STRUCT); | |
3809 printf ("%*cu.param_struct.stru:\n", indent, ' '); | |
3810 dump_type_list (indent, t->u.param_struct.stru); | |
3811 dump_fileloc (indent, t->u.param_struct.line); | |
3812 for (i = 0; i < NUM_PARAM; i++) | |
3813 { | |
3814 if (t->u.param_struct.param[i] == NULL) | |
3815 continue; | |
3816 printf ("%*cu.param_struct.param[%d]:\n", indent, ' ', i); | |
3817 dump_type (indent + INDENT, t->u.param_struct.param[i]); | |
3818 } | |
3819 } | |
3820 | |
3821 /* Recursively dumps the type list T. */ | |
3822 | |
3823 static void | |
3824 dump_type_list (int indent, type_p t) | |
3825 { | |
3826 type_p p = t; | |
3827 while (p) | |
3828 { | |
3829 dump_type (indent, p); | |
3830 p = p->next; | |
3831 } | |
3832 } | |
3833 | |
3834 static htab_t seen_types; | |
3835 | |
3836 /* Recursively dumps the type T if it was not dumped previously. */ | |
3837 | |
3838 static void | |
3839 dump_type (int indent, type_p t) | |
3840 { | |
3841 PTR *slot; | |
3842 | |
3843 printf ("%*cType at %p: ", indent, ' ', (void *)t); | |
3844 slot = htab_find_slot (seen_types, t, INSERT); | |
3845 if (*slot != NULL) | |
3846 { | |
3847 printf ("already seen.\n"); | |
3848 return; | |
3849 } | |
3850 *slot = t; | |
3851 printf ("\n"); | |
3852 | |
3853 dump_typekind (indent, t->kind); | |
3854 printf ("%*cpointer_to = %p\n", indent + INDENT, ' ', | |
3855 (void *)t->pointer_to); | |
3856 dump_gc_used (indent + INDENT, t->gc_used); | |
3857 switch (t->kind) | |
3858 { | |
3859 case TYPE_SCALAR: | |
3860 printf ("%*cscalar_is_char = %s\n", indent + INDENT, ' ', | |
3861 t->u.scalar_is_char ? "true" : "false"); | |
3862 break; | |
3863 case TYPE_STRING: | |
3864 break; | |
3865 case TYPE_STRUCT: | |
3866 case TYPE_UNION: | |
3867 case TYPE_LANG_STRUCT: | |
3868 dump_type_u_s (indent + INDENT, t); | |
3869 break; | |
3870 case TYPE_POINTER: | |
3871 printf ("%*cp:\n", indent + INDENT, ' '); | |
3872 dump_type (indent + INDENT, t->u.p); | |
3873 break; | |
3874 case TYPE_ARRAY: | |
3875 dump_type_u_a (indent + INDENT, t); | |
3876 break; | |
3877 case TYPE_PARAM_STRUCT: | |
3878 dump_type_u_param_struct (indent + INDENT, t); | |
3879 break; | |
3880 default: | |
3881 gcc_unreachable (); | |
3882 } | |
3883 printf ("%*cEnd of type at %p\n", indent, ' ', (void *)t); | |
3884 } | |
3885 | |
3886 /* Dumps the pair P. */ | |
3887 | |
3888 static void | |
3889 dump_pair (int indent, pair_p p) | |
3890 { | |
3891 printf ("%*cpair: name = %s\n", indent, ' ', p->name); | |
3892 dump_type (indent, p->type); | |
3893 dump_fileloc (indent, p->line); | |
3894 dump_options (indent, p->opt); | |
3895 printf ("%*cEnd of pair %s\n", indent, ' ', p->name); | |
3896 } | |
3897 | |
3898 /* Dumps the list of pairs PP. */ | |
3899 | |
3900 static void | |
3901 dump_pair_list (const char * name, pair_p pp) | |
3902 { | |
3903 pair_p p; | |
3904 printf ("%s:\n", name); | |
3905 for (p = pp; p != NULL; p = p->next) | |
3906 dump_pair (0, p); | |
3907 printf ("End of %s\n\n", name); | |
3908 } | |
3909 | |
3910 /* Dumps the STRUCTURES. */ | |
3911 | |
3912 static void | |
3913 dump_structures (const char * name, type_p structures) | |
3914 { | |
3915 printf ("%s:\n", name); | |
3916 dump_type_list (0, structures); | |
3917 printf ("End of %s\n\n", name); | |
3918 } | |
3919 | |
3920 /* Dumps the internal structures of gengtype. */ | |
3921 | |
3922 static void | |
3923 dump_everything (void) | |
3924 { | |
3925 seen_types = htab_create (100, htab_hash_pointer, htab_eq_pointer, NULL); | |
3926 dump_pair_list ("typedefs", typedefs); | |
3927 dump_structures ("structures", structures); | |
3928 dump_structures ("param_structs", param_structs); | |
3929 dump_pair_list ("variables", variables); | |
3930 htab_delete (seen_types); | |
3931 } | |
3932 | |
3692 | 3933 |
3693 int | 3934 int |
3694 main (int argc, char **argv) | 3935 main (int argc, char **argv) |
3695 { | 3936 { |
3696 size_t i; | 3937 size_t i; |
3697 static struct fileloc pos = { this_file, 0 }; | 3938 static struct fileloc pos = { this_file, 0 }; |
3698 char* inputlist = 0; | 3939 char* inputlist = 0; |
3940 int do_dump = 0; | |
3699 outf_p output_header; | 3941 outf_p output_header; |
3700 char* plugin_output_filename = NULL; | 3942 char* plugin_output_filename = NULL; |
3701 /* fatal uses this */ | 3943 /* fatal uses this */ |
3702 progname = "gengtype"; | 3944 progname = "gengtype"; |
3945 | |
3946 if (argc >= 2 && !strcmp (argv[1], "-d")) | |
3947 { | |
3948 do_dump = 1; | |
3949 argv = &argv[1]; | |
3950 argc--; | |
3951 } | |
3703 | 3952 |
3704 if (argc >= 6 && !strcmp (argv[1], "-P")) | 3953 if (argc >= 6 && !strcmp (argv[1], "-P")) |
3705 { | 3954 { |
3706 plugin_output_filename = argv[2]; | 3955 plugin_output_filename = argv[2]; |
3707 plugin_output = create_file ("GCC", plugin_output_filename); | 3956 plugin_output = create_file ("GCC", plugin_output_filename); |
3723 { | 3972 { |
3724 srcdir = argv[1]; | 3973 srcdir = argv[1]; |
3725 inputlist = argv[2]; | 3974 inputlist = argv[2]; |
3726 } | 3975 } |
3727 else | 3976 else |
3728 fatal ("usage: gengtype [-P pluginout.h] srcdir input-list " | 3977 fatal ("usage: gengtype [-d] [-P pluginout.h] srcdir input-list " |
3729 "[file1 file2 ... fileN]"); | 3978 "[file1 file2 ... fileN]"); |
3730 | 3979 |
3731 srcdir_len = strlen (srcdir); | 3980 srcdir_len = strlen (srcdir); |
3732 | 3981 |
3733 read_input_list (inputlist); | 3982 read_input_list (inputlist); |
3771 } | 4020 } |
3772 write_roots (variables, plugin_files == NULL); | 4021 write_roots (variables, plugin_files == NULL); |
3773 write_rtx_next (); | 4022 write_rtx_next (); |
3774 close_output_files (); | 4023 close_output_files (); |
3775 | 4024 |
4025 if (do_dump) | |
4026 dump_everything (); | |
4027 | |
3776 if (plugin_files) | 4028 if (plugin_files) |
3777 { | 4029 { |
3778 for (i = 0; i < nb_plugin_files; i++) | 4030 for (i = 0; i < nb_plugin_files; i++) |
3779 free (plugin_files[i] - sizeof (lang_bitmap)); | 4031 free (plugin_files[i] - sizeof (lang_bitmap)); |
3780 free (plugin_files); | 4032 free (plugin_files); |